Thanks for all the help in advanced (yes I am new to php or should I say have limited exposure). The code below works in all aspects when doing checking like print "user exists"; or print "user doesn't exist";. I just want to change those two little lines to jump statements or goto (just no sure how to in php).
And yes before you say anything about security etc.. this code is for internal network use only and will not be on the internet!
This is what I want to change in the code:
//Make sure the User exists in Windows ADS
$userid = exec ("sudo getent passwd | grep $user");
if(($userid)){
//print "user exists"; I want it to skip down to "Make sure the User Account isn't already configured"
}else {
//print "doesn't exist"; I want it to do header("Location: failed.php");
CODE:
<?php
//Get information from post
$user = $_POST['username'];
//Make sure the User exists in Windows ADS
$userid = exec ("sudo getent passwd | grep $user");
if(($userid)){
//print "user exists"; I want it to skip down to "Make sure the User Account isn't already configured"
}else {
//print "doesn't exist"; I want it to do header("Location: failed.php");
}
//Make sure the User Account isn't already configured
$userpasswd = "/home/$user/etc/passwd";
if(file_exists($userpasswd)){
header("Location: exists.php");
}else {
//Execute mkdir
$mkdiruser = exec ("mkdir -m 751 /home/$user");
$inbound = exec ("mkdir -m 770 /home/$user/inbound");
$outbound = exec ("mkdir -m 770 /home/$user/outbound");
$test = exec ("mkdir -m 770 /home/$user/test");
$ssh = exec ("mkdir -m 700 /home/$user/.ssh");
//Execute Change Owner of Directories
$chuser = exec ("sudo chown $user /home/$user");
$chinbound = exec ("sudo chown $user /home/$user/inbound");
$choutbound = exec ("sudo chown $user /home/$user/outbound");
$chtest = exec ("sudo chown $user /home/$user/test");
$chssh = exec ("sudo chown $user /home/$user/.ssh");
//Execute Change Group Owner of Directories
$chguser = exec ("sudo chgrp \"Domain Users\" /home/$user");
$chginbound = exec ("sudo chgrp \"Domain Users\" /home/$user/inbound");
$chgoutbound = exec ("sudo chgrp \"Domain Users\" /home/$user/outbound");
$chgtest = exec ("sudo chgrp \"Domain Users\" /home/$user/test");
$chgssh = exec ("sudo chgrp \"Domain Users\" /home/$user/.ssh");
//Unzip scponly.zip to user home dir
$unzip = exec("sudo /usr/bin/unzip -d /home/$user/ /usr/local/src/scponly.zip");
//Change file permissions to write ALL
$write = exec ("sudo chmod 666 /home/$user/etc/passwd");
//Pipe user UID into users/etc/passwd file
$filename = ("/home/$user/etc/passwd");
$getent = exec ("sudo getent passwd | grep $user");
$somecontent = "$getent\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
} else {
echo "The file $filename is not writable";
}
//Change file permissions back
$write = exec ("sudo chmod 644 /home/$user/etc/passwd");
//Print results of make direcotries
header("Location: success.php");
}
?>