X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCommandmode.pm;h=dfaaa3e34887454ffe047c14b9a397fb70aa27e3;hb=766014807e2521cc60a219c6eda5b49d13ffc70f;hp=46d2b1d38bd4d450f0f95b0fbda2e7b37281f274;hpb=8e14149148baba63ce5ae2b95aacda8ab6dd0d87;p=spider.git diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index 46d2b1d3..dfaaa3e3 100644 --- a/perl/DXCommandmode.pm +++ b/perl/DXCommandmode.pm @@ -50,6 +50,7 @@ use DXCIDR; use strict; use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers + $maxcmdlth ); %Cache = (); # cache of dynamically loaded routine's mod times @@ -64,6 +65,8 @@ $cmdimportdir = "$main::root/cmd_import"; # the base directory for importing com $users = 0; # no of users on this node currently $maxusers = 0; # max no users on this node for this run +$maxcmdlth = 512; # max length of incoming cmd line (including the command and any arguments + # # obtain a new connection this is derived from dxchannel # @@ -249,6 +252,7 @@ sub start } $self->lastmsgpoll($main::systime); + $self->{user_interval} = $self->user->user_interval || $main::user_interval; # allow user to change idle time between prompts $self->prompt; } @@ -345,22 +349,26 @@ sub normal } $self->state('prompt'); delete $self->{talklist}; - } elsif ($cmdline =~ m|^/+\w+|) { + } elsif ($cmdline =~ m|^[/\w\\]+|) { $cmdline =~ s|^/||; my $sendit = $cmdline =~ s|^/+||; if (@bad = BadWords::check($cmdline)) { $self->badcount(($self->badcount||0) + @bad); LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with badwords: '" . join(',', @bad) . "'"); } else { - my @in = $self->run_cmd($cmdline); - $self->send_ans(@in); - if ($sendit && $self->{talklist} && @{$self->{talklist}}) { - foreach my $l (@in) { - for (@{$self->{talklist}}) { - if ($self->{state} eq 'talk') { - $self->send_talks($_, $l); - } else { - send_chats($self, $_, $l) + my @cmd = split /\s*\\n\s*/, $cmdline; + foreach my $l (@cmd) { + my @in = $self->run_cmd($l); + $self->send_ans(@in); + if ($sendit && $self->{talklist} && @{$self->{talklist}}) { + foreach my $l (@in) { + for (@{$self->{talklist}}) { + if ($self->{state} eq 'talk') { + $self->send_talks($_, $l); + } + else { + send_chats($self, $_, $l) + } } } } @@ -406,8 +414,11 @@ sub normal # if (@bad = BadWords::check($cmdline)) { # $self->badcount(($self->badcount||0) + @bad); # LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with badwords: '" . join(',', @bad) . "'"); -# } else { - $self->send_ans(run_cmd($self, $cmdline)); + # } else { + my @cmd = split /\s*\\n\s*/, $cmdline; + foreach my $l (@cmd) { + $self->send_ans(run_cmd($self, $l)); + } # } } @@ -534,15 +545,15 @@ sub run_cmd if ($cmd) { - # check cmd - if ($cmd =~ m|^/| || $cmd =~ m|[^-?\w/]|) { + # strip out // on command only + $cmd =~ s|//+|/|g; + + # check for length of whole command line and any invalid characters + if (length $cmdline > $maxcmdlth || $cmd =~ m|\.| || $cmd !~ m|^\w+(?:/\w+){0,1}(?:/\d+)?$|) { LogDbg('DXCommand', "cmd: $self->{call} - invalid characters in '$cmd'"); - return $self->_error_out('e1'); + return $self->_error_out('e40'); } - # strip out // on command only - $cmd =~ s|//|/|g; - my ($path, $fcmd); dbg("cmd: $cmd") if isdbg('command'); @@ -585,7 +596,7 @@ sub run_cmd return $self->_error_out('e1'); } } else { - dbg("cmd: $cmd not found") if isdbg('command'); + LogDbg('DXCommand', "$self->{call} cmd: '$cmd' not found"); return $self->_error_out('e1'); } } @@ -594,11 +605,11 @@ sub run_cmd if ($ok) { delete $self->{errors}; } else { - if (++$self->{errors} > $DXChannel::maxerrors) { + if ($self != $main::me && ++$self->{errors} > $DXChannel::maxerrors) { $self->send($self->msg('e26')); $self->disconnect; return (); - } + } } return map {s/([^\s])\s+$/$1/; $_} @ans; } @@ -624,7 +635,7 @@ sub process } # send a prompt if no activity out on this channel - if ($t >= $dxchan->t + $main::user_interval) { + if ($t >= $dxchan->t + $dxchan->{user_interval}) { $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o; $dxchan->t($t); } @@ -878,7 +889,6 @@ sub find_cmd_name { if (isdbg('eval')) { my @list = split /\n/, $eval; - my $line; for (@list) { dbg($_ . "\n") if isdbg('eval'); }