Difference between revisions of "Commands.pl"
(Make IPcheck loop forever checking every 10 sec) |
(update) |
||
| Line 46: | Line 46: | ||
# Backup wiki database at 2am | # Backup wiki database at 2am | ||
| − | sub | + | sub wikiBackup { |
my $file = 'od-wiki-db-'.strftime("%Y-%m-%d", localtime).'.gz'; | my $file = 'od-wiki-db-'.strftime("%Y-%m-%d", localtime).'.gz'; | ||
qx( mysqldump wiki -u peer --password=$::pwd1 | gzip > $file ); | qx( mysqldump wiki -u peer --password=$::pwd1 | gzip > $file ); | ||
| Line 52: | Line 52: | ||
my $comment = "Wiki Backup: $file ($stat[7] bytes)"; | my $comment = "Wiki Backup: $file ($stat[7] bytes)"; | ||
logAdd $comment; | logAdd $comment; | ||
| − | wikiLogin( $::OD, | + | wikiLogin( $::OD, $::peer, $::pwd1 ); |
| − | wikiPageAppend( $::OD, | + | wikiPageAppend( $::OD, $::wikilog, "\n*".localtime()." : $comment", $comment ); |
wikiLogout( $::OD ); | wikiLogout( $::OD ); | ||
} | } | ||
# Clear sandbox at 3am | # Clear sandbox at 3am | ||
| − | sub | + | sub clearSandbox { |
| − | wikiLogin( $::OD, | + | wikiLogin( $::OD, $::peer, $::pwd1 ); |
wikiPageEdit( $::OD, 'Sandbox', '', 'Who left that mess in my sandbox dammit!' ) if wikiRawPage( $::OD, 'Sandbox' ); | wikiPageEdit( $::OD, 'Sandbox', '', 'Who left that mess in my sandbox dammit!' ) if wikiRawPage( $::OD, 'Sandbox' ); | ||
wikiLogout( $::OD ); | wikiLogout( $::OD ); | ||
| Line 65: | Line 65: | ||
# Return IP address according to router | # Return IP address according to router | ||
| − | sub | + | sub getIP { |
my $i = qx( lynx -source -auth=admin:$::pwd2 http://192.168.0.254/wancfg.cmd?action=view ); | 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 : ''; | return $i = ($i =~ /([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/) ? $1 : ''; | ||
| Line 71: | Line 71: | ||
# update IP with zoneedit.com if changed | # update IP with zoneedit.com if changed | ||
| − | sub | + | sub checkIP { |
while (1) { | while (1) { | ||
| − | my $i = | + | my $i = getIP; |
if ( ($i ne '') && ($i ne $::IP) ) { | 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=www.organicdesign.co.nz ); | ||
| Line 80: | Line 80: | ||
$::IP = $i; | $::IP = $i; | ||
# update the IP log on the wiki | # update the IP log on the wiki | ||
| − | wikiLogin( $::OD, | + | wikiLogin( $::OD, $::peer, $::pwd1 ); |
| − | wikiPageAppend( $::OD, | + | wikiPageAppend( $::OD, $::wikilog, "\n*".localtime()." : $comment", $comment ); |
wikiLogout( $::OD ); | wikiLogout( $::OD ); | ||
} | } | ||
Revision as of 07:32, 5 February 2006
- 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 wikiBackup { 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, $::pwd1 ); wikiPageAppend( $::OD, $::wikilog, "\n*".localtime()." : $comment", $comment ); wikiLogout( $::OD ); }
- Clear sandbox at 3am
sub clearSandbox { wikiLogin( $::OD, $::peer, $::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 getIP { 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 checkIP { while (1) { my $i = getIP; 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, $::pwd1 ); wikiPageAppend( $::OD, $::wikilog, "\n*".localtime()." : $comment", $comment ); wikiLogout( $::OD ); } else { logAdd 'IP unchanged' } sleep 10; } }



