430 lines
20 KiB
Perl
430 lines
20 KiB
Perl
#!/usr/bin/perl
|
||
|
||
require 'config.pl';
|
||
$header = "$forumdir/header.txt";
|
||
##########################################################################
|
||
|
||
################ NO EDITING NEEDED BELOW HERE ###################
|
||
##########################################################################
|
||
#
|
||
|
||
##########################################################################
|
||
# parse form values
|
||
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
|
||
@pairs = split(/&/, $buffer);
|
||
foreach $pair (@pairs) {
|
||
local($name, $value) = split(/=/, $pair);
|
||
$value =~ tr/+/ /;
|
||
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
|
||
$value =~ s/<!--(.|\n)*-->//g;
|
||
$in{$name} = $value;
|
||
}
|
||
|
||
##########################################################################
|
||
# miscellaneous values
|
||
$command = $in{'command'};
|
||
@months = ("January","February","March","April","May","June","July","August","September","October","November","December");
|
||
|
||
##########################################################################
|
||
# determine what sub-routine to run based on the $command form value
|
||
if ($command eq '') {&login;}
|
||
elsif ($command eq 'displayList') {&displayList;}
|
||
elsif ($command eq 'displayThreads') {&displayThreads;}
|
||
elsif ($command eq 'deleteThreads') {&deleteThreads;}
|
||
elsif ($command eq 'displayEditThread') {&displayEditThread;}
|
||
elsif ($command eq 'editThread') {&editThread;}
|
||
|
||
##########################################################################
|
||
# prints the login page
|
||
sub login {
|
||
&printHeader("$forumclass");
|
||
print <<"EOF";
|
||
<tr><td><table cellpadding="10" cellspacing="1" border="0" width="410" class="border"><tr><td colspan="0" bgcolor="white"><br><table width="410" border="0" cellspacing="1" cellpadding="0" bordercolor="white"><table width="410" align="center" border="0" cellspacing="0" cellpadding="0"><h2>Weblog Administrator - Please Login</h2> </span><BR><BR>
|
||
<FORM ACTION="weblog-admin.pl" METHOD="POST">
|
||
<INPUT TYPE="Hidden" NAME="command" VALUE="displayList">
|
||
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1>
|
||
<TR><TD CLASS="txt">Username:</TD>
|
||
<TD><INPUT TYPE="Text" CLASS="txt" NAME="username" SIZE="25"></TD></TR>
|
||
<TR><TD CLASS="txt">Password:</TD>
|
||
<TD><INPUT TYPE="Password" CLASS="txt" NAME="password" SIZE="25"></TD></TR>
|
||
<TR><TD CLASS="headers"><BR><BR></TD>
|
||
<td><INPUT TYPE="Submit" CLASS="submit" VALUE="Login"></td></TR>
|
||
</TABLE>
|
||
</FORM><BR>Return to your weblog by clicking <A HREF="weblog.pl">here</A><br>----------------------------------------------------------------------------------<BR><small>Powered by PerlBlog</small><br><br></tr></table></td></tr></td></tr></table></div>
|
||
EOF
|
||
&printSooter;
|
||
}
|
||
|
||
##########################################################################
|
||
# checks username and password, called from every sub-routine
|
||
sub checkAccess {
|
||
if ($in{'username'} ne $adminusername || $in{'password'} ne $adminpassword) {
|
||
print "Content-type: text/html\n\n";
|
||
print "Access Denied - Click Back to Retry Your Login and Password.";
|
||
exit(0);
|
||
}
|
||
}
|
||
##########################################################################
|
||
# prints a list of months that have been archived
|
||
sub displayList {
|
||
&checkAccess;
|
||
&printHeader("");
|
||
print "<FORM ACTION=\"weblog-admin.pl\" METHOD=\"POST\">\n";
|
||
open(MONTHS,"$forumdir/months.txt");
|
||
@headerfiles = <MONTHS>;
|
||
close(MONTHS);
|
||
print <<"EOF";
|
||
<tr><td><table cellpadding="10" cellspacing="1" border="0" width="410" class="border"><tr><td colspan="0" bgcolor="white"><BR><table width="410" border="0" cellspacing="1" cellpadding="0" bordercolor="white"><table width="410" align="center" border="0" cellspacing="0" cellpadding="0"><h2>Choose Month to Edit</h2> </span><p> </p>
|
||
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1>
|
||
<TR BGCOLOR="#FFFFFF"><TD CLASS="headers">Month</TD><TD CLASS="headers">Year</TD></TR>
|
||
EOF
|
||
foreach $headerfile (@headerfiles) {
|
||
if ($headerfile ne '') {
|
||
$year = substr ($headerfile,0,4);
|
||
$month = substr ($headerfile,4,5);
|
||
$month = sprintf("%5.0f", $month);
|
||
$monthname = $months[$month-1];
|
||
$headerfile = substr ($headerfile,0,6);
|
||
print "<TR BGCOLOR=\"#FFFFFF\"><TD><INPUT TYPE=\"Radio\" NAME=\"headerfile\" VALUE=\"$headerfile\">$monthname </TD><TD>$year</TD></TR>\n";
|
||
}
|
||
}
|
||
print <<"EOF";
|
||
<INPUT TYPE="Hidden" NAME="username" VALUE="$in{username}">
|
||
<INPUT TYPE="Hidden" NAME="password" VALUE="$in{password}">
|
||
<INPUT TYPE="Hidden" NAME="command" VALUE="displayThreads">
|
||
<TR BGCOLOR="#FFFFFF"><TD><BR><BR><INPUT TYPE="Submit" class="submit" VALUE="Edit Month"></TD></TR>
|
||
</TABLE>
|
||
</FORM><br><BR><small>Powered by PerlBlog</small><br><br></tr></table></td></tr></td></tr></table></div>
|
||
EOF
|
||
&printSooter;
|
||
}
|
||
|
||
##########################################################################
|
||
# print the headers for a particular month
|
||
sub displayThreads {
|
||
&checkAccess;
|
||
$headerfile = $in{'headerfile'};
|
||
|
||
$year = substr ($headerfile,0,4);
|
||
$month = substr ($headerfile,4,5);
|
||
$month = sprintf("%5.0f", $month);
|
||
$monthname = $months[$month-1];
|
||
|
||
open(DATA,"$forumdir/$headerfile.txt");
|
||
@headerlines = <DATA>;
|
||
close(DATA);
|
||
$length = @headerlines;
|
||
|
||
&printHeader("");
|
||
print <<"EOF";
|
||
<SCRIPT LANGUAGE="JavaScript">
|
||
<!--
|
||
|
||
function submitForm(which) {
|
||
df = document.forum
|
||
if (which == 'delete') {
|
||
var str = ""
|
||
for (var i=0; i<$length; i++) {
|
||
if (eval('df.delete'+i+'.checked == true')) {
|
||
str += eval('df.delete'+i+'.value')+","
|
||
}
|
||
}
|
||
if (str!="") {
|
||
df.todelete.value = str.substring(0,str.length-1)
|
||
df.command.value = "deleteThreads"
|
||
df.submit()
|
||
}
|
||
else {
|
||
df.todelete.value = str.substring(0,str.length-1)
|
||
df.command.value = "deleteThreads"
|
||
df.submit()
|
||
}
|
||
}
|
||
else if (which == 'edit') {
|
||
var editselected = false
|
||
for (var i=0; i<df.toedit.length; i++) {
|
||
if (df.toedit[i].checked == true) {
|
||
editselected = true
|
||
break
|
||
}
|
||
}
|
||
if (editselected == false) {
|
||
df.command.value = "displayEditThread"
|
||
df.submit()
|
||
}
|
||
else {
|
||
df.command.value = "displayEditThread"
|
||
df.submit()
|
||
}
|
||
}
|
||
}
|
||
|
||
//-->
|
||
</SCRIPT>
|
||
|
||
<tr><td><table cellpadding="10" cellspacing="1" border="0" width="410" class="border"><tr><td colspan="0" bgcolor="white"><BR><table width="410" border="0" cellspacing="1" cellpadding="0" bordercolor="white"><table width="410" align="center" border="0" cellspacing="0" cellpadding="0"><h2>Editing/Deleting Entries | <A HREF="weblog.pl"><B>$monthname $year</b></a></h2><BR><BR>
|
||
<TABLE BORDER=0 width="650" CELLSPACING=1 CELLPADDING=1>
|
||
<TR BGCOLOR="#FFFFFF"><TD class="border"> Delete</TD><TD class="border"> Edit</TD><TD class="border"> Subject</TD><TD class="border"> Entry</TD><TD CLASS="headers">Responses</TD>
|
||
<FORM NAME="forum" ACTION="weblog-admin.pl" METHOD="POST">
|
||
EOF
|
||
for ($i=0;$i<@headerlines;$i++) {
|
||
if ($headerlines[$i] ne '') {
|
||
@info = split (/_/, $headerlines[$i]);
|
||
$num = $info[0];
|
||
$subject = $info[1];
|
||
$name = $info[2];
|
||
$date = $info[3];
|
||
$responses = $info[6];
|
||
print <<"EOF";
|
||
<TR BGCOLOR="#FFFFFF"><TD ALIGN="CENTER"><INPUT TYPE="Checkbox" NAME="delete$i" VALUE="$num"></TD>
|
||
<TD ALIGN="CENTER"><INPUT TYPE="Radio" NAME="toedit" VALUE="$num"></TD>
|
||
<TD> $subject </TD><TD> $name </TD><TD ALIGN="CENTER">$responses</TD></TR>
|
||
EOF
|
||
}
|
||
}
|
||
print <<"EOF";
|
||
<TR BGCOLOR="#FFFFFF">
|
||
<TD><BR><BR><INPUT TYPE="BUTTON" class="submit" VALUE="Delete" onClick="submitForm('delete')"></TD>
|
||
<TD><BR><BR><INPUT TYPE="BUTTON" class="submit" VALUE="Edit" onClick="submitForm('edit')"></TD>
|
||
</TR>
|
||
</TABLE>
|
||
<INPUT TYPE="HIDDEN" NAME="todelete">
|
||
<INPUT TYPE="HIDDEN" NAME="headerfile" VALUE="$headerfile">
|
||
<INPUT TYPE="HIDDEN" NAME="username" VALUE="$in{username}">
|
||
<INPUT TYPE="HIDDEN" NAME="password" VALUE="$in{password}">
|
||
<INPUT TYPE="HIDDEN" NAME="command" VALUE="">
|
||
</FORM><br><BR><small>Powered by PerlBlog</small><br><br></tr></table></td></tr></td></tr></table></div>
|
||
EOF
|
||
&printSooter;
|
||
}
|
||
|
||
##########################################################################
|
||
# prints the edit thread page, where you edit the source file to a message
|
||
sub displayEditThread {
|
||
&checkAccess;
|
||
$headerfile = $in{'headerfile'};
|
||
$toedit = $in{'toedit'};
|
||
$toedit =~ s/[\x00-\x20<>\|;\(\)\$^\+!\^\[\]\?\"\'\`]//g;
|
||
&printHeader("");
|
||
print <<"EOF";
|
||
<tr><td><table cellpadding="10" cellspacing="1" border="0" width="750" class="border"><tr><td colspan="0" bgcolor="white"><BR><table width="600" border="0" cellspacing="1" cellpadding="0" bordercolor="white"><table width="600" align="center" border="0" cellspacing="0" cellpadding="0"><h2>Editing/Deleting Entries | <A HREF="weblog.pl">Thread $toedit</A></h2><br><font size="1">Edit within the first <name> parameters for the actual blog entry<br>Comments follow blog entry</font></span><center><BR><BR></B>
|
||
<FORM NAME="forum" ACTION="weblog-admin.pl" METHOD="POST">
|
||
<TEXTAREA NAME="body" class="txt" ROWS=20>
|
||
EOF
|
||
open(DATA,"$forumdir/messages/$toedit.txt");
|
||
@msglines = <DATA>;
|
||
close(DATA);
|
||
foreach $msgline (@msglines) {
|
||
print $msgline;
|
||
}
|
||
print "</TEXTAREA>\n";
|
||
print <<"EOF";
|
||
<BR>
|
||
<INPUT TYPE="HIDDEN" NAME="toedit" VALUE="$toedit">
|
||
<INPUT TYPE="HIDDEN" NAME="headerfile" VALUE="$headerfile">
|
||
<INPUT TYPE="HIDDEN" NAME="username" VALUE="$in{username}">
|
||
<INPUT TYPE="HIDDEN" NAME="password" VALUE="$in{password}">
|
||
<INPUT TYPE="HIDDEN" NAME="command" VALUE="editThread"><BR><BR>
|
||
<INPUT TYPE="Submit" class="submit" VALUE="<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>">
|
||
</FORM><br><BR><small>Powered by PerlBlog</small><br><br></tr></table></td></tr></td></tr></table></div>
|
||
EOF
|
||
&printSooter;
|
||
}
|
||
|
||
##########################################################################
|
||
# sub-routine of &displayPreview that wraps a block of text to a given line length
|
||
# Deleted to see if it affect runing on Linux. Works okay on NTP on PC with Apache
|
||
# Not needed for admin
|
||
|
||
##########################################################################
|
||
# saves the message that was being edited
|
||
sub editThread {
|
||
&checkAccess;
|
||
&printHeader("");
|
||
$headerfile = $in{'headerfile'};
|
||
$toedit = $in{'toedit'};
|
||
$body = $in{'body'}; ### redid, dumped unneeded textwrap subroutine
|
||
@msglines = split(/\n/,$body);
|
||
|
||
open(DATA,">$forumdir/messages/$toedit.txt");
|
||
foreach $msgline (@msglines) {
|
||
if ($msgline !~ /<\/msg>/) {chop($msgline);}
|
||
print DATA "$msgline\n";
|
||
}
|
||
close(DATA);
|
||
|
||
for ($i=0; $i<@msglines; $i++) {
|
||
if ($msglines[$i] =~ /<subject>(.*)<\/subject>/) {
|
||
$subject = $1;
|
||
}
|
||
if ($msglines[$i] =~ /<name>(.*)<\/name>/) {
|
||
$name = $1;
|
||
}
|
||
if ($msglines[$i] =~ /<date>(.*)<\/date>/) {
|
||
$date = $1;
|
||
last;
|
||
}
|
||
}
|
||
$replies = -1;
|
||
for ($i=0; $i<@msglines; $i++) {
|
||
if ($msglines[$i] =~ /<msg>/) {
|
||
$replies += 1;
|
||
$replytime
|
||
}
|
||
}
|
||
open(HEADER,"$forumdir/$headerfile.txt");
|
||
@headers = <HEADER>;
|
||
close(HEADER);
|
||
open(HEADER,">$forumdir/$headerfile.txt");
|
||
foreach $headerline (@headers) {
|
||
@headerdata = split(/_/, $headerline);
|
||
$threadnum = $headerdata[0];
|
||
if ($threadnum == $toedit) {
|
||
@headerdata = split(/_/, $headerline);
|
||
print HEADER "$toedit\_$subject\_$name\_$image\_$postm\_$date\_0\_ \n";
|
||
}
|
||
else {print HEADER "$headerline";}
|
||
}
|
||
close(HEADER);
|
||
|
||
open(ALL,"$forumdir/all.txt");
|
||
@headers = <ALL>;
|
||
close(ALL);
|
||
open(ALL,">$forumdir/all.txt");
|
||
foreach $headerline (@headers) {
|
||
@headerdata = split(/_/, $headerline);
|
||
$threadnum = $headerdata[0];
|
||
if ($threadnum == $toedit) {
|
||
@headerdata = split(/_/, $headerline);
|
||
print ALL "$toedit\_$subject\_$name\_$image\_$postm\_$date\_0\_ \n";
|
||
}
|
||
else {print ALL "$headerline";}
|
||
}
|
||
close(ALL);
|
||
print <<"EOF";
|
||
<tr><td><table cellpadding="10" cellspacing="1" border="0" width="410" class="border"><tr><td colspan="0" bgcolor="white"><BR><table width="410" border="0" cellspacing="1" cellpadding="0" bordercolor="white"><table width="410" align="center" border="0" cellspacing="0" cellpadding="0"><h2>Editing Entries | <A HREF="weblog.pl">Successful</A></h2><BR><BR>
|
||
<P>Message number $toedit has been saved<BR><BR>
|
||
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1"><TR>
|
||
<FORM NAME="forum" ACTION="weblog-admin.pl" METHOD="POST">
|
||
<INPUT TYPE="HIDDEN" NAME="username" VALUE="$in{username}">
|
||
<INPUT TYPE="HIDDEN" NAME="password" VALUE="$in{password}">
|
||
<INPUT TYPE="HIDDEN" NAME="command" VALUE="displayList">
|
||
<INPUT TYPE="Submit" class="submit" VALUE="Choose Different Month">
|
||
</FORM><br>
|
||
<FORM NAME="forum" ACTION="weblog-admin.pl" METHOD="POST">
|
||
<INPUT TYPE="HIDDEN" NAME="username" VALUE="$in{username}">
|
||
<INPUT TYPE="HIDDEN" NAME="password" VALUE="$in{password}">
|
||
<INPUT TYPE="HIDDEN" NAME="headerfile" VALUE="$headerfile">
|
||
<INPUT TYPE="HIDDEN" NAME="command" VALUE="displayThreads">
|
||
<INPUT TYPE="Submit" class="submit" VALUE="Edit This Month Again">
|
||
</FORM>
|
||
|
||
<FORM><br>
|
||
<INPUT TYPE="BUTTON" class="submit" VALUE="View Weblog" onClick="document.location.href='weblog.pl'">
|
||
</FORM><br><BR><small>Powered by PerlBlog</small><br><br></tr></table></td></tr></td></tr></table></div>
|
||
EOF
|
||
&printSooter;
|
||
}
|
||
|
||
##########################################################################
|
||
# deletes the messages that were selected in the &displayThreads page
|
||
sub deleteThreads {
|
||
&checkAccess;
|
||
&printHeader("");
|
||
$headerfile = $in{'headerfile'};
|
||
$todelete = $in{'todelete'};
|
||
@threads = split (/,/, $todelete);
|
||
|
||
open(HEADER,"$forumdir/$headerfile.txt");
|
||
@headerlines = <HEADER>;
|
||
close(HEADER);
|
||
|
||
open(HEADER,">$forumdir/$headerfile.txt");
|
||
for ($i=0; $i<@headerlines; $i++) {
|
||
$remove = "false";
|
||
for ($j=0; $j<@threads; $j++) {
|
||
if ($headerlines[$i] =~ /$threads[$j]_/) {
|
||
$remove = "true";
|
||
}
|
||
}
|
||
if ($remove eq "false") {print HEADER "$headerlines[$i]";}
|
||
}
|
||
close(HEADER);
|
||
|
||
open(ALL,"$forumdir/all.txt");
|
||
@headerlines = <ALL>;
|
||
close(ALL);
|
||
|
||
open(ALL,">$forumdir/all.txt");
|
||
for ($i=0; $i<@headerlines; $i++) {
|
||
$remove = "false";
|
||
for ($j=0; $j<@threads; $j++) {
|
||
if ($headerlines[$i] =~ /$threads[$j]_/) {
|
||
$remove = "true";
|
||
}
|
||
}
|
||
if ($remove eq "false") {print ALL "$headerlines[$i]";}
|
||
}
|
||
close(ALL);
|
||
|
||
foreach $thread (@threads) {
|
||
unlink ("$forumdir/messages/$thread.txt");
|
||
}
|
||
print <<"EOF";
|
||
<tr><td><table cellpadding="10" cellspacing="1" border="0" width="410" class="border"><tr><td colspan="0" bgcolor="white"><BR><table width="410" border="0" cellspacing="1" cellpadding="0" bordercolor="white"><table width="410" align="center" border="0" cellspacing="0" cellpadding="0"><h2>Deleting Entries | <A HREF="weblog.pl">Successful</A></h2><BR><BR><P>The following threads were removed:<BR>
|
||
EOF
|
||
foreach $thread (@threads) {
|
||
print "$thread,";
|
||
}
|
||
print <<"EOF";
|
||
<BR><BR>
|
||
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1"><TR>
|
||
<FORM NAME="forum" ACTION="weblog-admin.pl" METHOD="POST">
|
||
<INPUT TYPE="HIDDEN" NAME="username" VALUE="$in{username}">
|
||
<INPUT TYPE="HIDDEN" NAME="password" VALUE="$in{password}">
|
||
<INPUT TYPE="HIDDEN" NAME="command" VALUE="displayList">
|
||
<INPUT TYPE="Submit" class="submit" VALUE="Choose Different Month">
|
||
</FORM><br>
|
||
<FORM NAME="forum" ACTION="weblog-admin.pl" METHOD="POST">
|
||
<INPUT TYPE="HIDDEN" NAME="username" VALUE="$in{username}">
|
||
<INPUT TYPE="HIDDEN" NAME="password" VALUE="$in{password}">
|
||
<INPUT TYPE="HIDDEN" NAME="headerfile" VALUE="$headerfile">
|
||
<INPUT TYPE="HIDDEN" NAME="command" VALUE="displayThreads">
|
||
<INPUT TYPE="Submit" class="submit" VALUE="Edit This Month Again">
|
||
</FORM><br>
|
||
<FORM>
|
||
<INPUT TYPE="BUTTON" class="submit" VALUE="View weblog" onClick="document.location.href='weblog.pl'">
|
||
</FORM><br><BR><small>Powered by PerlBlog</small><br><br></tr></table></td></tr></td></tr></table></div>
|
||
EOF
|
||
&printSooter;
|
||
}
|
||
|
||
##########################################################################
|
||
# common HTML header for all pages
|
||
sub printHeader {
|
||
my($title) = @_;
|
||
print "Content-type: text/html\n\n";
|
||
print "<html><meta http-equiv=\"Content-Type\" content='text/html; charset=$charset'><head>";
|
||
if ($cookieHash{'light'}){print '<link type="text/css" rel="stylesheet" href="white.css">';}
|
||
else {print '<link type="text/css" rel="stylesheet" href="black.css">';}
|
||
print <<"EOF";
|
||
<title>$blogtitle</title>
|
||
<meta name="description" content="$description" />
|
||
<meta name="keywords" content="$keywords" />
|
||
<meta name="author" content="$author" />
|
||
</head>
|
||
<body>
|
||
EOF
|
||
print "<span class=ftitle>$title</span>\n";
|
||
print "<P>\n";
|
||
}
|
||
##########################################################################
|
||
# common HTML footer for all pages
|
||
sub printFooter {
|
||
open FOOTER, "$forumdir/footer.txt"
|
||
or die "Can't open footer file because $!\n";
|
||
print while (<FOOTER>);
|
||
close FOOTER;
|
||
}
|
||
print "\n<br></body></html>\n\n";
|