Difference between revisions of "Commands.pl"

From Organic Design wiki
(The infamous commands.pl)
 
(bug fix)
Line 1: Line 1:
 
sub command {
 
sub command {
  
my ($title, $args) = $_[0] =~ /(.+?)(\((.+)\))?$/g;
+
my $command = shift;
 +
$command =~ /(.+?)(\((.+)\))?$/;
 +
my ($title, $args) = ( $1, $2 );
 
my $article;
 
my $article;
  
 
# pon/poff
 
# pon/poff
 
if ($title eq 'ppp') { $article = `ifconfig` }
 
if ($title eq 'ppp') { $article = `ifconfig` }
if ($title eq 'pon') { `pon`; $article = `tail -n 1 /var/log/syslog|grep pppd`; }
+
elsif ($title eq 'pon') { `pon`; $article = `tail -n 1 /var/log/syslog|grep pppd`; }
if ($title eq 'poff') { `poff`; $article = `tail -n 3 /var/log/syslog|grep pppd`; }
+
elsif ($title eq 'poff') { `poff`; $article = `tail -n 3 /var/log/syslog|grep pppd`; }
  
 
# syslog
 
# syslog
if ($title eq 'syslog') { $article = `tail -n 50 /var/log/syslog` }
+
elsif ($title eq 'syslog') { $article = `tail -n 50 /var/log/syslog` }
  
 
# Restart
 
# Restart
if ($title eq 'restart') {
+
elsif ($title eq 'restart') {
 
my $closed = 0;
 
my $closed = 0;
 
for ( keys %activePeers ) {
 
for ( keys %activePeers ) {
Line 29: Line 31:
 
}
 
}
  
else { logAdd $article = "Unknown command: $_[0]" }
+
else { logAdd $article = "Unknown command: $command" }
  
 
return $article;
 
return $article;
 
}
 
}

Revision as of 05:05, 9 December 2005

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