#!/usr/bin/perl use LWP; use URI; ### Commands for tunnel creation and managing ### $sudocmd="sudo -u root screen -d -m"; $sshcmd="ssh -q -l -p -L:3129:: -2 -i "; $checkcmd="ps -ef | grep \"$sshcmd\" | grep -v grep | grep -v SCREEN | wc -l"; ################################################ $|=1; while (<>) { @X = split; $url = $X[0]; if ($url =~ /^http:\/\/REMOTE\.URL\.HERE/) { $rv = `$checkcmd`; if ($rv == 0) { system("$sudocmd $sshcmd >/dev/null & "); my $browser = LWP::UserAgent->new; my $url = URI->new( 'http://' ); $url->port( '3129' ); my $response = $browser->get($url); $count = 1; while (($count<30) && ($response->status_line != "400 Bad Request" )) { sleep 2; $response = $browser->get($url); $count++; } if ($count>=30) { print "oops! Can't bring up ssh tunnel.

Please check."; exit;} else { print "302:http://\n"; } }; system("rm -f /tmp/vpnactive"); system("touch /tmp/vpnactive"); } print "$url\n"; }