#!/usr/bin/perl my $r = Apache->request; print "HTTP/1.1 200 OK Server: Apache/1.3b3 mod_perl/1.08 "; use DBI; use strict 'vars'; require 'ctime.pl'; use slashmod; my ($imagedir,$rootdir,$datadir)=slashmod::config(); my $dbh; sub main { $dbh ||= slashmod::dbconnect(); my %FORM = slashmod::getform(); my %COOKIES = slashmod::getcookies(); my ($aid, $thisuser, $error, $email, $url, $seclev)=("", "","","","",0); if ($COOKIES{session} ne "") { ($aid,$seclev)=slashmod::getadmininfo($COOKIES{session}); } if (defined $FORM{aid} and defined $FORM{pwd}) { ($aid,$seclev)=slashmod::setadmininfo($FORM{aid},$FORM{pwd}); } ($thisuser,$email,$url)=slashmod::getuserinfo($COOKIES{userinfo}); $thisuser=$aid; print "Content-Type: text/html\n\n"; slashmod::header("Slashdot Admin","nohead"); print "

 

"; if($seclev > 0) { print " [ Logout $aid | Home | List | Topics "; } if($seclev > 10) { print " | New | Modify "; } if($seclev > 499) { print " | Submissions"; } if($seclev > 1000) { print " | Blocks | Polls "; } if($seclev > 10000) { print " | Authors | Variables "; } if($seclev > 0) { print "]

"; } if(not $seclev) { slashmod::titlebar("99%","Login $error"); print "

Login
Password
"; } elsif($FORM{'op'} eq "logout") { $dbh->do("DELETE FROM sessions WHERE aid='$aid'"); print "You are now logged out. Bub-Bye"; } elsif($FORM{'op'} eq "submissions" or $FORM{op} eq "rmsub" or $FORM{op} eq "GenQuickies") { slashmod::titlebar("99%","Submissions Admin"); submissioned(%FORM); } elsif($FORM{op} eq "topiced") { topiced(%FORM); } elsif($FORM{'op'} eq "viewsub") { editstory($aid,"",$FORM{subid}); } elsif($FORM{'op'} eq "save") { $FORM{dept}=~ s/'/''/gi; $FORM{title}=~ s/'/''/gi; $FORM{bodytext}=~ s/'/''/gi; $FORM{introtext}=~ s/'/''/gi; my $cursor=$dbh->prepare("INSERT into stories (sid,aid,tid,title,dept,introtext,bodytext, time,writestatus,commentcount,hits,section) VALUES('$FORM{sid}', '$FORM{aid}', '$FORM{tid}', '$FORM{title}', '$FORM{dept}','$FORM{introtext}', '$FORM{bodytext}', NOW(),1,0,0,'$FORM{section}')"); $cursor->execute; $cursor->finish; slashmod::titlebar("99%","Article Saved","c"); liststories($aid,$FORM{next}); } elsif($FORM{'op'} eq "update") { $FORM{dept}=~ s/'/''/gi; $FORM{bodytext}=~ s/'/''/gi; $FORM{introtext}=~ s/'/''/gi; $FORM{title}=~ s/'/''/gi; my $cursor=$dbh->prepare("UPDATE stories set aid='$FORM{aid}', tid='$FORM{tid}', title='$FORM{title}', dept='$FORM{dept}', introtext='$FORM{introtext}', bodytext='$FORM{bodytext}', section='$FORM{section}', writestatus=1 WHERE sid=\"$FORM{sid}\""); $cursor->execute; slashmod::titlebar("99%","Article Updated","c"); } elsif($FORM{'op'} eq "list") { slashmod::titlebar("99%","Article List","c"); liststories($aid,$FORM{next}); } elsif($FORM{'op'} eq "delete") { rmstory($aid,$FORM{sid}); liststories($aid,$FORM{next}); } elsif($FORM{'op'} eq "preview") { editstory($aid,"","",%FORM); } elsif($FORM{'op'} eq "edit") { slashmod::titlebar("99%","Article Editor","c"); editstory($aid, $FORM{sid}); } elsif($FORM{'op'} eq "topics") { listtopics($seclev); } elsif($FORM{'op'} eq "blocks") { blocklist(); } elsif($FORM{'op'} eq "blocksave") { blocksave(%FORM); } elsif($FORM{'op'} eq "blockadmin") { blockadmin(%FORM); } elsif($FORM{'op'} eq "authors") { listauthors(); } elsif($FORM{'op'} eq "authorsave") { saveauthors(%FORM); listauthors(); } elsif($FORM{'op'} eq "vars") { listvars(); } elsif($FORM{'op'} eq "savevars") { savevars(%FORM); listvars(); } else { slashmod::titlebar("99%","Story List","c"); liststories("",$FORM{next}); } slashmod::writelog("admin",$aid); if($seclev > 0) { print "

Current Users: "; my $c=$dbh->prepare("SELECT aid FROM sessions GROUP BY aid ORDER BY aid"); $c->execute(); while(my ($aid)=$c->fetchrow()) { print "$aid "; } $c->finish(); } print "   "; } sub submissioned { my (%FORM)=@_; if($FORM{op} eq "rmsub") { $dbh->do("DELETE from submissions where subid='$FORM{subid}'"); delete $FORM{op}; delete $FORM{subid}; foreach my $key (keys %FORM) { my ($t,$n)=split("_",$key); if($t eq "note") { if($FORM{$key} ne "") { print "$n "; $dbh->do("UPDATE submissions set note='$FORM{$key}' WHERE subid='$n'") } } else { print "$key " unless not $dbh->do("DELETE from submissions WHERE subid='$key'"); } } } if(lc($FORM{op}) eq "genquickies") { my $c=$dbh->prepare("SELECT story FROM submissions WHERE subid='quickies'"); $c->execute(); my ($stuff)=$c->fetchrow(); $dbh->do("DELETE FROM submissions WHERE subid='quickies'"); $c=$dbh->prepare("SELECT subid,subj,email,name,story FROM submissions WHERE note='Quik'"); $c->execute(); while(my ($subid, $subj, $email, $name, $story)=$c->fetchrow()) { $stuff.=" $name writes \"$story\"\n\n"; } $stuff=~s/'/''/g; my $strSQL="INSERT into submissions (subid,subj,email,name,time,story) VALUES('quickies','Generated Quickies', '','',now(),'$stuff')"; print "$strSQL"; $dbh->do($strSQL); $c->finish(); } print "

"; my $cursor=$dbh->prepare("SELECT subid, subj, time,tid,note FROM submissions ORDER BY time"); $cursor->execute; my ($subid, $subj, $time,$tid,$note)=""; while(($subid, $subj, $time,$tid,$note)=$cursor->fetchrow) { print "
$time $subj  (delete) $tid "; } print "

"; $cursor->finish; } sub topiced { my (%FORM)=@_; if($FORM{tid} ne "") { $dbh->do("DELETE from topics WHERE tid='$FORM{tid}'"); $dbh->do("INSERT into topics VALUES('$FORM{tid}','$FORM{image}', '$FORM{alttext}','$FORM{width}', '$FORM{height}')"); } print "
"; my $c=$dbh->prepare("SELECT tid,width,height,alttext,image FROM topics WHERE tid='$FORM{nexttid}'"); $c->execute; my ($tid,$width,$height,$alttext,$image)=$c->fetchrow(); if($FORM{nexttid} ne "") { print "
\"$alttext\""; } print "
Tid

"; print " Dimensions

Alt Text

Image

"; } sub blockadmin { my (%FORM)=@_; slashmod::titlebar("98%","Block:$FORM{bid}"); print "
"; my $c=$dbh->prepare("SELECT bid FROM blocks order by bid"); $c->execute(); print "Block Name:
"; my $blockcontents=""; if(defined $FORM{newbid}) { print "Inserted $FORM{newbid}
"; $dbh->do("INSERT into blocks VALUES('$FORM{newbid}','$FORM{block}')"); } if($FORM{button} eq "new") { print "
"; } elsif($FORM{button} eq "del") { print "Deleted $FORM{bid}
"; $dbh->do("DELETE from BLOCKS where bid='$FORM{bid}'"); } else { print "Saving $FORM{oldbid}
"; $dbh->do("UPDATE blocks set block='$FORM{block}' WHERE bid='$FORM{oldbid}' "); } if($FORM{bid} ne "" and $FORM{button} ne "new") { my $c=$dbh->prepare("SELECT block FROM blocks where bid='$FORM{bid}'"); $c->execute(); ($blockcontents)=$c->fetchrow(); } $c->finish(); print "
"; } sub listvars { my $c=$dbh->prepare("SELECT name,value,description FROM vars"); $c->execute(); print "
"; while(my ($name, $value, $desc)=$c->fetchrow()) { print "

$name $desc
"; } $c->finish(); print "

New Variable
Name
Desc
Value

"; } sub savevars { my (%FORM)=@_; # Update Each Var foreach (keys %FORM) { if(not /new_/ and $_ ne "op" and $_ ne "submit") { slashmod::setvar($_,$FORM{$_}); print "$_ = $FORM{$_}
"; } } $dbh->do("DELETE from vars where value=''"); if($FORM{new_name} ne "") { print "Inserting $FORM{new_name}
"; slashmod::newvar($FORM{new_name}, $FORM{new_value}, $FORM{new_desc}); } } sub listauthors { my $c=$dbh->prepare("SELECT aid,name,url,email,pwd,seclev, copy,quote FROM authors"); $c->execute(); print "
"; while(my ($aid, $name, $url, $email, $pwd, $seclev)=$c->fetchrow()) { slashmod::titlebar("99%",$aid,"nc"); print "

"; } $c->finish(); slashmod::titlebar("99%","New User","nc"); print "

"; print "

Completely useless. Don't bother trying to

"; } sub saveauthors { my (%FORM)=@_; my @authors; # Get the list of all my $c=$dbh->prepare("SELECT aid FROM authors"); $c->execute(); while(my ($aid)=$c->fetchrow) { push @authors, $aid; } $c->finish(); foreach my $key (@authors) { print "Updating $key ".$FORM{$key."_email"}."
"; my $c=$dbh->prepare("UPDATE authors SET pwd='".$FORM{$key."_pwd"}."', email='".$FORM{$key."_email"}."', seclev='".$FORM{$key."_seclev"}."', name='".$FORM{$key."_name"}."', url='".$FORM{$key."_url"}."', copy='".$FORM{$key."_copy"}."', quote='".$FORM{$key."_quote"}."' WHERE aid='$key'"); $c->execute(); $c->finish(); } $dbh->do("DELETE from authors where seclev=0"); # Insert Newbie if($FORM{new_aid} ne "") { $dbh->do("INSERT into authors VALUES('$FORM{new_aid}', '$FORM{new_name}', '$FORM{new_url}', '$FORM{new_email}', '','', '$FORM{new_pwd}', $FORM{new_seclev})"); print "Inserted $FORM{new_aid}\n
"; } } sub blocklist() { my $c=$dbh->prepare("SELECT block,bid FROM blocks"); $c->execute(); print "
"; while(my ($block, $bid)=$c->fetchrow()) { slashmod::titlebar("99%","$bid"); print "

"; } $c->finish(); slashmod::titlebar("99%","New Block"); print "Name:
"; } sub blocksave() { my (%FORM)=@_; foreach my $key (keys %FORM) { if($key ne "newblock" and $key ne "newname" and $key ne "op") { $FORM{$key}=~s/'/''/g; if($FORM{$key} ne "") { print "Updating $key
"; $dbh->do("UPDATE blocks SET block='$FORM{$key}' WHERE bid='$key'"); } else { print "Deleting $key
"; $dbh->do("DELETE from blocks WHERE bid='$key'"); } } } if($FORM{newname} ne "" and $FORM{newblock} ne "") { $FORM{newblock}=~s/'/''/g; $dbh->do("INSERT into blocks VALUES('$FORM{newname}', '$FORM{newblock}', '')"); print "$FORM{newname} Inserted."; } else { print "No need to insert anything new $FORM{newname}
"; } } sub rmstory { my ($aid, $sid) =@_; $dbh->do("UPDATE stories set writestatus=5 WHERE ('$aid'=aid OR '$aid'='CmdrTaco') AND '$sid'=sid"); slashmod::titlebar("99%","$sid will probably be deleted in 60 seconds."); } sub listtopics { my ($seclev)=$_[0]; my ($tid,$image, $alttext, $width, $height)=""; my $cursor=$dbh->prepare("SELECT tid,image,alttext,width,height FROM topics ORDER BY tid"); slashmod::titlebar("99%","Topic Lister"); my $x=0; $cursor->execute; print ""; while(($tid,$image,$alttext,$width,$height)=$cursor->fetchrow) { if($x++ % 5 == 0) { print ""; } print ""; } print "
"; if($seclev > 1000) { print ""; } print " \"$alttext\"
$tid
"; } sub editstory { my ($author,$sid,$subid,%FORM) = @_; my ($cursor,$thisection,$thistype); my ($title,$dept,$aid,$tid,$introtext,$bodytext,$time)=""; print" "; if(defined %FORM) { $title=$FORM{title}; $dept=$FORM{dept}; $aid=$FORM{aid}; $tid=$FORM{tid}; $introtext=$FORM{introtext}; $bodytext=$FORM{bodytext}; $thisection=$FORM{section}; slashmod::titlebar("99%","$title"); $dept=~ s/ /-/gi; $sid=slashmod::getsid(); print "from the $dept dept.
$introtext

$bodytext"; print "

"; print ""; }elsif(defined $subid) { # Format a submission for article editing. $cursor=$dbh->prepare("SELECT subid, email, name, subj, tid, story FROM submissions WHERE subid='$subid'"); $cursor->execute(); my ($subid, $email, $name); ($subid, $email, $name, $title, $tid, $introtext)=$cursor->fetchrow(); $introtext=~s/\n\n/

/gi; $introtext=$introtext." "; # Add a charachter so regex works $introtext=~s/(?!"|=)(.|\n|^)(http|ftp|gopher|telnet):\/\/(.*?)[\s]/ link <\/A> /gi; print "

$name $email

$introtext

[ Delete Submission ]
"; $introtext="$name writes \"$introtext\""; $sid=slashmod::getsid(); $thisection="articles"; print " "; } elsif(defined $sid) { $thistype="edit"; $cursor=$dbh->prepare("SELECT title,aid, dept,tid, introtext, bodytext,time,section FROM stories WHERE sid='$sid'"); $cursor->execute; ($title,$aid,$dept,$tid,$introtext,$bodytext,$time,$thisection) =$cursor->fetchrow; print "Article Created on $time

"; } else { $sid=slashmod::getsid(); $tid="news"; $thisection="articles"; print " "; } print "
title
dept
topic type
Intro Copy

"; if($thistype eq "edit") { print "
"; } else { print "
"; } print " Extended Copy

"; if($thistype eq "edit") { print "
"; } else { print "
"; } } sub getsections { my ($r,$tid)=""; my $cursor=$dbh->prepare("SELECT section from sections"); $cursor->execute(); while(my ($section)=$cursor->fetchrow) { $r.="

$left More"; } } main(); $dbh->disconnect() unless not $dbh; 1;