PHP adduser
Okay, here's the script I have at the moment:
if (isset($HTTP_POST_VARS["submit"]))
{
for ($i = 0; $i < 9; $i++)
{
$tmp_rand = rand(48,90);
$salt_temp .= chr($tmp_rand);
}
$salt_2 = "$1$".substr($salt_temp,0,8)."$";
$salt .= "$1$".$salt_temp."$";
echo $salt."<br>".$salt_2."<br>";
$passwd = crypt($HTTP_POST_VARS["dpasswd"],$salt);
echo $passwd."<br>";
//
$cmd = "sudo /usr/sbin/adduser"; // Base Command
$cmd .= " -g pppusers"; // Group Setting
//$cmd .= " -p ".chr(34).$HTTP_POST_VARS["dpasswd"].chr(34); // Password
$cmd .= " -p ".chr(34).$passwd.chr(34);
$cmd .=" -c ".chr(34).$HTTP_POST_VARS["realname"].chr(34); // Comment section, IE Realname
$cmd .= " -s /sbin/nologin"; // Shell
$cmd .= " -d /home/pppusers/".$HTTP_POST_VARS["dusername"]; // Home Directory
$cmd .=" ".$HTTP_POST_VARS["dusername"]; // Username
$oput;
echo $cmd."<br>";
// $args = array("/usr/sbin/adduser","-g pppusers","-p ".$passwd,$HTTP_POST_VARS["dusername"],"-c ".$HTTP_POST_VARS["realname"]);
exec($cmd,$oput,$stdout);
if ($stdout == 0)
{
echo "Success";
}
else
{
foreach ($oput as $op)
{
echo $op."<br>";
}
echo $cmd;
}
}
As you can tell, I'm trying to add a user to the system, well, this works, all except the password portion. I can't get that to work quite right. This is a redhat 7.3 system (Why upgrade when things work nicely). Any ideas from the guru's?
Thanks,
Tibby
|