#!/usr/bin/perl -w
# $Id$
# This script is maintained by Rdiger Beck
# It is Free Software (License GPLv3)
# If you find errors, contact the author
# jeffbeck@web.de  or  jeffbeck@gmx.de



# Usage:
# set_passwords
#   -> set passwords from user_db (user.protokoll from old server)
#
# set_passwords --kill
#   -> mark accounts as killable where no password can be found in
#      user_db (user.protokoll)


# Bibliotheken
use strict;
use Getopt::Long;
Getopt::Long::Configure ("bundling");
use Sophomorix::SophomorixConfig;
use Sophomorix::SophomorixBase;
use Sophomorix::SophomorixAPI;
use DBI;
use Net::LDAP;

use Sophomorix::SophomorixPgLdap qw(db_connect
                                    db_disconnect
                                   );
my ($opt)=@ARGV;
if (not defined $opt){
    $opt="";
}


my @ws=&fetchcomputers_from_school();

foreach my $ws (@ws){

       my $command="sophomorix-passwd --force -u $ws --pass 12345678";
       print "$command \n";
       system("$command");
}






sub fetchcomputers_from_school {
    # fetch all subclasses
    my @rooms=();
    my $dbh=&db_connect();
    my $sth= $dbh->prepare( "SELECT uid
                             FROM userdata 
                             WHERE (homedirectory LIKE '/dev/null'
                               AND uid LIKE '%\$')
                             ORDER BY uid");
    $sth->execute();
    my $array_ref = $sth->fetchall_arrayref();
    my $i=0;
    foreach ( @{ $array_ref } ) {
        my $gid=${$array_ref}[$i][0];
        push @rooms, $gid;
        $i++;
    }   
    &db_disconnect($dbh);
    return @rooms;
}
