Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI baby...

Status
Not open for further replies.

leo2180

IS-IT--Management
Jun 7, 2000
52
0
0
US
Ok,<br>I have a form and it has 20 fields of input.&nbsp;&nbsp;How do I get all fields to be submitted to the cgi program at the same time, and the cgi program being able to handle(process) all of them(at the same time)?&nbsp;&nbsp;I could do it for only 1 input field...<br><br>I know this is a little vague but...<br>Help!!!!!!<br><br><br>
 
I don't think Perl supports threads that way, does it?<br><br>Why on earth would you need to process all form entries at the same time, as opposed to individually? <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
OK, <br><br>lets say you're trying to create a 'file'.&nbsp;&nbsp;The cgi, when sent the query creates this file.&nbsp;&nbsp;Thats simple.&nbsp;&nbsp;However lets say you're trying to create a bunch of files (n amount) with one push of the submit button.&nbsp;&nbsp;I wouldnt want to have to run the program lets say 'n' amount of times to create the 'n' amount of files would I?&nbsp;&nbsp;<br><br>No,<br><br>So I created 20 different input fields, so that I could create 20 different files at the same time.&nbsp;&nbsp;How do I do that?<br><br><br>
 
you'd have to create a for (or foreach) loop. As far as I know (and somebody should correct me on this if I'm wrong), there's no way to write to multiple files at the same time. Now if this were Java, it'd be a different story; but it's not. Perl, try as it might be, is not really object-oriented in a true sense. A thread, being an object, doesn't show up in Perl. Perl's procedural... so you need to handle file IO from a procedural standpoint. That means you write one file, then write the next, etc. Create a for loop to handle your file IO. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
See the thing is I'm not actually creating files.&nbsp;&nbsp;That was just an example.&nbsp;&nbsp;the script I have creates user account on a unix machine.&nbsp;&nbsp;When I put their name in the field it generates their password and username randomly, and displays it to the screen.&nbsp;&nbsp;Now the challenge is creating more than one at a time.&nbsp;&nbsp;For example if I have 5 accounts to create, I dont want to have to do them individually, you know...<br><br><br>I want to just have one form and 5 different input fields in the form, when I hit submit the script runs and creates all 5 (or how much ever) accounts I wanted.&nbsp;&nbsp;Its that any different, or easier?&nbsp;&nbsp;Let me know...
 
leo, i like your idea, and as i'm following up on the whole cgi-wannabe idea, i think what your trying to do is the following (is pseudo) -- so correct me if i'm wrong...<br><br>10 until exit is prompted:<br>20&nbsp;&nbsp;&nbsp;&nbsp;Display input username:<br>30&nbsp;&nbsp;&nbsp;&nbsp;accept username variable<br>40&nbsp;&nbsp;&nbsp;&nbsp;if variable not value of exit<br>50&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read into array of users to be added,<br>60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-and go to 20<br>70&nbsp;&nbsp;&nbsp;&nbsp;-=- (finish condition)<br>80 -=- (finish condition)<br>90 until EOA (end of array)<br>100 ADD THE FLIPPIN USERS!!<br>110 -=-<br><br>-- of course, that's only for one user, but to be honest with you, why not just do each form individually, and tell the perl script to re-initialize the form after it has set up the username anyhow? it would happen too fast for you to notice that it has already been added, and it would make life much easier :)<br><br>-- however, please coninue to tell us we are thick and cant understand what your trying to tell us, hehehe.<br><br>Signing off, Karl.<br><br> <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
leo,<br>you can do anything in the Perl that you want.&nbsp;&nbsp;If you submit 20 names, then you can loop through that list of 20 names and do 20 things with them.&nbsp;&nbsp;I'm sorry to have to disagree with IMOTIC, but, Perl could do this in a parrallel sense via several different approaches, one might be fully objectified.&nbsp;&nbsp;In order to do that though, you would need to write a class to handle your chores, which I don't think you want to do.&nbsp;&nbsp;You could also spawn child processes to run in parallel for each new user, but, that to is some significant overkill.&nbsp;&nbsp;What you probably want to do is more like.......<br><br>If you HTML looks like.....<FONT FACE=monospace><br>html starting stuff with &lt;form&gt; tag.....<br>First User Name: &lt;input type=text name=user1 size=15&gt;&lt;BR&gt;<br>Second User Name: &lt;input type=text name=user2 size=15&gt;&lt;BR&gt;<br>Third User Name: &lt;input type=text name=user3 size=15&gt;&lt;BR&gt;<br>Fourth User Name: &lt;input type=text name=user4 size=15&gt;&lt;BR&gt;<br>html ending stuff......</font><br><br>Your CGI code could simply check to see if each field is populated, if so, run useradd.<br><FONT FACE=monospace>@users = ('user1','user2','user3','user4');<br>foreach $user (@users)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;if ($FORM{$user}) { &RUN_USERADD($user); }<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br></font><br><br>This is a little simplist, but it would be effective.....<br><br>'hope this helpls...<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
ok now, this sounds and look right.&nbsp;&nbsp;Another thing is I have the option of choosing any amount of users to add, up to 20.&nbsp;&nbsp;So I could choose any amount I want up to 20.&nbsp;&nbsp;How would I set it to only run the script for the amount I selected?<br><br><br>I sound so dumb but, Im new to this...
 
That is what the <FONT FACE=monospace>if ($FORM{$user}) { &RUN_USERADD($user); }</font> does.<br><br>This is a simple approach that should show simple function.....<br>Write your HTML data entry page to have 20 input fields named from user1 to user20.&nbsp;&nbsp;<br>In the CGI, expand the @users array to include user1, user2....user19, user20.<br><br>Then, if you fill in the first 9 fields in the HTML data entry page and submit, <br>$FORM{$user} will evaluate true for names 1 through 9 and will evaluate null for names 10 through 20.&nbsp;&nbsp;Therefore, the sub RUN_USERADD will only run for the first nine.<br><br>'hope this helps<br><br><br><br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
COOOL............<br><br>I'll give it a try...<br>
 
oh wait, the var $FORM, do I have to declare it somewhere else or does it automatically get declared there and knows what its supposed to do?
 
you have to do something to create the hash, 'FORM'.&nbsp;&nbsp;If you are doing any CGI, then you are decoding the CGI parms some how.&nbsp;&nbsp;Something like...............<br><br><FONT FACE=monospace>%FORM = &cgidecode;<br>$someVar = $FORM{'varName'};</font><br>where sub cgidecode returns a hash of the submitted input field names and values.<br><br>or, are you using CGI.pm, maybe,<br><FONT FACE=monospace>$query = new CGI;<br>$someVar = $query-&gt;param('varName');<br></font> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Yeah Im using CGI.pm, in the second example you have no sign of $FORM.&nbsp;&nbsp;<br><br>This is what my code look looks like (well your code)...<br><br>use CGI;<br>$q = new CGI;<br>print $q-&gt;header;<br><br>@users = ('user1','user2','user3','user4');<br>foreach $user (@users)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;if ($FORM{$user}) { &RUN_USERADD($user); }<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>Does this looks correct? What do I do with the var $FORM?<br><br>Do I add: <br><br>%FORM = &cgidecode;<br>$someVar = $FORM{'varName'};<br><br>or do I do somehting else?<br><br><br>
 
Since you are using CGI.pm, forget the FORM hash.&nbsp;&nbsp;You want to use the CGI.pm syntax to check each input field to see if it has been filled.<br>Like this...<br><br><FONT FACE=monospace><br>use CGI;<br>$q = new CGI;<br>print $q-&gt;header;<br><br>@users = ('user1','user2','user3','user4'); # increase up to 20 users<br>foreach $user (@users)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;<font color=red># check to see if param $user exists, <br>&nbsp;&nbsp;&nbsp;&nbsp;#if it does, run_adduser sub routine</font><br>&nbsp;&nbsp;&nbsp;&nbsp;if($q-&gt;param(&quot;$user&quot;)) { &RUN_USERADD($user); }<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>'hope this helps..... <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
goBoating... I'm sorry, I fail to see how you're disagreeing with me. You're going through each item and running a sub on it... That's what I was suggesting. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
now the subroutine &RUN_USERADD, is it the name of my perl script that does all of the adduser stuff?&nbsp;&nbsp;If not what does it do, and where and how do I declare it or replace it or whatever?
 
yep, &RUN_USERADD would be your user add script. You'd have that down in a seperate sub. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Imotic is correct.&nbsp;&nbsp;I was not disagreeing with you.&nbsp;&nbsp;Rather, where I was including two versions of the syntax in previous posts, I later discarded the non-CGI.pm syntax when you wrote that you were using CGI.pm.&nbsp;&nbsp;That is why-&gt; &quot;Forget&quot; the FORM hash stuff.<br><br>This,<FONT FACE=monospace><br>if($q-&gt;param(&quot;$user&quot;)) { &RUN_USERADD($user); } <br></font><br>and this, <FONT FACE=monospace><br>&nbsp;if ($FORM{$user}) { &RUN_USERADD($user); }<br></font><br>are synonymous.&nbsp;&nbsp;They do the same thing.&nbsp;&nbsp;The first is using the CGI.pm object syntax ( the one you want) and the second uses a non-CGI.pm non-object syntax ( not what you want).&nbsp;&nbsp;As Imotic says, &RUN_USERADD would be a sub routine that is called each time $query-&gt;param(&quot;$user&quot;) evaluates true.<br><br>Question???......how are you going to deal with priviledges?&nbsp;&nbsp;Don't you need to be root when running adduser?&nbsp;&nbsp;If this is done via the web, unless you play some more tricks, the process will be running as the web daemon.......( a user you probably do not want to give root priviledges to)????? <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
yeah I understand, the script though that does it for one user already handles all that.&nbsp;&nbsp;Thanks again fellas...<br><br><br>I'll let you know the results of this...<br><br>Peace
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top