From ed95c54a38bcd780c5801de74b0f05a83740d8d7 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Tue, 14 Jul 2009 11:25:17 +0000 Subject: [PATCH] [package] add init and configuration files for sslh (#5500) SVN-Revision: 16838 --- net/sslh/Makefile | 7 +- net/sslh/files/sslh.config | 43 +++++++++++++ net/sslh/files/sslh.init | 129 +++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 net/sslh/files/sslh.config create mode 100644 net/sslh/files/sslh.init diff --git a/net/sslh/Makefile b/net/sslh/Makefile index 02790f4a2b..a5052f74c0 100644 --- a/net/sslh/Makefile +++ b/net/sslh/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=sslh PKG_VERSION:=1.6i -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://rutschle.net/tech/ @@ -35,7 +35,10 @@ endef 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)) - diff --git a/net/sslh/files/sslh.config b/net/sslh/files/sslh.config new file mode 100644 index 0000000000..a4c5abad6f --- /dev/null +++ b/net/sslh/files/sslh.config @@ -0,0 +1,43 @@ +package 'sslh' + +config 'sslh' 'default' +# disable or enable + option 'enable' '1' +# listen defaults to '0.0.0.0:443' (all interfaces) +# -p : + option 'listen' '' +# ssh defaults to 'localhost:22' +# -s : + option 'ssh' '' +# ssl defaults to 'localhost:442' +# -l : + option 'ssl' '' +# timeout (for ssh, then ssl is assumed) defaults to 2 +# -t + option 'timeout' '' +# verbose defaults to off +# -v + option 'verbose' '0' +package 'sslh' + +config 'sslh' 'default' + # disable or enable start of sslh + option 'enable' '1' + # listen defaults to '0.0.0.0:443' (all interfaces) + # -p : + option 'listen' '' + # ssh defaults to 'localhost:22' + # -s : + option 'ssh' '' + # ssl defaults to 'localhost:442' + # -l : + option 'ssl' '' + # pid file defaults to /var/run/sslh.pid + # -P pidfile + option 'pidfile' '' + # timeout (for ssh, then ssl is assumed) defaults to 2 + # -t + option 'timeout' '' + # verbose defaults to off + # -v + option 'verbose' '0' diff --git a/net/sslh/files/sslh.init b/net/sslh/files/sslh.init new file mode 100644 index 0000000000..8c110ed00a --- /dev/null +++ b/net/sslh/files/sslh.init @@ -0,0 +1,129 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2009 OpenWrt.org + +NAME=sslh +PROG=/usr/sbin/sslh +START=95 +PIDCOUNT=0 + +sslh_start() +{ + local section="$1" + + # check if section is enabled (default) + local enabled + config_get_bool enabled "${section}" enable 1 + [ ${enabled} -eq 0 ] && return 1 + + # increase pid file count to handle multiple instances correctly + PIDCOUNT="$(( ${PIDCOUNT} + 1 ))" + + # prepare parameters (initialise with pid file) + local args="-P /var/run/${NAME}.${PIDCOUNT}.pid" + local val + # A) listen parameter + config_get val "${section}" listen + [ ! -z ${val} ] && append args "-p ${val}" + # B) ssh parameter + config_get val "${section}" ssh + [ ! -z ${val} ] && append args "-s ${val}" + # C) ssl parameter + config_get val "${section}" ssl + [ ! -z ${val} ] && append args "-l ${val}" + # D) timeout (for ssh, then ssl is assumed) + config_get val "${section}" timeout + [ ! -z ${val} ] && append args "-t ${val}" + # E) verbose parameter + local verbosed + config_get_bool verbosed "${section}" verbose 0 + [ ${verbosed} -ne 0 ] && append args "-v" + + # execute program and return its exit code + [ ${verbosed} -ne 0 ] && echo "${NAME}: section ${section} starting ${PROG} ${args}" + ${PROG} ${args} + return $? +} + +start() +{ + config_load "${NAME}" + config_foreach sslh_start sslh +} + +stop() +{ + local pidfile + local rc=0 + + # killing all known processes + for pidfile in `ls /var/run/${NAME}.*.pid` + do + start-stop-daemon -K -s KILL -p "${pidfile}" -n "${NAME}" + [ $? -ne 0 ] && rc=1 + rm -f "${pidfile}" + done + + # kill orphaned processes + if [ ${rc} -ne 0 ] + then + echo "${NAME}: inconsistency in pid files killing all orphaned processes" + for pid in `pidof sslh` + do + # check if correct program + ps | grep ${pid} | grep ${PROG} >/dev/null + [ $? -ne 0 ] && continue + + # kill process + echo "Killing ${pid}..." + kill -s KILL ${pid} + done + fi +} +#!/bin/sh /etc/rc.common +# Copyright (C) 2009 OpenWrt.org + +NAME="$(basename "${initscript}")" +PROG=/usr/sbin/${NAME} +START=95 + +start() +{ + # load config into variables + uci_load "${NAME}" + + # check if enabled + local enabled + config_get_bool enabled 'default' 'enable' 0 + if [ ${enabled} -eq 0 ] + then + echo "${NAME} is not enabled" + return 1 + fi + + # prepare parameters + local ARGS='' + # A) listen parameter + [ ! -z ${CONFIG_default_listen} ] && ARGS="${ARGS} -p ${CONFIG_default_listen}" + # B) ssh parameter + [ ! -z ${CONFIG_default_ssh} ] && ARGS="${ARGS} -s ${CONFIG_default_ssh}" + # C) ssl parameter + [ ! -z ${CONFIG_default_ssl} ] && ARGS="${ARGS} -l ${CONFIG_default_ssl}" + # D) pid file + [ ! -z ${CONFIG_default_pidfile} ] && ARGS="${ARGS} -P ${CONFIG_default_pidfile}" + # E) timeout (for ssh, then ssl is assumed) + [ ! -z ${CONFIG_default_timeout} ] && ARGS="${ARGS} -t ${CONFIG_default_timeout}" + # F) verbose parameter + local verbosed + config_get_bool verbosed 'default' 'verbose' 0 + [ ${verbosed} -ne 0 ] && ARGS="${ARGS} -v" + + # execute command and return its exit code + [ ${verbosed} -ne 0 ] && echo "Starting ${PROG} ${ARGS}" + ${PROG} ${ARGS} + return $? +} + +stop() +{ + killall "${NAME}" +} -- 2.30.2