#!/usr/bin/perl -w ########################################################################## # Blosedit.cgi # # Allows editing of Blosxom files while maintaining posting file date. # # Using just one other file for user/password entry, one can root a # # user to a home directory. The use of user flags control visibility of # # subdirectories such as /.settings/ as used in Blosxom 3 and visibility # # of dot named files such as .htaccess. Old files can be edited while # # maintaining integrity of timestamps. New files can aslo be created. # # Edited files can be saved as draft and then later saved as completed # # Directories or files need to be writable by "www" (or "apache") to # # work. # # # # Blosedit is free software. you may redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the # # Free Software Foundation. # # pdr 11/08/04, v1.1.6 # ########################################################################## use strict; use CGI; use Time::Local; use File::Find; # # <<<<<<<<<<<<<< Edit below for Your setup >>>>>>>>>>>>>>>>> # as they say, "Location, Location, Location!" #my $passfile = '/Library/WebServer/CGI-Executables/pssw.txt'; # absolute path to user/password file my $passfile = '/var/www/cgi-bin/pssw.txt'; # absolute path to user/password file my $salt ='gh'; # salt for crypt function my $usesecure = 0; # set if you want to use SSL secured cookie my $Xpiration = '+1d'; # cookie expiration date my $MAX_SIZE = 50; # if flag is set, user is not allowed to upload flles larger then this in kilobytes my $draft = '.tmp'; # draft file extension ig. mysummertrip.txt is saved as mysummertrip.txt.tmp # thus preventing blosxom from showing it until it has a valid 'flavour' name # also when re-loaded, comes up with non-draft name for normal save # for more personal style define your own header/footer # Note, user's header and footer files care not active until log in my $usr_headerfile =''; # path is relative to current user's root my $usr_footerfile =''; # path is relative to current user's root # If user's header/footer not defined or possibly doesn't exist then try default (if defined and exists) my $default_headerfile=''; # must be aboslute path to header my $default_footerfile=''; # must be aboslute path to footer my $Use_JavaScript=1; #set to zero if no Java script wanted # <<<<<<<<<<<<<< Edit above for Your setup >>>>>>>>>>>>>>>>> ########################################################################## # Password File Format: # a white-space delimited file with the following on each line # userid password flags rootdirectory # userid may be preded by white-space # if the path to user's root has a subdirectory with white space in the name then you must quote the # pathname. Single or double quotes ok # examples: # admin bratwurst 0 /var/www/html/data # betty boop 3 '/var/www/html/toons only' # otto bismark 12 "/var/www/html/prussia 1900" # # file flags are decimal summation of flag (bits) values that are set # if flag is clear then its value is not added (= zero) # File Invisibility value = 1 files with names starting with period are not shown # Directory Invisible value = 2 directories w/names starting w/period are not shown # Directory create value = 4 User cannot create new subdirectories in home folder # File upload value = 8 User limited to maximum set file size # example: betty can not see any dot name files or directories since flag = 3 =1 + 2 # and otto is not allowed to expand beyond his current boundaries by making new subdirectories # in his root folder named prussia and his upload size is limited 12 = 4 + 8 ########################################################################## #create a new CGI object my $cgi = new CGI; my $script=$cgi->script_name; my $submitted = ''; my $user =''; my $pass =''; my $root ='/bad'; #use non-existing directory here, if somegoes wrong then will get a open error my $mydir = ''; my $Cookie = 0; my $badlogin = 0; # flags must be set to self bit mask my $FileInvisible = 1; my $DirInvisible = 2; my $DirCreate = 4; my $LimitUpload = 8; # misc globals my ($HtmlPageTitle, $EditFileName, $story_title, $DateComment) = ('', '', '', ''); my ($LoginForm, $FileNavForm, $NewDirForm, $EditForm) = ('', '', '', ''); my ($CurrentDir, $DirList, $FileList, $UploadFile, $Logout) = ('', '', '', '',''); my ($CSS_Header, $JS_Code, $JS_Menu) = ('', '', ''); my ($FileForm, $CurrentPath, $FileName, $FileDate, $FileTime) = ('', '', '', '', ''); my ($StoryTitle, $StoryBody, $EditSubmits, $FileFormEnd) = ('', '', '', ''); #attempt to read the cookie from the clients cache my $userdata = $cgi->cookie("login"); if ($userdata) { $userdata =~ / pw=/; $user = $`; $pass = $'; $user =~ / /; $mydir = $'; $user = $`; if (ValidateUser()) { $Cookie =1; # user has a valid cookie. GetAction(); } } # check if the user has filled in the form. verify their ID/password and issue a cookie $submitted = $cgi->param('choose'); if (($submitted) && ($submitted eq 'Login')){ $user = $cgi->param('user'); $pass = $cgi->param('pass'); chomp($user); chomp($pass); $pass = Encrypt($pass) if ($pass); if (ValidateUser()) { $Cookie =1; HTML_ShowFiles(); } else { # Let them know that they didn't pass $badlogin =1; } } if (!$Cookie) { # user has no valid cookie. Allow them to log in HTML_Login(); } ############## HTML Pages and their Forms ############## sub HTML_Login { $LoginForm = qq(
Time: : :
); $CurrentPath = qq($FileName
$FileDate$DateComment
); $EditForm .= qq($FileTime
$StoryTitle$StoryBody);
$EditForm .= $JS_Menu.$EditSubmits.$FileFormEnd;
$HtmlPageTitle ='Edit File';
HTML_Header($EditForm);
HTML_Foot();
}
sub HTML_Header {
if (($HtmlPageTitle ne 'Login') || ($Xpiration eq 'now')) {
# you passed user/password, so here's a cookie for you!
$userdata = "$user $mydir pw=$pass";
$Cookie = $cgi->cookie(-name=>'login', -value=>$userdata, -expires=>$Xpiration, -secure=>$usesecure);
print $cgi->header(-cookie=>$Cookie);
}
else {
# blehhhh... no cookie for you
print $cgi->header;
}
SetCSSHead ($CSS_Header);
Set_JSCode ( $JS_Code) if ($Use_JavaScript && ($HtmlPageTitle eq 'Edit File'));
# get a name of an external header only if it exists
my $headerfile;
if ($usr_headerfile && (-e $root.'/'.$usr_headerfile)) {
$headerfile = $root.'/'.$usr_headerfile;
}
elsif ($default_headerfile && (-e $default_headerfile)) {
$headerfile = $default_headerfile;
}
if ($headerfile) {
open (HTML_FILEHANDLE, $headerfile) || Error('Cant open header file: ', $headerfile);
my @hcontent =