Signed-off-by: Dmitri Bogomolov <[email protected]>

diff --git a/net/vpnc/Makefile b/net/vpnc/Makefile
index 58af207..66cad8b 100644
--- a/net/vpnc/Makefile
+++ b/net/vpnc/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006-2012 OpenWrt.org
+# Copyright (C) 2006-2013 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -20,7 +20,7 @@ include $(INCLUDE_DIR)/package.mk
 define Package/vpnc
   SECTION:=net
   CATEGORY:=Network
-  DEPENDS:=+libgpg-error +libgcrypt +kmod-tun +vpnc-scripts
+  DEPENDS:=+libgpg-error +libgcrypt +kmod-tun +vpnc-scripts +coreutils-shuf
   TITLE:=VPN client for Cisco EasyVPN
   URL:=http://www.unix-ag.uni-kl.de/~massar/vpnc/
   SUBMENU:=VPN
@@ -36,6 +36,7 @@ endef
 
 define Package/vpnc/conffiles
 /etc/vpnc/default.conf
+/etc/config/vpnc
 endef
 
 define Build/Compile
@@ -51,11 +52,19 @@ endef
 
 define Package/vpnc/install
        $(INSTALL_DIR) $(1)/usr/sbin
+       sed -i -e "s|pid=.*|pid=/var/run/vpnc.pid|g" 
$(PKG_INSTALL_DIR)/usr/sbin/vpnc-disconnect
        $(CP)   $(PKG_INSTALL_DIR)/usr/sbin/vpnc \
                $(PKG_INSTALL_DIR)/usr/sbin/vpnc-disconnect \
                $(1)/usr/sbin/
        $(INSTALL_DIR) $(1)/etc/vpnc
+       echo "Pidfile /var/run/vpnc.pid" > 
$(PKG_INSTALL_DIR)/etc/vpnc/default.conf
+       echo "Noninteractive" >> $(PKG_INSTALL_DIR)/etc/vpnc/default.conf
+
        $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/vpnc/default.conf $(1)/etc/vpnc/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) ./files/vpnc.config $(1)/etc/config/vpnc
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/vpnc.init  $(1)/etc/init.d/vpnc
 endef
 
 $(eval $(call BuildPackage,vpnc))
diff --git a/net/vpnc/files/vpnc.config b/net/vpnc/files/vpnc.config
new file mode 100644
index 0000000..ebeb81d
--- /dev/null
+++ b/net/vpnc/files/vpnc.config
@@ -0,0 +1,6 @@
+config vpnc config
+#        list ipsec_gateway    'vpn.example.com'
+#        option ipsec_id       'your id'
+#        option ipsec_secret   'your secret'
+#        option xauth_username         'username'
+#        option xauth_password         'password'
diff --git a/net/vpnc/files/vpnc.init b/net/vpnc/files/vpnc.init
new file mode 100644
index 0000000..10248c2
--- /dev/null
+++ b/net/vpnc/files/vpnc.init
@@ -0,0 +1,77 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2013 OpenWrt.org
+
+START=99
+STOP=10
+
+PID_F=/var/run/vpnc.pid
+CONFIGFILE="/etc/vpnc.conf"
+
+append_string() {
+       local section="$1"
+       local option="$2"
+       local value="$3"
+       local _val
+       config_get _val "$section" "$option"
+       [ -n "$_val" ] && append args "$3 $_val"
+}
+
+update_conffile() {
+       local ipsec_id ipsec_secret ipsec_secret_obfuscated
+       local xauth_username xauth_password xauth_password_obfuscated
+       local vendor natt_mode
+
+       config_get ipsec_id config "ipsec_id"
+       config_get ipsec_secret config "ipsec_secret"
+       config_get_bool ipsec_secret_obfuscated config 
"ipsec_secret_obfuscated" 0
+       config_get xauth_username config "xauth_username"
+       config_get xauth_password config "xauth_password"
+       config_get_bool xauth_password_obfuscated config 
"xauth_password_obfuscated" 0
+       config_get vendor config "vendor" "cisco"
+       config_get natt_mode config "natt_mode" "natt"
+
+       echo "# Autogenerated vpnc config" > "$CONFIGFILE"
+       echo "IPSec gateway $ipsec_gateway" >> "$CONFIGFILE"
+       echo "IPSec ID $ipsec_id" >> "$CONFIGFILE"
+       echo "Xauth username $xauth_username" >> "$CONFIGFILE"
+
+       local pass_string="IPSec"
+       [ $ipsec_secret_obfuscated -gt 0 ] && append pass_string "obfuscated"
+       echo "$pass_string secret $ipsec_secret" >> "$CONFIGFILE"
+       pass_string="Xauth"
+       [ $xauth_password_obfuscated -gt 0 ] && append pass_string "obfuscated"
+       echo "$pass_string password $xauth_password" >> "$CONFIGFILE"
+
+       echo "Vendor $vendor" >> "$CONFIGFILE"
+       echo "NAT Traversal Mode $natt_mode" >> "$CONFIGFILE"
+}
+
+start() {
+       config_load "vpnc"
+       args=""
+       update_conffile
+
+       append_string config domain "--domain"
+       append_string config dh_group "--dh"
+       append_string config pfs "--pfs"
+       append_string config ifname "--ifname"
+       # append_string config debug "--debug"
+
+       local _val
+       config_get _val config xauth_inter 0
+       [ $_val -gt 0 ] && append args "--xauth-inter"
+       config_get _val config dpd_off 0
+       [ $_val -eq 1 ] && append args "--dpd-idle 0"
+
+       local ipsec_gateway
+       config_get ipsec_gateway config "ipsec_gateway"
+       for ipsec_gateway in $(shuf -e $ipsec_gateway); do
+           /usr/sbin/vpnc $args --gateway $ipsec_gateway
+           [ $? -eq 0 ] && break
+       done
+}
+
+stop() {
+       vpnc-disconnect
+       [ -f $PID_F ] && kill $(cat $PID_F)
+}
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to