Adopted sslh to uci config.
Config allows for configuring all possible options.
Allows only one instance.

Create files directory in package folder and apply patch from the
feeds/packages folder.

Didn't know if I should have updated the package revision to 2.
If so please do.

sslh is working fine and could be added to the 8.0.9 branch, if it isn't
already.

Signed-off-by: Maddes <m...@maddes.net>

Good night.
Maddes

Index: net/sslh/files/sslh.init
===================================================================
--- net/sslh/files/sslh.init    (revision 0)
+++ net/sslh/files/sslh.init    (revision 0)
@@ -0,0 +1,168 @@
+#!/bin/sh /etc/rc.common
+
+START=95
+
+start()
+{
+  local RC=0
+
+## load config into variables
+  uci_load 'sslh'
+
+## check parameters
+# A) pid file is mandatory
+  if [ -z ${CONFIG_default_pidfile} ]
+   then
+    echo 'sslh: pidfile not stated, but mandatory (default is 
/var/run/sslh.pid)'
+    RC=1
+  fi
+# B) host and port are mandatory if one of them is stated
+  local failed
+# B1) listen
+  failed=0
+  [ ! -z ${CONFIG_default_listenaddr} ] && [   -z ${CONFIG_default_listenport} 
] && failed=1
+  [   -z ${CONFIG_default_listenaddr} ] && [ ! -z ${CONFIG_default_listenport} 
] && failed=1
+  if [ ${failed} -eq 1 ]
+   then
+    echo 'sslh: listen address and port must be stated'
+    RC=1
+  fi
+# B2) ssh
+  failed=0
+  [ ! -z ${CONFIG_default_sshhost} ] && [   -z ${CONFIG_default_sshport} ] && 
failed=1
+  [   -z ${CONFIG_default_sshhost} ] && [ ! -z ${CONFIG_default_sshport} ] && 
failed=1
+  if [ ${failed} -eq 1 ]
+   then
+    echo 'sslh: ssh host and port must be stated'
+    RC=1
+  fi
+# B3) ssl
+  failed=0
+  [ ! -z ${CONFIG_default_sslhost} ] && [   -z ${CONFIG_default_sslport} ] && 
failed=1
+  [   -z ${CONFIG_default_sslhost} ] && [ ! -z ${CONFIG_default_sslport} ] && 
failed=1
+  if [ ${failed} -eq 1 ]
+   then
+    echo 'sslh: ssl host and port must be stated'
+    RC=1
+  fi
+
+## check if sslh is already running with this pid file
+  if [ ! -z ${CONFIG_default_pidfile} ]
+   then
+    start-stop-daemon -K -t -q -p ${CONFIG_default_pidfile} -n sslh
+    if [ $? -eq 0 ]
+     then
+      echo "sslh: already running with pidfile ${CONFIG_default_pidfile}"
+      RC=1
+    fi
+  fi
+
+## leave if any check failed
+  [ ${RC} -ne 0 ] && return ${RC}
+
+## check if sslh is enabled
+  local enabled=0
+  config_get_bool enabled 'default' 'enable' 0
+  if [ ${enabled} -eq 0 ]
+   then
+    echo 'sslh is not enabled'
+    return 1
+  fi
+
+## prepare parameters (initialise with pid file)
+  local SSLHARGS="-P ${CONFIG_default_pidfile}"
+#
+  local option
+  local added
+# A) listen parameter
+  option='-p'
+  added=0
+  if [ ! -z ${CONFIG_default_listenaddr} ]
+   then
+    SSLHARGS="${SSLHARGS} ${option} "
+    SSLHARGS="${SSLHARGS}${CONFIG_default_listenaddr}"
+    added=1
+  fi
+  if [ ! -z ${CONFIG_default_listenport} ]
+   then
+    [ ${added} -eq 0 ] && SSLHARGS="${SSLHARGS} ${option} "
+    SSLHARGS="${SSLHARGS}:${CONFIG_default_listenport}"
+  fi
+# B) ssh parameter
+  option='-s'
+  added=0
+  if [ ! -z ${CONFIG_default_sshhost} ]
+   then
+    SSLHARGS="${SSLHARGS} ${option} "
+    SSLHARGS="${SSLHARGS}${CONFIG_default_sshhost}"
+    added=1
+  fi
+  if [ ! -z ${CONFIG_default_sshport} ]
+   then
+    [ ${added} -eq 0 ] && SSLHARGS="${SSLHARGS} ${option} "
+    SSLHARGS="${SSLHARGS}:${CONFIG_default_sshport}"
+  fi
+# C) ssl parameter
+  option='-l'
+  added=0
+  if [ ! -z ${CONFIG_default_sslhost} ]
+   then
+    SSLHARGS="${SSLHARGS} ${option} "
+    SSLHARGS="${SSLHARGS}${CONFIG_default_sslhost}"
+    added=1
+  fi
+  if [ ! -z ${CONFIG_default_sslport} ]
+   then
+    [ ${added} -eq 0 ] && SSLHARGS="${SSLHARGS} ${option} "
+    SSLHARGS="${SSLHARGS}:${CONFIG_default_sslport}"
+  fi
+# D) timeout (for ssh, then ssl is assumed)
+  if [ ! -z ${CONFIG_default_timeout} ]
+   then
+    SSLHARGS="${SSLHARGS} -t ${CONFIG_default_timeout}"
+  fi
+# E) verbose parameter
+  local verbosed=0
+  config_get_bool verbosed 'default' 'verbose' 0
+  if [ ${verbosed} -eq 1 ]
+   then
+    SSLHARGS="${SSLHARGS} -v"
+  fi
+#
+  if [ ${verbosed} -eq 1 ]
+   then
+    echo "Starting sslh ${SSLHARGS}"
+  fi
+
+## execute command and return its exit code
+  sslh ${SSLHARGS}
+  RC=$?
+  return ${RC}
+};
+
+
+stop()
+{
+  local RC=0
+
+## load config into variables
+  uci_load 'sslh'
+
+## check parameters
+# pid file is mandatory
+  if [ -z ${CONFIG_default_pidfile} ]
+   then
+    echo 'sslh: pidfile not stated, but mandatory (default is 
/var/run/sslh.pid)'
+    RC=1
+  fi
+
+## execute command and return its exit code
+  start-stop-daemon -K -q -p ${CONFIG_default_pidfile} -n sslh
+  RC=$?
+  if [ ${RC} -eq 0 ]
+   then
+    rm -f ${CONFIG_default_pidfile}
+  fi
+
+  return ${RC}
+};
Index: net/sslh/files/sslh.config
===================================================================
--- net/sslh/files/sslh.config  (revision 0)
+++ net/sslh/files/sslh.config  (revision 0)
@@ -0,0 +1,26 @@
+package 'sslh'
+
+config 'sslh' 'default'
+# disable or enable start of sslh
+    option 'enable' '1'
+# pid file is OBLIGATORY, defaults to /var/run/sslh.pid
+# -P pidfile
+    option 'pidfile' '/var/run/sslh.pid'
+# listen defaults to 0.0.0.0:443 (all interfaces)
+# -p <listenaddr>:<listenport>
+    option 'listenaddr' ''
+    option 'listenport' ''
+# ssh defaults to localhost:22
+# -s <sshhost>:<sshport>
+    option 'sshhost' ''
+    option 'sshport' ''
+# ssl defaults to localhost:442
+# -l <sslhost>:<sslport>
+    option 'sslhost' ''
+    option 'sslport' ''
+# timeout (for ssh, then ssl is assumed) defaults to 2
+# -t
+    option 'timeout' ''
+# verbose defaults to off
+# -v
+    option 'verbose' '0'
Index: net/sslh/Makefile
===================================================================
--- net/sslh/Makefile   (revision 16741)
+++ net/sslh/Makefile   (working copy)
@@ -35,6 +35,10 @@
 define Package/sslh/install
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/sslh $(1)/usr/sbin/
+       $(INSTALL_DIR) $(1)/etc/init.d/
+       $(INSTALL_BIN) files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) files/$(PKG_NAME).config $(1)/etc/config/$(PKG_NAME)
 endef
 
 $(eval $(call BuildPackage,sslh))
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to