#!/usr/local/bin/perl # Berita Surgawi - modified for Sahabat Surgawi by Daniel V. Kaunang ###################################################################### # Online News Updater and Manager - Version 2.0b - 05/02/1999 # Copyright 1998 - AA Consulting - By Tony Awtrey # tony@awtrey.com - http://www.awtrey.com/ # # This application is licensed under the GNU Public License. # For more information see: http://www.gnu.org/copyleft/gpl.html # # # With generous contributions made by: # Jeremy Janssens # Keith McDuffee # Anita Foster # # Changes made since version 1.0: # # * Added Y2K fix. If you have been using the 1.0 version of this # script and wish to preserve your existing news file, grab a # copy of the convnews.pl script. This will change the file names # to the new date format. Old version news files will not be read # by this script. If you have never used this script or do not # care to preserve your old news, don't bother getting it. # # * Added an optional "Front Page" news section. The news script # will update a static HTML page if you add the two tags: # # # The script puts the date as an HTML anchor and updates the most # current headlines on a static HTML page. Clicking the date will # take you to that days stories. # # * News is now listed in latest story first order. # # * You can now edit and delete news from the browser. # # * Fixed the news archive bug. # # * Various minor scripting and layout errors fixed. # # This script requires the use of .htpasswd and .htgroup files. # These files are useful for restricting access to private # sections of a website as well as providing a framework # for easy site management. See the web page for complete # instructions and the latest scripts. # # The only variable you might question is the $num_of_days # which refers to the number of days that you actually posted news. # You will not ever have a blank news page because of archiving. ###################################################################### #Program Vars $webmaster = "Tri Purwito"; $webmastername = "webmaster"; $webmasterdomain = "sahabatsurgawi.net"; $basedir = "/home/sahabatsurgawi/html"; $baseurl = "http://www.sahabatsurgawi.net"; $cgidir = "http://www.sahabatsurgawi.net/cgi"; $newsdir = "$basedir/news"; $htaccess_dir = "$basedir/private"; $htpasswd_file = ".htpasswd"; $htgroup_file = ".htgroup"; $timezone = "WIB"; $num_of_days = "2"; $fpfile = "index.html"; #Leave blank if you don't want this feature. if ($fpfile) { $fpnews = "$basedir/$fpfile"; } if ($fpfile) { $fpurl = "$baseurl/$fpfile"; } $cgifile = "beritasurgawi3.cgi"; $cgiurl = "$cgidir/$cgifile"; $lockfile = "lock.lok"; $backfile = "backup.news"; ################################### #HTML Vars $title = "Berita Surgawi"; $stylesheet = "global.css"; $bgcolor = "#FFFFFF"; $background = "images/ss_back_2.gif"; $text = "#000000"; $link = "#000000"; $vlink = "#00008C"; $titlecolor = "#000000"; $titlepostingcolor = "#6699CC"; $fontsize = "1"; $fontname = "Verdana"; $ttl_bgcolor = "#FFFFFF"; $body_bgcolor= "#FFFFFF"; require "template3ss.cgi"; #DO NOT MODIFY ANYTHING BELOW HERE ################################### ################################### #Start Main Prog if ($ENV{'QUERY_STRING'} eq "archive") { &get_news_files; &archive; } elsif ($ENV{'QUERY_STRING'} eq "admin") { &admin; } elsif ($ENV{'QUERY_STRING'} =~ /^edit/) { &get_news_files; &edit; } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { &form_vars; if ($FORM{'formtype'} eq 'addnews') { &addnews; } if ($FORM{'formtype'} eq 'editnews') { &editnews; } } elsif ($ENV{'QUERY_STRING'} =~ /\d{8}/) { if (length($ENV{'QUERY_STRING'}) < 9 ) { $thenewsday = $ENV{'QUERY_STRING'}; &get_news_files; &newsbyday; } } else { &get_news_files; &print_html_header; print "

Add News
\n"; print "Edit News

\n"; $thismany = 0; while ($thismany < $num_of_days) { &print_news(@newsfiles[$thismany]); $thismany++; } print "
\n"; #print "
If you are looking for our news archive, click\n"; print "Berita Surgawi News Archives.
"; print "Berita Surgawi maintained by Sahabat Surgawi
\n"; &print_html_footer; } exit; #End Main Prog ################################### ################################### #Form Subroutines sub archive { $title = "News Archive"; $current_year = "0"; $current_month = "0"; @months = ("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"); &print_html_header; foreach $nfn (@newsfiles) { $year = substr($nfn, 0, 4); $month = substr($nfn, 4, 2); $day = substr($nfn, 6, 2); $mon = ($month-1); if ($year ne $current_year) { $current_year = $year; $current_month = $month; print "

$current_year

\n"; print "
$months[$mon]
\n

\n"; print " $day"; next; } if ($month ne $current_month) { $current_month = $month; print "

\n
$months[$mon]
\n

\n"; print " $day"; next; } else { print " $day"; } } print "


\n"; print "

\n"; #print "If you are looking for our current news, click\n"; print "Current News.\n"; print "

\n"; &print_html_footer; } sub edit { $editstr = $ENV{'QUERY_STRING'}; if ($editstr =~ /=/) { ($name, $value) = split(/=/, $editstr); &newsedit($value); exit; } $title = "News Editor"; $current_year = "0"; $current_month = "0"; @months = ("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"); &print_html_header; foreach $nfn (@newsfiles) { $year = substr($nfn, 0, 4); $month = substr($nfn, 4, 2); $day = substr($nfn, 6, 2); $mon = ($month-1); if ($year ne $current_year) { $current_year = $year; $current_month = $month; print "

$current_year

\n"; print "
$months[$mon]
\n

\n"; print " $day"; next; } if ($month ne $current_month) { $current_month = $month; print "

\n
$months[$mon]
\n

\n"; print " $day"; next; } else { print " $day"; } } &print_html_footer; } sub admin { $title = "Add News"; &print_html_header; print "

\n"; print "
\n"; print "\n"; print "

Username:\n"; print "\n"; print "
\n"; print "Password:\n"; print "\n"; print "
\n"; print "Headline:\n"; print "\n"; print "

\n"; print "

News:

\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; &print_html_footer; } sub addnews { $testvar = 1; $title = "News Added"; $username = "$FORM{'user'}"; $password = "$FORM{'passwd'}"; if ($FORM{'headline'}) { $headline = "$FORM{'headline'}"; } else { &error_response(noheadline); return; } if ($FORM{'news'}) { $news = "$FORM{'news'}"; $news =~ s/\cM//g; $news =~ s/\n\n/

/g; $news =~ s/\n/
/g; $news =~ s/<//g; $news =~ s/"/"/g; } else { &error_response(nobody); return; } &check_passwd; &get_date; $nfn = "$labr_date\.news"; &print_html_header; print "

$headline - $short_time by $username
\n"; print "

\n"; print "$news\n"; print "

\n"; if (-e "$newsdir/$nfn") { print "

Using Existing News File

\n"; &check_lock; open(NFILE, "$newsdir/$nfn") || &error_response(badfile); open(BFILE, ">$newsdir/$backfile") || &error_response(badfile); while () { print BFILE; } close(BFILE); close(NFILE); open(BFILE, "$newsdir/$backfile") || &error_response(badfile); open(NFILE, ">$newsdir/$nfn") || &error_response(badfile); print NFILE "$short_time\n"; print NFILE "$headline\n"; print NFILE "$username\n"; print NFILE "$news\n"; print NFILE "$short_time\n"; while () { print NFILE; } close(NFILE); close(BFILE); unlink("$newsdir/$backfile"); unlink("$newsdir/$lockfile"); print "Return to the News Page\n"; if ($fpfile) { print "
Return to the Front Page\n"; } } else { print "

Creating New News File\: $nfn

\n"; &check_lock; open(NFILE, ">$newsdir/$nfn") || &error_response(badfile); print NFILE "$short_time\n"; print NFILE "$headline\n"; print NFILE "$username\n"; print NFILE "$news\n"; print NFILE "$short_time\n"; close(NFILE); print "Return to the News Page\n"; if ($fpfile) { print "
Return to the Front Page\n"; } unlink("$newsdir/$lockfile"); } if ($fpnews) { &dofpnews; } &print_html_footer; } sub editnews { $title = "News Updated"; $username = "$FORM{'user'}"; $password = "$FORM{'passwd'}"; &check_passwd; &get_date; $nfn = $FORM{'newsfile'}; &print_html_header; if ($FORM{'delday'} eq 'y') { print "

Deleting News File\: $nfn

\n"; &check_lock; unlink("$newsdir/$nfn"); unlink("$newsdir/$lockfile"); } else { print "

Editing News File\: $nfn

\n"; &check_lock; open(NFILE, ">$newsdir/$nfn") || &error_response(badfile); $howmany = $FORM{'numstory'}; for ($snum=1; $snum<=$howmany; $snum++) { $delete = "delete" . $snum; $delete = "$FORM{$delete}"; if ($delete eq 'y') { next; } $storytime = "storytime" . $snum; $headline = "headline" . $snum; $author = "author" . $snum; $news = "news" . $snum; $storytime = $FORM{$storytime}; $headline = $FORM{$headline}; $author = $FORM{$author}; $news = $FORM{$news}; $news =~ s/\cM//g; $news =~ s/\n\n/

/g; $news =~ s/\n/
/g; $news =~ s/<//g; $news =~ s/"/"/g; print NFILE "$storytime\n"; print NFILE "$headline\n"; print NFILE "$author\n"; print NFILE "$news\n"; print NFILE "$storytime\n"; } close(NFILE); } print "\n\nReturn to the News Page\n"; if ($fpfile) { print "
Return to the Front Page\n"; } unlink("$newsdir/$lockfile"); if ($fpnews) { &dofpnews; } &print_html_footer; } sub newsedit { $editnewsfile = $_[0]; $year = substr($editnewsfile, 0, 4); $month = substr($editnewsfile, 4, 2); $day = substr($editnewsfile, 6, 2); $mon = ($month-1); @months = ("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"); &print_html_header; print "

Edit News for $months[$mon] $day, $year
\n"; print "
\n"; print "
\n"; print "\n"; print "

Username:\n"; print "\n"; print "
\n"; print "Password:\n"; print "\n"; print "

\n"; $filename = $editnewsfile . ".news"; &check_lock; open(NFILE, "$newsdir/$filename") || &error_response(badfile); @newsdata =; close(NFILE); unlink("$newsdir/$lockfile"); $nidx = "0"; $ndt = "0"; $snum = 0; foreach $newsline (@newsdata) { chop($newsline) if ($newsline =~ /\n/); if ($nidx == "0") { $storytime = $newsline; $ndt = "2"; $nidx++; next; } elsif ($ndt == "1") { $snum++; $news = ''; $author = $newsline; print "\n
Headline:\n"; print "\n"; print "Delete: \n"; print "\n"; print "\n"; $ndt--; next; } elsif ($ndt == "2") { $headline = $newsline; $ndt--; next; } elsif ($ndt == "3") { $storytime = $newsline; $ndt--; next; } elsif ($storytime eq $newsline) { $ndt = "3"; $news =~ s/

/\n\n/g; $news =~ s/
/\n/g; print "
\n"; next; } else { $news = $news.$newsline; } } print "\n\n"; print "\n"; print "Delete News Day: \n"; &print_html_footer; } sub newsbyday { $title = "News Day Archive"; $newsfilename = "$thenewsday\.news"; foreach $nfn (@newsfiles) { if ($newsfilename eq $nfn) { &print_html_header; &print_news($newsfilename); print "


\n"; print "

\n"; print "\n"; print "Back to Main.\n"; #print "If you are looking for our current news, click\n"; print "Current News.\n"; print "
\n"; #print "If you are looking for our news archive, click\n"; print "News Archive.\n"; print "
\n"; #print "If you want to edit this news day, click\n"; print "Edit News Day.\n"; print "
\n"; print "

\n"; &print_html_footer; return; } } &error_response(noday); return; } sub print_news { $newsfilename = $_[0]; $year = substr($newsfilename, 0, 4); $month = substr($newsfilename, 4, 2); $day = substr($newsfilename, 6, 2); $mon = ($month-1); if ($year == "") { $thismany = $num_of_days; } if ($thismany < $num_of_days) { @months = ("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"); print "

$day $months[$mon], $year

\n"; &check_lock; open(NFILE, "$newsdir/$newsfilename") || &error_response(badfile); @newsdata =; close(NFILE); unlink("$newsdir/$lockfile"); $nidx = "0"; $ndt = "0"; foreach $newsline (@newsdata) { chop($newsline) if ($newsline =~ /\n/); if ($nidx == "0") { $storytime = $newsline; $nidx++; $ndt = "2"; next; } elsif ($ndt == "1") { $author = $newsline; print "
$headline - $storytime by $author

\n"; $ndt--; $nidx++; next; } elsif ($ndt == "2") { $headline = $newsline; $ndt--; $nidx++; next; } elsif ($ndt == "3") { $storytime = $newsline; $ndt--; $nidx++; next; } elsif ($storytime eq $newsline) { $ndt = "3"; print "

\n"; $nidx++; next; } else { print "$newsline\n"; $nidx++; } } print "\n"; } } sub dofpnews { print "

You are using news on the front page. Adding headlines.

\n"; &get_news_files; if (!(-e "$basedir/news/wc")) { link ("$fpnews", "$basedir/news/wc") || &error_response(badfile); } open(WC, "$basedir/news/wc") || &error_response(badfile); @index = ; close(WC); foreach $inline (@index) { if ($place == 1) { if (!($inline =~ //)) { next; } else { $place=2; next; } } elsif ($place == 2) { $after = $after . $inline; next; } elsif ($inline =~ //) { $place = 1; next; } else { $before = $before . $inline; } } while ($before =~ /\n$/) { chop($before); } while ($after =~ /\n$/) { chop($after); } open(WC, ">$basedir/news/wc") || &error_reponse(badfile); print WC "$before\n"; print WC "\n"; $thismany = 0; while ($thismany < $num_of_days) { &print_fpnews(@newsfiles[$thismany]); $thismany++; } print WC "
Berita Seluruhnya\n"; print WC "\n"; print WC "$after\n"; } sub print_fpnews { $newsfilename = $_[0]; $ndurl = "$cgiurl?".substr($newsfilename,0,8); $year = substr($newsfilename, 0, 4); $month = substr($newsfilename, 4, 2); $day = substr($newsfilename, 6, 2); $mon = ($month-1); if ($year == "") { $thismany = $num_of_days; } if ($thismany < $num_of_days) { @months = ("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"); print WC "$day $months[$mon], $year
\n"; &check_lock; open(NFILE, "$newsdir/$newsfilename") || &error_response(badfile); @newsdata =; close(NFILE); unlink("$newsdir/$lockfile"); $nidx = "0"; $ndt = "0"; foreach $newsline (@newsdata) { chop($newsline) if ($newsline =~ /\n/); if ($nidx == "0") { $storytime = $newsline; $nidx++; $ndt = "2"; next; } elsif ($ndt == "1") { $author = $newsline; print WC "  $headline
\n"; $ndt--; $nidx++; next; } elsif ($ndt == "2") { $headline = $newsline; $ndt--; $nidx++; next; } elsif ($ndt == "3") { $storytime = $newsline; $ndt--; $nidx++; next; } elsif ($storytime eq $newsline) { $ndt = "3"; $nidx++; next; } else { $nidx++; } } print WC "\n"; } } #End Form Subroutines ################################### ################################### #Real Subroutines sub print_html_header { print "Content-type: text/html\n\n"; print $prehead; print $prenews; require 'sidenavss.cgi'; print $prenews2; print $title print $prenews3; } sub print_html_footer { print $postnews; print "\n"; print "\n"; } sub form_vars { 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; $value =~ s///g; #$value =~ s/<([^>]|\n)*>//g; $FORM{$name} = $value; } } sub getaddr { $hostname = $ENV{'REMOTE_HOST'}; if ($ENV{'REMOTE_HOST'} && ($ENV{'REMOTE_HOST'} !~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/)) { $hostname = $ENV{'REMOTE_HOST'}; } else { &address_to_name ($ENV{'REMOTE_ADDR'}); } } #after close() be sure to add: unlink("$newsdir/$lockfile"); sub check_lock { $count=0; while (-e "$newsdir/$lockfile") { sleep(3); $count++; if ($count > 8){ last; } } if (-e "$newsdir/$lockfile") { &error_response(busy); } open (LOCK,">$newsdir/$lockfile"); close LOCK; } sub get_date { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } if ($hour > 11){ $ampm="pm $timezone"; if($hour > 12){ $hour=$hour-12; } } else{ $ampm="am $timezone"; } $month = ($mon + 1); if ($month < 10) { $month = "0$month"; } if ($mon < 10) { $mon = "0$mon"; } if ($mday < 10) { $mday = "0$mday"; } @months = ("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"); $abr_date = "$year$month$mday"; $long_year = 1900 + $year; $labr_date = "$long_year$month$mday"; $long_date = "$mday $months[$mon], $long_year at $hour\:$min $ampm"; $short_date = "$mday $months[$mon], $long_year"; $short_time = "$hour\:$min $ampm"; } sub error_response { $error = $_[0]; if ($error eq 'noday') { $title = "No News On That Day!"; &print_html_header; print "

Please try a different day
.\n"; print "Return to the News Page

\n"; if ($fpfile) { print "
Return to the Front Page\n"; } &print_html_footer; exit; } elsif ($error eq 'noheadline') { $title = "You Forgot to give a topic !"; &print_html_header; print "

Please don't forget to enter your topic
.\n"; print "Return to the News Page

\n"; if ($fpfile) { print "
Return to the Front Page\n"; } &print_html_footer; exit; } elsif ($error eq 'invalid_day') { $title = "Not a valid newsday format!!"; &print_html_header; print "

This is not a valid date?
\n"; print "Return to the News Page

\n"; if ($fpfile) { print "
Return to the Front Page\n"; } &print_html_footer; exit; } elsif ($error eq 'nobody') { $title = "You forgot your text !"; &print_html_header; print "

The Body of this message was empty.
\n"; print "Return to the News Page

\n"; if ($fpfile) { print "
Return to the Front Page\n"; } &print_html_footer; exit; } elsif ($error eq 'badfile') { $title = "File Error!!"; &print_html_header; print "\n\n"; print "

There was an unexpected file error.
Please contact webmaster.
\n"; print "Return to the News Page

\n"; if ($fpfile) { print "
Return to the Front Page\n"; } &print_html_footer; exit; } elsif ($error eq 'badcombo') { $title = "Bad Username/Password!!"; &print_html_header; print "

Bad Username/Password!
\n"; print "Return to the News Page

\n"; if ($fpfile) { print "
Return to the Front Page\n"; } &print_html_footer; exit; } elsif ($error eq 'notnews') { $title = "Unauthorized Data Entry!!"; &print_html_header; print "

$title
\n"; print "Return to the News Page

\n"; if ($fpfile) { print "
Return to the Front Page\n"; } &print_html_footer; exit; } else { $title = "Unspecified News Error!"; &print_html_header; print "

Oops.

\n"; &print_html_footer; exit; } } sub get_news_files { opendir(NEWS, $newsdir); @newsfiles = reverse(sort(grep(/.\.news/, readdir(NEWS)))); closedir(NEWS); } sub check_passwd { &is_news; $sent_user = $FORM{'user'}; $sent_pw = $FORM{'passwd'}; open(HTPASSWD, "$htaccess_dir/$htpasswd_file") || &error_response(badfile); @htpasswd = ; close(HTPASSWD); foreach $passwd_line (@htpasswd) { chop($passwd_line) if ($passwd_line =~ /\n/); ($real_user,$real_pw) = split(/:/,$passwd_line); if (!($real_user eq $sent_user)) { next; } if ($real_pw =~ /^\$1\$/) { $enc_pw = crypt($sent_pw,substr($real_pw, 3, 2)); } else { $enc_pw = crypt($sent_pw,substr($real_pw, 0, 2)); } if (!($enc_pw eq $real_pw)) { &error_response(badcombo); } else { return; } } &error_response(badcombo); } sub is_news { $sent_user = $FORM{'user'}; $sent_pw = $FORM{'passwd'}; open(HTGROUP, "$htaccess_dir/$htgroup_file") || &error_response(badfile); @htgroup = ; close(HTGROUP); foreach $group_line (@htgroup) { chop($group_line) if ($group_line =~ /\n/); ($group,$members) = split(/: /,$group_line); if (!($group eq "News")) { next; } @admins = split(/ /,$members); } foreach $member (@admins) { chop($member) if ($member =~ /\n/); if (!($sent_user eq $member)) { next; } return; } &error_response(notnews); }