So we can only find a way to get webserver to call this command, usually want to improve the permissions only Su and sudo these two commands, so I put the idea on this, but the results call the two commands are still not, search on the internet to know can modify the sudo configuration to achieve the effect I want, Okay, no more nonsense, let's get down to business.
First confirm that the sudo command is installed
Then modify the/etc/sudoers
Because/etc/sudoers is a read-only file, you use Visudo to modify it.
Add a line to the end
User name All=nopasswd:/usr/sbin/useradd
The username above is changed to your username for executing the webserver program.
For example, the Apache default username is Apache.
And then use the following PHP code to do it (in the main place has been marked on the note)
PHP Code: (Please remove the space after <, otherwise it will not be used normally)
The code is as follows:
Header ("content-type:text/html; Charset=utf-8 ");
Header ("Cache-control:no-cache, must-revalidate");
Header ("Pragma:no-cache");
Echo ' < pre> ';
$submit = $_get[' Submit '];
$username = $_get[' username '];
$pass = $_get[' Pass '];
$password = Crypt ($pass); Encrypt the password with crypt
$edate = $_get[' edate '];
$self = $_server[' php_self '];
Echo ' < form methode= ' get ' action= ' > ';
Echo ' username < input type= ' text ' name= ' username ' ></input> ';
Echo ' Password < input type= ' text ' name= ' pass ' ></input> ';
Echo ' Validity < input type= ' text ' name= ' edate ' ></input> ';
Echo ' < input type= "submit" class= "Ssubmit" name= "Submit" value= "submit" ></input> ";
Echo ' </form> ';
If ($submit = = "Submit")
{
$expire _date = Date ("Y-m-d", Time () + ($edate *24*60*60));
echo $username;//user name
Echo ' < br/> ';
echo $pass;/password plaintext
Echo ' < br/> ';
echo $edate//Validity period
Echo ' < br/> ';
echo $expire _date;//Due Date
Echo ' < br/> ';
System ("/usr/bin/sudo/usr/sbin/useradd-e $expire _date-p $password $username");
}
Echo ' </pre> ';
Main function Description
The code is as follows:
$username User Name
$pass Password PlainText
$password encrypt the password with crypt
$edate Validity
$expire _date Due Date