#!/usr/bin/perl $discus_conf = '/usr/local/www/www.hirez.org/discus_admin_149349189/discus.conf'; #Discus board new messages script #------------------------------------------------------------------------------- # This script is copyright (c) 1998 by DiscusWare, LLC, all rights reserved. # Its use is subject to the license agreement that can be found at the following # URL: http://www.chem.hope.edu/discus/license #------------------------------------------------------------------------------- # If you want to change the default selection on the new messages # top page, you can do so here by commenting/uncommenting lines. $CHECKED{'last'} = "CHECKED"; # Search last x days/hours #$CHECKED{'user'} = "CHECKED"; # Search by username/password #$CHECKED{'since'} = "CHECKED"; # Search since 12:01 am ... # If you want the message tree view to be enabled by default, you # can define this variable $CHECKED{'treeview'} = "CHECKED"; # To enable multiple selection of topics, you can enable one of # the following two options. However, this makes the interface # look not-so-good. # $multiple = "MULTIPLE SIZE=1"; # $multiple = "MULTIPLE"; # If you want the "do not use 7 day limit" enabled, uncomment this: # $nolimit = 1; # If you want more characters in the username, change this value: $max_name_chars = 20; #------------------------------------------------------------------------------ if (open (FILE, "$discus_conf")) { @file = ; close (FILE); $evals = ""; foreach $line (@file) { if ($line =~ /^(\w+)=(.*)/) { $varname = $1; $value = $2; $value =~ s/'/\\'/g; $value =~ s/\r//g; $evals .= "\$$varname='$value'; "; } } eval($evals); require "$admin_dir/source/src-board-subs-common"; } else { print "Content-type: text/html\n\n"; print "Script Execution Error\n"; print "\n"; print "

Script Execution Error

\n"; print "Discus scripts could not execute because the discus.conf file\n"; print "could not be opened."; print "

Reason: $!" if $!; print "

This generally indicates a setup error of some kind.\n"; print "Consult the Discus "; print "Resource Center for troubleshooting information.\n"; exit(0); } $version_number = join(".", $release_version, $free_revision) if !$pro; $version_number = join(".", $release_version, $pro_revision) if $pro; $version_number .= "(W95)" if ($platform eq "win95" || $win95); $version_number .= "(NT)" if ($platform eq "NT" || $NT); $version_number .= "*PRO*" if $pro; # This tries to keep long lines out of no frames interface $maxchar = 40; $maxchar = 25 if $interface eq "noframes"; &parse_form; &read_cookie; open (LOG, "$admin_dir/log.txt"); @LOG = ; close (LOG); @LOG = reverse @LOG; ($time) = &ex('get_date_time', "long"); ######################################################### # This is the static page that gets spit out if ($FORM{'method'} eq "") { $option_string = ""; foreach $logline (@LOG) { ($what,$who,$when,$where,$anon) = split(/;/, $logline); next if $what =~ /^D/; last if $what !~ /^D/; } $count = scalar(@LOG); $when = "" if $what =~ /^D/; if ($when ne "") { ($lasttime) = &ex('get_date_time', "long", $when); } $lasttime = "N/A" if $when eq ""; $counter = -1; $todays_day = (localtime(time))[6]; for($i = ($todays_day + 5); $i >= ($todays_day); $i -= 1) { $counter += 1; $option_string .= "


$L{NMSEARCHIN}   

$L{NMWITHINLAST} 

$L{NMLASTCHECK}

$L{NMAFTER}  $ampmstr

$L{NMTREEVIEW}


$lps
EOF &ex('printuntil', 3, 17, 0, "", 0, 1); exit(0); } $cutoff = 0; $timestore = time; if ($FORM{'method'} eq 'redo') { $cutoff = $FORM{'cutoff'}; } elsif ($FORM{'method'} eq 'last') { $number = $FORM{'number'}; $factor = $FORM{'units'}; &error_message("Invalid Number", "The number you specified is invalid!") if $number <= 0; &error_message("Invalid Units", "What are you trying to do?") if $factor <= 0; $cutoff = $timestore; $cutoff -= $number * $factor * 60; } elsif ($FORM{'method'} eq 'since') { ($sec, $min, $hour, $day, $nmonth, $year, $wday, $yday, $isdst) = localtime($timestore); $midnighttoday = $timestore - $sec - (60 * $min) - (3600 * $hour); $day = $FORM{'day'} + 2; $cutoff = $midnighttoday - ($day * 86400); $cutoff += 43200 if $FORM{'ampm'} eq "pm"; $timearg = $FORM{'time'}; $timesep = $L{TIMESEPARATOR}; $timearg =~ s/[^\d$timesep]//g; ($hour, $min) = split(/$timesep/, $timearg); $hour =- 12 if ($L{HRCLOCK} == 12 && $FORM{'ampm'} eq "pm"); $cutoff += ($min * 60) + ($hour * 3600); } elsif ($FORM{'method'} eq 'check') { ($result) = &ex('verify_user_password', $FORM{'username'}, $FORM{'password'}); @result = split(/\n/, $result); @result_save = @result; &error_message($L{BPAUTHERROR}, $L{PROFILE_AUTHERROR_DESCR},0,1) if scalar(@result) == 0; if ($pro) { &ex('get_preferences', $FORM{'username'}, $FORM{'password'}); $FORM{'tree'} = "" if $PREF{'nm_view'} == 1; } $lastcheck = 0; foreach $result (@result_save) { ($file, $user, $pass, $foo, $foo, $foo, $foo, $lc, $therest) = split(/:/, $result); $lastcheck = $lc if $lc > $lastcheck; $password_save = $pass; } if ($lastcheck == 0) { $docut = "$L{NMNOCHECK}\n"; $cutoff = $timestore; $cutoff -= 1440 * 60 * 7; } else { $cutoff = $lastcheck; if ($timestore > ($cutoff + 604800) && $PREF{'show_all_nm'} == 0 && !$FORM{'nolimit'}) { $docut .= "$L{NMCHECKSEVENDAYS}

\n"; $cutoff = $timestore - 604800; } else { $docut .= "$L{NMYOULASTCHECKED} "; ($dt) = &ex('get_date_time', 'long', $cutoff); $docut .= $dt; $docut .= ".
\n"; } } if (!$FORM{'silent'}) { $ctime = time; &ex('save_profile_information', "", "", "", "", "", $ctime, "", @result_save); } else { $docut .= "$L{NMNOTRECORDED}\n"; } } if ($pro) { &ex('get_preferences', 1); if ($FORM{'tree'} eq "ON") { $FORM{'tree'} = "" if $PREF{'nm_view'} == 1; $FORM{'where'} = $PREF{'favorites'} if ($PREF{'last_favs'} == 1 && $PREF{'favorites'} =~ /\S/); } } $| = 1; undef @returned_list; undef %file; $counter = 0; undef %seen; @LOG = &ex('log_authorization', @LOG) if $pro; &header; foreach $line (@LOG) { next if $line !~ /^(\d+);([^;]*);/; # Deleted and Old style chop ($line) if $line =~ /\n$/; ($what,$who,$when,$where,$how) = split(/;/, $line); last if $when == 0; last if $when < $cutoff; $flag = 0; ($thistopic, $num) = split(/\//, $where); if ($FORM{'where'} ne "all") { $flag = 1 if !grep(/^$thistopic$/, split(/,/, $FORM{'where'})); } push(@returned_list, $line) if $flag == 0; $file{$where} .= "$line," if $flag == 0; $flag = 1 if $seen{$where} == 1; $seen{$where} = 1 if $flag == 0; $counter += 1 if $flag == 0; } ######################################################### # Build up data for the output page undef %subdata; undef %headstr; undef %msgdata; undef %topic; undef @topic_order; undef @result; undef @msgid; foreach $line (@returned_list) { chop $line if $line =~ m|\n$|; ($postindex, $who, $time, $where, $addr, $host, $message2, $who2) = split(/;/, $line); if ($headstr{$where} eq "") { ($topic, $page) = split(/\//, $where); ($head, $color, $lm, $ann, $ann_src, $sublist, $about, $about_src, $message, $message_src) = &get_page($topic, $page); push (@result, $where) if $head ne ""; $headstr{$where} = $head; $msgdata{$where} = $message; $subdata{$where} = $sublist; $lm{$where} = $lm; @head = split(/\n/, $head); foreach $l (@head) { if ($l =~ m||; $k = $2; $subname{$res} = &JavaScript_prepare($k, 1); @subl = split(/\n/, $sublist); $res =~ m|^(\d+)/|; $topic = $1; foreach $s (@subl) { if ($s =~ m|^|) { $lastnum{$res} = $1 if $seen{"$topic/$1"}; } } } $last = $results[scalar(@results)-1]; $last =~ m|^(\d+)/|; $LAST_TOPIC = $1; foreach $res (@results) { $res =~ m|^(\d+)/|; $topic = $1; @hs = split(/,/, $headdata{$res}); $c = 0; $t = $topic; $parent = ""; foreach $l (@hs) { $c += 1; $res2 = "$topic/$l"; if (!$seen2{$res2}) { print "p('" if !$nsbug; $thisstr = ""; if ($c == 1) { if (!$nsbug) { print "$thisstr", "g','$subname{$res2}',"; if (-e "$message_dir/$res2.$ext") { print "'$message_url/$res2.$ext"; print "?$lm{$res2}" if !$noqm; } else { print "'$script_url/board-auth.$cgi_extension?file=/$res2.$ext&lm=$lm{$res2}"; } print "','');\n"; } else { $lmstr = "?$lm{$res2}" if !$noqm; print ""; print "$subname{$res2}
"; } $seen2{$res2} = 1; } else { for ($i = 1; $i < ($c-1); $i++) { $thisstr .= "i" if $on{$i}; $thisstr .= "j" if !$on{$i}; if ($nsbug) { print "" if $on{$i}; print "" if $on{$j}; } } if ($l != $lastnum{$parent}) { $thisstr .= "e"; if ($nsbug) { print "" if $on{$j}; } $on{$i} = 1; } else { $thisstr .= "f"; if ($nsbug) { print "" if $on{$j}; } $on{$i} = 0; } if (!$nsbug) { print "$thisstr", "g','$subname{$res2}',"; if (-e "$message_dir/$res2.$ext") { print "'$message_url/$res2.$ext"; print "?$lm{$res2}" if !$noqm; } else { print "'$script_url/board-auth.$cgi_extension?file=/$res2.$ext&lm=$lm{$res2}"; } print "', '');\n"; } else { while ($thisstr =~ m|(\w)|g) { print ""; } print ""; $lmstr = "?$lm{$res2}" if !$noqm; print "$subname{$res2}
"; } $seen2{$res2} = 1; } } $thisstr =~ s/e$/i/; $thisstr =~ s/f$/j/; $parent = $res2; if ($pr{$res2} == 0) { $pr{$res2} = 1; if (grep(/^$res2$/, values(%msgplace))) { $msg = $msgdata{$res2}; if ($subdata{$res2} =~ m||) { while ($subdata{$res2} =~ m||g) { $o = $1; $has_subtopics{$res2} = 1 if $seen{"$topic/$o"}; } } @msg = split(/\n/, $msg); undef @li1; undef @li2; undef @li3; undef @li4; undef @li5; $flag = 0; foreach $line (@msg) { if ($line =~ m||) { $pn = $1; if (grep(/^$pn$/, @msgid)) { push (@li1, $thisstr . "el"); push (@li4, $pn); push (@li5, $postedwhen{$pn}); if ($postedby{$pn} ne "") { $postedby{$pn} =~ s/\([^\)]*\)//g; $postedby{$pn} =~ s/\s+$//; $postedby{$pn} = &remove_html($postedby{$pn}, 1); $msgtext{$pn} = &remove_html($msgtext{$pn}, 1); $msgtext{$pn} = substr($msgtext{$pn}, 0, $maxchar); push (@li2, &JavaScript_prepare($postedby{$pn}, 1)); push (@li3, &JavaScript_prepare($msgtext{$pn}, 1)); } else { $flag = 1; } } else { $flag = 0; } } elsif ($flag > 0) { if ($line =~ m|By (.*) on(.*)

|) { $p = $1; $p =~ s/\([^\)]*\)//g; $p = &JavaScript_prepare($p, 1); $p =~ s/\s+$//; push (@li2, $p); $p = ""; $flag = 2; } elsif ($flag == 2) { $p .= $line; } } } $p = scalar(@li1); if ($p > 0) { $li1[$p-1] =~ s/el$/fl/ if !$has_subtopics{$res2}; } for ($i = 0; $i < $p; $i++) { if (length($li2[$i]) > $max_name_chars) { $l = $li2[$i]; while ($l =~ m|&#(\d+);|) { $l = join("", $`, pack("c", $1), $'); } $l = substr($l, 0, $max_name_chars); $l = &JavaScript_prepare($l, 1); $li2[$i] = $l; } if (!$nsbug) { print "p('", $li1[$i], "','", $li2[$i], "',"; if (-e "$message_dir/$res2.$ext") { print "'$message_url/$res2.$ext"; print "?$lm{$res2}" if !$noqm; } else { print "'$script_url/board-auth.$cgi_extension?file=/$res2.$ext&lm=$lm{$res2}"; } print "#POST", $li4[$i], "','-"; $pt = $li5[$i]; ($dt) = &ex('get_date_time', 'realshort', $pt); print "$dt-"; print $li3[$i], "');\n"; } else { while ($li1[$i] =~ m|(\w)|g) { print ""; } print "" if -e "$message_dir/$res2.$ext"; print "$li2[$i]"; print "-"; $pt = $li5[$i]; ($dt) = &ex('get_date_time', 'realshort', $pt); print "$dt-"; print "$li3[$i]
"; } } } } } } if (!$nsbug) { print "// -->\n"; print "\n"; } } else { foreach $where (@results) { ($topic, $page) = split(/\//, $where); @head = split(/\n/, $headstr{$where}); ($topicstr) = grep(/|; $navbar = $1; foreach $line (@head) { if ($line =~ m||) { $navbar .= ": $1"; } } print ""; print $navbar; print "\n"; @message = split(/\n/, $msgdata{$where}); $flag = 0; print "

\n"; foreach $line (@message) { if ($line =~ m||) { $post = $1; $pn = $post; ($dateprint) = &ex('get_date_time', 'realshort', $postedwhen{$pn}); $flag = 1 if (grep(/^$post$/, @msgid)); if ($postedby{$pn} ne "") { $postedby{$pn} =~ s/\([^\)]*\)//g; $postedby{$pn} =~ s/\s+$//; $by = &JavaScript_prepare($postedby{$pn}, 1); $text = &JavaScript_prepare($msgtext{$pn}, 1); $flag = 2 if $flag == 1; } } elsif ($line =~ m||) { $pn = $1; $l = $by; while ($l =~ m|&#(\d+);|) { $l = join("", $`, pack("c", $1), $'); } $l = substr($l, 0, $max_name_chars); $l = &JavaScript_prepare($l, 1); $by = $l; if ($flag > 0) { print "$by: $dateprint: $text
\n"; $flag = 0; } } elsif ($flag == 1 && $line =~ m|By (.*)( [\(]).*.*(.*):

|i) { ($postby, $foo, $date) = ($1, $2, $3); $by = &remove_html($postby, 1); } elsif ($flag == 1 && $line =~ m|(.*).*(.*):

|i) { ($postby, $date) = ($1, $2); $by = &remove_html($postby, 1); } elsif ($line =~ m|^


|) { next; } elsif ($flag) { $line2 = &remove_html($line, 1); $line2 .= " "; $line2 =~ m|(.{0,40})\s|; $tempvar = $1; $tempvar = substr($tempvar, 0, $maxchar); $text = $tempvar; $flag = 3; } } print "

\n"; } } print "


\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n" if $FORM{'tree'} eq ""; print "" if $FORM{'tree'} ne ""; print "" if $FORM{'tree'} eq ""; print "
\n"; &ex('printuntil', 7, 17, 0, "", 0, 1); exit(0); ######################################################### # Miscellaneous Subroutines sub check_password { local ($username, $guess) = @_; local ($user, $ok, @passwd_line, $line, $pass, $test_pass, @group, $groupline); local ($field1, $field2, @valid, @result); undef (@result); undef (@users); open (PASSWD, "$admin_dir/users.txt") || &error_message("Verify Password Error", "Cannot open password file (users.txt) for reading!"); @users = ; close (PASSWD); @valid = @users; open(PASSWD,"$admin_dir/passwd.txt") || &error_message("Verify Password Error", "Cannot open password file (passwd.txt) for reading!"); @passwd_line = ; close(PASSWD); $ok = ""; foreach $line (@passwd_line) { ($user, $pass) = split(/:/, $line, 3); if ($user eq $username) { $test_pass = crypt($guess, $pass); $ok = ""; $ok = "Yes" if $test_pass eq $pass; $ok = "Yes" if $COOKIE{'cpwd' . $COOKIE_ID} eq crypt($pass, "cookie"); $ok = "No" if $guess eq ""; $ok = "No" if $pass eq ""; push (@result, "passwd:$line") if $ok eq "Yes"; } } open(PASSWD,"$admin_dir/users.txt") || &error_message("Verify Password Error", "Cannot open password file (users.txt) for reading!"); @passwd_line = ; close(PASSWD); $ok = ""; foreach $line (@passwd_line) { chop ($line) if $line =~ /\n/; ($user, $pass, $foo, $foo, $foo, $foo, $foo, $group_test) = split(/:/, $line); if ($user eq $username) { $test_pass = crypt($guess, $pass); $ok = ""; $ok = "Yes" if $test_pass eq $pass; $ok = "No" if $guess eq ""; $ok = "Yes" if $COOKIE{'cpwd' . $COOKIE_ID} eq crypt($pass, "cookie"); $ok = "No" if $pass eq ""; push (@result, "users:$line") if $ok eq "Yes"; } } return @result; }