Commands.pl
- TMP
- command() should be generic and declared in wikid.pl
- - can use command_name()
- - 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; }
- 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 ); }
- 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 ); }
- 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 : ; }
- 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; } }



