aboutsummaryrefslogtreecommitdiffstats
path: root/packages/torouter-web/src/tui/utils/configuration.py
blob: 336aa5436fbb013485948248eac48d419237a07b (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import web
import re
from tui.utils import parsing
from tui import config

def get(name):
  conf = {}
  itfc = parsing.interfaces(config.interfaces_file)
  itfc.parse()
 
  if name == "wireless":
    conf['essid'] = "tor"
    conf['mac'] = "00:11:22:33:44:55"
    for entry in itfc.wifi['post-up']:
      if re.search("sys_cfg_ssid", entry):
        conf['essid'] = entry.split(" ")[2].split("\"")[1]
   
    if type(itfc.wifi['pre-up']) is str:
      conf['mac'] = itfc.wifi['pre-up'].split(" ")[4]
    else:
      for entry in itfc.wifi['pre-up']:
        if re.search("ether", entry):
          print "hahah"
          conf['mac'] = entry.split(" ")[4]

    conf['netmask'] = itfc.wifi['netmask']
    conf['address'] = itfc.wifi['address']
    conf['encryption'] = "open"
    conf['key'] = ""
    return conf
  elif name == "firewall":
    conf['el1'] = "Element 1"
    conf['el2'] = "Element 2"
    conf['el3'] = "Element 3"
    return conf
  elif name == "wired":
    conf['el1'] = "Element 1"
    conf['el2'] = "Element 2"
    conf['el3'] = "Element 3"
    return conf
  elif name == "tor":
    conf['el1'] = "Element 1"
    conf['el2'] = "Element 2"
    conf['el3'] = "Element 3"
    return conf
  
def write(name, data):
  if name == "wireless":
    return True
  elif name == "firewall":
    return True
  elif name == "wired":
    return True
  elif name == "tor":
    return True
  
def get_form(name):
  # Also these are just skeletons
  if name == "wireless":
    c = get(name)
    return web.form.Form(
      web.form.Textbox(name='essid',
        description='ESSID', value=c['essid']),
      web.form.Textbox(name='mac',
        description='MAC address', value=c['mac']),
      web.form.Textbox(name='address',
        description='IP address', value=c['address']),
      web.form.Textbox(name='netmask',
        description='Netmask address', value=c['netmask']),
      web.form.Dropdown(name='enctype', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'],
        description='Encryption scheme', value=c['encryption']),
      web.form.Password(name='key',
        description='Key', value=c['key']),
      web.form.Button('save')
    )
  elif name == "firewall":
    c = get(name) 
    return web.form.Form(
      web.form.Textbox(name='el1',
        description='The first element', value=c['el2']),
      web.form.Dropdown(name='el2', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'],
        description='The second selement', value=c['el2']),
      web.form.Password(name='el3',
        description='The third element', value=c['el3']),
      web.form.Button('save')
    )
  elif name == "wired":
    c = get(name)
    return web.form.Form(
      web.form.Textbox(name='el1',
        description='The first element', value=c['el2']),
      web.form.Dropdown(name='el2', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'],
        description='The second selement', value=c['el2']),
      web.form.Password(name='el3',
        description='The third element', value=c['el3']),
      web.form.Button('save')
    )
  elif name == "tor":
    c = get(name)
    return web.form.Form(
      web.form.Textbox(name='el1',
        description='The first element', value=c['el2']),
      web.form.Dropdown(name='el2', args=['WPA2', 'WPA', 'WEP (not reccomended)', 'open'],
        description='The second selement', value=c['el2']),
      web.form.Password(name='el3',
        description='The third element', value=c['el3']),
      web.form.Button('save')
    )