ACC SHELL

Path : /usr/share/YaST2/clients/
File Upload :
Current File : //usr/share/YaST2/clients/users_plugin_ldap_passwordpolicy.ycp

/**
 * File:
 *	include/users/users_plugin_ldap_passwordpolicy.ycp
 *
 * Package:
 *	Configuration of Users
 *
 * Summary:
 *	This is GUI part of UsersPluginLDAPPasswordPolicy
 *	- plugin for editing LDAP user password policy (see feature 301179)
 *
 * Authors:
 *	Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: users_plugin_ldap_passwordpolicy.ycp 50470 2008-08-29 09:58:54Z jsuchome $
 */


{
    textdomain "users";

    import "Label";
    import "LdapPopup";
    import "Report";
    import "Users";
    import "UsersPluginLDAPPasswordPolicy"; // plugin module
    import "Wizard";

    any ret = nil;
    string func			= "";
    map<string,any> config	= $[];
    map<string,any> data	= $[];

    /* Check arguments */
    if(size(WFM::Args()) > 0 && is(WFM::Args(0), string)) {
	func = (string) WFM::Args(0);
	if(size(WFM::Args()) > 1 && is(WFM::Args(1), map))
	    config = (map<string,any>)WFM::Args(1);
	if(size(WFM::Args()) > 2 && is(WFM::Args(2), map))
	    data = (map<string,any>)WFM::Args(2);
    }
    y2milestone("----------------------------------------");
    y2milestone("users plugin started: LDAPPasswordPolicy");

    y2debug ("func=%1", func);
    y2debug ("config=%1", config);
    y2debug ("data=%1", data);

    if (func == "Summary") {
	ret = UsersPluginLDAPPasswordPolicy::Summary (config, $[]);
    }
    else if (func == "Name") {
	ret = UsersPluginLDAPPasswordPolicy::Name (config, $[]);
    }
    else if (func == "Dialog") {

	string caption	= UsersPluginLDAPPasswordPolicy::Name (config, $[]);
	map<string, any> tmp_data	= $[];

	// helptext
	string help_text = _("<p>Assign a password policy object to this user in <b>DN of Password Policy object</b>. Activate <b>Reset Password</b> to reset the password of modified user.</p>");

	boolean pwdreset		= data["pwdReset"]:"FALSE" == "TRUE";
	string pwdpolicysubentry	= data["pwdPolicySubentry"]:"";
	boolean usedefault              = (pwdpolicysubentry == "");

	term contents = `HBox (
	    `HSpacing (3),
            `VBox (
		`Left (
		    `CheckBox (`id (`usedefault), `opt (`notify),
			// check box label
			_("Use &Default Password Policy"), usedefault)
		),
		`HBox (
		    // text entry label
		    `TextEntry (`id ("pwdPolicySubentry"),
			_("DN of &Password Policy object"), pwdpolicysubentry),
		    `VBox (
			`Label (""),
			`PushButton (`id (`browse), Label::BrowseButton ())
		    )
		),
                `Left (
		    `CheckBox (`id ("pwdReset"), _("&Reset Password"), pwdreset)
		)
	    ),
            `HSpacing (3)
	);

	Wizard::CreateDialog ();
        Wizard::SetDesktopIcon("users");

	// dialog caption
	Wizard::SetContentsButtons(_("Password Policy Settings"),
	    contents, help_text, Label::CancelButton(), Label::OKButton());

	Wizard::HideAbortButton ();
	if (usedefault)
	{
	    UI::ChangeWidget (`id (`browse), `Enabled, false);
	    UI::ChangeWidget (`id ("pwdPolicySubentry"), `Enabled, false);
	}

	ret = `next;
	repeat
	{
	    ret = UI::UserInput();
	    if (ret == `browse)
	    {
		string dn = LdapPopup::BrowseTree ("");
		if (dn != "")
		    UI::ChangeWidget (`id ("pwdPolicySubentry"), `Value, dn);
	    }
	    else if (ret == `usedefault)
	    {
		usedefault = (boolean)UI::QueryWidget(`id (`usedefault),`Value);
		UI::ChangeWidget (`id (`browse ), `Enabled, !usedefault);
		UI::ChangeWidget(`id("pwdPolicySubentry"),`Enabled,!usedefault);
            }
	    else if (ret == `next)
	    {
		string new_pwdpolicysubentry = "";
		if (!usedefault)
		{
		    new_pwdpolicysubentry = (string)
			UI::QueryWidget (`id ("pwdPolicySubentry"), `Value);
		}

		if (new_pwdpolicysubentry != pwdpolicysubentry)
		    tmp_data["pwdPolicySubentry"]	= new_pwdpolicysubentry;

		boolean new_pwdreset	= (boolean) UI::QueryWidget (`id ("pwdReset"), `Value);
		if (new_pwdreset != pwdreset)
		    tmp_data["pwdReset"]	= new_pwdreset ? "TRUE" : "FALSE";

		if (tmp_data == $[])
		    break;

		string err = UsersPluginLDAPPasswordPolicy::Check (config, tmp_data);

		if (err != "")
		{
		    Report::Error (err);
		    ret = `notnext;
		    continue;
		}

		// if this plugin wasn't in default set, we must save its name
		if (!contains (data["plugins"]:[], "UsersPluginLDAPPasswordPolicy"))
		{
		    tmp_data["plugins"] = add (tmp_data["plugins"]:[],
			"UsersPluginLDAPPasswordPolicy");
		}
		if (data["what"]:"" == "edit_user")
		{
		    Users::EditUser (tmp_data);
		}
		else if (data["what"]:"" == "add_user")
		{
		    Users::AddUser (tmp_data);
		}
	    }
	} until (is(ret,symbol) &&
	    contains ([`next, `abort, `back, `cancel], (symbol) ret));

	Wizard::CloseDialog ();
    }
    /* unknown function */
    else {
	y2error("unknown function: %1", func);
	ret = false;
    }

    y2debug ("ret=%1", ret);
    y2milestone("users plugin finished");
    y2milestone("----------------------------------------");

    return ret;
}

ACC SHELL 2018