Re: openvpn plugin http-proxy support patch



patch clenup, no verbose, no standalone port import.
t.
Tomas Kovacik wrote:
Hi,

this is my first code after 8 years, I hope it's ok . Basically  it's only copy/paste :). Proxy auth is not implemented yet.

t.

_______________________________________________ NetworkManager-list mailing list NetworkManager-list gnome org http://mail.gnome.org/mailman/listinfo/networkmanager-list

diff -ru network-manager-openvpn-0.7~~svn20081015t024626.test/properties/auth-helpers.c network-manager-openvpn-0.7~~svn20081015t024626.proxy/properties/auth-helpers.c
--- network-manager-openvpn-0.7~~svn20081015t024626.test/properties/auth-helpers.c	2008-10-02 21:41:09.000000000 +0200
+++ network-manager-openvpn-0.7~~svn20081015t024626.proxy/properties/auth-helpers.c	2008-10-20 12:22:29.516180339 +0200
@@ -726,6 +726,10 @@
 	NM_OPENVPN_KEY_COMP_LZO,
 	NM_OPENVPN_KEY_TAP_DEV,
 	NM_OPENVPN_KEY_PROTO_TCP,
+	NM_OPENVPN_KEY_HTTP_PROXY,
+	NM_OPENVPN_KEY_HTTP_PROXY_PORT,
+	NM_OPENVPN_KEY_HTTP_PROXY_RETRY,
+	NM_OPENVPN_KEY_HTTP_PROXY_AUTH,
 	NM_OPENVPN_KEY_CIPHER,
 	NM_OPENVPN_KEY_TA_DIR,
 	NM_OPENVPN_KEY_TA,
@@ -773,6 +777,42 @@
 	gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
 }
 
+
+static void
+http_proxy_toggled_cb (GtkWidget *check, gpointer user_data)
+{
+        GladeXML *xml = (GladeXML *) user_data;
+        GtkWidget *widget;
+
+        widget = glade_xml_get_widget (xml, "http_proxy_entry");
+        gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+
+        widget = glade_xml_get_widget (xml, "http_proxy_port_entry");
+        gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+
+        /*
+        http-proxy
+        depend:
+                tcp
+        options:
+                proxy retry (--http-proxy-retry)
+                proxy authentication
+        */
+        widget = glade_xml_get_widget (xml, "tcp_checkbutton");
+        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check))) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+        gtk_widget_set_sensitive (widget, !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+        /*proxy auth*/
+	/* not implemented yet */
+	/*
+	widget = glade_xml_get_widget (xml, "http_proxy_auth_checkbutton");
+        gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+	*/
+        /*http-proxy-retry*/
+        widget = glade_xml_get_widget (xml, "http_proxy_retry_checkbutton");
+        gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+
+}
+
 static const char *
 nm_find_openvpn (void)
 {
@@ -905,7 +945,7 @@
 	GtkWidget *dialog = NULL;
 	char *glade_file = NULL;
 	GtkWidget *widget;
-	const char *value;
+	const char *value, *value2;
 
 	g_return_val_if_fail (hash != NULL, NULL);
 
@@ -925,6 +965,35 @@
 	                        xml, (GDestroyNotify) g_object_unref);
 	g_object_set_data (G_OBJECT (dialog), "connection-type", GINT_TO_POINTER (contype));
 
+        widget = glade_xml_get_widget (xml, "http_proxy_checkbutton");
+        g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (http_proxy_toggled_cb), xml);
+
+        value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_HTTP_PROXY);
+        value2 = g_hash_table_lookup (hash, NM_OPENVPN_KEY_HTTP_PROXY_PORT);
+        if (value && strlen (value) && value2 && strlen (value2)) {
+                        widget = glade_xml_get_widget (xml, "http_proxy_checkbutton");
+                        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+
+                        widget = glade_xml_get_widget (xml, "http_proxy_entry");
+			gtk_entry_set_text (GTK_ENTRY (widget), value);
+                	gtk_widget_set_sensitive (widget, TRUE);
+
+                        widget = glade_xml_get_widget (xml, "http_proxy_port_entry");
+                        gtk_entry_set_text (GTK_ENTRY (widget), value2);
+                        gtk_widget_set_sensitive (widget, TRUE);
+
+
+        } else {
+                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+
+                widget = glade_xml_get_widget (xml, "http_proxy_entry");
+                gtk_widget_set_sensitive (widget, FALSE);
+
+                widget = glade_xml_get_widget (xml, "http_proxy_port_entry");
+                gtk_widget_set_sensitive (widget, FALSE);
+
+        }
+
 	widget = glade_xml_get_widget (xml, "port_checkbutton");
 	g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (port_toggled_cb), xml);
 
@@ -1034,6 +1103,7 @@
 	GtkWidget *widget;
 	GladeXML *xml;
 	const char *contype = NULL;
+	const char *value, *value2;
 
 	g_return_val_if_fail (dialog != NULL, NULL);
 	if (error)
@@ -1053,6 +1123,45 @@
 		g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PORT), g_strdup_printf ("%d", port));
 	}
 
+       /* PROXY SUPPORT */
+
+        widget = glade_xml_get_widget (xml, "http_proxy_checkbutton");
+        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+
+                       widget = glade_xml_get_widget (xml, "http_proxy_entry");
+                       value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+                        widget = glade_xml_get_widget (xml, "http_proxy_port_entry");
+                        value2 = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+
+                       if (value && strlen (value) && value2 && strlen (value2)) {
+                                               g_hash_table_insert (hash,
+                                               g_strdup (NM_OPENVPN_KEY_HTTP_PROXY),
+                                               g_strdup (value));
+
+                                                g_hash_table_insert (hash,
+                                                g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_PORT),
+                                                g_strdup (value2));
+
+                       } else {
+                                                g_hash_table_insert (hash,
+                                                g_strdup (NM_OPENVPN_KEY_HTTP_PROXY),
+                                                g_strdup ("no"));
+                       }
+
+                       widget = glade_xml_get_widget (xml, "http_proxy_retry_checkbutton");
+                       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+                               g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_RETRY), g_strdup ("yes"));
+                       }
+
+			/* not implemented yet */
+                        /*
+			widget = glade_xml_get_widget (xml, "http_proxy_auth_checkbutton");
+                        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+                                g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_AUTH), g_strdup ("yes"));
+                        }
+                        */
+	}
+
 	widget = glade_xml_get_widget (xml, "lzo_checkbutton");
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
 		g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_COMP_LZO), g_strdup ("yes"));
diff -ru network-manager-openvpn-0.7~~svn20081015t024626.test/properties/import-export.c network-manager-openvpn-0.7~~svn20081015t024626.proxy/properties/import-export.c
--- network-manager-openvpn-0.7~~svn20081015t024626.test/properties/import-export.c	2008-08-19 13:59:36.000000000 +0200
+++ network-manager-openvpn-0.7~~svn20081015t024626.proxy/properties/import-export.c	2008-10-20 12:21:43.624094544 +0200
@@ -55,6 +55,8 @@
 #define SECRET_TAG "secret"
 #define AUTH_USER_PASS_TAG "auth-user-pass"
 #define TLS_AUTH_TAG "tls-auth"
+#define PROXY_TAG "http-proxy"
+#define PROXY_RETRY_TAG "http-retry-proxy"
 
 static gboolean
 handle_path_item (const char *line,
@@ -221,6 +223,48 @@
 			continue;
 		}
 
+                if (!strncmp (*line, PROXY_RETRY_TAG, strlen (PROXY_RETRY_TAG))) {
+                        g_hash_table_insert (s_vpn->data,
+                                             g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_RETRY),
+                                             g_strdup ("yes"));
+                        continue;
+                }
+
+
+                if (!strncmp (*line, PROXY_TAG, strlen (PROXY_TAG))) {
+                        items = get_args (*line + strlen (PROXY_TAG));
+                        if (!items)
+                                continue;
+
+                        if (g_strv_length (items) >= 1) {
+                                g_hash_table_insert (s_vpn->data,
+                                                     g_strdup (NM_OPENVPN_KEY_HTTP_PROXY),
+                                                     g_strdup (items[0]));
+                                if (g_strv_length (items) >= 2) {
+                                        glong port;
+
+                                        errno = 0;
+                                        port = strtol (items[1], NULL, 10);
+                                        if ((errno == 0) && (port > 0) && (port < 65536)) {
+                                                g_hash_table_insert (s_vpn->data,
+                                                                     g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_PORT),
+                                                                  // g_strdup (items[1]));
+                                                                     g_strdup_printf ("%d", (guint32) port));
+					if (g_strv_length (items) >= 3) {
+						g_hash_table_insert (s_vpn->data,
+			                                             g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_AUTH),
+                        			                     g_strdup ("yes"));
+						/*save http proxy usename/password*/
+					}
+                                        } else
+                                                g_warning ("%s: invalid http proxy port in option '%s'", __func__, *line);
+                                }
+                        }
+
+                        g_strfreev (items);
+                        continue;
+                }
+
 		if (!strncmp (*line, REMOTE_TAG, strlen (REMOTE_TAG))) {
 			items = get_args (*line + strlen (REMOTE_TAG));
 			if (!items)
diff -ru network-manager-openvpn-0.7~~svn20081015t024626.test/properties/nm-openvpn-dialog.glade network-manager-openvpn-0.7~~svn20081015t024626.proxy/properties/nm-openvpn-dialog.glade
--- network-manager-openvpn-0.7~~svn20081015t024626.test/properties/nm-openvpn-dialog.glade	2008-10-02 21:41:09.000000000 +0200
+++ network-manager-openvpn-0.7~~svn20081015t024626.proxy/properties/nm-openvpn-dialog.glade	2008-10-20 12:27:27.412662434 +0200
@@ -893,6 +893,169 @@
                     <property name="expand">False</property>
                   </packing>
                 </child>
+              <child>
+                <widget class="GtkHBox" id="hbox3">
+                  <property name="visible">True</property>
+                  <property name="homogeneous">False</property>
+                  <property name="spacing">6</property>
+
+                  <child>
+                    <widget class="GtkCheckButton" id="http_proxy_checkbutton">
+                      <property name="visible">True</property>
+                      <property name="can_focus">True</property>
+                      <property name="label" translatable="yes">Use _http proxy:</property>
+                      <property name="use_underline">True</property>
+                      <property name="relief">GTK_RELIEF_NORMAL</property>
+                      <property name="focus_on_click">True</property>
+                      <property name="active">False</property>
+                      <property name="inconsistent">False</property>
+                      <property name="draw_indicator">True</property>
+                    </widget>
+                    <packing>
+                      <property name="padding">0</property>
+                      <property name="expand">False</property>
+                      <property name="fill">True</property>
+                    </packing>
+                  </child>
+
+                  <child>
+                    <widget class="GtkEntry" id="http_proxy_entry">
+                      <property name="width_request">110</property>
+                      <property name="visible">True</property>
+                      <property name="can_focus">True</property>
+                      <property name="editable">True</property>
+                      <property name="visibility">True</property>
+                      <property name="max_length">0</property>
+                      <property name="text" translatable="yes"></property>
+                      <property name="has_frame">True</property>
+                      <property name="invisible_char">â??</property>
+                      <property name="activates_default">False</property>
+                    </widget>
+                    <packing>
+                      <property name="padding">0</property>
+                      <property name="expand">False</property>
+                      <property name="fill">False</property>
+                    </packing>
+                  </child>
+                  <child>
+                    <widget class="GtkLabel" id="label31">
+                      <property name="visible">True</property>
+                      <property name="label" translatable="yes">:</property>
+                      <property name="use_underline">True</property>
+                      <property name="use_markup">True</property>
+                      <property name="justify">GTK_JUSTIFY_LEFT</property>
+                      <property name="wrap">True</property>
+                      <property name="selectable">False</property>
+                      <property name="xalign">0</property>
+                      <property name="yalign">0.5</property>
+                      <property name="xpad">0</property>
+                      <property name="ypad">0</property>
+                      <property name="mnemonic_widget">http_proxy_port_entry</property>
+                      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                      <property name="width_chars">-1</property>
+                      <property name="single_line_mode">False</property>
+                      <property name="angle">0</property>
+                    </widget>
+                    <packing>
+                      <property name="padding">0</property>
+                      <property name="expand">False</property>
+                      <property name="fill">False</property>
+                    </packing>
+                  </child>
+
+                  <child>
+                    <widget class="GtkLabel" id="label31">
+                      <property name="visible">True</property>
+                      <property name="label" translatable="yes">:</property>
+                      <property name="use_underline">True</property>
+                      <property name="use_markup">True</property>
+                      <property name="justify">GTK_JUSTIFY_LEFT</property>
+                      <property name="wrap">True</property>
+                      <property name="selectable">False</property>
+                      <property name="xalign">0</property>
+                      <property name="yalign">0.5</property>
+                      <property name="xpad">0</property>
+                      <property name="ypad">0</property>
+                      <property name="mnemonic_widget">http_proxy_port_entry</property>
+                      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                      <property name="width_chars">-1</property>
+                      <property name="single_line_mode">False</property>
+                      <property name="angle">0</property>
+                    </widget>
+                    <packing>
+                      <property name="padding">0</property>
+                      <property name="expand">False</property>
+                      <property name="fill">False</property>
+                    </packing>
+                  </child>
+
+                  <child>
+                    <widget class="GtkEntry" id="http_proxy_port_entry">
+                      <property name="width_request">40</property>
+                      <property name="visible">True</property>
+                      <property name="can_focus">True</property>
+                      <property name="editable">True</property>
+                      <property name="visibility">True</property>
+                      <property name="max_length">4</property>
+                      <property name="text" translatable="yes"></property>
+                      <property name="has_frame">True</property>
+                      <property name="invisible_char">â??</property>
+                      <property name="activates_default">False</property>
+                    </widget>
+                    <packing>
+                      <property name="padding">0</property>
+                      <property name="expand">False</property>
+                      <property name="fill">True</property>
+                    </packing>
+                  </child>
+                </widget>
+                <packing>
+                  <property name="padding">0</property>
+                  <property name="expand">False</property>
+                  <property name="fill">True</property>
+                </packing>
+              </child>
+
+              <child>
+                <widget class="GtkCheckButton" id="http_proxy_retry_checkbutton">
+                  <property name="visible">True</property>
+                  <property name="sensitive">False</property>
+                  <property name="can_focus">True</property>
+                  <property name="label" translatable="yes">Use _http proxy retry</property>
+                  <property name="use_underline">True</property>
+                  <property name="relief">GTK_RELIEF_NORMAL</property>
+                  <property name="focus_on_click">True</property>
+                  <property name="active">True</property>
+                  <property name="inconsistent">False</property>
+                  <property name="draw_indicator">True</property>
+                </widget>
+                <packing>
+                  <property name="padding">0</property>
+                  <property name="expand">False</property>
+                  <property name="fill">False</property>
+                </packing>
+              </child>
+
+              <child>
+                <widget class="GtkCheckButton" id="http_proxy_auth_checkbutton">
+                  <property name="visible">True</property>
+                  <property name="sensitive">False</property>
+                  <property name="can_focus">True</property>
+                  <property name="label" translatable="yes">Use http proxy _authentication</property>
+                  <property name="use_underline">True</property>
+                  <property name="relief">GTK_RELIEF_NORMAL</property>
+                  <property name="focus_on_click">True</property>
+                  <property name="active">False</property>
+                  <property name="inconsistent">False</property>
+                  <property name="draw_indicator">True</property>
+                </widget>
+                <packing>
+                  <property name="padding">0</property>
+                  <property name="expand">False</property>
+                  <property name="fill">False</property>
+                </packing>
+              </child>
+		
                 <child>
                   <widget class="GtkCheckButton" id="lzo_checkbutton">
                     <property name="visible">True</property>
diff -ru network-manager-openvpn-0.7~~svn20081015t024626.test/src/nm-openvpn-service.c network-manager-openvpn-0.7~~svn20081015t024626.proxy/src/nm-openvpn-service.c
--- network-manager-openvpn-0.7~~svn20081015t024626.test/src/nm-openvpn-service.c	2008-10-20 12:32:30.212096301 +0200
+++ network-manager-openvpn-0.7~~svn20081015t024626.proxy/src/nm-openvpn-service.c	2008-10-20 12:32:45.268179127 +0200
@@ -103,6 +103,10 @@
 	{ NM_OPENVPN_KEY_PASSWORD,             G_TYPE_STRING, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_CERTPASS,             G_TYPE_STRING, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_NOSECRET,             G_TYPE_STRING, 0, 0, FALSE },
+	{ NM_OPENVPN_KEY_HTTP_PROXY,           G_TYPE_STRING, 0, 0, FALSE },
+	{ NM_OPENVPN_KEY_HTTP_PROXY_PORT,      G_TYPE_STRING, 0, 65535, FALSE },
+	{ NM_OPENVPN_KEY_HTTP_PROXY_RETRY,     G_TYPE_BOOLEAN, 0, 0, FALSE },
+	{ NM_OPENVPN_KEY_HTTP_PROXY_AUTH,      G_TYPE_BOOLEAN, 0, 0, FALSE },
 	{ NULL,                                G_TYPE_NONE, FALSE }
 };
 
@@ -549,7 +553,7 @@
                                  GError **error)
 {
 	NMOpenvpnPluginPrivate *priv = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin);
-	const char *openvpn_binary, *connection_type, *tmp;
+	const char *openvpn_binary, *connection_type, *tmp, *tmp2;
 	GPtrArray *args;
 	GSource *openvpn_watch;
 	GPid pid;
@@ -584,6 +588,19 @@
 		add_openvpn_arg (args, tmp);
 	}
 
+        tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_HTTP_PROXY);
+	tmp2 = g_hash_table_lookup (properties, NM_OPENVPN_KEY_HTTP_PROXY_PORT);
+        if (tmp && strlen (tmp) && tmp2 && strlen (tmp2)) {
+                add_openvpn_arg (args, "--http-proxy");
+                add_openvpn_arg (args, tmp);
+                add_openvpn_arg (args, tmp2);
+	}
+
+        tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_HTTP_PROXY_RETRY);
+	if (tmp && strlen (tmp)){
+                add_openvpn_arg (args, "--http-proxy-retry");
+        }
+
 	tmp = g_hash_table_lookup (properties, NM_OPENVPN_KEY_COMP_LZO);
 	if (tmp && !strcmp (tmp, "yes"))
 		add_openvpn_arg (args, "--comp-lzo");
diff -ru network-manager-openvpn-0.7~~svn20081015t024626.test/src/nm-openvpn-service.h network-manager-openvpn-0.7~~svn20081015t024626.proxy/src/nm-openvpn-service.h
--- network-manager-openvpn-0.7~~svn20081015t024626.test/src/nm-openvpn-service.h	2008-09-08 21:55:33.000000000 +0200
+++ network-manager-openvpn-0.7~~svn20081015t024626.proxy/src/nm-openvpn-service.h	2008-10-20 12:24:02.052095658 +0200
@@ -55,6 +55,10 @@
 #define NM_OPENVPN_KEY_TA "ta"
 #define NM_OPENVPN_KEY_TA_DIR "ta-dir"
 #define NM_OPENVPN_KEY_USERNAME "username"
+#define NM_OPENVPN_KEY_HTTP_PROXY "http-proxy"
+#define NM_OPENVPN_KEY_HTTP_PROXY_PORT "http-proxy-port"
+#define NM_OPENVPN_KEY_HTTP_PROXY_RETRY "http-proxy-retry"
+#define NM_OPENVPN_KEY_HTTP_PROXY_AUTH "http-proxy-auth"
 
 #define NM_OPENVPN_KEY_PASSWORD "password"
 #define NM_OPENVPN_KEY_CERTPASS "cert-pass"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]