Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moving HTTP proxy (client) configuration to a standalone package.

yast2-network is big enough already; yast2-proxy is independent of it

svn path=/trunk/proxy/; revision=67872
  • Loading branch information...
commit 955df507f806d732beae2df659308c3d9c385fed 0 parents
@mvidner mvidner authored
1  MAINTAINER
@@ -0,0 +1 @@
+Martin Vidner <mvidner@suse.cz>
23 Makefile.cvs
@@ -0,0 +1,23 @@
+#
+# Makefile.cvs
+#
+
+LIB = $(shell y2tool get-lib)
+
+PREFIX = /usr
+
+configure: all
+ ./configure --prefix=$(PREFIX) --libdir=$(PREFIX)/$(LIB)
+
+all:
+ y2tool y2autoconf
+ y2tool y2automake
+ autoreconf --force --install
+
+install: configure
+ make
+ make install
+
+reconf: all
+ ./config.status --recheck
+ ./config.status
1  RPMNAME
@@ -0,0 +1 @@
+yast2-proxy
1  VERSION
@@ -0,0 +1 @@
+2.22.0
8 config/Makefile.am
@@ -0,0 +1,8 @@
+desktop_DATA = proxy.desktop
+
+rncdir = $(schemadir)/autoyast/rnc
+rnc_DATA = proxy.rnc
+
+scrconf_DATA = $(wildcard *.scr)
+
+EXTRA_DIST = $(desktop_DATA) $(rnc_DATA) $(scrconf_DATA)
26 config/cfg_proxy.scr
@@ -0,0 +1,26 @@
+/**
+ * File: cfg_proxy.scr
+ * Summary: Agent for reading/writing /etc/sysconfig/proxy
+ * Author: Michal Svec <msvec@suse.cz>
+ * Access: read / write
+ *
+ * Example:
+ * Dir(.sysconfig.proxy)
+ * (["HTTP_PROXY"])
+ **
+ * Read(.sysconfig.proxy.HTTP_PROXY)
+ * ("yes")
+ **
+ * Write(.sysconfig.proxy.HTTP_PROXY, "ppp")
+ * (true)
+ *
+ * $Id$
+ *
+ * Read/Sets the values defined in <tt>/etc/sysconfig/proxy</tt>
+ * in an easy manner.
+ */
+.sysconfig.proxy
+
+`ag_ini(
+ `SysConfigFile("/etc/sysconfig/proxy")
+)
25 config/proxy.desktop
@@ -0,0 +1,25 @@
+[Desktop Entry]
+Type=Application
+Categories=Settings;System;Qt;X-SuSE-YaST;X-SuSE-YaST-Net_advanced;
+
+X-KDE-ModuleType=Library
+X-KDE-HasReadOnlyMode=true
+X-KDE-Library=yast2
+X-SuSE-YaST-Call=proxy
+
+X-SuSE-YaST-Group=Net_advanced
+X-SuSE-YaST-Argument=
+X-SuSE-YaST-RootOnly=true
+X-SuSE-YaST-AutoInst=all
+X-SuSE-YaST-Geometry=
+X-SuSE-YaST-SortKey=
+X-SuSE-YaST-AutoInstResource=proxy
+X-SuSE-YaST-AutoInstClonable=true
+X-SuSE-YaST-AutoInstSchema=proxy.rnc
+
+Icon=yast-proxy
+Exec=xdg-su -c "/sbin/yast2 proxy"
+
+Name=Proxy
+GenericName=Configure a proxy
+StartupNotify=true
13 config/proxy.rnc
@@ -0,0 +1,13 @@
+default namespace = "http://www.suse.com/1.0/yast2ns"
+namespace a = "http://relaxng.org/ns/compatibility/annotations/1.0"
+namespace config = "http://www.suse.com/1.0/configns"
+
+proxy = element proxy {
+ element enabled { BOOLEAN }? &
+ element ftp_proxy { text }? &
+ element http_proxy { text }? &
+ element https_proxy { text }? &
+ element no_proxy { text }? &
+ element proxy_password { text }? &
+ element proxy_user { text }?
+}
37 config/root_curlrc.scr
@@ -0,0 +1,37 @@
+/**
+ * File: root_curlrc.scr
+ * Summary: Agent for reading/writing /root/.curlrc
+ * Access: read / write
+ * Author: Michal Svec <msvec@suse.cz>
+ * See: wget(1)
+ *
+ * Example:
+ * Dir(.root.curlrc)
+ * (["proxy_user", "proxy_user"])
+ **
+ * Read(.root.curlrc.proxy_user)
+ * ("olduser")
+ **
+ * Write(.root.curlrc.proxy_user, "newuser")
+ * (true)
+ *
+ * $Id$
+ */
+.root.curlrc
+
+`ag_ini(
+ `IniAgent( "/root/.curlrc",
+ $[
+ "options" : [ "ignore_case", "global_values", "flat" ],
+ "comments" : [ "^#.*", "^[ \t]*$", ],
+ "params" : [
+ $[ "match" : [ "^[ \t]*([a-zA-Z_-]+)[ \t]* [ \t]*\"(.*)\"[ \t]*$", "%s \"%s\"" ] ],
+ $[ "match" : [ "^[ \t]*([a-zA-Z_-]+)[ \t]*=[ \t]*\"(.*)\"[ \t]*$", "%s = \"%s\"" ] ],
+ $[ "match" : [ "^[ \t]*([a-zA-Z_-]+)[ \t]*:[ \t]*\"(.*)\"[ \t]*$", "%s : \"%s\"" ] ],
+ $[ "match" : [ "^[ \t]*([a-zA-Z_-]+)[ \t]* [ \t]*(.*)[ \t]*$", "%s %s" ] ],
+ $[ "match" : [ "^[ \t]*([a-zA-Z_-]+)[ \t]*=[ \t]*(.*)[ \t]*$", "%s = %s" ] ],
+ $[ "match" : [ "^[ \t]*([a-zA-Z_-]+)[ \t]*:[ \t]*(.*)[ \t]*$", "%s : %s" ] ],
+ ]
+ ]
+ )
+)
32 config/root_wgetrc.scr
@@ -0,0 +1,32 @@
+/**
+ * File: root_wgetrc.scr
+ * Summary: Agent for reading/writing /root/.wgetrc
+ * Access: read / write
+ * Author: Michal Svec <msvec@suse.cz>
+ * See: wget(1)
+ *
+ * Example:
+ * Dir(.root.wgetrc)
+ * (["proxy_user", "proxy_user"])
+ **
+ * Read(.root.wgetrc.proxy_user)
+ * ("olduser")
+ **
+ * Write(.root.wgetrc.proxy_user, "newuser")
+ * (true)
+ *
+ * $Id$
+ */
+.root.wgetrc
+
+`ag_ini(
+ `IniAgent( "/root/.wgetrc",
+ $[
+ "options" : [ "ignore_case", "global_values", "flat" ],
+ "comments" : [ "^#.*", "^[ \t]*$", ],
+ "params" : [
+ $[ "match" : [ "^[ \t]*([a-zA-Z_]+)[ \t]*=[ \t]*(.*)[ \t]*$", "%s = %s" ] ]
+ ]
+ ]
+ )
+)
12 configure.in.in
@@ -0,0 +1,12 @@
+## YCP module configure.in.in
+
+## Initialize
+@YAST2-INIT-COMMON@
+@YAST2-INIT-YCP@
+
+## some common checks
+@YAST2-CHECKS-COMMON@
+@YAST2-CHECKS-YCP@
+
+## and generate the output...
+@YAST2-OUTPUT@
6 package/yast2-proxy.changes
@@ -0,0 +1,6 @@
+-------------------------------------------------------------------
+Tue Apr 10 14:49:56 CEST 2012 - mvidner@suse.cz
+
+- Split off yast2-network
+- 2.22.0
+
1  src/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = clients modules
2  src/clients/Makefile.am
@@ -0,0 +1,2 @@
+client_DATA = $(wildcard proxy*.ycp)
+EXTRA_DIST = $(client_DATA)
220 src/clients/proxy.ycp
@@ -0,0 +1,220 @@
+/**
+ * File: clients/proxy.ycp
+ * Package: Network configuration
+ * Summary: Proxy client
+ * Authors: Michal Svec <msvec@suse.cz>
+ *
+ * $Id$
+ *
+ * Main file for proxy configuration.
+ * Uses all other files.
+ */
+
+{
+
+textdomain "network";
+
+/* The main () */
+y2milestone("----------------------------------------");
+y2milestone("Proxy module started");
+
+import "CommandLine";
+import "Label";
+import "Proxy";
+import "Wizard";
+
+/**
+ * Return a modification status
+ * @return true if data was modified
+ */
+define boolean Modified() {
+ return Proxy::modified;
+}
+
+any ProxyGUI() {
+ include "network/runtime.ycp";
+ include "network/services/proxy.ycp";
+
+ Proxy::Read ();
+
+ Wizard::CreateDialog();
+ Wizard::SetDesktopTitleAndIcon("proxy");
+ Wizard::SetNextButton(`next, Label::FinishButton() );
+
+ /* main ui function */
+ any ret = ProxyMainDialog(true);
+ y2debug("ret == %1", ret);
+
+ if (ret == `next && Modified ())
+ Proxy::Write();
+
+ UI::CloseDialog();
+
+ return ret;
+}
+
+boolean EnableHandler (map<string, string> options)
+{
+ Proxy::enabled = true;
+ Proxy::modified = true;
+ return true;
+}
+
+boolean DisableHandler (map<string, string> options)
+{
+ Proxy::enabled = false;
+ Proxy::modified = true;
+ return true;
+}
+
+boolean SetHandler(map<string, string> options)
+{
+ boolean clear = haskey (options, "clear");
+
+ // TODO: maybe we should validate the values
+ foreach (string option, string value, options, {
+ switch (option) {
+ case "http" :
+ y2milestone ("Setting HTTP proxy to '%1'", clear ? "" : option);
+ Proxy::http = clear ? "" : value;
+ Proxy::modified = true;
+ break;
+ case "https" :
+ y2milestone ("Setting HTTPS proxy to '%1'", clear ? "" : option);
+ Proxy::https = clear ? "" : value;
+ Proxy::modified = true;
+ break;
+ case "ftp" :
+ y2milestone ("Setting FTP proxy to '%1'", clear ? "" : option);
+ Proxy::ftp = clear ? "" : value;
+ Proxy::modified = true;
+ break;
+ case "noproxy" :
+ y2milestone ("Setting NO proxy to '%1'", clear ? "" : option);
+ Proxy::no = clear ? "" : value;
+ Proxy::modified = true;
+ break;
+ }
+ });
+
+ return true;
+}
+
+boolean AuthHandler(map<string, string> options)
+{
+ if ( haskey (options, "clear") ) {
+ Proxy::user = "";
+ Proxy::pass = "";
+ }
+ else
+ {
+ Proxy::user = options["username"]:"";
+ Proxy::pass = options["password"]:nil;
+
+ if (Proxy::pass == nil)
+ {
+ // ask the user
+
+ // translators: command line prompt for entering a password
+ Proxy::pass = CommandLine::PasswordInput (_("Password:"));
+ }
+ }
+ return true;
+}
+
+boolean SummaryHandler (map<string, string> options)
+{
+ import "RichText";
+
+ CommandLine::Print (RichText::Rich2Plain (Proxy::Summary ()));
+ return true;
+}
+
+map cmdline = $[
+ /* Commandline help title */
+ "help" : _("Proxy Configuration"),
+ "id" : "proxy",
+ "guihandler": ProxyGUI,
+ "initialize": Proxy::Read,
+ "finish" : Proxy::Write,
+ "actions" : $[
+ "enable" : $[
+ /* command-line help */
+ "help" : _("Enable proxy settings"),
+ "handler" : EnableHandler,
+ ],
+ "disable" : $[
+ /* command-line help */
+ "help" : _("Disable proxy settings"),
+ "handler" : DisableHandler,
+ ],
+ "set" : $[
+ /* command-line help */
+ "help" : _("Change the current proxy settings"),
+ "handler" : SetHandler,
+ ],
+ "authentication" : $[
+ /* command-line help */
+ "help" : _("Set the authentication for proxy"),
+ "handler" : AuthHandler,
+ ],
+ "summary" : $[
+ /* command-line help */
+ "help" : _("Show the summary of the current settings"),
+ "handler" : SummaryHandler,
+ ],
+ ],
+ "options" : $[
+ "http": $[
+ /* command-line option help */
+ "help" : _("Set HTTP proxy"),
+ "type" : "string",
+ ],
+ "https" : $[
+ /* command-line option help */
+ "help" : _("Set HTTPS proxy"),
+ "type" : "string",
+ ],
+ "ftp" : $[
+ /* command-line option help */
+ "help" : _("Set FTP proxy"),
+ "type" : "string",
+ ],
+ "clear" : $[
+ /* command-line option help */
+ "help" : _("Clear all options listed"),
+ ],
+ "noproxy" : $[
+ /* command-line option help */
+ "help" : _("Set domains for not using the proxy settings"),
+ "type" : "string",
+ ],
+ "username" : $[
+ /* command-line option help */
+ "help" : _("The username to be used for proxy authentication"),
+ "type" : "string",
+ ],
+ "password" : $[
+ /* command-line option help */
+ "help" : _("The password to be used for proxy authentication"),
+ "type" : "string",
+ ],
+ ],
+ "mappings" : $[
+ "enable" : [],
+ "disable" : [],
+ "summary" : [],
+ "set" : [ "http", "https", "ftp", "noproxy", "clear" ],
+ "authentication" : [ "username", "password", "clear" ],
+ ],
+];
+
+any ret = CommandLine::Run(cmdline);
+
+/* Finish */
+y2milestone("Proxy module finished");
+y2milestone("----------------------------------------");
+return ret;
+
+/* EOF */
+}
134 src/clients/proxy_auto.ycp
@@ -0,0 +1,134 @@
+/**
+ * File: clients/proxy_auto.ycp
+ * Package: Network configuration
+ * Summary: Client for autoinstallation
+ * Authors: Michal Svec <msvec@suse.cz>
+ *
+ * $Id$
+ *
+ * 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::https!="") {
+ summary = Summary::AddHeader(summary, _("HTTPS"));
+ summary = Summary::AddLine(summary, Proxy::https );
+ }
+ 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::SetDesktopTitleAndIcon("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 ();
+}
+/* Read configuration (useful for cloning) */
+else if (func == "Read") {
+ ret = Proxy::Read();
+}
+/* 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 */
+}
100 src/clients/proxy_proposal.ycp
@@ -0,0 +1,100 @@
+/**
+ * File: clients/proxy_proposal.ycp
+ * Package: Configuration of proxy
+ * Summary: Proposal function dispatcher.
+ * Authors: Martin Vidner <mvidner@suse.cz>
+ * Michal Svec <msvec@suse.cz>
+ *
+ * $Id$
+ *
+ * Proposal function dispatcher for proxy configuration.
+ * See source/installation/proposal/proposal-API.txt
+ */
+
+{
+
+textdomain "network";
+
+/* The main () */
+y2milestone("----------------------------------------");
+y2milestone("Proxy proposal started");
+y2milestone("Arguments: %1", WFM::Args());
+
+import "Label";
+import "Proxy";
+import "Progress";
+import "Wizard";
+
+string func = (string) WFM::Args(0);
+map param = (map) WFM::Args(1);
+map ret = $[];
+
+/* create a textual proposal */
+if(func == "MakeProposal") {
+ string proposal = "";
+ string warning = nil;
+ symbol warning_level = nil;
+ boolean force_reset = param["force_reset"]:false;
+
+ if(force_reset || !Proxy::proposal_valid) {
+ Proxy::proposal_valid = true;
+ boolean progress_orig = Progress::set (false);
+ Proxy::Read();
+ Progress::set (progress_orig);
+ }
+ proposal = Proxy::Summary();
+
+ ret = $[
+ "preformatted_proposal" : proposal,
+ "warning_level" : warning_level,
+ "warning" : warning,
+ ];
+}
+/* run the module */
+else if(func == "AskUser") {
+
+ include "network/services/proxy.ycp";
+
+ map stored = Proxy::Export();
+
+ Wizard::CreateDialog();
+ Wizard::SetDesktopIcon("proxy");
+ Wizard::SetNextButton(`next, Label::FinishButton() );
+
+ /* main ui function */
+ symbol result =(symbol) ProxyMainDialog(true);
+
+ UI::CloseDialog();
+
+ if(result != `next) Proxy::Import(stored);
+ y2debug("stored=%1", stored);
+ y2debug("result=%1", result);
+ ret = $[ "workflow_sequence" : result ];
+}
+/* create titles */
+else if(func == "Description") {
+ ret = $[
+ /* Rich text title */
+ "rich_text_title" : _("Proxy"),
+ /* MenuButton title */
+ "menu_title" : _("&Proxy"),
+ "id" : "proxy",
+ ];
+}
+/* write the proposal */
+else if(func == "Write") {
+ Proxy::Write();
+}
+/* unknown function */
+else {
+ y2error("unknown function: %1", func);
+}
+
+/* Finish */
+y2debug("ret=%1",ret);
+y2milestone("Proxy proposal finished");
+y2milestone("----------------------------------------");
+return ret;
+
+/* EOF */
+}
5 src/modules/Makefile.am
@@ -0,0 +1,5 @@
+module_DATA = Proxy.ycp
+EXTRA_DIST = $(module_DATA)
+
+YCPCFLAGS =
+include $(top_srcdir)/Makefile.am.common
402 src/modules/Proxy.ycp
@@ -0,0 +1,402 @@
+/**
+ * File: modules/Proxy.ycp
+ * Package: Network configuration
+ * Summary: Proxy data
+ * Authors: Michal Svec <msvec@suse.cz>
+ *
+ * $Id$
+ *
+ * Configures FTP and HTTP proxies via sysconfig & SuSEconfig
+ * and /root/.curlrc (for YOU)
+ */
+
+{
+
+module "Proxy";
+textdomain "network";
+
+import "Summary";
+import "Progress";
+
+include "network/routines.ycp";
+include "network/runtime.ycp";
+
+global boolean proposal_valid = false;
+global boolean write_only = false;
+
+/**
+ * Data was modified?
+ */
+global boolean modified = false;
+
+global boolean enabled = false;
+global string http = "";
+global string https = "";
+global string ftp = "";
+global string no = "";
+global string user = "";
+global string pass = "";
+
+/**
+ * Display popup at the end of the proxy configuration
+ * @param modified true if proxy settings have been modified
+ */
+define void ProxyFinishPopup(boolean modified) ``{
+
+string text = _("It is recommended to relogin to make new proxy settings effective.");
+
+ FinishPopup(modified, "proxy", text, "", []);
+}
+
+/**
+ * Read settings
+ * @return true if success
+ */
+global define boolean Read() {
+
+ /* Read /etc/sysconfig/proxy */
+ http = (string) SCR::Read(.sysconfig.proxy.HTTP_PROXY);
+ if(http == nil) http = "";
+ https = (string) SCR::Read(.sysconfig.proxy.HTTPS_PROXY);
+ if(https == nil) https = "";
+ ftp = (string) SCR::Read(.sysconfig.proxy.FTP_PROXY);
+ if(ftp == nil) ftp = "";
+ no = (string) SCR::Read(.sysconfig.proxy.NO_PROXY);
+ if(no == nil) no = "";
+ enabled = (string) SCR::Read(.sysconfig.proxy.PROXY_ENABLED) != "no";
+
+ /* Read /root/.curlrc */
+ if(SCR::Read(.target.size, "/root/.curlrc") > 0)
+ user = (string) SCR::Read (add (.root.curlrc, "--proxy-user"));
+
+ if(user == nil) user = "";
+
+ if(issubstring(user, ":")) {
+ pass = regexpsub(user, "^.*:(.*)$", "\\1");
+ user = regexpsub(user, "^(.*):.*$", "\\1");
+ }
+
+ if(pass == nil) pass = "";
+ if(user == nil)
+ user = "";
+ else {
+ if ( regexpmatch(user, "^.*\\\\.*$"))
+ user = regexpsub(user, "^(.*)\\\\(.*)$", "\\1\\2");
+ }
+
+ /* Read /root/.wgetrc */
+ /* YOU uses curl(1)
+ user = SCR::Read(.root.wgetrc.proxy_user);
+ if(user == nil) user = "";
+ pass = SCR::Read(.root.wgetrc.proxy_passwd);
+ if(pass == nil) pass = "";
+ */
+
+ return true;
+}
+
+/**
+ * Write routing settings and apply changes
+ * @return true if success
+ */
+global define boolean Write() {
+
+ y2milestone("Writing configuration");
+ if(!modified) {
+ y2milestone("No changes to proxy configuration -> nothing to write");
+ return true;
+ }
+
+ list <string> steps = [
+ _("Update proxy configuration"),
+ ];
+
+ string caption = _("Saving Proxy Configuration");
+ // sleep for longer time, so that progress does not disappear right afterwards
+ // but only when Progress is visible
+ integer sl = (Progress::status() == true ? 500 : 0);
+
+ Progress::New(caption, " ", size(steps), steps, [], "");
+
+ ProgressNextStage(_("Updating proxy configuration..."));
+
+ /* Update /etc/sysconfig/proxy */
+ SCR::Write(.sysconfig.proxy.PROXY_ENABLED, enabled?"yes":"no");
+ SCR::Write(.sysconfig.proxy.HTTP_PROXY, http);
+ SCR::Write(.sysconfig.proxy.HTTPS_PROXY, https);
+ SCR::Write(.sysconfig.proxy.FTP_PROXY, ftp);
+ SCR::Write(.sysconfig.proxy.NO_PROXY, no);
+ SCR::Write(.sysconfig.proxy, nil);
+
+ // proxy is used, write /root/.curlrc
+ // bugzilla #305163
+ if (enabled) {
+ /* Update /root/.curlrc */
+ string proxyuser = nil;
+ if (user != "") {
+ //Escape backslash characters in .curlrc (#331038)
+ user = mergestring (splitstring(user, "\\"), "\\\\");
+ proxyuser = user;
+ if (pass != "") proxyuser = user + ":" + pass;
+ }
+
+ // nil or real value
+ SCR::Write (add (.root.curlrc, "--proxy-user"), proxyuser);
+
+ // not 'nil', not empty
+ // bugzilla #305163
+ if (http != nil && size (http) > 0) {
+ SCR::Write (add (.root.curlrc, "--proxy"), http);
+ } else {
+ SCR::Write (add (.root.curlrc, "--proxy"), nil);
+ }
+
+ // only written value can have a comment
+ if (proxyuser != nil) {
+ SCR::Write (add (add (.root.curlrc, "--proxy-user"), "comment"), ChangedComment("proxy"));
+ // only when set, can have a comment
+ } else if (http != nil && size (http) > 0) {
+ SCR::Write (add (add (.root.curlrc, "--proxy"), "comment"), ChangedComment("proxy"));
+ }
+ // proxy is not used, remove proxy-related settings
+ } else {
+ SCR::Write (add (.root.curlrc, "--proxy-user"), nil);
+ SCR::Write (add (.root.curlrc, "--proxy"), nil);
+ }
+
+ SCR::Write(.root.curlrc, nil);
+ sleep(sl);
+ Progress::NextStage();
+
+ //user can't relogin in installation and update, do not show the msg then (bnc#486037, bnc#543469)
+ if (Mode::normal())
+ ProxyFinishPopup(true);
+
+ /* Update /root/.wgetrc */
+ /* YOU uses curl(1)
+ SCR::Write(.root.wgetrc.proxy_user, user);
+ SCR::Write(.root.wgetrc.proxy_passwd, pass);
+ SCR::Write(.root.wgetrc, nil); */
+
+ modified = false;
+
+ return true;
+}
+
+
+/**
+ * Get all settings from a map.
+ * When called by <name>_auto (preparing autoinstallation data)
+ * the map may be empty.
+ * @param settings autoinstallation settings
+ * @return true if success
+ */
+global define boolean Import(map settings) {
+ enabled = settings["enabled"]:false;
+ http = settings["http_proxy"]:"";
+ https = settings["https_proxy"]:"";
+ ftp = settings["ftp_proxy"]:"";
+ no = settings["no_proxy"]:"localhost";
+ user = settings["proxy_user"]:"";
+ pass = settings["proxy_password"]:"";
+
+ modified = true;
+ return true;
+}
+
+/**
+ * Runs tests of the HTTP and FTP proxy
+ *
+ * @param string http_proxy such as "http://cache.example.com:3128"
+ * @param string https_proxy such as "http://cache.example.com:3128"
+ * @param string ftp_proxy such as "http://cache.example.com:3128"
+ * @param string proxy_user such as "proxy-username"
+ * @param string proxy_password such as "proxy-password"
+ *
+ * @return map <string, map <string, any> > with results of the test
+ * @struct return = $[
+ * "HTTP" : $[
+ * "exit" : _exit_code,
+ * "stdout" : _stdout,
+ * "stderr" : _stderr,
+ * ],
+ * "HTTPS" : $[
+ * "exit" : _exit_code,
+ * "stdout" : _stdout,
+ * "stderr" : _stderr,
+ * ],
+ * "FTP" : $[
+ * "exit" : _exit_code,
+ * "stdout" : _stdout,
+ * "stderr" : _stderr,
+ * ],
+ * ]
+ */
+global define map <string, map <string, any> > RunTestProxy (string http_proxy, string https_proxy, string ftp_proxy, string proxy_user, string proxy_password) {
+ // /usr/bin/curl --verbose
+ // --proxy http://server_name:port_number
+ // --proxy-user user:password
+ // --url http://www.novell.com or ftp://ftp.novell.com | suggested for HTTP or FTP test
+ // --url https://secure-www.novell.com --insecure
+ map <string, map <string, any> > ret = $[];
+
+ boolean test_http = ((http_proxy != "" && http_proxy != "http://") ? true:false);
+ boolean test_https = ((https_proxy != "" && https_proxy != "http://") ? true:false);
+ boolean test_ftp = ((ftp_proxy != "" && ftp_proxy != "http://") ? true:false);
+
+ http_proxy = mergestring (splitstring(http_proxy, "\""), "\\\"");
+ https_proxy = mergestring (splitstring(https_proxy, "\""), "\\\"");
+ ftp_proxy = mergestring (splitstring(ftp_proxy, "\""), "\\\"");
+ proxy_user = mergestring (splitstring(proxy_user, "\""), "\\\"");
+ //escape also '\' character - usernames such as domain\user are causing pain to .target.bash_output
+ //and to curl - #256360
+ proxy_user = mergestring (splitstring(proxy_user, "\\"), "\\\\");
+ proxy_password = mergestring (splitstring(proxy_password, "\""), "\\\"");
+
+ // enclose user:password into quotes, it may contain special characters (#338264)
+ string user_pass = (proxy_user != "" ?
+ " --proxy-user '" + proxy_user + (proxy_password != "" ?
+ ":" + proxy_password
+ :
+ "") + "'"
+ :
+ "");
+
+ // timeout for the connection
+ integer timeout_sec = 90;
+ // %1 = http or ftp proxy, %2 = user:password if any, %3 = URL
+ string command = "curl --verbose --proxy %1 %2 --connect-timeout %3 --url %4";
+ string http_command = sformat(command, http_proxy, user_pass, timeout_sec, "http://www.novell.com");
+ // adding option --insecure to accept the certificate without asking
+ string https_command = sformat(command, https_proxy, user_pass, timeout_sec, "https://secure-www.novell.com --insecure");
+ string ftp_command = sformat(command, ftp_proxy, user_pass, timeout_sec, "ftp://ftp.novell.com");
+
+ y2milestone("Running HTTP_PROXY test...");
+ if (test_http) {
+ y2milestone("Testing HTTP proxy %1", http_proxy);
+ ret["HTTP"] = (map <string, any>) SCR::Execute(.target.bash_output, http_command);
+ } else {
+ y2milestone("Skipping HTTP Proxy test, no proxy used.");
+ ret["HTTP"] = $["exit":0, "stderr":"", "stdout":"", "tested":false];
+ }
+ y2milestone("Done.");
+
+ y2milestone("Running HTTPS_PROXY test...");
+ if (test_https) {
+ y2milestone("Testing HTTPS proxy %1", https_proxy);
+ ret["HTTPS"] = (map <string, any>) SCR::Execute(.target.bash_output, https_command);
+ } else {
+ y2milestone("Skipping HTTPS Proxy test, no proxy used.");
+ ret["HTTPS"] = $["exit":0, "stderr":"", "stdout":"", "tested":false];
+ }
+ y2milestone("Done.");
+
+ y2milestone("Running FTP_PROXY test...");
+ if (test_ftp) {
+ y2milestone("Testing FTP proxy %1", ftp_proxy);
+ ret["FTP"] = (map <string, any>) SCR::Execute(.target.bash_output, ftp_command);
+ } else {
+ y2milestone("Skipping FTP Proxy test, no proxy used.");
+ ret["FTP"] = $["exit":0, "stderr":"", "stdout":"", "tested":false];
+ }
+ y2milestone("Done.");
+
+ return ret;
+}
+
+/**
+ * Dump the Routing settings to a map, for autoinstallation use.
+ * @return autoinstallation settings
+ */
+global define map Export() {
+ map settings = $[
+ "enabled" : enabled,
+ "http_proxy" : http,
+ "https_proxy" : https,
+ "ftp_proxy" : ftp,
+ "no_proxy" : no,
+ "proxy_user" : user,
+ "proxy_password": pass,
+ ];
+ return settings;
+}
+
+/**
+ * Create proxy summary
+ * @return summary text
+ */
+global define string Summary() {
+
+ list<string> ret = [];
+
+ /* Summary text */
+ if(!enabled) ret = [ Summary::Device(_("Proxy is disabled."), "") ];
+
+ else {
+
+ /* Summary text */
+ ret = [ Summary::Device(_("Proxy is enabled."), "" +
+ /* Summary text */
+ (http != "" ? sformat(_("HTTP Proxy: %1"), http) + "<br>" : "" ) +
+ /* Summary text */
+ (https != "" ? sformat(_("HTTPS Proxy: %1"), https) + "<br>" : "" ) +
+ /* Summary text */
+ (ftp != "" ? sformat(_("FTP Proxy: %1"), ftp) + "<br>" : "" ) +
+
+ "" )];
+
+ /* Summary text * /
+ Summary::Device(sformat(_("No Proxy Domains: %1"), no) + "\n<br>" +
+ "<p>" + ( user == "" ?
+ /* Summary text * /
+ _("Proxy user name is not set.") :
+ /* Summary text * /
+ sformat(_("Proxy User Name: %1"), user)) +
+ "<br>" + ( pass == "" ?
+ /* Summary text * /
+ _("Proxy password is not set.") :
+ /* Summary text * /
+ _("Proxy password is set.")) ];
+ */
+ }
+
+ return Summary::DevicesList(ret);
+}
+
+/**
+ * Function which returns if the settings were modified
+ * @return boolean settings were modified
+ */
+global define boolean GetModified () {
+ return modified;
+}
+/**
+ * Function sets internal variable, which indicates, that any
+ * settings were modified, to "true"
+ */
+global define void SetModified () {
+ modified = true;
+}
+
+/**
+ * Function returns an environment usable for curl. The proxy user/password
+ * are read from /root/.curlrc.
+ */
+global define map <string, string> GetEnvironment ()
+{
+ if (!enabled)
+ return $[];
+
+ if (!modified)
+ Read ();
+
+ return $[
+ "http_proxy" : http,
+ "HTTPS_PROXY" : https,
+ "FTP_PROXY" : ftp,
+ "NO_PROXY" : no
+ ];
+}
+
+/* EOF */
+}
21 testsuite/Makefile.am
@@ -0,0 +1,21 @@
+#
+# Makefile.am for .../testsuite
+#
+# Do not edit this file (Makefile.am) as it will be overwritten!
+#
+
+AUTOMAKE_OPTIONS = dejagnu
+EXTRA_DIST = $(wildcard tests/*.out) $(wildcard tests/*.err) $(wildcard tests/*.ycp) $(wildcard tests/*.yh)
+
+testsuite_prepare = @ydatadir@/testsuite/Makefile.testsuite
+
+all-local: $(testsuite_prepare)
+ make -f $(testsuite_prepare) RPMNAME=$(RPMNAME) srcdir=$(srcdir)
+
+clean-local: $(testsuite_prepare)
+ make -f $(testsuite_prepare) RPMNAME=$(RPMNAME) srcdir=$(srcdir) clean
+
+check-local: $(testsuite_prepare)
+ make -f $(testsuite_prepare) RPMNAME=$(RPMNAME) srcdir=$(srcdir) check
+
+# EOF
0  testsuite/tests/Proxy.err
No changes.
14 testsuite/tests/Proxy.out
@@ -0,0 +1,14 @@
+Read .target.tmpdir "/tmp"
+Dump Read
+Read .sysconfig.proxy.HTTP_PROXY "h"
+Read .sysconfig.proxy.HTTPS_PROXY "h"
+Read .sysconfig.proxy.FTP_PROXY "f"
+Read .sysconfig.proxy.NO_PROXY nil
+Read .sysconfig.proxy.PROXY_ENABLED nil
+Read .target.size "/root/.curlrc" 1
+Read .root.curlrc."--proxy-user" "user:pass"
+Return true
+Dump Write
+Dump Import
+Dump Export
+Return $["enabled":true, "ftp_proxy":"f", "http_proxy":"h", "https_proxy":"h", "no_proxy":"", "proxy_password":"pass", "proxy_user":"user"]
99 testsuite/tests/Proxy.ycp
@@ -0,0 +1,99 @@
+{
+
+include "testsuite.ycp";
+
+map READ = $[
+ "root" : $[
+ "curlrc" : $[
+ "--proxy-user" : "user:pass",
+ ],
+ ],
+ "sysconfig" : $[
+ "proxy" : $[
+ "PROXY_ENABLED" : nil,
+ "HTTP_PROXY" : "h",
+ "HTTPS_PROXY" : "h",
+ "FTP_PROXY" : "f",
+ ],
+ "language" : $[
+ "RC_LANG" : "",
+ "DEFAULT_LANGUAGE" : "",
+ "ROOT_USES_LANG" : "no",
+ ],
+ "console" : $[
+ "CONSOLE_ENCODING" : "UTF-8",
+ ],
+ ],
+ "probe" : $[
+ "system" : [],
+ ],
+ "target" : $[
+ "size" : 1,
+ "tmpdir" : "/tmp",
+ ],
+ "product" : $[
+ "features" : $[
+ "USE_DESKTOP_SCHEDULER" : "0",
+ "ENABLE_AUTOLOGIN" : "0",
+ "EVMS_CONFIG" : "0",
+ "IO_SCHEDULER" : "cfg",
+ "UI_MODE" : "expert",
+ ],
+ ],
+];
+
+map EXEC = $["target": $["bash_output": $[] ] ];
+
+TESTSUITE_INIT([READ, $[], EXEC], nil);
+
+import "Proxy";
+import "Progress";
+Progress::off();
+
+DUMP("Read");
+TEST(``(Proxy::Read()), [READ], nil);
+
+DUMP("Write");
+//TEST(``(Proxy::Write()), [], nil);
+
+map lan_settings = $[
+ "dns" : $[
+ "dhcp_hostname" : false,
+ "domain" : "suse.com",
+ "hostname" : "nashif",
+ "nameservers" : ["10.0.0.1"],
+ "searchlist" : ["suse.com"]
+ ],
+ "interfaces" : [
+ $[
+ "STARTMODE" : "onboot",
+ "BOOTPROTO" : "static",
+ "BROADCAST" : "10.10.1.255",
+ "IPADDR" : "10.10.1.1",
+ "NETMASK" : "255.255.255.0",
+ "NETWORK" : "10.10.1.0",
+ "UNIQUE" : "",
+ "device" : "eth0",
+ "module" : "",
+ "options" : ""
+ ]
+ ],
+ "routing" : $[
+ "routes":[
+ $[
+ "destination" : "default",
+ "device" : "",
+ "gateway" : "10.10.0.8",
+ "netmask" : "0.0.0.0"
+ ]],
+ "ip_forwarding":false
+ ]
+];
+
+DUMP("Import");
+//TEST(``(Proxy::Import(lan_settings)), [], nil);
+
+DUMP("Export");
+TEST(``(Proxy::Export()), [], nil);
+
+}
40 yast2-proxy.spec.in
@@ -0,0 +1,40 @@
+@HEADER-COMMENT@
+
+@HEADER@
+Group: System/YaST
+License: GPL v2 or later
+# should be required by devtools
+BuildRequires: pkgconfig perl-XML-Writer rpm
+BuildRequires: update-desktop-files
+BuildRequires: yast2-devtools yast2-testsuite
+
+BuildRequires: yast2
+Requires: yast2
+
+PreReq: /bin/rm
+
+Summary: YaST2 - Proxy Configuration
+
+%description
+This package contains the YaST2 component for proxy configuration.
+
+@PREP@
+
+@BUILD@
+
+@INSTALL@
+
+@CLEAN@
+
+%files
+%defattr(-,root,root)
+@clientdir@/*.ycp
+@moduledir@/*.ycp
+@moduledir@/*.ybc
+@desktopdir@/*.desktop
+@scrconfdir@/*.scr
+@schemadir@/autoyast/rnc/proxy.rnc
+
+%dir @docdir@
+@docdir@/COPYING
+%readme @docdir@/README
Please sign in to comment.
Something went wrong with that request. Please try again.