Dynamic user creating with PHP
Moderator: Project members
Dynamic user creating with PHP
i want to create FTP users with my application (made with PHP). I know that server keeps user setting in "FileZilla Server.xml" file. I can insert all info for user creating except user's password.
How can i insert user's password. Is there any encrypt function or algorithm.
regards
How can i insert user's password. Is there any encrypt function or algorithm.
regards
This has been answered before, remember to search the forums before posting a new topic.
http://filezilla.sourceforge.net/forum/ ... php?t=1317
(it's vbscript but you get the picture)
Think there are other posts on the subject as well, just search here on in the sf.net forums.
http://filezilla.sourceforge.net/forum/ ... php?t=1317
(it's vbscript but you get the picture)
Think there are other posts on the subject as well, just search here on in the sf.net forums.
All php add user
Code: Select all
//user info
$username = "test2";
$password = md5("password");
$userDir = "D:";
//location of filezilla
$fileloc = "C:/FileZillaFTP/";
$filelocfile = ($fileloc."FileZilla Server.xml");
//echo $filelocfile;
////////////////
// 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="test2');//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 . date("Y-m-d;H-i-s")." FileZilla Server.xml" );
// 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"/>
<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>
<Permission Dir=".$userDir.">
<Option Name="FileRead">' . $fileread . '</Option>
<Option Name="FileWrite">' . $filewrite . '</Option>
<Option Name="FileDelete">' . $filedelete . '</Option>
<Option Name="FileAppend">' . $fileappend . '</Option>
<Option Name="DirCreate">' . $dircreate . '</Option>
<Option Name="DirDelete">' . $dirdelete . '</Option>
<Option Name="DirList">' . $dirlist . '</Option>
<Option Name="DirSubdirs">' . $dirsubdirs . '</Option>
<Option Name="IsHome">1</Option>
<Option Name="AutoCreate">0</Option>
</Permission>
</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
passthru($fileloc.'filezillaserver.exe /reload-config');
Echo (" filezilla reloaded, user active");
}else{
echo "user name ".$username." already used";//did not add user, user name already used
}
////////////////
// end add filezilla user
////////////////
i see there are a few command line aruguments that can be used
but is there one for adding user or deleting a userStarting and stopping the service:
/start
/stop
Installing the service for manual startup:
/install
Installing the service for start at boot:
/install auto
Uninstalling service
/uninstall
Reloading configuration at runtime
/reload-config
Start and stop can be used together with /compat:
/compat start
/compat stop
That will start FileZilla Server as normal application and not as a service. Main purpose is for debugging.
Re: All php add user
I tried this, but it seems that command is somehow rejecterd becouse the server doesn't reload itselfcooperspc wrote:Code: Select all
... //added user now reload FileZilla Server XML file to add user passthru($fileloc.'filezillaserver.exe /reload-config'); Echo (" filezilla reloaded, user active"); ...
I also tried exec() and system() but it doesn't work either. Any idea what can i do ?
Thanks
EDiT: Found mistake
Code: Select all
passthru('"' . $fileloc . 'FileZilla Server.exe" /reload-config');
Improved add-user function
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
////////////////
}
?>
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
-
- 504 Command not implemented
- Posts: 6
- Joined: 2005-12-18 10:24
reload config command gotcha
for those who arent having any luck, instead of
"FileZilla Server.exe" /reload-config
use
"FileZilla Server.exe" -reload-config
just a gotcha - the /reload-config just pops up a message box, cos it isnt recognised on the latest version
"FileZilla Server.exe" /reload-config
use
"FileZilla Server.exe" -reload-config
just a gotcha - the /reload-config just pops up a message box, cos it isnt recognised on the latest version