X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=web%2Fssendfile.pl;h=5347dd2193b0ce6f86cea58a8e9d91a8e700bfda;hb=1e7869f8141084245dcd34fb065f38a418517e7b;hp=0901b8b37f2b3c2e93274343b083ea18811b1a98;hpb=ce95bb11a855774a36fb21c0d16cfd0d6be3669d;p=nms diff --git a/web/ssendfile.pl b/web/ssendfile.pl index 0901b8b..5347dd2 100755 --- a/web/ssendfile.pl +++ b/web/ssendfile.pl @@ -1,54 +1,12 @@ #!/usr/bin/perl -# -# - use warnings; use strict; -use Net::Telnet; +use lib '../include'; use POSIX; -my $timeout = 15; my $delaytime = 30; my $poll_frequency = 60; -# Send a command to switch and return the data recvied from the switch -sub switch_exec($$) { - my ($cmd, $conn) = @_; - - # Send the command and get data from switch - my @data = $conn->cmd($cmd); - my @lines = (); - foreach my $line (@data) { - # Remove escape-7 sequence - $line =~ s/\x1b\x37//g; - push (@lines, $line); - } - - return @lines; -} - -sub switch_connect($) { - my ($ip) = @_; - -# Dump_Log => '/tmp/dumplog-queue', - my $conn = new Net::Telnet( Timeout => $timeout, - Errmode => 'return', - Prompt => '/(es3024|e\d+\-\dsw)>/i'); - my $ret = $conn->open( Host => $ip); - if (!$ret || $ret != 1) { - return (undef); - } - # XXX: Just send the password as text, I did not figure out how to - # handle authentication with only password through $conn->login(). - #$conn->login(»·Prompt => '/password[: ]*$/i', - # Name => $password, - # Password => $password); - $conn->cmd($nms::config::zyxel_password); - # Get rid of banner - $conn->get; - return ($conn); -} - sub mylog { my $msg = shift; my $time = POSIX::ctime(time); @@ -61,7 +19,7 @@ if ($#ARGV != 1) { "./ssendfile.pl addr configfile\n"); } -my $conn = switch_connect($ARGV[0]); +my $conn = nms::switch_connect($ARGV[0]); if (!defined($conn)) { die("Could not connect to switch.\n"); } @@ -75,13 +33,13 @@ while () { # print "New ip: $1\n"; # $conn->cmd( String => $cmd, # Timeout => 3); -# $conn = switch_connect($1); +# $conn = nms::switch_connect($1); # if (!defined($conn)) { # die "Could not connect to new ip: $1\n"; # } # } # else { - my @data = switch_exec($cmd, $conn); + my @data = nms::switch_exec($cmd, $conn); foreach my $line (@data) { $line =~ s/[\r\n]+//g; print "$line\n";