Compare commits
8 Commits
543e44abc8
...
main
Author | SHA1 | Date | |
---|---|---|---|
086e7c7a77 | |||
181bed4449 | |||
6e0795bbdf | |||
5df5a0ad7a | |||
63b49dd282 | |||
5e8f4e33e3 | |||
a140a35448 | |||
a0765efc3c |
0
.devcontainer/Caddyfile
Normal file → Executable file
0
.devcontainer/Dockerfile
Normal file → Executable file
0
.devcontainer/devcontainer.json
Normal file → Executable file
0
.devcontainer/start.sh
Normal file → Executable file
0
.vscode/launch.json
vendored
Normal file → Executable file
0
LICENSE.md
Normal file → Executable file
0
cache/.gitignore
vendored
Normal file → Executable file
0
docker-compose-dev.yml
Normal file → Executable file
2
docker-compose.yml
Normal file → Executable file
@ -1,7 +1,7 @@
|
||||
version: '3.3'
|
||||
services:
|
||||
http2pic:
|
||||
image: ghcr.io/hascheksolutions/http2pic:2
|
||||
image: gitea.haschek.at/haschek-solutions/http2pic:2
|
||||
restart: unless-stopped
|
||||
|
||||
environment:
|
||||
|
@ -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 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
|
||||
RUN chmod +x /start.sh
|
||||
|
||||
|
21
docker/dokploy-compose.yml
Executable 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
|
@ -3,7 +3,7 @@ echo ' [+] Starting php'
|
||||
php-fpm84
|
||||
|
||||
cd /srv/src
|
||||
composer install
|
||||
composer install --no-dev --optimize-autoloader
|
||||
|
||||
echo ' [+] Starting Chrome'
|
||||
chromedriver --port=4444 &
|
||||
@ -20,6 +20,6 @@ _buildConfig() {
|
||||
echo ""
|
||||
}
|
||||
|
||||
_buildConfig > src/inc/config.inc.php
|
||||
_buildConfig > /srv/src/config.inc.php
|
||||
|
||||
caddy run --config /etc/caddy/Caddyfile
|
1
src/.gitignore
vendored
Normal file → Executable file
@ -1 +1,2 @@
|
||||
vendor/
|
||||
config.inc.php
|
0
src/composer.json
Normal file → Executable file
0
src/composer.lock
generated
Normal file → Executable file
0
src/config.inc.php → src/config.inc.php.php
Normal file → Executable file
3
src/example.config.inc.php
Executable file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
define('URL','http://localhost:8080');
|
19
src/helpers.php
Normal file → Executable file
@ -14,3 +14,22 @@ function renderTemplate($templatename,$variables=[],$basepath=ROOT.'/src')
|
||||
|
||||
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
2
src/templates/index.html.php
Normal file → Executable file
@ -71,7 +71,7 @@
|
||||
<!-- Main Content -->
|
||||
<div class="container">
|
||||
<h2>How the API works</h2>
|
||||
<div class="well"><h2 ><?=URL?>/api/url=<span style="color:#1e90ff">[WEBSITE_URL]</span>&<span style="color:#C73C49">[OPTIONS]</span></h2></div><hr/><br/>
|
||||
<div class="well"><h2 ><?=URL?>/api/?url=<span style="color:#1e90ff">[WEBSITE_URL]</span>&<span style="color:#C73C49">[OPTIONS]</span></h2></div><hr/><br/>
|
||||
<div >
|
||||
<div>
|
||||
<section>
|
||||
|
0
web/css/bootstrap.css
vendored
Normal file → Executable file
0
web/css/bootstrap.min.css
vendored
Normal file → Executable file
0
web/css/clean-blog.css
Normal file → Executable file
0
web/css/clean-blog.min.css
vendored
Normal file → Executable file
0
web/css/http2pic.css
Normal file → Executable file
0
web/fonts/glyphicons-halflings-regular.eot
Normal file → Executable file
0
web/fonts/glyphicons-halflings-regular.svg
Normal file → Executable file
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
0
web/fonts/glyphicons-halflings-regular.ttf
Normal file → Executable file
0
web/fonts/glyphicons-halflings-regular.woff
Normal file → Executable file
0
web/fonts/glyphicons-halflings-regular.woff2
Normal file → Executable file
0
web/img/domainfailed.jpg
Normal file → Executable file
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
0
web/img/failed.jpg
Normal file → Executable file
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
0
web/img/home-bg.jpg
Normal file → Executable file
Before Width: | Height: | Size: 169 KiB After Width: | Height: | Size: 169 KiB |
0
web/img/hs_logo.png
Normal file → Executable file
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
0
web/img/loading.gif
Normal file → Executable file
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 200 KiB |
0
web/img/pagefailed.jpg
Normal file → Executable file
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
58
web/index.php
Normal file → Executable file
@ -1,36 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
||||
|
||||
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.'helpers.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 . 'config.inc.php');
|
||||
require_once(ROOT . DS . 'src' . DS . 'helpers.php');
|
||||
require_once(ROOT . DS . 'src' . DS . 'http2pic.class.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
|
||||
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;
|
||||
|
||||
|
||||
switch($url[0])
|
||||
{
|
||||
switch ($url[0]) {
|
||||
case 'api':
|
||||
$target = substr($_SERVER['REQUEST_URI'],5);
|
||||
if(!$target || !filter_var($target, FILTER_VALIDATE_URL))
|
||||
$target = substr($_SERVER['REQUEST_URI'], 5);
|
||||
if (!$target || !filter_var($target, FILTER_VALIDATE_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');
|
||||
echo 'Invalid URL';
|
||||
exit;
|
||||
}
|
||||
$viewport = $_REQUEST['viewport'];
|
||||
$js = $_REQUEST['js']=='false'?false:true;
|
||||
$ip = getUserIP();
|
||||
|
||||
$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';
|
||||
$options = new \Facebook\WebDriver\Chrome\ChromeOptions();
|
||||
@ -40,28 +46,32 @@ switch($url[0])
|
||||
$capabilities->setCapability(\Facebook\WebDriver\Chrome\ChromeOptions::CAPABILITY, $options);
|
||||
|
||||
//disable javascript if $js is false
|
||||
if(!$js)
|
||||
if (!$js)
|
||||
$capabilities->setCapability('javascriptEnabled', false);
|
||||
|
||||
|
||||
try {
|
||||
$driver = RemoteWebDriver::create($serverUrl, $capabilities);
|
||||
|
||||
$driver->get($target);
|
||||
|
||||
//hide scroll bars
|
||||
$driver->executeScript('document.body.style.overflow = "hidden";');
|
||||
|
||||
//set screenshot size to 1920x1080
|
||||
//$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768));
|
||||
//if $viewport is set, set window size
|
||||
if($viewport)
|
||||
{
|
||||
$viewport = explode('x',$viewport);
|
||||
if ($viewport) {
|
||||
$viewport = explode('x', $viewport);
|
||||
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($viewport[0], $viewport[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension(1024, 768));
|
||||
}
|
||||
addToLog("$ip\tRequested $target with viewport " . implode('x', $viewport) . " and js " . ($js ? 'enabled' : 'disabled'));
|
||||
} catch (Exception $e) {
|
||||
header('HTTP/1.0 500 Internal Server Error');
|
||||
addToLog("$ip\tRequested $target but resulted in error:\t" . $e->getMessage());
|
||||
echo 'Error: ' . $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
// take screenshot and save to file
|
||||
//header for png
|
||||
|