#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib DAEMON=tinyproxy case "$1" in ""|load|start|restart|stop) if [ ! -r "/mod/etc/conf/$DAEMON.cfg" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi . /mod/etc/conf/$DAEMON.cfg ;; esac start() { if [ ! -r /tmp/flash/tinyproxy.conf ]; then echo "Copying /etc/default.tinyproxy/default.conf to flash" cp /mod/etc/default.tinyproxy/default.conf /tmp/flash/tinyproxy.conf fi if [ ! -r /tmp/flash/tinyproxy.filter ]; then echo "Copying /etc/default.tinyproxy/default.filter to flash" cp /mod/etc/default.tinyproxy/default.filter /tmp/flash/tinyproxy.filter fi { if [ -x "/tmp/flash/${DAEMON}_conf" ]; then /tmp/flash/${DAEMON}_conf else /mod/etc/default.$DAEMON/${DAEMON}_conf fi if [ -r "/tmp/flash/${DAEMON}.extra" ]; then cat /tmp/flash/${DAEMON}.extra fi } > /mod/etc/$DAEMON.conf echo -n "Starting $DAEMON server ... " $DAEMON -c /mod/etc/$DAEMON.conf exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi if [ "$TINYPROXY_CATCHALL" == "yes" ]; then echo -n "Configuring IPTABLES to make all web traffic go through tinyproxy ... " /usr/sbin/iptables -t nat -A PREROUTING -i lan -p tcp --dport 80 -j REDIRECT --to-port $TINYPROXY_PORT echo "done." fi if [ "$TINYPROXY_CONFSERVER" == "yes" ]; then echo -n "Starting the webserver for the proxy config file ... " httpd -p $TINYPROXY_CONFSERVERPORT -h /mod/usr/mww_tinyproxy echo "done." fi } stop() { echo -n "Stopping $DAEMON server..." killall $DAEMON > /dev/null 2>&1 exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' fi if [ "$TINYPROXY_CATCHALL" == "yes" ]; then echo -n "Removing tinyproxy IPTABLES rules if any ... " /usr/sbin/iptables -t nat -D PREROUTING -i lan -p tcp --dport 80 -j REDIRECT --to-port $TINYPROXY_PORT echo "done." fi if [ "$TINYPROXY_CONFSERVER" == "yes" ]; then echo -n "Stopping the webserver for the proxy config file ... " pid="$(ps aux | egrep "httpd\ -p.*tinyproxy" | cut -d ' ' -f 2)" kill -9 $pid > /dev/null 2>&1 exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' fi fi } case "$1" in ""|load) modreg cgi 'tinyproxy' 'tinyproxy' deffile='/mod/etc/default.tinyproxy/tinyproxy_conf.def' [ -r /tmp/flash/tinyproxy_conf.def ] && deffile='/tmp/flash/tinyproxy_conf.def' modreg file 'tinyproxy_conf' 'tinyproxy conf' 0 "$deffile" deffile='/mod/etc/default.tinyproxy/tinyproxy_filter.def' [ -r /tmp/flash/tinyproxy_filter.def ] && deffile='/tmp/flash/tinyproxy_filter.def' modreg file 'tinyproxy_filter' 'tinyproxy filter' 0 "$deffile" if [ "$TINYPROXY_ENABLED" != "yes" ]; then echo "$DAEMON is disabled" 1>&2 exit 1; fi start ;; unload) stop modunreg file 'tinyproxy_conf' modunreg file 'tinyproxy_filter' modunreg cgi 'tinyproxy' ;; start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) if [ -z "$(pidof "$DAEMON")" ]; then echo 'stopped' else echo 'running' fi ;; esac exit 0