Commands.pl

From Organic Design wiki
Revision as of 05:05, 9 December 2005 by Nad (talk | contribs) (bug fix)

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

# Restart elsif ($title eq 'restart') { my $closed = 0; for ( keys %activePeers ) { my $handle = $activePeers{$_}{handle}; if ( defined $handle ) { $closed++; $select->remove($handle); $handle->close(); } } $server->shutdown(SHUT_RDWR); logAdd "$closed handles closed."; logAdd "Restarting $daemon using: $cmd"; exec "sleep 60; $cmd"; }

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

return $article; }