Page 1 of 1

Advanced PHP Help needed

Posted: Fri Jul 14, 2006 5:38 am
by chrchcol
I need to create a php web interface that will allow me to create ftp accounts, passwords, ect. I know all the parts about the sql data, however can someone point me in the right direction where to look for help on the php scripting where it interfaces with the linux server and creates the accounts.

Posted: Fri Jul 14, 2006 6:02 am
by Chris Corbyn
Not 100% this should be in T&D until I see what exactly you're looking for but I'd just do this using shell commands.... the only hurdle is getting around the privileges that apache runs under.

I use backticks to execute shell commands:

Code: Select all

echo `ls -l`;
If you need to add real linux accounts here's a handy function from php.net for getting the password salted in the correct form for the /etc/shadow file.

Code: Select all

function makeSalt($type=CRYPT_SALT_LENGTH) {
        switch($type) {
                case 8:
                $saltlen=9; $saltprefix='$1$'; $saltsuffix='$'; break;
                case 2:
                default: // by default, fall back on Standard DES (should work everywhere)
                $saltlen=2; $saltprefix=''; $saltsuffix=''; break;
                #
        }
        $salt='';
        while(strlen($salt)<$saltlen) $salt.=chr(rand(64,126));
        return $saltprefix.$salt.$saltsuffix;
}

$password_string = crypt($password, makeSalt(8));

$data = $user.':'.$password_string.':::::::'."\n"; //fwrite() this to /etc/shadow

Advanced Script

Posted: Fri Jul 14, 2006 6:27 am
by chrchcol
So you can basically execute bash commands from a php script on the web?

What I want to do is make a simple web interface that will create ftp users, delete ftp users, create directories within a certian account ect? My preferred method because thats what I know most is php.

Chris

Posted: Fri Jul 14, 2006 7:02 am
by jamiel
Yes, take a look at shell_exec() ... although backtick's is just as effective.

Posted: Fri Jul 14, 2006 7:11 am
by sweatje
You biggest problem will be permissions. You have to give the user running the web server the rights to perform all of the actions you are asking, and then anybody with the capability of putting PHP scripts onto the server will have all of the same rights.

Posted: Fri Jul 14, 2006 7:28 am
by Chris Corbyn
sweatje wrote:You biggest problem will be permissions. You have to give the user running the web server the rights to perform all of the actions you are asking, and then anybody with the capability of putting PHP scripts onto the server will have all of the same rights.
Not necessarily... I can see a way to apply a different userid to just one script if you put that script under a different directory. suexec with CGI can do this, and many shared hosts apply the same principles in order to make PHP run under the userid of the account holder ;)