Dynamic user creating with PHP

Need help with FileZilla Server? Something does not work as expected? In this forum you may find an answer.

Moderator: Project members

Post Reply
Message
Author
itunali
500 Command not understood
Posts: 1
Joined: 2005-09-07 08:28

Dynamic user creating with PHP

#1 Post by itunali » 2005-09-07 08:35

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

eddan
226 Transfer OK
Posts: 423
Joined: 2004-02-25 08:44
Location: Norway

#2 Post by eddan » 2005-09-07 08:42

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.

User avatar
botg
Site Admin
Posts: 35492
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse

#3 Post by botg » 2005-09-07 08:53

After updating the xml file, call 'FileZilla Server.exe' with the -reload-config commandline argument, that will make FZS to reload it's config.

cooperspc
226 Transfer OK
Posts: 94
Joined: 2005-10-21 15:21
Location: Indiana USA

All php add user

#4 Post by cooperspc » 2006-05-02 22:55

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
////////////////

cooperspc
226 Transfer OK
Posts: 94
Joined: 2005-10-21 15:21
Location: Indiana USA

#5 Post by cooperspc » 2006-05-08 01:49

i see there are a few command line aruguments that can be used
Starting 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.
but is there one for adding user or deleting a user

Limona
500 Command not understood
Posts: 1
Joined: 2006-05-08 11:28

Re: All php add user

#6 Post by Limona » 2006-05-08 11:31

cooperspc 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 tried this, but it seems that command is somehow rejecterd becouse the server doesn't reload itself :cry:
I also tried exec() and system() but it doesn't work either. Any idea what can i do ?

Thanks

EDiT: Found mistake :P

Code: Select all

passthru('"' . $fileloc . 'FileZilla Server.exe" /reload-config');
Obviously there were missing "" :lol:

dbr
500 Command not understood
Posts: 2
Joined: 2006-06-23 20:52

Improved add-user function

#7 Post by dbr » 2006-06-23 21:01

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 :oops: 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 :wink: :P
- Ben

shimmyshack
504 Command not implemented
Posts: 6
Joined: 2005-12-18 10:24

reload config command gotcha

#8 Post by shimmyshack » 2006-09-02 18:43

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

Post Reply