# FILE: src-board-subs-common # Copyright (c) 1998, Kevin W. Paulisse and William F. Polik, all rights reserved # Licensed under the Discus license agreement # http://www.chem.hope.edu/discus ##################################### # Configuration options for the board # If enabled, a user's username and password will be # remembered in a cookie until the user quits their # browser. # 0=Off [default] 1=On $store_username_and_password_as_cookies = 0; # Do not change the following -- this is essential for # us to be able to provide technical support. $version_number = "2.50.6"; ##################################### # Program shortcuts -- DON'T change $url_to_default_image = "$html_url/clipart/your_image.gif"; $message_dir = "$html_dir/messages"; $message_url = "$html_url/messages"; $cgiurl = "$script_url/board-admin.$cgi_extension"; $cgiurlm = "$script_url/board-admin-menuonly.$cgi_extension"; ##################################### # Actual code of this routine &read_declarations; undef %ev; sub ex { local ($function_name) = shift (@_); local (@params, @file, $o); @params = @_; local ($tmp, $file, $num, $sub, @sub, @s1, @s2, $tmpvar); if (!$ev{$function_name}) { $tmp = $/; $/ = "#---SEPARATOR---#"; ($file, $num) = split(/-/, $funct{$function_name}); open (FILE, "$admin_dir/source/src-board-subs-$file"); @file = ; close (FILE); $sub = $file[$num]; $/ = $tmp; @sub = split(/\n/, $sub); @s1 = grep(/^#REQ:/, @sub); @s2 = grep(!/^#/, @sub); foreach $tempvar (@s1) { $tempvar =~ m|^#REQ:(\w+)|; $o = $1; &ex($o); } $tempvar = join("\n", @s2); eval $tempvar; $ev{$function_name} = $1; } if (scalar(@params) > 0) { $tempvar = "\@result = &$function_name(\@params);"; eval $tempvar; return @result; } else { return 0; } } sub header { print "Content-type: text/html\n\n"; } $fs = ""; sub lock { local ($filename) = @_; open (LOCK, "$admin_dir/locks.txt") || &error_message("File Locking Error", "Could not open file $admin_dir/locks.txt (System returned error: $!). Make sure $admin_dir/locks.txt exists and is world writable."); @LOCK = ; close (LOCK); $time = time; if (grep(/\*/, @LOCK)) { &error_message("$L{'FILELOCKERROR'}", "$L{FILEISLOCKED}"); } if (!grep(/,$filename\s*$/, @LOCK)) { open (LOCK, ">>$admin_dir/locks.txt") || &error_message("File Locking Error", "Could not append file $admin_dir/locks.txt (System returned error: $!). Make sure $admin_dir/locks.txt exists and is world writable."); print LOCK "$time,$filename\n"; close (LOCK); return 1; } else { $ctr = 0; ($line) = grep(/,$filename\s*$/, @LOCK); ($time_l) = split(/,/, $line); if ($time > ($time_l + 5)) { @LOCK = grep(!/,$filename\s*$/, @LOCK); push (@LOCK, "$time,$filename\n"); open (LOCK, ">$admin_dir/locks.txt"); print LOCK @LOCK; close (LOCK); return 1; } else { for ($ctr = 0; $ctr <= 100; $ctr++) { open (LOCK, "$admin_dir/locks.txt"); @LOCK = ; close (LOCK); $time = time; if (!grep(/,$filename\s*$/, @LOCK)) { open (LOCK, ">>$admin_dir/locks.txt"); print LOCK "$time,$filename\n"; close (LOCK); return 1; } } &error_message("$L{'FILELOCKERROR'}", "$L{FILEISLOCKED}"); } } } sub unlock { local ($filename) = @_; open (LOCK, "$admin_dir/locks.txt") || &error_message("File Unlocking Error", "Could not open file $admin_dir/locks.txt (System returned error: $!). Make sure $admin_dir/locks.txt exists and is world writable.");; @LOCK = ; close (LOCK); @LOCK = grep(!/,$filename\s*$/, @LOCK) if $filename ne "*"; @LOCK = grep(!/\*/, @LOCK) if $filename eq "*"; if (scalar(@LOCK) == 0) { push (@LOCK, "#\n"); } open (LOCK, ">$admin_dir/locks.txt") || &error_message("File Unlocking Error", "Could not open file $admin_dir/locks.txt (System returned error: $!). Make sure $admin_dir/locks.txt exists and is world writable.");; print LOCK @LOCK; close (LOCK); } sub parse_form { undef %FORM; if ($ENV{'CONTENT_LENGTH'} != 0) { 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/\r//g; if ($FORM{$name} eq "") { $FORM{$name} = $value; } else { $FORM{$name} .= ",$value"; } } } $ENV{'QUERY_STRING'} =~ s/#(.*)$//; if ($ENV{'QUERY_STRING'} ne "") { $command = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $command); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value = &unescape($value); $FORM{$name} = $value if $FORM{$name} eq ""; } } } sub error_message { local ($reason, $explanation) = @_; &header; print "\n"; print "$reason\n"; print "\n"; print "$fs
$reason
\n"; print "

\n"; print "\n"; print "$explanation

\n"; if ($!) { print "\$!: $!

"; } if ($@) { print "\$\@: $@

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

Please contact $contact if this problem persists.\n"; print "\n"; exit(0); } sub extract { local ($strin) = @_; local ($line, $filename, @file,$key); undef %level_number; $_ = "/$strin"; /.*\/(\d+)\/(\d+)\.$ext/; $f1 = $1; $f2 = $2; &error_message('Undefined Error',"Undefined Error extracting file!") if $f1 eq ""; $filename = "$message_dir/$f1/$f2.$ext"; if (!-e $filename) { if (-e "$filename.NEW") { &lock($filename); if (!-e $filename && -e "$filename.NEW") { $code = rename("$filename.NEW", "$filename"); if ($code != 1 || !-e $filename) { open (FILE, "$filename.NEW"); @file = ; close (FILE); open (FILE, ">$filename"); print FILE @file; close (FILE); unlink ("$filename.NEW"); } chmod (0666, "$filename"); } &unlock($filename); } } open (FILE_EXTRACT, $filename) || &error_message("Extract Error","Undefined Error extracting file! $filename could not be opened because $!!"); @file = ; close (FILE_EXTRACT); foreach $line (@file) { $_ = $line; $topic_name = $2 if //; $topic_number = $1 if //; $owner = $1 if //; if (//) { $key = $1; $level_name{$key} = $3; $level_number{$key} = $2; } $me_name = $2 if //; $me_number = $1 if //; $parent_number = $1 if //) { $param = $1; } } return 1; } sub JavaScript_prepare { ($str) = @_; $str =~ s/([^/\[$1\]/g; $str =~ s/<([^>]*)>//g; $str =~ s/&#(\d+);//g; $str =~ s/'//g; $str =~ s/"//g; $str =~ s/"//g; $str =~ s/&//g; $str =~ s/\n//g; return $str; } sub remove_links { local ($string) = @_; local ($str); $str = $string; $str =~ s/]*)>//g; $str =~ s/<\/A>//g; return $str; } sub read_cookie { $buffer = $ENV{'HTTP_COOKIE'}; @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; $COOKIE{$name} = $value; } } sub escape { local ($input) = @_; local ($string); $string = $input; $string =~ s/([^\w ])/sprintf("%%%02lx", ord($1))/eg; $string =~ tr/ /+/; return $string; } sub unescape { local ($input) = @_; local ($string); $string = $input; $string =~ tr/+/ /; $string =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; return $string; } sub remove_html { local ($string, $flag) = @_; local ($str); $str = $string; $str =~ s/([^/\[$1\]/g; $str =~ s/<[^>]*>//g; $str =~ s/&#(\d+);//g if $flag == 0; return $str; } sub seturl { local ($targeturl) = @_; if (!($nph_server)) { print "Location: $targeturl\n\n"; exit(0); } else { &header; print "Document Moved\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; exit(0); } } sub print_cookie_string { local ($username_in, $password_in, $password_to_crypt_in) = @_; return 0 if $store_username_and_password_as_cookies == 0; print "Set-cookie: user=$username_in; path=/\n" if $username_in; print "Set-cookie: rpwd=", "x" x $password_in, "; path=/\n" if $password_in; print "Set-cookie: cpwd=" if $password_to_crypt_in; print crypt($password_to_crypt_in, "cookie") if $password_to_crypt_in; print "; path=/\n" if $password_to_crypt_in; return 1; } sub get_page { local ($topic, $page) = @_; local ($head, $sublist, $about, $about_src, $message, $message_src, $flag, $color, $lm); local ($save, @file); open (FILE, "$html_dir/messages/$topic/$page.$ext"); @file = ; close (FILE); foreach $_ (@file) { if (/^/) { $flag = 1; } elsif (/^|) { $flag = 0; } elsif ($flag == 2) { $about_src .= $_ if !/^-->/; } elsif (m||) { $flag = 3; $save = $1; $message .= $_; } elsif (m||) { $flag = 0; $message .= $_; } elsif ($flag == 3) { $message .= $_; } elsif (/^/) { $flag = 0; } elsif ($flag == 4) { $message_src .= $_; } } if ($color eq "") { $color = "c0c0c0\t000000\t0000ff\t800080\tff0000\t\t3\tTimes New Roman"; } return ($head, $color, $lm, $sublist, $about, $about_src, $message, $message_src); } sub set_page { local ($topic, $page, $head, $color, $timestr, $subtopic_variable, $about_variable, $about_source_variable, $message_variable, $message_source_variable, $templatefile, $addfile) = @_; local (@tfile, $line, $param, $owner, $levelj, $navline, $navbar, $str, $filename, @file); if ($templatefile) { @tfile = split(/\n/, $templatefile); foreach $line (@tfile) { $line .= "\n"; } @tfile = grep(/\S/, @tfile); } else { if (open (TFILE, "$html_dir/messages/$topic/newpage.txt")) { @tfile = ; close (TFILE); } else { open (TFILE, "$admin_dir/newpage.txt"); @tfile = ; close (TFILE); } } if (!(grep(//, @tfile))) { &error_message("Save Error", "The newpage.txt template has been corrupted; unable to save your change"); } if (!(grep(/\$subtopic_variable/, @tfile)) || !(grep(/\$about_variable/, @tfile)) || !(grep(/\$message_variable/, @tfile)) || !(grep(/\$message_source_variable/, @tfile)) || !(grep(/\$about_source_variable/, @tfile)) || !(grep(/\$head/, @tfile))) { &error_message("Save Error", "The newpage.txt template has been corrupted; unable to save your change"); } local ($bgcolor, $text, $link, $vlink, $alink, $image, $size, $face) = split(/\t/, $color); local (%level_number, %level_name, $topic_number, $topic_name, $me_number, $me_name); foreach $line (split(/\n/, $head)) { if ($line =~ m||) { ($topic_number, $topic_name) = ($1, $2); } elsif ($line =~ m||) { $level_number{$1} = $2; $level_name{$1} = $3; } elsif ($line =~ m||) { $me_number = $1; $me_name = $2; } elsif ($line =~ m||) { $param = $1; } elsif ($line =~ m||) { $owner = $1; } } $navline = "$title: "; if ($topic_number != $me_number) { $levelj = &JavaScript_prepare($topic_name); $navline .= ""; $navline .= "$topic_name: "; } else { $navline .= "$topic_name"; } foreach $line (sort by_number keys(%level_number)) { if ($level_number{$line} != $me_number) { $levelj = &JavaScript_prepare($level_name{$line}); $navline .= ""; $navline .= "$level_name{$line}:\n"; } else { $navline .= "$level_name{$line}"; } } $str = &JavaScript_prepare($navline); $navbar = $navline; local (@users, @addfile, $line_2, @valid, $privpub); if ($addfile) { @addfile = split(/\n/, $addfile); foreach $line (@addfile) { $line .= "\n"; } @addfile = grep(/\S/, @addfile); } else { $privpub = "private"; open (USER, "$admin_dir/users.txt"); @users = ; close (USER); @valid = grep(/:$owner\n?$/, @users); $privpub = "public" if grep(/^PUBLIC:/, @valid); open (FILExx, "$admin_dir/addmessage-$privpub.txt"); @addfile = ; close (FILExx); foreach $line_2 (@addfile) { $line_2 =~ s///g; $line_2 =~ s//$script_url\/board-post.$cgi_extension/g; } } local ($flag, $navflag, $flag2, $pagetitle, @array); @array = split(/\n/, $subtopic_variable); @array = grep(/\S/, @array); $subtopic_variable = join("\n", @array); @array = split(/\n/, $about_variable); @array = grep(/\S/, @array); $about_variable = join("\n", @array); @array = split(/\n/, $about_source_variable); @array = grep(/\S/, @array); $about_source_variable = join("\n", @array); @array = split(/\n/, $message_variable); @array = grep(/\S/, @array); $message_variable = join("\n", @array); @array = split(/\n/, $message_source_variable); @array = grep(/\S/, @array); $message_source_variable = join("\n", @array); $pagetitle = $me_name; $flag = 0; $navflag = 0; $flag2 = 0; undef @file; foreach $line (@tfile) { if ($line =~ //) { $flag = 1; } elsif ($flag == 1) { if ($line =~ m|\n\n$navbar\n\n\n"); } elsif ($navflag == 1) { $navflag = 0 if $line =~ m||) { push (@file, "\n") if $param =~ m|Sublist|; } elsif ($line =~ m||) { push (@file, "-->\n\n") if $param !~ m|Sublist|; push (@file, "\n") if $param =~ m|Sublist|; } elsif ($line =~ m||) { push (@file, "\n") if $param =~ m|Create|; } elsif ($line =~ m||) { push (@file, "-->\n\n") if $param !~ m|Create|; push (@file, "\n") if $param =~ m|Create|; } elsif ($line =~ m||) { push (@file, "\n") if $param =~ m|About|; } elsif ($line =~ m||) { push (@file, "-->\n|) { push (@file, "\n") if $param =~ m|Messages|; } elsif ($line =~ m||) { push (@file, "-->\n\n") if $param !~ m|Messages|; push (@file, "\n") if $param =~ m|Messages|; } elsif ($line =~ m||) { push (@file, "\n") if $param =~ m|Add|; } elsif ($line =~ m||) { push (@file, "-->\n\n") if $param !~ m|Add|; push (@file, "\n") if $param =~ m|Add|; } else { push (@file, $line); } } } } } $filename = "$message_dir/$topic/$page.$ext"; open (FILE, ">$filename.NEW") || &error_message("File Save - Write Error", "Could not open $filename.NEW for writing. Reason: $!!"); print FILE @file; close (FILE); if (-e "$filename.NEW") { if ($platform eq "NT" || $NT) { $code = 0; } else { $code = rename("$filename.NEW", "$filename"); } if ($code != 1 || !-e $filename) { open (FILE, ">$filename"); print FILE @file; close (FILE); unlink ("$filename.NEW"); } chmod (0666, "$filename"); } else { &error_message("File Save - Write Error", "Could not open $filename.NEW for reading. Reason: $!!"); } return 1; } sub by_number { $a <=> $b; } sub read_declarations { $funct{'page_mgr_1'} = "3-1"; $funct{'page_mgr_2'} = "3-2"; $funct{'build_graphical_tree'} = "4-2"; $funct{'admin_main_menu'} = "4-3"; $funct{'front_page'} = "4-4"; $funct{'viewmessage'} = "4-5"; $funct{'moderator_mgr'} = "4-6"; $funct{'first_pass'} = "4-10"; $funct{'group_mgr'} = "6-1"; $funct{'profile_editor'} = "7-1"; $funct{'user_mgr_1'} = "7-2"; $funct{'user_mgr_2'} = "7-3"; $funct{'get_date_time'} = "9-2"; $funct{'extract_colorsonly'} = "9-5"; $funct{'page_manager_navbar'} = "8-7"; $funct{'graphic_browser_select'} = "8-8"; $funct{'add_topic'} = "1-1"; $funct{'remove_topic'} = "1-2"; $funct{'rename_topic'} = "1-3"; $funct{'reorder_topics'} = "1-4"; $funct{'change_main_message'} = "1-5"; $funct{'register_discus'} = "1-6"; $funct{'change_topic_group'} = "1-7"; $funct{'preview_board_colors'} = "1-8"; $funct{'change_board_colors'} = "1-9"; $funct{'change_board_toppage'} = "1-10"; $funct{'add_page'} = "2-1"; $funct{'rename_topic_form'} = "2-2"; $funct{'change_topic_group_form'} = "2-3"; $funct{'add_moderator'} = "2-4"; $funct{'delete_moderator'} = "2-5"; $funct{'edit_moderator'} = "2-6"; $funct{'change_password'} = "2-7"; $funct{'change_profile'} = "2-8"; $funct{'rename_subtopic_form'} = "2-9"; $funct{'rename_link_form'} = "2-10"; $funct{'rename_subtopic'} = "2-11"; $funct{'rename_link'} = "2-12"; $funct{'reorder_subtopics'} = "2-13"; $funct{'board_manager'} = "4-1"; $funct{'build_graphical_tree'} = "4-2"; $funct{'remove_message_from_log'} = "4-7"; $funct{'moved_message_update_log'} = "4-8"; $funct{'remove_message'} = "4-9"; $funct{'preview_admin_message'} = "5-1"; $funct{'change_about_message'} = "5-2"; $funct{'remove_page'} = "5-3"; $funct{'move_page'} = "5-4"; $funct{'printuntil'} = "5-5"; $funct{'passwd_success'} = "5-6"; $funct{'add_group'} = "6-2"; $funct{'delete_group'} = "6-3"; $funct{'edit_group'} = "6-4"; $funct{'delete_moderator_from_group'} = "6-5"; $funct{'add_to_group'} = "6-6"; $funct{'move_message_form'} = "6-7"; $funct{'move_message'} = "6-8"; $funct{'edit_message_form'} = "6-9"; $funct{'save_edited_message'} = "6-10"; $funct{'reorder_messages'} = "6-11"; $funct{'add_user'} = "7-4"; $funct{'version_manager'} = "7-5"; $funct{'preview_user_list'} = "7-6"; $funct{'modify_list'} = "7-7"; $funct{'add_user_list'} = "7-8"; $funct{'delete_user'} = "7-9"; $funct{'edit_user'} = "7-10"; $funct{'special_user'} = "7-11"; $funct{'change_addmessage'} = "7-12"; $funct{'change_layout'} = "8-1"; $funct{'read_source'} = "8-2"; $funct{'write_source'} = "8-2"; $funct{'remove_source'} = "8-2"; $funct{'message_source'} = "8-2"; $funct{'extract_lastmodified'} = "8-3"; $funct{'prepare_navbar'} = "8-4"; $funct{'webtags'} = "8-5"; $funct{'make_new_tree'} = "8-7"; $funct{'graphic_browser_select'} = "8-8"; $funct{'move_subtopic_form'} = "8-9"; $funct{'recurse'} = "8-10"; $funct{'new_file'} = "8-11"; $funct{'post_message'} = "9-1"; $funct{'get_date_time'} = "9-2"; $funct{'get_number'} = "9-3"; $funct{'check_owner'} = "9-4"; $funct{'extract_colorsonly'} = "9-5"; $funct{'update_time'} = "9-7"; undef %evaluated; } open (LANG, "$admin_dir/language.conf"); @lang = ; close (LANG); undef %lang; @lang = grep(!/^#/, @lang); @lang = grep(/\S/, @lang); $cur = ""; foreach $line (@lang) { $line =~ s/##(.*)//; $line =~ s/^\s+//; $line =~ s/\s+$//; if ($line =~ m|^\$(\w+)|) { $cur = $1; $del = ""; } elsif ($line =~ m|^\@(\w+)\((.)\)|) { $cur = $1; $del = $2; } elsif ($del ne "") { @arr = split(/$del/, $line); foreach $a (@arr) { $a =~ s/^\s+//; $a =~ s/\s+$//; } $evst = "\@$cur = ("; foreach $a (@arr) { $evst .= "'$a',"; } chop ($evst); $evst .= ");"; eval $evst; } elsif ($cur ne "") { $L{$cur} .= $line . " "; } } foreach $key (keys(%L)) { $L{$key} =~ s/^\s+//; $L{$key} =~ s/\s+$//; } 1;