# FILE: src-board-subs-2 # 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 #---SEPARATOR---# #REQ:new_file #REQ:get_date_time #REQ:get_number sub add_page { local ($newpage, $type, $url, $target, $tn, $mn, $grp, $datetime_in) = @_; local ($num, $dt, @sublist, $line, $str, $strg, $ts); $owner = $grp if $grp ne ""; $num = &get_number; if ($tn != 0) { $topic_number = $tn; $me_number = $mn; } $url = "$message_url/$topic_number/$num.$ext" if $type ne "LINK"; $dt = &get_date_time('long'); $dt =~ s/\W//g; $newpage = &remove_links($newpage); $url .= "?$dt" if ($type ne "LINK" && !$noqm); &lock("$message_dir/$topic_number/$me_number.$ext"); local ($head, $color, $lm, $sublist, $about, $about_src, $message, $message_src) = &get_page($topic_number,$me_number); $str = &JavaScript_prepare($newpage); $strg = "onMouseOver=\"return setStatus('$str')\""; $ts = &get_date_time('short'); $ts = $datetime_in if $datetime_in ne ""; $sublist .= "
  • $newpage $ts
  • \n" if $type ne "LINK"; $sublist .= "

  • $newpage
  • \n" if $type eq "LINK"; &set_page($topic_number, $me_number, $head, $color, $lm, $sublist, $about, $about_src, $message, $message_src); &unlock("$message_dir/$topic_number/$me_number.$ext"); &new_file ($topic_number, $num, $me_number, $owner, $newpage, $type) if $type ne "LINK"; return $num; } #---SEPARATOR---# sub rename_topic_form { local ($oldname, $topic_number, $username) = @_; &header; print "Topic Properties\n"; print "$fs\n"; print "

    Topic Properties
    \n"; print "
    \n"; print "Board Manager: Topic Properties
    \n"; print "
    \n"; print "
    \n"; print "
    $fs", "Name:

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

    \n"; print "
    \n"; exit(0); } #---SEPARATOR---# sub change_topic_group_form { local ($topics, $username) = @_; @topics = split(/,/, $topics); &header; print "Change Topic Group\n"; print "\n"; print "$fs
    Change Topic Group
    \n"; print "
    \n"; print "Board Manager: Change Topic Group
    \n"; print "
    \n"; print "
    $fs\n"; print "The following topic"; print "s have" if scalar(@topics) > 1; print " has" if scalar(@topics) == 1; print " been selected:

    \n"; foreach $topic (@topics) { &extract("//$topic/$topic.$ext"); print "

  • $topic_name (\u$owner)\n"; } print "

    Select New Group:   "; print "\n"; print "

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

  • \n"; print "
    \n"; exit(0); } #---SEPARATOR---# sub add_moderator { local ($username, $newuser, $pass1, $pass2) = @_; $newuser =~ tr/A-Z/a-z/; $pass1 =~ tr/A-Z/a-z/; $pass2 =~ tr/A-Z/a-z/; &error_message("Add Moderator Error", "Username is invalid (username may contain only alphanumeric characters).") if $newuser =~ /\W/; &error_message("Add Moderator Error", "The entered passwords do not match!") if $pass1 ne $pass2; $usercount = length($newuser); &error_message("Add Moderator Error", "The username is invalid (username must be between 3 and 15 characters).") if ($usercount < 3 || $usercount > 15); &error_message("Add Moderator Error", "The entered passwords are invalid (password may contain only alphanumeric characters.") if $pass1 =~ /\W/; $passcount = length($pass1); &error_message("Add Moderator Error", "The entered passwords are invalid (password must be between 3 and 15 alphanumeric characters).") if ($passcount < 3 || $passcount > 15); open(PASSWD,"$admin_dir/passwd.txt") || &error_message("Add Moderator Error", "Cannot read password file (passwd.txt)! (Code 020401)"); @passwdline = ; close(PASSWD); foreach $line (@passwdline) { ($user, $encpass, $therest) = split(/:/, $line); &error_message("Add Moderator Error", "The selected username already exists as a moderator!") if $user eq $newuser; } srand(time); undef (@salt); for ($i=1; $i<=4; $i++) { push (@salt, int(rand(26))+65); } $salt = pack('c4', @salt); &lock("$admin_dir/passwd.txt"); open(PASSWD,">>$admin_dir/passwd.txt") || &error_message("Add Moderator Error", "Cannot append password file (passwd.txt)! (Code 020202)"); $new_password = crypt($pass1, $salt); print PASSWD "$newuser:$new_password:email:fullname:1:0:0\n"; close(PASSWD); &unlock("$admin_dir/passwd.txt"); } #---SEPARATOR---# sub delete_moderator { local ($toremove) = @_; local (@passwd, $line, $user, $therest); &lock("$admin_dir/passwd.txt"); open (PASSWD, "$admin_dir/passwd.txt") || &error_message("File Error", "Cannot open password file (passwd.txt) for reading! (Code 020501)"); @passwd = ; close (PASSWD); open (PASSWD, ">$admin_dir/passwd.txt") || &error_message("File Error", "Cannot open password file (passwd.txt) for writing! (Code 020502)"); foreach $line (@passwd) { ($user) = split(/:/, $line); print PASSWD $line if $toremove ne $user; } close (PASSWD); &unlock("$admin_dir/passwd.txt"); &lock("$admin_dir/groups.txt"); open (GRP, "$admin_dir/groups.txt"); @grp = ; close (GRP); foreach $line (@grp) { chop $line if $line =~ /\n/; ($group, $users) = split(/:/, $line); @users = split(/,/, $users); @users = grep(!/^$toremove$/, @users); $users = join(",", @users); $users .= "\n"; $line = join(":", $group, $users); } open (GRP, ">$admin_dir/groups.txt"); print GRP @grp; close (GRP); &unlock("$admin_dir/groups.txt"); } #---SEPARATOR---# sub edit_moderator { local ($username, $moderator) = @_; open (PASSWD, "$admin_dir/passwd.txt") || &error_message("File Error", "Cannot open password file (passwd.txt) for reading! (Code 020601)"); @passwd = ; close (PASSWD); &error_message("Invalid Moderator Selection", "The specified moderator does not exist! (Code 020602)") if !grep(/^$moderator:/, @passwd); &error_message("Invalid Moderator Selection", "The specified moderator does not exist! (Code 020603)") if $moderator eq ""; ($line) = grep(/^$moderator:/, @passwd); ($user, $encrpass, $email, $fullname, $profile, $notify, $lastcheck) = split(/:/, $line); &header; print "Edit Moderator\n"; print "\n"; print "
    Moderator Editor: \u$moderator
    \n"; print "
    \n"; print "Moderator Manager: Edit \u$moderator\n
    \n"; print "
    \n"; print "

    Profile Settings

    \n"; print ""; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
    SettingSet New Value
    Username\u$moderator
    E-mail Address
    Full Name
    Can edit profile\n"; print "No "; print "Yes
    E-mail Notification"; print "Own Posts
    "; print "= 2; print ">Within Moderated Groups
    \n"; print "\n"; print "\n"; print "\n"; print "
    \n"; print "\n"; print "\n"; print "\n"; print "
    \n"; print "\n" if $moderator eq $superuser; return if $moderator eq $superuser; print "

    Change Moderator Password

    \n"; print "
    \n"; print ""; print "\n"; print "\n"; print "
    New Password:
    Verify:

    \n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
    \n"; print "\n"; } #---SEPARATOR---# sub change_password { local ($file, $username, $pass1, $pass2, $group) = @_; $pass1 =~ tr/A-Z/a-z/; $pass2 =~ tr/A-Z/a-z/; local ($passcount); &error_message("Change Password Error", "The entered passwords do not match (case-sensitive)!") if $pass1 ne $pass2; &error_message("Change Password Error", "The entered passwords are invalid (password may contain only alphanumeric characters.") if $pass1 =~ /\W/; $passcount = ($pass1 =~ s/(\w)/$1/g); &error_message("Change Password Error", "The entered passwords are invalid (password must be between 3 and 15 alphanumeric characters).") if ($passcount < 3 || $passcount > 15); local ($salt, @salt, @passwd, $line, $new_passwd); srand(time); undef (@salt); for ($i=1; $i<=4; $i++) { push (@salt, int(rand(26))+65); } $salt = pack('c4', @salt); $new_password = crypt($pass1, $salt); &lock("$admin_dir/$file.txt"); open(PASSWD,"$admin_dir/$file.txt") || &error_message("Change Password Error", "Cannot read password file ($file.txt)! (Code 020701)"); @passwd = ; close(PASSWD); foreach $line (@passwd) { if ($line =~ /^$username:[^:]*:(.*)/ && $file eq "passwd") { $line = "$username:$new_password:$1\n"; } elsif ($line =~ /^$username:[^:]*:(.*):$group(\n?)$/ && $file eq "users") { $line = "$username:$new_password:$1:$group\n"; } } open(PASSWD,">$admin_dir/$file.txt") || &error_message("Change Password Error", "Cannot write to password file ($file.txt)! (Code 020702)"); print PASSWD @passwd; close(PASSWD); &unlock("$admin_dir/$file.txt"); return $new_password; } #---SEPARATOR---# sub change_profile { local ($file, $user, $email, $fullname, $profile, $wantemail, $lastcheck, $group) = @_; local ($userX, $encpassX, $emailX, $fullnameX, $profileX, $wantemailX, $lastcheckX, $groupX); &lock("$admin_dir/$file.txt"); open(PASSWD,"$admin_dir/$file.txt") || &error_message("Change Profile Error", "Cannot read password file ($file.txt)! (Code 020801)"); @passwd = ; close(PASSWD); foreach $line (@passwd) { next if $line !~ /^$user:/; next if $file eq "users" && $line !~ /$group(\n?)$/; chop $line if $line =~ /\n$/; ($userX, $encpassX, $emailX, $fullnameX, $profileX, $wantemailX, $lastcheckX, $groupX) = split(/:/, $line); $line = "$userX:$encpassX:"; $line .= $email eq "*" ? "$emailX:" : "$email:"; $line .= $fullname eq "*" ? "$fullnameX:" : "$fullname:"; $line .= $profile eq "*" ? "$profileX:" : "$profile:"; $line .= $wantemail eq "*" ? "$wantemailX:" : "$wantemail:"; $line .= $lastcheck eq "*" ? "$lastcheckX" : "$lastcheck"; $line .= $groupX eq "*" ? ":$groupX" : ":$groupX" if $file eq "users"; $line .= "\n"; } open(PASSWD,">$admin_dir/$file.txt") || &error_message("Change Profile Error", "Cannot write to password file ($file.txt)! (Code 020802)"); print PASSWD @passwd; close(PASSWD); &unlock("$admin_dir/$file.txt"); } #---SEPARATOR---# #REQ:page_manager_navbar sub rename_subtopic_form { local ($referer, $page_number, $username) = @_; &extract($referer); &error_message("Permissions Error", "Only the superuser may rename a topic! (Code 020901)") if $topic_number == $page_number; &extract("//$topic_number/$page_number.$ext"); local ($oldname) = $me_name; &header; print "Subtopic Properties\n"; print "$fs\n"; print "
    Subtopic Properties
    \n"; &page_manager_navbar($topic_number, $page_number, "Subtopic Properties"); print "
    \n"; print "
    \n"; $oldname = &JavaScript_prepare($oldname); print "\n"; print "
    $fs", "Name:

    \n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
    \n"; exit(0); } #---SEPARATOR---# #REQ:page_manager_navbar sub rename_link_form { local ($referer, $linknum, $username) = @_; local ($file, $line, $topic, $page, $url, $target, $str); if ($referer =~ m|/(\d+)/(\d+)\.$ext|) { ($topic, $page) = ($1, $2); } else { &error_message("Link Properties Error", "Could not extract requested page."); } local ($head, $color, $lm, $sublist, $about, $about_src, $message, $message_src) = &get_page($topic,$page); @sublist = split(/\n/, $sublist); ($file) = grep(/^/, @sublist); $file =~ m|
  • (.*)| || &error_message("FAILED", $file); ($url, $target, $oldname) = ($1, $2, $4); &header; print "Link Properties\n"; print "$fs\n"; print "
    Link Properties
    \n"; &page_manager_navbar($topic, $page, "Link Properties"); print "
    \n"; print "
    \n"; $oldname = &remove_html($oldname); $oldname =~ s/"//g; print "\n"; print "\n"; print "
    $fs", "Name:
    $fs", "URL:
    $fs", "Frame:

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

    \n"; exit(0); } #---SEPARATOR---# #REQ:recurse #REQ:JavaScript_prepare #REQ:extract_lastmodified #REQ:get_date_time sub rename_subtopic { local ($referer, $num, $newname) = @_; local ($file, @lines, $line); &extract($referer); $file = "$message_dir/$topic_number/$me_number.$ext"; &lock("$file"); open (FILER, $file) || &error_message("File Error", "Could not open page file."); @lines = ; close(FILER); foreach $line (@lines) { if ($line =~ //) { $line =~ /
  • ]*)>(.*)<\/A>/; $line = join("", $`, "
  • $newname", $'); } } open (FILE, ">$file"); print FILE @lines; close (FILE); &unlock("$file"); &extract("/$topic_number/$num.$ext"); foreach $key (keys(%level_number)) { if ($level_number{$key} eq $num) { $keypl = $key; $type = "Level $keypl"; } } $type = "Level 1" if $type eq ""; $recurse_action = "rename:$type"; &recurse ($topic_number, $num, $recurse_action, $newname); } #---SEPARATOR---# #REQ:JavaScript_prepare sub rename_link { local ($referer, $linknum, $newname, $newurl, $newtarget) = @_; local ($file, $line, $topic, $page, $url, $target, $str); if ($referer =~ m|/(\d+)/(\d+)\.$ext|) { ($topic, $page) = ($1, $2); } else { &error_message("Rename Link Error", "Could not extract requested page."); } &lock("$message_dir/$topic/$page.$ext"); local ($head, $color, $lm, $sublist, $about, $about_src, $message, $message_src) = &get_page($topic,$page); @sublist = split(/\n/, $sublist); foreach $line (@sublist) { if ($line =~ //) { $line =~ /
  • (.*)<\/A>/; ($url, $target) = ($1, $2); $str = &JavaScript_prepare($newname); $url = $newurl if $newurl ne ""; $target = "TARGET=\"Main\"" if $newtarget eq "Main"; $target = "TARGET=\"_top\"" if $newtarget eq "_top"; $target = "TARGET=\"_blank\"" if $newtarget eq "_blank"; $line = "
  • $newname
  • \n"; } } $sublist = join("\n", @sublist); &set_page($topic, $page, $head, $color, $lm, $sublist, $about, $about_src, $message, $message_src); &unlock("$message_dir/$topic/$page.$ext"); } #---SEPARATOR---# sub reorder_subtopics { local ($referer, $array) = @_; local ($topic_number,@ascending,$line,@lines,%newarray,$flag,$key, %printed); @ascending = split(/:/, $array); &extract($referer); &lock("$message_dir/$topic_number/$me_number.$ext"); open(MAIN_1, "$message_dir/$topic_number/$me_number.$ext"); @lines = ; close(MAIN_1); undef %printed; foreach $line (@lines) { if ($line =~ // || $line =~ //) { $newarray{$1} = $line; $printed{$1} = 0; } } open(MAIN_1, ">$message_dir/$topic_number/$me_number.$ext"); $flag = 0; foreach $line (@lines) { if (($line =~ // || $line =~ //) && $flag == 0) { $flag = 1; foreach $key (@ascending) { print MAIN_1 $newarray{$key}; $printed{$key} = 1; } foreach $key (keys(%printed)) { print MAIN_1 $newarray{$key} if $printed{$key} == 0; } } elsif ($line =~ //) { $flag = 0; print MAIN_1 $line; } elsif ($flag == 0) { print MAIN_1 $line; } } close (MAIN_1); &unlock("$message_dir/$topic_number/$me_number.$ext"); }