|
 |
|
 |
12-14-2005, 05:05 AM
|
#1 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
script giving users ftp access
I've read this can be done with shell_exec(), but I can't find any online documentation on it. The code examples I've seen don't explain the commands which leaves me lost on where to track down the source material so I can apply it.
Anyone know what I'm talking about?
|
|
|
12-14-2005, 07:00 AM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,487
|
are you talking about users on the system the permission to ftp in via an ftp client? .. or doing ftp stuff via php from a web page?
|
|
|
12-14-2005, 10:46 AM
|
#3 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
The first one. Would like to shell_exec in new users, give'em a specific subdir to use, username/pass it... the whole shebang. Doing it manually on the host control panel for all the folks I want to give ftp rights to is a bit time consuming.
|
|
|
12-14-2005, 11:22 AM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,487
|
do you know how to do it manually? the answer is going to be specific to what ftp server you are using and how it can be configured.
you'lle probably have to write a shell to do the work, then like you say, execute that script from PHP. if you need to modify files, your shell script can even be written in PHP.
|
|
|
12-14-2005, 11:46 AM
|
#5 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
"do you know how to do it manually?"
Host has cpanel so it makes the creation of new ftp accounts point and click easy...but not ideal here like I mentioned.
Ftp server being used is PureFTPd.
|
|
|
12-14-2005, 11:56 AM
|
#6 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,487
|
do you have control of the entire server? if not, i doubt you can do it.
if you do, then you need to determine what cpanel is doing when it adds a new account. i'm not familiare with pureftpd, but a place to start might be to look at the configs for it in /etc/
at this point, it's more of a pureftpd configuration or cpanel question. once you find out how to do it, then you can employ PHP to either execute a shell script or modify files itself. you have to make sure it's not going to interfear with the logic cpanel uses to manage ftp accounts. by that, i mean that if you create an account with your own interface, make sure cpanel shows it as well. this way you won't end up with rouge ftp accounts anywhere.
sorry i can't be much help on this one.
|
|
|
12-14-2005, 12:24 PM
|
#7 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
No biggie  helpful enough, I knew this was a decent sized undertaking when I had such a hard time tracking down anything about it via the web.
How much control over the server is necessary btw? One of the things I came across stated that what I'm doing isn't possible if safe mode in php is on and shell_exec, exec, etc. and other like functions are disabled. I checked the server info yesterday and neither is the case.
|
|
|
12-15-2005, 03:50 AM
|
#8 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
|
Thats going to be quite difficult, usualy ftp-servers grants ftp access to users who are members of ftp usergroup and already have a valid shell on the machine, in this case /bin/true (or /bin/false) in order to prevent them from having a valid login shell on the machine.
Since creating a new user with a predefined passwd requires interactive typing/parsing of the password to the passwd program, it is very difficult to provide it as a script, since passwd won't even accept it from a pipe.
I once created a user/adding/modification system in php, but all the specific passwd/useradd actions were wraped in a C program which would send a exit code and then I would let the PHP script decide what went wrong from the exit code generated by the C program, when it was called with shell_exec().
Since Pureftpd provides interaction with mySQL database, you might want to check the documentation and then realise you can easily control you'r users through a simple mySQL user database, if you're used to have php interact with mySQL, then it should be breeze from there on.
You might want to check up on cpanel, if it uses a SQL database, or if it uses /etc/passwd or another form, like virtual users, from the Cpanel documentation it seems to be a non-GPL software, so I can't see and they won't tell how it interacts with your system... But my guess is that since you have to login as root, then it will add/maintain any ftp account through useradd and /etc/passwd, which means you're in for some tough coding in order to make your addition work with Cpanel.
:edit:
From a quote found in their FAQ: There is no plaintext record, even for root, to view clients passwords. The only copies on the server will be in the password hashes in the /etc/proftpd/* files.
I guess they're hevily relying on direct access to the programs configuration files, in this case you're in for some trouble, usualy these files can only be written by root, so if you're planing something like a web-interface where non-root users can handle the ftp-access, you still have to figure out a way to run the requests SUID-root, which isn't easy.
You might want to check up on their forum in order to sort some of these questions out.. I didn't join to search for your specific request, given that I have no insigt to exactly what you want, and given that a membership there most likely will be more usefull for you than for me.
Last edited by redhead; 12-15-2005 at 04:55 AM.
|
|
|
12-21-2005, 05:20 AM
|
#9 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
Thanks redhead  . The picture you made was crystal and left me with a no brainer on what to do. I worked out a solution that is much more sensible for me. I understand what the above post entails, and with all the circumvention required to do a simple task I need done, I just went in another direction completely. No need for the FTP.
Since I'm here, (I'd rather not create a new thread for one other question) maybe you guys can help me with this too... can anyone tell me how the below function works? It's not broken or anything I just can't understand it.
I got this off of php.net while looking up the filesize function. There were no definitive comments that came along with it and I'm just scratching my head at how log() operates (I didn't find the contributions to it in the manual helpful).
How does the below know to move to the next value in the array when the byte size warrants it?
PHP Code:
function human_file_size($size)
{
$filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i];
|
|
|
12-21-2005, 06:23 AM
|
#10 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
|
You have to split it up, and look at what is calculated within the expression ie:
Code:
($i = floor(log($size, 1024))))
$i is assigned the value for the 1024 logarithm to $size, meaning deciding how many times 1024 is logarithmic held in $size ie:
512 = 0 (1024^0), 1024 = 1 (1024^1), 1048576 = 2 (1024^2), 1073741824 = 3 (1024^3), etc.
Code:
. $filesizename[$i]
decides the appropriate extension given the value stored in $i fetched as the index found in $filesizename, from the previus ie:
0 = " Bytes", 1 = " KB", 2 = " MB", etc.
Code:
$size/pow(1024, ($i = floor(log($size, 1024)))), 2) == $size/pow(1024, $i, 2)
meaning it will give you the appropriate count of said 1024 is contained in your $size, ie:
$size = 512 yields $i = 0 yields pow(1024, 0, 2) = 1 yields $size/1 = 512, and filesizenames[$i] will provide you with "Bytes" so it will be "512 Bytes" it returnes.
$size = 1024 yields $i = 1 yields pow(1024, 1, 2) = 1024 yields $size/1024 = 1, and filesizenames[$i] will provide you with " KB" so it will be "1 KB" it returns
and so forth.
I hope this dosn't sound too complicated.
|
|
|
12-21-2005, 07:34 AM
|
#11 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
Thanks man, I got it  . That was as good a breakdown on how something works as any. Much better than compared to my kooky chemistry teacher showing me half-life equations and I still couldn't get it.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 11:27 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|