aboutsummaryrefslogtreecommitdiffstats
path: root/packages/torouter-web/src/tui/controllers/tor.py
blob: e671d8070089af5e8dea80704d0311aea3a9c280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import web
from tui import config
from tui import view
from tui.view import render
from tui.utils import session, parsing, fileio

"""
The main Tor status page
"""
class status:
  def GET(self):
    if session.is_logged() > 0:
      trc = parsing.torrc(config.torrc_file)
      trc.parse()
      output = trc.html_output()
      return render.base(render.torstatus(output,config.torrc_file))
    else:
      return render.base(render.login())


  def POST(self):
    if session.is_logged() > 0:
      trc = parsing.torrc(config.torrc_file)
      trc.parse()
      output = trc.html_output()
      return render.base(render.torstatus(output,config.torrc_file))
    else:
      return render.base(render.login())

"""
Tor configuration page
"""
class torrc:
  def update_config(self, data):
    # Now it will just write to /tmp/torrc
    files = [('/tmp/torrc',data.torrc)]
    fileio.write(files)

    return True

  def GET(self):
    if session.is_logged() > 0:
      trc = parsing.torrc(config.torrc_file)
      output = trc.output()
      return render.base(render.torconfig(output))
    else:
      return render.base(render.login())

  def POST(self):
    if session.is_logged() > 0:
      self.update_config(web.input())
      trc = parsing.torrc(config.torrc_file)
      trc.parse()
      output = trc.html_output()
      return render.base(render.torstatus(output,config.torrc_file))
    else:
      return render.base(render.login())