2013-01-30 20:07:15 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2013-10-07 21:28:14 +00:00
|
|
|
# Copyright (C) 2008-2013 OpenWrt.org
|
2013-01-30 20:07:15 +00:00
|
|
|
# Copyright (C) 2008 Jo-Philipp Wich
|
|
|
|
# This is free software, licensed under the GNU General Public License v2.
|
|
|
|
# See /LICENSE for more information.
|
|
|
|
|
2013-10-07 21:28:14 +00:00
|
|
|
START=90
|
|
|
|
STOP=10
|
2013-01-30 20:07:15 +00:00
|
|
|
|
2013-10-07 21:28:14 +00:00
|
|
|
USE_PROCD=1
|
|
|
|
PROG=/usr/sbin/openvpn
|
2013-01-30 20:07:15 +00:00
|
|
|
|
|
|
|
LIST_SEP="
|
|
|
|
"
|
|
|
|
|
|
|
|
append_param() {
|
2013-10-09 11:25:09 +00:00
|
|
|
local s="$1"
|
|
|
|
local v="$2"
|
2013-01-30 20:07:15 +00:00
|
|
|
case "$v" in
|
|
|
|
*_*_*_*) v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
|
|
|
|
*_*_*) v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
|
|
|
|
*_*) v=${v%%_*}-${v#*_} ;;
|
|
|
|
esac
|
2013-10-09 11:25:09 +00:00
|
|
|
echo -n "$v" >> "/var/etc/openvpn-$s.conf"
|
2013-01-30 20:07:15 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
append_bools() {
|
|
|
|
local p; local v; local s="$1"; shift
|
|
|
|
for p in $*; do
|
|
|
|
config_get_bool v "$s" "$p"
|
2014-10-14 12:21:11 +00:00
|
|
|
[ "$v" = 1 ] && append_param "$s" "$p" && echo >> "/var/etc/openvpn-$s.conf"
|
2013-01-30 20:07:15 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
append_params() {
|
|
|
|
local p; local v; local s="$1"; shift
|
|
|
|
for p in $*; do
|
|
|
|
config_get v "$s" "$p"
|
|
|
|
IFS="$LIST_SEP"
|
|
|
|
for v in $v; do
|
2013-10-09 11:25:09 +00:00
|
|
|
[ -n "$v" ] && append_param "$s" "$p" && echo " $v" >> "/var/etc/openvpn-$s.conf"
|
2013-01-30 20:07:15 +00:00
|
|
|
done
|
|
|
|
unset IFS
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
section_enabled() {
|
|
|
|
config_get_bool enable "$1" 'enable' 0
|
|
|
|
config_get_bool enabled "$1" 'enabled' 0
|
|
|
|
[ $enable -gt 0 ] || [ $enabled -gt 0 ]
|
|
|
|
}
|
|
|
|
|
2013-10-31 17:36:24 +00:00
|
|
|
openvpn_add_instance() {
|
|
|
|
local name="$1"
|
|
|
|
local dir="$2"
|
|
|
|
local conf="$3"
|
|
|
|
|
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command "$PROG" \
|
|
|
|
--syslog "openvpn($name)" \
|
|
|
|
--cd "$dir" \
|
|
|
|
--config "$conf"
|
|
|
|
procd_set_param file "$dir/$conf"
|
|
|
|
procd_close_instance
|
|
|
|
}
|
|
|
|
|
2013-01-30 20:07:15 +00:00
|
|
|
start_instance() {
|
|
|
|
local s="$1"
|
|
|
|
|
|
|
|
section_enabled "$s" || return 1
|
|
|
|
|
2013-10-09 11:25:09 +00:00
|
|
|
config_get config "$s" config
|
2013-01-30 20:07:15 +00:00
|
|
|
|
2013-10-09 11:25:09 +00:00
|
|
|
[ ! -d "/var/run" ] && mkdir -p "/var/run"
|
|
|
|
|
|
|
|
if [ ! -z "$config" ]; then
|
2013-10-31 17:36:24 +00:00
|
|
|
openvpn_add_instance "$s" "$(dirname "$config")" "$(basename "$config")"
|
2013-10-09 11:25:09 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ ! -d "/var/etc" ] && mkdir -p "/var/etc"
|
|
|
|
[ -f "/var/etc/openvpn-$s.conf" ] && rm "/var/etc/openvpn-$s.conf"
|
2013-10-07 21:28:14 +00:00
|
|
|
|
2013-01-30 20:07:15 +00:00
|
|
|
# append flags
|
|
|
|
append_bools "$s" \
|
|
|
|
auth_nocache auth_retry auth_user_pass_optional bind ccd_exclusive client client_cert_not_required \
|
2013-10-15 12:42:58 +00:00
|
|
|
client_to_client comp_noadapt disable \
|
2013-01-30 20:07:15 +00:00
|
|
|
disable_occ down_pre duplicate_cn fast_io float http_proxy_retry \
|
|
|
|
ifconfig_noexec ifconfig_nowarn ifconfig_pool_linear management_forget_disconnect management_hold \
|
|
|
|
management_query_passwords management_signal mktun mlock mtu_test multihome mute_replay_warnings \
|
|
|
|
nobind no_iv no_name_remapping no_replay opt_verify passtos persist_key persist_local_ip \
|
|
|
|
persist_remote_ip persist_tun ping_timer_rem pull push_reset \
|
|
|
|
remote_random rmtun route_noexec route_nopull single_session socks_proxy_retry \
|
|
|
|
suppress_timestamps tcp_nodelay test_crypto tls_client tls_exit tls_server \
|
|
|
|
tun_ipv6 up_delay up_restart username_as_common_name
|
|
|
|
|
|
|
|
# append params
|
|
|
|
append_params "$s" \
|
|
|
|
cd askpass auth auth_user_pass auth_user_pass_verify bcast_buffers ca cert \
|
2013-10-15 12:42:58 +00:00
|
|
|
chroot cipher client_config_dir client_connect client_disconnect comp_lzo connect_freq \
|
2013-01-30 20:07:15 +00:00
|
|
|
connect_retry connect_timeout connect_retry_max crl_verify dev dev_node dev_type dh \
|
|
|
|
echo engine explicit_exit_notify fragment group hand_window hash_size \
|
|
|
|
http_proxy http_proxy_option http_proxy_timeout ifconfig ifconfig_pool \
|
|
|
|
ifconfig_pool_persist ifconfig_push inactive ipchange iroute keepalive \
|
|
|
|
key key_method keysize learn_address link_mtu lladdr local log log_append \
|
|
|
|
lport management management_log_cache max_clients \
|
|
|
|
max_routes_per_client mode mssfix mtu_disc mute nice ns_cert_type ping \
|
|
|
|
ping_exit ping_restart pkcs12 plugin port port_share prng proto rcvbuf \
|
|
|
|
redirect_gateway remap_usr1 remote remote_cert_eku remote_cert_ku remote_cert_tls \
|
|
|
|
reneg_bytes reneg_pkts reneg_sec \
|
|
|
|
replay_persist replay_window resolv_retry route route_delay route_gateway \
|
|
|
|
route_metric route_up rport script_security secret server server_bridge setenv shaper sndbuf \
|
|
|
|
socks_proxy status status_version syslog tcp_queue_limit tls_auth \
|
|
|
|
tls_cipher tls_remote tls_timeout tls_verify tmp_dir topology tran_window \
|
2014-06-02 12:44:30 +00:00
|
|
|
tun_mtu tun_mtu_extra txqueuelen user verb down push up \
|
|
|
|
ifconfig_ipv6 route_ipv6 server_ipv6 ifconfig_ipv6_pool ifconfig_ipv6_push iroute_ipv6
|
2013-01-30 20:07:15 +00:00
|
|
|
|
2013-10-31 17:36:24 +00:00
|
|
|
openvpn_add_instance "$s" "/var/etc" "openvpn-$s.conf"
|
2013-01-30 20:07:15 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 21:28:14 +00:00
|
|
|
start_service() {
|
2013-01-30 20:07:15 +00:00
|
|
|
config_load 'openvpn'
|
|
|
|
config_foreach start_instance 'openvpn'
|
|
|
|
}
|