8 Commits

Author SHA1 Message Date
086e7c7a77 full path 2025-06-10 12:00:35 +02:00
181bed4449 config corrections 2025-06-10 11:57:16 +02:00
6e0795bbdf url 2025-06-10 11:55:13 +02:00
5df5a0ad7a added logging
All checks were successful
Build Container / docker (push) Successful in 1m23s
2025-06-10 11:50:24 +02:00
63b49dd282 url showing 2025-06-10 11:25:27 +02:00
5e8f4e33e3 ups 2025-06-10 11:23:45 +02:00
a140a35448 symlink 2025-06-10 11:21:11 +02:00
a0765efc3c ok 2025-06-10 11:16:25 +02:00
48 changed files with 97 additions and 40 deletions

0
.devcontainer/Caddyfile Normal file → Executable file
View File

0
.devcontainer/Dockerfile Normal file → Executable file
View File

0
.devcontainer/devcontainer.json Normal file → Executable file
View File

0
.devcontainer/start.sh Normal file → Executable file
View File

0
.vscode/launch.json vendored Normal file → Executable file
View File

0
LICENSE.md Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
cache/.gitignore vendored Normal file → Executable file
View File

0
docker-compose-dev.yml Normal file → Executable file
View File

2
docker-compose.yml Normal file → Executable file
View File

@ -1,7 +1,7 @@
version: '3.3' version: '3.3'
services: services:
http2pic: http2pic:
image: ghcr.io/hascheksolutions/http2pic:2 image: gitea.haschek.at/haschek-solutions/http2pic:2
restart: unless-stopped restart: unless-stopped
environment: environment:

View File

@ -12,6 +12,9 @@ RUN echo "error_log = /srv/logs/php_errors.log" >> /etc/php84/php.ini
RUN apk add --no-cache php84-ctype php84-dom php84-fileinfo php84-gd php84-iconv php84-simplexml php84-xml php84-xmlreader php84-xmlwriter php84-zip php84-phar php84-openssl RUN apk add --no-cache php84-ctype php84-dom php84-fileinfo php84-gd php84-iconv php84-simplexml php84-xml php84-xmlreader php84-xmlwriter php84-zip php84-phar php84-openssl
RUN curl -sS https://getcomposer.org/installer | /usr/bin/php84 -- --install-dir=/usr/bin --filename=composer RUN curl -sS https://getcomposer.org/installer | /usr/bin/php84 -- --install-dir=/usr/bin --filename=composer
# add symlink for php
RUN ln -s /usr/bin/php84 /usr/bin/php
ADD docker/start.sh /start.sh ADD docker/start.sh /start.sh
RUN chmod +x /start.sh RUN chmod +x /start.sh

21
docker/dokploy-compose.yml Executable file
View File

@ -0,0 +1,21 @@
services:
http2pic:
build:
context: ../
dockerfile: docker/Dockerfile
restart: unless-stopped
ports:
- 80
environment:
- URL=https://http2pic.haschek.at
networks:
- dokploy-network
labels:
- "traefik.enable=true"
- "traefik.http.routers.http2pic.rule=Host(`http2pic.haschek.at`)"
- "traefik.http.routers.http2pic.entrypoints=websecure"
- "traefik.http.routers.http2pic.tls.certResolver=letsencrypt"
- "traefik.http.services.http2pic.loadbalancer.server.port=80"
networks:
dokploy-network:
external: true

View File

@ -3,7 +3,7 @@ echo ' [+] Starting php'
php-fpm84 php-fpm84
cd /srv/src cd /srv/src
composer install composer install --no-dev --optimize-autoloader
echo ' [+] Starting Chrome' echo ' [+] Starting Chrome'
chromedriver --port=4444 & chromedriver --port=4444 &
@ -20,6 +20,6 @@ _buildConfig() {
echo "" echo ""
} }
_buildConfig > src/inc/config.inc.php _buildConfig > /srv/src/config.inc.php
caddy run --config /etc/caddy/Caddyfile caddy run --config /etc/caddy/Caddyfile

3
src/.gitignore vendored Normal file → Executable file
View File

@ -1 +1,2 @@
vendor/ vendor/
config.inc.php

0
src/composer.json Normal file → Executable file
View File

0
src/composer.lock generated Normal file → Executable file
View File

0
src/config.inc.php → src/config.inc.php.php Normal file → Executable file
View File

3
src/example.config.inc.php Executable file
View File

@ -0,0 +1,3 @@
<?php
define('URL','http://localhost:8080');

19
src/helpers.php Normal file → Executable file
View File

@ -13,4 +13,23 @@ function renderTemplate($templatename,$variables=[],$basepath=ROOT.'/src')
ob_end_clean(); ob_end_clean();
return $rendered; return $rendered;
}
function addToLog($data)
{
$fp = fopen(ROOT.DS.'logs'.DS.'app.log','a');
fwrite($fp,date("d.m.y H:i")."\t".$data."\n");
fclose($fp);
}
function getUserIP()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
} }

0
src/http2pic.class.php Normal file → Executable file
View File

2
src/templates/index.html.php Normal file → Executable file
View File

@ -71,7 +71,7 @@
<!-- Main Content --> <!-- Main Content -->
<div class="container"> <div class="container">
<h2>How the API works</h2> <h2>How the API works</h2>
<div class="well"><h2 ><?=URL?>/api/url=<span style="color:#1e90ff">[WEBSITE_URL]</span>&amp;<span style="color:#C73C49">[OPTIONS]</span></h2></div><hr/><br/> <div class="well"><h2 ><?=URL?>/api/?url=<span style="color:#1e90ff">[WEBSITE_URL]</span>&amp;<span style="color:#C73C49">[OPTIONS]</span></h2></div><hr/><br/>
<div > <div >
<div> <div>
<section> <section>

0
web/css/bootstrap.css vendored Normal file → Executable file
View File

0
web/css/bootstrap.min.css vendored Normal file → Executable file
View File

0
web/css/clean-blog.css Normal file → Executable file
View File

0
web/css/clean-blog.min.css vendored Normal file → Executable file
View File

0
web/css/http2pic.css Normal file → Executable file
View File

0
web/fonts/glyphicons-halflings-regular.eot Normal file → Executable file
View File

0
web/fonts/glyphicons-halflings-regular.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

0
web/fonts/glyphicons-halflings-regular.ttf Normal file → Executable file
View File

0
web/fonts/glyphicons-halflings-regular.woff Normal file → Executable file
View File

0
web/fonts/glyphicons-halflings-regular.woff2 Normal file → Executable file
View File

0
web/img/domainfailed.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

0
web/img/failed.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

0
web/img/home-bg.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 169 KiB

After

Width:  |  Height:  |  Size: 169 KiB

0
web/img/hs_logo.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

0
web/img/loading.gif Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 200 KiB

After

Width:  |  Height:  |  Size: 200 KiB

0
web/img/pagefailed.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

80
web/index.php Normal file → Executable file
View File

@ -1,66 +1,76 @@
<?php <?php
use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\DesiredCapabilities;
define('DS', DIRECTORY_SEPARATOR); define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__).DS.'..'); define('ROOT', dirname(__FILE__) . DS . '..');
require_once(ROOT.DS.'src'.DS.'config.inc.php'); require_once(ROOT . DS . 'src' . DS . 'config.inc.php');
require_once(ROOT.DS.'src'.DS.'helpers.php'); require_once(ROOT . DS . 'src' . DS . 'helpers.php');
require_once(ROOT.DS.'src'.DS.'http2pic.class.php'); require_once(ROOT . DS . 'src' . DS . 'http2pic.class.php');
require_once(ROOT.DS.'src'.DS.'vendor'.DS.'autoload.php'); require_once(ROOT . DS . 'src' . DS . 'vendor' . DS . 'autoload.php');
$url = array_filter(explode('/',ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),'/'))); $url = array_filter(explode('/', ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/')));
//check for integrated server //check for integrated server
if(php_sapi_name()=='cli-server' && file_exists(ROOT.DS.'web'.DS.implode('/',$url)) && !is_dir(ROOT.DS.'web'.DS.implode('/',$url))) if (php_sapi_name() == 'cli-server' && file_exists(ROOT . DS . 'web' . DS . implode('/', $url)) && !is_dir(ROOT . DS . 'web' . DS . implode('/', $url)))
return false; return false;
switch($url[0]) switch ($url[0]) {
{
case 'api': case 'api':
$target = substr($_SERVER['REQUEST_URI'],5); $target = substr($_SERVER['REQUEST_URI'], 5);
if(!$target || !filter_var($target, FILTER_VALIDATE_URL)) if (!$target || !filter_var($target, FILTER_VALIDATE_URL))
$target = $_REQUEST['url']; $target = $_REQUEST['url'];
if(!filter_var($target, FILTER_VALIDATE_URL)) if (!filter_var($target, FILTER_VALIDATE_URL)) {
{
header('HTTP/1.0 400 Bad Request'); header('HTTP/1.0 400 Bad Request');
echo 'Invalid URL'; echo 'Invalid URL';
exit; exit;
} }
$viewport = $_REQUEST['viewport']; $ip = getUserIP();
$js = $_REQUEST['js']=='false'?false:true;
$viewport = $_REQUEST['viewport'] ?? '1024x768';
if (!preg_match('/^\d+x\d+$/', $viewport)) {
header('HTTP/1.0 400 Bad Request');
echo 'Invalid viewport format. Use WIDTHxHEIGHT (e.g., 1024x768)';
exit;
}
$js = $_REQUEST['js'] == 'false' ? false : true;
$serverUrl = 'http://localhost:4444'; $serverUrl = 'http://localhost:4444';
$options = new \Facebook\WebDriver\Chrome\ChromeOptions(); $options = new \Facebook\WebDriver\Chrome\ChromeOptions();
$options->addArguments(['--headless', '--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage']); $options->addArguments(['--headless', '--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage']);
$capabilities = DesiredCapabilities::chrome(); $capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(\Facebook\WebDriver\Chrome\ChromeOptions::CAPABILITY, $options); $capabilities->setCapability(\Facebook\WebDriver\Chrome\ChromeOptions::CAPABILITY, $options);
//disable javascript if $js is false //disable javascript if $js is false
if(!$js) if (!$js)
$capabilities->setCapability('javascriptEnabled', false); $capabilities->setCapability('javascriptEnabled', false);
$driver = RemoteWebDriver::create($serverUrl, $capabilities);
$driver->get($target); try {
$driver = RemoteWebDriver::create($serverUrl, $capabilities);
$driver->get($target);
//hide scroll bars
$driver->executeScript('document.body.style.overflow = "hidden";');
//hide scroll bars //set screenshot size to 1920x1080
$driver->executeScript('document.body.style.overflow = "hidden";'); //$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768));
//if $viewport is set, set window size
//set screenshot size to 1920x1080 if ($viewport) {
//$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768)); $viewport = explode('x', $viewport);
//if $viewport is set, set window size $driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($viewport[0], $viewport[1]));
if($viewport) } else {
{ $driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768));
$viewport = explode('x',$viewport); }
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($viewport[0], $viewport[1])); addToLog("$ip\tRequested $target with viewport " . implode('x', $viewport) . " and js " . ($js ? 'enabled' : 'disabled'));
} } catch (Exception $e) {
else header('HTTP/1.0 500 Internal Server Error');
{ addToLog("$ip\tRequested $target but resulted in error:\t" . $e->getMessage());
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768)); echo 'Error: ' . $e->getMessage();
exit;
} }
// take screenshot and save to file // take screenshot and save to file
@ -68,8 +78,8 @@ switch($url[0])
header('Content-Type: image/png'); header('Content-Type: image/png');
echo $driver->takeScreenshot(); echo $driver->takeScreenshot();
break; break;
default: default:
echo renderTemplate('index.html.php'); echo renderTemplate('index.html.php');
break; break;
} }

0
web/js/bootstrap.js vendored Normal file → Executable file
View File

0
web/js/bootstrap.min.js vendored Normal file → Executable file
View File

0
web/js/clean-blog.js Normal file → Executable file
View File

0
web/js/clean-blog.min.js vendored Normal file → Executable file
View File

0
web/js/http2pic.js Normal file → Executable file
View File

0
web/js/jquery.js vendored Normal file → Executable file
View File

0
web/js/jquery.min.js vendored Normal file → Executable file
View File

0
web/less/clean-blog.less Normal file → Executable file
View File

0
web/less/mixins.less Normal file → Executable file
View File

0
web/less/variables.less Normal file → Executable file
View File