2 # The rudimentary beginnings of a Spider client which is known to run on ActiveState
5 # It's very scrappy, but it *does* do enough to allow SysOp console access. It also
6 # means that since it's perl, Dirk might pretty it up a bit :-)
10 # Iain Philipps, G0RDI 03-Mar-01
17 # search local then perl directories
19 use vars qw($root $myalias $mycall $clusteraddr $clusterport $data);
21 # root of directory tree for this system
23 $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
25 unshift @INC, "$root/perl"; # this IS the right way round!
26 unshift @INC, "$root/local";
40 my $call = uc shift @ARGV if @ARGV;
41 $call = uc $myalias if !$call;
42 my ($scall, $ssid) = split /-/, $call;
43 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;
45 $ssid = 15 if $ssid > 15;
46 $call = "$scall-$ssid";
48 if ($call eq $mycall) {
49 print "You cannot connect as your cluster callsign ($mycall)\n";
54 my $handle = IO::Socket::INET->new(Proto => "tcp",
55 PeerAddr => $clusteraddr,
56 PeerPort => $clusterport);
58 if (-r "$data/offline") {
59 open IN, "$data/offline" or die;
65 print "Sorry, the cluster $mycall is currently off-line\n";
71 $handle->autoflush(1);
72 print $handle "A$call|local\n";
74 # Fork or thread one in / one out .....
77 if ($Config{usethreads}) {
79 # print "Using Thread Method\n";
80 $t = Thread->new(\&dostdin);
85 # print "Using Fork Method\n";
86 die "can't fork: $!" unless defined($childpid = fork());
89 kill 'TERM', $childpid;
99 my ($lastend, $end) = ("\n", "\n");
101 while (defined (my $msg = <$handle>)) {
102 my ($sort, $call, $line) = $msg =~ /^(\w)([^\|]+)\|(.*)$/;
103 next unless defined $sort;
104 $line =~ s/\%([0-9A-F][0-9A-F])/chr(hex($1))/eg;
107 } elsif ($sort eq 'E' || $sort eq 'B') {
110 # newline ends all lines except a prompt
113 if ($line =~ /^$call de $mycall\s+\d+-\w\w\w-\d+\s+\d+Z >$/o) {
116 my $begin = ($lastend eq "\n") ? '' : "\n";
117 print $begin . $line . $end;
124 while (defined (my $line = <STDIN>)) {
125 print $handle "I$call|$line\n";
126 if ($t && ($line =~ /^b/i || $line =~ /^q/i)) {