From: Banana Date: Fri, 30 Nov 2012 11:44:55 +0000 (+0100) Subject: support to use phantomjs. can make screenshots of the bookmark. headless browser. X-Git-Tag: 2.1-alpha-2019-0-29~78 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=8ac9199274d37e85966b6c9f746cbc77ca75360c;p=insipid.git support to use phantomjs. can make screenshots of the bookmark. headless browser. --- diff --git a/lib/Insipid/Main.pm b/lib/Insipid/Main.pm index b4aa552..73e37b9 100755 --- a/lib/Insipid/Main.pm +++ b/lib/Insipid/Main.pm @@ -74,6 +74,8 @@ sub main { my $username = getconfig('username'); my $userpass = getconfig('userpass'); + my $usePhantomjs = getconfig('usePhantomjs'); + my $phantomjsPath = getconfig('phantomPath'); my $redirect = ''; my $et = ''; @@ -408,6 +410,51 @@ IFORM $extra_params +FORM + } + } + elsif(param('op') eq 'screenshot' && $usePhantomjs) { + my $id; + + if (defined(param('id'))) {$id = param('id');} + if (defined(url_param('id'))) {$id = url_param('id');} + + if ($id eq "-1") { + if (defined(param('url'))) { + $id = get_bookmark_id(param('url')); + } + } + my ($url, $title, $description, $access_level, $md5) = get_bookmark($id); + + if (defined(param('create_screenshot')) && param('create_screenshot') eq '1') { + + print '

creating screenshot...

'; + + my $output = `$phantomjsPath --proxy=10.0.1.11:80 ./lib/screen.js $url ./screenshots/$md5.png`; + + if ($? == -1) { + print "failed to execute: $!\n"; + } + elsif ($? & 127) { + printf "child died with signal %d, %s coredump\n", + ($? & 127), ($? & 128) ? 'with' : 'without'; + } + else { + printf "child exited with value %d\n", $? >> 8; + } + } + else { + + print < +

$title : $url

+
+ + + Create screenshot: + + +
FORM } } @@ -460,7 +507,6 @@ DESC javascript:location.href='$site_url/insipid.cgi?op=add_bookmark&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&redirect=true' BLET print ""; - #print ""; print "
"; exit; } @@ -468,7 +514,6 @@ BLET # Configuration and management pages if (param('op') eq 'tags') { tag_operations(); - #print ''; print "
"; exit; } @@ -476,7 +521,6 @@ BLET # show the options if (param('op') eq 'options') { show_options(); - #print ''; print "
"; exit; } @@ -484,10 +528,16 @@ BLET # management if (param('op') eq 'stats') { show_stats(); - #print ''; print "
"; exit; } + + # screenshot overview + if (param('op') eq 'screenshots') { + show_screenshots(); + print "
"; + exit; + } } } @@ -1131,6 +1181,8 @@ sub show_bookmark { $timestamp, $cachetime, $md5 ) = (@_); + my $usePhantomjs = getconfig('usePhantomjs'); + print "
"; print "
  • "; if ($access_level eq 0) { @@ -1183,6 +1235,9 @@ sub show_bookmark { if (!defined($cachetime)) { print ", snapshot"; } + if($usePhantomjs) { + print ", screenshot"; + } print ")
    $description
  • \n"; } @@ -1215,13 +1270,14 @@ sub get_bookmark { $tbl_bookmarks.title, $tbl_bookmarks.description, $tbl_bookmarks.url, - $tbl_bookmarks.access_level + $tbl_bookmarks.access_level, + $tbl_bookmarks.md5 from $tbl_bookmarks where ($tbl_bookmarks.id = ?)"; my $sth = $dbh->prepare($sql); $sth->execute($id); my @r = $sth->fetchrow_array; - return ($r[2], $r[0], $r[1], $r[3]); + return ($r[2], $r[0], $r[1], $r[3], $r[4]); } sub update_bookmark { diff --git a/lib/screen.js b/lib/screen.js new file mode 100644 index 0000000..96a444b --- /dev/null +++ b/lib/screen.js @@ -0,0 +1,32 @@ +/* + * this file is iused by phantomjs (http://phantomjs.org/) to load the given bookmark and save the output to a file + * + * Copyright (C) 2012 jumpin.banana + * + */ +var page = require('webpage').create(), system = require('system'), address, output; +page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'; + +if (system.args.length < 2) { + console.log('Usage: screen.js URL Outputfilename'); + phantom.exit(1); +} +else { + address = system.args[1]; + output = system.args[2]; + + page.open(address, function (status) { + if (status !== 'success') { + //console.log('Unable to access network'); + phantom.exit(1); + } else { + window.setTimeout(function () { + //console.log('rendering'); + + page.render(output); + + phantom.exit(0); + }, 100); + } + }); +} \ No newline at end of file diff --git a/screenshots/.gitignore b/screenshots/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/screenshots/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore