Difference between revisions of "Commands.pl"

From Organic Design wiki
(Add images to backup)
m
Line 93: Line 93:
 
qx( cp -R /var/www/wiki/images ../$name );
 
qx( cp -R /var/www/wiki/images ../$name );
 
qx( tar -czf ../$name.tgz ../$name );
 
qx( tar -czf ../$name.tgz ../$name );
my @stat = stat( $file );
+
my @stat = stat( "../$name.tgz" );
my $comment = "Wiki Backup: $file ($stat[7] bytes)";
+
my $comment = "Wiki Backup: $name.tgz ($stat[7] bytes)";
 
logAdd $comment;
 
logAdd $comment;
 
wikiLogin( $::wiki, $::peer, $::pwd1 );
 
wikiLogin( $::wiki, $::peer, $::pwd1 );

Revision as of 02:41, 21 February 2006

  1. Get initial IP from local wiki log

$::IP = ; if ( wikiRawPage( $::wiki, $::wikilog ) =~ /^.+to ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/sm ) { $::IP = $1; logAdd "Last IP obtained from Network Log: $::IP"; }

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` }

# ps elsif ($title eq 'env') { $^V =~ m/(.)(.)(.)/; my $ver = ord($1).'.'.ord($2).'.'.ord($3); $cmd =~ /^(.+?)\s+(.+)/; $article = "Environment:\nOS:\t$^O\nPERL:\t$1 ($ver)\nDaemon:\t$2\n\n"; $article .= "Current instances of $::peer:\n"; $article .= qx( ps aux|grep "$::daemon\[:] $::peer" ); }

# fileSync elsif ($title eq 'fileSync') { $article = 'Manually executing fileSync()...'; spawn 'fileSync'; }

# swfCompile elsif ($title eq 'swfCompile') { $article = swfCompile(); }

# 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 "$daemon is restarting using: $::cmd"; killChildren(); exec "sleep 1; $::cmd"; }

elsif ($title eq 'stop') { logAdd "$daemon is stopping"; killChildren(); exit; }

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

return $article; }

  1. Kill all processes related to this peer

sub killChildren { for ( split /\n/, qx( ps x|grep "$::daemon\[:] $::peer" ) ) { if ( /^\s*([0-9]+).+?\d+:\d\d\s*(.+)/ and $1 != $$ ) { qx( kill $1 ); logAdd "Kill $2 ($1)"; } } }

  1. Backup wiki LocalFS cache

sub peerBackup { my $file = '/var/www/wiki/peer.tar.gz'; qx( tar -czf $file ./ ); my @stat = stat( $file ); my $comment = "Peer Backup: $file ($stat[7] bytes)"; logAdd $comment; wikiLogin( $::wiki, $::peer, $::pwd1 ); wikiPageAppend( $::wiki, $::wikilog, "\n*".localtime()." : $comment", $comment ); }

  1. Backup wiki database

sub wikiBackup { my $name = 'od-wiki-db-'.strftime("%Y-%m-%d", localtime); qx( mysqldump wiki -u peer --password=$::pwd1 > ../$name/wiki.sql ); qx( cp -R /var/www/wiki/images ../$name ); qx( tar -czf ../$name.tgz ../$name ); my @stat = stat( "../$name.tgz" ); my $comment = "Wiki Backup: $name.tgz ($stat[7] bytes)"; logAdd $comment; wikiLogin( $::wiki, $::peer, $::pwd1 ); wikiPageAppend( $::wiki, $::wikilog, "\n*".localtime()." : $comment", $comment ); }

  1. Clear sandbox

sub clearSandbox { wikiLogin( $::wiki, $::peer, $::pwd1 ); wikiPageEdit( $::wiki, 'Sandbox', , 'Who left that mess in my sandbox dammit!' ) if wikiRawPage( $::wiki, 'Sandbox' ); }

  1. 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 : ; }

  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( $::wiki, $::peer, $::pwd1 ); wikiPageAppend( $::wiki, $::wikilog, "\n*".localtime()." : $comment", $comment ); } sleep 10; } }