LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need help with a script to automatically create a subdirectory (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-with-a-script-to-automatically-create-a-subdirectory-313703/)

verbatim 04-15-2005 07:13 PM

need help with a script to automatically create a subdirectory
 
was wondering if someone could assist me in creating the functionality where a person can sign into my website as a new user and have a script automatically create a new subdirectory based on their input?"

I would also need the script to copy files into the folder after it is created.



how would i go about doing this??

Verb

btmiller 04-15-2005 07:29 PM

Allowing totally unsupervised user creation probably isn't the greatest idea in the world from a security standpoint. Some public access Unix systems do it though, but you have to sign up and then are put into a restricted account until you can be approved. I think how some of them do it is new users sign on to a heavily restricted test account and then there is a SUID binary that they run which does nothing more than execs useradd with the correct options to create the account.

verbatim 04-15-2005 08:33 PM

looking for something similar to a blog site
 
where you sign up and get a subdirectory or virtual host on the site.

i dont know how to dynamically create either on a site though.

can any one help??

btmiller 04-15-2005 10:25 PM

Well, you'd probably want to write some sort of customized shell or Perl script to do it. You have some sort of sign up page that launched a script which creates the necessary directory and copies the appropriate files over. If you set it up right, you can even do the sign up form and the directory creation in PHP. I think some content management systems allow users to sign up and get their own space too, but I've never actually played with anything like that.

You'll need to say a bit more about your specific requirements if you want more specifics than that, but hopefully this will get you started.

verbatim 04-16-2005 12:44 AM

more detail:
 
i believe i can do the sign up form with a php user authentication script. i cant figure out how to do teh directory creation in php though.

in a perfect situation, it would work as such. Tom sign up for the site. he gets a confirmation email he must click to activate his account.

he then goes to the home page, signs in and is redirected to: www.abc.com/tom

the /tom directory being created automatically some how after he confirms his sign up.....

btmiller 04-16-2005 12:56 AM

Making a directory in PHP is pretty easy -- see the mkdir functions. You can also use the copy function to copy files. bear in mind, though, that the Apache process will be running as a nonpriviliged user (running Apache as root is a really bad idea...), therefore it will need to have write permission to the directory in which it will create the new directory. Also the new directory will have the same ownership. If this is a problem you can probably run Apache with suexec to get the correct permissions or run a SUID binary to do the work. Please be VERY careful with suid binaries being run from web applications, though. You can severely compromise your system's security if you are not careful. The pure PHP approach is probably the best way to do it.

Activation e-mails are easy, too. Have your PHP script generate a random number and use the mail function to send it. Also store the number in a session variable. Ask the user to click on a button (or a link, so long ass the PHPSESSID is preserved) and input the number into a form. Check this with the session variable before kicking off the directory creation. OK I am quite tired right now, so I hope that explanation made a little bit of sense :).

verbatim 04-26-2005 12:51 AM

does the folder that this script is in have to have a certain chmod setting?

i currently have it in a folder with 0755 settings.

and which of the three [if any] would be the correct syntax:


Code:

1
<?php
mkdir("/home/xxx/mainwebsite_html ./mkdirtesst/", 0700);
?>



2
<?php
mkdir("http://" . $_SERVER['HTTP_HOST'] ./{$username}/", 0700);
?>

3
<?php

$dir = "http://" . $_SERVER['HTTP_HOST'] ./{$username}/";

// make directory
if (!(is_dir($dir))) {
    mkdir($dir, 0777);
chdir('./');
  }
?>



All times are GMT -5. The time now is 06:35 PM.