From 667e2f7ba3ea873954138eae2aaff04f4cd7f034 Mon Sep 17 00:00:00 2001 From: dream Date: Fri, 14 May 2010 22:01:41 +0000 Subject: [PATCH] Just shutdown GoHE wanted a script to just shutdown i2p, not check for the time left. --- shutdown/just-shutdown-i2p.pl | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 shutdown/just-shutdown-i2p.pl diff --git a/shutdown/just-shutdown-i2p.pl b/shutdown/just-shutdown-i2p.pl new file mode 100755 index 0000000..dd3a088 --- /dev/null +++ b/shutdown/just-shutdown-i2p.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use XML::LibXML; +use XML::Smart; +use XML::LibXML::XPathContext; +require LWP::UserAgent; + +my $mode = 'shutdown'; +for my $arg (@ARGV) { + $mode = 'restart' if $arg =~ /restart/i; +} + +my $ua = LWP::UserAgent->new(agent=>'feepyfeep'); + +sub main { + my $doc = $ua->get("http://localhost:7657/summaryframe.jsp"); + unless ($doc->code==200) { + print "I2P does not seem to be running!\n"; + exit; + } + my $cleaned = XML::Smart->new($doc->content,'html')->data; + my $dom = XML::LibXML->load_xml(string => $cleaned); + my $xpc = XML::LibXML::XPathContext->new($dom); + + my @nonces = $xpc->find('//form[@action="/summaryframe.jsp"]/input[@name="consoleNonce"]/@value'); + die "Too many nonces!" if scalar(@nonces) > 1; + my $nonce = $nonces[0]->string_value; + + $doc = $ua->get("http://localhost:7657/summaryframe.jsp?consoleNonce=$nonce&action=$mode"); + unless ($doc->code==200) { + print "I2P does not seem to be running!\n"; + exit; + } +} + +&main;