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