Jump to content

Recommended Posts

Posted

I knocked this script up this morning because the teachers are trying to force teachers to start using their emails, trouble is half of them have used it once and forgotten their pw's. This script is just a mass password reset at the moment, but i will be adding more features soon. If anyone is interested i will keep you updated. Anyway, thoughts and improvements are welcome :)

 

#!/usr/bin/perl
#mylgfl script - reset all passwords
#by josh hall for BBEC

use strict;
use warnings;
use Getopt::Long;
use LWP::UserAgent;
use HTTP::Request::Common;

my %options;
GetOptions( \%options,    'user=s',
		  'pass=s',
		  'domain=s',
		  'password=s',
		);

help() unless $options{'domain'};

my $username = $options{'user'} . '@' . $options{'domain'};

my $ua = LWP::UserAgent->new();
$ua->cookie_jar({});
$ua->agent('Mozilla/5.0');
$ua->env_proxy();
push @{ $ua->requests_redirectable }, 'POST';

#ok now we need to login
my $check = $ua->request(GET 'http://www.lancsngfl.ac.uk/email-admin/login.php');

$check = $ua->request(POST 'http://www.lancsngfl.ac.uk/email-admin/login.php',
		   [ do => 'login',
		     user => $username,
		     password => $options{'pass'},
		     submit => 1,
		   ],
	 	);

die "You are not logged in\n" unless $check->content =~ /Logged in as/;

#grab all the usernames
$check = $ua->request(GET 'http://www.lancsngfl.ac.uk/email-admin/view.php');
print $check->content();
my @users = $check->content() =~ /(\w+)@[a-z\.]+<\/td>/g;

#reset all users
for my $user (@users) {
print "Resetings User: $user\n";
edituser($user, $options{'password'})
}

sub edituser {
my ($username, $password) = @_;
my ($surname, $initial) = $username =~ /(\w+)([a-z0-9])$/;
my $check = $ua->request(POST 'http://www.lancsngfl.ac.uk/email-admin/edit.php',
		[ task => 'editSingle',
		  uid => $username,
		  forename => $initial,
		  surname => $surname,
		  password => $password,
		  password2 => $password,
		],
	);
}

sub help {
print <<"ENDDOC";
--------------------------------------------
MYLGFL all user Password reset version 0.1
Code grabs all usernames from view.php and then
proceeds to reset the passwords to one you specified.

Usage:
perl mylgflreset.pl
-user LGFLADMIN 
-pass LGFLPASSWORD 
-domain SCHOOLDOMAIN 
-password DEFAULTPASSWORD
ENDDOC
exit;
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...