X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCommandmode.pm;h=6e6b176ea928e4b3be8d5b51aa90351a12c0d7d2;hb=cee0bfe61e83c87a6ded04034cc57789a0950f9e;hp=dfaaa3e34887454ffe047c14b9a397fb70aa27e3;hpb=766014807e2521cc60a219c6eda5b49d13ffc70f;p=spider.git diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index dfaaa3e3..6e6b176e 100644 --- a/perl/DXCommandmode.pm +++ b/perl/DXCommandmode.pm @@ -50,7 +50,7 @@ use DXCIDR; use strict; use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers - $maxcmdlth + $maxcmdlth $maxcmdcount $cmdinterval ); %Cache = (); # cache of dynamically loaded routine's mod times @@ -64,8 +64,9 @@ $cmdimportdir = "$main::root/cmd_import"; # the base directory for importing com # this does not exist as default, you need to create it manually $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 +$maxcmdcount = 27; # max no cmds entering $cmdinterval seconds +$cmdinterval = 20; # if user enters more than $maxcmdcount in $cmdinterval seconds, they are logged off # # obtain a new connection this is derived from dxchannel @@ -174,25 +175,12 @@ sub start # sort out privilege reduction $self->{priv} = 0 unless $self->{hostname} eq '127.0.0.1' || $self->conn->peerhost eq '127.0.0.1' || $self->{hostname} eq '::1' || $self->conn->{usedpasswd}; - # get the filters - my $nossid = $call; - $nossid =~ s/-\d+$//; - $self->{spotsfilter} = Filter::read_in('spots', $call, 0) - || Filter::read_in('spots', $nossid, 0) - || Filter::read_in('spots', 'user_default', 0); - $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) - || Filter::read_in('wwv', $nossid, 0) - || Filter::read_in('wwv', 'user_default', 0); - $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) - || Filter::read_in('wcy', $nossid, 0) - || Filter::read_in('wcy', 'user_default', 0); - $self->{annfilter} = Filter::read_in('ann', $call, 0) - || Filter::read_in('ann', $nossid, 0) - || Filter::read_in('ann', 'user_default', 0) ; - $self->{rbnfilter} = Filter::read_in('rbn', $call, 0) - || Filter::read_in('rbn', $nossid, 0) - || Filter::read_in('rbn', 'user_default', 0); + Filter::load_dxchan($self, 'spots', 0); + Filter::load_dxchan($self, 'wwv', 0); + Filter::load_dxchan($self, 'wcy', 0); + Filter::load_dxchan($self, 'ann', 0); + Filter::load_dxchan($self, 'rbn', 0); # clean up qra locators my $qra = $user->qra; @@ -254,6 +242,10 @@ 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; + + $self->{cmdintstart} = 0; # set when systime > this + cmdinterval and a command entered, cmdcount set to 0 + $self->{cmdcount} = 0; # incremented on a coming in. If this value > $maxcmdcount, disconnect + } # @@ -343,6 +335,8 @@ sub normal for (@{$self->{talklist}}) { if ($self->{state} eq 'talk') { $self->send_talks($_, $self->msg('talkend')); + } elsif ($self->{state} eq 'chat') { + $self->send_talks($_, $self->msg('chatend')); } else { $self->local_send('C', $self->msg('chatend', $_)); } @@ -351,15 +345,18 @@ sub normal delete $self->{talklist}; } elsif ($cmdline =~ m|^[/\w\\]+|) { $cmdline =~ s|^/||; - my $sendit = $cmdline =~ s|^/+||; + my $sendit = ($cmdline = unpad($cmdline)); if (@bad = BadWords::check($cmdline)) { $self->badcount(($self->badcount||0) + @bad); LogDbg('DXCommand', "$self->{call} swore: '$cmdline' with badwords: '" . join(',', @bad) . "'"); } else { - my @cmd = split /\s*\\n\s*/, $cmdline; - foreach my $l (@cmd) { - my @in = $self->run_cmd($l); + my $c; + my @in; + if (($c) = $cmdline =~ /^cmd\s+(.*)$/) { + @in = $self->run_cmd($c); $self->send_ans(@in); + } else { + push @in, $cmdline; if ($sendit && $self->{talklist} && @{$self->{talklist}}) { foreach my $l (@in) { for (@{$self->{talklist}}) { @@ -417,6 +414,20 @@ sub normal # } else { my @cmd = split /\s*\\n\s*/, $cmdline; foreach my $l (@cmd) { + + # rate limiting code + + if (($self->{cmdintstart} + $cmdinterval <= $main::systime) || $self->{inscript}) { + $self->{cmdintstart} = $main::systime; + $self->{cmdcount} = 1; + dbg("$self->{call} started cmdinterval") if isdbg('cmdcount'); + } else { + if (++$self->{cmdcount} > $maxcmdcount) { + LogDbg('baduser', qq{User $self->{call} sent $self->{cmdcount} (>= $maxcmdcount) cmds in $cmdinterval seconds starting at } . atime($self->{cmdintstart}) . ", disconnected" ); + $self->disconnect; + } + dbg("$self->{call} cmd: '$l' cmdcount = $self->{cmdcount} in $cmdinterval secs") if isdbg('cmdcount'); + } $self->send_ans(run_cmd($self, $l)); } # }