3 # This module impliments the user facing command mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
10 package DXCommandmode;
41 use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase $maxerrors %nothereslug
42 $maxbadcount $msgpolltime $default_pagelth $cmdimportdir);
44 %Cache = (); # cache of dynamically loaded routine's mod times
45 %cmd_cache = (); # cache of short names
46 $errstr = (); # error string from eval
47 %aliases = (); # aliases for (parts of) commands
48 $scriptbase = "$main::root/scripts"; # the place where all users start scripts go
49 $maxerrors = 20; # the maximum number of concurrent errors allowed before disconnection
50 $maxbadcount = 3; # no of bad words allowed before disconnection
51 $msgpolltime = 3600; # the time between polls for new messages
52 $cmdimportdir = "$main::root/cmd_import"; # the base directory for importing command scripts
53 # this does not exist as default, you need to create it manually
56 use vars qw($VERSION $BRANCH);
57 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
58 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
59 $main::build += $VERSION;
60 $main::branch += $BRANCH;
63 # obtain a new connection this is derived from dxchannel
68 my $self = DXChannel::alloc(@_);
70 # routing, this must go out here to prevent race condx
73 my @rout = $main::routeroot->add_user($call, Route::here(1));
75 # ALWAYS output the user
76 my $ref = Route::User::get($call);
77 $main::me->route_pc16($main::mycall, undef, $main::routeroot, $ref) if $ref;
82 # this is how a a connection starts, you get a hello message and the motd with
83 # possibly some other messages asking you to set various things up if you are
84 # new (or nearly new and slacking) user.
88 my ($self, $line, $sort) = @_;
89 my $user = $self->{user};
90 my $call = $self->{call};
91 my $name = $user->{name};
94 my $host = $self->{conn}->{peerhost};
95 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
97 LogDbg('DXCommand', "$call connected from $host");
99 $self->{name} = $name ? $name : $call;
100 $self->send($self->msg('l2',$self->{name}));
101 $self->state('prompt'); # a bit of room for further expansion, passwords etc
102 $self->{priv} = $user->priv || 0;
103 $self->{lang} = $user->lang || $main::lang || 'en';
104 my $pagelth = $user->pagelth;
105 $pagelth = $default_pagelth unless defined $pagelth;
106 $self->{pagelth} = $pagelth;
107 ($self->{width}) = $line =~ /width=(\d+)/; $line =~ s/\s*width=\d+\s*//;
108 $self->{width} = 80 unless $self->{width} && $self->{width} > 80;
109 $self->{consort} = $line; # save the connection type
111 # set some necessary flags on the user if they are connecting
112 $self->{beep} = $user->wantbeep;
113 $self->{ann} = $user->wantann;
114 $self->{wwv} = $user->wantwwv;
115 $self->{wcy} = $user->wantwcy;
116 $self->{talk} = $user->wanttalk;
117 $self->{wx} = $user->wantwx;
118 $self->{dx} = $user->wantdx;
119 $self->{logininfo} = $user->wantlogininfo;
120 $self->{ann_talk} = $user->wantann_talk;
122 $self->{prompt} = $user->prompt if $user->prompt;
124 # sort out new dx spot stuff
125 $user->wantdxcq(0) unless defined $user->{wantdxcq};
126 $user->wantdxitu(0) unless defined $user->{wantdxitu};
127 $user->wantusstate(0) unless defined $user->{wantusstate};
129 # sort out registration
130 if ($main::reqreg == 1) {
131 $self->{registered} = $user->registered;
132 } elsif ($main::reqreg == 2) {
133 $self->{registered} = !$user->registered;
135 $self->{registered} = 1;
139 # decide which motd to send
141 unless ($self->{registered}) {
142 $motd = "${main::motd}_nor_$self->{lang}";
143 $motd = "${main::motd}_nor" unless -e $motd;
145 $motd = "${main::motd}_$self->{lang}" unless $motd && -e $motd;
146 $motd = $main::motd unless $motd && -e $motd;
147 $self->send_file($motd) if -e $motd;
149 # sort out privilege reduction
150 $self->{priv} = 0 if $line =~ /^(ax|te)/ && !$self->conn->{usedpasswd};
154 $nossid =~ s/-\d+$//;
156 $self->{spotsfilter} = Filter::read_in('spots', $call, 0)
157 || Filter::read_in('spots', $nossid, 0)
158 || Filter::read_in('spots', 'user_default', 0);
159 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0)
160 || Filter::read_in('wwv', $nossid, 0)
161 || Filter::read_in('wwv', 'user_default', 0);
162 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0)
163 || Filter::read_in('wcy', $nossid, 0)
164 || Filter::read_in('wcy', 'user_default', 0);
165 $self->{annfilter} = Filter::read_in('ann', $call, 0)
166 || Filter::read_in('ann', $nossid, 0)
167 || Filter::read_in('ann', 'user_default', 0) ;
169 # clean up qra locators
170 my $qra = $user->qra;
171 $qra = undef if ($qra && !DXBearing::is_qra($qra));
173 my $lat = $user->lat;
174 my $long = $user->long;
175 $user->qra(DXBearing::lltoqra($lat, $long)) if (defined $lat && defined $long);
179 my $echo = $user->wantecho;
181 $self->send_now('E', "0");
182 $self->send($self->msg('echow'));
183 $self->conn->echo($echo) if $self->conn->can('echo');
186 $self->tell_login('loginu');
187 $self->tell_buddies('loginb');
189 # do we need to send a forward/opernam?
190 my $lastoper = $user->lastoper || 0;
191 my $homenode = $user->homenode || "";
192 if ($homenode eq $main::mycall && $main::systime >= $lastoper + $DXUser::lastoperinterval) {
193 run_cmd($main::me, "forward/opernam $call");
194 $user->lastoper($main::systime + ((int rand(10)) * 86400));
197 # run a script send the output to the punter
198 my $script = new Script(lc $call) || new Script('user_default');
199 $script->run($self) if $script;
202 my $info = Route::cluster();
203 $self->send("Cluster:$info");
205 # send prompts and things
206 $self->send($self->msg('namee1')) if !$user->name;
207 $self->send($self->msg('qthe1')) if !$user->qth;
208 $self->send($self->msg('qll')) if !$user->qra || (!$user->lat && !$user->long);
209 $self->send($self->msg('hnodee1')) if !$user->qth;
210 $self->send($self->msg('m9')) if DXMsg::for_me($call);
211 $self->lastmsgpoll($main::systime);
216 # This is the normal command prompt driver
225 # save this for them's that need it
226 my $rawline = $cmdline;
228 # remove leading and trailing spaces
229 $cmdline =~ s/^\s*(.*)\s*$/$1/;
231 if ($self->{state} eq 'page') {
232 my $i = $self->{pagelth};
233 my $ref = $self->{pagedata};
236 # abort if we get a line starting in with a
237 if ($cmdline =~ /^a/io) {
242 # send a tranche of data
243 while ($i-- > 0 && @$ref) {
244 my $line = shift @$ref;
245 $line =~ s/\s+$//o; # why am having to do this?
249 # reset state if none or else chuck out an intermediate prompt
251 $tot -= $self->{pagelth};
252 $self->send($self->msg('page', $tot));
254 $self->state('prompt');
256 } elsif ($self->{state} eq 'sysop') {
257 my $passwd = $self->{user}->passwd;
259 my @pw = grep {$_ !~ /\s/} split //, $passwd;
260 my @l = @{$self->{passwd}};
261 my $str = "$pw[$l[0]].*$pw[$l[1]].*$pw[$l[2]].*$pw[$l[3]].*$pw[$l[4]]";
262 if ($cmdline =~ /$str/) {
263 $self->{priv} = $self->{user}->priv;
265 $self->send($self->msg('sorry'));
268 $self->send($self->msg('sorry'));
270 $self->state('prompt');
271 } elsif ($self->{state} eq 'passwd') {
272 my $passwd = $self->{user}->passwd;
273 if ($passwd && $cmdline eq $passwd) {
274 $self->send($self->msg('pw1'));
275 $self->state('passwd1');
277 $self->conn->{echo} = $self->conn->{decho};
278 delete $self->conn->{decho};
279 $self->send($self->msg('sorry'));
280 $self->state('prompt');
282 } elsif ($self->{state} eq 'passwd1') {
283 $self->{passwd} = $cmdline;
284 $self->send($self->msg('pw2'));
285 $self->state('passwd2');
286 } elsif ($self->{state} eq 'passwd2') {
287 if ($cmdline eq $self->{passwd}) {
288 $self->{user}->passwd($cmdline);
289 $self->send($self->msg('pw3'));
291 $self->send($self->msg('pw4'));
293 $self->conn->{echo} = $self->conn->{decho};
294 delete $self->conn->{decho};
295 $self->state('prompt');
296 } elsif ($self->{state} eq 'talk') {
297 if ($cmdline =~ m{^(?:/EX|/ABORT)}i) {
298 for (@{$self->{talklist}}) {
299 $self->send_talks($_, $self->msg('talkend'));
301 $self->state('prompt');
302 delete $self->{talklist};
303 } elsif ($cmdline =~ m|^/+\w+|) {
305 my $sendit = $cmdline =~ s|^/+||;
306 my @in = $self->run_cmd($cmdline);
307 $self->send_ans(@in);
308 if ($sendit && $self->{talklist} && @{$self->{talklist}}) {
309 foreach my $l (@in) {
311 if (@bad = BadWords::check($l)) {
312 $self->badcount(($self->badcount||0) + @bad);
313 LogDbg('DXCommand', "$self->{call} swore: $l with words:" . join(',', @bad) . ")");
315 for (@{$self->{talklist}}) {
316 $self->send_talks($_, $l);
321 $self->send($self->talk_prompt);
322 } elsif ($self->{talklist} && @{$self->{talklist}}) {
323 # send what has been said to whoever is in this person's talk list
325 if (@bad = BadWords::check($cmdline)) {
326 $self->badcount(($self->badcount||0) + @bad);
327 LogDbg('DXCommand', "$self->{call} swore: $cmdline with words:" . join(',', @bad) . ")");
329 for (@{$self->{talklist}}) {
330 $self->send_talks($_, $rawline);
333 $self->send($self->talk_prompt) if $self->{state} eq 'talk';
336 $self->state('prompt');
338 } elsif (my $func = $self->{func}) {
341 if (ref $self->{edit}) {
342 eval { @ans = $self->{edit}->$func($self, $rawline)};
344 eval { @ans = &{$self->{func}}($self, $rawline) };
347 $self->send_ans("Syserr: on stored func $self->{func}", $@);
348 delete $self->{func};
349 $self->state('prompt');
352 $self->send_ans(@ans);
354 $self->send_ans(run_cmd($self, $cmdline));
357 # check for excessive swearing
358 if ($self->{badcount} && $self->{badcount} >= $maxbadcount) {
359 LogDbg('DXCommand', "$self->{call} logged out for excessive swearing");
364 # send a prompt only if we are in a prompt state
365 $self->prompt() if $self->{state} =~ /^prompt/o;
368 # send out the talk messages taking into account vias and connectivity
371 my ($self, $ent, $line) = @_;
373 my ($to, $via) = $ent =~ /(\S+)>(\S+)/;
374 $to = $ent unless $to;
375 my $call = $via ? $via : $to;
376 my $clref = Route::get($call);
377 my $dxchan = $clref->dxchan if $clref;
379 $dxchan->talk($self->{call}, $to, $via, $line);
381 $self->send($self->msg('disc2', $via ? $via : $to));
382 my @l = grep { $_ ne $ent } @{$self->{talklist}};
384 $self->{talklist} = \@l;
386 delete $self->{talklist};
387 $self->state('prompt');
396 for (@{$self->{talklist}}) {
397 my ($to, $via) = /(\S+)>(\S+)/;
401 return $self->msg('talkprompt', join(',', @call));
405 # send a load of stuff to a command user with page prompting
413 if ($self->{pagelth} && @_ > $self->{pagelth}) {
415 for ($i = $self->{pagelth}; $i-- > 0; ) {
417 $line =~ s/\s+$//o; # why am having to do this?
420 $self->{pagedata} = [ @_ ];
421 $self->state('page');
422 $self->send($self->msg('page', scalar @_));
434 # this is the thing that runs the command, it is done like this for the
435 # benefit of remote command execution
441 my $user = $self->{user};
442 my $call = $self->{call};
447 return () if length $cmdline == 0;
450 # split the command line up into parts, the first part is the command
451 my ($cmd, $args) = split /\s+/, $cmdline, 2;
452 $args = "" unless defined $args;
455 # strip out // on command only
457 $cmd =~ s|^/||g; # no leading / either
458 $cmd =~ s|[^-?\w/]||g; # and no funny characters either
462 dbg("cmd: $cmd") if isdbg('command');
464 # alias it if possible
465 my $acmd = CmdAlias::get_cmd($cmd);
467 ($cmd, $args) = split /\s+/, "$acmd $args", 2;
468 $args = "" unless defined $args;
469 dbg("aliased cmd: $cmd $args") if isdbg('command');
472 # first expand out the entry to a command
473 ($path, $fcmd) = search($main::localcmd, $cmd, "pl");
474 ($path, $fcmd) = search($main::cmd, $cmd, "pl") unless $path && $fcmd;
477 dbg("path: $cmd cmd: $fcmd") if isdbg('command');
479 my $package = find_cmd_name($path, $fcmd);
484 dbg("package: $package") if isdbg('command');
485 eval { @ans = &$package($self, $args) };
486 return (DXDebug::shortmess($@)) if $@;
489 dbg("cmd: $cmd not found") if isdbg('command');
490 if (++$self->{errors} > $maxerrors) {
491 $self->send($self->msg('e26'));
495 return ($self->msg('e1'));
502 delete $self->{errors};
504 if (++$self->{errors} > $maxerrors) {
505 $self->send($self->msg('e26'));
510 return map {s/([^\s])\s+$/$1/; $_} @ans;
514 # This is called from inside the main cluster processing loop and is used
515 # for despatching commands that are doing some long processing job
520 my @dxchan = DXChannel::get_all();
523 foreach $dxchan (@dxchan) {
524 next if $dxchan->sort ne 'U';
526 # send a outstanding message prompt if required
527 if ($t >= $dxchan->lastmsgpoll + $msgpolltime) {
528 $dxchan->send($dxchan->msg('m9')) if DXMsg::for_me($dxchan->call);
529 $dxchan->lastmsgpoll($t);
532 # send a prompt if no activity out on this channel
533 if ($t >= $dxchan->t + $main::user_interval) {
534 $dxchan->prompt() if $dxchan->{state} =~ /^prompt/o;
539 while (my ($k, $v) = each %nothereslug) {
540 if ($main::systime >= $v + 300) {
541 delete $nothereslug{$k};
549 # finish up a user context
554 my $call = $self->call;
556 return if $self->{disconnecting}++;
558 delete $self->{senddbg};
560 my $uref = Route::User::get($call);
563 @rout = $main::routeroot->del_user($uref);
564 dbg("B/C PC17 on $main::mycall for: $call") if isdbg('route');
566 # issue a pc17 to everybody interested
567 $main::me->route_pc17($main::mycall, undef, $main::routeroot, $uref);
569 confess "trying to disconnect a non existant user $call";
572 # I was the last node visited
573 $self->user->node($main::mycall);
575 # send info to all logged in thingies
576 $self->tell_login('logoutu');
577 $self->tell_login('logoutb');
579 LogDbg('DXCommand', "$call disconnected");
581 $self->SUPER::disconnect;
585 # short cut to output a prompt
591 my $call = $self->call;
592 my $date = cldate($main::systime);
593 my $time = ztime($main::systime);
594 my $prompt = $self->{prompt} || $self->msg('pr');
596 $call = "($call)" unless $self->here;
597 $prompt =~ s/\%C/$call/g;
598 $prompt =~ s/\%D/$date/g;
599 $prompt =~ s/\%T/$time/g;
600 $prompt =~ s/\%M/$main::mycall/g;
602 $self->send($prompt);
605 # broadcast a message to all users [except those mentioned after buffer]
608 my $pkg = shift; # ignored
609 my $s = shift; # the line to be rebroadcast
611 foreach my $dxchan (DXChannel::get_all()) {
612 next unless $dxchan->{sort} eq 'U'; # only interested in user channels
613 next if grep $dxchan == $_, @_;
614 $dxchan->send($s); # send it
618 # gimme all the users
621 return grep {$_->{sort} eq 'U'} DXChannel::get_all();
624 # run a script for this user
628 my $silent = shift || 0;
633 # search for the command in the cache of short->long form commands
638 my ($path, $short_cmd, $suffix) = @_;
641 # commands are lower case
642 $short_cmd = lc $short_cmd;
643 dbg("command: $path $short_cmd\n") if isdbg('command');
645 # do some checking for funny characters
646 return () if $short_cmd =~ /\/$/;
648 # return immediately if we have it
649 ($apath, $acmd) = split ',', $cmd_cache{$short_cmd} if $cmd_cache{$short_cmd};
650 if ($apath && $acmd) {
651 dbg("cached $short_cmd = ($apath, $acmd)\n") if isdbg('command');
652 return ($apath, $acmd);
656 my @parts = split '/', $short_cmd;
660 while (my $p = shift @parts) {
661 opendir(D, $curdir) or confess "can't open $curdir $!";
665 # if this isn't the last part
668 foreach my $l (sort @ls) {
670 if ((-d "$curdir/$l") && $p eq substr($l, 0, length $p)) {
671 dbg("got dir: $curdir/$l\n") if isdbg('command');
678 # only proceed if we find the directory asked for
679 return () unless $found;
681 foreach my $l (sort @ls) {
683 next unless $l =~ /\.$suffix$/;
684 if ($p eq substr($l, 0, length $p)) {
685 $l =~ s/\.$suffix$//;
686 $dirfn = "" unless $dirfn;
687 $cmd_cache{$short_cmd} = join(',', ($path, "$dirfn$l")); # cache it
688 dbg("got path: $path cmd: $dirfn$l\n") if isdbg('command');
689 return ($path, "$dirfn$l");
698 # clear the command name cache
704 undef *{$_} unless /cmd_cache/;
705 dbg("Undefining cmd $_") if isdbg('command');
712 # the persistant execution of things from the command directories
715 # This allows perl programs to call functions dynamically
717 # This has been nicked directly from the perlembed pages
720 #require Devel::Symdump;
722 sub valid_package_name {
724 $string =~ s|([^A-Za-z0-9_/])|sprintf("_%2x",unpack("C",$1))|eg;
727 return "cmd_$string";
731 # this bit of magic finds a command in the offered directory
735 my $package = valid_package_name($cmdname);
736 my $filename = "$path/$cmdname.pl";
737 my $mtime = -M $filename;
739 # return if we can't find it
741 unless (defined $mtime) {
742 $errstr = DXM::msg('e1');
746 if(defined $Cache{$package}->{mtime} &&$Cache{$package}->{mtime} <= $mtime) {
747 #we have compiled this subroutine already,
748 #it has not been updated on disk, nothing left to do
749 #print STDERR "already compiled $package->handler\n";
753 my $sub = readfilestr($filename);
755 $errstr = "Syserr: can't open '$filename' $!";
759 #wrap the code into a subroutine inside our unique package
760 my $eval = qq( sub $package { $sub } );
763 my @list = split /\n/, $eval;
766 dbg($_ . "\n") if isdbg('eval');
770 # get rid of any existing sub and try to compile the new one
773 if (exists $Cache{$package}) {
774 dbg("Redefining $package") if isdbg('command');
777 dbg("Defining $package") if isdbg('command');
781 $Cache{$package} = {mtime => $mtime };
790 my ($self, $let, $buf) = @_;
791 if ($self->{state} eq 'prompt' || $self->{state} eq 'talk') {
792 if ($self->{enhanced}) {
793 $self->send_later($let, $buf);
802 # send a talk message here
805 my ($self, $from, $to, $via, $line) = @_;
806 $line =~ s/\\5E/\^/g;
807 $self->local_send('T', "$to de $from: $line") if $self->{talk};
808 Log('talk', $to, $from, $via?$via:$main::mycall, $line);
809 # send a 'not here' message if required
810 unless ($self->{here} && $from ne $to) {
811 my $key = "$to$from";
812 unless (exists $nothereslug{$key}) {
814 if (($ref = Route::get($from)) && ($dxchan = $ref->dxchan)) {
815 my $name = $self->user->name || $to;
816 my $s = $self->user->nothere || $dxchan->msg('nothere', $name);
817 $nothereslug{$key} = $main::systime;
818 $dxchan->talk($to, $from, undef, $s);
835 if (!$self->{ann_talk} && $to ne $self->{call}) {
836 my $call = AnnTalk::is_talk_candidate($_[0], $text);
840 if ($self->{annfilter}) {
841 ($filter, $hops) = $self->{annfilter}->it(@_ );
842 return unless $filter;
845 unless ($self->{ann}) {
846 return if $_[0] ne $main::myalias && $_[0] ne $main::mycall;
848 return if $target eq 'SYSOP' && $self->{priv} < 5;
849 my $buf = "$to$target de $_[0]: $text";
851 $buf .= "\a\a" if $self->{beep};
852 $self->local_send($target eq 'WX' ? 'W' : 'N', $buf);
866 return unless grep uc $_ eq $target, @{$self->{user}->{group}};
868 $text =~ s/^\#\d+ //;
869 my $buf = "$target de $_[0]: $text";
871 $buf .= "\a\a" if $self->{beep};
872 $self->local_send('C', $buf);
879 my $t = ztime($_[2]);
881 my $clth = $self->{consort} eq 'local' ? 29 : 30;
882 my $comment = substr $_[3], 0, $clth;
883 $comment .= ' ' x ($clth - length($comment));
884 if ($self->{user}->wantgrid) {
885 my $ref = DXUser->get_current($_[4]);
887 $loc = $ref->qra || '';
888 $loc = ' ' . substr($loc, 0, 4) if $loc;
892 if ($self->{user}->wantdxitu) {
893 $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
894 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8];
895 } elsif ($self->{user}->wantdxcq) {
896 $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
897 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9];
898 } elsif ($self->{user}->wantusstate) {
899 $loc = ' ' . $_[13] if $_[13];
900 $comment = substr($comment, 0, $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12];
903 return sprintf "DX de %-7.7s%11.1f %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
912 return unless $self->{dx};
916 if ($self->{spotsfilter}) {
917 ($filter, $hops) = $self->{spotsfilter}->it(@_ );
918 return unless $filter;
921 dbg('spot: "' . join('","', @_) . '"') if isdbg('dxspot');
924 if ($self->{ve7cc}) {
925 $buf = VE7CC::dx_spot($self, @_);
927 $buf = $self->format_dx_spot(@_);
928 $buf .= "\a\a" if $self->{beep};
932 $self->local_send('X', $buf);
942 return unless $self->{wwv};
944 if ($self->{wwvfilter}) {
945 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_] );
946 return unless $filter;
949 my $buf = "WWV de $_[6] <$_[1]>: SFI=$_[2], A=$_[3], K=$_[4], $_[5]";
950 $buf .= "\a\a" if $self->{beep};
951 $self->local_send('V', $buf);
961 return unless $self->{wcy};
963 if ($self->{wcyfilter}) {
964 ($filter, $hops) = $self->{wcyfilter}->it(@_ );
965 return unless $filter;
968 my $buf = "WCY de $_[10] <$_[1]> : K=$_[4] expK=$_[5] A=$_[3] R=$_[6] SFI=$_[2] SA=$_[7] GMF=$_[8] Au=$_[9]";
969 $buf .= "\a\a" if $self->{beep};
970 $self->local_send('Y', $buf);
973 # broadcast debug stuff to all interested parties
976 my $s = shift; # the line to be rebroadcast
978 foreach my $dxchan (DXChannel::get_all) {
979 next unless $dxchan->{enhanced} && $dxchan->{senddbg};
980 $dxchan->send_later('L', $s);
990 if ($self->state eq 'enterbody') {
991 my $loc = $self->{loc} || confess "local var gone missing" ;
992 if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
994 push @out, &{$loc->{endaction}}($self); # like this for < 5.8.0
996 $self->state('prompt');
997 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
998 push @out, $self->msg('m10');
999 delete $loc->{lines};
1000 delete $self->{loc};
1002 $self->state('prompt');
1004 push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
1005 # i.e. it ain't and end or abort, therefore store the line
1008 confess "Invalid state $self->{state}";
1013 sub store_startup_script
1016 my $loc = $self->{loc} || confess "local var gone missing" ;
1018 my $call = $loc->{call} || confess "callsign gone missing";
1019 confess "lines array gone missing" unless ref $loc->{lines};
1020 my $r = Script::store($call, $loc->{lines});
1023 push @out, $self->msg('m19', $call, $r);
1025 push @out, $self->msg('m20', $call);
1028 push @out, "error opening startup script $call $!";
1033 # Import any commands contained in any files in import_cmd directory
1035 # If the filename has a recogisable callsign as some delimited part
1036 # of it, then this is the user the command will be run as.
1040 # are there any to do in this directory?
1041 return unless -d $cmdimportdir;
1042 unless (opendir(DIR, $cmdimportdir)) {
1043 LogDbg('err', "can\'t open $cmdimportdir $!");
1047 my @names = readdir(DIR);
1050 foreach $name (@names) {
1051 next if $name =~ /^\./;
1053 my $s = Script->new($name, $cmdimportdir);
1055 LogDbg('DXCommand', "Run import cmd file $name");
1056 my @cat = split /[^A-Za-z0-9]+/, $name;
1057 my ($call) = grep {is_callsign(uc $_)} @cat;
1058 $call ||= $main::mycall;
1063 $s->inscript(0); # switch off script checks
1065 if ($call eq $main::mycall) {
1066 @out = $s->run($main::me, 1);
1068 my $dxchan = DXChannel::get($call);
1070 @out = $s->run($dxchan, 1);
1072 my $u = DXUser->get($call);
1074 $dxchan = $main::me;
1075 my $old = $dxchan->{call};
1076 my $priv = $dxchan->{priv};
1077 my $user = $dxchan->{user};
1078 $dxchan->{call} = $call;
1079 $dxchan->{priv} = $u->priv;
1080 $dxchan->{user} = $u;
1081 @out = $s->run($dxchan, 1);
1082 $dxchan->{call} = $call;
1083 $dxchan->{priv} = $priv;
1084 $dxchan->{user} = $user;
1086 LogDbg('err', "Trying to run import cmd for non-existant user $call");
1092 LogDbg('DXCommand', "Import cmd $name/$call: $_");
1095 LogDbg('err', "Failed to open $cmdimportdir/$name $!");
1096 unlink "$cmdimportdir/$name";