/**
 * File:	clients/security.ycp
 * Package:	Security configuration
 * Summary:	Main file
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: security.ycp 18706 2004-08-19 11:45:44Z jsuchome $
 *
 * This is a main file of the module. There is in the file
 * only some calls to the basic functions. The settings are
 * initialized, main dialog is called and then settings are
 * saved.
 */

{

/***
 * <h3> Security configuration
 */

textdomain "security";

/* The main () */
y2milestone("----------------------------------------");
y2milestone("Security module started");

import "CommandLine";
import "Security";

include "security/wizards.ycp";

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

/**
 * Print security summary
 * @return boolean false
 */
define boolean SecuritySummaryHandler (map options) {

    list sum = Security::Summary ();
    CommandLine::Print (sum[0]:"");
    return false; // do not call Write...
}

/**
 * Set security level
 * @return boolean successfully modified?
 */
define boolean SecurityLevelHandler (map options) {

    any current = `custom;
    maplist (string key, map level, Levels, {
	if(level == Security::Settings)
	    current = key;
    });
    string lvl	= "";
    if (haskey (options, "home"))
	lvl	= "Level1";
    else if (haskey (options, "network"))
	lvl	= "Level2";
    else if (haskey (options, "server"))
	lvl	= "Level3";

    if (current != lvl)
    {
	Security::Settings = Levels[lvl]:$[];
	Security::modified = true;
	return true;
    }
    return false;
}

/**
 * Set value of specific security option
 * @return boolean false
 */
define boolean SecuritySetHandler (map options) {

    y2internal ("op: %1", options);
    if (haskey (options, "passwd") &&
	options["passwd"]:"" != Security::Settings["PASSWD_ENCRYPTION"]:"")
    {
	Security::Settings["PASSWD_ENCRYPTION"]	= options["passwd"]:"des";
	Security::modified = true;
    }
    if (haskey (options, "obscure") &&
	options["obscure"]:"" != Security::Settings["OBSCURE_CHECKS_ENAB"]:"")
    {
	Security::Settings["OBSCURE_CHECKS_ENAB"] = options["obscure"]:"yes";
	Security::modified = true;
    }
    if (haskey (options, "crack") &&
	options["crack"]:"" != Security::Settings["PASSWD_USE_CRACKLIB"]:"")
    {
	Security::Settings["PASSWD_USE_CRACKLIB"] = options["crack"]:"yes";
	Security::modified = true;
    }
    if (haskey (options, "permissions") &&
	! issubstring (Security::Settings["PERMISSION_SECURITY"]:"",
	options["permissions"]:""))
    {
	Security::Settings["PERMISSION_SECURITY"] =
	    options["permissions"]:"" + " local";
	Security::modified = true;
    }
    return Security::modified;
}



/* the command line description map */
map cmdline = $[
    "id"		: "security",
    // translators: command line help text for Securoty module
    "help"		: _("Security configuration module."),
    "guihandler"	: SecuritySequence,
    "initialize"	: Security::Read,
    "finish"		: Security::Write,
    "actions"		: $[
	"summary" :$[
	    "handler"	: SecuritySummaryHandler,
	    // command line help text for 'summary' action
	    "help"	: _("Security configuration summary"),
	],
	"level" :$[
	    "handler"	: SecurityLevelHandler,
	    // command line help text for 'level' action
	    "help"	: _("Set the security level"),
	],
	"set" :$[
	    "handler"	: SecuritySetHandler,
	    // command line help text for 'set' action
	    "help"	: _("Set the value of specific option"),
	],
    ],
    "options"		: $[
	"home"		: $[
	    // command line help text for 'level home' option
	    "help"	: _("Home Workstation security level (without network)")
	],
	"network"	: $[
	    // command line help text for 'level network' option
	    "help"	: _("Networked Workstation security level")
	],
	"server"	: $[
	    // command line help text for 'level server' option
	    "help"	: _("Networked Server security level")
	],
	"passwd"	: $[
	    // command line help text for 'set passwd' option
	    "help"	: _("Password encryption method"),
	    "type"	: "enum",
	    "typespec"	: [ "des", "md5", "blowfish" ],
	],
	"obscure"	: $[
	    // command line help text for 'set obscure' option
	    "help"	: _("Plausibility test for password"),
	    "type"	: "enum",
	    "typespec"	: [ "yes", "no" ],
	],
	"crack"	: $[
	    // command line help text for 'set crack' option
	    "help"	: _("Checking new passwords strength"),
	    "type"	: "enum",
	    "typespec"	: [ "yes", "no" ],
	],
	"permissions" : $[
	    // command line help text for 'set permissions' option
	    "help"	: _("Setting of file permissions"),
	    "type"	: "enum",
	    "typespec"	: [ "easy", "secure", "paranoid" ],
	],
    ],
    "mappings"		: $[
	"summary"	: [],
	"level"		: [ "home", "network", "server" ],//FIXME 1,2,3 aliases
	"set"		: [ "passwd", "obscure", "crack", "permissions" ],
    ]
];

any ret = CommandLine::Run (cmdline);
y2debug("ret == %1", ret);

/* Finish */
y2milestone("Security module finished");
y2milestone("----------------------------------------");
return ret;

/* EOF */
}
