head	1.3;
access;
symbols;
locks; strict;
comment	@# @;


1.3
date	99.02.10.15.28.14;	author trockij;	state Exp;
branches;
next	1.2;

1.2
date	99.01.29.17.46.05;	author trockij;	state Exp;
branches;
next	1.1;

1.1
date	99.01.29.17.41.07;	author trockij;	state Exp;
branches;
next	;


desc
@change passwords on 3com switches
@


1.3
log
@*** empty log message ***
@
text
@#!/usr/local/bin/perl
#
# change passwords on 3Com switches
#
# $Id: a3compasswd,v 1.2 1999/01/29 17:46:05 trockij Exp trockij $
#
# Copyright (C) 1998 Jim Trocki
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

use A3Com::Password;

sub get_passwd;

$OLDPASS = get_passwd ("Old adm password:");
$NEWPASS = get_passwd ("New adm password:");
$NEWPASS2 = get_passwd ("Confirm new adm password:");

die "new passwords do not match\n" unless ($NEWPASS eq $NEWPASS2);

@@success = ();
@@failures = ();

$| = 1;

foreach $sw (@@ARGV) {

    $begin = time;
    print "$sw...";

    $n = new A3Com::Password;
    $n->switch ($sw);
    $n->login ("adm");
    $n->password ($OLDPASS);
    $n->log (0);

    $result = $n->set_admpassword ($NEWPASS);

    if ($result eq undef) {
	push (@@failures, [$sw, $n->error]);
	$s = "fail!";
    } else {
    	push @@success, $sw;
	$s = "ok";
    }
    $end = time;

    print "done ($s), ($begin $end) " . $end - $begin . " seconds\n";
}

if (@@failures == 0) {
    print "\nAll switches updated successfully\n";
    exit (0);
}

#
# failures!
#
print STDERR "\n#\n# failures occurred:\n#\n";

for (@@failures) {
    print STDERR "@@{$_}\n";
}

exit (1);


sub get_passwd {
    my $prompt = shift;
    my ($PASS, $oldhandler);

    $prompt = "Password:" if ($prompt eq "");

    $oldhandler = $SIG{"INT"};
    $SIG{"INT"} = \&sigint_handler;
    system "stty -echo";
    print "$prompt ";
    chop ($PASS = <STDIN>);
    print "\n";
    system "stty echo";
    $SIG{"INT"} = $oldhandler;

    $PASS;
}

sub sigint_handler {
    system "stty echo";
    for (@@success) { print "$_ changed\n" }
    for (@@failures) { print "$_ NOT CHANGED\n" }
    exit;
}
@


1.2
log
@*** empty log message ***
@
text
@d5 1
a5 1
# Jim Trocki
d7 1
a7 1
# $Id: a3compasswd,v 1.1 1999/01/29 17:41:07 trockij Exp trockij $
d9 15
d34 5
d40 4
d54 4
d59 3
d65 1
a65 1
    print "all switches updated successfully\n";
d72 1
a72 1
print STDERR "#\n# failures occurred:\n#\n";
d101 2
@


1.1
log
@Initial revision
@
text
@d7 1
a7 1
# $Id$
d15 3
d33 4
a36 1
exit (0) unless @@failures != 0;
d38 3
@
