Skip to content

Commit c6e26b3

Browse files
committed
tor2web packaged for pip
1 parent 83032b2 commit c6e26b3

File tree

13 files changed

+78
-53
lines changed

13 files changed

+78
-53
lines changed

contrib/debian/tor2web.init

+4-14
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
2525
NAME=tor2web
2626
DAEMON=twistd
27-
DAEMON_ENV=/home/tor2web/t2wenv/bin/activate
2827
DAEMON_DIR=/home/tor2web/Tor2web-3.0
2928
DAEMON_PIDFILE=${DAEMON_DIR}/tor2web.pid
3029
DAEMON_USER=tor2web
31-
DAEMON_ARGS="--pidfile ${DAEMON_PIDFILE} --uid ${DAEMON_USER} --gid ${DAEMON_USER} -y ${DAEMON_DIR}/t2w.py"
30+
DAEMON_ARGS="--pidfile ${DAEMON_PIDFILE} --uid ${DAEMON_USER} --gid ${DAEMON_USER} -y ${DAEMON_DIR}/tor2web/t2w.py"
3231

3332
NAME=$(basename $(readlink -nf $0))
3433

@@ -72,7 +71,7 @@ else
7271
MAX_FILEDESCRIPTORS=8192
7372
fi
7473

75-
do_setup_env()
74+
checks()
7675
{
7776
if [[ $EUID -ne 0 ]]; then
7877
log_failure_msg "Error: Tor2web init script must be run as root"
@@ -87,15 +86,6 @@ do_setup_env()
8786
exit 1
8887
fi
8988

90-
if [ ! -f ${DAEMON_ENV} ]
91-
then
92-
log_failure_msg "invalid DAEMON_ENV: ${DAEMON_ENV}"
93-
log_end_msg 1
94-
exit 1
95-
fi
96-
97-
. ${DAEMON_ENV}
98-
9989
DAEMON=`which twistd`
10090
if [ ! ${DAEMON} ]; then
10191
log_end_msg 1 "twistd is not installed"
@@ -105,7 +95,7 @@ do_setup_env()
10595

10696
do_t2w_start()
10797
{
108-
do_setup_env
98+
checks
10999

110100
if [ -n "$MAX_FILEDESCRIPTORS" ]; then
111101
ulimit -n "$MAX_FILEDESCRIPTORS"
@@ -128,7 +118,7 @@ do_t2w_start()
128118

129119
do_t2w_stop()
130120
{
131-
do_setup_env
121+
checks
132122

133123
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile ${DAEMON_PIDFILE}
134124
}

tor2web.conf.example renamed to data/tor2web.conf.example

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
nodename = [UNIQUE_IDENTIFIER]
66

77
# path to Tor2web data directort
8-
datadir = ./data
8+
datadir = /home/tor2web/Tor2web-3.0/data
99

1010
# debug and logging
1111
debugtostdout = False
@@ -33,7 +33,8 @@ sockretryautomatically = True
3333
cipher_list = DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:RC4-SHA
3434

3535
# Access Blocking
36-
blocklists = True
36+
mode = BLACKLIST
37+
onion = None
3738
blockcrawl = True
3839

3940
# Mail configuration for automatic exceptions notification and user abuse notice

setup.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[egg_info]
2+
tag_build =
3+
tag_date = 0
4+
tag_svn_revision = 0
5+

setup.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
#-*- coding: utf-8 -*-
3+
4+
from setuptools import setup
5+
6+
data_files = []
7+
8+
requires = [
9+
"twisted (==12.3.0)",
10+
"zope.interface (>=4.0.0)",
11+
"pyOpenSSL"
12+
]
13+
14+
setup(
15+
name="tor2web",
16+
version="0.3",
17+
author="Random GlobaLeaks developers",
18+
author_email = "[email protected]",
19+
url="https://tor2web.org/",
20+
packages=["tor2web", "tor2web.utils"],
21+
data_files=data_files,
22+
requires=requires
23+
)

t2w.py renamed to tor2web/t2w.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
from twisted.python.filepath import FilePath
6060
from twisted.python import log, logfile, failure
6161

62-
from utils.config import VERSION, config
63-
from utils.lists import List, torExitNodeList
64-
from utils.mail import sendmail, MailException
65-
from utils.socks import SOCKS5ClientEndpoint, SOCKSError
66-
from utils.ssl import T2WSSLContextFactory
67-
from utils.storage import Storage
68-
from utils.templating import PageTemplate
62+
from tor2web.utils.config import VERSION, config
63+
from tor2web.utils.lists import List, torExitNodeList
64+
from tor2web.utils.mail import sendmail, MailException
65+
from tor2web.utils.socks import SOCKS5ClientEndpoint, SOCKSError
66+
from tor2web.utils.ssl import T2WSSLContextFactory
67+
from tor2web.utils.storage import Storage
68+
from tor2web.utils.templating import PageTemplate
6969

7070
rexp = {
7171
'href': re.compile(r'<[a-z]*\s*.*?\s*href\s*=\s*[\\\'"]?([a-z0-9/#:\-\.]*)[\\\'"]?\s*.*?>', re.I),
@@ -684,7 +684,7 @@ def process(self):
684684
# because some checks must be done only for remote requests;
685685
# in fact local content is always served (css, js, and png in fact are used in errors)
686686

687-
if not verify_resource_is_local(request.host, request.uri, self.staticpath):
687+
if not verify_resource_is_local(request.host, request.uri, self.staticmap):
688688
if not request.host:
689689
return self.sendError(406, 'error_invalid_hostname.tpl')
690690

@@ -733,7 +733,7 @@ def process(self):
733733
self.obj.client_supports_gzip = True
734734

735735
# 2: Content delivery stage
736-
if verify_resource_is_local(request.host, request.uri, self.staticpath):
736+
if verify_resource_is_local(request.host, request.uri, self.staticmap):
737737
# the requested resource is local, we deliver it directly
738738
try:
739739
staticpath = request.uri
@@ -943,6 +943,8 @@ def startTor2webHTTPS(t2w, f, ip):
943943
###############################################################################
944944
# Basic Safety Checks
945945
###############################################################################
946+
config.load()
947+
946948
if not os.path.exists(config.datadir):
947949
print "Tor2web Startup Failure: unexistent directory (%s)" % config.datadir
948950
exit(1)
File renamed without changes.

utils/config.py renamed to tor2web/utils/config.py

+30-26
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,44 @@ class Config(Storage):
4545
A Storage-like class which loads and store each attribute into a portable
4646
conf file.
4747
"""
48-
def __init__(self, section, cfgfile="tor2web.conf"):
48+
def __init__(self, cfgfile="/etc/tor2web.conf"):
4949
Storage.__init__(self)
50+
self._file = cfgfile
51+
self._section = 'main'
52+
self._parser = ConfigParser.ConfigParser()
5053

54+
def load(self):
5155
try:
52-
if (not os.path.exists(cfgfile) or
53-
not os.path.isfile(cfgfile) or
54-
not os.access(cfgfile, os.R_OK)):
55-
print "Tor2web Startup Failure: cannot open config file (%s)" % cfgfile
56+
if (not os.path.exists(self._file) or
57+
not os.path.isfile(self._file) or
58+
not os.access(self._file, os.R_OK)):
59+
print "Tor2web Startup Failure: cannot open config file (%s)" % self._file
5660
exit(1)
5761
except:
58-
print "Tor2web Startup Failure: error while accessing config file (%s)" % cfgfile
62+
print "Tor2web Startup Failure: error while accessing config file (%s)" % self._file
5963
exit(1)
6064

6165
try:
62-
self._cfgfile = cfgfile
63-
self._cfgparser = ConfigParser.ConfigParser()
64-
self._cfgparser.read([self._cfgfile])
65-
self._section = section
66+
self._parser.read([self._file])
6667

67-
for name in self._cfgparser.options(section):
68-
value = self._cfgparser.get(self._section, name)
68+
for name in self._parser.options(self._section):
69+
value = self._parser.get(self._section, name)
6970
self.__dict__[name] = self.parse(name)
7071
except:
71-
raise Exception("Tor2web Error: invalid config file (%s)" % cfgfile)
72+
raise Exception("Tor2web Error: invalid config file (%s)" % self._file)
73+
74+
def store(self):
75+
"""
76+
Commit changes in config file.
77+
"""
78+
if self._file is None:
79+
raise Exception("Tor2web Error: cannot store configuration (never loaded)")
80+
81+
self._file = open(self._file, 'w')
82+
try:
83+
self._parser.write(self._file)
84+
finally:
85+
self._file.close()
7286

7387
def splitlist(self, line):
7488
return [x[1:-1] if x[:1] == x[-1:] == '"' else x
@@ -77,7 +91,7 @@ def splitlist(self, line):
7791
def parse(self, name):
7892
try:
7993

80-
value = self._cfgparser.get(self._section, name)
94+
value = self._parser.get(self._section, name)
8195
if value.isdigit():
8296
value = int(value)
8397
elif value.lower() in ('true', 'false'):
@@ -106,19 +120,9 @@ def __setattr__(self, name, value):
106120
try:
107121

108122
# XXX: Automagically discover variable type
109-
self._cfgparser.set(self._section, name, value)
123+
self._parser.set(self._section, name, value)
110124

111125
except ConfigParser.NoOptionError:
112126
raise NameError(name)
113127

114-
def commit(self):
115-
"""
116-
Commit changes in config file.
117-
"""
118-
cfgfile = open(self._cfgfile, 'w')
119-
try:
120-
self._cfgparser.write(cfgfile)
121-
finally:
122-
cfgfile.close()
123-
124-
config = Config("main")
128+
config = Config()
File renamed without changes.

utils/mail.py renamed to tor2web/utils/mail.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
from OpenSSL import SSL
3838
from StringIO import StringIO
3939

40-
from utils.config import VERSION, config
41-
4240
from twisted.internet import reactor
4341
from twisted.mail.smtp import ESMTPSenderFactory
4442
from twisted.internet.ssl import ClientContextFactory
4543

44+
from tor2web.utils.config import VERSION, config
45+
4646
def sendmail(authenticationUsername, authenticationSecret, fromAddress, toAddress, messageFile, smtpHost, smtpPort=25):
4747
"""
4848
Sends an email using SSLv3 over SMTP
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)