#!/usr/local/bin/perl # script by marcel@kraan.net use DBI; use Crypt::SmbHash; $dserver = "localhost"; $ddatabase = "radius"; $duser = "radius"; $dpassword = "radpass""; undef $usercheck; undef $doublecheck; $dbh = DBI->connect("DBI:mysql:database=$ddatabase;host=$dserver", "$duser", "$dpassword")||die "login/dbase/passwd/host error"; $username = $ARGV[0]; $password = $ARGV[1]; if ( !$password ) { print "Not enough arguments\n"; print "Usage: $0 username password\n"; exit 1; } ntlmgen $password, $lm, $nt; $query = "SELECT username from radcheck where username = '$username'"; $sth = $dbh->prepare("$query"); die $dbh->errstr unless $sth && $sth->execute; while(@row = $sth->fetchrow) { $usercheck = $row[0]; } if ($usercheck){ print "user: $username already exist\n"; }else{ &useradd; $query = "SELECT username from radcheck where username = '$username'"; $sth = $dbh->prepare("$query"); die $dbh->errstr unless $sth && $sth->execute; while(@row = $sth->fetchrow) { $doublecheck = $row[0]; } if ($doublecheck){ print "user $username succesfully added to the database\n"; } } sub useradd { $query = "INSERT INTO radcheck (username,attribute,value) VALUES ('$username','NT-Password','$nt')"; $sth = $dbh->prepare("$query"); die $dbh->errstr unless $sth && $sth->execute; }