openvpn: switch to new procd init script style
[openwrt/staging/chunkeey.git] / package / network / services / openvpn / files / openvpn.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2013 OpenWrt.org
3 # Copyright (C) 2008 Jo-Philipp Wich
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6
7 START=90
8 STOP=10
9
10 USE_PROCD=1
11 PROG=/usr/sbin/openvpn
12
13 LIST_SEP="
14 "
15
16 append_param() {
17 local v="$1"
18 case "$v" in
19 *_*_*_*) v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
20 *_*_*) v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
21 *_*) v=${v%%_*}-${v#*_} ;;
22 esac
23 procd_append_param command --"$v"
24 return 0
25 }
26
27 append_bools() {
28 local p; local v; local s="$1"; shift
29 for p in $*; do
30 config_get_bool v "$s" "$p"
31 [ "$v" == 1 ] && append_param "$p"
32 done
33 }
34
35 append_params() {
36 local p; local v; local s="$1"; shift
37 for p in $*; do
38 config_get v "$s" "$p"
39 IFS="$LIST_SEP"
40 for v in $v; do
41 [ -n "$v" ] && append_param "$p" && procd_append_param command "$v"
42 done
43 unset IFS
44 done
45 }
46
47 section_enabled() {
48 config_get_bool enable "$1" 'enable' 0
49 config_get_bool enabled "$1" 'enabled' 0
50 [ $enable -gt 0 ] || [ $enabled -gt 0 ]
51 }
52
53 start_instance() {
54 local s="$1"
55
56 section_enabled "$s" || return 1
57
58 ARGS=""
59
60 procd_open_instance
61 procd_set_param command "$PROG" --syslog "openvpn($s)" --writepid "/var/run/openvpn-$s.pid"
62
63 # append flags
64 append_bools "$s" \
65 auth_nocache auth_retry auth_user_pass_optional bind ccd_exclusive client client_cert_not_required \
66 client_to_client comp_lzo comp_noadapt disable \
67 disable_occ down_pre duplicate_cn fast_io float http_proxy_retry \
68 ifconfig_noexec ifconfig_nowarn ifconfig_pool_linear management_forget_disconnect management_hold \
69 management_query_passwords management_signal mktun mlock mtu_test multihome mute_replay_warnings \
70 nobind no_iv no_name_remapping no_replay opt_verify passtos persist_key persist_local_ip \
71 persist_remote_ip persist_tun ping_timer_rem pull push_reset \
72 remote_random rmtun route_noexec route_nopull single_session socks_proxy_retry \
73 suppress_timestamps tcp_nodelay test_crypto tls_client tls_exit tls_server \
74 tun_ipv6 up_delay up_restart username_as_common_name
75
76 # append params
77 append_params "$s" \
78 cd askpass auth auth_user_pass auth_user_pass_verify bcast_buffers ca cert \
79 chroot cipher client_config_dir client_connect client_disconnect config connect_freq \
80 connect_retry connect_timeout connect_retry_max crl_verify dev dev_node dev_type dh \
81 echo engine explicit_exit_notify fragment group hand_window hash_size \
82 http_proxy http_proxy_option http_proxy_timeout ifconfig ifconfig_pool \
83 ifconfig_pool_persist ifconfig_push inactive ipchange iroute keepalive \
84 key key_method keysize learn_address link_mtu lladdr local log log_append \
85 lport management management_log_cache max_clients \
86 max_routes_per_client mode mssfix mtu_disc mute nice ns_cert_type ping \
87 ping_exit ping_restart pkcs12 plugin port port_share prng proto rcvbuf \
88 redirect_gateway remap_usr1 remote remote_cert_eku remote_cert_ku remote_cert_tls \
89 reneg_bytes reneg_pkts reneg_sec \
90 replay_persist replay_window resolv_retry route route_delay route_gateway \
91 route_metric route_up rport script_security secret server server_bridge setenv shaper sndbuf \
92 socks_proxy status status_version syslog tcp_queue_limit tls_auth \
93 tls_cipher tls_remote tls_timeout tls_verify tmp_dir topology tran_window \
94 tun_mtu tun_mtu_extra txqueuelen user verb down push up
95
96
97 procd_close_instance
98 }
99
100 start_service() {
101 config_load 'openvpn'
102 config_foreach start_instance 'openvpn'
103 }