aboutsummaryrefslogtreecommitdiffstats
path: root/packages/torouter-web/src/tui/controllers/tor.py
blob: 491c6b7fbd62b0b7eab4e417ab947b8412f82dba (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
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):
    trc = parsing.torrc(config.torrc_file)
    trc.parse()
    output = trc.html_output()
    return render.base(render.torstatus(output,config.torrc_file))

  def POST(self):
    trc = parsing.torrc(config.torrc_file)
    trc.parse()
    output = trc.html_output()
    return render.base(render.torstatus(output,config.torrc_file))

"""
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):
    trc = parsing.torrc(config.torrc_file)
    output = trc.output()
    return render.base(render.torconfig(output))

  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())