#!/usr/bin/perl -U use strict; use Time::CTime qw(strftime); use File::stat; use editor_com; my $ALLOW_HIDDEN = 0; my %fieldHash; my $queryString = ''; my ($rows, $cols) = (25, 65); # Rows and columns for the textarea in file edit if(uc($ENV{REQUEST_METHOD}) eq 'GET'){ $queryString = $ENV{QUERY_STRING}; }else{ read(STDIN, $queryString, $ENV{CONTENT_LENGTH}); } StripEncoding($queryString, \%fieldHash); if(exists $fieldHash{'rows'} and exists $fieldHash{'cols'}){ ($rows, $cols) = @fieldHash{'rows', 'cols'}; }else{ ($rows, $cols) = (21, 73); } unless(exists $fieldHash{'phase'}){ print "Content-type: text/html\n\n"; print "User Entry$bodyTag\n"; print qq%
\n%; print qq%

Log into your communities account

%; print qq%Enter your username:
\n%; print qq%Enter your password:
\n%; print qq%
\n%; print qq%\n%; print qq%$closeBody%; exit; } $_ = $fieldHash{phase}; # Prep for the switch below my ($userName, $password) = ($fieldHash{userName}, $fieldHash{password}); PHASE_SWITCH: { /cookie/ and do{ print "Set-Cookie: userName=$userName\n"; print "Set-Cookie: password=$password\n"; print "Location: editor.cgi?userName=$userName&password=$password&phase=dirlist&first=true\n\n"; last PHASE_SWITCH; }; /dirlist/ and do{ my $dir = &SetupUser($userName, $password, $fieldHash{curDir}); # if(!(exists $fieldHash{manualEntry}) or ($fieldHash{manualEntry} eq 'no' and !(exists $fieldHash{extension}))){ if($fieldHash{first} eq 'true'){ $fieldHash{manualEntry} = 'no'; $fieldHash{extension} = {html => 1, gif => 1, jpeg => 1, other => 1}; $fieldHash{numFiles} = 4; print "Location: editor.cgi?" . GetComFields('dirlist', %fieldHash) . "\n\n"; last PHASE_SWITCH; # print "Content-type: text/html\n\n"; # print "$bodyTag
\n"; # &DisplayFilterSelect(1); # print "
$closeBody\n"; # last PHASE_SWITCH; } &DirListing($dir); last PHASE_SWITCH; }; /edit/ and do{ SetupUser($userName, $password, $fieldHash{curDir}); $_ = $fieldHash{operation}; unless(exists $fieldHash{file} or $_ eq 'Create New HTML File' or $_ eq 'Create Subdirectory'){ Error('Must choose a file'); } EDIT_SWITCH: { /.*Edit$/ and do{ &Editor(); last EDIT_SWITCH; }; /^Rename$/ and do{ print "Location: editor.cgi?" . GetComFields('rename', %fieldHash) . "&file=$fieldHash{'file'}\n\n"; last EDIT_SWITCH; }; /^Delete$/ and do{ unlink @fieldHash{file}; print "Location: editor.cgi?" . GetComFields('dirlist', %fieldHash) . "\n\n"; last EDIT_SWITCH; }; /^Create New HTML File$/ and do{ print 'Location: editor.cgi?' . GetComFields('create', %fieldHash) . "\n\n"; last EDIT_SWITCH; }; /^Preview$/ and do{ # Have to translate file into http directory first my $file = "/~$userName/" . $fieldHash{file}; print "Location: $fieldHash{'file'}\n\n"; last EDIT_SWITCH; }; /^Copy$/ and do{ open ORIG, $fieldHash{file}; open DUP, ">copy_of_" . $fieldHash{file}; my $tmp; while(($tmp = )){ print DUP $tmp; } close DUP; close ORIG; print "Location: editor.cgi?" . GetComFields('dirlist', %fieldHash) . "\n\n"; last EDIT_SWITCH; }; /^Create Subdirectory$/ and do{ print "Content-type: text/html\n\n"; print "$bodyTag\n"; print "\n"; print "Enter the name of the new subdirectory:
\n"; print "
\n"; print ""; PrintComFields('createSub', %fieldHash); print "$closeBody"; last EDIT_SWITCH; }; } last PHASE_SWITCH; }; /save/ and do{ SetupUser($userName, $password, $fieldHash{curDir}); $_ = $fieldHash{'operation'}; SAVE_SWITCH: { /^Save$/ and do{ SaveFile($fieldHash{'file'}, $fieldHash{'fileContents'}); print "Location: editor.cgi?" . GetComFields('dirlist', %fieldHash) . "\n\n"; last SAVE_SWITCH; }; /Save and Continue Editing/ and do{ SaveFile($fieldHash{'file'}, $fieldHash{'fileContents'}); print "Location: editor.cgi?" . GetComFields('edit', %fieldHash) . "&file=$fieldHash{'file'}\n\n"; last SAVE_SWITCH; }; /Preview/ and do{ print "Content-type: text/html\n\n"; print "$fieldHash{'fileContents'}"; last SAVE_SWITCH; }; /Return to Directory/ and do{ print "Location: editor.cgi?" . GetComFields('dirlist', %fieldHash) . "\n\n"; last SAVE_SWITCH; }; } last PHASE_SWITCH; }; /^create$/ and do{ SetupUser($userName, $password, $fieldHash{curDir}); my $file = $fieldHash{file} . '.html'; if(exists $fieldHash{file}){ unless($file =~ /\..*/){ open(NEWFILE, ">$file") or Error("Can't create $file: $!"); print NEWFILE 'New file'; close NEWFILE; } if($fieldHash{operation} eq 'Create'){ print 'Location: editor.cgi?' . GetComFields('dirlist', %fieldHash) . "\n\n"; }else{ print 'Location: editor.cgi?' . GetComFields('edit', %fieldHash) . "&file=$file&operation=Edit\n\n"; } }else{ print "Content-type: text/html\n\n"; print "Create HTML File\n"; print qq%$bodyTag
\n%; print "Enter the name of the file (.html will be appended):
\n"; print qq%
\n%; print qq% \n%; print qq%
\n%; PrintComFields('create', %fieldHash); print "$closeBody\n"; } last PHASE_SWITCH; }; /^rename$/ and do{ SetupUser($userName, $password, $fieldHash{curDir}); if(exists $fieldHash{newFileName}){ rename $fieldHash{file}, $fieldHash{newFileName}; print "Location: editor.cgi?" . GetComFields('dirlist', %fieldHash) . "\n\n"; }else{ print "Content-type: text/html\n\n"; print "Rename a File$bodyTag\n"; print qq%\n%; print "What to rename it to:
\n"; print qq%
\n%; print qq%
\n%; PrintComFields('rename', %fieldHash); print qq%\n%; print "
$closeBody\n"; } last PHASE_SWITCH; }; /^createSub$/ and do{ my $newDir = $fieldHash{newDir}; if($newDir eq '' or $newDir =~ /^\./){ Error('Invalid directory name'); last PHASE_SWITCH; } SetupUser($userName, $password, $fieldHash{curDir}); mkdir($newDir, 0775) or Error("Couldn't create directory: $!"); print "Content-type: text/html\n\n"; print "$bodyTag\n"; print "
\n"; print "Subdirectory successfully created!
\n"; print "\n"; PrintComFields('dirlist', %fieldHash); print "
$closeBody"; last PHASE_SWITCH; }; } exit; sub DirListing{ my $dirName = shift; my @fileList = (); my @dirList = (); { opendir DIR, $dirName or Error("Can't open directory $dirName: $!"); my @tmpList = readdir DIR; my $refExt = $fieldHash{extension}; foreach my $file (@tmpList){ $_ = $file; study; unless((($ALLOW_HIDDEN)?(0):(/^\./))){ if(-d){ push @dirList, ($file); }elsif((exists $$refExt{html} and /\.html?$/) or (exists $$refExt{gif} and /\.gif$/) or (exists $$refExt{jpeg} and /\.jpe?g$/) or (exists $$refExt{other} and $_ !~ /\.(html?|gif|jpe?g)$/)){ push @fileList, ($file); } } } closedir DIR; } print "Content-type: text/html\n\n"; print "Directory listing for $dirName\n"; print "$bodyTag"; print qq%
Don't know where to start? You can create a basic page here
Or you can upload files from your computer here
%; print "

Listing of $dirName

\n"; print qq%

%; print "\n"; print ""; print ""; # space for radio buttons print ""; print ""; # space for the view link print ""; print ""; print "\n"; my $tmplt = '%b %o, %Y'; # template for strftime() my $lineToggle = 1; if($fieldHash{curDir} ne ''){ $fieldHash{curDir} =~ /(.*)\/[^\/]+$/; my $tmp = $1; $tmp =~ s/\//%2F/g; print qq%%; $lineToggle = 0; } foreach my $dir (@dirList){ $lineToggle = not $lineToggle; my $bgcolor = ($lineToggle?('#FFFFFF'):('#D2D2D2')); print qq%%; } foreach my $file (@fileList){ $lineToggle = not $lineToggle; my $size = -s $file; my $fStats = stat($file); my $view = "/~$userName$fieldHash{'curDir'}/$file"; my $bgcolor = ($lineToggle?('#FFFFFF'):('#D2D2D2')); printf(qq~\n~, strftime($tmplt, gmtime($fStats->mtime))); } print qq%\n
NameLast Modified
(GMT)
Size
(bytes)
Up one level
$dir
$fileView%s$size


\n%; PrintComFields('edit', %fieldHash); print "
\n"; print "


\n"; &DisplayFilterSelect; print "


"; print qq%

File upload utility


%; print qq%
\n%; print qq% Convert filenames to lowercase
\n%; print qq%
\n% x $fieldHash{numFiles}; print "Send this many files at once: "; print qq%
\n"; print qq% %; print qq%
\n%; PrintComFields('fileupload', %fieldHash); print "

"; print "$closeBody\n"; } sub Editor{ open FILE, $fieldHash{file}; my @fileData = ; close FILE; $" = ''; print "Content-type: text/html\n\n"; print "Editing File $fieldHash{file}\n"; print "$bodyTag

Editing file $fieldHash{file}

\n"; print qq%
\n%; print qq%
\n"; print qq% %; print qq% %; print qq%
\n%; print qq%
%; print qq%\n%; PrintComFields('save', %fieldHash); print "$closeBody"; } sub DisplayFilterSelect{ my $refExt = $fieldHash{'extension'}; print qq%%; print "
\n
"; print qq%\n"; print qq%List files with the following extensions:%; print "
\n"; print qq% html "; print qq% gif "; print qq% jpg "; print qq% other "; print qq%\n"; print "
\n"; print qq% Enter files manually\n"; PrintComFields('refreshdir', %fieldHash); print "
\n"; print "\n"; }