#!/usr/local/bin/perl
$discus_conf = '/usr/u/web/estarc/discus_admin_1969/discus.conf';
#Discus board administration (menu only) 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 (open (FILE, "$discus_conf")) {
	@file = <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 "<HTML><HEAD><TITLE>Script Execution Error</TITLE></HEAD>\n";
	print "<BODY BGCOLOR=#ffffff TEXT=#000000>\n";
	print "<H1>Script Execution Error</H1>\n";
	print "Discus scripts could not execute because the discus.conf file\n";
	print "could not be opened.";
	print "<P>Reason: <FONT COLOR=#ff0000><B>$!</B></FONT>" if $!;
	print "<P>This generally indicates a setup error of some kind.\n";
	print "Consult the <A HREF=\"http://www.chem.hope.edu/discus/rc\">Discus ";
	print "Resource Center</A> for troubleshooting information.</BODY></HTML>\n";
	exit(0);
}
require "$admin_dir/source/src-board-subs-admin";
&parse_form;
&read_cookie;
if ($FORM{'action'} eq 'mgr_1') {
	&check_passwd;
	&ex('page_mgr_1', $FORM{"username"});
	exit(0);
}
if ($FORM{'cmd'} eq "backup_mgr") {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access this functionality") if $FORM{'username'} ne $superuser;
	&ex('backup_mgr', 1);
	exit(0);
}
if ($FORM{'action'} eq 'access_mgr_1') {
	&check_passwd;
	&ex('page_mgr_1', $FORM{"username"}, 2);
	exit(0);
}
if ($FORM{'cmd'} eq 'log_analy') {
	&check_passwd;
	&ex('log_analysis_1', $FORM{"username"});
	exit(0);
}
if ($FORM{'cmd'} eq 'archive_mgr') {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access this functionality") if $FORM{'username'} ne $superuser;
	&ex('archive_mgr', 1);
	exit(0);
}
if ($FORM{'cmd'} eq 'options_mgr') {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access this functionality") if $FORM{'username'} ne $superuser;
	&ex('options_mgr', 1);
	exit(0);
}
if ($FORM{'cmd'} eq 'profanity_editor') {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access this functionality") if $FORM{'username'} ne $superuser;
	&ex('profanity_editor', 1);
	exit(0);
}
if ($FORM{'cmd'} eq 'email_configurator') {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access this functionality") if $FORM{'username'} ne $superuser;
	&ex('email_configurator', 1);
	exit(0);
}
if ($FORM{'action'} eq 'queue_mgr_1') {
	&check_passwd;
	&ex('queue_mgr_1', $FORM{'username'}) if $pro;
	exit(0);
}
if ($FORM{'action'} eq 'queue_mgr_disp') {
	&check_passwd;
	&ex('queue_mgr_disp', $FORM{'username'}, $FORM{'number'}) if $pro;
	exit(0);
}
if ($FORM{'action'} eq 'queue_frames') {
	&check_passwd;
	&ex('queue_frames', $FORM{'username'}) if $pro;
	exit(0);
}
if ($FORM{'action'} eq 'access_mgr_2') {
	&check_passwd;
	&extract($FORM{'HTTP_REFERER'});
	&verify_owner($owner,$FORM{'username'}) || &error_message("Permissions Error", "You do not have permission to edit the selected topic!");
	&ex('access_mgr_2', $topic_number, $FORM{'username'}) if !$pro;
	&ex('access_mgr_2_pro', $topic_number, $FORM{'username'}) if $pro;
	exit(0);
}
if ($FORM{'action'} eq "page_editor") {
	&check_passwd;
	&extract($FORM{'HTTP_REFERER'});
	&verify_owner($owner,$FORM{'username'}) || &error_message("Permissions Error", "You do not have permission to edit the selected topic!");
	$refer = "//$FORM{'HTTP_REFERER'}";
	&ex("page_mgr_2", $refer,$FORM{"username"});
}
if ($FORM{'action'} eq "graphic_browser") {
	&check_passwd;
	&extract ($FORM{'HTTP_REFERER'});
	&ex('graphic_browser_select', $topic_number, $me_number, $FORM{'username'});
	exit(0);
}
if ($FORM{'cmd'} eq "board_mgr") {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access the board manager!") if $FORM{'username'} ne $superuser;
	&ex('board_manager', $FORM{"username"}); exit(0);
}
if ($FORM{'cmd'} eq "data_recovery") {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access the data recovery utility!") if $FORM{'username'} ne $superuser;
	&ex('data_recovery', $FORM{"username"}); exit(0);
}
if ($FORM{'cmd'} eq "moderator_mgr") {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access the moderator manager!") if $FORM{'username'} ne $superuser;
	&ex('moderator_mgr', $FORM{"username"});
	exit(0);
}
if ($FORM{'action'} eq "viewmessage") {
	&check_passwd;
	&extract ($FORM{'HTTP_REFERER'});
	&verify_owner($owner,$FORM{'username'}) || &error_message("Permissions Error", "You do not have permission to view messages in this topic!");
	$file = "$message_dir/$topic_number/$me_number.$ext";
	$post = $FORM{'num'};
	&ex('viewmessage', $topic_number, $me_number, $post);
	exit(0);
}
if ($FORM{'action'} eq 'menu' || $FORM{'cmd'} eq 'menu') {
	$COOKIE{'pass' . $COOKIE_ID} = "";
	$pass = &check_passwd(1,1);
	$flag = 1 if $pass eq "* BLANK *";
	if ($GLOBAL_OPTIONS{'admin'} == 0 && $GLOBAL_OPTIONS{'options_used'} == 1) {
		&error_message("Administration Disabled", "Administration has been disabled on this board for all moderators except the superuser.") if $FORM{'username'} ne $superuser;
	}
	&ex('admin_main_menu',$FORM{"username"}, $pass, $flag);
	exit(0);
}
if ($FORM{'action'} eq 'first_pass') {
	$pass = &check_passwd(0,1);
	&error_message("Permissions Error", "Only the superuser may access this!") if $FORM{'username'} ne $superuser;
	&ex('first_pass', $FORM{"username"});
	exit(0);
}
if ($FORM{'cmd'} eq "group_mgr") {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access the group manager!") if $FORM{'username'} ne $superuser;
   &ex('group_mgr', $FORM{"username"}); exit(0);
}
if ($FORM{'cmd'} eq "user_mgr") {
	&check_passwd;
	&ex('user_mgr_1', $FORM{"username"});
	exit(0);
}
if ($FORM{'cmd'} eq "user_mgr_2") {
	&check_passwd;
	&verify_owner($FORM{'group'},$FORM{'username'}) || &error_message("Permissions Error", "You do not have permission to edit users in this group!");
	&ex('user_mgr_2', $FORM{"username"}, $FORM{"group"});
	exit(0);
}
if ($FORM{'cmd'} eq "version_mgr") {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access the version manager!") if $FORM{'username'} ne $superuser;
	&ex('version_manager', 1);
	exit(0);
}
if ($FORM{'cmd'} eq "reg_configurator") {
	&check_passwd;
	&error_message("Permissions Error", "Only the superuser may access the version manager!") if $FORM{'username'} ne $superuser;
	&ex('reg_configurator', 1);
	exit(0);
}
if ($FORM{'cmd'} eq "start") {
	&ex('admin_from_here', 1);
}
&ex("front_page", 1);
exit(0);

