b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #!/bin/sh /etc/rc.common |
| 2 | # Copyright (C) 2009-2017 OpenWrt.org |
| 3 | |
| 4 | START=95 |
| 5 | |
| 6 | # XXX: pid-files are useless because sslh forks after creating them |
| 7 | SERVICE_USE_PID= |
| 8 | |
| 9 | start_instance() { |
| 10 | local section="$1" |
| 11 | |
| 12 | # check if section is enabled (default) |
| 13 | local enable |
| 14 | config_get_bool enable "${section}" 'enable' '0' |
| 15 | [ ${enable} -gt 0 ] || return 1 |
| 16 | |
| 17 | local args="" |
| 18 | local val |
| 19 | # A) listen parameter |
| 20 | config_get vals "${section}" listen |
| 21 | [ -n "${vals}" ] && for val in $vals; do append args "-p${val}"; done |
| 22 | # B) ssh parameter |
| 23 | config_get val "${section}" ssh |
| 24 | [ -n "${val}" ] && append args "--ssh ${val}" |
| 25 | # C) tls parameter |
| 26 | config_get val "${section}" tls |
| 27 | [ -n "${val}" ] && append args "--tls ${val}" |
| 28 | # D) openvpn parameter |
| 29 | config_get val "${section}" openvpn |
| 30 | [ -n "${val}" ] && append args "--openvpn ${val}" |
| 31 | # E) tinc parameter |
| 32 | config_get val "${section}" tinc |
| 33 | [ -n "${val}" ] && append args "--tinc ${val}" |
| 34 | # F) xmpp parameter |
| 35 | config_get val "${section}" xmpp |
| 36 | [ -n "${val}" ] && append args "--xmpp ${val}" |
| 37 | # G) timeout (before a connection is considered to be SSH) |
| 38 | config_get val "${section}" timeout |
| 39 | [ -n "${val}" ] && append args "-t ${val}" |
| 40 | # H) verbose parameter |
| 41 | local verbosed |
| 42 | config_get_bool verbosed "${section}" verbose 0 |
| 43 | [ "${verbosed}" -ne 0 ] && append args "-v" |
| 44 | # I) sslh config file (cmd line args override file settings) |
| 45 | config_get val "${section}" configfile |
| 46 | [ -n "${val}" ] && append args "-F${val}" |
| 47 | # J) http parameter |
| 48 | config_get val "${section}" http |
| 49 | [ -n "${val}" ] && append args "--http ${val}" |
| 50 | # K) transparent parameter |
| 51 | config_get_bool val "${section}" transparent 0 |
| 52 | [ "${val}" -ne 0 ] && append args "--transparent" |
| 53 | |
| 54 | # Defaults were removed for --user and --pidfile options |
| 55 | # in sslh 1.11; Define them here instead. |
| 56 | append args "--user nobody" |
| 57 | append args "--pidfile /var/run/sslh.pid" |
| 58 | |
| 59 | # XXX: allow more that one instance to run simultaneously |
| 60 | SERVICE_MATCH_NAME=1 SERVICE_NAME="sslh-dummy-$$" \ |
| 61 | service_start /usr/sbin/sslh ${args} |
| 62 | } |
| 63 | |
| 64 | start() { |
| 65 | config_load 'sslh' |
| 66 | config_foreach start_instance 'sslh' |
| 67 | } |
| 68 | |
| 69 | stop() { |
| 70 | service_stop /usr/sbin/sslh |
| 71 | } |