Gossamer Forum
Home : General : Perl Programming :

Setup Script

Quote Reply
Setup Script
Hi all,

Im trying to make a setup script, i have the basics in place for the page but i cant get anything to happen.
when someone clicks on the setup button it should run the following "BASIC"

if ($ENV{'QUERY_STRING'} eq "setup") {&setup;}

sub setup{

mkdir ('admin', 0755); #Make the directory


&print_page_success;
&print_page_end;
}


eventually i want it to create two directories, copy some files there and change the permissions, and then it will print a success.

Any ideas, why it isnt even making the test "admin" directory??


Regards

MDJ1
http://www.isee-multimedia.co.uk
Quote Reply
Re: Setup Script In reply to
Why duplicate Thread??? Wink

Regards,

Eliot Lee
Quote Reply
Re: Setup Script In reply to
Code:
#!/usr/bin/perl
Code:
use strict;
use CGI qw(:standard);
Code:
&main();
Code:
sub main {
Code:
my $IN = new CGI;
Code:
if ($IN->param('do') eq "setup") {
&make();
} else {
&error("Invalid call.");
}
Code:
}
Code:
sub make {
Code:
my $dir = "/path/to/admin";
mkdir($dir, 0755) || &error("Couldn't create $dir : $!");
print header;
print "Done!";
Code:
}
Code:
sub error {
Code:
my ($msg) = shift;
print header;
print $msg;
exit;
Code:
}
Installs:http://www.wiredon.net/gt/
MODS:http://wiredon.net/gt/download.shtml

Quote Reply
Re: Setup Script In reply to
Hi paul,

Thanks for that, but when I try to implement it into my script i get 500 errors, ive posted my original script in the hope you can point me in the right direction.

use CGI;

#Send fatal errors to browser
use CGI::Carp;
$query = new CGI;

&print_page_start;
&print_form;
&print_page_end;

#executed instalation of file.

if ($ENV{'QUERY_STRING'} eq "setup") {&setup;}

sub setup{

mkdir ('admin', 0755); #Make the directory


&print_page_success;
&print_page_end;
}

sub print_page_start {
print $query->header;
print "<html>
<head><title>$sitename Order Retrieval</title>
<style>
a:link {color:blue}
a:hover {color:red}
a:visited {color:blue}
a:visited:hover {color:red}
</style>
<head>
<body>
<table width='60%' border='0' cellspacing='0' cellpadding='2'>
<tr>
<td>
<div align='center'><font face='Tahoma, Arial' size='2' color='#3333FF'><b>$ENV{'SERVER_NAME'} QuickPoll Instalation
</b></font></div>
</td>
</tr>
</table>
\n";
}

sub print_page_end {
print "
</body>
</html>

\n";
}

sub print_page_success {

print "Copy success
\n";
}

sub print_form {
print "
<TABLE width='500' border='0' cellspacing='0' cellpadding='2' align='left'>
<TR>
<TD colspan='2'><FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>Quick
Poll Installation Script.</FONT></TD>
</TR>
<TR>
<TD colspan='2'>
<P><FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>By clicking
on the install button below you will install the necessary files into
the correct folders.</FONT></P>
<P><FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>The following
folders will be created in your webspace</FONT></P>
<P><FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>QPDAT<BR>
QPRES</FONT></P>
<P><FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>The admininstration
tools will be accessable by clicking on URL</FONT></P>
</TD>
</TR>
<TR>
<TD colspan='2'>
<FORM name='form1' method='post' action='install.cgi?setup'>
<input type='submit' value='submit'>
</FORM>
</TD>
</TR>
</TABLE>

\n";
}

sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
}



Regards

MDJ1
http://www.isee-multimedia.co.uk
Quote Reply
Re: Setup Script In reply to
All you need is:
Code:
#!/usr/bin/perl
Code:
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
Code:
&main();
Code:
sub main {
Code:
my $IN = new CGI;
Code:
if (!$IN->param('do')) {
&show_home();
} elsif ($IN->param('do') eq 'install') {
&process();
} else {
&error("Invalid call.");
}

}
Code:
sub show_home {
Code:
print header;
Code:
print qq|
<TABLE width='500' border='0' cellspacing='0' cellpadding='2' align='left'>
<TR>
<TD colspan='2'>
<FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>Quick
Poll Installation Script.</FONT>
</TD></TR>
<TR> <TD colspan='2'>
<P>
<FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>By clicking
on the install button below you will install the necessary files into
the correct folders.</FONT>
</P>
<P>
<FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>The following
folders will be created in your webspace</FONT>
</P>
<P>
<FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>QPDAT<BR>
QPRES</FONT>
</P>
<P>
<FONT face='Verdana, Arial, Helvetica, sans-serif' size='2'>The admininstration
tools will be accessable by clicking on URL</FONT></P>
</TD></TR>
<TR> <TD colspan='2'>
<FORM name='form1' method='post' action='install.cgi'>
<input type='hidden' name='do' value='install'>
<input type='submit' value='submit'>
</FORM>
</TD>
</TR>
</TABLE>
|;

}
Code:
sub process {
Code:
my $dir = "/path/to/admin";
mkdir($dir, 0755) || &error("Couldn't create $dir : $!");
print header;
print "Done!";

}
Code:
sub error {
Code:
my ($msg) = shift;
print header;
print $msg;
exit;
Code:
}
Something like that anyway - I just did that quickly. As far as I can see - that should work.





s;(.)(.);$2$1;g+s;\$; ;g+print,if $_='hOm$$yoG$doy$uiklldeK$neyn$,oy$uabtsra!d';

Quote Reply
Re: Setup Script In reply to
Paul,

YOU ARE A *****STAR***** it works a treat, i wish i could write code like that off the top of my head.

From what you have done i should be able to get the rest working.

Thanks A million!!

Regards

MDJ1
http://www.isee-multimedia.co.uk
Quote Reply
Re: Setup Script In reply to
Glad to be of help Smile

s;(.)(.);$2$1;g+s;\$; ;g+print,if $_='hOm$$yoG$doy$uiklldeK$neyn$,oy$uabtsra!d';

Quote Reply
Re: Setup Script In reply to
Mmm stuck again,

whenever i try to use the file:copy to copy or move anything i get 500, the syntax seems to be OK,

sub process {
my $dir = "$ENV{'DOCUMENT_ROOT'}/qpdat";
mkdir($dir, 0777) || &error("Couldn't create $dir : $!");
my $dir1 = "$ENV{'DOCUMENT_ROOT'}/qpres";
mkdir($dir1, 0755) || &error("Couldn't create $dir1 : $!");
$mypath = `pwd`;
use File::Copy;
copy("$mypath/qpoll.000000.dat", "$ENV{'DOCUMENT_ROOT'}/qpdat/qpoll.000000.dat");
copy("Copy.pm", \*STDOUT);
use POSIX;
use File::Copy 'cp';
$fh = FileHandle->new("/dev/null", "r");
cp($fh, "$ENV{'DOCUMENT_ROOT'}/qpdat/qpoll.000000.dat");'

this is the last attempt i tried, any ideas why it isnt working.



Regards

MDJ1
http://www.isee-multimedia.co.uk
Quote Reply
Re: Setup Script In reply to
I always use the Links2 way:

&File::Copy::copy ("$mypath/qpoll.000000.dat", "$ENV{'DOCUMENT_ROOT'}/qpdat/qpoll.000000.dat") or &cgierr ("Unable to copy. Reason: $!");


If that doesn't fix it, try running it from telnet or ssh and it'll spot the error for you.


s;(.)(.);$2$1;g+s;\$; ;g+print,if $_='hOm$$yoG$doy$uiklldeK$neyn$,oy$uabtsra!d';

Quote Reply
Re: Setup Script In reply to
Mmm

Got the following error

Undefined subroutine &main::cgierr called at /home/iseecouk/cgi-bin/qpoll/install.cgi line 62.

Regards

MDJ1
http://www.isee-multimedia.co.uk
Quote Reply
Re: Setup Script In reply to
Sorry my fault.

Just change &cgierr( ... ) to &error( ... )

s;(.)(.);$2$1;g+s;\$; ;g+print,if $_='hOm$$yoG$doy$uiklldeK$neyn$,oy$uabtsra!d';

Quote Reply
Re: Setup Script In reply to
Well so far so good, sort of.

Ive managed to get the first file to copy but for some reason it has changed the ownership of the directory "qpdat" and the file to nobody : nobody

how can i make sure that the folder and the file keep the user ownership, and also chmod the file after transfer??

sub process {
my $dir = "$ENV{'DOCUMENT_ROOT'}/qpdat";
mkdir($dir, 0777) || &error("Couldn't create $dir : $!");
my $dir1 = "$ENV{'DOCUMENT_ROOT'}/qpres";
mkdir($dir1, 0755) || &error("Couldn't create $dir1 : $!");
$mypath = `pwd`;
&File::Copy::copy ("$mypath/qpoll.000000.dat", "$ENV{'DOCUMENT_ROOT'}/qpdat/qpoll.000000.dat") or &error ("Unable to copy. Reason: $!");


Regards

MDJ1
http://www.isee-multimedia.co.uk
Quote Reply
Re: Setup Script In reply to
References to the nobody user have been posted in this forum QUITE a FEW TIMES...search for nobody and you will find references to a script where you can leech the codes from and use in your script.

bye...

Regards,

Eliot Lee