3 # This module impliments the user facing command mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
10 package DXCommandmode;
20 use POSIX qw(:math_h);
46 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug
47 $maxbadcount $msgpolltime $default_pagelth $cmdimportdir);
49 %Cache = (); # cache of dynamically loaded routine's mod times
50 %cmd_cache = (); # cache of short names
51 $errstr = (); # error string from eval
52 %aliases = (); # aliases for (parts of) commands
53 $scriptbase = "$main::root/scripts"; # the place where all users start scripts go
54 $maxbadcount = 3; # no of bad words allowed before disconnection
55 $msgpolltime = 3600; # the time between polls for new messages
56 $cmdimportdir = "$main::root/cmd_import"; # the base directory for importing command scripts
57 # this does not exist as default, you need to create it manually
61 # obtain a new connection this is derived from dxchannel
66 my $self = DXChannel::alloc(@_);
68 # routing, this must go out here to prevent race condx
71 # my @rout = $main::routeroot->add_user($call, Route::here(1));
72 DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $self->{conn}->peerhost], );
74 # ALWAYS output the user
75 my $ref = Route::User::get($call);
77 $main::me->route_pc16($main::mycall, undef, $main::routeroot, $ref);
78 $main::me->route_pc92a($main::mycall, undef, $main::routeroot, $ref) unless $DXProt::pc92_slug_changes;
84 # this is how a a connection starts, you get a hello message and the motd with
85 # possibly some other messages asking you to set various things up if you are
86 # new (or nearly new and slacking) user.
90 my ($self, $line, $sort) = @_;
91 my $user = $self->{user};
92 my $call = $self->{call};
93 my $name = $user->{name};
96 my $host = $self->{conn}->peerhost;
97 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
99 LogDbg('DXCommand', "$call connected from $host");
101 $self->{name} = $name ? $name : $call;
102 $self->send($self->msg('l2',$self->{name}));
103 $self->state('prompt'); # a bit of room for further expansion, passwords etc
104 $self->{priv} = $user->priv || 0;
105 $self->{lang} = $user->lang || $main::lang || 'en';
106 my $pagelth = $user->pagelth;
107 $pagelth = $default_pagelth unless defined $pagelth;
108 $self->{pagelth} = $pagelth;
109 ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
110 $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
111 $self->{consort} = $line; # save the connection type
113 # set some necessary flags on the user if they are connecting
114 $self->{beep} = $user->wantbeep;
115 $self->{ann} = $user->wantann;
116 $self->{wwv} = $user->wantwwv;
117 $self->{wcy} = $user->wantwcy;
118 $self->{talk} = $user->wanttalk;
119 $self->{wx} = $user->wantwx;
120 $self->{dx} = $user->wantdx;
121 $self->{logininfo} = $user->wantlogininfo;
122 $self->{ann_talk} = $user->wantann_talk;
124 $self->{prompt} = $user->prompt if $user->prompt;
126 # sort out new dx spot stuff
127 $user->wantdxcq(0) unless defined $user->{wantdxcq};
128 $user->wantdxitu(0) unless defined $user->{wantdxitu};
129 $user->wantusstate(0) unless defined $user->{wantusstate};
131 # sort out registration
132 if ($main::reqreg == 1) {
133 $self->{registered} = $user->registered;
134 } elsif ($main::reqreg == 2) {
135 $self->{registered} = !$user->registered;
137 $self->{registered} = 1;
140 # send the relevant MOTD
143 # sort out privilege reduction
144 $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
148 $nossid =~ s/-\d+$//;
150 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
151 || Filter::read_in('spots', $nossid, 0)
152 || Filter::read_in('spots', 'user_default', 0);
153 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
154 || Filter::read_in('wwv', $nossid, 0)
155 || Filter::read_in('wwv', 'user_default', 0);
156 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
157 || Filter::read_in('wcy', $nossid, 0)
158 || Filter::read_in('wcy', 'user_default', 0);
159 $self->{annfilter} = Filter::read_in('ann', $call, 0)
160 || Filter::read_in('ann', $nossid, 0)
161 || Filter::read_in('ann', 'user_default', 0) ;
163 # clean up qra locators
164 my $qra = $user->qra;
165 $qra = undef if ($qra && !DXBearing::is_qra($qra));
167 my $lat = $user->lat;
168 my $long = $user->long;
169 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
173 my $echo = $user->wantecho;
175 $self->send_now('E', "0");
176 $self->send($self->msg('echow'));
177 $self->conn->echo($echo) if $self->conn->can('echo');
180 $self->tell_login('loginu');
181 $self->tell_buddies('loginb');
183 # do we need to send a forward/opernam?
184 my $lastoper = $user->lastoper || 0;
185 my $homenode = $user->homenode || "";
186 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
187 run_cmd($main::me, "forward/opernam $call");
188 $user->lastoper($main::systime + ((int rand(10)) * 86400));
191 # run a script send the output to the punter
192 my $script = new Script(lc $call) || new Script('user_default');
193 $script->run($self) if $script;
196 my $info = Route::cluster();
197 $self->send("Cluster:$info");
199 # send prompts for qth, name and things
200 $self->send($self->msg('namee1')) if !$user->name;
201 $self->send($self->msg('qthe1')) if !$user->qth;
202 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
203 $self->send($self->msg('hnodee1')) if !$user->qth;
204 $self->send($self->msg('m9')) if DXMsg::for_me($call);
206 # send out any buddy messages for other people that are online
207 foreach my $call (@{$user->buddies}) {
208 my $ref = Route::User::get($call);
210 foreach my $node ($ref->parents) {
211 $self->send($self->msg($node eq $main::mycall ? 'loginb' : 'loginbn', $call, $node));
216 $self->lastmsgpoll($main::systime);
221 # This is the normal command prompt driver
230 # save this for them's that need it
231 my $rawline = $cmdline;
233 # remove leading and trailing spaces
234 $cmdline =~ s/^\s*(.*)\s*$/$1/;
236 if ($self->{state} eq 'page') {
237 my $i = $self->{pagelth};
238 my $ref = $self->{pagedata};
241 # abort if we get a line starting in with a
242 if ($cmdline =~ /^a/io) {
247 # send a tranche of data
248 while ($i-- > 0 && @$ref) {
249 my $line = shift @$ref;
250 $line =~ s/\s+$//o; # why am having to do this?
254 # reset state if none or else chuck out an intermediate prompt
256 $tot -= $self->{pagelth};
257 $self->send($self->msg('page', $tot));
259 $self->state('prompt');
261 } elsif ($self->{state} eq 'sysop') {
262 my $passwd = $self->{user}->passwd;
264 my @pw = grep {$_ !~ /\s/} split //, $passwd;
265 my @l = @{$self->{passwd}};
266 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
267 if ($cmdline =~ /$str/) {
268 $self->{priv} = $self->{user}->priv;
270 $self->send($self->msg('sorry'));
273 $self->send($self->msg('sorry'));
275 $self->state('prompt');
276 } elsif ($self->{state} eq 'passwd') {
277 my $passwd = $self->{user}->passwd;
278 if ($passwd && $cmdline eq $passwd) {
279 $self->send($self->msg('pw1'));
280 $self->state('passwd1');
282 $self->conn->{echo} = $self->conn->{decho};
283 delete $self->conn->{decho};
284 $self->send($self->msg('sorry'));
285 $self->state('prompt');
287 } elsif ($self->{state} eq 'passwd1') {
288 $self->{passwd} = $cmdline;
289 $self->send($self->msg('pw2'));
290 $self->state('passwd2');
291 } elsif ($self->{state} eq 'passwd2') {
292 if ($cmdline eq $self->{passwd}) {
293 $self->{user}->passwd($cmdline);
294 $self->send($self->msg('pw3'));
296 $self->send($self->msg('pw4'));
298 $self->conn->{echo} = $self->conn->{decho};
299 delete $self->conn->{decho};
300 $self->state('prompt');
301 } elsif ($self->{state} eq 'talk' || $self->{state} eq 'chat') {
302 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
303 for (@{$self->{talklist}}) {
304 if ($self->{state} eq 'talk') {
305 $self->send_talks($_, $self->msg('talkend'));
307 $self->local_send('C', $self->msg('chatend', $_));
310 $self->state('prompt');
311 delete $self->{talklist};
312 } elsif ($cmdline =~ m|^/+\w+|) {
314 my $sendit = $cmdline =~ s|^/+||;
315 my @in = $self->run_cmd($cmdline);
316 $self->send_ans(@in);
317 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
318 foreach my $l (@in) {
320 if (@bad = BadWords::check($l)) {
321 $self->badcount(($self->badcount||0) + @bad);
322 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
324 for (@{$self->{talklist}}) {
325 if ($self->{state} eq 'talk') {
326 $self->send_talks($_, $l);
328 send_chats($self, $_, $l)
334 $self->send($self->{state} eq 'talk' ? $self->talk_prompt : $self->chat_prompt);
335 } elsif ($self->{talklist} && @{$self->{talklist}}) {
336 # send what has been said to whoever is in this person's talk list
338 if (@bad = BadWords::check($cmdline)) {
339 $self->badcount(($self->badcount||0) + @bad);
340 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
342 for (@{$self->{talklist}}) {
343 if ($self->{state} eq 'talk') {
344 $self->send_talks($_, $rawline);
346 send_chats($self, $_, $rawline);
350 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
351 $self->send($self->chat_prompt) if $self->{state} eq 'chat';
354 $self->state('prompt');
356 } elsif (my $func = $self->{func}) {
359 if (ref $self->{edit}) {
360 eval { @ans = $self->{edit}->$func($self, $rawline)};
362 eval { @ans = &{$self->{func}}($self, $rawline) };
365 $self->send_ans("Syserr: on stored func $self->{func}", $@);
366 delete $self->{func};
367 $self->state('prompt');
370 $self->send_ans(@ans);
372 $self->send_ans(run_cmd($self, $cmdline));
375 # check for excessive swearing
376 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
377 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
382 # send a prompt only if we are in a prompt state
383 $self->prompt() if $self->{state} =~ /^prompt/o;
386 # send out the talk messages taking into account vias and connectivity
389 my ($self, $ent, $line) = @_;
391 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
392 $to = $ent unless $to;
393 my $call = $via && $via ne '*' ? $via : $to;
394 my $clref = Route::get($call);
395 my $dxchan = $clref->dxchan if $clref;
397 $dxchan->talk($self->{call}, $to, undef, $line);
399 $self->send($self->msg('disc2', $via ? $via : $to));
400 my @l = grep { $_ ne $ent } @{$self->{talklist}};
402 $self->{talklist} = \@l;
404 delete $self->{talklist};
405 $self->state('prompt');
416 my $msgid = DXProt::nextchatmsgid();
417 $text = "#$msgid $text";
418 $main::me->normal(DXProt::pc93($target, $self->{call}, undef, $text));
426 for (@{$self->{talklist}}) {
427 my ($to, $via) = /(\S+)>(\S+)/;
431 return $self->msg($prompt, join(',', @call));
437 return $self->special_prompt('talkprompt');
443 return $self->special_prompt('chatprompt');
447 # send a load of stuff to a command user with page prompting
455 if ($self->{pagelth} && @_ > $self->{pagelth}) {
457 for ($i = $self->{pagelth}; $i-- > 0; ) {
459 $line =~ s/\s+$//o; # why am having to do this?
462 $self->{pagedata} = [ @_ ];
463 $self->state('page');
464 $self->send($self->msg('page', scalar @_));
477 # this is the thing that runs the command, it is done like this for the
478 # benefit of remote command execution
484 my $user = $self->{user};
485 my $call = $self->{call};
489 return () if length $cmdline == 0;
491 # split the command line up into parts, the first part is the command
492 my ($cmd, $args) = split /\s+/, $cmdline, 2;
493 $args = "" unless defined $args;
498 if ($cmd =~ m|^/| || $cmd =~ m|[^-?\w/]|) {
499 LogDbg('DXCommand', "cmd: invalid characters in '$cmd'");
500 return $self->_error_out('e1');
503 # strip out // on command only
508 dbg("cmd: $cmd") if isdbg('command');
510 # alias it if possible
511 my $acmd = CmdAlias::get_cmd($cmd);
513 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
514 $args = "" unless defined $args;
515 dbg("cmd: aliased $cmd $args") if isdbg('command');
518 # first expand out the entry to a command
519 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
520 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
523 dbg("cmd: path $cmd cmd: $fcmd") if isdbg('command');
525 my $package = find_cmd_name($path, $fcmd);
528 if ($package && DXCommandmode->can($package)) {
530 dbg("cmd: package $package") if isdbg('command');
531 eval { @ans = &$package($self, $args) };
532 return (DXDebug::shortmess($@)) if $@;
534 dbg("cmd: $package not present") if isdbg('command');
535 return $self->_error_out('e1');
538 dbg("cmd: $cmd not found") if isdbg('command');
539 return $self->_error_out('e1');
545 delete $self->{errors};
547 if (++$self->{errors} > $DXChannel::maxerrors) {
548 $self->send($self->msg('e26'));
553 return map {s/([^\s])\s+$/$1/; $_} @ans;
557 # This is called from inside the main cluster processing loop and is used
558 # for despatching commands that are doing some long processing job
563 my @dxchan = DXChannel::get_all();
566 foreach $dxchan (@dxchan) {
567 next if $dxchan->sort ne 'U';
569 # send a outstanding message prompt if required
570 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
571 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
572 $dxchan->lastmsgpoll($t);
575 # send a prompt if no activity out on this channel
576 if ($t >= $dxchan->t + $main::user_interval) {
577 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
582 while (my ($k, $v) = each %nothereslug) {
583 if ($main::systime >= $v + 300) {
584 delete $nothereslug{$k};
592 # finish up a user context
597 my $call = $self->call;
599 return if $self->{disconnecting}++;
601 delete $self->{senddbg};
603 my $uref = Route::User::get($call);
606 # @rout = $main::routeroot->del_user($uref);
607 @rout = DXProt::_del_thingy($main::routeroot, [$call, 0]);
609 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
611 # issue a pc17 to everybody interested
612 $main::me->route_pc17($main::mycall, undef, $main::routeroot, $uref);
613 $main::me->route_pc92d($main::mycall, undef, $main::routeroot, $uref) unless $DXProt::pc92_slug_changes;
615 confess "trying to disconnect a non existant user $call";
618 # I was the last node visited
619 $self->user->node($main::mycall);
621 # send info to all logged in thingies
622 $self->tell_login('logoutu');
623 $self->tell_buddies('logoutb');
625 LogDbg('DXCommand', "$call disconnected");
627 $self->SUPER::disconnect;
631 # short cut to output a prompt
638 return if $self->{gtk}; # 'cos prompts are not a concept that applies here
640 my $call = $self->call;
641 my $date = cldate($main::systime);
642 my $time = ztime($main::systime);
643 my $prompt = $self->{prompt} || $self->msg('pr');
645 $call = "($call)" unless $self->here;
646 $prompt =~ s/\%C/$call/g;
647 $prompt =~ s/\%D/$date/g;
648 $prompt =~ s/\%T/$time/g;
649 $prompt =~ s/\%M/$main::mycall/g;
651 $self->send($prompt);
654 # broadcast a message to all users [except those mentioned after buffer]
657 my $pkg = shift; # ignored
658 my $s = shift; # the line to be rebroadcast
660 foreach my $dxchan (DXChannel::get_all()) {
661 next unless $dxchan->{sort} eq 'U'; # only interested in user channels
662 next if grep $dxchan == $_, @_;
663 $dxchan->send($s); # send it
667 # gimme all the users
670 return grep {$_->{sort} eq 'U'} DXChannel::get_all();
673 # run a script for this user
677 my $silent = shift || 0;
682 # search for the command in the cache of short->long form commands
687 my ($path, $short_cmd, $suffix) = @_;
690 # commands are lower case
691 $short_cmd = lc $short_cmd;
692 dbg("command: $path $short_cmd\n") if isdbg('command');
694 # do some checking for funny characters
695 return () if $short_cmd =~ /\/$/;
697 # return immediately if we have it
698 ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
699 if ($apath && $acmd) {
700 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
701 return ($apath, $acmd);
705 my @parts = split '/', $short_cmd;
709 while (my $p = shift @parts) {
710 opendir(D, $curdir) or confess "can't open $curdir $!";
714 # if this isn't the last part
717 foreach my $l (sort @ls) {
719 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
720 dbg("got dir: $curdir/$l\n") if isdbg('command');
727 # only proceed if we find the directory asked for
728 return () unless $found;
730 foreach my $l (sort @ls) {
732 next unless $l =~ /\.$suffix$/;
733 if ($p eq substr($l, 0, length $p)) {
734 $l =~ s/\.$suffix$//;
735 $dirfn = "" unless $dirfn;
736 $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
737 dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
738 return ($path, "$dirfn$l");
747 # clear the command name cache
753 undef *{$_} unless /cmd_cache/;
754 dbg("Undefining cmd $_") if isdbg('command');
761 # the persistant execution of things from the command directories
764 # This allows perl programs to call functions dynamically
766 # This has been nicked directly from the perlembed pages
769 #require Devel::Symdump;
771 sub valid_package_name {
773 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
776 return "cmd_$string";
780 # this bit of magic finds a command in the offered directory
784 my $package = valid_package_name($cmdname);
785 my $filename = "$path/$cmdname.pl";
786 my $mtime = -M $filename;
788 # return if we can't find it
790 unless (defined $mtime) {
791 $errstr = DXM::msg('e1');
795 if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
796 #we have compiled this subroutine already,
797 #it has not been updated on disk, nothing left to do
798 #print STDERR "already compiled $package->handler\n";
802 my $sub = readfilestr($filename);
804 $errstr = "Syserr: can't open '$filename' $!";
808 #wrap the code into a subroutine inside our unique package
809 my $eval = qq( sub $package { $sub } );
812 my @list = split /\n/, $eval;
815 dbg($_ . "\n") if isdbg('eval');
819 # get rid of any existing sub and try to compile the new one
822 if (exists $Cache{$package}) {
823 dbg("find_cmd_name: Redefining $package") if isdbg('command');
826 dbg("find_cmd_name: Defining $package") if isdbg('command');
831 $Cache{$package} = {mtime => $mtime } unless $@;
843 $self->SUPER::send(dd(['cmd',$_]));
846 $self->SUPER::send(@_);
852 my ($self, $let, $buf) = @_;
853 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk' || $self->{state} eq 'chat') {
854 if ($self->{enhanced}) {
855 $self->send_later($let, $buf);
864 # send a talk message here
867 my ($self, $from, $to, $via, $line, $onode) = @_;
868 $line =~ s/\\5E/\^/g;
871 $self->local_send('T', dd(['talk',$to,$from,$via,$line]));
873 $self->local_send('T', "$to de $from: $line");
876 Log('talk', $to, $from, '<' . ($onode || '*'), $line);
877 # send a 'not here' message if required
878 unless ($self->{here} && $from ne $to) {
879 my $key = "$to$from";
880 unless (exists $nothereslug{$key}) {
882 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
883 my $name = $self->user->name || $to;
884 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
885 $nothereslug{$key} = $main::systime;
886 $dxchan->talk($to, $from, undef, $s);
903 if (!$self->{ann_talk} && $to ne $self->{call}) {
904 my $call = AnnTalk::is_talk_candidate($_[0], $text);
908 if ($self->{annfilter}) {
909 ($filter, $hops) = $self->{annfilter}->it(@_ );
910 return unless $filter;
913 unless ($self->{ann}) {
914 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
916 return if $target eq 'SYSOP' && $self->{priv} < 5;
919 $buf = dd(['ann', $to, $target, $text, @_])
921 $buf = "$to$target de $_[0]: $text";
923 $buf .= "\a\a" if $self->{beep};
925 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
939 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
941 $text =~ s/^\#\d+ //;
944 $buf = dd(['chat', $to, $target, $text, @_])
946 $buf = "$target de $_[0]: $text";
948 $buf .= "\a\a" if $self->{beep};
950 $self->local_send('C', $buf);
957 my $t = ztime($_[2]);
959 my $clth = $self->{consort} eq 'local' ? 29 : 30;
960 my $comment = substr (($_[3] || ''), 0, $clth);
961 $comment .= ' ' x ($clth - length($comment));
962 if ($self->{user}->wantgrid) {
963 my $ref = DXUser::get_current($_[4]);
965 $loc = $ref->qra || '';
966 $loc = ' ' . substr($loc, 0, 4) if $loc;
970 if ($self->{user}->wantdxitu) {
971 $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
972 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8];
973 } elsif ($self->{user}->wantdxcq) {
974 $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
975 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9];
976 } elsif ($self->{user}->wantusstate) {
977 $loc = ' ' . $_[13] if $_[13];
978 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12];
981 return sprintf "DX de %-7.7s%11.1f %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
990 return unless $self->{dx};
994 if ($self->{spotsfilter}) {
995 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
996 return unless $filter;
999 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
1002 if ($self->{ve7cc}) {
1003 $buf = VE7CC::dx_spot($self, @_);
1004 } elsif ($self->{gtk}) {
1005 my ($dxloc, $byloc);
1007 my $ref = DXUser::get_current($_[4]);
1010 $byloc = substr($byloc, 0, 4) if $byloc;
1014 $spot =~ s|/\w{1,4}$||;
1015 $ref = DXUser::get_current($spot);
1018 $dxloc = substr($dxloc, 0, 4) if $dxloc;
1020 $buf = dd(['dx', @_, ($dxloc||''), ($byloc||'')]);
1023 $buf = $self->format_dx_spot(@_);
1024 $buf .= "\a\a" if $self->{beep};
1028 $self->local_send('X', $buf);
1035 my $isolate = shift;
1036 my ($filter, $hops);
1038 return unless $self->{wwv};
1040 if ($self->{wwvfilter}) {
1041 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
1042 return unless $filter;
1047 $buf = dd(['wwv', @_])
1049 $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
1050 $buf .= "\a\a" if $self->{beep};
1053 $self->local_send('V', $buf);
1060 my $isolate = shift;
1061 my ($filter, $hops);
1063 return unless $self->{wcy};
1065 if ($self->{wcyfilter}) {
1066 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
1067 return unless $filter;
1072 $buf = dd(['wcy', @_])
1074 $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
1075 $buf .= "\a\a" if $self->{beep};
1077 $self->local_send('Y', $buf);
1080 # broadcast debug stuff to all interested parties
1083 my $s = shift; # the line to be rebroadcast
1085 foreach my $dxchan (DXChannel::get_all) {
1086 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
1087 if ($dxchan->{gtk}) {
1088 $dxchan->send_later('L', dd(['db', $s]));
1090 $dxchan->send_later('L', $s);
1101 if ($self->state eq 'enterbody') {
1102 my $loc = $self->{loc} || confess "local var gone missing" ;
1103 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
1105 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
1107 $self->state('prompt');
1108 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
1109 push @out, $self->msg('m10');
1110 delete $loc->{lines};
1111 delete $self->{loc};
1113 $self->state('prompt');
1115 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1116 # i.e. it ain't and end or abort, therefore store the line
1119 confess "Invalid state $self->{state}";
1124 sub store_startup_script
1127 my $loc = $self->{loc} || confess "local var gone missing" ;
1129 my $call = $loc->{call} || confess "callsign gone missing";
1130 confess "lines array gone missing" unless ref $loc->{lines};
1131 my $r = Script::store($call, $loc->{lines});
1134 push @out, $self->msg('m19', $call, $r);
1136 push @out, $self->msg('m20', $call);
1139 push @out, "error opening startup script $call $!";
1144 # Import any commands contained in any files in import_cmd directory
1146 # If the filename has a recogisable callsign as some delimited part
1147 # of it, then this is the user the command will be run as.
1151 # are there any to do in this directory?
1152 return unless -d $cmdimportdir;
1153 unless (opendir(DIR, $cmdimportdir)) {
1154 LogDbg('err', "can\'t open $cmdimportdir $!");
1158 my @names = readdir(DIR);
1161 foreach $name (@names) {
1162 next if $name =~ /^\./;
1164 my $s = Script->new($name, $cmdimportdir);
1166 LogDbg('DXCommand', "Run import cmd file $name");
1167 my @cat = split /[^A-Za-z0-9]+/, $name;
1168 my ($call) = grep {is_callsign(uc $_)} @cat;
1169 $call ||= $main::mycall;
1174 $s->inscript(0); # switch off script checks
1176 if ($call eq $main::mycall) {
1177 @out = $s->run($main::me, 1);
1179 my $dxchan = DXChannel::get($call);
1181 @out = $s->run($dxchan, 1);
1183 my $u = DXUser::get($call);
1185 $dxchan = $main::me;
1186 my $old = $dxchan->{call};
1187 my $priv = $dxchan->{priv};
1188 my $user = $dxchan->{user};
1189 $dxchan->{call} = $call;
1190 $dxchan->{priv} = $u->priv;
1191 $dxchan->{user} = $u;
1192 @out = $s->run($dxchan, 1);
1193 $dxchan->{call} = $call;
1194 $dxchan->{priv} = $priv;
1195 $dxchan->{user} = $user;
1197 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1203 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1206 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1207 unlink "$cmdimportdir/$name";
1212 sub print_find_reply
1214 my ($self, $node, $target, $flag, $ms) = @_;
1215 my $sort = $flag == 2 ? "External" : "Local";
1216 $self->send("$sort $target found at $node in $ms ms" );
1219 # send the most relevant motd
1225 unless ($self->{registered}) {
1226 $motd = "${main::motd}_nor_$self->{lang}";
1227 $motd = "${main::motd}_nor" unless -e $motd;
1229 $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
1230 $motd = $main::motd unless $motd && -e $motd;
1231 if ($self->conn->ax25) {
1233 $motd = "${motd}_ax25" if -e "${motd}_ax25";
1235 $motd = "${main::motd}_ax25" if -e "${main::motd}_ax25";
1238 $self->send_file($motd) if -e $motd;
1244 my ($host, $uri, $cb) = @_;
1246 # store results here
1247 my ($response, $header, $body);
1250 $handle = AnyEvent::Handle->new(
1251 connect => [$host => 'http'],
1253 $cb->("HTTP/1.0 500 $!");
1254 $self->anyevent_del($handle);
1255 $handle->destroy; # explicitly destroy handle
1258 $cb->($response, $header, $body);
1259 $self->anyevent_del($handle);
1260 $handle->destroy; # explicitly destroy handle
1263 $self->anyevent_add($handle);
1264 $handle->push_write ("GET $uri HTTP/1.0\015\012\015\012");
1266 # now fetch response status line
1267 $handle->push_read (line => sub {
1268 my ($handle, $line) = @_;
1273 $handle->push_read (line => "\015\012\015\012", sub {
1274 my ($handle, $line) = @_;
1278 # and finally handle any remaining data as body
1279 $handle->on_read (sub {
1280 $body .= $_[0]->rbuf;