Advanced PHP Help needed

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
chrchcol
Forum Newbie
Posts: 15
Joined: Fri Jul 14, 2006 5:35 am

Advanced PHP Help needed

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
chrchcol
Forum Newbie
Posts: 15
Joined: Fri Jul 14, 2006 5:35 am

Advanced Script

Post 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
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

Yes, take a look at shell_exec() ... although backtick's is just as effective.
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
Post Reply