# Configurable Finger Daemon Makefile Configuration program for DIALOG
# by Ken Hollis
#
# Released under the GPL as part of the Security/Administrative Package.
#
# **** DO NOT RUN THIS PROGRAM BY ITSELF!  IT IS AN INCLUSION SCRIPT! ****
# **** DO NOT RUN THIS PROGRAM BY ITSELF!  IT IS AN INCLUSION SCRIPT! ****
# **** DO NOT RUN THIS PROGRAM BY ITSELF!  IT IS AN INCLUSION SCRIPT! ****
#
# Please read the file "README" for more details.

sub change_compiler {
    $exec_str = "dialog ".
	"--title \"<< CHANGE COMPILER [CURRENTLY ${COMPILER}] >>\" ".
	"--backtitle \"Change the compiler (GCC is recommended)\" ".
	"--inputbox \"Please enter the name of the compiler you wish\\n" .
	"to use.  Hit return (or CANCEL) to accept the\\n" .
	"current config.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$COMPILER = $tmp;
    }
}

sub change_compiler_flags {
    $exec_str = "dialog ".
	"--title \"<< CHANGE FLAGS [CURRENTLY ${COMPILE_FLAGS}] >>\" ".
	"--backtitle \"Change the compile flags (-Wall -O2 -m486 -DLINUX is recommended)\" ".
	"--inputbox \"Please enter the compiler flags that you desire.\\n" .
	"Hit return (or CANCEL) to accept the current\\n" .
	"config.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$COMPILE_FLAGS = $tmp;
    }
}

sub change_debugging {
    $exec_str = "dialog ".
	"--title \"<< DEBUGGING [${DEBUGGING}] >>\" ".
	"--backtitle \"Change debugging flags (*NO* is recommended)\" ".
	"--yesno \"Do you wish to enable debugging?  If you want to waste\\n" .
	"disk space and have EXTREMELY verbose error reports,\\n" .
	"I suggest you enable this; otherwise, select \\\"NO\\\". \" ".
	" 7 60";

    $ret = system($exec_str);

    if ($ret eq "0") {
	$DEBUGGING = "Y";
    } else {
	$DEBUGGING = "N";
    }
}

sub change_g_debugging {
    $exec_str = "dialog ".
	"--title \"<< G_DEBUG [${G_DEBUG}] >>\" ".
	"--backtitle \"Change -g debugging flags (NO is *HIGHLY* RECOMMENDED!!)\" ".
	"--yesno \"It all depends on what size you want your executable to\\n" .
	"be.  If you want to have an executable about 1MB in\\n" .
	"size, select YES, otherwise, select NO.\" ".
	" 7 60";

    $ret = system($exec_str);

    if ($ret eq "0") {
	$G_DEBUG = "Y";
    } else {
	$G_DEBUG = "N";
    }
}

sub change_grace_period {
    $exec_str = "dialog ".
	"--title \"<< CHANGE GRACE PERIOD [CURRENTLY ${GRACE_PERIOD}] >>\" ".
	"--backtitle \"Change the grace period (RECOMMENDED: LINUX - 0, SYSV/Ultrix - 1, SunOS - 2)\" ".
	"--inputbox \"Please enter the number of seconds that you want the\\n" .
	"daemon to wait before query starts.  Normals are\\n" .
	"between 0 and 2.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$GRACE_PERIOD = $tmp;
    }
}

sub change_install_dir {
    $exec_str = "dialog ".
	"--title \"<< CHANGE INSTALL DIR [CURRENTLY ${INSTALL_DIR}] >>\" ".
	"--backtitle \"Change the installation dir (/usr/sbin is recommended)\" ".
	"--inputbox \"Please enter the name of the directory you wish\\n" .
	"to use.  Hit return (or CANCEL) to accept the\\n" .
	"current config.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$INSTALL_DIR = $tmp;
    }
}

sub change_config_file {
    $exec_str = "dialog ".
	"--title \"<< CHANGE CONFIG FILE [CURRENTLY ${CONFIG_FILE}] >>\" ".
	"--backtitle \"Change the config filename (cfingerd.conf is recommended)\" ".
	"--inputbox \"Please enter the name of the filename you wish\\n" .
	"to use.  Hit return (or CANCEL) to accept the\\n" .
	"current config.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$CONFIG_FILE = $tmp;
    }
}

sub change_config_file_dest {
    $exec_str = "dialog ".
	"--title \"<< CHANGE CONFIG FILE DIR [CURRENTLY ${CONFIG_FILE_DEST}] >>\" ".
	"--backtitle \"Change the config file dir (/etc is recommended)\" ".
	"--inputbox \"Please enter the name of the directory you wish\\n" .
	"to use.  Hit return (or CANCEL) to accept the\\n" .
	"current config.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$CONFIG_FILE_DEST = $tmp;
    }
}

sub change_man_page {
    $exec_str = "dialog ".
	"--title \"<< CHANGE MAN PAGE DIR [CURRENTLY ${MAN_PAGE}] >>\" ".
	"--backtitle \"Change the manual page dir (/usr/man/man1 is recommended)\" ".
	"--inputbox \"Please enter the name of the directory you wish\\n" .
	"to use.  Hit return (or CANCEL) to accept the\\n" .
	"current config.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$MAN_PAGE = $tmp;
    }
}

sub change_timeout {
    $exec_str = "dialog ".
	"--title \"<< CHANGE TIMEOUT [CURRENTLY ${TIMEOUT}] >>\" ".
	"--backtitle \"Change the timeout duration (10 is recommended)\" ".
	"--inputbox \"Please enter the duration value that you wish\\n" .
	"to use.  Hit return (or CANCEL) to accept the\\n" .
	"current config.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$TIMEOUT = $tmp;
    }
}

sub change_whois {
    $exec_str = "dialog ".
	"--title \"<< CHANGE WHOIS PROGRAM [CURRENTLY ${TIMEOUT}] >>\" ".
	"--backtitle \"Change the whois program (/usr/bin/whois is recommended)\" ".
	"--inputbox \"Please enter the name of the program that you\\n" .
	"wish to use.  Hit return (or CANCEL) to accept\\n" .
	"the current config.\" " .
	" 10 60 2>$temp";

    $ret = system($exec_str);
    $tmp = `cat $temp`;

    if ($tmp ne "") {
	$WHOIS = $tmp;
    }
}

sub change_syslog {
    $exec_str = "dialog ".
	"--title \"<< SYSLOG [${SYSLOG}] >>\" ".
	"--backtitle \"Change syslogging flags (*YES* is recommended)\" ".
	"--yesno \"Do you wish to have syslogging enabled?  This will\\n" .
	"report all bugs, and all warnings to the syslogger\\n" .
	"which can be saved for reference. \" ".
	" 7 60";

    $ret = system($exec_str);

    if ($ret eq "0") {
	$SYSLOG = "Y";
    } else {
	$SYSLOG = "N";
    }
}

sub do_makefile {
    $exec_str = "dialog ".
	"--infobox \"One moment...\" 3 17";

    system($exec_str);

    $COMPILE_FLAGS_OLD = $COMPILE_FLAGS;
    $G_DEBUG_OLD = $G_DEBUG;

    if ($G_DEBUG eq "Y") {
	$G_DEBUG = "-g";
    } else {
	$G_DEBUG = "";
    }

    &make_makefile;

    $COMPILE_FLAGS = $COMPILE_FLAGS_OLD;
    $G_DEBUG = $G_DEBUG_OLD;

    $MAKE_MADE = "TRUE";
}

sub manage_config {
    $exec_str = "dialog ".
	"--title \"<< CFINGERD Configuration ${VERSION} >>\" ".
	"--backtitle \"Configuration\" ".
	"--menu \"Welcome to CFINGERD ${VERSION} Configuration script.\\n" .
	"\\nPlease select your choice and press the [RETURN] key to select\\n" .
	"your configuration option.  <CANCEL> exits Configure.\" 20 67 10 ".
	"\"COMPILER\"		\"Change compiler [${COMPILER}]\" ".
	"\"FLAGS\"		\"Compiler flags [${COMPILE_FLAGS}]\" ".
	"\"DEBUGGING\"		\"Debugging [${DEBUGGING}]\" ".
	"\"SIZE\"		\"Enable -g compile option [${G_DEBUG}]\" ".
	"\"WAIT_PERIOD\"	\"Grace period [${GRACE_PERIOD}]\" ".
	"\"INSTALL_DIR\"	\"Installation dir [${INSTALL_DIR}]\" ".
	"\"FINGER_FILE\"	\"Configuration file [${CONFIG_FILE}]\" ".
	"\"DEST_CONFIG_FILE\"	\"Configure file destination [${CONFIG_FILE_DEST}]\" ".
	"\"PAGE\"		\"Man page directory [${MAN_PAGE}]\" ".
	"\"TIMEOUT\"		\"Script timeout duration [${TIMEOUT}]\" ".
	"\"WHOIS\"		\"Whois program [${WHOIS}]\" ".
	"\"SYSLOG\"		\"Enable syslogging output [${SYSLOG}]\" ".
	"\"MAKEFILE\"		\"Create the makefile\" 2>$temp";

    $ret = system($exec_str);
    $tmp = eval `cat $temp`;

    if ($ret eq "0") {
	if ($tmp eq "COMPILER") {
	    &change_compiler;
	} elsif ($tmp eq "FLAGS") {
	    &change_compiler_flags;
	} elsif ($tmp eq "DEBUGGING") {
	    &change_debugging;
	} elsif ($tmp eq "SIZE") {
	    &change_g_debugging;
	} elsif ($tmp eq "WAIT_PERIOD") {
	    &change_grace_period;
	} elsif ($tmp eq "INSTALL_DIR") {
	    &change_install_dir;
	} elsif ($tmp eq "FINGER_FILE") {
	    &change_config_file;
	} elsif ($tmp eq "DEST_CONFIG_FILE") {
	    &change_config_file_dest;
	} elsif ($tmp eq "PAGE") {
	    &change_man_page;
	} elsif ($tmp eq "TIMEOUT") {
	    &change_timeout;
	} elsif ($tmp eq "WHOIS") {
	    &change_whois;
	} elsif ($tmp eq "SYSLOG") {
	    &change_syslog;
	} elsif ($tmp eq "MAKEFILE") {
	    &do_makefile;
	}

	&manage_config;
    }
}

sub config_dialog {
    $temp = "./configure_opt";

    $MAKE_MADE = "FALSE";

    &manage_config;
    system("rm $temp");

    system("clear");

    if ($MAKE_MADE eq "TRUE") {
	print <<"EOT";
Done.  If you recently created a Makefile, you will want to type
\"make\" after you edit the configuration file, and such.

Good luck!

EOT
    } else {
	print <<"EOT";
Operation cancelled.  If you didn't mean to do that, please either re-run 
the Configuration program, or type \"Configure help\" for a list of options.

EOT
    }
}

1;
