From 186f61070822ad037b328ebfd04f6d2f0008522e Mon Sep 17 00:00:00 2001
From: James Valleroy
Date: Wed, 26 Mar 2014 23:27:59 -0400
Subject: [PATCH] Add tor information page.
---
actions/tor-get-ports | 28 +++++++++++++
modules/installed/privacy/privacy.py | 3 +-
modules/installed/privacy/tor.py | 61 ++++++++++++++++++++++++++++
modules/tor.py | 1 +
4 files changed, 91 insertions(+), 2 deletions(-)
create mode 100755 actions/tor-get-ports
create mode 100644 modules/installed/privacy/tor.py
create mode 120000 modules/tor.py
diff --git a/actions/tor-get-ports b/actions/tor-get-ports
new file mode 100755
index 000000000..de50f4237
--- /dev/null
+++ b/actions/tor-get-ports
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+#
+# This file is part of Plinth.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+
+# Action to get ports used by Tor.
+
+echo "ORPort" `tor-get-orport`
+
+transports="obfs3 scramblesuit"
+for transport in $transports
+do
+ echo $transport `grep $transport /var/lib/tor/state | awk -F'[: ]*' '{print $4}'`
+done
diff --git a/modules/installed/privacy/privacy.py b/modules/installed/privacy/privacy.py
index 12517e370..802c42f81 100644
--- a/modules/installed/privacy/privacy.py
+++ b/modules/installed/privacy/privacy.py
@@ -12,7 +12,6 @@ class Privacy(PagePlugin):
self.menu = cfg.main_menu.add_item("Privacy", "icon-eye-open", "/privacy", 12)
self.menu.add_item("General Config", "icon-asterisk", "/privacy/config", 10)
self.menu.add_item("Ad Blocking", "icon-ban-circle", "/privacy/adblock", 20)
- self.menu.add_item("TOR", "icon-eye-close", "/privacy/TOR", 30)
self.menu.add_item("HTTPS Everywhere", "icon-lock", "/privacy/https_everywhere", 30)
@cherrypy.expose
@@ -38,5 +37,5 @@ information on it.
Your personal information should not leave this box without your
knowledge and direction. And if companies or government wants this
information, they have to ask you for it. This gives you a
-change to refuse and also tells you who wants your data.
+chance to refuse and also tells you who wants your data.
""") % cfg.product_name)
diff --git a/modules/installed/privacy/tor.py b/modules/installed/privacy/tor.py
new file mode 100644
index 000000000..78a60d068
--- /dev/null
+++ b/modules/installed/privacy/tor.py
@@ -0,0 +1,61 @@
+#
+# This file is part of Plinth.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+
+"""
+Plinth module for configuring Tor
+"""
+
+import cherrypy
+from gettext import gettext as _
+from plugin_mount import PagePlugin
+from modules.auth import require
+import actions
+import cfg
+
+class tor(PagePlugin):
+ order = 30 # order of running init in PagePlugins
+ def __init__(self, *args, **kwargs):
+ PagePlugin.__init__(self, *args, **kwargs)
+ self.register_page("privacy.tor")
+ cfg.html_root.privacy.menu.add_item("Tor", "icon-eye-close", "/privacy/tor", 30)
+
+ @cherrypy.expose
+ @require()
+ def index(self):
+ output, error = actions.superuser_run("tor-get-ports")
+ port_info = output.split("\n")
+ ports = {}
+ for line in port_info:
+ try:
+ (key, val) = line.split()
+ ports[key] = val
+ except ValueError:
+ continue
+
+ main = _("""
+ Tor is an anonymous communication system. You can learn more about it from the Tor Project website. For best protection when web surfing, the Tor Project recommends that you use the Tor Browser Bundle.
+ A Tor SOCKS port is available on your FreedomBox on TCP port 9050.
+ Your FreedomBox is configured as a Tor bridge with obfsproxy, so it can help circumvent censorship. If your FreedomBox is behind a router or firewall, you should make sure the following ports are open, and port-forwarded, if necessary:
+ """)
+
+ main += ''
+ for key in ports:
+ main += "| " + str(key) + " | "
+ main += "" + str(ports[key]) + " |
"
+ main += "
"
+
+ return self.fill_template(title=_("Tor Control Panel"), main=main)
diff --git a/modules/tor.py b/modules/tor.py
new file mode 120000
index 000000000..28c310568
--- /dev/null
+++ b/modules/tor.py
@@ -0,0 +1 @@
+installed/privacy/tor.py
\ No newline at end of file