Package: popularity-contest
Version: 1.61
Followup-For: Bug #773663

Here is an updated version of the patch: now it checks for torsocks and it
supports a 3-state variable to enable Tor: yes/auto/no. The difference between
"always" and "auto" is that "always" prevents any fallback in case Tor cannot
be used.

Bye,
--
Federico
diff --git a/debian/control b/debian/control
index 2bf1d82..225d37e 100644
--- a/debian/control
+++ b/debian/control
@@ -14,7 +14,7 @@ Architecture: all
 Pre-Depends: debconf (>= 1.5.34) | cdebconf (>= 0.106)
 Depends: ${misc:Depends}, ${perl:Depends}, dpkg (>= 1.10), libio-socket-ip-perl (>= 0.25-3)
 Recommends: gnupg, cron | fcron, exim4 | mail-transport-agent
-Suggests: anacron
+Suggests: anacron, tor, torsocks
 Provides: popcon
 Description: Vote for your favourite packages automatically
  The popularity-contest package sets up a cron job that will
diff --git a/debian/cron.daily b/debian/cron.daily
index c45bccb..f7b2dad 100644
--- a/debian/cron.daily
+++ b/debian/cron.daily
@@ -12,8 +12,39 @@ unset MY_HOSTID
 unset PARTICIPATE
 unset SUBMITURLS
 unset USEHTTP
+unset USETOR
 unset MTAOPS
 
+TORIFY_PATH=/usr/bin/torify
+
+torify_enabled() {
+    # Return 1 to enable torify for HTTP submission, otherwise 0; exit on error
+    TORSOCKS_PATH=/usr/bin/torsocks
+    [ -f "$TORIFY_PATH" ] && [ -f "$TORSOCKS_PATH" ] && TOR_AVAILABLE=1
+
+    case "$USETOR" in
+        "always")
+            if [ -z $TOR_AVAILABLE ]; then
+                echo "popularity-contest: USETOR is set but torify is not available." 2>&1
+                echo "popularity-contest: Please install the tor and torsocks packages." 2>&1
+                exit 1
+            fi
+            if [ "yes" != "$USEHTTP" ]; then
+                echo "popularity-contest: when USETOR is set USEHTTP must be set as well" 2>&1
+                exit 1
+            fi
+            return 0
+        ;;
+        "auto")
+            [ "yes" = "$USEHTTP" ] && [ ! -z $TOR_AVAILABLE ] && return 0
+            return 1
+        ;;
+        "no")
+            return 1
+        ;;
+    esac
+}
+
 # get configuration information
 . /usr/share/popularity-contest/default.conf
 . /etc/popularity-contest.conf
@@ -31,6 +62,14 @@ if [ -z "$MAILTO" ] && [ "yes" != "$USEHTTP" ]; then exit 0; fi
 # don't run if PARTICIPATE is "no" or unset!
 if [ "$PARTICIPATE" = "no" ] || [ -z "$PARTICIPATE" ]; then exit 0; fi
 
+# enable torify
+if torify_enabled; then
+    TORIFY=$TORIFY_PATH
+else
+    TORIFY=''
+fi
+
+
 if [ -n "$HTTP_PROXY" ]; then
   export http_proxy="$HTTP_PROXY";
 fi
@@ -98,7 +137,7 @@ SUBMITTED=no
 # try to post the report through http POST
 if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
     for URL in $SUBMITURLS ; do
-	if setsid /usr/share/popularity-contest/popcon-upload \
+	if setsid $TORIFY /usr/share/popularity-contest/popcon-upload \
 	    -u $URL -f $POPCON 2>/dev/null ; then
 		SUBMITTED=yes
 	else
@@ -108,8 +147,9 @@ if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
 fi
 
 # try to email the popularity contest data
+# skip emailing if USETOR is set
 
-if [ yes != "$SUBMITTED" ] && [ "$MAILTO" ]; then
+if [ yes != "$SUBMITTED" ] && [ yes != "$USETOR" ] && [ "$MAILTO" ]; then
     if [ -x "`which sendmail 2>/dev/null`" ]; then
 	(
 	    if [ -n "$MAILFROM" ]; then
diff --git a/default.conf b/default.conf
index 433bc14..2474f45 100644
--- a/default.conf
+++ b/default.conf
@@ -51,6 +51,16 @@ SUBMITURLS="http://popcon.debian.org/cgi-bin/popcon.cgi";
 # USEHTTP enables http reporting.   Set this to 'yes' to enable it.
 USEHTTP="yes"
 
+# USETOR enables using Tor to perform http reporting.
+# In order to use Tor also set USEHTTP to "yes" and ensure that the
+# "tor" and "sockproxy" packages are installed and the tor daemon
+# is running. More information: https://www.torproject.org/
+# Supported values:
+#   always: use Tor; exit with error if not available.
+#   auto: use Tor if available.
+#   no: do not use Tor.
+USETOR="auto"
+
 # HTTP_PROXY allows to specify an HTTP proxy server, the syntax is
 # HTTP_PROXY="http://proxy:port";. This overrides the environment
 # variable http_proxy.

Reply via email to