/**
 * File:	clients/firewall_auto.ycp
 * Package:	SuSE firewall configuration
 * Summary:	Client for autoinstallation
 * Authors:	Anas Nashif <nashif@suse.de>
 *		Lukas Ocilka <locilka@suse.cz>
 *
 * $Id: firewall_auto.ycp 22125 2005-03-02 09:56:43Z locilka $
 *
 * 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 function to execute
 * @param map/list of firewall settings
 * @return map edited settings, Summary or boolean on success depending on called function
 * @example map mm = $[ "FAIL_DELAY" : "77" ];
 * @example map ret = WFM::CallFunction ("firewall_auto", [ "Summary", mm ]);
 */

{

textdomain "firewall";

y2milestone("----------------------------------------");
y2milestone("Firewall auto started");

import "Map";
import "SuSEFirewall";

include "firewall/wizards.ycp";
include "firewall/summary.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);

/* Create a summary*/
if (func == "Summary") {
    ret = InitBoxSummary(SuSEFirewall::GetKnownFirewallZones());
}
/* Reset configuration */
else if (func == "Reset") {
    SuSEFirewall::Import($[]);
    ret = $[];
    SuSEFirewall::SetEnableService(SuSEFirewall::GetStartService());
}
/* Return required packages for module to operate */
else if (func == "Packages") {
    ret = $[];
}
/* Change configuration (run FirewallAutoSequence) */
else if (func == "Change") {
    ret = FirewallAutoSequence();
    SuSEFirewall::SetStartService(SuSEFirewall::GetEnableService());
}
/* Import configuration */
else if (func == "Import") {
    ret = SuSEFirewall::Import((map<string,any>) param);
}
/* Read firewall data */
else if (func == "Read") {
    ret = SuSEFirewall::Read();
    SuSEFirewall::SetEnableService(SuSEFirewall::GetStartService());
}
/* Return actual state */
else if (func == "Export") {
    ret = SuSEFirewall::Export();
}
/* Return actual state */
else if (func == "GetModified") {
    ret = SuSEFirewall::GetModified();
}
else if (func == "SetModified") {
    SuSEFirewall::SetModified();
    ret = true;
}
/* Write given settings */
else if (func == "Write") {
    import "Progress";
    Progress::off();
    ret = SuSEFirewall::Write();
    Progress::on();
}
/* Unknown function */
else {
    y2error("Unknown function: %1", func);
    ret = false;
}

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

return ret;

/* EOF */
}
