PHP Create a Linux account with expiration

Source: Internet
Author: User
Tags crypt php code

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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.