X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCommandmode.pm;h=a9777cbf0929b2da31cc5d3b76fa30929e6e55cb;hb=ed2d469812ca5ab82baab7f8b4795660e01ef539;hp=0a42e510852834fede44e4417b7904dcfb45de0a;hpb=cf757a24d80e093d2da598c76bbe3f59fde26902;p=spider.git diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index 0a42e510..a9777cbf 100644 --- a/perl/DXCommandmode.pm +++ b/perl/DXCommandmode.pm @@ -13,6 +13,10 @@ package DXCommandmode; @ISA = qw(DXChannel); +use AnyEvent; +use AnyEvent::Handle; +use AnyEvent::Socket; + use POSIX qw(:math_h); use DXUtil; use DXChannel; @@ -39,7 +43,7 @@ use VE7CC; use DXXml; use strict; -use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors %nothereslug +use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug $maxbadcount $msgpolltime $default_pagelth $cmdimportdir); %Cache = (); # cache of dynamically loaded routine's mod times @@ -47,7 +51,6 @@ use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors %notheresl $errstr = (); # error string from eval %aliases = (); # aliases for (parts of) commands $scriptbase = "$main::root/scripts"; # the place where all users start scripts go -$maxerrors = 20; # the maximum number of concurrent errors allowed before disconnection $maxbadcount = 3; # no of bad words allowed before disconnection $msgpolltime = 3600; # the time between polls for new messages $cmdimportdir = "$main::root/cmd_import"; # the base directory for importing command scripts @@ -66,7 +69,7 @@ sub new my $pkg = shift; my $call = shift; # my @rout = $main::routeroot->add_user($call, Route::here(1)); - DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1]); + DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $self->{conn}->peerhost], ); # ALWAYS output the user my $ref = Route::User::get($call); @@ -90,7 +93,7 @@ sub start my $name = $user->{name}; # log it - my $host = $self->{conn}->{peerhost}; + my $host = $self->{conn}->peerhost; $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport}; $host ||= "unknown"; LogDbg('DXCommand', "$call connected from $host"); @@ -134,23 +137,8 @@ sub start $self->{registered} = 1; } - - # decide which motd to send - my $motd; - unless ($self->{registered}) { - $motd = "${main::motd}_nor_$self->{lang}"; - $motd = "${main::motd}_nor" unless -e $motd; - } - $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd; - $motd = $main::motd unless $motd && -e $motd; - if ($self->conn->{csort} eq 'ax25') { - if ($motd) { - $motd = "${motd}_ax25" if -e "${motd}_ax25"; - } else { - $motd = "${main::motd}_ax25" if -e "${main::motd}_ax25"; - } - } - $self->send_file($motd) if -e $motd; + # send the relevant MOTD + $self->send_motd; # sort out privilege reduction $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd}; @@ -219,7 +207,7 @@ sub start foreach my $call (@{$user->buddies}) { my $ref = Route::User::get($call); if ($ref) { - foreach my $node (@{$ref->parent}) { + foreach my $node ($ref->parents) { $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node)); } } @@ -485,19 +473,6 @@ sub send_ans } } -sub _error_out -{ - my $self = shift; - my $e = shift; - if (++$self->{errors} > $maxerrors) { - $self->send($self->msg('e26')); - $self->disconnect; - return (); - } else { - return ($self->msg($e)); - } -} - # # this is the thing that runs the command, it is done like this for the # benefit of remote command execution @@ -569,7 +544,7 @@ sub run_cmd if ($ok) { delete $self->{errors}; } else { - if (++$self->{errors} > $maxerrors) { + if (++$self->{errors} > $DXChannel::maxerrors) { $self->send($self->msg('e26')); $self->disconnect; return (); @@ -985,7 +960,7 @@ sub format_dx_spot my $comment = substr (($_[3] || ''), 0, $clth); $comment .= ' ' x ($clth - length($comment)); if ($self->{user}->wantgrid) { - my $ref = DXUser->get_current($_[4]); + my $ref = DXUser::get_current($_[4]); if ($ref) { $loc = $ref->qra || ''; $loc = ' ' . substr($loc, 0, 4) if $loc; @@ -1029,7 +1004,7 @@ sub dx_spot } elsif ($self->{gtk}) { my ($dxloc, $byloc); - my $ref = DXUser->get_current($_[4]); + my $ref = DXUser::get_current($_[4]); if ($ref) { $byloc = $ref->qra; $byloc = substr($byloc, 0, 4) if $byloc; @@ -1037,7 +1012,7 @@ sub dx_spot my $spot = $_[1]; $spot =~ s|/\w{1,4}$||; - $ref = DXUser->get_current($spot); + $ref = DXUser::get_current($spot); if ($ref) { $dxloc = $ref->qra; $dxloc = substr($dxloc, 0, 4) if $dxloc; @@ -1205,7 +1180,7 @@ sub import_cmd if ($dxchan) { @out = $s->run($dxchan, 1); } else { - my $u = DXUser->get($call); + my $u = DXUser::get($call); if ($u) { $dxchan = $main::me; my $old = $dxchan->{call}; @@ -1240,5 +1215,72 @@ sub print_find_reply my $sort = $flag == 2 ? "External" : "Local"; $self->send("$sort $target found at $node in $ms ms" ); } + +# send the most relevant motd +sub send_motd +{ + my $self = shift; + my $motd; + + unless ($self->{registered}) { + $motd = "${main::motd}_nor_$self->{lang}"; + $motd = "${main::motd}_nor" unless -e $motd; + } + $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd; + $motd = $main::motd unless $motd && -e $motd; + if ($self->conn->ax25) { + if ($motd) { + $motd = "${motd}_ax25" if -e "${motd}_ax25"; + } else { + $motd = "${main::motd}_ax25" if -e "${main::motd}_ax25"; + } + } + $self->send_file($motd) if -e $motd; +} + +sub http_get +{ + my $self = shift; + my ($host, $uri, $cb) = @_; + + # store results here + my ($response, $header, $body); + + my $handle; + $handle = AnyEvent::Handle->new( + connect => [$host => 'http'], + on_error => sub { + $cb->("HTTP/1.0 500 $!"); + $self->anyevent_del($handle); + $handle->destroy; # explicitly destroy handle + }, + on_eof => sub { + $cb->($response, $header, $body); + $self->anyevent_del($handle); + $handle->destroy; # explicitly destroy handle + } + ); + $self->anyevent_add($handle); + $handle->push_write ("GET $uri HTTP/1.0\015\012\015\012"); + + # now fetch response status line + $handle->push_read (line => sub { + my ($handle, $line) = @_; + $response = $line; + }); + + # then the headers + $handle->push_read (line => "\015\012\015\012", sub { + my ($handle, $line) = @_; + $header = $line; + }); + + # and finally handle any remaining data as body + $handle->on_read (sub { + $body .= $_[0]->rbuf; + $_[0]->rbuf = ""; + }); +} + 1; __END__