/**
 * File:	include/security/dialogs.ycp
 * Package:	Security configuration
 * Summary:	Dialogs definitions
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: dialogs.ycp 22094 2005-03-02 08:20:09Z jsuchome $
 */

{

textdomain "security";

import "Label";
import "Popup";
import "Security";
import "Wizard";

include "security/helps.ycp";
include "security/routines.ycp";

/**
 * Boot dialog
 * @return dialog result
 */
define symbol BootDialog() ``{

    /* Boot dialog caption */
    string caption = _("Boot Settings");
    string help = HELPS["boot"]:"";

    /* Boot dialog contents */
    term contents = `HVCenter(`HVSquash(`HBox(
	`HSpacing(5),
	`VBox(
	    `VSpacing(2),
	    /* Frame label */
	    `Frame(_("Boot Permissions"),`HBox(
		`HSpacing(3),
		`VBox(
		    `VSpacing(1),
		    settings2widget("CONSOLE_SHUTDOWN"),
		    `VSpacing(1.0),
		    settings2widget("KDM_SHUTDOWN"),
		    `VSpacing(1)
		),
		`HSpacing(3)
	    )),
	    `VSpacing(2)
	),
	`HSpacing(5)
    )));

    Wizard::SetContentsButtons(caption, contents, help,
	    Label::BackButton(), Label::NextButton());

    any ret = nil;
    while(true) {
	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	else if(ret == `back || ret == `next) {
	    break;
	}
	else {
	    y2error("Unexpected return code: %1", ret);
	    continue;
	}
    }

    if(ret == `next) {
	widget2settings("CONSOLE_SHUTDOWN");
	widget2settings("KDM_SHUTDOWN");
    }

    return (symbol) ret;
}

/**
 * Misc dialog
 * @return dialog result
 */
define symbol MiscDialog() ``{

    /* Misc dialog caption */
    string caption = _("Miscellaneous Settings");
    string help = HELPS["misc"]:"";

    /* Misc dialog contents */
    term contents = `VBox(
	VSeparator(),
	settings2widget("PERMISSION_SECURITY"),
	`VSpacing(1.0),
	settings2widget("RUN_UPDATEDB_AS"),
	`VSpacing(1.0),
	settings2widget("CWD_IN_ROOT_PATH"),
	VSeparator(),
	settings2widget("CWD_IN_USER_PATH"),
	`VSpacing(1.0),
	settings2widget("ENABLE_SYSRQ"),
	`VSpacing(1.8)
    );
    contents = `HVCenter(`HVSquash(`HBox(`HSpacing(5),`VBox(`VSpacing(2),`ReplacePoint(`id(`rp_main),contents),`VSpacing(2)),`HSpacing(5))));

    Wizard::SetContentsButtons(caption, contents, help,
	    Label::BackButton(), Label::FinishButton());

    any ret = nil;
    while(true) {
	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	else if(ret == `back) {
	    break;
	}
	else if(ret == `next) {
	    /* check_* */
	    break;
	}
	else {
	    y2error("Unexpected return code: %1", ret);
	    continue;
	}
    }

    if(ret == `next) {
	widget2settings("PERMISSION_SECURITY");
	widget2settings("CWD_IN_ROOT_PATH");
	widget2settings("CWD_IN_USER_PATH");
	widget2settings("RUN_UPDATEDB_AS");
	widget2settings("ENABLE_SYSRQ");
    }

    return (symbol) ret;
}

/**
 * Password dialog
 * @return dialog result
 */
define symbol PassDialog() ``{

    /* Password dialog caption */
    string caption = _("Password Settings");
    string help = HELPS["password"]:"";

    /* Password dialog contents */
    term contents = `VBox(
	/* Frame label */
	XFrame(0.3,0.15,_("Checks"),`VBox(
	    settings2widget("PASSWD_USE_CRACKLIB"),
	    VSeparator(),
	    settings2widget("OBSCURE_CHECKS_ENAB"),
	    VSeparator()
	)),
	`VSpacing(1.0),
	settings2widget("PASSWD_ENCRYPTION"),
	`VSpacing(1.0),
	settings2widget("PASS_MIN_LEN"),
	`VSpacing(1.0),
	/* Frame label */
	`Frame(_("Days to Password Change Warning"),`HBox(
	    `HSpacing(0.4),
	    settings2widget("PASS_MIN_DAYS"),
	    `HSpacing(0.4),
	    settings2widget("PASS_MAX_DAYS"),
	    `HSpacing(0.4)
	)),
	`VSpacing(0.15),
	settings2widget("PASS_WARN_AGE"),
	`VSpacing(0.0)
    );
    contents = `HVCenter(`HVSquash(`HBox(`HSpacing(5),`VBox(`VSpacing(2),`ReplacePoint(`id(`rp_main),contents),`VSpacing(2)),`HSpacing(5))));

    Wizard::SetContentsButtons(caption, contents, help,
	    Label::BackButton(), Label::NextButton());

    any ret = nil;
    while(true) {
	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	else if(ret == `back) {
	    break;
	}
	else if(ret == `next) {
	    /* check_* */
	    if(checkMinMax("PASS_MIN_DAYS","PASS_MAX_DAYS") != true) {
		/* Popup text */
		Popup::Error(_("The minimum number of days cannot be larger than maximum"));
		continue;
	    }
	    string enc	=
		(string) UI::QueryWidget(`id("PASSWD_ENCRYPTION"), `Value);
	    integer min = (integer) UI::QueryWidget(`id("PASS_MIN_LEN"),`Value);
	    if (min > Security::PasswordMaxLengths[enc]:8)
	    {
		// Popup text, %1 is number
		Popup::Error (sformat (_("The minimum password length cannot be larger than the maximum.
The maximum password length for the selected encryption method is %1."),
		Security::PasswordMaxLengths[enc]:8));
		continue;
	    }
	    break;
	}
	else if (ret != "PASSWD_ENCRYPTION") {
	    y2error("Unexpected return code: %1", ret);
	    continue;
	}
    }

    if(ret == `next) {
	widget2settings("PASS_MIN_DAYS");
	widget2settings("PASS_MAX_DAYS");
	widget2settings("PASS_MIN_LEN");
	widget2settings("PASSWD_USE_CRACKLIB");
	widget2settings("OBSCURE_CHECKS_ENAB");
	widget2settings("PASS_WARN_AGE");
	widget2settings("PASSWD_ENCRYPTION");
    }

    return (symbol) ret;
}

/**
 * Login dialog
 * @return dialog result
 */
define symbol LoginDialog() ``{

    /* Login dialog caption */
    string caption = _("Login Settings");
    string help = HELPS["login"]:"";

    /* Login dialog contents */
    term contents = `VBox(
	/* Frame label */
	XFrame(3.0,1.0,_("Login"),`VBox(
	    //VSeparator(),
	    settings2widget("FAIL_DELAY"),
	    //VSeparator(),
	    `VSpacing(0.5),
	    settings2widget("FAILLOG_ENAB"),
	    VSeparator(),
	    settings2widget("LASTLOG_ENAB"),
	    VSeparator(),
	    settings2widget("DISPLAYMANAGER_REMOTE_ACCESS")
	    //VSeparator()
	))
	//,`VSpacing(1.7)
    );
    contents = `HVCenter(`HVSquash(`HBox(`HSpacing(5),`VBox(`VSpacing(2),`ReplacePoint(`id(`rp_main),contents),`VSpacing(2)),`HSpacing(5))));

    Wizard::SetContentsButtons(caption, contents, help,
	    Label::BackButton(), Label::NextButton());

    any ret = nil;
    while(true) {
	ret = UI::UserInput();

	/* abort? */
	if(ret == `abort || ret == `cancel) {
	    if(ReallyAbort()) break;
	    else continue;
	}
	else if(ret == `back) {
	    break;
	}
	else if(ret == `next) {
	    /* check_* */
	    break;
	}
	else {
	    y2error("Unexpected return code: %1", ret);
	    continue;
	}
   }

    if(ret == `next) {
	widget2settings("FAILLOG_ENAB");
	widget2settings("LASTLOG_ENAB");
	widget2settings("FAIL_DELAY");
	widget2settings("DISPLAYMANAGER_REMOTE_ACCESS");
    }

    return (symbol) ret;
}

/* EOF */
}
