
parham_m_s
journeyman
Jul 14, 2000, 12:38 PM
Post #2 of 2
(6403 views)
|
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).]
|