/**
 * File:	clients/ldap.ycp
 * Module:	Configuration of LDAP client
 * Summary:	Client file, including commandline handlers
 * Authors:	Thorsten Kukuk <kukuk@suse.de>
 *		Anas Nashif <nashif@suse.de>
 *
 * $Id: ldap.ycp 20510 2004-12-07 16:03:35Z jsuchome $
 */

/***
 * <h3>Configuration of the ldap</h3>
 */

{

    textdomain "ldap-client";

    import "CommandLine";
    import "Ldap";
    import "RichText";
    import "Service";

    include "ldap/wizards.ycp";

    any ret = `auto;

// --------------------------------------------------------------------------
// --------------------------------- cmd-line handlers

/**
 * Enable or disable LDAP authentication
 * @param options  a list of parameters passed as args
 * @return boolean true on success
 */
define boolean LdapEnableHandler( map<string,string> options ) ``{
    // check the "command" to be present exactly once
    string command = CommandLine::UniqueOption( options,
	["enable", "disable" ] );
    if( command == nil ) return false;

    Ldap::RestartSSHD (
	command == "enable" && !Ldap::start && Service::Status ("sshd") == 0);

    Ldap::start = ( command == "enable" );
    return true;
}

/**
 * Print summary of basic options
 * @return boolean false
 */
define boolean LdapSummaryHandler (map options ) ``{

    CommandLine::Print (RichText::Rich2Plain ("<br>" + Ldap::ShortSummary ()));
    return false; // do not call Write...
}

/**
 * Change basic configuration of LDAP client (server, base DN)
 * @param options  a list of parameters passed as args
 * @return boolean true on success
 */
define boolean LdapChangeConfiguration (map options ) ``{

    string server = options["server"]:"";
    if( server != "" )
    {
	Ldap::server	= server;
	Ldap::modified	= true;
    }
    string base = options["base"]:"";
    if( base != "" )
    {
	Ldap::SetDomain (base);
	Ldap::modified	= true;
    }
    return Ldap::modified;
}

define boolean LdapWrite () ``{

    block<boolean> abort = ``{ return false; };
    return (Ldap::Write(abort) == `next);
}

/* the command line description map */
map cmdline = $[
    "id"		: "ldap",
    // translators: command line help text for Ldap client module
    "help"		: _("LDAP client configuration module."),
    "guihandler"	: LdapSequence,
    "initialize"	: Ldap::Read,
    "finish"		: LdapWrite,
    "actions"		: $[
	"pam" :$[
	    "handler"	: LdapEnableHandler,
	    // translators: command line help text for pam action
	    "help"	: _("Enable or disable authentication with LDAP")
	],
	"summary" :$[
	    "handler"	: LdapSummaryHandler,
	    // translators: command line help text for summary action
	    "help"	: _("Configuration summary of LDAP client")
	],
	"configure"	: $[
	    "handler"	: LdapChangeConfiguration,
	    // translators: command line help text for configure action
	    "help"	: _("Change the global settings of LDAP client")
	]
    ],
    "options"		: $[
	"enable"	:$[
	    // translators: command line help text for pam enable option
	    "help"	: _("Enable the service")
	],
	"disable"	:$[
	    // translators: command line help text for pam disable option
	    "help"	: _("Disable the service")
	],
	"server"	:$[
	    // translators: command line help text for the server option
	    "help"	: _("The LDAP server name"),
	    "type"	: "string"
	],
	"base"	:$[
	    // translators: command line help text for the base option
	    "help"	: _("Distinguished Name (DN) of the search base"),
	    "type"	: "string"
	],
    ],
    "mappings"		: $[
	"pam"		: [ "enable", "disable" ],
	"summary"	: [],
	"configure"	: [ "server", "base" ],
    ]
];

   ret = CommandLine::Run( cmdline );
   return ret;
}
