CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: Throw Down The Gauntlet:
a script

 



parham_m_s
journeyman

Jul 13, 2000, 2:36 PM

Post #1 of 2 (3778 views)
a script Can't Post

i'm looking for a script that takes the info from a textbox/form and puts it in a text file, and from the text file it is inserted into a html file.

i haven't had any luck of finding such a file yet.

IF possible, can somoene take the above script, and make an admin with it. the login name would equal the same filename of the text file, and http://www.domain.com/cgi-bin/text.cgi?login.name.here would make the html file??? just multi-user support in short.

could somoene please help me out. it's for a school websites so that teachers could make class announcments. Much appreciated Smile.

------------------

Come to Emulation Online for all of your needs! Currently looking for help with the site (perl programmers, html, news writers, article writers, image creators, etc.)... apply within or email me at emu_online@hotmail.com . <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>All life begins with Nu and ends with Nu... This is the truth! This is my belief! ... at least for now.- "The Mystery of Life" Vol. 841 Ch. 26 , Chrono Trigger<HR></BLOCKQUOTE>


parham_m_s
journeyman

Jul 14, 2000, 12:38 PM

Post #2 of 2 (3778 views)
Re: a script [In reply to] Can't Post

i found the following coding, but this edits all files within a directory.. can someone please help me edit it so that it only opens one file to edit which i can set as a variable

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl

# This is the path to the directory that you want to edit.
# Note that all subdirectories in this directory will also be accessible.

$path = '.';

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
}

if(exists($FORM{'edit'})) {
$FORM{'edit'} =~ s/<\;/</g;
$FORM{'edit'} =~ s/>\;/>/g;
$FORM{'edit'} =~ s/"\;/\"/g;
}

if($FORM{'diradd'} eq '..') {
$FORM{'dir'} =~ s/\/[^\/]*?$//;
}elsif($FORM{'diradd'} ne '') {
$FORM{'dir'} .= "/$FORM{'diradd'}";
}

$path = "$path$FORM{'dir'}/";

if(exists($FORM{'file'})) {
unless(open(FILE,"$path$FORM{'file'}")) {
&system_error("Can't read file $path$FORM{'file'}.\n");
exit;
}
@lines = <FILE>;
close(FILE);
chomp(@lines);
for $line (@lines) {
$line =~ s/\t/ /g;
$line =~ s/\"/"\;/g;
$line =~ s/</<\;/g;
$line =~ s/>/>\;/g;

}

print "Content-type: text/html\n\n";
print "<html><head></head><body>\n";
print "<h1>File: $FORM{'file'}</h1>\n";
print "<form action=$ENV{'SCRIPT_NAME'} METHOD=POST>\n";
print "<textarea rows=20 cols=60 name=edit wrap=off>";
for (@lines) {print "$_\n"}
print "</textarea>\n";
print "<input type=hidden name=filename value=\"$FORM{'file'}\">\n";
print "<input type=hidden name=dir value=\"$FORM{'dir'}\">\n";
print "<br><input type=submit></form>\n";
print "</body></html>";
exit;

}elsif(exists($FORM{'edit'})) {
unless(open(NEW,">$path$FORM{'filename'}")) {
&system_error("Couldn't write to $path$FORM{'filename'}.\n");
exit;
}
$FORM{'edit'} =~ s/\r//gs;
$FORM{'edit'} =~ s/ /\t/gs;
print NEW "$FORM{'edit'}";
close(NEW);
}

&listdir($path);

print "Content-type: text/html\n\n";
print "<html><head></head><body>\n";
print "<form action=$ENV{'SCRIPT_NAME'} METHOD=POST>\n";
print "<H2>Path:</H2>\n";
print "$path\n";
print "<hr>\n";
print "<H2>Directories:</H2>\n";
print "<input type=radio name=diradd value=\"..\">.. |\n" if $FORM{'dir'};
for $dir (@subdirs) {
print "<input type=radio name=diradd value=\"$dir\">$dir |\n";
}
print "<hr>\n";
print "<H2>Files:</H2>\n";
for $file (@ascii_files) {
print "<input type=radio name=file value=\"$file\">$file |\n";
}
print "<input type=hidden name=dir value=\"$FORM{'dir'}\">\n";
print "<hr><input type=submit></form>\n";
print "</body></html>";

exit;

################################
# Error Subs
sub system_error {
local($errmsg) = @_;
&print_header("System Error");
print $errmsg;
&print_footer;
}

sub print_header {
local($title) = @_;
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>$title</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<H1>$title</H1>\n";
}

sub print_footer {
print "</BODY>\n";
print "</HTML>\n";
}
#################################################
# listdir
# Given:
# The path to the directory
#
# Returns:
# @subdirs - the list of subdirectories
# @ascii_files - the list of ascii files
# @binaries - the list of binary files
#################################################

sub listdir {
my $dirpath = shift(@_);
opendir(DIR, "$dirpath");
@raw = sort grep(!/^\./, readdir(DIR));
closedir(DIR);
@ascii_files = ();
@subdirs = ();
@binaries = ();
for $item(@raw) {
if(-d "$dirpath/$item") {
push(@subdirs, $item);
}elsif(-T "$dirpath/$item") {
push(@ascii_files, $item);
}else {
push(@binaries, $item);
}
}
}

</pre><HR></BLOCKQUOTE>

Can this still be done to it:
IF possible, can somoene take the above script, and make an admin with it. the login name would equal the same filename of the text file, and http://www.domain.com/cgi-bin/text.cgi?login.name.here would make the html file??? just multi-user support in short.

[This message has been edited by parham_m_s (edited 07-14-2000).]

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives