/**
 * File:	clients/proxy_auto.ycp
 * Package:	Network configuration
 * Summary:	Client for autoinstallation
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: proxy_auto.ycp 20958 2005-01-25 16:34:37Z mvidner $
 *
 * 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 proxy 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 ("proxy_auto", [ "Summary", mm ]);
 */

{

textdomain "network";

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

import "Proxy";
import "Wizard";
import "Summary";

include "network/services/proxy.ycp";

/**
 * Return a modification status
 * @return true if data was modified
 */
define boolean Modified() {
    return Proxy::modified;
}
define string ProxySummary() {
   string summary = "";
   string nc = Summary::NotConfigured ();
   summary = Summary::AddHeader(summary, _("Status of Proxy Configuration"));
   summary = Summary::AddLine(summary, Proxy::enabled ? _("Enabled") : nc );
   if (Proxy::http!="") {
    summary = Summary::AddHeader(summary, _("HTTP"));
    summary = Summary::AddLine(summary, Proxy::http  );
   }
   if (Proxy::ftp!="") {
    summary = Summary::AddHeader(summary, _("FTP"));
    summary = Summary::AddLine(summary, Proxy::ftp  );
   }
   return summary;
}

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 = ProxySummary();
}
/* Reset configuration */
else if (func == "Reset") {
    Proxy::Import($[]);
    ret = $[];
}
/* Change configuration (run AutoSequence) */
else if (func == "Change") {
    Wizard::CreateDialog();
    Wizard::SetDesktopIcon("proxy");
    ret = ProxyMainDialog(true);
    UI::CloseDialog();
}
/* return required package list */
else if (func == "Packages") {
    ret = $[];
}
/* Import configuration */
else if (func == "Import") {
    ret = Proxy::Import(param);
}
else if (func == "SetModified") {
    ret = Proxy::SetModified ();
}
else if (func == "GetModified") {
    ret = Proxy::GetModified ();
}
/* Return actual state */
else if (func == "Export") {
    ret = Proxy::Export();
}
/* Write givven settings */
else if (func == "Write") {
    import "Progress";
    boolean progress_orig = Progress::set (false);
    Proxy::write_only = true;
    ret = Proxy::Write();
    Progress::set (progress_orig);
}
/* Unknown function */
else {
    y2error("Unknown function: %1", func);
    ret = false;
}

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

return ret;

/* EOF */
}
