#!/usr/bin/perl -I/usr/sausalito/perl
##########################################################################
#                                                                        #
#               Copyright (C) 1999-2000, Cobalt Networks, Inc            #
#                          All rights reserved                           #
#                                                                        #
# Filename: reset_password                                               #
#                                                                        #
# Author(s): Timothy Stonis                                              #
#            Patrick Bose - worked into CCE/i18n                         #
#                                                                        #
# Description: Reset script activated by LCD panel. Sets admin password  #
#              to "".  Also sets the shell to /bin/bash.                 #
#                                                                        #
##########################################################################

use CCE;
use I18n;
use LCD;

my $i18n = new I18n;
my $language = &LCD::get_locale();
$i18n->setLocale($language) if (defined $language);

$line1 = $i18n->get("[[base-lcd.RESETTING ADMIN ]]");
$line2 = $i18n->get("[[base-lcd.   PASSWORD     ]]");

# We're going to be nasty here and remove the lock lcdsleep put in here. 
system("/bin/rm -f /etc/locks/.lcdlock") if (-e "/etc/locks/.lcdlock");

# Show what we're doing
system("/sbin/lcd-write \"$line1\" \"$line2\"");

# Let the user see what we're doing since this server is so fast ;-)
sleep 4;

# Reset the password and shell
my $cce = new CCE;
$cce->connectuds();

my (@oids) = $cce->find("User", { 'name' => 'admin' } );
$cce->set( $oids[0], "", { password => 'admin', shell => '/bin/bash' } ) 
    if (@oids > 0);

$cce->bye("SUCCESS");

# Back to the IP display
system("/etc/rc.d/init.d/lcd-showip");

# Put the lock back
system("/bin/touch /etc/locks/.lcdlock");

