/**
 * File:	clients/ldap_auto.ycp
 * Package:	Configuration of LDAP client
 * Summary:	Client for autoinstallation
 * Authors:	Thorsten Kukuk <kukuk@suse.de>
 *		Anas Nashif <nashif@suse.de>
 *
 * $Id: ldap_auto.ycp 20588 2004-12-16 14:55:20Z jsuchome $
 *
 * This is a client for autoinstallation. It takes its arguments,
 * goes through the configuration and return the setting.
 * Does not do any changes to the configuration.
 */

/**
 * @param first a map of LDAP settings
 * @return map edited settings or an empty map if canceled
 * @example map mm = $[ "FAIL_DELAY" : "77" ];
 * @example map ret = WFM::CallModule ("ldap_auto", [ mm ]);
 */

{

textdomain "ldap-client";
y2milestone("----------------------------------------");
y2milestone("Ldap auto started");

import "Ldap";
include "ldap/wizards.ycp";


any ret = nil;
string func = "";
map param = $[];

/* 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))
	param = (map) WFM::Args(1);
}
y2debug("func=%1", func);
y2debug("param=%1", param);


block<boolean> abort_block = ``{ return false; };

/* Import Data*/
if(func == "Import") {
    ret = Ldap::Import(param);
}
/* Create a  summary*/
else if(func == "Summary") {
    ret = Ldap::Summary();
}
/* Reset configuration */
else if (func == "Reset") {
    Ldap::Import($[]);
    Ldap::modified = false;
    ret = $[];
}
/* Change configuration (run AutoSequence) */
else if (func == "Change") {
    ret = LdapAutoSequence ();
}
/* Return actual state */
else if (func == "Export") {
    ret = Ldap::Export();
}
/**
 * Return if configuration  was changed
 * return boolean
 */
else if (func == "GetModified") {
    ret = Ldap::modified;
}
/**
 * Set modified flag
 * return boolean
 */
else if (func == "SetModified") {
    Ldap::modified = true;
    ret = true;
}
/* Write givven settings */
else if (func == "Write") {
    import "Progress";
    Ldap::write_only = true;
    boolean progress_orig = Progress::set (false);
    ret = Ldap::Write(abort_block);
    Progress::set (progress_orig);
}
else if (func == "Packages") {
    ret = Ldap::AutoPackages();
}
/* Unknown function */
else {
    y2error("Unknown function: %1", func);
    ret = false;
}

y2debug("ret=%1", ret);
y2milestone("Ldap auto finished");
y2milestone("----------------------------------------");

return ret;

/* EOF */
}
