It's intended for sharing files with an external comany only for a short time.
The following code is a simple PHP-Site with a dropdown-menu where you can chose the amount of days the account is available. After submitting, the script creates a user with the accordant homedir and with a prefix, the expiredate and a random number in the username (exp. tmp_YYYYMMDD1234)
(Sorry, but the comments in the script are in german)
Code: Select all
<html>
<head>
</head>
<body>
<?
//Formular-Variablen abholen
$i_days = isset($_POST["i_days"]) ? $_POST["i_days"] : 0;
if ($i_days > 0) {
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Variablen setzen
$s_server = 'yourserver:5466'; //Servername & Port des Adminzugangs
$s_admin = 'admin'; //Account mit Administratorberechtigung
$s_adminpwd = 'adminpassword'; //Passwort
$s_domain = 'yourdomain'; //Auf dem WFTPServer eingerichtete Domäne
$s_rootdir = '/data01/tmp_users/'; //Root Verzeichnis (darin wird jeweils ein Verzeichnis mit dem Usernamen erstellt)
$s_group = 'tmp_users'; //Gruppe des neuen Users (Leerlassen falls keine gewünscht)
$s_prefix = 'tmp_'; //Prefix für den Usernamen
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$b_read = 'true';
$b_write = 'true';
$b_delete = 'true';
/* Uncomment this part to have the option to set permissions
$b_read = isset($_POST["b_read"]) ? $_POST["b_read"] : 'false';
$b_write = isset($_POST["b_write"]) ? $_POST["b_write"] : 'false';
$b_delete = isset($_POST["b_delete"]) ? $_POST["b_delete"] : 'false';*/
$expire_stamp = time() + ($i_days * 24 * 60 * 60); //Ablaufzeitpunkt setzen
$expire_date = date('Y-m-d H:i:s', $expire_stamp); //Ablaufzeitpunkt setzen
$strUrl = "http://".$s_server."/admin_webservice.html"; //URL zusammen setzen
$strUrlParam = "?admin=".$s_admin."&pass=".$s_adminpwd."&cmd="; //URL zusammen setzen
$username = $s_prefix.date('Ymd', $expire_stamp).mt_rand(0,9999); //account name (prefix tmp_ / Ablaufdatum / 4-stellige Zufallszahl)
$password = mt_rand(); //account password
$homedir = $s_rootdir.$username; //home directory
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//LUA Script erstellen
//Userverzeichnis erstellen
$strLuaScript = "c_MkDir('".$homedir."')";
//temporären User erstellen
// Parameternummern: 7 10 15 20 25 30 35 40 45 48
$strLuaScript .= "c_AddUser('".$s_domain."','".$username."',md5('".$password."'),63,1,1, '', '', '', '', '', '', '', '', 0, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', {{'".$s_group."'}}, '', '', '', '', '', '', '', '', '', 1,'".$expire_date."', '', '')";
// User-Verzeichnis mit entsprechenden Berechtigungen setzen
$strLuaScript .= "c_AddUserDirectory('".$s_domain."','".$username."','".$homedir."','/',true,".$b_read.",".$b_write.",".$b_write.",".$b_delete.",".$b_read.",".$b_write.",".$b_delete.",".$b_write.")";
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//LUA Script ausführen
$strResult = file_get_contents($strUrl.$strUrlParam.rawurlencode($strLuaScript));
//echo $strLuaScript;
echo 'Username: '.$username.'<br>'.
'Password: '.$password.'<br>'.
'Expires: '.$expire_date.'<br><br>';
echo '<a href='.$PHP_SELF.'>Zurueck</a>';
}
else {
?>
<h1>Neuen temporären User-Account generieren</h1>
<form method="post" action="<?=$PHP_SELF; ?>">
<p>Gültigkeit <select name="i_days">
<option value="1">1 Tag</option>
<option value="2">2 Tage</option>
<option value="5">5 Tage</option>
<option value="10">10 Tage</option>
<option value="20">20 Tage</option>
<option value="30">30 Tage</option>
</select>
</p>
<!-- Uncomment this part to have the option to set permissions
<p>
<input type="checkbox" name="b_read" value="true"> Leseberechtigung<br>
<input type="checkbox" name="b_write" value="true"> Schreibberechtigung<br>
<input type="checkbox" name="b_delete" value="true"> Löschberechtigung<br>
</p> -->
<input type="submit" value="Los geht's">
</form>
<?
}
?>
</body>
</html>
To remove the expired accounts automatically put the following LUA-Script into the task sheduler
Code: Select all
local mydomain = "yourdomain"
local rootdirtmp = "/data01/tmp_users/"
local group = "tmp_users"
do
local strUserlist = c_GetUserList(mydomain)
local userlist = Split(strUserlist,"\n")
for _,username in pairs(userlist) do
local user = c_GetUser(mydomain,username)
local expiretime_t = c_TranslateTime(user.expiretime)
if (os.time() > expiretime_t) and (user.enable_expire == true) and (user.usergroups[1].groupname == group) then
c_DeleteUser(mydomain,username)
c_RemoveFileDir(rootdirtmp .. username)
end
end
end
This is still very basic, but it may helps you to create something similar...
//edit: I made a little change to the deleting script. It checks now if a user is in the tmp_users group...