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