]> www.dxcluster.org Git - spider.git/blob - perl/DXXml/Cmd.pm
remove all $Id$ strings
[spider.git] / perl / DXXml / Cmd.pm
1 #
2 # XML (R)Cmd handler
3 #
4 #
5 #
6 # Copyright (c) Dirk Koopman, G1TLH
7 #
8
9 use strict;
10
11 package DXXml::Cmd;
12
13 use DXDebug;
14 use DXProt;
15 use IsoTime;
16 use Investigate;
17 use DXXml::Text;
18 use DXLog;
19
20 use vars qw(@ISA);
21 @ISA = qw(DXXml);
22
23 sub handle_input
24 {
25         my $self = shift;
26         my $dxchan = shift;
27
28         if ($self->{to} eq $main::mycall) {
29                 my @in;
30                 
31                 my $cmd = $self->{content};
32                 
33                 if ($self->{u} && $self->{u} eq $dxchan->call) {        # online user or node
34                         @in = (DXCommandmode::run_cmd($dxchan, $cmd));
35                 } else {
36                         # remote command
37                         my $ref = DXUser->get_current($self->{o});
38                         my $cref = Route::Node::get($self->{o});
39                         my $answer;
40                         
41                         if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
42                                 $self->{remotecmd} = 1; # for the benefit of any command that needs to know
43                                 my $oldpriv = $dxchan->{priv};
44                                 $dxchan->{priv} = $ref->{priv}; # assume the user's privilege level
45                                 @in = (DXCommandmode::run_cmd($dxchan, $cmd));
46                                 $dxchan->{priv} = $oldpriv;
47                                 delete $dxchan->{remotecmd};
48                                 $answer = "success";
49                         } else {
50                                 $answer = "denied";
51                         }
52                         Log('rcmd', 'in', $ref->{priv}, $self->{o}, "$self->{content}($answer)");
53                 }
54                 my $rep = DXXml::Text->new(u=>$self->{u}, to=>$self->{o}, content=>join('%0A', map {"$main::mycall:$_"} @in));
55                 $rep->route($main::me); # because it's coming from me!
56         } else {
57                 $self->route($dxchan);
58         }
59 }
60
61 sub topcxx
62 {
63         my $self = shift;
64
65         my $ref = DXUser->get_current($self->{to});
66         my $s;
67         
68         if ($ref && $ref->is_clx && $self->{u}) {
69                 $s = DXProt::pc84(($self->{o} || $main::mycall), $self->{to}, $self->{u}, $self->{content});
70         } else {
71                 $s = DXProt::pc34(($self->{o} || $main::mycall), $self->{to}, $self->{content});
72         }
73         return $self->{'-pcxx'} = $s;
74 }
75
76 1;