]> git.sesse.net Git - nms/blobdiff - web/smanagement.pl
Update make-switches.pl for TG07.
[nms] / web / smanagement.pl
index e6474586eb467bc45b3a248e352e0b260074f887..de7e1b8d134d4df33b69b99bfae02d59e7c810fd 100755 (executable)
@@ -1,23 +1,12 @@
 #!/usr/bin/perl
-use lib '../include';
-use nms;
-#
-#
-
-my $username = '';
-my $password = 'removed';
-
-# Seconds to wait for connection
-my $timeout = 15;
-
-
 use warnings;
 use strict;
-use Switch;
 use CGI;
-use Net::Telnet;
 use DBI;
 use Data::Dumper;
+use Switch;
+use lib '../include';
+use nms;
 
 # Grab from .htaccess-authentication
 my $user = $ENV{'REMOTE_USER'};
@@ -34,58 +23,21 @@ my $sgetip = $dbh->prepare("SELECT ip FROM switches WHERE sysname = ?")
        or die "Could not prepare sgetip";
 my $sgid = $dbh->prepare("SELECT nextval('squeue_group_sequence') as gid");
 
-# 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) = @_;
-
-       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 (0);
-       }
-       # 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($password);
-       # Get rid of banner
-       $conn->get;
-       return ($conn);
-}
-
 sub parse_range($) {
        my $switches = $_;
        my @range;
 
        my @rangecomma = split(/\s*,\s*/, $switches);
        foreach (@rangecomma) {
-               my ($first, $drop1, $last, $drop2) = $_ =~ /(e\d+\-[123456])(sw)?\s*\-\s*(e\d+\-[123456])?(sw)?/;
-               if (!defined($first) && $_ =~ /e\d+\-[123456]/) {
+               my ($first, $last) = $_ =~ /(e\d+\-(?:sw)?[123456])\s*\-\s*(e\d+\-(?:sw)?[123456])?/;
+               if (!defined($first) && $_ =~ /e\d+\-(sw)?[123456]/) {
                        $first = $_;
                }
                if (!defined($first)) {
                        print "<font color=\"red\">Parse error in: $_</font><br>\n";
                        next;
                }
-               my ($rowstart, $placestart) = $first =~ /e(\d+)\-([123456])/;
+               my ($rowstart, $placestart) = $first =~ /e(\d+)\-(?:sw)?([123456])/;
                if (!defined($rowstart) || !defined($placestart)) {
                        print "<font color=\"red\">Parse error in: $_</font><br>\n";
                        next;
@@ -96,7 +48,7 @@ sub parse_range($) {
                        $placeend = $placestart;
                }
                else {
-                       ($rowend, $placeend) = $last =~ /e(\d+)\-([123456])/;
+                       ($rowend, $placeend) = $last =~ /e(\d+)\-(?:sw)?([123456])/;
                }
                if (!defined($rowend) || !defined($placeend)) {
                        print "<font color=\"red\">Parse error in: $_</font><br>\n";
@@ -113,7 +65,7 @@ sub parse_range($) {
                        }
                        for (my $j = $dostart; $j <= 6; $j++) {
                                last if ($i == $rowend && $j > $placeend);
-                               push(@range, "e$i-$j");
+                               push(@range, "e$i-sw$j");
                        }
                }
        }
@@ -126,9 +78,9 @@ sub parse_range($) {
 sub get_addr_from_switchnum($) {
        my ($sysname) = @_;
 
-       $sgetip->execute($sysname."sw");
+       $sgetip->execute($sysname);
        if ($sgetip->rows() < 1) {
-               print "Could not get the ip for: ".$sysname."sw";
+               print "Could not get the ip for: ".$sysname;
                return undef;
        }
        my $row = $sgetip->fetchrow_hashref();