http://kicken.mine.nu:8008/extras/webshot/add.php `<?php
/************************************************
* Screen Capture script *
* Written by: Keith (aka kicken) *
* Email: keithm@aoeex.com *
* *
* What's it do? *
* This script takes a URL and creates a *
*graphic of the url that can be displayed. *
* *
* How's it do that? *
* It's quite simple, but does require a *
*few things. First, you need some sort of a *
*web browser that can be called up with a *
*defualt URL on the command line and supports *
*javascript. Second, you need to have *
*Imagemagick (specifically the import *
*command). This is used to take a screen *
*capture a few seconds after the web browser *
*has been launched. *
************************************************/
$path_to_browser='/usr/local/bin/mozilla';
$path_to_import='/usr/X11R6/bin/import';
$path_to_output='/home/kicken/gimp/ss';
$path_to_redirect='file:///home/kicken/programming/PHP/ss.html';
$crop='1008x622+0+126';
$format='.jpg';
$quality=60;
$timeout=60;
//// Stop Editing Here!!!!!! //////
function valid_url($url){
if (substr($url, 0, 7) != 'http://'){
return false;
}
$parts=parse_url($url);
if (!isset($parts['port'])){
$parts['port']=80;
}
if (!isset($parts['query'])){
$parts['query']='';
}
else {
$parts['query']='?'.$parts['query'];
}
$fs=@fsockopen($parts['host'], $parts['port']);
if (!$fs){
return false;
}
fputs($fs, "HEAD {$parts['path']}{$parts['query']} HTTP/1.0\n");
fputs($fs, "Host: {$parts['host']}\n");
fputs($fs, "User-agent: Webshot v.01 (http://kicken.mine.nu:8008/extras/webshot/ss.php)\n");
fputs($fs, "Connection: close\n\n");
while ($line=fgets($fs, 2048)){
if (preg_match('/^HTTP\/1.\d (\d{3})/', $line, $matches)){
if ($matches[1] != 200){
return false;
}
}
}
return true;
}
function fixchars($str){
return preg_replace('/[^a-zA-Z0-9_]/', '_', $str);
}
$url=(isset($_SERVER['argv'][1]))?$_SERVER['argv'][1]:(isset($_GET['url'])?$_GET['url']:'about:blank');
if (isset($_SERVER['REMOTE_ADDR']) && $url=='about:blank'){
echo <<<EOP
<html>
<head>
<title>Website Screen Capture</title>
</head>
<body>
<form action="{$_SERVER['PHP_SELF']}" method="get">
What URL would you like to capture? <input type="text" value="" name="url" />
<br />
<input type="submit" value="Get a capture" />
</form>
<p>Or, you can look at all the pages that have <a href='images/'>already been captured</a></p>
</body>
</html>
EOP;
exit;
}
else if ($url=='about:blank'){
echo 'You must specify a URL. Please use the format php -q '.__FILE__.' <url>';
echo chr(10);
exit;
}
if (get_magic_quotes_gpc()){
$url=stripslashes($url);
}
if (!valid_url($url)){
echo 'The URL you entered is not one that will be accepted. ', chr(10);
echo 'Accepted URL\'s return a 200 status code and contain ';
echo 'data.';
exit;
}
include('/home/kicken/bin/mysql_connect.php');
//Check if the URL already exists in the db.
$res=mysql_query('SELECT id FORM ss_que WHERE url=\''.$url.'\'');
if (!$res || mysql_num_rows($res)==0){
mysql_query('INSERT INTO ss_que (url) VALUES ("'.$url.'")');
//Find the number of entries before this one.
$id=mysql_insert_id();
$res=mysql_query('SELECT COUNT(ID) FROM ss_que WHERE ID <= "'.$id.'"');
$num=mysql_result($res, 0, 0);
$wait=$num*60;
echo 'Your screen shot is '.$num.' and should <a href="images/">be ready</a> in about '.$wait.' seconds.';
}
else {
$res=mysql_query('SELECT COUNT(ID) FROM ss_que WHERE ID <= "'.mysql_result($res, 0, 0).'"');
$num=mysql_result($res, 0, 0);
$wait=$num*60;
echo 'That URL has already been registered to be snapped. Approximate wait time: ';
echo $wait.' seconds';
}
?>
`