3 # This module impliments the protocal mode for a dx cluster
5 # Copyright (c) 1998 Dirk Koopman G1TLH
40 use vars qw($VERSION $BRANCH);
41 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
42 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
43 $main::build += $VERSION;
44 $main::branch += $BRANCH;
46 use vars qw($pc11_max_age $pc23_max_age $last_pc50 $eph_restime $eph_info_restime $eph_pc34_restime
47 $last_hour $last10 %eph %pings %rcmds $ann_to_talk
48 $pingint $obscount %pc19list $chatdupeage $chatimportfn
49 $investigation_int $pc19_version $myprot_version
50 %nodehops $baddx $badspotter $badnode $censorpc $rspfcheck
51 $allowzero $decode_dk0wcy $send_opernam @checklist
52 $eph_pc15_restime $pc92_update_period $last_pc92_update
55 $pc11_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc11
56 $pc23_max_age = 1*3600; # the maximum age for an incoming 'real-time' pc23
58 $last_hour = time; # last time I did an hourly periodic update
59 %rcmds = (); # outstanding rcmd requests outbound
60 %nodehops = (); # node specific hop control
61 %pc19list = (); # list of outstanding PC19s that haven't had PC16s on them
63 $censorpc = 1; # Do a BadWords::check on text fields and reject things
64 # loads of 'bad things'
65 $baddx = new DXHash "baddx";
66 $badspotter = new DXHash "badspotter";
67 $badnode = new DXHash "badnode";
68 $last10 = $last_pc50 = time;
72 $eph_info_restime = 60*60;
73 $eph_pc15_restime = 6*60;
74 $eph_pc34_restime = 30;
77 $chatdupeage = 20 * 60 * 60;
78 $chatimportfn = "$main::root/chat_import";
79 $investigation_int = 12*60*60; # time between checks to see if we can see this node
80 $pc19_version = 5466; # the visible version no for outgoing PC19s generated from pc59
81 $pc92_update_period = 60*60; # the period between PC92 C updates
82 $last_pc92_update = time; # the last time a PC92 config update
87 [ qw(i c c m bp bc c) ], # pc10
88 [ qw(i f m d t m c c h) ], # pc11
89 [ qw(i c bm m bm bm p h) ], # pc12
93 undef , # pc16 has to be validated manually
94 [ qw(i c c h) ], # pc17
96 undef , # pc19 has to be validated manually
97 undef , # pc20 no validation
98 [ qw(i c m h) ], # pc21
99 undef , # pc22 no validation
100 [ qw(i d n n n n m c c h) ], # pc23
101 [ qw(i c p h) ], # pc24
102 [ qw(i c c n n) ], # pc25
103 [ qw(i f m d t m c c bc) ], # pc26
104 [ qw(i d n n n n m c c bc) ], # pc27
105 [ qw(i c c m c d t p m bp n p bp bc) ], # pc28
106 [ qw(i c c n m) ], # pc29
107 [ qw(i c c n) ], # pc30
108 [ qw(i c c n) ], # pc31
109 [ qw(i c c n) ], # pc32
110 [ qw(i c c n) ], # pc33
111 [ qw(i c c m) ], # pc34
112 [ qw(i c c m) ], # pc35
113 [ qw(i c c m) ], # pc36
114 [ qw(i c c n m) ], # pc37
115 undef, # pc38 not interested
116 [ qw(i c m) ], # pc39
117 [ qw(i c c m p n) ], # pc40
118 [ qw(i c n m h) ], # pc41
119 [ qw(i c c n) ], # pc42
120 undef, # pc43 don't handle it
121 [ qw(i c c n m m c) ], # pc44
122 [ qw(i c c n m) ], # pc45
123 [ qw(i c c n) ], # pc46
126 [ qw(i c m h) ], # pc49
127 [ qw(i c n h) ], # pc50
128 [ qw(i c c n) ], # pc51
150 [ qw(i d n n n n n n m m m c c h) ], # pc73
161 [ qw(i c c c m) ], # pc84
162 [ qw(i c c c m) ], # pc85
167 [ qw(i c n) ], # pc90
170 # use the entry in the check list to check the field list presented
171 # return OK if line NOT in check list (for now)
176 return 0 if $n < 0 || $n > @checklist;
177 my $ref = $checklist[$n];
178 return 0 unless ref $ref;
181 for ($i = 1; $i < @$ref; $i++) {
182 my ($blank, $act) = $$ref[$i] =~ /^(b?)(\w)$/;
183 return 0 unless $act;
184 next if $blank && $_[$i] =~ /^[ \*]$/;
186 return $i unless is_callsign($_[$i]);
187 } elsif ($act eq 'i') {
189 } elsif ($act eq 'm') {
190 return $i unless is_pctext($_[$i]);
191 } elsif ($act eq 'p') {
192 return $i unless is_pcflag($_[$i]);
193 } elsif ($act eq 'f') {
194 return $i unless is_freq($_[$i]);
195 } elsif ($act eq 'n') {
196 return $i unless $_[$i] =~ /^[\d ]+$/;
197 } elsif ($act eq 'h') {
198 return $i unless $_[$i] =~ /^H\d\d?$/;
199 } elsif ($act eq 'd') {
200 return $i unless $_[$i] =~ /^\s*\d+-\w\w\w-[12][90]\d\d$/;
201 } elsif ($act eq 't') {
202 return $i unless $_[$i] =~ /^[012]\d[012345]\dZ$/;
210 do "$main::data/hop_table.pl" if -e "$main::data/hop_table.pl";
213 my $user = DXUser->get($main::mycall);
214 die "User $main::mycall not setup or disappeared RTFM" unless $user;
216 $myprot_version += $main::version*100;
217 $main::me = DXProt->new($main::mycall, 0, $user);
218 $main::me->{here} = 1;
219 $main::me->{state} = "indifferent";
220 $main::me->{sort} = 'S'; # S for spider
221 $main::me->{priv} = 9;
222 $main::me->{metric} = 0;
223 $main::me->{pingave} = 0;
224 $main::me->{registered} = 1;
225 $main::me->{version} = $main::version;
226 $main::me->{build} = $main::build;
230 # obtain a new connection this is derived from dxchannel
235 my $self = DXChannel::alloc(@_);
237 # add this node to the table, the values get filled in later
240 $main::routeroot->add($call, '5000', Route::here(1)) if $call ne $main::mycall;
245 # this is how a pc connection starts (for an incoming connection)
246 # issue a PC38 followed by a PC18, then wait for a PC20 (remembering
247 # all the crap that comes between).
250 my ($self, $line, $sort) = @_;
251 my $call = $self->{call};
252 my $user = $self->{user};
255 my $host = $self->{conn}->{peerhost};
256 $host ||= "AGW Port #$self->{conn}->{agwport}" if exists $self->{conn}->{agwport};
259 Log('DXProt', "$call connected from $host");
261 # remember type of connection
262 $self->{consort} = $line;
263 $self->{outbound} = $sort eq 'O';
264 my $priv = $user->priv;
265 $priv = $user->priv(1) unless $priv;
266 $self->{priv} = $priv; # other clusters can always be 'normal' users
267 $self->{lang} = $user->lang || 'en';
268 $self->{isolate} = $user->{isolate};
269 $self->{consort} = $line; # save the connection type
273 # sort out registration
274 $self->{registered} = 1;
276 # get the output filters
277 $self->{spotsfilter} = Filter::read_in('spots', $call, 0) || Filter::read_in('spots', 'node_default', 0);
278 $self->{wwvfilter} = Filter::read_in('wwv', $call, 0) || Filter::read_in('wwv', 'node_default', 0);
279 $self->{wcyfilter} = Filter::read_in('wcy', $call, 0) || Filter::read_in('wcy', 'node_default', 0);
280 $self->{annfilter} = Filter::read_in('ann', $call, 0) || Filter::read_in('ann', 'node_default', 0) ;
281 $self->{routefilter} = Filter::read_in('route', $call, 0) || Filter::read_in('route', 'node_default', 0) unless $self->{isolate} ;
284 # get the INPUT filters (these only pertain to Clusters)
285 $self->{inspotsfilter} = Filter::read_in('spots', $call, 1) || Filter::read_in('spots', 'node_default', 1);
286 $self->{inwwvfilter} = Filter::read_in('wwv', $call, 1) || Filter::read_in('wwv', 'node_default', 1);
287 $self->{inwcyfilter} = Filter::read_in('wcy', $call, 1) || Filter::read_in('wcy', 'node_default', 1);
288 $self->{inannfilter} = Filter::read_in('ann', $call, 1) || Filter::read_in('ann', 'node_default', 1);
289 $self->{inroutefilter} = Filter::read_in('route', $call, 1) || Filter::read_in('route', 'node_default', 1) unless $self->{isolate};
291 # set unbuffered and no echo
292 $self->send_now('B',"0");
293 $self->send_now('E',"0");
294 $self->conn->echo(0) if $self->conn->can('echo');
296 # ping neighbour node stuff
297 my $ping = $user->pingint;
298 $ping = $pingint unless defined $ping;
299 $self->{pingint} = $ping;
300 $self->{nopings} = $user->nopings || $obscount;
301 $self->{pingtime} = [ ];
302 $self->{pingave} = 999;
303 $self->{metric} ||= 100;
304 $self->{lastping} = $main::systime;
306 # send initialisation string
307 unless ($self->{outbound}) {
311 $self->state('init');
312 $self->{pc50_t} = $main::systime;
314 # send info to all logged in thingies
315 $self->tell_login('loginn');
317 # run a script send the output to the debug file
318 my $script = new Script(lc $call) || new Script('node_default');
319 $script->run($self) if $script;
323 # send outgoing 'challenge'
333 # This is the normal pcxx despatcher
337 my ($self, $line) = @_;
339 if ($line =~ '^<\w+\s' && $main::do_xml) {
340 DXXml::normal($self, $line);
344 my @field = split /\^/, $line;
345 return unless @field;
347 pop @field if $field[-1] eq '~';
349 # print join(',', @field), "\n";
352 # process PC frames, this will fail unless the frame starts PCnn
353 my ($pcno) = $field[0] =~ /^PC(\d\d)/; # just get the number
354 unless (defined $pcno && $pcno >= 10 && $pcno <= 99) {
355 dbg("PCPROT: unknown protocol") if isdbg('chanerr');
359 # check for and dump bad protocol messages
360 my $n = check($pcno, @field);
362 dbg("PCPROT: bad field $n, dumped (" . parray($checklist[$pcno-10]) . ")") if isdbg('chanerr');
366 # modify the hop count here
367 if (my ($hops, $trail) = $line =~ /\^H(\d+)(\^?\~?)?$/) {
371 $line =~ s/\^H(\d+)(\^?\~?)?$/sprintf('^H%d%s', $hops, $trail)/e;
372 $field[-1] = "H$hops";
375 # send it out for processing
376 my $origin = $self->{call};
378 my $sub = "handle_$pcno";
380 if ($self->can($sub)) {
381 $self->$sub($pcno, $line, $origin, @field);
383 $self->handle_default($pcno, $line, $origin, @field);
388 # This is called from inside the main cluster processing loop and is used
389 # for despatching commands that are doing some long processing job
394 my @dxchan = DXChannel::get_all();
398 # send out a pc50 on EVERY channel all at once
399 if ($t >= $last_pc50 + $DXProt::pc50_interval) {
400 $pc50s = pc50($main::me, scalar DXChannel::get_all_users);
405 foreach $dxchan (@dxchan) {
406 next unless $dxchan->is_node;
407 next if $dxchan->handle_xml;
408 next if $dxchan == $main::me;
411 $dxchan->send($pc50s) if $pc50s;
413 # send a ping out on this channel
414 if ($dxchan->{pingint} && $t >= $dxchan->{pingint} + $dxchan->{lastping}) {
415 if ($dxchan->{nopings} <= 0) {
418 DXXml::Ping::add($main::me, $dxchan->call);
419 $dxchan->{nopings} -= 1;
420 $dxchan->{lastping} = $t;
421 $dxchan->{lastping} += $dxchan->{pingint} / 2 unless @{$dxchan->{pingtime}};
426 Investigate::process();
429 if ($t - $last10 >= 10) {
435 if ($main::systime >= $last_pc92_update + $pc92_update_period) {
437 $last_pc92_update = $main::systime;
443 if ($main::systime - 3600 > $last_hour) {
444 $last_hour = $main::systime;
449 # finish up a pc context
453 # some active measures
461 my @dxchan = DXChannel::get_all();
464 # send it if it isn't the except list and isn't isolated and still has a hop count
465 # taking into account filtering and so on
466 foreach $dxchan (@dxchan) {
467 next if $dxchan == $main::me;
468 next if $dxchan == $self && $self->is_node;
469 $dxchan->dx_spot($line, $self->{isolate}, @_, $self->{call});
480 if ($self->{spotsfilter}) {
481 ($filter, $hops) = $self->{spotsfilter}->it(@_);
482 return unless $filter;
484 send_prot_line($self, $filter, $hops, $isolate, $line);
489 my ($self, $filter, $hops, $isolate, $line) = @_;
495 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
497 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
498 return unless $routeit;
501 $self->send($routeit);
503 $self->send($routeit) unless $self->{isolate} || $isolate;
512 my @dxchan = DXChannel::get_all();
514 my @dxcc = ((Prefix::cty_data($_[6]))[0..2], (Prefix::cty_data($_[7]))[0..2]);
516 # send it if it isn't the except list and isn't isolated and still has a hop count
517 # taking into account filtering and so on
518 foreach $dxchan (@dxchan) {
519 next if $dxchan == $main::me;
520 next if $dxchan == $self && $self->is_node;
524 $dxchan->wwv($line, $self->{isolate}, @_, $self->{call}, @dxcc);
535 if ($self->{wwvfilter}) {
536 ($filter, $hops) = $self->{wwvfilter}->it(@_[7..$#_]);
537 return unless $filter;
539 send_prot_line($self, $filter, $hops, $isolate, $line)
546 my @dxchan = DXChannel::get_all();
548 my @dxcc = ((Prefix::cty_data($_[10]))[0..2], (Prefix::cty_data($_[11]))[0..2]);
550 # send it if it isn't the except list and isn't isolated and still has a hop count
551 # taking into account filtering and so on
552 foreach $dxchan (@dxchan) {
553 next if $dxchan == $main::me;
554 next if $dxchan == $self;
556 $dxchan->wcy($line, $self->{isolate}, @_, $self->{call}, @dxcc);
567 if ($self->{wcyfilter}) {
568 ($filter, $hops) = $self->{wcyfilter}->it(@_);
569 return unless $filter;
571 send_prot_line($self, $filter, $hops, $isolate, $line) if $self->is_clx || $self->is_spider || $self->is_dxnet;
579 my @dxchan = DXChannel::get_all();
583 my $text = unpad($_[2]);
585 if ($_[3] eq '*') { # sysops
587 } elsif ($_[3] gt ' ') { # speciality list handling
588 my ($name) = split /\./, $_[3];
589 $target = "$name"; # put the rest in later (if bothered)
596 $target = "ALL" if !$target;
599 # obtain country codes etc
600 my @a = Prefix::cty_data($_[0]);
601 my @b = Prefix::cty_data($_[4]);
602 if ($self->{inannfilter}) {
603 my ($filter, $hops) =
604 $self->{inannfilter}->it(@_, $self->{call},
606 @b[0..2], $a[3], $b[3]);
608 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
613 if (AnnTalk::dup($_[0], $_[1], $_[2])) {
614 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
618 Log('ann', $target, $_[0], $text);
620 # send it if it isn't the except list and isn't isolated and still has a hop count
621 # taking into account filtering and so on
622 foreach $dxchan (@dxchan) {
623 next if $dxchan == $main::me;
624 next if $dxchan == $self && $self->is_node;
625 $dxchan->announce($line, $self->{isolate}, $to, $target, $text, @_, $self->{call},
635 $msgid = 1 if $msgid > 999;
644 my @dxchan = DXChannel::get_all();
647 my $text = unpad($_[2]);
650 # munge the group and recast the line if required
651 if ($target =~ s/\.LST$//) {
655 # obtain country codes etc
656 my @a = Prefix::cty_data($_[0]);
657 my @b = Prefix::cty_data($_[4]);
658 if ($self->{inannfilter}) {
659 my ($filter, $hops) =
660 $self->{inannfilter}->it(@_, $self->{call},
662 @b[0..2], $a[3], $b[3]);
664 dbg("PCPROT: Rejected by input announce filter") if isdbg('chanerr');
669 if (AnnTalk::dup($_[0], $_[1], $_[2], $chatdupeage)) {
670 dbg("PCPROT: Duplicate Announce ignored") if isdbg('chanerr');
675 Log('chat', $target, $_[0], $text);
677 # send it if it isn't the except list and isn't isolated and still has a hop count
678 # taking into account filtering and so on
679 foreach $dxchan (@dxchan) {
680 my $is_ak1a = $dxchan->is_ak1a;
682 if ($dxchan->is_node) {
683 next if $dxchan == $main::me;
684 next if $dxchan == $self;
685 next unless $dxchan->is_spider || $is_ak1a;
686 next if $target eq 'LOCAL';
687 if (!$ak1a_line && $is_ak1a) {
688 $ak1a_line = DXProt::pc12($_[0], $text, $_[1], "$target.LST");
692 $dxchan->chat($is_ak1a ? $ak1a_line : $line, $self->{isolate}, $target, $_[1],
693 $text, @_, $self->{call}, @a[0..2], @b[0..2]);
707 if ($self->{annfilter}) {
708 ($filter, $hops) = $self->{annfilter}->it(@_);
709 return unless $filter;
711 send_prot_line($self, $filter, $hops, $isolate, $line) unless $_[1] eq $main::mycall;
720 sub send_local_config
724 dbg('DXProt::send_local_config') if isdbg('trace');
727 if ($self->{do_pc92}) {
728 $self->send_pc92_config;
735 if ($self->{isolate}) {
736 @localnodes = ( $main::routeroot );
737 $self->send_route($main::mycall, \&pc19, 1, $main::routeroot);
739 # create a list of all the nodes that are not connected to this connection
740 # and are not themselves isolated, this to make sure that isolated nodes
741 # don't appear outside of this node
743 # send locally connected nodes
744 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all_nodes();
745 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan if @dxchan;
746 $self->send_route($main::mycall, \&pc19, scalar(@localnodes)+1, $main::routeroot, @localnodes);
749 my @rawintcalls = map { $_->nodes } @localnodes if @localnodes;
751 for $node (@rawintcalls) {
752 push @intcalls, $node unless grep $node eq $_, @intcalls;
754 my $ref = Route::Node::get($self->{call});
755 my @rnodes = $ref->nodes;
756 for $node (@intcalls) {
757 push @remotenodes, Route::Node::get($node) unless grep $node eq $_, @rnodes, @remotenodes;
759 $self->send_route($main::mycall, \&pc19, scalar(@remotenodes), @remotenodes);
762 # get all the users connected on the above nodes and send them out
763 foreach $node ($main::routeroot, @localnodes, @remotenodes) {
765 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
766 $self->send_route($main::mycall, \&pc16, 1, $node, @rout) if @rout && $self->user->wantsendpc16;
768 dbg("sent a null value") if isdbg('chanerr');
777 my $with_pc92_nodes = shift;
781 dbg('DXProt::send_pc92_update') if isdbg('trace');
783 # send 'my' configuration for all users and pc92 capable nodes
784 my @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} } DXChannel::get_all();
785 my @localnodes = map { my $r = Route::get($_->{call}); $r ? $r : () } @dxchan;
786 # push @localnodes, map { my $r = Route::Node::get($_->{call}); $r ? $r : () } DXChannel::get_all_users();
787 push @lines, pc92c($main::routeroot, @localnodes);
790 if ($with_pc92_nodes) {
791 # send out the configuration of all the PC92 nodes with current configuration
792 # but with the dates that the last config came in with.
793 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && $_->{do_pc92} } DXChannel::get_all_nodes();
794 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
795 foreach $node (@localnodes) {
796 if ($node && $node->lastid->{92}) {
797 my @rout = map {my $r = Route::get($_); $r ? ($r) : ()} $node->nodes, $node->users;
798 push @lines, gen_pc92_with_time($node->call, 'C', $node->lastid->{92}, @rout);
803 # send the configuration of all the 'external' nodes that don't handle PC92
804 # out with the 'external' marker on the first node.
805 @dxchan = grep { $_->call ne $main::mycall && $_ != $self && !$_->{isolate} && !$_->{do_pc92} } DXChannel::get_all_nodes();
806 @localnodes = map { my $r = Route::Node::get($_->{call}); $r ? $r : () } @dxchan;
807 foreach $node (@localnodes) {
809 my @rout = map {my $r = Route::User::get($_); $r ? ($r) : ()} $node->users;
810 push @lines, pc92c($node, @rout);
821 dbg('DXProt::send_pc92_config') if isdbg('trace');
823 my @out = $self->gen_pc92_update(1);
825 # send the complete config out on this interface
833 my @out = $main::me->gen_pc92_update(0);
835 # broadcast the lines to all PC92 nodes
837 $main::me->broadcast_route_pc9x('', undef, $_, 0);
842 # route a message down an appropriate interface for a callsign
844 # is called route(to, pcline);
849 my ($self, $call, $line) = @_;
851 if (ref $self && $call eq $self->{call}) {
852 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
856 # always send it down the local interface if available
857 my $dxchan = DXChannel::get($call);
859 dbg("route: $call -> $dxchan->{call} direct" ) if isdbg('route');
861 my $cl = Route::get($call);
862 $dxchan = $cl->dxchan if $cl;
864 if (ref $self && $dxchan eq $self) {
865 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
868 dbg("route: $call -> $dxchan->{call} using normal route" ) if isdbg('route');
872 # try the backstop method
874 my $rcall = RouteDB::get($call);
876 if ($self && $rcall eq $self->{call}) {
877 dbg("PCPROT: Trying to route back to source, dropped") if isdbg('chanerr');
880 $dxchan = DXChannel::get($rcall);
881 dbg("route: $call -> $rcall using RouteDB" ) if isdbg('route') && $dxchan;
886 my $routeit = adjust_hops($dxchan, $line); # adjust its hop count by node name
888 $dxchan->send($routeit) unless $dxchan == $main::me;
891 dbg("PCPROT: No route available, dropped") if isdbg('chanerr');
896 # obtain the hops from the list for this callsign and pc no
902 my $hops = $DXProt::hopcount{$pcno};
903 $hops = $DXProt::def_hopcount if !$hops;
908 # adjust the hop count on a per node basis using the user loadable
909 # hop table if available or else decrement an existing one
916 my $call = $self->{call};
919 if (($hops) = $s =~ /\^H(\d+)\^?~?$/o) {
920 my ($pcno) = $s =~ /^PC(\d\d)/o;
921 confess "$call called adjust_hops with '$s'" unless $pcno;
922 my $ref = $nodehops{$call} if %nodehops;
924 my $newhops = $ref->{$pcno};
925 return "" if defined $newhops && $newhops == 0;
926 $newhops = $ref->{default} unless $newhops;
927 return "" if defined $newhops && $newhops == 0;
928 $newhops = $hops if !$newhops;
929 $s =~ s/\^H(\d+)(\^~?)$/\^H$newhops$2/ if $newhops;
941 return $self->msg('lh1') unless -e "$main::data/hop_table.pl";
942 do "$main::data/hop_table.pl";
949 my ($self, $tonode, $fromnode, $user, $cmd) = @_;
950 if ($tonode eq $main::mycall) {
951 my $ref = DXUser->get_current($fromnode);
952 my $cref = Route::Node::get($fromnode);
953 Log('rcmd', 'in', $ref->{priv}, $fromnode, $cmd);
954 if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
955 if ($ref->{priv}) { # you have to have SOME privilege, the commands have further filtering
956 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
957 my $oldpriv = $self->{priv};
958 $self->{priv} = $ref->{priv}; # assume the user's privilege level
959 my @in = (DXCommandmode::run_cmd($self, $cmd));
960 $self->{priv} = $oldpriv;
961 $self->send_rcmd_reply($main::mycall, $fromnode, $user, @in);
962 delete $self->{remotecmd};
964 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "sorry...!");
967 $self->send_rcmd_reply($main::mycall, $fromnode, $user, "your attempt is logged, Tut tut tut...!");
970 my $ref = DXUser->get_current($tonode);
971 if ($ref && $ref->is_clx) {
972 $self->route($tonode, pc84($fromnode, $tonode, $user, $cmd));
974 $self->route($tonode, pc34($fromnode, $tonode, $cmd));
979 sub process_rcmd_reply
981 my ($self, $tonode, $fromnode, $user, $line) = @_;
982 if ($tonode eq $main::mycall) {
983 my $s = $rcmds{$fromnode};
985 my $dxchan = DXChannel::get($s->{call});
986 my $ref = $user eq $tonode ? $dxchan : (DXChannel::get($user) || $dxchan);
987 $ref->send($line) if $ref;
988 delete $rcmds{$fromnode} if !$dxchan;
990 # send unsolicited ones to the sysop
991 my $dxchan = DXChannel::get($main::myalias);
992 $dxchan->send($line) if $dxchan;
995 my $ref = DXUser->get_current($tonode);
996 if ($ref && $ref->is_clx) {
997 $self->route($tonode, pc85($fromnode, $tonode, $user, $line));
999 $self->route($tonode, pc35($fromnode, $tonode, $line));
1008 my $fromnode = shift;
1013 Log('rcmd', 'out', $fromnode, $line);
1014 if ($self->is_clx) {
1015 $self->send(pc85($main::mycall, $fromnode, $user, "$main::mycall:$line"));
1017 $self->send(pc35($main::mycall, $fromnode, "$main::mycall:$line"));
1022 # add a rcmd request to the rcmd queues
1025 my ($self, $to, $cmd) = @_;
1028 $r->{call} = $self->{call};
1029 $r->{t} = $main::systime;
1033 my $ref = Route::Node::get($to);
1034 my $dxchan = $ref->dxchan;
1035 if ($dxchan && $dxchan->is_clx) {
1036 route(undef, $to, pc84($main::mycall, $to, $self->{call}, $cmd));
1038 route(undef, $to, pc34($main::mycall, $to, $cmd));
1045 my $pc39flag = shift;
1046 my $call = $self->call;
1048 return if $self->{disconnecting}++;
1050 unless ($pc39flag && $pc39flag == 1) {
1051 $self->send_now("D", DXProt::pc39($main::mycall, $self->msg('disc1', "System Op")));
1054 # get rid of any PC16/17/19
1055 eph_del_regex("^PC1[679]*$call");
1057 # do routing stuff, remove me from routing table
1058 my $node = Route::Node::get($call);
1061 @rout = $node->del($main::routeroot);
1063 # and all my ephemera as well
1066 eph_del_regex("^PC1[679].*$c");
1070 RouteDB::delete_interface($call);
1072 # unbusy and stop and outgoing mail
1073 my $mref = DXMsg::get_busy($call);
1074 $mref->stop_msg($call) if $mref;
1076 # broadcast to all other nodes that all the nodes connected to via me are gone
1077 unless ($pc39flag && $pc39flag == 2) {
1078 $self->route_pc21($main::mycall, undef, @rout) if @rout;
1079 $self->route_pc92d($main::mycall, undef, $main::routeroot, $node) if $node;
1082 # remove outstanding pings
1083 delete $pings{$call};
1085 # I was the last node visited
1086 $self->user->node($main::mycall);
1088 # send info to all logged in thingies
1089 $self->tell_login('logoutn');
1091 Log('DXProt', $call . " Disconnected");
1093 $self->SUPER::disconnect;
1098 # send a talk message to this thingy
1102 my ($self, $from, $to, $via, $line, $origin) = @_;
1104 $line =~ s/\^/\\5E/g; # remove any ^ characters
1105 $self->send(DXProt::pc10($from, $to, $via, $line, $origin));
1106 Log('talk', $to, $from, $via?$via:$self->call, $line) unless $origin && $origin ne $main::mycall;
1109 # send it if it isn't the except list and isn't isolated and still has a hop count
1110 # taking into account filtering and so on
1116 my $generate = shift;
1117 my $no = shift; # the no of things to filter on
1119 my ($filter, $hops);
1122 for (; @_ && $no; $no--) {
1125 if (!$self->{isolate} && $self->{routefilter}) {
1128 ($filter, $hops) = $self->{routefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->{state}, $r->{state});
1132 dbg("DXPROT: $self->{call}/" . $r->call . " rejected by output filter") if isdbg('chanerr');
1135 dbg("was sent a null value") if isdbg('chanerr');
1138 push @rin, $r unless $self->{isolate} && $r->call ne $main::mycall;
1142 foreach my $line (&$generate(@rin, @_)) {
1145 $routeit =~ s/\^H\d+\^\~$/\^H$hops\^\~/;
1147 $routeit = adjust_hops($self, $line); # adjust its hop count by node name
1148 next unless $routeit;
1151 $self->send($routeit);
1160 my $generate = shift;
1162 my @dxchan = DXChannel::get_all_nodes();
1166 $line =~ /\^H(\d+)\^?\~?$/;
1167 return unless $1 > 0;
1169 unless ($self->{isolate}) {
1170 foreach $dxchan (@dxchan) {
1171 next if $dxchan == $self;
1172 next if $dxchan == $main::me;
1173 next unless $dxchan->isa('DXProt');
1174 next if $dxchan->{do_pc92};
1175 next if ($generate == \&pc16 || $generate==\&pc17) && !$dxchan->user->wantsendpc16;
1177 $dxchan->send_route($origin, $generate, @_);
1182 # this is only used for next door nodes on init
1187 return unless $self->{do_pc92};
1190 my $generate = shift;
1191 my $no = shift; # the no of things to filter on
1194 $line = &$generate(@_);
1198 sub broadcast_route_pc9x
1202 my $generate = shift;
1205 my @dxchan = DXChannel::get_all_nodes();
1208 if ($origin eq $main::mycall) {
1209 $line = &$generate(@_);
1212 $line =~ /\^H(\d+)\^\~?$/;
1213 unless ($1 > 0 && $self->{isolate}) {
1214 foreach $dxchan (@dxchan) {
1215 next if $dxchan == $self;
1216 next if $dxchan == $main::me;
1217 next unless $dxchan->{do_pc92};
1218 next unless $dxchan->isa('DXProt');
1220 $dxchan->send($line);
1228 return unless $self->user->wantpc16;
1231 broadcast_route($self, $origin, \&pc16, $line, 1, @_);
1237 return unless $self->user->wantpc16;
1240 broadcast_route($self, $origin, \&pc17, $line, 1, @_);
1248 broadcast_route($self, $origin, \&pc19, $line, scalar @_, @_);
1256 broadcast_route($self, $origin, \&pc21, $line, scalar @_, @_);
1264 broadcast_route($self, $origin, \&pc24, $line, 1, @_);
1272 broadcast_route($self, $origin, \&pc41, $line, 1, @_);
1280 broadcast_route($self, $origin, \&pc50, $line, 1, @_);
1288 broadcast_route_pc9x($self, $origin, \&pc92c, $line, 1, @_);
1296 broadcast_route_pc9x($self, $origin, \&pc92a, $line, 1, @_);
1304 broadcast_route_pc9x($self, $origin, \&pc92d, $line, 1, @_);
1311 my ($filter, $hops) = (1, 1);
1313 if ($self->{inroutefilter}) {
1314 ($filter, $hops) = $self->{inroutefilter}->it($self->{call}, $self->{dxcc}, $self->{itu}, $self->{cq}, $r->call, $r->dxcc, $r->itu, $r->cq, $self->state, $r->state);
1315 dbg("PCPROT: $self->{call}/" . $r->call . ' rejected by in_filter_route') if !$filter && isdbg('chanerr');
1323 my $t = shift || $eph_restime;
1327 $s =~ s/\^H\d\d?\^?\~?$//;
1328 $r = 1 if exists $eph{$s}; # pump up the dup if it keeps circulating
1329 $eph{$s} = $main::systime + $t;
1330 dbg("PCPROT: emphemeral duplicate") if $r && isdbg('chanerr');
1338 while (($key, $val) = each %eph) {
1339 if ($key =~ m{$regex}) {
1349 while (($key, $val) = each %eph) {
1350 if ($main::systime >= $val) {
1361 while (($key, $val) = each %eph) {
1362 push @out, $key, $val;
1369 goto &DXCommandmode::run_cmd;
1373 # import any msgs in the chat directory
1374 # the messages are sent to the chat group which forms the
1375 # the first part of the name (eg: solar.1243.txt would be
1376 # sent to chat group SOLAR)
1378 # Each message found is sent: one non-blank line to one chat
1379 # message. So 4 lines = 4 chat messages.
1381 # The special name LOCAL is for local users ANN
1382 # The special name ALL is for ANN/FULL
1383 # The special name SYSOP is for ANN/SYSOP
1387 # are there any to do in this directory?
1388 return unless -d $chatimportfn;
1389 unless (opendir(DIR, $chatimportfn)) {
1390 dbg("can\'t open $chatimportfn $!") if isdbg('msg');
1391 Log('msg', "can\'t open $chatimportfn $!");
1395 my @names = readdir(DIR);
1398 foreach $name (@names) {
1399 next if $name =~ /^\./;
1400 my $splitit = $name =~ /^split/;
1401 my $fn = "$chatimportfn/$name";
1403 unless (open(MSG, $fn)) {
1404 dbg("can\'t open import file $fn $!") if isdbg('msg');
1405 Log('msg', "can\'t open import file $fn $!");
1409 my @msg = map { s/\r?\n$//; $_ } <MSG>;
1413 my @cat = split /\./, $name;
1414 my $target = uc $cat[0];
1416 foreach my $text (@msg) {
1417 next unless $text && $text !~ /^\s*#/;
1418 if ($target eq 'ALL' || $target eq 'LOCAL' || $target eq 'SYSOP') {
1419 my $sysopflag = $target eq 'SYSOP' ? '*' : ' ';
1420 if ($target ne 'LOCAL') {
1421 send_announce($main::me, pc12($main::mycall, $text, '*', $sysopflag), $main::mycall, '*', $text, $sysopflag, $main::mycall, '0');
1423 Log('ann', 'LOCAL', $main::mycall, $text);
1424 DXChannel::broadcast_list("To LOCAL de ${main::mycall}: $text\a", 'ann', undef, DXCommandmode->get_all());
1427 my $msgid = nextchatmsgid();
1428 $text = "#$msgid $text";
1429 send_chat($main::me, pc12($main::mycall, $text, '*', $target), $main::mycall, '*', $text, $target, $main::mycall, '0');