/**
 *
 * File:
 *   master.ycp
 *
 * Module:
 *   Network/YPServer
 *
 * Summary:
 *   YPServer module.
 *
 * Authors:
 *   Dan Vesely <dan@suse.cz>
 *   Martin Vidner <mvidner@suse.cz>
 *
 * $Id: master.ycp 18466 2004-08-10 07:15:41Z jsuchome $
 *
 * YPServer module part.
 *
 */


{

    textdomain "nis_server";

    import "CWMFirewallInterfaces";
    import "Nis";		// check_nisdomainname
    import "NisServer";
    import "Popup";
    import "Wizard";

    include "nis_server/routines.ycp";

    /**
     * Master dialog
     * @return `back, `abort, `next or `details
     */
    define symbol MasterDialog () ``{

	map<string,any> firewall_widget = GetFirewallWidget ();
	term firewall_layout = firewall_widget["custom_widget"]:`VBox ();

	// help text 1/3
	string helptext = _("<p>Enter a NIS <b>domain</b>. If this host is also a NIS client using this machine as a server, check
the corresponding option.</p>
");

	// help text 2/3
	helptext = helptext + _("<p>For slave servers to cooperate with this master, check
<i>Active Slave NIS server exists</i>. If you check
<i>Fast Map distribution</i>, it will speed up the transfer of maps to the
slaves.</p>
");

	// help text 3/3
	helptext = helptext + _("<p><i>Allow changes to passwords</i> lets the users change their
passwords in the presence of NIS. Buttons to allow
changing the login shell or GECOS (full name and related information) can
be used to set up these more specific options.</p>
");

	helptext = helptext + firewall_widget["help"]:"";

	term pass_yes_buttons = `VBox ();
				// To translators: checkbox label
	pass_yes_buttons = add (pass_yes_buttons, `Left (`CheckBox (`id (`allow_gecos), _("Allow changes to &GECOS field"),
				NisServer::pwd_chfn)));
				// To translators: checkbox label
	pass_yes_buttons = add (pass_yes_buttons, `Left (`CheckBox (`id (`allow_shell), _("Allow changes to login &shell"),
				NisServer::pwd_chsh)));
	pass_yes_buttons = `HBox (`HSpacing (3), pass_yes_buttons);

	term pass_buttons = `VBox ();
	pass_buttons = add (pass_buttons, `VSpacing (0.3));
	pass_buttons = add (pass_buttons, `Left (`CheckBox (`id (`change_passwords), `opt (`notify),
							    // To translators: checkbox label
			    _("Allow changes to &passwords"),
			    NisServer::start_yppasswdd)));
	pass_buttons = add (pass_buttons, `VSpacing (0.3));
	pass_buttons = add (pass_buttons, pass_yes_buttons);
	pass_buttons = add (pass_buttons, `VSpacing (0.3));
	pass_buttons = `HBox (`HSpacing (), pass_buttons);

	term domain_frame = `VBox ();
	domain_frame = add (domain_frame, `VSpacing (0.3));
	domain_frame = add (domain_frame, `TextEntry (`id (`domain), "",
						      NisServer::domain));
	domain_frame = add (domain_frame, `VSpacing (0.3));
	domain_frame = add (domain_frame, `Left (
	    // To translators: checkbox label
	    `CheckBox (`id (`also_client), _("This host is also a NIS &client"),
		NisServer::start_ypbind)));
	domain_frame = add (domain_frame, `VSpacing (0.3));
	domain_frame = `HBox (`HSpacing (), domain_frame, `HSpacing (4));

	term contents = `VBox ();
	contents = add (contents, `VSpacing (0.5));
				// To translators: frame label
	contents = add (contents, `Frame (_("NIS &Domain Name"), domain_frame));
	contents = add (contents, `VSpacing (0.5));
				// To translators: checkbox label
	contents = add (contents, `HBox (`HSpacing (), `Left (`CheckBox (`id (`have_slave), _("Active Slave NIS server &exists"),
			!NisServer::nopush))));
	contents = add (contents, `VSpacing (0.5));
				// To translators: checkbox label
	contents = add (contents, `HBox (`HSpacing (),`Left (`CheckBox (`id (`fast_map), _("&Fast Map distribution (rpc.ypxfrd)"),
			NisServer::start_ypxfrd))));
	contents = add (contents, `VSpacing (0.5));
				// To translators: frame label
	contents = add (contents, `Frame (_("Changing of passwords"), pass_buttons));
	contents = add (contents, `VSpacing (0.5));
	contents = add (contents, firewall_layout);

	contents = `VBox (
	    contents,
	    `VSpacing (0.5),
	    `PushButton (`id (`details), `opt (`key_F7),
		// To translators: pushbutton label
		_("&Other global settings ..."))
	);

	contents = `HBox (`HSpacing (4), contents, `HSpacing (6));

	// To translators: dialog label
	Wizard::SetContents (_("Master Server Setup"),
	    contents, helptext, true, true);

	boolean a = NisServer::start_yppasswdd;
	UI::ChangeWidget (`id (`allow_shell), `Enabled, a);
	UI::ChangeWidget (`id (`allow_gecos), `Enabled, a);

	CWMFirewallInterfaces::OpenFirewallInit (firewall_widget, "");

	map event = $[];
	any ui = nil;
	repeat
	{
	    event	= UI::WaitForEvent ();
	    ui		= event["ID"]:nil;
	    CWMFirewallInterfaces::OpenFirewallHandle(firewall_widget,"",event);
	    if (ui == `cancel)
	    {
		ui = `abort;
	    }

	    if (ui == `change_passwords)
	    {
		boolean enabled = (boolean) UI::QueryWidget (`id (`change_passwords), `Value);
		UI::ChangeWidget (`id (`allow_shell), `Enabled, enabled);
		UI::ChangeWidget (`id (`allow_gecos), `Enabled, enabled);
	    }

	    else if (ui == `next)
	    {
		string domainname = (string) UI::QueryWidget (`id (`domain), `Value);

		if (!Nis::check_nisdomainname (domainname))
		{
		    UI::SetFocus (`id (`domain));
		    Popup::Error (Nis::valid_nisdomainname ());
		    ui = `again;
		}
		if (ui == `next)
		{
		    NisServer::start_ypbind = (boolean)
			UI::QueryWidget (`id (`also_client), `Value);
		    CheckForDHCPClient (domainname);
		    CWMFirewallInterfaces::OpenFirewallStore (
			firewall_widget,"",event);
		}
	    }

	    if (ui == `abort && !Popup::ReallyAbort (true))
	    {
		ui = `again;
	    }
	}
	until (	is (ui,symbol) &&
		contains ([`next, `back, `abort, `details], (symbol) ui));

	NisServer::nopush =
	    ! (boolean) UI::QueryWidget (`id (`have_slave), `Value);
	NisServer::pwd_chfn =
	    (boolean) UI::QueryWidget (`id (`allow_gecos), `Value);
	NisServer::pwd_chsh =
	    (boolean) UI::QueryWidget (`id (`allow_shell), `Value);
	NisServer::start_yppasswdd =
	    (boolean) UI::QueryWidget (`id (`change_passwords), `Value);
	NisServer::start_ypxfrd =
	    (boolean) UI::QueryWidget (`id (`fast_map), `Value);
	NisServer::domain =
	    (string) UI::QueryWidget (`id (`domain), `Value);

	return (symbol) ui;
    }
}
