]> dxcluster.org Git - spider.git/commitdiff
add cmd and text xml handlers
authorminima <minima>
Mon, 23 Jan 2006 00:02:51 +0000 (00:02 +0000)
committerminima <minima>
Mon, 23 Jan 2006 00:02:51 +0000 (00:02 +0000)
add more sophistication to the dxxml router

perl/DXXml.pm
perl/DXXml/Cmd.pm [new file with mode: 0644]
perl/DXXml/Text.pm [new file with mode: 0644]
perl/cluster.pl

index 9d0a59698170c153a5db6ec4ab77ac124012c878..a9072d467d4fcc3ea8e3ea150be2174c3cd749af 100644 (file)
@@ -18,6 +18,8 @@ use DXUtil;
 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+)/ );
@@ -37,7 +39,13 @@ sub new
 {
        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; 
 }
 
 #
@@ -204,7 +212,13 @@ sub route
        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');
@@ -216,7 +230,7 @@ sub route
        }
 
        # 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 {
@@ -249,13 +263,30 @@ sub route
                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);
+               }
        }
 }
 
diff --git a/perl/DXXml/Cmd.pm b/perl/DXXml/Cmd.pm
new file mode 100644 (file)
index 0000000..821606a
--- /dev/null
@@ -0,0 +1,81 @@
+#
+# 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;
diff --git a/perl/DXXml/Text.pm b/perl/DXXml/Text.pm
new file mode 100644 (file)
index 0000000..35c8319
--- /dev/null
@@ -0,0 +1,70 @@
+#
+# 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;
index 5f5b492cb8785fa46a9a2a983927d666afd443b4..8aade278e42ebe2bb38d1297b21cf6e85491a260 100755 (executable)
@@ -135,7 +135,7 @@ $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;
-$main::build -= 1;                             # fudge (put back for now)
+$main::build -= 3;                             # fudge (put back for now)