Difference between revisions of "Commands.pl"

From Organic Design wiki
(Move backup, IP, sandbox etc into here)
(Make IPcheck loop forever checking every 10 sec)
Line 72: Line 72:
 
# update IP with zoneedit.com if changed
 
# update IP with zoneedit.com if changed
 
sub cmdCheckIP {
 
sub cmdCheckIP {
my $i = cmdGetIP;
+
while (1) {
if ( ($i ne '') && ($i ne $::ip) ) {
+
my $i = cmdGetIP;
qx( lynx -source -auth=ADunkley:$::pwd1 http://dynamic.zoneedit.com/auth/dynamic.html?host=www.organicdesign.co.nz );
+
if ( ($i ne '') && ($i ne $::IP) ) {
qx( lynx -source -auth=ADunkley:$::pwd1 http://dynamic.zoneedit.com/auth/dynamic.html?host=organicdesign.co.nz);
+
qx( lynx -source -auth=ADunkley:$::pwd1 http://dynamic.zoneedit.com/auth/dynamic.html?host=www.organicdesign.co.nz );
logAdd $comment = "External IP has changed to $i, updated DNS records.";
+
qx( lynx -source -auth=ADunkley:$::pwd1 http://dynamic.zoneedit.com/auth/dynamic.html?host=organicdesign.co.nz);
$::IP = $i;
+
logAdd my $comment = "External IP has changed to $i, updated DNS records.";
# update the IP log on the wiki
+
$::IP = $i;
wikiLogin( $::OD, 'peer.pl', $::pwd1 );
+
# update the IP log on the wiki
wikiPageAppend( $wiki, 'Network Log', "\n*".localtime()." : $comment", $comment );
+
wikiLogin( $::OD, 'peer.pl', $::pwd1 );
wikiLogout( $::OD );
+
wikiPageAppend( $::OD, 'Network Log', "\n*".localtime()." : $comment", $comment );
 +
wikiLogout( $::OD );
 +
}
 +
else { logAdd 'IP unchanged' }
 +
sleep 10;
 
}
 
}
 
}
 
}

Revision as of 00:41, 5 February 2006

  1. TMP
  2. command() should be generic and declared in wikid.pl
  3. - can use command_name()
  4. - maybe we can execute lambda style now

sub command {

my $command = shift; $command =~ /(.+?)(\((.+)\))?$/; my ($title, $args) = ( $1, $2 ); my $article;

# pon/poff if ($title eq 'ppp') { $article = `ifconfig` } elsif ($title eq 'pon') { `pon`; $article = `tail -n 1 /var/log/syslog|grep pppd`; } elsif ($title eq 'poff') { `poff`; $article = `tail -n 3 /var/log/syslog|grep pppd`; }

# syslog elsif ($title eq 'syslog') { $article = `tail -n 50 /var/log/syslog` }

# peer log elsif ($title eq 'peerlog') { $article = qx( tail -n 50 $peer.log ) }

# reboot elsif ($title eq 'reboot') { $article = `shutdown -r now` }

# shutdown elsif ($title eq 'shutdown') { $article = `halt` }

# Restart # - For some reason it fucks up if it doesn't wait for a minute # - 2005-12-09 tried closing handles and server->shutdown(SHUT_RDWR) but made no difference elsif ($title eq 'restart') { logAdd "Restarting $daemon using: $cmd"; exec "sleep 60; $cmd"; }

# Version elsif ($title eq 'version') { $article = "OS: $^O\nPERL: $ver\nDaemon: $cmd\n" }

else { logAdd $article = "Unknown command: $command" }

return $article; }

  1. Backup wiki database at 2am

sub cmdBackup { my $file = 'od-wiki-db-'.strftime("%Y-%m-%d", localtime).'.gz'; qx( mysqldump wiki -u peer --password=$::pwd1 | gzip > $file ); my @stat = stat( $file ); my $comment = "Wiki Backup: $file ($stat[7] bytes)"; logAdd $comment; wikiLogin( $::OD, 'peer.pl', $::pwd1 ); wikiPageAppend( $::OD, 'Network Log', "\n*".localtime()." : $comment", $comment ); wikiLogout( $::OD ); }

  1. Clear sandbox at 3am

sub cmdClearSandbox { wikiLogin( $::OD, 'peer.pl', $::pwd1 ); wikiPageEdit( $::OD, 'Sandbox', , 'Who left that mess in my sandbox dammit!' ) if wikiRawPage( $::OD, 'Sandbox' ); wikiLogout( $::OD ); }

  1. Return IP address according to router

sub cmdGetIP { my $i = qx( lynx -source -auth=admin:$::pwd2 http://192.168.0.254/wancfg.cmd?action=view ); return $i = ($i =~ /([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/) ? $1 : ; }

  1. update IP with zoneedit.com if changed

sub cmdCheckIP { while (1) { my $i = cmdGetIP; if ( ($i ne ) && ($i ne $::IP) ) { qx( lynx -source -auth=ADunkley:$::pwd1 http://dynamic.zoneedit.com/auth/dynamic.html?host=www.organicdesign.co.nz ); qx( lynx -source -auth=ADunkley:$::pwd1 http://dynamic.zoneedit.com/auth/dynamic.html?host=organicdesign.co.nz); logAdd my $comment = "External IP has changed to $i, updated DNS records."; $::IP = $i; # update the IP log on the wiki wikiLogin( $::OD, 'peer.pl', $::pwd1 ); wikiPageAppend( $::OD, 'Network Log', "\n*".localtime()." : $comment", $comment ); wikiLogout( $::OD ); } else { logAdd 'IP unchanged' } sleep 10; } }