From eeabfeed8ef48bb64950ece57e4715af16c583f3 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Mon, 8 Dec 2014 20:40:47 +0100 Subject: [PATCH] privoxy: moved to github and update to 3.0.22 - moved from oldpackages to github - set maintainer - update pkg source to new version 3.0.22 - run privoxy as non root user privoxy:privoxy - using procd including network events to restart on changes - log start and stop to syslog, privoxy not using syslog Signed-off-by: Christian Schoenebeck --- net/privoxy/Makefile | 168 ++++++++++++++++++++++++++++ net/privoxy/files/privoxy.config | 43 +++++++ net/privoxy/files/privoxy.init | 124 ++++++++++++++++++++ net/privoxy/files/privoxy.oldconfig | 33 ++++++ 4 files changed, 368 insertions(+) create mode 100644 net/privoxy/Makefile create mode 100644 net/privoxy/files/privoxy.config create mode 100644 net/privoxy/files/privoxy.init create mode 100644 net/privoxy/files/privoxy.oldconfig diff --git a/net/privoxy/Makefile b/net/privoxy/Makefile new file mode 100644 index 000000000..80083d27c --- /dev/null +++ b/net/privoxy/Makefile @@ -0,0 +1,168 @@ +# +# Copyright (C) 2006-2014 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=privoxy +PKG_VERSION:=3.0.22 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-stable-src.tar.gz +PKG_SOURCE_URL:=@SF/ijbswa +PKG_MD5SUM:=aa121751d332a51d37d3c6e4b7594daa + +PKG_LICENSE:=GPL-2.0 +PKG_LICENSE_FILES:=LICENSE + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)-stable +PKG_FIXUP:=autoreconf +PKG_INSTALL:=1 + +PKG_MAINTAINER:=christian.schoenebeck@gmail.com + +include $(INCLUDE_DIR)/package.mk + +define Package/privoxy + SECTION:=net + CATEGORY:=Network + SUBMENU:=Web Servers/Proxies + DEPENDS:=+libpcre +libpthread +zlib + TITLE:=web proxy with advanced filtering capabilities + URL:=http://www.privoxy.org/ + USERID:=privoxy=8118:privoxy=8118 +endef + +define Package/privoxy/description +Privoxy is a web proxy with advanced filtering capabilities for + protecting privacy, modifying web page content, managing cookies, + controlling access, and removing ads, banners, pop-ups and other + obnoxious Internet junk. Privoxy has a very flexible configuration + and can be customized to suit individual needs and tastes. Privoxy + has application for both stand-alone systems and multi-user networks. +Version: $(PKG_VERSION)-$(PKG_RELEASE) +endef + +CONFIGURE_ARGS += \ + --sysconfdir=/etc/privoxy \ + +# needed otherwise errors during compile +MAKE_FLAGS:= + +define Build/Install + $(call Build/Install/Default,) + # rename original sample config from pkg_source to save existing one during install + mv $(PKG_INSTALL_DIR)/etc/privoxy/config $(PKG_INSTALL_DIR)/etc/privoxy/config.privoxy +endef + +define Package/privoxy/conffiles +/etc/config/privoxy +/etc/privoxy/config # temporary needed if updating from old version +endef + +define Package/privoxy/preinst + #!/bin/sh + # if run within buildroot exit + [ -n "$${IPKG_INSTROOT}" ] && exit 0 + # stop service # if PKG_UPGRADE NOT WORKING + # [ "$${PKG_UPGRADE}" = "1" ] && /etc/init.d/privoxy stop + /etc/init.d/privoxy stop >/dev/null 2>&1 + exit 0 # supress errors from stop command +endef + +define Package/privoxy/install + $(INSTALL_DIR) $(1)/usr/sbin + $(CP) $(PKG_INSTALL_DIR)/usr/sbin/privoxy $(1)/usr/sbin/ + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/privoxy.init $(1)/etc/init.d/privoxy + # no longer needed because running with procd + # $(INSTALL_DIR) $(1)/etc/hotplug.d/iface + # $(INSTALL_BIN) ./files/privoxy.hotplug $(1)/etc/hotplug.d/iface/80-privoxy + + $(INSTALL_DIR) $(1)/etc/privoxy + $(CP) $(PKG_INSTALL_DIR)/etc/privoxy/* $(1)/etc/privoxy/ + # temporary needed if updating from old version + # otherwise old config file will be delete by opkg + $(INSTALL_CONF) ./files/privoxy.oldconfig $(1)/etc/privoxy/config + # create .old file to be removed with next pacakge builds during update + $(INSTALL_CONF) ./files/privoxy.oldconfig $(1)/etc/privoxy/config.old + + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_CONF) ./files/privoxy.config $(1)/etc/config/privoxy +endef + +define Package/privoxy/postinst + #!/bin/sh + + # if fresh install we don't need old config file in privoxy directory + [ "$${PKG_UPGRADE}" = "0" ] && rm -f /etc/privoxy/config + + # if run within buildroot exit here + [ -n "$${IPKG_INSTROOT}" ] && exit 0 + + # if PKG_UPGRADE then build uci configuration + # from existing(?) old /etc/privoxy/config file + if [ "$${PKG_UPGRADE}" = "1" -a -f /etc/privoxy/config ]; then + + echo "converting OLD config to NEW uci configuration" + + SECTION="privoxy.privoxy" + CFGFILE=/etc/privoxy/config + + echo -n > /etc/config/privoxy # clear/create uci configuration file + cp -f $${CFGFILE} $${CFGFILE}.old # save old configuration + + # cleanup + sed -i 's/^[ \t]*//;s/[ \t]*$$//' $${CFGFILE} # remove invisible chars at beginning and end of lines + sed -i '/^#/d' $${CFGFILE} # remove lines with "#" + sed -i '/^$$/d' $${CFGFILE} # remove empty lines + + uci -q set $${SECTION}="privoxy" # create section + + cat $${CFGFILE} | while read LINE; do + # option is first parameter; uci did not like "-" in option names + OPT=$$(echo $${LINE} | awk '{print $$1}' | sed 's/-/_/g') + VAL=$$(echo $${LINE} | awk '{print $$2}') + case $${OPT} in + # debug 1024 => debug_1024 '1' + debug) + uci -q set $${SECTION}.debug_$${VAL}="1" + ;; + # handle list values; splitted case for better reading + actionsfile|filterfile|listen_address) + uci -q add_list $${SECTION}.$${OPT}="$${VAL}" + ;; + permit_access|deny_access) + uci -q add_list $${SECTION}.$${OPT}="$${VAL}" + ;; + trust_info_url|forward) + uci -q add_list $${SECTION}.$${OPT}="$${VAL}" + ;; + forward_socks4|forward_socks4a) + uci -q add_list $${SECTION}.$${OPT}="$${VAL}" + ;; + forward_socks5|forward_socks5t) + uci -q add_list $${SECTION}.$${OPT}="$${VAL}" + ;; + # all others are normal options + *) + uci -q set $${SECTION}.$${OPT}="$${VAL}" + ;; + esac + done + uci -q commit privoxy # commit changes + rm -f $${CFGFILE} # remove old configuration file + fi + + # set permissions to privoxy group + echo "setting permissions" + chgrp -R privoxy /etc/privoxy/* + chmod 664 /etc/privoxy/* + chmod 755 /etc/privoxy/templates + chmod 644 /etc/privoxy/templates/* +endef + +$(eval $(call BuildPackage,privoxy)) diff --git a/net/privoxy/files/privoxy.config b/net/privoxy/files/privoxy.config new file mode 100644 index 000000000..50e401f9a --- /dev/null +++ b/net/privoxy/files/privoxy.config @@ -0,0 +1,43 @@ +# this file support all available configuration options of +# Privoxy web-proxy +# the scripts move all options to the final privoxy readable configuration file +# +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# !!! privoxy uses "-" in option names but uci only support "_" !!! +# !!! privoxy "listen-address" must be uci "listen_address" !!! +# !!! !!! +# !!! if you add entries please use !!! +# !!! option for options with one parameter (option confdir) !!! +# !!! list for options with multiple parameters (list listen_address) !!! +# !!! !!! +# !!! special handling for debug option !!! +# !!! privoxy option "debug 1024" must be uci option debug_1024 '1' !!! +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# +config privoxy 'privoxy' + option confdir '/etc/privoxy' + option logdir '/var/log' + option logfile 'privoxy.log' + list filterfile 'default.filter' + list actionsfile 'match-all.action' + list actionsfile 'default.action' +# list actionsfile 'user.action' + list listen_address '127.0.0.1:8118' + list listen_address '192.168.1.1:8118' + option toggle '1' + option enable_remote_toggle '1' + option enable_remote_http_toggle '0' + option enable_edit_actions '1' + option enforce_blocks '0' + option buffer_limit '4096' + option forwarded_connect_retries '0' + option accept_intercepted_requests '0' + option allow_cgi_request_crunching '0' + option split_large_forms '0' + option keep_alive_timeout '300' + option socket_timeout '300' + list permit_access '192.168.1.0/24' + option debug_1 '0' + option debug_1024 '0' + option debug_4096 '1' + option debug_8192 '1' diff --git a/net/privoxy/files/privoxy.init b/net/privoxy/files/privoxy.init new file mode 100644 index 000000000..8ea6d6f5d --- /dev/null +++ b/net/privoxy/files/privoxy.init @@ -0,0 +1,124 @@ +#!/bin/sh /etc/rc.common + +START=80 +USE_PROCD=1 + +PIDFILE=/var/run/privoxy.pid +CFGFILE=/var/etc/privoxy.conf +CFGTEMP=/var/etc/privoxy.conf.tmp + +_uci2conf() { + local _LOGDIR="/var/log" # set default + local _LOGFILE="privoxy.log" # set default + + # redefined callback for options when calling config_load + option_cb() + { + # $1 name of variable + # $2 value + local __OPT="$1" + local __VAL="$2" + case $__OPT in + logdir) # logdir handled later + _LOGDIR="$__VAL" ;; + logfile) # logfile handled later + _LOGFILE="$__VAL" ;; + *) + # detect list options (LENGTH) and ignore + echo $__OPT | grep -i "_LENGTH" >/dev/null 2>&1 && return + # detect list options (ITEM) and ignore + echo $__OPT | grep -i "_ITEM" >/dev/null 2>&1 && __OPT=$(echo $__OPT | sed -e "s#_ITEM.##g") + # filter debug_* + echo $__OPT | grep -i "debug_" >/dev/null 2>&1 && { + [ $__VAL -eq 0 ] && return # not set ignore + __VAL=$(echo $__OPT | sed -e "s#debug_##g") + __OPT="debug" + } + # uci only accept "_" but we need "-" + local __OPT=$(echo $__OPT | sed -e "s#_#-#g") + # write to config + echo -e "$__OPT\t$__VAL" >> $CFGTEMP + ;; + esac + } + + mkdir -m0755 -p /var/etc + echo "" > $CFGTEMP # create tmp config file + chmod 644 $CFGTEMP # garantee that privoxy can read + chgrp privoxy $CFGTEMP + + echo '### AUTO-GENERATED CONFIGURATION' >> $CFGTEMP + echo '### USED BY PRIVOXY' >> $CFGTEMP + echo '### DO NOT EDIT' >> $CFGTEMP + echo '### SEE /etc/config/privoxy INSTEAD' >> $CFGTEMP + echo '' >> $CFGTEMP + + config_load privoxy # calling above option_cb() + + # write logdir/logfile to config + echo -e "logdir\t$_LOGDIR" >> $CFGTEMP + echo -e "logfile\t$_LOGFILE" >> $CFGTEMP + + # create logfile and set permissions + touch $_LOGDIR/$_LOGFILE + chmod 664 $_LOGDIR/$_LOGFILE + chown privoxy:privoxy $_LOGDIR/$_LOGFILE + + # move temp to final privoxy readable configuration + mv -f $CFGTEMP $CFGFILE +} + +# privoxy should auto-reload it's configuration +# but it only reload on next connect to one of the listen_address +# if we create a new listen_address privoxy never reload +reload_service() { + # so we restart here because rc.common reload_service only start without stopping + restart "$@" + + # the following should normally work but see above +# _uci2conf # convert uci config +} + +service_triggers() { + procd_add_reload_trigger "privoxy" +} + +start_service() { + # redefined callback for sections when calling config_load + config_cb() { + # $1 type of config section + # $2 name of section + [ "$1" = "interface" ] && \ + procd_add_interface_trigger interface.* $2 /etc/init.d/privoxy restart + } + + _uci2conf # convert uci config + + procd_open_instance + + procd_set_param command /usr/sbin/privoxy + procd_append_param command --no-daemon # for procd run in foreground + procd_append_param command --pidfile $PIDFILE # set pid file + procd_append_param command --user privoxy.privoxy # set user + procd_append_param command $CFGFILE # config file + + procd_set_param file $CFGFILE # set configration file + + procd_open_trigger # we need a restart on interface events not a reload + config_load network # load network configuration and set trigger(s) in config_cb() above + procd_close_trigger + + procd_close_instance +} + +service_running() { + logger_trick() { + sleep 1 # give privoxy time to completely come up + logger -p daemon.notice -t "privoxy[$(cat $PIDFILE)]" "Service started successfully" + } + logger_trick & +} + +stop_service() { + logger -p daemon.notice -t "privoxy[$(cat $PIDFILE)]" "Service shutdown" +} diff --git a/net/privoxy/files/privoxy.oldconfig b/net/privoxy/files/privoxy.oldconfig new file mode 100644 index 000000000..9496356dc --- /dev/null +++ b/net/privoxy/files/privoxy.oldconfig @@ -0,0 +1,33 @@ +# +# original configuration file used by privoxy +# this is no longer supported by this package +# it's converted and moved to uci configuration +# please look at /etc/config/privoxy +# +confdir /etc/privoxy +logdir /var/log +logfile privoxy.log +filterfile default.filter +actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on. +actionsfile default.action # Main actions file +#actionsfile user.action # User customizations +listen-address 127.0.0.1:8118 +toggle 1 +enable-remote-toggle 1 +enable-remote-http-toggle 0 +enable-edit-actions 1 +enforce-blocks 0 +buffer-limit 4096 +forwarded-connect-retries 0 +accept-intercepted-requests 0 +allow-cgi-request-crunching 0 +split-large-forms 0 +keep-alive-timeout 300 +socket-timeout 300 +permit-access 192.168.1.0/24 +debug 1 # show each GET/POST/CONNECT request +debug 4096 # Startup banner and warnings +debug 8192 # Errors - *we highly recommended enabling this* +#admin-address privoxy-admin@example.com +#proxy-info-url http://www.example.com/proxy-service.html +