dear members !

In my job i jst face this problem with one of our PHP based sites.

what this script does is that asks users for some inoformation when they want to have a folder in one of our web servers.
now the problem is that when they submit their information it gaves the user an ID that already is assigned to someone.
I am not a programer my job is networking and server managment soo if anyone knows the problem please let me know as soon as possible :)

here is the script

<?php
$host = "ldap1.unomaha.edu";
$base = "dc=unomaha,dc=edu";
$gbase = "ou=groups,$base";
$pbase = "ou=people,$base";
$log = "/var/log/groupman.log";
function stdin($ask)
{
print "$ask: ";
$stdin = fopen("php://stdin","r");
$answer = fgets($stdin,1024);
$answer = trim($answer);
if ($ask != "Your LDAP password")
{
$answer = strtolower($answer);
}
fclose($stdin);
if ($answer == 'q')
{
exit("Goodbye\n");
}
return $answer;
}
function pause()
{
print "\n";
$answer = stdin("Enter 'm' for menu, or 'q' to quit");
}
function notnull($ask)
{
do
{
$answer = stdin($ask);
} while ($answer == "");
return $answer;
}
function get_member_values()
{
global $ds, $base, $uid, $host_array;
$sr = ldap_search($ds,$base,"uid=$uid");
$entry = ldap_first_entry($ds,$sr);
$host_array = ldap_get_values($ds,$entry,"host");
ldap_free_result($sr);
}
function get_group_values($cn)
{
global $ds, $base, $gecos, $homedirectory, $owner, $seealso, $member_count, $uniquemember_netid_array;
$sr = ldap_search($ds,$base,"cn=$cn");
$entry = ldap_first_entry($ds,$sr);
$gecos_array = ldap_get_values($ds,$entry,"gecos");
$homedir_array = ldap_get_values($ds,$entry,"homedirectory");
$owner_array = ldap_get_values($ds,$entry,"owner");
$seealso_array = ldap_get_values($ds,$entry,"seealso"); 
$uniquemember_array = ldap_get_values($ds,$entry,"uniquemember");
$gecos = $gecos_array[0];
$homedirectory = $homedir_array[0];
$owner_dn = $owner_array[0]; 
$owner_netid = ldap_explode_dn($owner_dn,1);
$owner = $owner_netid[0];
$seealso_dn = $seealso_array[0];
$seealso_netid = ldap_explode_dn($seealso_dn,1);
$seealso = $seealso_netid[0];
$member_count = $uniquemember_array["count"];
for ($i=0; $i<$uniquemember_array["count"]; $i++) 
{
$uniquemember_dn = $uniquemember_array[$i];
$uniquemember_netid = ldap_explode_dn($uniquemember_dn,1);
$uniquemember = $uniquemember_netid[0]; 
$uniquemember_netid_array[$i] = $uniquemember;
}
ldap_free_result($sr);
}
function group_exists($cn)
{
global $ds, $gbase;
$sr = ldap_search($ds,$gbase,"cn=$cn");
$count = ldap_count_entries($ds,$sr);
if ($count == 0) {
print "group does not exist\n";
}
return $count;
}
function group_not_exists($cn)
{
global $ds, $gbase;
$sr = ldap_search($ds,$gbase,"cn=$cn");
$count = ldap_count_entries($ds,$sr);
if ($count > 0)
{
print "group exists\n";
}
return $count;
}
function member_exists($uid)
{
global $ds, $pbase;
$sr = ldap_search($ds,$pbase,"uid=$uid");
$count = ldap_count_entries($ds,$sr);
return $count;
}
function add_host($uid)
{
global $ds, $pbase, $host_array, $log;

@get_member_values($uid);
$rec["host"][0] = "avalon.unomaha.edu"; 
$rec["host"][1] = "avalon1.unomaha.edu"; 
$rec["host"][2] = "avalon2.unomaha.edu"; 
if (!(in_array($host_array,$rec)))
{
$member_dn = "uid=$uid,$pbase\n";
$ldapmodadd = ldap_mod_add($ds,$member_dn,$rec);
}
}
function remove_host($uid)
{
global $ds, $pbase, $base;

$member_dn = "uid=$uid,$pbase";
$sr = ldap_search($ds,$base,"uniquemember=$member_dn");
$entry = ldap_first_entry($ds,$sr);
$count = ldap_count_entries($ds,$sr);
if ($count == 1) {
$rec["host"][0] = "avalon.unomaha.edu";
$rec["host"][1] = "avalon1.unomaha.edu";
$rec["host"][2] = "avalon2.unomaha.edu";
$ldapmoddel = ldap_mod_del($ds,$member_dn,$rec);
}
}
function mk_home_dir($uid)
{
system("mkdir /home/$uid");
system("chmod 700 /home/$uid");
system("cp /etc/skel/.bashrc /home/$uid/.bashrc");
system("cp /etc/skel/.bash_profile /home/$uid/.bash_profile");
system("cp /etc/skel/.bash_logout /home/$uid/.bash_logout");
system("chmod 644 /home/$uid/.bashrc /home/$uid/.bash_profile /home/$uid/.bash_logout");
system("chown -R $uid.$uid /home/$uid");
}
function show_group($cn)
{
global $ds, $base, $gecos, $homedirectory, $owner, $seealso, $member_count, $uniquemember_netid_array;
print "\ndescription:\n";
print " $gecos\n";
print "\nhome directory:\n";
print " $homedirectory\n";
print "\nprimary contact:\n";
print " $owner\n";
print "\nsecondary contact:\n";
print " $seealso\n";
print "\neditors:\n";
for ($i=0; $i<$member_count; $i++) 
{
print " $uniquemember_netid_array[$i]\n";
}
}
function show_member($uid)
{
global $ds, $pbase, $base;
$member_dn = "uid=$uid,$pbase";
$sr = ldap_search($ds,$base,"owner=$member_dn"); 
$entry = ldap_get_entries($ds,$sr);
print "\nprimary contact on:\n";
for ($i=0; $i < $entry["count"]; $i++)
{
print " " . $entry[$i]["cn"][0] . "\n"; 
}
$sr = ldap_search($ds,$base,"seealso=$member_dn"); 
$entry = ldap_get_entries($ds,$sr);
print "\nsecondary contact on:\n";
for ($i=0; $i < $entry["count"]; $i++)
{
print " " . $entry[$i]["cn"][0] . "\n"; 
}
$sr = ldap_search($ds,$base,"uniquemember=$member_dn"); 
$entry = ldap_get_entries($ds,$sr);
print "\neditor on:\n";
for ($i=0; $i < $entry["count"]; $i++)
{
print " " . $entry[$i]["cn"][0] . "\n"; 
}
}
function get_uidnumber()
{
global $ds, $gbase;
$sr = ldap_search($ds,$gbase,"uidnumber=*");
$info = ldap_get_entries($ds,$sr);
$highuid = 0;
for ( $i=0; $i<$info["count"]; $i++ ) 
{
$thisuid = $info[$i]["uidnumber"][0];
if ($thisuid > $highuid) 
{
$highuid = $thisuid;
}
}
$highuid++;
return $highuid;
}
function send_mail_message($cn,$recipients)
{
$special = stdin("List actions taken regarding Special Instructions");
if ($special == "") {
$special = "None";
}
$mailmsg = "/root/bin/new_group_msg";
$email = fopen($mailmsg,"w");
fputs($email,"From: UNO Helpdesk <unohelpdesk@mail.unomaha.edu>\n");
fputs($email,"To: $recipients\n");
fputs($email,"Subject: Your web space request - $cn\n");
fputs($email,"Hello. Your organizational account on the campus webserver has been created.\n\n");
fputs($email,"Host: www.unomaha.edu\n");
fputs($email,"URL: http://www.unomaha.edu/$cn\n");
fputs($email,"Directory: /web/$cn\n\n");
fputs($email,"To access your organizational directory, log on to www.unomaha.edu with your UNO NetID and password using a secure FTP client, such as WinSCP (Windows) or MacSSH (Macintosh), then change directory to '/web/$cn'.\n\n");
fputs($email,"You may download WinSCP or MacSSH from http://install.unomaha.edu.\n\n");
fputs($email,"Regarding your Special Instructions:\n");
fputs($email,"$special\n\n");
fputs($email,"UNO Helpdesk\n");
fputs($email,"unohelpdesk@mail.unomaha.edu\n");
fputs($email,"402-554-4917\n");
fclose($email);
`echo "" | mutt -H $mailmsg`;
}
function add_group($cn)
{
global $ds, $base, $pbase, $gbase, $log;
$gecos = notnull("brief description");
$homedirectory = "/web/$cn";
do 
{
$owner = notnull("primary contact netid");
} while (!member_exists($owner));
@add_host($owner);
$recipients .= "$owner@mail.unomaha.edu";
do
{ 
$seealso = notnull("secondary contact netid");
} while ((!member_exists($seealso)) || ($seealso == $owner));
@add_host($seealso);
$recipients .= ",$seealso@mail.unomaha.edu";
$j = 2;
do
{
$editor = stdin("editor");
if (member_exists($editor)) 
{
@add_host($editor);
$uniquemember[$j] = "uid=$editor,$pbase";
$j++;
$recipients .= ",$editor@mail.unomaha.edu";
}
} while ($editor != "");
$uidnumber = get_uidnumber();
$entry["cn"] = $cn;
$entry["objectclass"][0] = "top";
$entry["objectclass"][1] = "posixAccount";
$entry["objectclass"][2] = "posixGroup";
$entry["objectclass"][3] = "groupofuniquenames";
$entry["uid"] = $cn;
$entry["uidnumber"] = $uidnumber;
$entry["gidnumber"] = $uidnumber;
$entry["gecos"] = $gecos;
$entry["homedirectory"] = "$homedirectory";
$entry["owner"] = "uid=$owner,$pbase";
$entry["seealso"] = "uid=$seealso,$pbase";
$entry["uniquemember"][0] = "uid=$owner,$pbase";
$entry["uniquemember"][1] = "uid=$seealso,$pbase";
for ($i = 2; $i < $j; $i++) 
{
$entry["uniquemember"][$i] = "$uniquemember[$i]";
}

$recipients .= ",unohelpdesk@mail.unomaha.edu";
print "please wait... ";
$dn = "cn=$cn,$gbase";
$ldapadd = ldap_add($ds,$dn,$entry);
if ($ldapadd) 
{
print "$cn added\n";
send_mail_message($cn,$recipients);
sleep(10);
$creategrouphomedir = system("/root/bin/create_group_homedir $cn");
if ($creategrouphomedir == 0) {
print "Group home directory created\n";
system("edquota -p groupquota -g $cn");
$now = date("D M j G:i:s T Y");
$fp = fopen($log,"a+");
fputs($fp,"$now: $cn CREATED (contacts: $owner, $seealso)\n");
fclose($fp); 
}
}
}
function delete_group($cn)
{
global $ds, $gbase, $member_count, $uniquemember_netid_array, $log;
show_group($cn);

$answer = stdin("\nAre you sure you want to delete this group [y/n]");
if ($answer == "y") 
{
$per = notnull("NetID requesting group deletion");
for ($i=0; $i < $member_count; $i++) 
{
$uid = $uniquemember_netid_array[$i];
remove_host($uid);
}

print "please wait... ";
$dn = "cn=$cn,$gbase";
$ldapdelete = ldap_delete($ds,$dn);
if ($ldapdelete)
{
print "$cn deleted. Remember to remove the group directory.\n";
$now = date("D M j G:i:s T Y");
$fp = fopen($log,"a+");
fputs($fp,"$now: $cn DELETED (per: $per)\n");
fclose($fp); 
}
} 
}
function add_member($cn)
{
global $ds, $gbase, $pbase;
show_group($cn);
print "\n";
$uid = notnull("Member NetID to add");
if (!member_exists($uid))
{
print "$uid does not exist\n";
}
else
{
$uidarray[] = $uid;
$member_dn = "uid=$uid,$pbase"; 
$group_dn = "cn=$cn,$gbase";
$rec["uniquemember"][] = $member_dn;
$ldapmodadd = @ldap_mod_add($ds,$group_dn,$rec);
@add_host($uid);
if (!(is_dir("/home/$uid"))) 
{
$mkhomedir = mk_home_dir($uid);
system("/usr/sbin/edquota -p userquota -u $uid");
if ($mkhomedir == 0) 
{
print "$uid home directory created\n";
}
else
{
print "$uid home directory create failed\n";
}
}
if ($ldapmodadd) 
{
print "$uid added to $cn\n";
}
else
{
print "$uid add failed\n";
}
}
}
function delete_member($cn, $uid)
{
global $ds, $gbase, $pbase;
show_group($cn);
print "\n";
if ($uid == "")
{
$uid = notnull("Member NetID to delete");
}
if (!member_exists($uid))
{
print "$uid does not exist\n";
}
else
{
$member_dn = "uid=$uid,$pbase";
$group_dn = "cn=$cn,$gbase";
$rec["uniquemember"][] = $member_dn;
$ldapmoddel = @ldap_mod_del($ds,$group_dn,$rec);

if ($ldapmoddel)
{
print "$uid deleted from $cn\n";
}
else
{
print "$uid delete from $cn failed\n";
}
@remove_host($uid);
}
}
function change_contact($cn,$role,$prompt)
{
global $ds, $gbase, $pbase, $owner, $seealso, $uniquemember_netid_array, $log;
show_group($cn);
print "\n";
$uid = notnull($prompt);
if (!member_exists($uid))
{
print "$uid does not exist\n";
}
else
{
if ($role == "owner") 
{
$oldrole = $owner;
}
else
{
$oldrole = $seealso;
}
@remove_host($oldrole);
delete_member($cn,$oldrole); 
$member_dn = "uid=$uid,$pbase";
$group_dn = "cn=$cn,$gbase";
$rec["$role"][0] = $member_dn;
$ldapmodreplace = @ldap_mod_replace($ds,$group_dn,$rec);
if ($ldapmodreplace)
{
print "$role successfully changed\n";
$now = date("D M j G:i:s T Y");
$fp = fopen($log,"a+");
fputs($fp,"$now: $cn CHANGED $role (old: $oldrole, new: $uid)\n");
fclose($fp);
}
else
{
print "$role change failed\n";
}
$uidarray[] = $uid;
if (!(in_array($uniquemember_netid_array,$uidarray)))
{
$rec2["uniquemember"][] = $member_dn;
$ldapmodadd = @ldap_mod_add($ds,$group_dn,$rec2);
@add_host($uid);
}
}
}
function menu()
{
print "\n";
print "---------------------------------------------\n";
print " avalon group management\n"; 
print "---------------------------------------------\n";
print " [0] show group\n";
print " [1] add a group\n";
print " [2] delete a group\n";
print " [3] add a member to a group\n";
print " [4] remove member from a group\n";
print " [5] change group primary contact\n";
print " [6] change group secondary contact\n";
print " [7] show member\n";
print " [q] quit\n";
print "---------------------------------------------\n";
$answer = stdin("[0-6]");

switch($answer)
{
case 0: 
$cn = notnull("group name");
if (group_exists($cn)) 
{
get_group_values($cn);
@show_group($cn);
pause();
}
menu(); 
case 1;
$cn = notnull("group name");
if (group_exists($cn))
{
}
else
{
add_group($cn);
sleep(10);
system("/root/bin/create_group_homedir $cn");
}
menu();
case 2:
$cn = notnull("group name");
if (group_exists($cn))
{
get_group_values($cn);
delete_group($cn);
pause();
}
menu();
case 3:
$cn = notnull("group name");
if (group_exists($cn))
{
get_group_values($cn);
add_member($cn);
pause();
}
menu();
case 4:
$cn = notnull("group name");
if (group_exists($cn))
{
get_group_values($cn);
delete_member($cn,"");
pause();
}
menu();
case 5:
$cn = notnull("group name");
if (group_exists($cn))
{
get_group_values($cn);
change_contact($cn,"owner","New primary contact NetID");
pause();
}
menu();
case 6:
$cn = notnull("group name");
if (group_exists($cn))
{
get_group_values($cn);
change_contact($cn,"seealso","New secondary contact NetID");
pause();
}
menu();
case 7:
$uid = notnull("member NetID");
show_member($uid);
menu();
case 'q':
exit ("Goodbye\n");
default:
menu();
}
}
$ds = @ldap_connect($host);
if (!$ds) 
{ 
die("Cannot CONNECT to LDAP server\n"); 
}
$login = @notnull("your LDAP login");
system('stty -echo');
$pw = @notnull("Your LDAP password");
system('stty echo');
$ldapbind = @ldap_bind($ds,"uid=$login,$pbase",$pw);
if (!$ldapbind)
{
die("Cannot BIND to LDAP server\n");
}
menu();
?>

Do you think your boss is ok with you posting this? Beside that, can't you trace the problem down to a specific piece fo code? This is to big for me to wade through.

To I like code that's indented.

it is not a project or soemthing like boss thing or etc....

i jst needed to figure the probelm in code out in order to move on with setting the server up. i am not a programer to narrow the code down but the problem is that the script gives users not a unique ID it gaves them the id that already is in use :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.