LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-15-2005, 08:13 PM   #1
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Rep: Reputation: 15
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
 
Old 04-15-2005, 08:29 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,141

Rep: Reputation: 322Reputation: 322Reputation: 322Reputation: 322
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.
 
Old 04-15-2005, 09:33 PM   #3
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
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??
 
Old 04-15-2005, 11:25 PM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,141

Rep: Reputation: 322Reputation: 322Reputation: 322Reputation: 322
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.
 
Old 04-16-2005, 01:44 AM   #5
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
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.....
 
Old 04-16-2005, 01:56 AM   #6
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,141

Rep: Reputation: 322Reputation: 322Reputation: 322Reputation: 322
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 .
 
Old 04-26-2005, 01:51 AM   #7
verbatim
Member
 
Registered: Apr 2005
Posts: 31

Original Poster
Rep: Reputation: 15
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('./');
  }
?>
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically create virtual mail Courier Imap account hawkpaul Linux - Software 6 06-29-2005 09:06 AM
How to create a bash script to automatically disown a process. jon_k Linux - Software 5 06-19-2005 06:53 AM
Newbie: does Slackware 9.1 automatically create partitions? DogTags Slackware - Installation 3 01-04-2004 02:01 PM
How to create a tiny script and make it start automatically tchigi Linux - Newbie 2 11-28-2003 04:48 AM
Samba Fails to create machine accounts automatically. ghotip Linux - Distributions 7 10-17-2003 05:26 PM


All times are GMT -5. The time now is 11:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration