preparations for rewrite
1
.gitignore
vendored
@ -1 +0,0 @@
|
||||
cache/*
|
14
.htaccess
@ -1,14 +0,0 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
|
||||
RewriteRule ^(.*)$ index.php?url=$1 [QSA,PT,L]
|
||||
|
||||
</IfModule>
|
||||
|
||||
<Files "debug.log">
|
||||
Order Allow,Deny
|
||||
Deny from all
|
||||
</Files>
|
2
cache/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
5
docker/Caddyfile
Normal file
@ -0,0 +1,5 @@
|
||||
:80 {
|
||||
root * /srv
|
||||
php_fastcgi 127.0.0.1:9000
|
||||
file_server
|
||||
}
|
16
docker/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
||||
FROM ghcr.io/surnet/alpine-wkhtmltopdf:3.20.3-0.12.6-full
|
||||
|
||||
# Install PHP and necessary extensions
|
||||
RUN apk add --no-cache php83 php83-fpm php83-opcache caddy php83-curl
|
||||
|
||||
RUN sed -i 's/nobody/caddy/g' /etc/php83/php-fpm.d/www.conf
|
||||
RUN sed -i 's/E_ALL \& ~E_DEPRECATED \& ~E_STRICT/E_ALL \& ~E_DEPRECATED \& ~E_STRICT \& ~E_NOTICE \& ~E_WARNING/g' /etc/php83/php.ini
|
||||
|
||||
# Copy the contents of the web/ directory to /srv
|
||||
COPY web/ /srv
|
||||
|
||||
# Copy the Caddyfile to the container
|
||||
COPY docker/Caddyfile /etc/caddy/Caddyfile
|
||||
|
||||
# Set the default command to start PHP-FPM and Caddy
|
||||
CMD ["sh", "-c", "php-fpm83 && caddy run --config /etc/caddy/Caddyfile"]
|
28
phantom.js
@ -1,28 +0,0 @@
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
address, output, size;
|
||||
|
||||
var input = system.args[1].split(",");
|
||||
|
||||
address = input[0];
|
||||
output = input[1];
|
||||
var vp_w = input[2];
|
||||
var vp_h = input[3];
|
||||
var js = input[4];
|
||||
|
||||
var pageWidth = (vp_w!="")?parseInt(vp_w, 10):1024;
|
||||
var pageHeight = (vp_h!="")?parseInt(vp_h, 10):'auto';
|
||||
page.viewportSize = { width: pageWidth, height: pageHeight };
|
||||
page.settings['javascriptEnabled'] = (js=="no")?false:true;
|
||||
|
||||
page.open(address, function (status) {
|
||||
if (status !== 'success') {
|
||||
console.log('Unable to load the address!');
|
||||
phantom.exit(1);
|
||||
} else {
|
||||
window.setTimeout(function () {
|
||||
page.render(output);
|
||||
phantom.exit();
|
||||
}, 200);
|
||||
}
|
||||
});
|
3
src/config.inc.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
define('URL','http://localhost:8081');
|
16
src/helpers.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
function renderTemplate($templatename,$variables=[],$basepath=ROOT.'/src')
|
||||
{
|
||||
ob_start();
|
||||
if(is_array($variables))
|
||||
extract($variables);
|
||||
if(file_exists($basepath.DS.'templates'.DS.$templatename.'.php'))
|
||||
include($basepath.DS.'templates'.DS.$templatename.'.php');
|
||||
else if(file_exists($basepath.DS.'templates'.DS.$templatename))
|
||||
include($basepath.DS.'templates'.DS.$templatename);
|
||||
$rendered = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $rendered;
|
||||
}
|
@ -17,23 +17,23 @@
|
||||
//
|
||||
|
||||
// if true, will save all cmd queries
|
||||
define(DEBUG,false);
|
||||
define('DEBUG',false);
|
||||
|
||||
define(MAXTIMEOUT,30);
|
||||
define(ONFAILIMAGE, __DIR__.'/img/pagefailed.jpg');
|
||||
define(ONDOMAINFAILIMAGE, __DIR__.'/img/domainfailed.jpg');
|
||||
define('MAXTIMEOUT',30);
|
||||
define('ONFAILIMAGE', __DIR__.'/img/pagefailed.jpg');
|
||||
define('ONDOMAINFAILIMAGE', __DIR__.'/img/domainfailed.jpg');
|
||||
|
||||
//rendering engine: wkhtmltoimage or phantomjs
|
||||
define(RENDERINGENGINE,'wkhtmltoimage');
|
||||
define('RENDERINGENGINE','wkhtmltoimage');
|
||||
|
||||
//location of wkhtmltoimage
|
||||
define(WKHTMLTOIMAGEPATH,'/usr/sbin/wkhtmltoimage');
|
||||
define('WKHTMLTOIMAGEPATH','/usr/sbin/wkhtmltoimage');
|
||||
|
||||
//location of phantomJS
|
||||
define(PHANTOMJSPATH,__DIR__.'/phantomjs');
|
||||
define('PHANTOMJSPATH',__DIR__.'/phantomjs');
|
||||
|
||||
//where shoud we store cached images
|
||||
define(CACHEDIR,__DIR__.'/cache/');
|
||||
define('CACHEDIR',ROOT.DS.'cache'.DS);
|
||||
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
<?php
|
||||
$a = apache_request_headers();
|
||||
define('DOMAIN', $a['Host']);
|
||||
define('CONN', (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "")?'http':'https');
|
||||
|
||||
|
||||
?><!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
@ -18,8 +12,8 @@ define('CONN', (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "")?'http':'ht
|
||||
<!-- Open Graph data -->
|
||||
<meta property="og:title" content="HTTP2PIC | Website screenshot API" />
|
||||
<meta property="og:type" content="article" />
|
||||
<meta property="og:url" content="<?php echo CONN; ?>://<?php echo DOMAIN; ?>" />
|
||||
<meta property="og:image" content="<?php echo CONN; ?>://<?php echo DOMAIN; ?>/api.php?url=<?php echo rawurlencode(CONN.'://'.DOMAIN); ?>&cache=1&viewport=1200x630"/>
|
||||
<meta property="og:url" content="<?=URL?>" />
|
||||
<meta property="og:image" content="<?=URL?>/api.php?url=<?php echo rawurlencode(URL); ?>&cache=1&viewport=1200x630"/>
|
||||
<meta property="og:description" content="An open source website renderer" />
|
||||
<meta property="og:site_name" content="http2pic" />
|
||||
<meta property="article:published_time" content="2015-09-28 00:14:58" />
|
||||
@ -77,7 +71,7 @@ define('CONN', (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "")?'http':'ht
|
||||
<!-- Main Content -->
|
||||
<div class="container">
|
||||
<h2>How the API works</h2>
|
||||
<div class="well"><h2 ><?php echo CONN; ?>://<?php echo DOMAIN; ?>/api.php?<span style="color:#C73C49">[OPTIONS]</span>&url=<span style="color:#1e90ff">[WEBSITE_URL]</span></h2></div><hr/><br/>
|
||||
<div class="well"><h2 ><?=URL?>/api.php?<span style="color:#C73C49">[OPTIONS]</span>&url=<span style="color:#1e90ff">[WEBSITE_URL]</span></h2></div><hr/><br/>
|
||||
<div >
|
||||
<div>
|
||||
<section>
|
||||
@ -124,13 +118,13 @@ define('CONN', (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "")?'http':'ht
|
||||
<td>onfail</td>
|
||||
<td>[url of .jpg]</td>
|
||||
<td>If the page can't be reached, this image will be displayed instead</td>
|
||||
<td><?php echo CONN; ?>://<?php echo DOMAIN; ?>/img/pagefailed.jpg</td>
|
||||
<td><?=URL?>/img/pagefailed.jpg</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ondomainfail</td>
|
||||
<td>[url of .jpg]</td>
|
||||
<td>If the web server can't be reached, this image will be displayed instead</td>
|
||||
<td><?php echo CONN; ?>://<?php echo DOMAIN; ?>/img/domainfailed.jpg</td>
|
||||
<td><?=URL?>/img/domainfailed.jpg</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>cache</td>
|
||||
@ -153,7 +147,7 @@ define('CONN', (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "")?'http':'ht
|
||||
<?php
|
||||
$url = 'http://www.xkcd.com';
|
||||
$query = 'type=jpg&viewport=1200x330&url='.rawurlencode($url);
|
||||
$img="<?php echo CONN; ?>://<?php echo DOMAIN; ?>/api.php?$query";
|
||||
$img="<?=URL?>/api.php?$query";
|
||||
|
||||
echo "<img src='$img' />";
|
||||
?>
|
||||
@ -167,7 +161,7 @@ define('CONN', (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "")?'http':'ht
|
||||
<pre><code class="php">
|
||||
<?php
|
||||
$targeturl = 'http://www.xkcd.com';
|
||||
$url = '<?php echo CONN; ?>://<?php echo DOMAIN; ?>/api.php?url='.rawurlencode($targeturl);
|
||||
$url = '<?=URL?>/api.php?url='.rawurlencode($targeturl);
|
||||
|
||||
$ch = curl_init($url);
|
||||
$fp = fopen('xkcd.jpg', 'wb');
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
include_once('http2pic.class.php');
|
||||
include_once(ROOT.DS.'src'.DS.'http2pic.class.php');
|
||||
|
||||
$url = $_GET['url'];
|
||||
$type = $_GET['type'];
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 169 KiB After Width: | Height: | Size: 169 KiB |
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 200 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
46
web/index.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
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');
|
||||
|
||||
$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)))
|
||||
return false;
|
||||
|
||||
|
||||
switch($url[0])
|
||||
{
|
||||
case 'api':
|
||||
$url = $_GET['url'];
|
||||
$type = $_GET['type'];
|
||||
$timeout = $_GET['timeout'];
|
||||
$viewport = $_GET['viewport'];
|
||||
$js = $_GET['js'];
|
||||
$resizewidth = $_GET['width'];
|
||||
$cache = $_GET['cache'];
|
||||
$onfail = rawurldecode($_GET['onfail']);
|
||||
|
||||
$params = array('url'=>trim($url),
|
||||
'type'=>$type,
|
||||
'timeout'=>$timeout,
|
||||
'viewport'=>$viewport,
|
||||
'js'=>$js,
|
||||
'resizewidth'=>$resizewidth,
|
||||
'cache'=>$cache,
|
||||
'onfail'=>$onfail);
|
||||
|
||||
$http2pic = new http2pic($params);
|
||||
|
||||
break;
|
||||
case 'img':
|
||||
|
||||
break;
|
||||
default:
|
||||
echo renderTemplate('index.html.php');
|
||||
break;
|
||||
}
|