Code: Select all
<?PHP
//fzs_adduser("[Username]","[Password]","[Group]");
function fzs_adduser($username,$password,$group){
//user info
$username = $username;
$password = md5($password);
$userDir = "D:";
$group=$group;
//location of filezilla
$fileloc = "C:\\Program Files\\FileZilla Server\\";
$filelocfile = ($fileloc."FileZilla Server.xml");
echo "Path : " . $filelocfile . "\n";
////////////////
// start add filezilla user
////////////////
//Check to see if user name is already used
$fp = fopen($filelocfile,"r");
$data = fread($fp,filesize($filelocfile));
$pos1 = strpos($data,'<User Name="' . $username . '"');//find user name
echo (".".$pos1.".");
fclose($fp);
//if user not found .. add
if($pos1 == ""){
echo "adding user......";
// user setting for FileZilla FTP
$fileread = 1; //Files Read 1 = YES 0 = NO
$filewrite = 1; //Files Write
$filedelete = 1; //Files Delete
$fileappend = 1; //Files Append, must have Write on
$dircreate = 1; //Directory Create
$dirdelete = 1; //Directory Delete
$dirlist = 1; //Directory List
$dirsubdirs = 1; //Directory + Subdirs
// Aktuelle Config wird eingelesen
$lines = file($filelocfile);
// Copy Config for backup
rename($filelocfile, $fileloc . "settings_bk\\" . date("Y-m-d;H-i-s")." FileZilla Server.bak" );
// open Config for writing
$file = fopen($filelocfile,"a");
for($i=0; $i < sizeof($lines); $i++)
{
fwrite ($file, $lines[$i]);
// write new information on top of list after "<Users>"
if (strstr($lines[$i],"<Users>"))
{
fwrite($file, '<User Name="' . $username . '">
<Option Name="Pass">' . $password . '</Option>
<Option Name="Group">' . $group . '</Option>
<Option Name="Bypass server userlimit">0</Option>
<Option Name="User Limit">0</Option>
<Option Name="IP Limit">0</Option>
<Option Name="Enabled">1</Option>
<Option Name="Comments"/>
<Option Name="ForceSsl">0</Option>
<IpFilter>
<Disallowed/>
<Allowed/>
</IpFilter>
<Permissions/>
<SpeedLimits DlType="0" DlLimit="10" ServerDlLimitBypass="0" UlType="0" UlLimit="10" ServerUlLimitBypass="0">
<Download/>
<Upload/>
</SpeedLimits>
</User>
');
}
}
// Close xml file
fclose($file);
//added user now reload FileZilla Server XML file to add user
system('"' . $fileloc.'FileZilla server.exe' . '"' . '/reload-config');
echo ("Filezilla reloaded, user active");
return(true);
}else{
echo "user name ".$username." already used";//did not add user, user name already used
return(false);
}
////////////////
// end add filezilla user
////////////////
}
?>
There were a few problems (can't remeber what they were to be honest
nothing huge, just some things weren't as they should), and made it easier to change the username/password etc
It's somewhat setup for my server (Installed to C:\Program Files\Filezilla Server), with two groups, and instead of changing the share folders per-user, I just shove users in one of a few groups
Basicly, include this code (or just the function), then call it like
fzs_adduser("[Username]","[Password]","[Group]");
For example
if(fzs_adduser("dbr","mypassword","mygroup")){
echo("User added succesfully");
} else {
echo("Username taken");
}
(it returns true if it worked, false if not)
If you use this, you might want to scan over the code and make sure everything is setup right
I think you might need to make a folder called settings_bk (Which is where the backups of the filezilla server.xml file gets copied, which is to save cluttering the root folder, and make clearing the backups simple), I'm not sure if it'll auto-create it
Ideally I'd create a few functions, that'd let you list/edit users, and the likes, but not sure if I can
- Ben