use DXXml::Ping;
use DXXml::Dx;
use DXXml::IM;
+use DXXml::Text;
+use DXXml::Cmd;
use vars qw($VERSION $BRANCH $xs $id $max_old_age $max_future_age $dupeage);
$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
{
my $pkg = shift;
my $class = ref $pkg || $pkg;
- return bless{@_}, $class;
+ my $self = bless{@_}, $class;
+ while (@_) {
+ my $key = shift;
+ my $val = shift;
+ $self->{$key} = $val if defined $val;
+ }
+ return $self;
}
#
my $self = shift;
my $fromdxchan = shift;
my $to = shift;
- my $via = $to || $self->{'-via'} || $self->{to};
+ my $via = $to;
+ my $dxchan;
+
+ if (my $u = $self->{u}) {
+ $via ||= $u if ($dxchan = DXChannel::get($u));
+ }
+ $via ||= $self->{'-via'} || $self->{to};
unless ($via) {
dbg("XML: no route specified (" . $self->toxml . ")") if isdbg('chanerr');
}
# always send it down the local interface if available
- my $dxchan = DXChannel::get($via);
+ $dxchan ||= DXChannel::get($via);
if ($dxchan) {
dbg("route: $via -> $dxchan->{call} direct" ) if isdbg('route');
} else {
return;
}
+ $self->{o} ||= $main::mycall;
+ $self->{id} ||= nextid();
+ $self->{'-timet'} ||= $main::systime;
+
if ($dxchan->handle_xml) {
$dxchan->send($self->toxml);
+ } elsif ($dxchan->isnode) {
+ my $ref = $self->topcxx($dxchan);
+ if (ref $ref) {
+ for (@$ref) {
+ $dxchan->send($_);
+ }
+ } else {
+ $dxchan->send($ref);
+ }
} else {
- $self->{o} ||= $main::mycall;
- $self->{id} ||= nextid();
- $self->{'-timet'} ||= $main::systime;
- $dxchan->send($self->topcxx);
+ my $ref = $self->tocmd($dxchan);
+ if (ref $ref) {
+ for (@$ref) {
+ $dxchan->send($_);
+ }
+ } else {
+ $dxchan->send($ref);
+ }
}
}
--- /dev/null
+#
+# XML (R)Cmd handler
+#
+# $Id$
+#
+# Copyright (c) Dirk Koopman, G1TLH
+#
+
+use strict;
+
+package DXXml::Cmd;
+
+use DXDebug;
+use DXProt;
+use IsoTime;
+use Investigate;
+use Time::HiRes qw(gettimeofday tv_interval);
+use DXXml::Text;
+
+use vars qw($VERSION $BRANCH @ISA %pings);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
+@ISA = qw(DXXml);
+
+sub handle_input
+{
+ my $self = shift;
+ my $dxchan = shift;
+
+ if ($self->{to} eq $main::mycall) {
+ my @in;
+
+ my $cmd = $self->{content};
+
+ if ($self->{o} eq $dxchan->call) { # online user or node
+ @in = (DXCommandmode::run_cmd($dxchan, $cmd));
+ } else {
+ # remote command
+ my $ref = DXUser->get_current($self->{o});
+ my $cref = Route::Node::get($self->{o});
+ my $answer;
+
+ if ($cmd !~ /^\s*rcmd/i && $cref && $ref && $cref->call eq $ref->homenode) { # not allowed to relay RCMDS!
+ $self->{remotecmd} = 1; # for the benefit of any command that needs to know
+ my $oldpriv = $dxchan->{priv};
+ $dxchan->{priv} = $ref->{priv}; # assume the user's privilege level
+ @in = (DXCommandmode::run_cmd($dxchan, $cmd));
+ $dxchan->{priv} = $oldpriv;
+ delete $dxchan->{remotecmd};
+ $answer = "success";
+ } else {
+ $answer = "denied";
+ }
+ Log('rcmd', 'in', $ref->{priv}, $self->{o}, "$self->{content}($answer)");
+ }
+ my $rep = DXXml::Text->new(u=>$self->{u}, to=>$self->{o}, content=>join('%0A', @in));
+ $rep->route($dxchan);
+ } else {
+ $self->route($dxchan);
+ }
+}
+
+sub topcxx
+{
+ my $self = shift;
+
+ my $ref = DXUser->get_current($self->{to});
+ my $s;
+
+ if ($ref && $ref->is_clx && $self->{u}) {
+ $s = DXProt::pc84(($self->{o} || $main::mycall), $self->{to}, $self->{u}, $self->{content});
+ } else {
+ $s = DXProt::pc34(($self->{o} || $main::mycall), $self->{to}, $self->{content});
+ }
+ return $self->{'-pcxx'} = $s;
+}
+
+1;
--- /dev/null
+#
+# XML Text handler
+#
+# $Id$
+#
+# Copyright (c) Dirk Koopman, G1TLH
+#
+
+use strict;
+
+package DXXml::Text;
+
+use DXDebug;
+use DXProt;
+use IsoTime;
+use Investigate;
+use Time::HiRes qw(gettimeofday tv_interval);
+
+use vars qw($VERSION $BRANCH @ISA %pings);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
+@ISA = qw(DXXml);
+
+sub handle_input
+{
+ my $self = shift;
+ my $dxchan = shift;
+
+ # this is always routed
+ if ($self->{to} eq $main::mycall ) {
+ my $r = DXChannel::get($main::myalias);
+ $dxchan = $r if $r;
+ }
+ $self->route($dxchan);
+
+}
+
+sub topcxx
+{
+ my $self = shift;
+ my $dxchan = shift;
+ my @out;
+
+ my $ref = DXUser->get_current($self->{to});
+ while (@_) {
+ my $line = shift;
+ $line =~ s/\s*$//;
+ Log('rcmd', 'out', $self->{to}, $line);
+ if ($self->{u} && $dxchan->is_clx && $ref->is_clx) {
+ push @out, pc85($main::mycall, $self->{to}, $self->{u}, "$main::mycall:$line");
+ } else {
+ push @out, pc35($main::mycall, $self->{to}, "$main::mycall:$line");
+ }
+ }
+
+ return $self->{'-pcxx'} = \@out;
+}
+
+sub tocmd
+{
+ my $self = shift;
+
+ my @out = split /(?:%0D)?\%0A/, $self->{content};
+ return $self->{-cmd} = \@out;
+}
+
+1;
$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
$main::build += $VERSION;
$main::branch += $BRANCH;
-$main::build -= 1; # fudge (put back for now)
+$main::build -= 3; # fudge (put back for now)