04d50421ef22ba941ba80ed76aa7f21ce65bd529
[spider.git] / cmd / demonstrate.pl
1 #!/usr/bin/perl
2 #
3 # pretend that you are another user, execute a command
4 # as that user, then send the output back to them.
5 #
6 # This is for educating users....
7 #
8 # Copyright (c) 2002 Dirk Koopman G1TLH
9 #
10 my ($self, $line) = @_;
11
12 my $mycall = $self->call;
13 my $myuser = $self->user;
14 my $mypriv = $self->priv;
15
16 my ($call, $newline) = split /\s+/, $line, 2;
17 $call = uc $call;
18 my $dxchan = DXChannel->get($call);
19
20 return (1, $self->msg('e7', $call)) unless $dxchan;
21 if ($self->remotecmd) {
22         Log('DXCommand', "$mycall is trying to 'input' $call remotely");
23         return (1, $self->msg('e5'));
24 }
25 if ($mypriv < 8) {
26         Log('DXCommand', "$mycall is trying to 'input' $call locally");
27         return (1, $self->msg('e5'));
28 }
29
30 $call = uc $call;
31 my $user = $dxchan->user;
32
33 # set up basic environment
34 $self->call($call);
35 $self->user($user);
36 $self->priv($dxchan->priv);
37 Log('DXCommand', "input '$newline' as $call by $mycall");
38 my @in = $self->run_cmd($newline);
39 $self->call($mycall);
40 $self->user($myuser);
41 $self->priv($mypriv);
42
43 $dxchan->send($newline, @in);
44
45 return (1, map { "->$call: $_" } @in);