mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-06 17:30:35 +01:00
* Generalised properties dialog for other possible PPPd uses
* Abstracted somewhat - may be a useful base of other configuration
dialogs as it now simply needs the glade file and a few declarations.
* Added a dial-up option though the backend doesn't yet support that.
* Added many PPPD options including those for compression and encryption
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1804 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
b02830f9b7
commit
93b722d574
18 changed files with 3118 additions and 1248 deletions
|
|
@ -1,14 +1,27 @@
|
|||
|
||||
|
||||
lib_LTLIBRARIES = libnm-pptp-properties.la
|
||||
lib_LTLIBRARIES = libnm-ppp-properties.la
|
||||
|
||||
libnm_pptp_properties_la_SOURCES = \
|
||||
nm-pptp.c
|
||||
libnm_ppp_properties_la_SOURCES = \
|
||||
nm-ppp-properties.c \
|
||||
vpnui_impl.c \
|
||||
vpnui_expand.c \
|
||||
vpnui_opt.c \
|
||||
vpnui_validate.c \
|
||||
vpnui_variant.c \
|
||||
util_lists.c \
|
||||
vpnui_impl.h \
|
||||
vpnui_opt.h \
|
||||
vpnui_expand.h \
|
||||
vpnui_validate.h \
|
||||
vpnui_variant.h \
|
||||
util_lists.h \
|
||||
vpnui_impl.h
|
||||
|
||||
gladedir = $(datadir)/gnome-vpn-properties/pptp
|
||||
glade_DATA = nm-pptp-dialog.glade
|
||||
gladedir = $(datadir)/gnome-vpn-properties/ppp
|
||||
glade_DATA = nm-ppp-dialog.glade
|
||||
|
||||
libnm_pptp_properties_la_CFLAGS = \
|
||||
libnm_ppp_properties_la_CFLAGS = \
|
||||
$(GLADE_CFLAGS) \
|
||||
$(GTK_CFLAGS) \
|
||||
$(GCONF_CFLAGS) \
|
||||
|
|
@ -18,10 +31,10 @@ libnm_pptp_properties_la_CFLAGS = \
|
|||
-DG_DISABLE_DEPRECATED \
|
||||
-DGDK_DISABLE_DEPRECATED \
|
||||
-DGNOME_DISABLE_DEPRECATED \
|
||||
-DGNOMELOCALEDIR=\"$(datadir)/locale\" \
|
||||
-DGNOMELOCALEDIR=\"$(datadir)/locale\" \
|
||||
-DVERSION=\"$(VERSION)\"
|
||||
|
||||
libnm_pptp_properties_la_LIBADD = \
|
||||
libnm_ppp_properties_la_LIBADD = \
|
||||
$(GLADE_LIBS) \
|
||||
$(GTK_LIBS) \
|
||||
$(GCONF_LIBS) \
|
||||
|
|
|
|||
1360
vpn-daemons/pptp/properties/nm-ppp-dialog.glade
Normal file
1360
vpn-daemons/pptp/properties/nm-ppp-dialog.glade
Normal file
File diff suppressed because it is too large
Load diff
229
vpn-daemons/pptp/properties/nm-ppp-properties.c
Normal file
229
vpn-daemons/pptp/properties/nm-ppp-properties.c
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
/***************************************************************************
|
||||
* CVSID: $Id$
|
||||
*
|
||||
* nm-pptp.c : GNOME UI dialogs for configuring PPTP connections
|
||||
*
|
||||
* Copyright (C) 2005 Antony Mee <eemynotna@gmail.com>
|
||||
* Based on work by Tim Niemueller <tim@niemueller.de>
|
||||
* and David Zeuthen, <davidz@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#define NMVPNUI_PPTP_PROPERTIES_C
|
||||
|
||||
#include "vpnui_impl.h"
|
||||
#include "vpnui_opt.h"
|
||||
#include "vpnui_expand.h"
|
||||
#include "vpnui_validate.h"
|
||||
#include "vpnui_variant.h"
|
||||
#include "util_lists.h"
|
||||
|
||||
#include "nm-ppp-properties.h"
|
||||
|
||||
const char *GLADE_FILE="nm-ppp-dialog.glade";
|
||||
const char *GLADE_WIDGET="nm-ppp-widget";
|
||||
|
||||
void
|
||||
impl_setup (NetworkManagerVpnUIImpl *impl)
|
||||
{
|
||||
GSList *item;
|
||||
VpnUIConfigOption *opt;
|
||||
VpnUIVariant *variant;
|
||||
VpnUIExpander *expand;
|
||||
g_return_if_fail(impl!=NULL);
|
||||
|
||||
impl->display_name = VPNUI_DISPLAY_NAME;
|
||||
impl->service_name = VPNUI_SERVICE_NAME;
|
||||
// GLADE NAME TYPE
|
||||
// GCONF_NAME EXPORT_NAME DESCRIPTION(for summary)
|
||||
// VALIDATOR_Fn
|
||||
opt = vpnui_opt_new(
|
||||
"connection-name", VPN_UI_OPTTYPE_STRING,
|
||||
NULL, "Description", _("Name"),
|
||||
GTK_SIGNAL_FUNC(&editable_changed), &vld_non_empty, impl );
|
||||
impl->connection_name_opt = opt;
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"ppp-connection-type", VPN_UI_OPTTYPE_COMBO,
|
||||
"ppp-connection-type", "Connection-Type", NULL,
|
||||
GTK_SIGNAL_FUNC(&variant_changed), NULL, impl );
|
||||
impl->variant_combo = GTK_COMBO_BOX(opt->widget);
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"pptp-remote", VPN_UI_OPTTYPE_STRING,
|
||||
"pptp-remote", "PPTP-Server", _("PPTP Server"),
|
||||
GTK_SIGNAL_FUNC(&editable_changed), &vld_non_empty, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"phone-number", VPN_UI_OPTTYPE_STRING,
|
||||
"phone-number", "Telephone-Number", _("Telephone Number"),
|
||||
GTK_SIGNAL_FUNC(&editable_changed), &vld_non_empty, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"usepeerdns" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"usepeerdns", "Use-Peer-DNS", _("Use Peer DNS"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"encrypt-mppe" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"encrypt-mppe", "Encrypt-MPPE", _("Use MPPE encryption"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"compress-mppc" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"compress-mppc", "Compress-MPPC", _("Use MPPC compression"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"compress-deflate" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"compress-deflate", "Compress-Deflate", _("Do not use deflate compression"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"compress-bsd" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"compress-bsd", "Compress-BSD", _("Do not use BSD compression"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"ppp-lock" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"ppp-lock", "PPP-Lock", _("Exclusive device access by pppd"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"ppp-auth-peer" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"ppp-auth-peer", "Auth-Peer", _("Authenticate remote peer"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"mtu" , VPN_UI_OPTTYPE_SPINNER ,
|
||||
"mtu", "MTU", _("Maximum transmit unit (in bytes)"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"mru" , VPN_UI_OPTTYPE_SPINNER ,
|
||||
"mru", "MRU", _("Maximum receive unit (in bytes)"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"lcp-echo-failure" , VPN_UI_OPTTYPE_SPINNER ,
|
||||
"lcp-echo-failure", "LCP-Echo-Failure", _("Number of failed LCP echos to cause disconnect"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"lcp-echo-interval" , VPN_UI_OPTTYPE_SPINNER ,
|
||||
"lcp-echo-interval", "LCP-Echo-Interval", _("Interval (in seconds) at which to issue LCP echos"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"ppp-debug" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"ppp-debug", NULL, NULL,
|
||||
NULL, NULL, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"usepeerdns-overtunnel" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"usepeerdns-overtunnel", "Peer-DNS-Over-Tunnel", _("Use Peer DNS over the Tunnel"),
|
||||
NULL, NULL, impl );
|
||||
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"routes" , VPN_UI_OPTTYPE_STRING ,
|
||||
"routes", "X-NM-Routes", _("Specific networks available"),
|
||||
GTK_SIGNAL_FUNC(&editable_changed), &vld_routes_if_sens, impl );
|
||||
|
||||
opt = vpnui_opt_new(
|
||||
"use-routes" , VPN_UI_OPTTYPE_YESNO ,
|
||||
"use-routes", "Use-Routes", _("Limit to specific networks"),
|
||||
GTK_SIGNAL_FUNC(&use_routes_toggled), NULL, impl );
|
||||
|
||||
variant = vpnui_variant_new( "pptp","Windows VPN (PPTP)",
|
||||
VPNUI_BASIC_DEFAULTS VPNUI_PPTP_DEFAULTS,
|
||||
impl);
|
||||
variant = vpnui_variant_new( "dialup", "Dialup",
|
||||
VPNUI_BASIC_DEFAULTS VPNUI_DIALUP_DEFAULTS,
|
||||
impl);
|
||||
//
|
||||
// GLADE NAME IMPLEMENTATION_OBJ
|
||||
expand= vpnui_expand_new ("routing-expander",impl);
|
||||
expand= vpnui_expand_new ("dialup-expander",impl);
|
||||
expand= vpnui_expand_new ("pppd-expander",impl);
|
||||
expand= vpnui_expand_new ("pptp-expander",impl);
|
||||
|
||||
// Attach an import_button
|
||||
impl->w_import_button = GTK_BUTTON (glade_xml_get_widget (impl->xml,
|
||||
"import-button"));
|
||||
}
|
||||
|
||||
void
|
||||
use_routes_toggled (GtkToggleButton *togglebutton, gpointer user_data)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data;
|
||||
VpnUIConfigOption *opt = impl_opt_byglade(impl,"routes");
|
||||
|
||||
if (opt!=NULL) gtk_widget_set_sensitive (GTK_WIDGET (opt->widget),
|
||||
gtk_toggle_button_get_active (togglebutton));
|
||||
|
||||
if (impl->callback != NULL) {
|
||||
gboolean is_valid;
|
||||
|
||||
is_valid = impl_is_valid (&(impl->parent));
|
||||
impl->callback (&(impl->parent), is_valid, impl->callback_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
editable_changed (GtkEditable *editable, gpointer user_data)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data;
|
||||
|
||||
if (impl->callback != NULL) {
|
||||
gboolean is_valid;
|
||||
|
||||
is_valid = impl_is_valid (&(impl->parent));
|
||||
impl->callback (&(impl->parent), is_valid, impl->callback_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
variant_changed (GtkComboBox *combo, gpointer user_data)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data;
|
||||
char *variant_name;
|
||||
|
||||
|
||||
variant_name=gtk_combo_box_get_active_text(combo);
|
||||
|
||||
vpnui_variant_select_byname(impl,variant_name);
|
||||
|
||||
vpnui_expand_reset_all(impl);
|
||||
|
||||
if (impl->callback != NULL) {
|
||||
gboolean is_valid;
|
||||
|
||||
is_valid = impl_is_valid (&(impl->parent));
|
||||
impl->callback (&(impl->parent), is_valid, impl->callback_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
vpn-daemons/pptp/properties/nm-ppp-properties.h
Normal file
34
vpn-daemons/pptp/properties/nm-ppp-properties.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#define VPNUI_ROUTES_WIDGET "routes"
|
||||
#define VPNUI_ROUTES_TOGGLE_WIDGET "use-routes"
|
||||
#define VPNUI_DISPLAY_NAME _("PPPD Tunnel Client")
|
||||
#define VPNUI_SERVICE_NAME "org.freedesktop.NetworkManager.ppp_starter"
|
||||
#define VPNUI_BASIC_DEFAULTS "connection-name='';" \
|
||||
"ppp-debug=no;" \
|
||||
"usepeerdns=yes;" \
|
||||
"usepeerdns-overtunnel=yes;" \
|
||||
"encrypt-mppe=yes;" \
|
||||
"compress-mppc=no;" \
|
||||
"ppp-lock=yes;" \
|
||||
"ppp-auth-peer=no;" \
|
||||
"compress-bsd=no;" \
|
||||
"compress-deflate=no;" \
|
||||
"mru=1000;" \
|
||||
"mtu=1000;" \
|
||||
"lcp-echo-failure=10;" \
|
||||
"lcp-echo-interval=10;" \
|
||||
"use-routes=no;" \
|
||||
"routes=;" \
|
||||
"ppp-debug=no;"
|
||||
#define VPNUI_PPTP_DEFAULTS "pptp-remote='';" \
|
||||
"ppp-connection-type=pptp;"
|
||||
#define VPNUI_DIALUP_DEFAULTS "phone-number=THIS DOESN'T DO ANYTHING;" \
|
||||
"ppp-connection-type=dialup;"
|
||||
|
||||
#ifdef NMVPNUI_PPTP_PROPERTIES_C
|
||||
#endif
|
||||
|
||||
void impl_setup (NetworkManagerVpnUIImpl *impl);
|
||||
void use_routes_toggled (GtkToggleButton *togglebutton, gpointer user_data);
|
||||
void editable_changed (GtkEditable *editable, gpointer user_data);
|
||||
void variant_changed (GtkComboBox *combo, gpointer user_data);
|
||||
|
||||
|
|
@ -1,522 +0,0 @@
|
|||
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
|
||||
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
|
||||
|
||||
<glade-interface>
|
||||
<requires lib="gnome"/>
|
||||
|
||||
<widget class="GtkWindow" id="nm-pptp-widget-window">
|
||||
<property name="title" translatable="yes"></property>
|
||||
<property name="type">GTK_WINDOW_TOPLEVEL</property>
|
||||
<property name="window_position">GTK_WIN_POS_NONE</property>
|
||||
<property name="modal">False</property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="destroy_with_parent">False</property>
|
||||
<property name="decorated">True</property>
|
||||
<property name="skip_taskbar_hint">False</property>
|
||||
<property name="skip_pager_hint">False</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
|
||||
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="nm-pptp-widget">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">12</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Please enter the information provided by your system administrator below. Do not enter your password here as you will be prompted when connecting.</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</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>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox11">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">18</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">6</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><b>Connection Name</b></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">True</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</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>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment2">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xscale">1</property>
|
||||
<property name="yscale">1</property>
|
||||
<property name="top_padding">0</property>
|
||||
<property name="bottom_padding">0</property>
|
||||
<property name="left_padding">12</property>
|
||||
<property name="right_padding">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox3">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">6</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label4">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Name used to identify the connection to the private network, e.g. "Campus VPN" or "Corporate Network"</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_markup">False</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>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkEntry" id="pptp-connection-name">
|
||||
<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>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</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="GtkVBox" id="vbox9">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">6</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label28">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><b>Required Information</b></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">True</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</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>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment3">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xscale">1</property>
|
||||
<property name="yscale">1</property>
|
||||
<property name="top_padding">0</property>
|
||||
<property name="bottom_padding">0</property>
|
||||
<property name="left_padding">12</property>
|
||||
<property name="right_padding">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox10">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">6</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox17">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">12</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="nm-pptp-label-gateway">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Gateway:</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="mnemonic_widget">pptp-remote</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="pptp-remote">
|
||||
<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">True</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>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</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="GtkExpander" id="pptp-optional-information-expander">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="expanded">True</property>
|
||||
<property name="spacing">6</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment4">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xscale">1</property>
|
||||
<property name="yscale">1</property>
|
||||
<property name="top_padding">0</property>
|
||||
<property name="bottom_padding">0</property>
|
||||
<property name="left_padding">12</property>
|
||||
<property name="right_padding">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox6">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">6</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="pptp-use-routes">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">_Only use VPN connection for these addresses</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="GtkAlignment" id="alignment5">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xscale">1</property>
|
||||
<property name="yscale">1</property>
|
||||
<property name="top_padding">0</property>
|
||||
<property name="bottom_padding">0</property>
|
||||
<property name="left_padding">12</property>
|
||||
<property name="right_padding">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox7">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">6</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label26">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><i>example: 172.16.0.0/16 10.11.12.0/24</i></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">True</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</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>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkEntry" id="pptp-routes">
|
||||
<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">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</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="pptp-use-mppc">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Use MPPC compression</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="pptp-use-mppe">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Require MPPE encryption</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>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHButtonBox" id="hbuttonbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="layout_style">GTK_BUTTONBOX_END</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkButton" id="pptp-import-button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment1">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xscale">0</property>
|
||||
<property name="yscale">0</property>
|
||||
<property name="top_padding">0</property>
|
||||
<property name="bottom_padding">0</property>
|
||||
<property name="left_padding">0</property>
|
||||
<property name="right_padding">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox7">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">2</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-add</property>
|
||||
<property name="icon_size">4</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">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="label15">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Import Saved Configuration...</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</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">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
</glade-interface>
|
||||
|
|
@ -1,718 +0,0 @@
|
|||
/***************************************************************************
|
||||
* CVSID: $Id$
|
||||
*
|
||||
* nm-pptp.c : GNOME UI dialogs for configuring PPTP connections
|
||||
*
|
||||
* Copyright (C) 2005 Antony Mee <eemynotna@gmail.com>
|
||||
* Based on work by Tim Niemueller <tim@niemueller.de>
|
||||
* and David Zeuthen, <davidz@redhat.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#define NM_VPN_API_SUBJECT_TO_CHANGE
|
||||
|
||||
#include <NetworkManager/nm-vpn-ui-interface.h>
|
||||
|
||||
typedef struct _NetworkManagerVpnUIImpl NetworkManagerVpnUIImpl;
|
||||
|
||||
|
||||
struct _NetworkManagerVpnUIImpl {
|
||||
NetworkManagerVpnUI parent;
|
||||
|
||||
NetworkManagerVpnUIDialogValidityCallback callback;
|
||||
gpointer callback_user_data;
|
||||
|
||||
GladeXML *xml;
|
||||
|
||||
GtkWidget *widget;
|
||||
|
||||
GtkEntry *w_connection_name;
|
||||
GtkEntry *w_remote;
|
||||
GtkCheckButton *w_use_routes;
|
||||
GtkEntry *w_routes;
|
||||
GtkCheckButton *w_use_mppe;
|
||||
GtkCheckButton *w_use_mppc;
|
||||
GtkExpander *w_opt_info_expander;
|
||||
GtkButton *w_import_button;
|
||||
};
|
||||
|
||||
static void
|
||||
pptp_clear_widget (NetworkManagerVpnUIImpl *impl)
|
||||
{
|
||||
gtk_entry_set_text (impl->w_connection_name, "");
|
||||
gtk_entry_set_text (impl->w_remote, "");
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), FALSE);
|
||||
gtk_entry_set_text (impl->w_routes, "");
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_routes), FALSE);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe), TRUE);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc), TRUE);
|
||||
gtk_expander_set_expanded (impl->w_opt_info_expander, FALSE);
|
||||
}
|
||||
|
||||
static const char *
|
||||
impl_get_display_name (NetworkManagerVpnUI *self)
|
||||
{
|
||||
return _("PPTP Client");
|
||||
}
|
||||
|
||||
static const char *
|
||||
impl_get_service_name (NetworkManagerVpnUI *self)
|
||||
{
|
||||
return "org.freedesktop.NetworkManager.pptp";
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
impl_get_widget (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name)
|
||||
{
|
||||
GSList *i;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
gboolean should_expand;
|
||||
|
||||
pptp_clear_widget (impl);
|
||||
|
||||
should_expand = FALSE;
|
||||
|
||||
if (connection_name != NULL)
|
||||
gtk_entry_set_text (impl->w_connection_name, connection_name);
|
||||
|
||||
for (i = properties; i != NULL && g_slist_next (i) != NULL; i = g_slist_next (g_slist_next (i))) {
|
||||
const char *key;
|
||||
const char *value;
|
||||
|
||||
key = i->data;
|
||||
value = (g_slist_next (i))->data;
|
||||
|
||||
if (strcmp (key, "remote") == 0) {
|
||||
gtk_entry_set_text (impl->w_remote, value);
|
||||
} else if ( (strcmp (key, "comp-mppc") == 0) &&
|
||||
(strcmp (value, "yes")) ) {
|
||||
//gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc), TRUE);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), TRUE);
|
||||
should_expand = TRUE;
|
||||
} else if ( (strcmp (key, "comp-mppe") == 0) &&
|
||||
(strcmp (value, "yes")) ) {
|
||||
//gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe), TRUE);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), TRUE);
|
||||
should_expand = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (routes != NULL) {
|
||||
GString *route_str;
|
||||
char *str;
|
||||
|
||||
route_str = g_string_new ("");
|
||||
for (i = routes; i != NULL; i = g_slist_next (i)) {
|
||||
const char *route;
|
||||
|
||||
if (i != routes)
|
||||
g_string_append_c(route_str, ' ');
|
||||
|
||||
route = (const char *) i->data;
|
||||
g_string_append(route_str, route);
|
||||
}
|
||||
|
||||
str = g_string_free (route_str, FALSE);
|
||||
gtk_entry_set_text (impl->w_routes, str);
|
||||
g_free (str);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), TRUE);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_routes), TRUE);
|
||||
|
||||
should_expand = TRUE;
|
||||
}
|
||||
|
||||
gtk_expander_set_expanded (impl->w_opt_info_expander, should_expand);
|
||||
gtk_container_resize_children (GTK_CONTAINER (impl->widget));
|
||||
|
||||
return impl->widget;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
impl_get_properties (NetworkManagerVpnUI *self)
|
||||
{
|
||||
GSList *data;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
const char *connectionname;
|
||||
const char *remote;
|
||||
gboolean use_mppc;
|
||||
gboolean use_mppe;
|
||||
|
||||
connectionname = gtk_entry_get_text (impl->w_connection_name);
|
||||
remote = gtk_entry_get_text (impl->w_remote);
|
||||
use_mppc = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc));
|
||||
use_mppe = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe));
|
||||
|
||||
data = NULL;
|
||||
data = g_slist_append (data, g_strdup ("remote"));
|
||||
data = g_slist_append (data, g_strdup (remote));
|
||||
data = g_slist_append (data, g_strdup ("comp-mppc"));
|
||||
data = g_slist_append (data, use_mppc ? g_strdup ("yes") : g_strdup("no"));
|
||||
data = g_slist_append (data, g_strdup ("encrypt-mppe"));
|
||||
data = g_slist_append (data, use_mppe ? g_strdup ("yes") : g_strdup("no"));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
get_routes (NetworkManagerVpnUIImpl *impl)
|
||||
{
|
||||
GSList *routes;
|
||||
const char *routes_entry;
|
||||
gboolean use_routes;
|
||||
char **substrs;
|
||||
unsigned int i;
|
||||
|
||||
routes = NULL;
|
||||
|
||||
routes_entry = gtk_entry_get_text (impl->w_routes);
|
||||
use_routes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_routes));
|
||||
|
||||
if (!use_routes)
|
||||
goto out;
|
||||
|
||||
substrs = g_strsplit (routes_entry, " ", 0);
|
||||
for (i = 0; substrs[i] != NULL; i++) {
|
||||
char *route;
|
||||
|
||||
route = substrs[i];
|
||||
if (strlen (route) > 0)
|
||||
routes = g_slist_append (routes, g_strdup (route));
|
||||
}
|
||||
|
||||
g_strfreev (substrs);
|
||||
|
||||
out:
|
||||
return routes;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
impl_get_routes (NetworkManagerVpnUI *self)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
return get_routes (impl);
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
impl_get_connection_name (NetworkManagerVpnUI *self)
|
||||
{
|
||||
const char *name;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
name = gtk_entry_get_text (impl->w_connection_name);
|
||||
if (name != NULL)
|
||||
return g_strdup (name);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
impl_is_valid (NetworkManagerVpnUI *self)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
gboolean is_valid;
|
||||
const char *connectionname;
|
||||
const char *remote;
|
||||
gboolean use_routes;
|
||||
const char *routes_entry;
|
||||
|
||||
|
||||
is_valid = FALSE;
|
||||
|
||||
connectionname = gtk_entry_get_text (impl->w_connection_name);
|
||||
remote = gtk_entry_get_text (impl->w_remote);
|
||||
use_routes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_routes));
|
||||
routes_entry = gtk_entry_get_text (impl->w_routes);
|
||||
|
||||
/* initial sanity checking */
|
||||
if (strlen (connectionname) > 0 &&
|
||||
strlen (remote) > 0 &&
|
||||
((!use_routes) || (use_routes && strlen (routes_entry) > 0)) ) {
|
||||
is_valid = TRUE;
|
||||
}
|
||||
|
||||
/* validate gateway: can be a hostname or an IP; do not allow spaces or tabs */
|
||||
if (is_valid &&
|
||||
( (strstr (remote, " ") != NULL) ||
|
||||
(strstr (remote, "\t") != NULL) )
|
||||
) {
|
||||
is_valid = FALSE;
|
||||
}
|
||||
|
||||
/* validate routes: each entry must be of the form 'a.b.c.d/mask' */
|
||||
if (is_valid) {
|
||||
GSList *i;
|
||||
GSList *routes;
|
||||
|
||||
routes = get_routes (impl);
|
||||
|
||||
for (i = routes; i != NULL; i = g_slist_next (i)) {
|
||||
int d1, d2, d3, d4, mask;
|
||||
|
||||
const char *route = (const char *) i->data;
|
||||
//printf ("route = '%s'\n", route);
|
||||
|
||||
if (sscanf (route, "%d.%d.%d.%d/%d", &d1, &d2, &d3, &d4, &mask) != 5) {
|
||||
is_valid = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: this can be improved a bit */
|
||||
if (d1 < 0 || d1 > 255 ||
|
||||
d2 < 0 || d2 > 255 ||
|
||||
d3 < 0 || d3 > 255 ||
|
||||
d4 < 0 || d4 > 255 ||
|
||||
mask < 0 || mask > 32) {
|
||||
is_valid = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
//if (routes != NULL)
|
||||
// printf ("\n");
|
||||
|
||||
if (routes != NULL) {
|
||||
g_slist_foreach (routes, (GFunc)g_free, NULL);
|
||||
g_slist_free (routes);
|
||||
}
|
||||
}
|
||||
|
||||
return is_valid;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
use_routes_toggled (GtkToggleButton *togglebutton, gpointer user_data)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data;
|
||||
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_routes),
|
||||
gtk_toggle_button_get_active (togglebutton));
|
||||
|
||||
if (impl->callback != NULL) {
|
||||
gboolean is_valid;
|
||||
|
||||
is_valid = impl_is_valid (&(impl->parent));
|
||||
impl->callback (&(impl->parent), is_valid, impl->callback_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
editable_changed (GtkEditable *editable, gpointer user_data)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data;
|
||||
|
||||
if (impl->callback != NULL) {
|
||||
gboolean is_valid;
|
||||
|
||||
is_valid = impl_is_valid (&(impl->parent));
|
||||
impl->callback (&(impl->parent), is_valid, impl->callback_user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
impl_set_validity_changed_callback (NetworkManagerVpnUI *self,
|
||||
NetworkManagerVpnUIDialogValidityCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
impl->callback = callback;
|
||||
impl->callback_user_data = user_data;
|
||||
}
|
||||
|
||||
static void
|
||||
impl_get_confirmation_details (NetworkManagerVpnUI *self, gchar **retval)
|
||||
{
|
||||
GString *buf;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
const char *connectionname;
|
||||
const char *remote;
|
||||
gboolean use_routes;
|
||||
const char *routes;
|
||||
gboolean use_mppe;
|
||||
gboolean use_mppc;
|
||||
|
||||
connectionname = gtk_entry_get_text (impl->w_connection_name);
|
||||
remote = gtk_entry_get_text (impl->w_remote);
|
||||
use_routes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_routes));
|
||||
routes = gtk_entry_get_text (impl->w_routes);
|
||||
use_mppe = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe));
|
||||
use_mppc = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc));
|
||||
|
||||
|
||||
// This is risky, should be variable length depending on actual data!
|
||||
buf = g_string_sized_new (512);
|
||||
|
||||
g_string_append (buf, _("The following PPTP connection will be created:"));
|
||||
g_string_append (buf, "\n\n\t");
|
||||
g_string_append_printf (buf, _("Name: %s"), connectionname);
|
||||
g_string_append (buf, "\n\n\t");
|
||||
|
||||
g_string_append_printf (buf, _("Remote: %s"), remote);
|
||||
g_string_append (buf, "\n\t");
|
||||
|
||||
if (use_routes) {
|
||||
g_string_append (buf, "\n\t");
|
||||
g_string_append_printf (buf, _("Routes: %s"), routes);
|
||||
}
|
||||
|
||||
g_string_append (buf, "\n\t");
|
||||
g_string_append_printf( buf, _("Use MPPC Compression: %s"), ((use_mppc) ? _("Yes") : _("No")));
|
||||
g_string_append (buf, "\n\t");
|
||||
g_string_append_printf( buf, _("Use MPPE Encryption: %s"), ((use_mppe) ? _("Yes") : _("No")));
|
||||
|
||||
g_string_append (buf, "\n\n");
|
||||
g_string_append (buf, _("The connection details can be changed using the \"Edit\" button."));
|
||||
g_string_append (buf, "\n");
|
||||
|
||||
*retval = g_string_free (buf, FALSE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
import_from_file (NetworkManagerVpnUIImpl *impl, const char *path)
|
||||
{
|
||||
char *basename;
|
||||
GKeyFile *keyfile;
|
||||
gboolean file_is_good;
|
||||
|
||||
file_is_good = FALSE;
|
||||
basename = g_path_get_basename (path);
|
||||
|
||||
keyfile = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (keyfile, path, 0, NULL)) {
|
||||
char *connectionname = NULL;
|
||||
char *remote = NULL;
|
||||
char *routes = NULL;
|
||||
char *mppc = NULL;
|
||||
char *mppe = NULL;
|
||||
gboolean should_expand;
|
||||
|
||||
connectionname = g_key_file_get_string (keyfile, "main", "Description", NULL);
|
||||
remote = g_key_file_get_string (keyfile, "main", "Remote", NULL);
|
||||
mppc = g_key_file_get_string (keyfile, "main", "Comp-MPPC", NULL);
|
||||
mppe = g_key_file_get_string (keyfile, "main", "Encrypt-MPPE", NULL);
|
||||
|
||||
/* may not exist */
|
||||
if ((routes = g_key_file_get_string (keyfile, "main", "X-NM-Routes", NULL)) == NULL)
|
||||
routes = g_strdup ("");
|
||||
|
||||
/* sanity check data */
|
||||
if ( ( connectionname != NULL) &&
|
||||
( remote != NULL ) &&
|
||||
(strlen(connectionname) > 0) &&
|
||||
(strlen(remote) > 0) ) {
|
||||
|
||||
gtk_entry_set_text (impl->w_connection_name, connectionname);
|
||||
gtk_entry_set_text (impl->w_remote, remote);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppc), ((mppc != NULL) && (strcmp(mppc, "yes") == 0)));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_mppe), ((mppe != NULL) && (strcmp(mppe, "yes") == 0)));
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl->w_use_routes), strlen (routes) > 0);
|
||||
gtk_entry_set_text (impl->w_routes, routes);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (impl->w_routes), strlen (routes) > 0);
|
||||
|
||||
should_expand = (strlen (routes) > 0) ||
|
||||
((mppc != NULL) && (strcmp(mppc, "yes") == 0)) ||
|
||||
((mppe != NULL) && (strcmp(mppe, "yes") == 0));
|
||||
gtk_expander_set_expanded (impl->w_opt_info_expander, should_expand);
|
||||
|
||||
} else {
|
||||
g_free (connectionname);
|
||||
g_free (remote);
|
||||
g_free (mppe);
|
||||
g_free (mppc);
|
||||
}
|
||||
g_key_file_free (keyfile);
|
||||
|
||||
if (!file_is_good) {
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (NULL,
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_WARNING,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
_("Cannot import settings"));
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
_("The VPN settings file '%s' does not contain valid data."), basename);
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (basename);
|
||||
|
||||
return file_is_good;
|
||||
}
|
||||
|
||||
static void
|
||||
import_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
char *filename = NULL;
|
||||
GtkWidget *dialog;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new (_("Select file to import"),
|
||||
NULL,
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
|
||||
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
/*printf ("User selected '%s'\n", filename);*/
|
||||
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
if (filename != NULL) {
|
||||
import_from_file (impl, filename);
|
||||
g_free (filename);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
impl_can_export (NetworkManagerVpnUI *self)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
impl_import_file (NetworkManagerVpnUI *self, const char *path)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
return import_from_file (impl, path);
|
||||
}
|
||||
|
||||
static void
|
||||
export_to_file (NetworkManagerVpnUIImpl *impl, const char *path,
|
||||
GSList *properties, GSList *routes, const char *connection_name)
|
||||
{
|
||||
FILE *f;
|
||||
GSList *i;
|
||||
const char *remote = NULL;
|
||||
const char *mppc = NULL;
|
||||
const char *mppe = NULL;
|
||||
char *routes_str = NULL;
|
||||
|
||||
/*printf ("in export_to_file; path='%s'\n", path);*/
|
||||
|
||||
for (i = properties; i != NULL && g_slist_next (i) != NULL; i = g_slist_next (g_slist_next (i))) {
|
||||
const char *key;
|
||||
const char *value;
|
||||
|
||||
key = i->data;
|
||||
value = (g_slist_next (i))->data;
|
||||
|
||||
if (strcmp (key, "remote") == 0) {
|
||||
remote = value;
|
||||
} else if (strcmp (key, "comp-mppc") == 0) {
|
||||
mppc = value;
|
||||
} else if (strcmp (key, "encrypt-mppe") == 0) {
|
||||
mppe = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (routes != NULL) {
|
||||
GString *str;
|
||||
|
||||
str = g_string_new ("X-NM-Routes=");
|
||||
for (i = routes; i != NULL; i = g_slist_next (i)) {
|
||||
const char *route;
|
||||
|
||||
if (i != routes)
|
||||
g_string_append_c (str, ' ');
|
||||
|
||||
route = (const char *) i->data;
|
||||
g_string_append (str, route);
|
||||
}
|
||||
|
||||
g_string_append_c (str, '\n');
|
||||
|
||||
routes_str = g_string_free (str, FALSE);
|
||||
}
|
||||
|
||||
f = fopen (path, "w");
|
||||
if (f != NULL) {
|
||||
|
||||
fprintf (f,
|
||||
"[main]\n"
|
||||
"Description=%s\n"
|
||||
"Remote=%s\n"
|
||||
"Comp-MPPC=%s\n"
|
||||
"Encrypt-MPPE=%s\n"
|
||||
"%s",
|
||||
/* Description */ connection_name,
|
||||
/* Host */ remote,
|
||||
/* Comp-MPPC */ mppc,
|
||||
/* Comp-MPPE */ mppe,
|
||||
/* X-NM-Routes */ routes_str != NULL ? routes_str : "");
|
||||
|
||||
fclose (f);
|
||||
}
|
||||
g_free (routes_str);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
impl_export (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name)
|
||||
{
|
||||
char *suggested_name;
|
||||
char *path = NULL;
|
||||
GtkWidget *dialog;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
/*printf ("in impl_export\n");*/
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new (_("Save as..."),
|
||||
NULL,
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
suggested_name = g_strdup_printf ("%s.pcf", connection_name);
|
||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), suggested_name);
|
||||
g_free (suggested_name);
|
||||
|
||||
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
|
||||
path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
/*printf ("User selected '%s'\n", path);*/
|
||||
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
if (path != NULL) {
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
|
||||
int response;
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (NULL,
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_QUESTION,
|
||||
GTK_BUTTONS_CANCEL,
|
||||
_("A file named \"%s\" already exists."), path);
|
||||
gtk_dialog_add_buttons (GTK_DIALOG (dialog), "_Replace", GTK_RESPONSE_OK, NULL);
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
_("Do you want to replace it with the one you are saving?"));
|
||||
response = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
gtk_widget_destroy (dialog);
|
||||
if (response == GTK_RESPONSE_OK)
|
||||
export_to_file (impl, path, properties, routes, connection_name);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (path);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static NetworkManagerVpnUI*
|
||||
impl_get_object (void)
|
||||
{
|
||||
char *glade_file;
|
||||
NetworkManagerVpnUIImpl *impl;
|
||||
|
||||
impl = g_new0 (NetworkManagerVpnUIImpl, 1);
|
||||
|
||||
glade_file = g_strdup_printf ("%s/%s", GLADEDIR, "nm-pptp-dialog.glade");
|
||||
impl->xml = glade_xml_new (glade_file, NULL, GETTEXT_PACKAGE);
|
||||
g_free( glade_file );
|
||||
if (impl->xml != NULL) {
|
||||
|
||||
impl->widget = glade_xml_get_widget(impl->xml, "nm-pptp-widget");
|
||||
|
||||
impl->w_connection_name = GTK_ENTRY (glade_xml_get_widget (impl->xml, "pptp-connection-name"));
|
||||
impl->w_remote = GTK_ENTRY (glade_xml_get_widget (impl->xml, "pptp-remote"));
|
||||
impl->w_use_routes = GTK_CHECK_BUTTON (glade_xml_get_widget (impl->xml, "pptp-use-routes"));
|
||||
impl->w_routes = GTK_ENTRY (glade_xml_get_widget (impl->xml, "pptp-routes"));
|
||||
impl->w_opt_info_expander = GTK_EXPANDER (glade_xml_get_widget (impl->xml,
|
||||
"pptp-optional-information-expander"));
|
||||
impl->w_import_button = GTK_BUTTON (glade_xml_get_widget (impl->xml,
|
||||
"pptp-import-button"));
|
||||
|
||||
|
||||
impl->w_use_mppc = GTK_CHECK_BUTTON (glade_xml_get_widget (impl->xml, "pptp-use-mppc"));
|
||||
impl->w_use_mppe = GTK_CHECK_BUTTON (glade_xml_get_widget (impl->xml, "pptp-use-mppe"));
|
||||
|
||||
impl->callback = NULL;
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (impl->w_use_routes),
|
||||
"toggled", GTK_SIGNAL_FUNC (use_routes_toggled), impl);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (impl->w_connection_name),
|
||||
"changed", GTK_SIGNAL_FUNC (editable_changed), impl);
|
||||
gtk_signal_connect (GTK_OBJECT (impl->w_remote),
|
||||
"changed", GTK_SIGNAL_FUNC (editable_changed), impl);
|
||||
gtk_signal_connect (GTK_OBJECT (impl->w_routes),
|
||||
"changed", GTK_SIGNAL_FUNC (editable_changed), impl);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (impl->w_import_button),
|
||||
"clicked", GTK_SIGNAL_FUNC (import_button_clicked), impl);
|
||||
|
||||
/* make the widget reusable */
|
||||
gtk_signal_connect (GTK_OBJECT (impl->widget), "delete-event",
|
||||
GTK_SIGNAL_FUNC (gtk_widget_hide_on_delete), NULL);
|
||||
|
||||
pptp_clear_widget (impl);
|
||||
|
||||
impl->parent.get_display_name = impl_get_display_name;
|
||||
impl->parent.get_service_name = impl_get_service_name;
|
||||
impl->parent.get_widget = impl_get_widget;
|
||||
impl->parent.get_connection_name = impl_get_connection_name;
|
||||
impl->parent.get_properties = impl_get_properties;
|
||||
impl->parent.get_routes = impl_get_routes;
|
||||
impl->parent.set_validity_changed_callback = impl_set_validity_changed_callback;
|
||||
impl->parent.is_valid = impl_is_valid;
|
||||
impl->parent.get_confirmation_details = impl_get_confirmation_details;
|
||||
impl->parent.can_export = impl_can_export;
|
||||
impl->parent.import_file = impl_import_file;
|
||||
impl->parent.export = impl_export;
|
||||
impl->parent.data = impl;
|
||||
|
||||
return &(impl->parent);
|
||||
} else {
|
||||
g_free (impl);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
NetworkManagerVpnUI*
|
||||
nm_vpn_properties_factory (void)
|
||||
{
|
||||
return impl_get_object();
|
||||
}
|
||||
42
vpn-daemons/pptp/properties/util_lists.c
Normal file
42
vpn-daemons/pptp/properties/util_lists.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NMVPNUI_UTIL_LISTS_C
|
||||
#include "util_lists.h"
|
||||
|
||||
GSList *
|
||||
list_from_string (const char *string)
|
||||
{
|
||||
char **entries;
|
||||
char **parts;
|
||||
char **entry;
|
||||
char **part;
|
||||
int i;
|
||||
GSList *list=NULL;
|
||||
|
||||
if (string==NULL) return list;
|
||||
entries = g_strsplit(string,";",0);
|
||||
|
||||
for (entry=entries; *entry; entry++)
|
||||
{
|
||||
parts = g_strsplit(*entry,"=",2);
|
||||
part=parts;
|
||||
if ((!(*part)) || (strlen(*part)==0)) {
|
||||
g_strfreev(parts);
|
||||
continue;
|
||||
}
|
||||
|
||||
list = g_slist_append (list,g_strdup(*part));
|
||||
*part++;
|
||||
|
||||
if ((!(*part)) || (strlen(*part)==0) || (strcmp("''",*part)==0)) {
|
||||
list = g_slist_append (list,g_strdup(""));
|
||||
} else {
|
||||
list = g_slist_append (list,g_strdup(*part));
|
||||
}
|
||||
g_strfreev(parts);
|
||||
}
|
||||
g_strfreev(entries);
|
||||
|
||||
return list;
|
||||
}
|
||||
13
vpn-daemons/pptp/properties/util_lists.h
Normal file
13
vpn-daemons/pptp/properties/util_lists.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef NMVPNUI_UTIL_LISTS_H
|
||||
#define NMVPNUI_UTIL_LISTS_H
|
||||
|
||||
#define STORAGE_CLASS extern
|
||||
#ifdef NMVPNUI_UTIL_LISTS_C
|
||||
#undef STORAGE_CLASS
|
||||
#define STORAGE_CLASS
|
||||
#endif
|
||||
|
||||
STORAGE_CLASS GSList *list_from_string (const char *string);
|
||||
|
||||
#undef STORAGE_CLASS
|
||||
#endif
|
||||
72
vpn-daemons/pptp/properties/vpnui_expand.c
Normal file
72
vpn-daemons/pptp/properties/vpnui_expand.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#define NMVPNUI_EXPAND_C
|
||||
#include "vpnui_opt.h"
|
||||
#include "vpnui_expand.h"
|
||||
|
||||
void vpnui_expand_free(VpnUIExpander *expand)
|
||||
{
|
||||
g_return_if_fail(expand!=NULL);
|
||||
|
||||
if (expand->glade_name !=NULL) g_free(expand->glade_name);
|
||||
|
||||
g_free(expand);
|
||||
}
|
||||
|
||||
VpnUIExpander *vpnui_expand_new( char *glade_name,
|
||||
NetworkManagerVpnUIImpl *impl )
|
||||
{
|
||||
VpnUIExpander *expand;
|
||||
|
||||
g_return_val_if_fail(impl!=NULL,NULL);
|
||||
|
||||
if (!(expand = (VpnUIExpander *) g_new0(VpnUIExpander,1)))
|
||||
return NULL;
|
||||
|
||||
expand->glade_name=g_strdup(glade_name);
|
||||
|
||||
expand->impl=impl;
|
||||
|
||||
expand->widget = GTK_WIDGET (glade_xml_get_widget(expand->impl->xml, expand->glade_name));
|
||||
impl->expanders = g_slist_append(impl->expanders, (gpointer) expand);
|
||||
|
||||
return expand;
|
||||
}
|
||||
|
||||
void
|
||||
vpnui_expand_reset_all (NetworkManagerVpnUIImpl *impl)
|
||||
{
|
||||
GSList *item;
|
||||
|
||||
for (item=impl->expanders; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
vpnui_expand_reset((VpnUIExpander *)item->data);
|
||||
}
|
||||
|
||||
gtk_container_resize_children (GTK_CONTAINER (impl->widget));
|
||||
}
|
||||
|
||||
void vpnui_expand_reset(VpnUIExpander *expand)
|
||||
{
|
||||
GList *item;
|
||||
|
||||
g_return_if_fail(expand!=NULL);
|
||||
g_return_if_fail(expand->widget!=NULL);
|
||||
|
||||
if (GTK_IS_CONTAINER(expand->widget)) {
|
||||
if (vpnui_opt_has_active_children(GTK_CONTAINER(expand->widget),expand->impl)) {
|
||||
// gtk_expander_set_expanded(GTK_EXPANDER(expand->widget),TRUE);
|
||||
gtk_widget_show(GTK_WIDGET(expand->widget));
|
||||
} else {
|
||||
// gtk_expander_set_expanded(GTK_EXPANDER(expand->widget),FALSE);
|
||||
gtk_widget_hide(GTK_WIDGET(expand->widget));
|
||||
}
|
||||
}
|
||||
|
||||
// g_return_if_fail(expand!=NULL);
|
||||
// gtk_expander_set_expanded (GTK_EXPANDER(expand->widget), TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
36
vpn-daemons/pptp/properties/vpnui_expand.h
Normal file
36
vpn-daemons/pptp/properties/vpnui_expand.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef NMVPNUI_EXPAND_H
|
||||
#define NMVPNUI_EXPAND_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#include <vpnui_impl.h>
|
||||
|
||||
typedef struct VpnUIExpander
|
||||
{
|
||||
char *glade_name;
|
||||
NetworkManagerVpnUIImpl *impl;
|
||||
GtkWidget *widget;
|
||||
} VpnUIExpander;
|
||||
|
||||
#define STORAGE_CLASS extern
|
||||
#ifdef NMVPNUI_EXPAND_C
|
||||
#undef STORAGE_CLASS
|
||||
#define STORAGE_CLASS
|
||||
#endif
|
||||
|
||||
STORAGE_CLASS void vpnui_expand_free(VpnUIExpander *expand);
|
||||
STORAGE_CLASS VpnUIExpander *vpnui_expand_new( char *glade_name,
|
||||
NetworkManagerVpnUIImpl *impl );
|
||||
|
||||
STORAGE_CLASS void vpnui_expand_reset(VpnUIExpander *expand);
|
||||
STORAGE_CLASS void vpnui_expand_reset_all (NetworkManagerVpnUIImpl *impl);
|
||||
|
||||
#undef STORAGE_CLASS
|
||||
#endif
|
||||
551
vpn-daemons/pptp/properties/vpnui_impl.c
Normal file
551
vpn-daemons/pptp/properties/vpnui_impl.c
Normal file
|
|
@ -0,0 +1,551 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#define NM_VPN_API_SUBJECT_TO_CHANGE
|
||||
#include <NetworkManager/nm-vpn-ui-interface.h>
|
||||
|
||||
#define NMVPNUI_IMPL_C
|
||||
#include "vpnui_impl.h"
|
||||
#include "vpnui_expand.h"
|
||||
#include "vpnui_opt.h"
|
||||
|
||||
/* Stuff to be provided by the specific instance */
|
||||
extern const char *GLADE_FILE;
|
||||
extern const char *GLADE_WIDGET;
|
||||
extern void impl_setup (NetworkManagerVpnUIImpl *impl);
|
||||
|
||||
static void
|
||||
impl_set_validity_changed_callback (NetworkManagerVpnUI *self,
|
||||
NetworkManagerVpnUIDialogValidityCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
impl->callback = callback;
|
||||
impl->callback_user_data = user_data;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
impl_clear_widget (NetworkManagerVpnUIImpl *impl)
|
||||
{
|
||||
GSList *item;
|
||||
|
||||
g_return_if_fail(impl!=NULL);
|
||||
|
||||
vpnui_opt_set(impl->connection_name_opt,"");
|
||||
if (impl->defaults!=NULL)
|
||||
for (item=impl->config_options; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
vpnui_opt_set_default((VpnUIConfigOption *)item->data, impl->defaults);
|
||||
}
|
||||
|
||||
vpnui_expand_reset_all(impl);
|
||||
}
|
||||
|
||||
static const char *
|
||||
impl_get_display_name (NetworkManagerVpnUI *self)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
return impl->display_name;
|
||||
}
|
||||
|
||||
static const char *
|
||||
impl_get_service_name (NetworkManagerVpnUI *self)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
return impl->service_name;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
impl_get_widget (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name)
|
||||
{
|
||||
GSList *item;
|
||||
VpnUIConfigOption *opt;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
impl_clear_widget (impl);
|
||||
|
||||
if (connection_name != NULL) {
|
||||
if ((opt = impl->connection_name_opt) != NULL) {
|
||||
vpnui_opt_set(opt,connection_name);
|
||||
}
|
||||
}
|
||||
|
||||
for (item=properties; item != NULL; item = g_slist_next(g_slist_next(item)))
|
||||
{
|
||||
if (item->data==NULL) continue;
|
||||
if ((g_slist_next(item))->data==NULL) continue;
|
||||
opt = impl_opt_bygconf(impl,(char *)item->data);
|
||||
if (opt==NULL) continue;
|
||||
vpnui_opt_set(opt, (char *)(g_slist_next(item))->data);
|
||||
}
|
||||
|
||||
if (routes != NULL) {
|
||||
GString *route_str;
|
||||
char *str;
|
||||
|
||||
route_str = g_string_new ("");
|
||||
for (item = routes; item != NULL; item = g_slist_next (item)) {
|
||||
if (item != routes) g_string_append_c(route_str, ' ');
|
||||
g_string_append(route_str, (const char *) item->data);
|
||||
}
|
||||
str = g_string_free (route_str, FALSE);
|
||||
|
||||
vpnui_opt_set(impl->routes_opt,str);
|
||||
vpnui_opt_set(impl->routes_toggle_opt,"yes");
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
vpnui_expand_reset_all(impl);
|
||||
|
||||
return impl->widget;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
impl_get_properties (NetworkManagerVpnUI *self)
|
||||
{
|
||||
GSList *data;
|
||||
GSList *item;
|
||||
VpnUIConfigOption *opt;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
data = NULL;
|
||||
for (item=impl->config_options; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
opt = (VpnUIConfigOption *)item->data;
|
||||
if (opt==NULL) continue;
|
||||
if (opt->gconf_name==NULL) continue;
|
||||
if (!opt->active) continue;
|
||||
|
||||
data = g_slist_append (data, g_strdup(opt->gconf_name));
|
||||
data = g_slist_append (data, g_strdup(vpnui_opt_get(opt)));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
get_routes (NetworkManagerVpnUIImpl *impl)
|
||||
{
|
||||
GSList *routes;
|
||||
const char *routes_entry;
|
||||
const char *use_routes;
|
||||
char **substrs;
|
||||
unsigned int i;
|
||||
VpnUIConfigOption *opt;
|
||||
|
||||
routes = NULL;
|
||||
|
||||
opt = impl_opt_byglade(impl,"routes");
|
||||
g_return_val_if_fail(opt!=NULL,NULL);
|
||||
if (!opt->active) return NULL;
|
||||
routes_entry = vpnui_opt_get(opt);
|
||||
|
||||
opt = impl_opt_byglade(impl,"use-routes");
|
||||
g_return_val_if_fail(opt!=NULL,NULL);
|
||||
use_routes = vpnui_opt_get(impl_opt_byglade(impl,"use-routes"));
|
||||
|
||||
if (strcmp("no",use_routes)==0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
substrs = g_strsplit (routes_entry, " ", 0);
|
||||
for (i = 0; substrs[i] != NULL; i++) {
|
||||
char *route;
|
||||
|
||||
if (strlen(substrs[i]) > 0)
|
||||
routes = g_slist_append (routes, g_strdup (substrs[i]));
|
||||
}
|
||||
|
||||
g_strfreev (substrs);
|
||||
|
||||
out:
|
||||
return routes;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
impl_get_routes (NetworkManagerVpnUI *self)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
return get_routes (impl);
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
impl_get_connection_name (NetworkManagerVpnUI *self)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
return g_strdup( vpnui_opt_get(impl->connection_name_opt) );
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
impl_is_valid (NetworkManagerVpnUI *self)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
GSList *item;
|
||||
gboolean is_valid;
|
||||
VpnUIConfigOption *opt;
|
||||
|
||||
is_valid = TRUE;
|
||||
for (item=impl->config_options; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
opt = (VpnUIConfigOption *)item->data;
|
||||
if (opt==NULL) continue;
|
||||
if (!opt->active) continue;
|
||||
is_valid &= vpnui_opt_validate(opt);
|
||||
if (!is_valid) return is_valid;
|
||||
}
|
||||
|
||||
return is_valid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
impl_get_confirmation_details (NetworkManagerVpnUI *self, gchar **retval)
|
||||
{
|
||||
GString *buf;
|
||||
GSList *item;
|
||||
const char *value;
|
||||
VpnUIConfigOption *opt;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
// This is risky, should be variable length depending on actual data!
|
||||
buf = g_string_sized_new (1024);
|
||||
|
||||
g_string_append_printf (buf, _("The following '%s' connection will be created:"), impl->display_name);
|
||||
g_string_append (buf, "\n\n");
|
||||
for (item=impl->config_options; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
opt = (VpnUIConfigOption *)item->data;
|
||||
if (opt==NULL) continue;
|
||||
if (opt->description==NULL) continue;
|
||||
if (!opt->active) continue;
|
||||
|
||||
value = vpnui_opt_get(opt);
|
||||
if (value==NULL) continue;
|
||||
if (strlen(value)==0) continue;
|
||||
|
||||
g_string_append_printf (buf, _("\t%s: %s\n\n"), opt->description, value);
|
||||
}
|
||||
|
||||
g_string_append (buf, _("The connection details can be changed using the \"Back\" button."));
|
||||
g_string_append (buf, "\n");
|
||||
|
||||
*retval = g_string_free (buf, FALSE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
import_from_file (NetworkManagerVpnUIImpl *impl, const char *path)
|
||||
{
|
||||
char *basename;
|
||||
GKeyFile *keyfile;
|
||||
VpnUIConfigOption *opt;
|
||||
GSList *item;
|
||||
gboolean file_is_good;
|
||||
|
||||
file_is_good = FALSE;
|
||||
basename = g_path_get_basename (path);
|
||||
|
||||
keyfile = g_key_file_new ();
|
||||
if (g_key_file_load_from_file (keyfile, path, 0, NULL)) {
|
||||
char *value = NULL;
|
||||
|
||||
for (item=impl->config_options; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
opt = (VpnUIConfigOption *)item->data;
|
||||
if (opt==NULL) continue;
|
||||
if (opt->export_name==NULL) continue;
|
||||
|
||||
value = g_key_file_get_string (keyfile, "main", opt->export_name, NULL);
|
||||
vpnui_opt_set(opt,value);
|
||||
g_free (value);
|
||||
}
|
||||
g_key_file_free (keyfile);
|
||||
}
|
||||
|
||||
g_free (basename);
|
||||
|
||||
return file_is_good;
|
||||
|
||||
// if (!file_is_good) {
|
||||
// GtkWidget *dialog;
|
||||
//
|
||||
// dialog = gtk_message_dialog_new (NULL,
|
||||
// GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
// GTK_MESSAGE_WARNING,
|
||||
// GTK_BUTTONS_CLOSE,
|
||||
// _("Cannot import settings"));
|
||||
// gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
// _("The VPN settings file '%s' does not contain valid data."), basename);
|
||||
// gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
// gtk_widget_destroy (dialog);
|
||||
// }
|
||||
}
|
||||
|
||||
static void
|
||||
import_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
char *filename = NULL;
|
||||
GtkWidget *dialog;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) user_data;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new (_("Select file to import"),
|
||||
NULL,
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
|
||||
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
/*printf ("User selected '%s'\n", filename);*/
|
||||
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
if (filename != NULL) {
|
||||
import_from_file (impl, filename);
|
||||
g_free (filename);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
impl_can_export (NetworkManagerVpnUI *self)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
impl_import_file (NetworkManagerVpnUI *self, const char *path)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
return import_from_file (impl, path);
|
||||
}
|
||||
|
||||
static void
|
||||
export_to_file (NetworkManagerVpnUIImpl *impl, const char *path,
|
||||
GSList *properties, GSList *routes, const char *connection_name)
|
||||
{
|
||||
FILE *f;
|
||||
GSList *item;
|
||||
VpnUIConfigOption *opt;
|
||||
// gboolean use_routes = FALSE;
|
||||
const char *export = NULL;
|
||||
const char *value = NULL;
|
||||
char *routes_str = NULL;
|
||||
|
||||
f = fopen (path, "w");
|
||||
if (f == NULL) return;
|
||||
|
||||
/* Print the header */
|
||||
fprintf (f, "[main]\n");
|
||||
|
||||
/* Handle the connection-name */
|
||||
if (connection_name != NULL) {
|
||||
opt = impl_opt_byglade(impl,"connection-name");
|
||||
if (opt != NULL ) {
|
||||
export = opt->export_name;
|
||||
value = connection_name;
|
||||
if ((export != NULL ) && (value!=NULL) ) {
|
||||
fprintf (f, "%s=%s\n",export,value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (item=properties; item != NULL; item = g_slist_next(g_slist_next(item)))
|
||||
{
|
||||
if (item->data==NULL) continue;
|
||||
if ((g_slist_next(item))->data==NULL) continue;
|
||||
opt = impl_opt_bygconf(impl,(char *)item->data);
|
||||
if (opt==NULL) continue;
|
||||
vpnui_opt_set(opt, (char *)(g_slist_next(item))->data);
|
||||
}
|
||||
|
||||
if (routes != NULL) {
|
||||
GString *route_str;
|
||||
char *str;
|
||||
|
||||
route_str = g_string_new ("");
|
||||
for (item = routes; item != NULL; item = g_slist_next (item)) {
|
||||
if (item != routes) g_string_append_c(route_str, ' ');
|
||||
g_string_append(route_str, (const char *) item->data);
|
||||
}
|
||||
str = g_string_free (route_str, FALSE);
|
||||
|
||||
vpnui_opt_set(impl->routes_opt,str);
|
||||
vpnui_opt_set(impl->routes_toggle_opt,"yes");
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
/* Loop over properties and print them out */
|
||||
for (item=properties; item != NULL; item = g_slist_next(g_slist_next(item)))
|
||||
{
|
||||
if (item->data==NULL) continue;
|
||||
if ((g_slist_next(item))->data==NULL) continue;
|
||||
|
||||
// if (strcmp("use_routes",item->data)==0) {
|
||||
// if (strcmp("yes",(g_slist_next(item))->data)==0) use_routes=TRUE;
|
||||
// }
|
||||
|
||||
opt = impl_opt_bygconf(impl,(char *)item->data);
|
||||
if (opt==NULL) continue;
|
||||
if (opt->export_name==NULL) continue;
|
||||
if (!opt->active) continue;
|
||||
|
||||
export = opt->export_name;
|
||||
value = (const char *)(g_slist_next(item))->data;
|
||||
|
||||
if ((export != NULL ) && (value!=NULL) ) {
|
||||
fprintf (f, "%s=%s\n",export,value);
|
||||
}
|
||||
}
|
||||
|
||||
if (routes != NULL) {
|
||||
GString *route_str;
|
||||
char *str;
|
||||
|
||||
route_str = g_string_new ("");
|
||||
for (item = routes; item != NULL; item = g_slist_next (item)) {
|
||||
if (item != routes) g_string_append_c(route_str, ' ');
|
||||
g_string_append(route_str, (const char *) item->data);
|
||||
}
|
||||
value = ( str = g_string_free (route_str, FALSE) );
|
||||
value = str;
|
||||
|
||||
opt = impl_opt_byglade(impl,"routes");
|
||||
g_free (str);
|
||||
g_free (routes_str);
|
||||
}
|
||||
fclose (f);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
impl_export (NetworkManagerVpnUI *self, GSList *properties, GSList *routes, const char *connection_name)
|
||||
{
|
||||
char *suggested_name;
|
||||
char *path = NULL;
|
||||
GtkWidget *dialog;
|
||||
NetworkManagerVpnUIImpl *impl = (NetworkManagerVpnUIImpl *) self->data;
|
||||
|
||||
/*printf ("in impl_export\n");*/
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new (_("Save as..."),
|
||||
NULL,
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
suggested_name = g_strdup_printf ("%s.pcf", connection_name);
|
||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), suggested_name);
|
||||
g_free (suggested_name);
|
||||
|
||||
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
|
||||
path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
||||
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
if (path != NULL) {
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
|
||||
int response;
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (NULL,
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_QUESTION,
|
||||
GTK_BUTTONS_CANCEL,
|
||||
_("A file named \"%s\" already exists."), path);
|
||||
gtk_dialog_add_buttons (GTK_DIALOG (dialog), "_Replace", GTK_RESPONSE_OK, NULL);
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
_("Do you want to replace it with the one you are saving?"));
|
||||
response = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
gtk_widget_destroy (dialog);
|
||||
if (response == GTK_RESPONSE_OK)
|
||||
export_to_file (impl, path, properties, routes, connection_name);
|
||||
} else {
|
||||
export_to_file (impl, path, properties, routes, connection_name);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (path);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static NetworkManagerVpnUI*
|
||||
impl_get_object (void)
|
||||
{
|
||||
char *glade_file;
|
||||
NetworkManagerVpnUIImpl *impl;
|
||||
|
||||
impl = g_new0 (NetworkManagerVpnUIImpl, 1);
|
||||
|
||||
glade_file = g_strdup_printf ("%s/%s", GLADEDIR, GLADE_FILE);
|
||||
impl->xml = glade_xml_new (glade_file, NULL, GETTEXT_PACKAGE);
|
||||
g_free( glade_file );
|
||||
if (impl->xml != NULL) {
|
||||
|
||||
impl->widget = glade_xml_get_widget(impl->xml, GLADE_WIDGET);
|
||||
|
||||
impl_setup(impl);
|
||||
|
||||
impl->callback = NULL;
|
||||
|
||||
if (impl->w_import_button!=NULL) {
|
||||
gtk_signal_connect (GTK_OBJECT (impl->w_import_button),
|
||||
"clicked", GTK_SIGNAL_FUNC (import_button_clicked), impl);
|
||||
}
|
||||
|
||||
/* make the widget reusable */
|
||||
gtk_signal_connect (GTK_OBJECT (impl->widget), "delete-event",
|
||||
GTK_SIGNAL_FUNC (gtk_widget_hide_on_delete), NULL);
|
||||
|
||||
impl_clear_widget (impl);
|
||||
|
||||
impl->parent.get_display_name = impl_get_display_name;
|
||||
impl->parent.get_service_name = impl_get_service_name;
|
||||
impl->parent.get_widget = impl_get_widget;
|
||||
impl->parent.get_connection_name = impl_get_connection_name;
|
||||
impl->parent.get_properties = impl_get_properties;
|
||||
impl->parent.get_routes = impl_get_routes;
|
||||
impl->parent.set_validity_changed_callback = impl_set_validity_changed_callback;
|
||||
impl->parent.is_valid = impl_is_valid;
|
||||
impl->parent.get_confirmation_details = impl_get_confirmation_details;
|
||||
impl->parent.can_export = impl_can_export;
|
||||
impl->parent.import_file = impl_import_file;
|
||||
impl->parent.export = impl_export;
|
||||
impl->parent.data = impl;
|
||||
|
||||
return &(impl->parent);
|
||||
} else {
|
||||
g_free (impl);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
NetworkManagerVpnUI*
|
||||
nm_vpn_properties_factory (void)
|
||||
{
|
||||
return impl_get_object();
|
||||
}
|
||||
|
||||
|
||||
73
vpn-daemons/pptp/properties/vpnui_impl.h
Normal file
73
vpn-daemons/pptp/properties/vpnui_impl.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#ifndef NMVPNUI_IMPL_H
|
||||
#define NMVPNUI_IMPL_H
|
||||
|
||||
#include <glade/glade.h>
|
||||
|
||||
#define NM_VPN_API_SUBJECT_TO_CHANGE
|
||||
#include <NetworkManager/nm-vpn-ui-interface.h>
|
||||
|
||||
struct impl_config
|
||||
{
|
||||
const char *display_name;
|
||||
const char *glade_widget;
|
||||
const char *glade_file;
|
||||
const char *glade_connection_name;
|
||||
const char *glade_routes;
|
||||
const char *glade_routes_toggle;
|
||||
const char *glade_import_button;
|
||||
};
|
||||
|
||||
#define HAVE_VpnUIConfigOption
|
||||
typedef struct _VpnUIConfigOption VpnUIConfigOption;
|
||||
typedef struct _NetworkManagerVpnUIImpl NetworkManagerVpnUIImpl;
|
||||
|
||||
struct _NetworkManagerVpnUIImpl {
|
||||
NetworkManagerVpnUI parent;
|
||||
|
||||
NetworkManagerVpnUIDialogValidityCallback callback;
|
||||
gpointer callback_user_data;
|
||||
|
||||
GladeXML *xml;
|
||||
|
||||
GtkWidget *widget;
|
||||
|
||||
GSList *config_options;
|
||||
GSList *variants;
|
||||
|
||||
// GtkEntry *w_connection_name;
|
||||
// GtkEntry *w_remote;
|
||||
// GtkCheckButton *w_use_routes;
|
||||
// GtkEntry *w_routes;
|
||||
// GtkCheckButton *w_use_mppe;
|
||||
// GtkCheckButton *w_use_mppc;
|
||||
// GtkExpander *w_pppd_opt_info_expander;
|
||||
// GtkExpander *w_routing_opt_info_expander;
|
||||
// GtkExpander *w_pptp_opt_info_expander;
|
||||
VpnUIConfigOption *connection_name_opt;
|
||||
VpnUIConfigOption *routes_opt;
|
||||
VpnUIConfigOption *routes_toggle_opt;
|
||||
GtkComboBox *variant_combo;
|
||||
GtkButton *w_import_button;
|
||||
GSList *defaults;
|
||||
GSList *expanders;
|
||||
|
||||
const char *display_name;
|
||||
const char *service_name;
|
||||
};
|
||||
|
||||
#ifdef NMVPNUI_IMPL_C
|
||||
#define STORAGE_CLASS static
|
||||
#define STORAGE_CLASS2
|
||||
#else
|
||||
#define STORAGE_CLASS extern
|
||||
#define STORAGE_CLASS2 extern
|
||||
#endif
|
||||
|
||||
STORAGE_CLASS GSList *get_routes (NetworkManagerVpnUIImpl *impl);
|
||||
STORAGE_CLASS2 gboolean impl_is_valid (NetworkManagerVpnUI *self);
|
||||
STORAGE_CLASS void impl_set_validity_changed_callback (NetworkManagerVpnUI *self,
|
||||
NetworkManagerVpnUIDialogValidityCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
#undef STORAGE_CLASS
|
||||
#endif
|
||||
349
vpn-daemons/pptp/properties/vpnui_opt.c
Normal file
349
vpn-daemons/pptp/properties/vpnui_opt.c
Normal file
|
|
@ -0,0 +1,349 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#define NMVPNUI_OPT_C
|
||||
#include "vpnui_impl.h"
|
||||
#include "util_lists.h"
|
||||
#include "vpnui_opt.h"
|
||||
|
||||
char get_opt_buffer[64];
|
||||
|
||||
extern void use_routes_toggled (GtkToggleButton *togglebutton, gpointer user_data);
|
||||
extern void editable_changed (GtkEditable *editable, gpointer user_data);
|
||||
extern void impl_set_validity_changed_callback (NetworkManagerVpnUI *self,
|
||||
NetworkManagerVpnUIDialogValidityCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
void vpnui_opt_free(VpnUIConfigOption *opt)
|
||||
{
|
||||
g_return_if_fail(opt!=NULL);
|
||||
|
||||
if (opt->glade_name !=NULL) g_free(opt->glade_name);
|
||||
if (opt->gconf_name != NULL) g_free(opt->gconf_name);
|
||||
if (opt->export_name != NULL) g_free(opt->export_name);
|
||||
|
||||
g_free(opt);
|
||||
}
|
||||
|
||||
VpnUIConfigOption *vpnui_opt_new( char *glade_name,
|
||||
int option_type,
|
||||
char *gconf_name,
|
||||
char *export_name,
|
||||
char *description,
|
||||
void (*change_handler)(void),
|
||||
gboolean (*validator)(VpnUIConfigOption *opt),
|
||||
NetworkManagerVpnUIImpl *impl )
|
||||
{
|
||||
VpnUIConfigOption *opt;
|
||||
|
||||
g_return_val_if_fail(impl!=NULL,NULL);
|
||||
|
||||
if (impl->config_options == NULL) impl->config_options = NULL;
|
||||
|
||||
if (!(opt = (VpnUIConfigOption *) g_new0(VpnUIConfigOption,1)))
|
||||
return NULL;
|
||||
|
||||
opt->glade_name=g_strdup(glade_name);
|
||||
opt->option_type=option_type;
|
||||
if (gconf_name != NULL) opt->gconf_name=g_strdup(gconf_name);
|
||||
if (export_name != NULL) opt->export_name=g_strdup(export_name);
|
||||
if (description != NULL) opt->description=g_strdup(description);
|
||||
|
||||
opt->change_handler=change_handler;
|
||||
opt->validator=validator;
|
||||
|
||||
opt->impl=impl;
|
||||
impl->config_options = g_slist_append(impl->config_options, (gpointer) opt);
|
||||
|
||||
vpnui_opt_get_widget(opt);
|
||||
vpnui_opt_connect_signals(opt);
|
||||
|
||||
return opt;
|
||||
}
|
||||
|
||||
void vpnui_opt_connect_signals(VpnUIConfigOption *opt)
|
||||
{
|
||||
g_return_if_fail(opt!=NULL);
|
||||
g_return_if_fail(opt->widget!=NULL);
|
||||
g_return_if_fail(opt->impl!=NULL);
|
||||
|
||||
if (opt->change_handler==NULL) return;
|
||||
|
||||
switch (opt->option_type)
|
||||
{
|
||||
case VPN_UI_OPTTYPE_YESNO:
|
||||
gtk_signal_connect (GTK_OBJECT (opt->widget),
|
||||
"toggled", GTK_SIGNAL_FUNC (opt->change_handler), opt->impl);
|
||||
break;
|
||||
case VPN_UI_OPTTYPE_STRING:
|
||||
gtk_signal_connect (GTK_OBJECT (opt->widget),
|
||||
"changed", GTK_SIGNAL_FUNC (opt->change_handler), opt->impl);
|
||||
break;
|
||||
case VPN_UI_OPTTYPE_SPINNER:
|
||||
gtk_signal_connect (GTK_OBJECT (opt->widget),
|
||||
"changed", GTK_SIGNAL_FUNC (opt->change_handler), opt->impl);
|
||||
break;
|
||||
case VPN_UI_OPTTYPE_COMBO:
|
||||
gtk_signal_connect (GTK_OBJECT (opt->widget),
|
||||
"changed", GTK_SIGNAL_FUNC (opt->change_handler), opt->impl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void vpnui_opt_get_widget(VpnUIConfigOption *opt)
|
||||
{
|
||||
g_return_if_fail(opt!=NULL);
|
||||
g_return_if_fail(opt->impl!=NULL);
|
||||
|
||||
switch (opt->option_type)
|
||||
{
|
||||
case VPN_UI_OPTTYPE_YESNO:
|
||||
case VPN_UI_OPTTYPE_STRING:
|
||||
case VPN_UI_OPTTYPE_SPINNER:
|
||||
case VPN_UI_OPTTYPE_COMBO:
|
||||
opt->widget = GTK_WIDGET (glade_xml_get_widget(opt->impl->xml, opt->glade_name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char * vpnui_opt_get(VpnUIConfigOption *opt)
|
||||
{
|
||||
GtkTreeModel *combo_tree;
|
||||
GtkTreeIter iter;
|
||||
char *setting;
|
||||
gdouble value;
|
||||
g_return_val_if_fail(opt!=NULL,NULL);
|
||||
|
||||
switch (opt->option_type)
|
||||
{
|
||||
case VPN_UI_OPTTYPE_YESNO:
|
||||
if (gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (opt->widget) )) {
|
||||
return "yes";
|
||||
}
|
||||
return "no";
|
||||
case VPN_UI_OPTTYPE_STRING:
|
||||
return gtk_entry_get_text(GTK_ENTRY(opt->widget));
|
||||
case VPN_UI_OPTTYPE_SPINNER:
|
||||
value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(opt->widget));
|
||||
sprintf(get_opt_buffer,"%.0f",value);
|
||||
return get_opt_buffer;
|
||||
case VPN_UI_OPTTYPE_COMBO:
|
||||
combo_tree = gtk_combo_box_get_model(GTK_COMBO_BOX(opt->widget));
|
||||
if (combo_tree==NULL) return NULL;
|
||||
if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(opt->widget), &iter))
|
||||
return NULL;
|
||||
|
||||
gtk_tree_model_get (combo_tree, &iter, 0, &setting, -1);
|
||||
return setting;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vpnui_opt_set(VpnUIConfigOption *opt, const char *value)
|
||||
{
|
||||
int num_value;
|
||||
GtkTreeModel *combo_tree;
|
||||
GtkTreeIter iter;
|
||||
gboolean found;
|
||||
|
||||
g_return_if_fail(opt!=NULL);
|
||||
g_return_if_fail(value!=NULL);
|
||||
|
||||
switch (opt->option_type)
|
||||
{
|
||||
case VPN_UI_OPTTYPE_YESNO:
|
||||
if (strcmp("yes",value) == 0) {
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (opt->widget), TRUE);
|
||||
} else if (strcmp("no",value) == 0) {
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (opt->widget), FALSE);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case VPN_UI_OPTTYPE_STRING:
|
||||
gtk_entry_set_text ( GTK_ENTRY( opt->widget ), value );
|
||||
break;
|
||||
case VPN_UI_OPTTYPE_SPINNER:
|
||||
sscanf(value,"%d",&num_value);
|
||||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(opt->widget),num_value);
|
||||
break;
|
||||
case VPN_UI_OPTTYPE_COMBO:
|
||||
combo_tree = gtk_combo_box_get_model(GTK_COMBO_BOX(opt->widget));
|
||||
if (combo_tree==NULL) return;
|
||||
for (found = gtk_tree_model_get_iter_first(combo_tree, &iter);
|
||||
found == TRUE;
|
||||
found = gtk_tree_model_iter_next(combo_tree, &iter)) {
|
||||
char *setting;
|
||||
gtk_tree_model_get (combo_tree, &iter, 0, &setting, -1);
|
||||
if (strcmp(setting,value)==0) {
|
||||
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(opt->widget),&iter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean vpnui_opt_set_default(VpnUIConfigOption *opt, GSList *defaults)
|
||||
{
|
||||
GSList *item;
|
||||
|
||||
g_return_val_if_fail(opt!=NULL,FALSE);
|
||||
g_return_val_if_fail(defaults!=NULL,FALSE);
|
||||
|
||||
|
||||
// if (defaults == NULL) {
|
||||
// vpnui_opt_set_inactive(opt);
|
||||
// return FALSE;
|
||||
// }
|
||||
if (opt==opt->impl->connection_name_opt) {
|
||||
if (strlen(vpnui_opt_get(opt))>0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
for (item=defaults; item != NULL; item = g_slist_next(g_slist_next(item)))
|
||||
{
|
||||
if (strcmp((char *)item->data,opt->glade_name)!=0) continue;
|
||||
if ((g_slist_next(item))->data == NULL) continue;
|
||||
vpnui_opt_set(opt,(char *)(g_slist_next(item))->data);
|
||||
vpnui_opt_set_active(opt);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
vpnui_opt_set_inactive(opt);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean vpnui_opt_query_default(VpnUIConfigOption *opt, GSList *defaults)
|
||||
{
|
||||
GSList *item;
|
||||
const char *value;
|
||||
|
||||
g_return_val_if_fail(opt!=NULL,TRUE);
|
||||
|
||||
if (defaults == NULL) return TRUE;
|
||||
|
||||
for (item=defaults; item != NULL; item = g_slist_next(g_slist_next(item)))
|
||||
{
|
||||
if (strcmp(item->data,opt->glade_name)!=0) continue;
|
||||
value = vpnui_opt_get(opt);
|
||||
if (strcmp((g_slist_next(item))->data,value)==0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void vpnui_opt_set_active(VpnUIConfigOption *opt)
|
||||
{
|
||||
g_return_if_fail(opt!=NULL);
|
||||
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(opt->widget),TRUE);
|
||||
opt->active = TRUE;
|
||||
}
|
||||
|
||||
void vpnui_opt_set_inactive(VpnUIConfigOption *opt)
|
||||
{
|
||||
g_return_if_fail(opt!=NULL);
|
||||
|
||||
if (GTK_WIDGET(opt->widget)==GTK_WIDGET(opt->impl->variant_combo)) return;
|
||||
if (opt==opt->impl->connection_name_opt) return;
|
||||
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(opt->widget),FALSE);
|
||||
opt->active = FALSE;
|
||||
}
|
||||
|
||||
gboolean vpnui_opt_validate(VpnUIConfigOption *opt)
|
||||
{
|
||||
g_return_val_if_fail(opt!=NULL,TRUE);
|
||||
|
||||
if (opt->validator==NULL) return TRUE;
|
||||
return (opt->validator)(opt);
|
||||
}
|
||||
|
||||
VpnUIConfigOption *
|
||||
impl_opt_bygconf (NetworkManagerVpnUIImpl *impl, const char *name)
|
||||
{
|
||||
GSList *item;
|
||||
VpnUIConfigOption *opt;
|
||||
|
||||
for (item=impl->config_options; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
opt = (VpnUIConfigOption *)item->data;
|
||||
if (opt == NULL) continue;
|
||||
if (opt->gconf_name == NULL) continue;
|
||||
if (strcmp(opt->gconf_name,name)==0) return opt;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VpnUIConfigOption *
|
||||
impl_opt_byglade (NetworkManagerVpnUIImpl *impl, const char *name)
|
||||
{
|
||||
GSList *item;
|
||||
VpnUIConfigOption *opt;
|
||||
|
||||
for (item=impl->config_options; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
opt = (VpnUIConfigOption *)item->data;
|
||||
if (opt == NULL) continue;
|
||||
if (opt->glade_name == NULL) continue;
|
||||
if (strcmp(opt->glade_name,name)==0) return opt;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean vpnui_opt_has_active_children(GtkContainer *container, NetworkManagerVpnUIImpl *impl)
|
||||
{
|
||||
VpnUIConfigOption *opt;
|
||||
GList *item;
|
||||
|
||||
g_return_val_if_fail(GTK_IS_CONTAINER(container) ,FALSE);
|
||||
|
||||
for (item=gtk_container_get_children(container);
|
||||
item != NULL; item=g_list_next(item)) {
|
||||
if (item->data==NULL) continue;
|
||||
// g_warning("%s has child %s",gtk_widget_get_name(GTK_WIDGET(container)),
|
||||
// gtk_widget_get_name(GTK_WIDGET(item->data)));
|
||||
opt = impl_opt_byglade(impl,gtk_widget_get_name(GTK_WIDGET(item->data)));
|
||||
if (opt!=NULL && opt->active) return TRUE;
|
||||
|
||||
if (GTK_IS_CONTAINER(item->data)
|
||||
&& vpnui_opt_has_active_children(GTK_CONTAINER(item->data),impl)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
//const char * vpnui_opt_get(VpnUIConfigOption *opt)
|
||||
//{
|
||||
// g_return_if_fail(opt!=NULL);
|
||||
//
|
||||
// switch (opt->option_type)
|
||||
// {
|
||||
// case VPN_UI_OPTTYPE_YESNO:
|
||||
// if (gtk_toggle_button_get_active ( GTK_CHECK_BUTTON (opt->widget) )) {
|
||||
// return "yes";
|
||||
// } else {
|
||||
// return "no";
|
||||
// }
|
||||
// break;
|
||||
// case VPN_UI_OPTTYPE_STRING:
|
||||
// return gtk_entry_get_text(GTK_ENTRY(opt->widget));
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// return NULL;
|
||||
//}
|
||||
63
vpn-daemons/pptp/properties/vpnui_opt.h
Normal file
63
vpn-daemons/pptp/properties/vpnui_opt.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef NMVPNUI_OPT_H
|
||||
#define NMVPNUI_OPT_H
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
//##include <NetworkManager/nm-vpn-ui-interface.h>
|
||||
#include "vpnui_impl.h"
|
||||
|
||||
#define VPN_UI_OPTTYPE_YESNO 1
|
||||
#define VPN_UI_OPTTYPE_STRING 2
|
||||
#define VPN_UI_OPTTYPE_SPINNER 3
|
||||
#define VPN_UI_OPTTYPE_COMBO 4
|
||||
|
||||
#ifndef HAVE_VpnUIConfigOption
|
||||
typedef struct _VpnUIConfigOption VpnUIConfigOption;
|
||||
#endif
|
||||
|
||||
struct _VpnUIConfigOption
|
||||
{
|
||||
char *glade_name;
|
||||
int option_type;
|
||||
char *gconf_name;
|
||||
char *export_name;
|
||||
char *description;
|
||||
gboolean active;
|
||||
GtkSignalFunc change_handler;
|
||||
gboolean (*validator)(VpnUIConfigOption *opt);
|
||||
GtkWidget *widget;
|
||||
NetworkManagerVpnUIImpl *impl;
|
||||
};
|
||||
|
||||
#define STORAGE_CLASS extern
|
||||
#ifdef NMVPNUI_OPT_C
|
||||
#undef STORAGE_CLASS
|
||||
#define STORAGE_CLASS
|
||||
#endif
|
||||
|
||||
STORAGE_CLASS void vpnui_opt_free(VpnUIConfigOption *opt);
|
||||
STORAGE_CLASS VpnUIConfigOption *vpnui_opt_new( char *glade_name,
|
||||
int option_type,
|
||||
char *gconf_name,
|
||||
char *export_name,
|
||||
char *description,
|
||||
void (*change_handler)(void),
|
||||
gboolean (*validator)(VpnUIConfigOption *opt),
|
||||
NetworkManagerVpnUIImpl *impl );
|
||||
STORAGE_CLASS void vpnui_opt_set_active(VpnUIConfigOption *opt);
|
||||
STORAGE_CLASS void vpnui_opt_set_inactive(VpnUIConfigOption *opt);
|
||||
STORAGE_CLASS void vpnui_opt_get_widget(VpnUIConfigOption *opt);
|
||||
//static char * vpnui_opt_get(VpnUIConfigOption *opt);
|
||||
STORAGE_CLASS void vpnui_opt_set(VpnUIConfigOption *opt, const char *value);
|
||||
STORAGE_CLASS gboolean vpnui_opt_query_default(VpnUIConfigOption *opt, GSList *defaults);
|
||||
STORAGE_CLASS gboolean vpnui_opt_set_default(VpnUIConfigOption *opt, GSList *defaults);
|
||||
STORAGE_CLASS gboolean vpnui_opt_validate(VpnUIConfigOption *opt);
|
||||
STORAGE_CLASS const char * vpnui_opt_get(VpnUIConfigOption *opt);
|
||||
STORAGE_CLASS void vpnui_opt_connect_signals(VpnUIConfigOption *opt);
|
||||
STORAGE_CLASS VpnUIConfigOption *impl_opt_bygconf (NetworkManagerVpnUIImpl *impl, const char *name);
|
||||
STORAGE_CLASS VpnUIConfigOption *impl_opt_byglade (NetworkManagerVpnUIImpl *impl, const char *name);
|
||||
STORAGE_CLASS gboolean vpnui_opt_has_active_children(GtkContainer *container, NetworkManagerVpnUIImpl *impl);
|
||||
#undef STORAGE_CLASS
|
||||
#endif
|
||||
98
vpn-daemons/pptp/properties/vpnui_validate.c
Normal file
98
vpn-daemons/pptp/properties/vpnui_validate.c
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define NMVPNUI_VALIDATE_C
|
||||
#include "vpnui_impl.h"
|
||||
#include "vpnui_opt.h"
|
||||
#include "vpnui_validate.h"
|
||||
|
||||
gboolean vld_non_empty (VpnUIConfigOption *opt)
|
||||
{
|
||||
const char *value = vpnui_opt_get(opt);
|
||||
if ((value == NULL) || (strlen (value) == 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean vld_non_empty_no_ws (VpnUIConfigOption *opt)
|
||||
{
|
||||
const char *value = vpnui_opt_get(opt);
|
||||
if ((value == NULL) ||
|
||||
(strlen (value) == 0) ||
|
||||
(strstr(value, " ") != NULL) ||
|
||||
(strstr(value, "\t") != NULL) ) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean vld_routes_if_sens (VpnUIConfigOption *opt)
|
||||
{
|
||||
GSList *item;
|
||||
GSList *routes = NULL;
|
||||
VpnUIConfigOption *opt2;
|
||||
const char *value;
|
||||
const char *use_routes;
|
||||
char **substrs;
|
||||
int i;
|
||||
gboolean sens, is_valid;
|
||||
|
||||
sens = GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(opt->widget));
|
||||
if (!sens) return TRUE;
|
||||
|
||||
// routes = get_routes (opt->impl);
|
||||
g_return_val_if_fail(opt!=NULL,TRUE);
|
||||
value = vpnui_opt_get(opt);
|
||||
|
||||
opt2 = impl_opt_byglade(opt->impl,"use-routes");
|
||||
g_return_val_if_fail(opt2!=NULL,TRUE);
|
||||
use_routes = vpnui_opt_get(opt2);
|
||||
|
||||
if (strcmp("yes",use_routes)==0) {
|
||||
substrs = g_strsplit (value, " ", 0);
|
||||
for (i = 0; substrs[i] != NULL; i++) {
|
||||
char *route;
|
||||
|
||||
if (strlen(substrs[i]) > 0)
|
||||
routes = g_slist_append (routes, g_strdup (substrs[i]));
|
||||
}
|
||||
|
||||
g_strfreev (substrs);
|
||||
}
|
||||
|
||||
is_valid=TRUE;
|
||||
for (item = routes; item != NULL; item = g_slist_next (item)) {
|
||||
int d1, d2, d3, d4, mask;
|
||||
|
||||
const char *route = (const char *) item->data;
|
||||
//printf ("route = '%s'\n", route);
|
||||
|
||||
if (sscanf (route, "%d.%d.%d.%d/%d", &d1, &d2, &d3, &d4, &mask) != 5) {
|
||||
is_valid = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: this can be improved a bit */
|
||||
if (d1 < 0 || d1 > 255 ||
|
||||
d2 < 0 || d2 > 255 ||
|
||||
d3 < 0 || d3 > 255 ||
|
||||
d4 < 0 || d4 > 255 ||
|
||||
mask < 0 || mask > 32) {
|
||||
is_valid = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (routes != NULL) {
|
||||
g_slist_foreach (routes, (GFunc)g_free, NULL);
|
||||
g_slist_free (routes);
|
||||
}
|
||||
|
||||
return is_valid;
|
||||
}
|
||||
15
vpn-daemons/pptp/properties/vpnui_validate.h
Normal file
15
vpn-daemons/pptp/properties/vpnui_validate.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef NMVPNUI_VALIDATE_H
|
||||
#define NMVPNUI_VALIDATE_H
|
||||
|
||||
#define STORAGE_CLASS extern
|
||||
#ifdef NMVPNUI_VALIDATE_C
|
||||
#undef STORAGE_CLASS
|
||||
#define STORAGE_CLASS
|
||||
#endif
|
||||
|
||||
STORAGE_CLASS gboolean vld_non_empty (VpnUIConfigOption *value);
|
||||
STORAGE_CLASS gboolean vld_non_empty_no_ws (VpnUIConfigOption *value);
|
||||
STORAGE_CLASS gboolean vld_routes_if_sens (VpnUIConfigOption *value);
|
||||
|
||||
#undef STORAGE_CLASS
|
||||
#endif
|
||||
123
vpn-daemons/pptp/properties/vpnui_variant.c
Normal file
123
vpn-daemons/pptp/properties/vpnui_variant.c
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#define NMVPNUI_EXPAND_C
|
||||
#include "util_lists.h"
|
||||
#include "vpnui_opt.h"
|
||||
#include "vpnui_variant.h"
|
||||
|
||||
|
||||
void vpnui_variant_free( VpnUIVariant *variant )
|
||||
{
|
||||
g_return_if_fail(variant != NULL);
|
||||
|
||||
g_free(variant->name);
|
||||
g_free(variant->defaults);
|
||||
g_free(variant);
|
||||
}
|
||||
|
||||
VpnUIVariant *vpnui_variant_new( const char *name, const char *description,
|
||||
const char *defaults,
|
||||
NetworkManagerVpnUIImpl *impl
|
||||
)
|
||||
{
|
||||
VpnUIVariant *variant;
|
||||
GtkListStore *store;
|
||||
GtkTreeIter iter;
|
||||
GtkCellRenderer *renderer;
|
||||
gboolean first_variant=FALSE;
|
||||
|
||||
g_return_val_if_fail(name != NULL,NULL);
|
||||
g_return_val_if_fail(defaults != NULL,NULL);
|
||||
g_return_val_if_fail(impl != NULL,NULL);
|
||||
g_return_val_if_fail(impl->variant_combo != NULL,NULL);
|
||||
|
||||
if (!(variant = (VpnUIVariant *) g_new0(VpnUIVariant,1)))
|
||||
return NULL;
|
||||
|
||||
variant->name = g_strdup(name);
|
||||
variant->description = g_strdup(description);
|
||||
variant->defaults = list_from_string(defaults);
|
||||
variant->impl = impl;
|
||||
|
||||
first_variant=(impl->variants == NULL);
|
||||
|
||||
if (first_variant) {
|
||||
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
|
||||
} else {
|
||||
store =
|
||||
(GtkListStore *)gtk_combo_box_get_model(GTK_COMBO_BOX(impl->variant_combo));
|
||||
}
|
||||
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter, 0, variant->name, 1, variant->description, -1);
|
||||
|
||||
gtk_combo_box_set_model(impl->variant_combo,GTK_TREE_MODEL(store));
|
||||
if (first_variant) {
|
||||
gtk_cell_layout_clear (GTK_CELL_LAYOUT (impl->variant_combo));
|
||||
// renderer = gtk_cell_renderer_text_new ();
|
||||
// gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (impl->variant_combo), renderer, FALSE);
|
||||
// gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (impl->variant_combo), renderer,
|
||||
// "text", 0, "visible", FALSE,
|
||||
// NULL);
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (impl->variant_combo), renderer, TRUE);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (impl->variant_combo), renderer,
|
||||
"text", 1,
|
||||
NULL);
|
||||
}
|
||||
|
||||
// gtk_combo_box_append_text(GTK_COMBO_BOX(impl->variant_combo), variant->name);
|
||||
g_object_unref (store);
|
||||
|
||||
impl->variants = g_slist_append(impl->variants, (gpointer) variant);
|
||||
return variant;
|
||||
}
|
||||
|
||||
VpnUIVariant *
|
||||
vpnui_variant_byname (NetworkManagerVpnUIImpl *impl, const char *name)
|
||||
{
|
||||
GSList *item;
|
||||
VpnUIVariant *variant;
|
||||
|
||||
for (item=impl->variants; item != NULL; item = g_slist_next(item))
|
||||
{
|
||||
variant = (VpnUIVariant *)item->data;
|
||||
if (variant == NULL) continue;
|
||||
if (variant->name == NULL) continue;
|
||||
if (strcmp(variant->name,name)==0) return variant;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
vpnui_variant_select (VpnUIVariant *variant)
|
||||
{
|
||||
NetworkManagerVpnUIImpl *impl;
|
||||
GSList *item;
|
||||
|
||||
g_return_if_fail(variant != NULL);
|
||||
impl=variant->impl;
|
||||
|
||||
impl->defaults=variant->defaults;
|
||||
for (item=impl->config_options; item != NULL; item = g_slist_next(item)) {
|
||||
vpnui_opt_set_default((VpnUIConfigOption *)item->data, impl->defaults);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
vpnui_variant_select_byname (NetworkManagerVpnUIImpl *impl, const char *name)
|
||||
{
|
||||
VpnUIVariant *variant;
|
||||
|
||||
g_return_if_fail(impl != NULL);
|
||||
g_return_if_fail(name != NULL);
|
||||
|
||||
variant = vpnui_variant_byname(impl,name);
|
||||
g_return_if_fail(variant != NULL);
|
||||
vpnui_variant_select(variant);
|
||||
}
|
||||
|
||||
39
vpn-daemons/pptp/properties/vpnui_variant.h
Normal file
39
vpn-daemons/pptp/properties/vpnui_variant.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef NMVPNUI_VARIANT_H
|
||||
#define NMVPNUI_VARIANT_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#include "vpnui_impl.h"
|
||||
|
||||
typedef struct VpnUIVariant
|
||||
{
|
||||
char *name;
|
||||
char *description;
|
||||
GSList *defaults;
|
||||
NetworkManagerVpnUIImpl *impl;
|
||||
} VpnUIVariant;
|
||||
|
||||
#define STORAGE_CLASS extern
|
||||
#ifdef NMVPNUI_EXPAND_C
|
||||
#undef STORAGE_CLASS
|
||||
#define STORAGE_CLASS
|
||||
#endif
|
||||
|
||||
STORAGE_CLASS void vpnui_variant_free( VpnUIVariant *variant );
|
||||
STORAGE_CLASS VpnUIVariant *vpnui_variant_new( const char *name,
|
||||
const char *description,
|
||||
const char *defaults,
|
||||
NetworkManagerVpnUIImpl *impl
|
||||
);
|
||||
STORAGE_CLASS VpnUIVariant *vpnui_variant_byname (NetworkManagerVpnUIImpl *impl, const char *name);
|
||||
STORAGE_CLASS void vpnui_variant_select (VpnUIVariant *variant);
|
||||
STORAGE_CLASS void vpnui_variant_select_byname (NetworkManagerVpnUIImpl *impl, const char *name);
|
||||
#undef STORAGE_CLASS
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue