Skip to content

Commit

Permalink
+ logical-system support for Juniper routers
Browse files Browse the repository at this point in the history
  • Loading branch information
Cougar committed May 18, 2009
1 parent 6116853 commit 752f63a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ but these don't work as you expect (the same port for bgpd and zebra):
- telnet://pass@host:2601
- telnet://pass@host:2605

"logical-system" works only with OSType="JunOS" and when using SSH.


DOWNLOAD
Expand Down
12 changes: 9 additions & 3 deletions lg.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $ENV{HOME} = "."; # SSH needs access for $HOME/.ssh

use XML::Parser;

my $SYS_progid = '$Id: lg.cgi,v 1.33 2008/08/25 18:44:54 cougar Exp $';
my $SYS_progid = '$Id: lg.cgi,v 1.30 2004/11/25 14:12:42 cougar Exp $';

my $default_ostype = "ios";

Expand All @@ -52,6 +52,7 @@ my %router_list;
my @routers;
my %namemap;
my %ostypes;
my %logicalsystem;
my %cmdmap;

my $default_router;
Expand Down Expand Up @@ -407,6 +408,8 @@ sub xml_startparse {
}
} elsif (lc($attrval[$i]) eq "ostype") {
$ostypes{$xml_current_router_name} = lc($attrval[$i+1]);
} elsif (lc($attrval[$i]) eq "logical-system") {
$logicalsystem{$xml_current_router_name} = lc($attrval[$i+1]);
}
}
if ($xml_current_router_name eq "") {
Expand Down Expand Up @@ -680,15 +683,18 @@ sub print_results
use Net::SSH::Perl::Cipher;
";
die $@ if $@;
my $remotecmd = $command;
$remotecmd = "set cli logical-system $logicalsystem{$FORM{router}}; " . $command if (defined $logicalsystem{$FORM{router}});
$port = 22 if ($port eq "");
$ssh = Net::SSH::Perl->new($host, port => $port);
if ($] > 5.007) {
require Encode;
$login = Encode::encode_utf8($login);
$password = Encode::encode_utf8($password);
$remotecmd = Encode::encode_utf8($remotecmd);
}
$ssh->login($login, $password);
my ($out, $err) = $ssh->cmd("$command");
my ($out, $err) = $ssh->cmd("$remotecmd");
@output = split (/\n/, $out);
} elsif ($scheme eq "telnet") {
eval "
Expand Down Expand Up @@ -780,6 +786,7 @@ sub print_results

next if (/Type escape sequence to abort./);
next if (/Translating .*\.\.\.domain server/);
next if (/Logical system: /);

next if (($inemptyheader) && (/^$/));
$inemptyheader = 0;
Expand Down Expand Up @@ -995,7 +1002,6 @@ sub cgi_decode {
#### Strip out semicolons unless for special character
$value =~ s/;/$$/g;
$value =~ s/&(\S{1,6})$$/&\1;/g;
$value =~ s/$$/ /g;

$FORM{$name} .= $value;
}
Expand Down
4 changes: 4 additions & 0 deletions lg.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<URL>ssh://login@juniper</URL>
</Router>
<Router Name="JunOS SSH1 pubkey IPv4" OSType = "JunOS" logical-system="R2">
<URL>ssh://login@juniper</URL>
</Router>
<Router Name="JunOS telnet" OSType = "JunOS">
<URL>telnet://login:password@10.0.0.1</URL>
</Router>
Expand Down

0 comments on commit 752f63a

Please sign in to comment.