working prototype, many features missing

This commit is contained in:
Chris 2025-01-13 15:58:58 +00:00
parent 028a4b54f4
commit fbe7613f97
4 changed files with 13 additions and 43 deletions

View File

@ -14,7 +14,8 @@ cd ${WORKSPACE_PATH}/src
composer install
echo ' [+] Starting Chrome'
chromedriver --port=4444 &
cd /tmp
nohup chromedriver --port=4444 &
chmod 777 ${WORKSPACE_PATH}/cache

View File

@ -50,7 +50,7 @@
<!-- Page Header -->
<!-- Set your background image for this header on the line below. -->
<header id="intro-header" class="intro-header" style="background-image: url('img/home-bg.jpg')">
<header id="intro-header" class="intro-header" style="background-image: url('/img/home-bg.jpg')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
@ -58,7 +58,7 @@
<h1 style="text-shadow: 0px 0px 12px #000000;">http2pic</h1>
<h2 id="loading"><img src="img/loading.gif" /><br/>Loading..</h2>
<hr class="small">
<span style="text-shadow: 0px 0px 12px #000000;" class="subheading">Give it a try! <input id="showcase_url" type="url" placeholder="eg. http://xkcd.com" />
<span style="text-shadow: 0px 0px 12px #000000;" class="subheading">Give it a try! <input id="showcase_url" type="url" placeholder="eg. http://xkcd.com" value="https://xkcd.com" />
<input id="showcase_button" type="button" value="GO" /></div>
</div>
</div>
@ -71,7 +71,7 @@
<!-- Main Content -->
<div class="container">
<h2>How the API works</h2>
<div class="well"><h2 ><?=URL?>/api.php?<span style="color:#C73C49">[OPTIONS]</span>&amp;url=<span style="color:#1e90ff">[WEBSITE_URL]</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>
<section>
@ -90,12 +90,6 @@
<td>The URL of the webpage you'd like to take a screenshot of. Make sure to encode the URL!</td>
<td>url=http://xkcd.com</td>
</tr>
<tr>
<td>width</td>
<td>WIDTH</td>
<td>Resizes the screenshot to a specified maximum width. Default value is the original size</td>
<td>width=400</td>
</tr>
<tr>
<td>viewport</td>
<td>WIDTHxHEIGHT</td>
@ -104,33 +98,9 @@
</tr>
<tr>
<td>js</td>
<td>yes|no</td>
<td>true|false</td>
<td>Allows you to enable/disable JavaScript in the rendered Website. Default value: yes</td>
<td>js=yes</td>
</tr>
<tr>
<td>type</td>
<td>jpg|png</td>
<td>Sets the output file format of the rendered screenshot. Default value: jpg</td>
<td>type=png</td>
</tr>
<tr>
<td>onfail</td>
<td>[url of .jpg]</td>
<td>If the page can't be reached, this image will be displayed instead</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><?=URL?>/img/domainfailed.jpg</td>
</tr>
<tr>
<td>cache</td>
<td>[any alphanumeric string]</td>
<td>If provided, caches the rendered image (based on the URL) so it loads faster on next request. The same cache id with the same url will return the cached image. Change cache id to re-render</td>
<td>f01d0</td>
<td>js=false</td>
</tr>
</tbody>
</table>
@ -146,11 +116,10 @@
<pre><code class="php">
&lt;?php
$url = 'http://www.xkcd.com';
$query = 'type=jpg&viewport=1200x330&url='.rawurlencode($url);
$img="<?=URL?>/api.php?$query";
$query = 'viewport=1200x330&url='.rawurlencode($url);
$img="<?=URL?>/api/?$query";
echo "&lt;img src='$img' /&gt;";
?&gt;
</code></pre>
</p>
@ -161,7 +130,7 @@
<pre><code class="php">
&lt;?php
$targeturl = 'http://www.xkcd.com';
$url = '<?=URL?>/api.php?url='.rawurlencode($targeturl);
$url = '<?=URL?>/api/?url='.rawurlencode($targeturl);
$ch = curl_init($url);
$fp = fopen('xkcd.jpg', 'wb');
@ -170,7 +139,6 @@
curl_exec($ch);
curl_close($ch);
fclose($fp);
?&gt;
</code></pre>
</p>
</section>

View File

@ -21,7 +21,7 @@ switch($url[0])
{
case 'api':
$target = substr($_SERVER['REQUEST_URI'],5);
if(!$target)
if(!$target || !filter_var($target, FILTER_VALIDATE_URL))
$target = $_REQUEST['url'];
$viewport = $_REQUEST['viewport'];
$js = $_REQUEST['js']=='false'?false:true;

View File

@ -3,7 +3,8 @@ $(function() {
{
$("#showcase_button").attr("disabled","true");
var urlenc = encodeURIComponent(url);
var imageURL = "api.php?js=no&cache=1&viewport=1200x330&url="+urlenc;
var host = location.protocol + '//' + location.host;
var imageURL = host+"/api/?js=false&viewport=1200x330&url="+urlenc;
//$("#intro-header").css('background-image', 'url(\'/img/loading.gif\')');
$("#loading").show();