Permalink
Browse files

[dnsmasq] Edit/delete hosts

  • Loading branch information...
Eugeny committed Apr 20, 2011
1 parent ead4a27 commit d1ae2e1dcc7d68e7f6e9c4a7750a8eb25fcc205c
@@ -2,7 +2,7 @@
<toolbar>
<hcontainer>
<toolbutton id="add_task" text="Add task" icon="/dl/cron/add-task.png" />
- <toolbutton id="add_oth" text="Add non-task string" icon="/dl/cron/add-task.png" />
+ <toolbutton id="add_oth" text="Add non-task string" icon="/dl/core/ui/stock/add.png" />
<div style="padding: 4px 5px 0">
<formbox id="frmUser" hideok="True" hidecancel="True">
<hcontainer spacing="5">
View
@@ -36,15 +36,47 @@ def get_config(self):
if k == 'dhcp-host':
r['dhcp-hosts'].append(self.parse_host(v))
- elif k == 'domain':
- r['domains'].append(v)
+ elif k == 'address':
+ r['domains'].append(v.split('/'))
else:
r['opts'][k] = v
else:
k = l.strip()
r['opts'][k] = None
return r
+ def save_config(self, cfg):
+ s = ''
+ s += '# Hosts\n'
+ for x in cfg['dhcp-hosts']:
+ v = []
+ for y in x['id']:
+ if y[0] == 'dhcpid':
+ v.append('id:'+y[1])
+ else:
+ v.append(y[1])
+ for y in x['act']:
+ if y[0] == 'ignore':
+ v.append(y[0])
+ elif y[0] == 'set':
+ v.append('set:' + y[1])
+ else:
+ v.append(y[1])
+ s += 'dhcp-host=' + ','.join(v) + '\n'
+
+ s += '\n\n# Domains\n'
+ for x in cfg['domains']:
+ s += 'address=' + '/'.join(x) + '\n'
+
+ s += '\n\n# Other options\n'
+ for x in cfg['opts']:
+ if cfg['opts'][x]:
+ s += '%s=%s\n' % (x, cfg['opts'][x])
+ else:
+ s += x + '\n'
+
+ open(self.config_file, 'w').write(s)
+
def parse_host(self, s):
r = { 'id': [], 'act': [] }
s = s.split(',')
@@ -95,7 +127,7 @@ def str_act(self, h):
r = []
for x in h:
if x[0] == 'set':
- r.append('apply option set %s' % x[1])
+ r.append('use tag %s' % x[1])
if x[0] == 'ignore':
r.append('ignore')
if x[0] == 'name':
@@ -0,0 +1,73 @@
+<xml>
+ <dialogbox id="dlgEditHost">
+ <label size="2" text="Identification" />
+ <layouttable>
+ <layouttablerow>
+ <layouttablecell>
+ <checkbox id="id_mac" name="id_mac" text="MAC" />
+ </layouttablecell>
+ <layouttablecell>
+ <textinput id="id_mac_val" name="id_mac_val" />
+ </layouttablecell>
+ </layouttablerow>
+ <layouttablerow>
+ <layouttablecell>
+ <checkbox id="id_dhcp" name="id_dhcp" text="DHCP ID" />
+ </layouttablecell>
+ <layouttablecell>
+ <textinput id="id_dhcp_val" name="id_dhcp_val" />
+ </layouttablecell>
+ </layouttablerow>
+ <layouttablerow>
+ <layouttablecell>
+ <checkbox id="id_name" name="id_name" text="Client name" />
+ </layouttablecell>
+ <layouttablecell>
+ <textinput id="id_name_val" name="id_name_val" />
+ </layouttablecell>
+ </layouttablerow>
+ </layouttable>
+
+ <label size="2" text="Actions" />
+ <layouttable>
+ <layouttablerow>
+ <layouttablecell>
+ <checkbox id="act_ip" name="act_ip" text="Assign IP" />
+ </layouttablecell>
+ <layouttablecell>
+ <textinput id="act_ip_val" name="act_ip_val" />
+ </layouttablecell>
+ </layouttablerow>
+ <layouttablerow>
+ <layouttablecell>
+ <label text="Lease time" />
+ </layouttablecell>
+ <layouttablecell>
+ <textinput id="time" name="time" />
+ <helpicon text="15m, 2h, 5d or infinite" />
+ </layouttablecell>
+ </layouttablerow>
+ <layouttablerow>
+ <layouttablecell>
+ <checkbox id="act_tag" name="act_tag" text="Use tag" />
+ </layouttablecell>
+ <layouttablecell>
+ <textinput id="act_tag_val" name="act_tag_val" />
+ </layouttablecell>
+ </layouttablerow>
+ <layouttablerow>
+ <layouttablecell>
+ <checkbox id="act_ignore" name="act_ignore" text="Ignore" />
+ </layouttablecell>
+ </layouttablerow>
+ <layouttablerow>
+ <layouttablecell>
+ <checkbox id="act_name" name="act_name" text="Set name" />
+ </layouttablecell>
+ <layouttablecell>
+ <textinput id="act_name_val" name="act_name_val" />
+ </layouttablecell>
+ </layouttablerow>
+ </layouttable>
+ </dialogbox>
+</xml>
@@ -1,8 +1,12 @@
<xml>
+ <toolbar>
+ <toolbutton id="btnAddHost" text="Add DHCP host" icon="/dl/core/ui/stock/add.png" />
+ </toolbar>
+
<label size="5" text="Active leases" />
- <pad>
+ <pad id="main">
<datatable id="list" width="100%">
<datatablerow header="True">
<datatablecell width="30%">
@@ -19,7 +23,7 @@
</pad>
- <label size="5" text="DHCP options" />
+ <label size="5" text="DHCP hosts" />
<pad>
<datatable id="hosts" width="100%">
View
@@ -17,6 +17,9 @@ def on_init(self):
self.backend = Backend(self.app)
self.cfg = self.backend.get_config()
+ def on_session_start(self):
+ self._editing_host = None
+
def get_main_ui(self):
ui = self.app.inflate('dnsmasq:main')
@@ -48,10 +51,81 @@ def get_main_ui(self):
)
ui.append('hosts', row)
+ if self._editing_host is not None:
+ dlg = self.app.inflate('dnsmasq:edit-host')
+ self.setup_host_dialog(dlg)
+ ui.append('main', dlg)
+
return ui
+ def setup_host_dialog(self, dlg):
+ if self._editing_host == -1:
+ return
+
+ h = self.cfg['dhcp-hosts'][self._editing_host]
+ for x in h['id']:
+ if x[0] == 'mac':
+ dlg.find('id_mac').set('checked', True)
+ dlg.find('id_mac_val').set('value', x[1])
+ if x[0] == 'dhcpid':
+ dlg.find('id_dhcp').set('checked', True)
+ dlg.find('id_dhcp_val').set('value', x[1])
+ if x[0] == 'name':
+ dlg.find('id_name').set('checked', True)
+ dlg.find('id_name_val').set('value', x[1])
+ for x in h['act']:
+ if x[0] == 'ip':
+ dlg.find('act_ip').set('checked', True)
+ dlg.find('act_ip_val').set('value', x[1])
+ if x[0] == 'set':
+ dlg.find('act_tag').set('checked', True)
+ dlg.find('act_tag_val').set('value', x[1])
+ if x[0] == 'ignore':
+ dlg.find('act_ignore').set('checked', True)
+ if x[0] == 'name':
+ dlg.find('act_name').set('checked', True)
+ dlg.find('act_name_val').set('value', x[1])
+ if x[0] == 'time':
+ dlg.find('time').set('value', x[1])
+
@event('button/click')
+ @event('minibutton/click')
def on_click(self, event, params, vars=None):
- if params[0] == 'progress':
- pass
+ if params[0] == 'btnAddHost':
+ self._editing_host = -1
+ if params[0] == 'editHost':
+ self._editing_host = int(params[1])
+ if params[0] == 'deleteHost':
+ del self.cfg['dhcp-hosts'][int(params[1])]
+ self.backend.save_config(self.cfg)
+
+ @event('dialog/submit')
+ def on_submit(self, event, params, vars=None):
+ if params[0] == 'dlgEditHost':
+ if vars.getvalue('action', None) == 'OK':
+ x = { 'id': [], 'act': [] }
+ if vars.getvalue('id_mac', None) == '1':
+ x['id'].append(('mac', vars.getvalue('id_mac_val', None)))
+ if vars.getvalue('id_dhcp', None) == '1':
+ x['id'].append(('dhcpid', vars.getvalue('id_dhcp_val', None)))
+ if vars.getvalue('id_name', None) == '1':
+ x['id'].append(('name', vars.getvalue('id_name_val', None)))
+ if vars.getvalue('act_ip', None) == '1':
+ x['act'].append(('ip', vars.getvalue('act_ip_val', None)))
+ if vars.getvalue('act_ignore', None) == '1':
+ x['act'].append(('ignore', None))
+ if vars.getvalue('act_tag', None) == '1':
+ x['act'].append(('set', vars.getvalue('act_tag_val', None)))
+ if vars.getvalue('act_name', None) == '1':
+ x['act'].append(('name', vars.getvalue('act_name_val', None)))
+ if vars.getvalue('time', '') != '':
+ x['act'].append(('time', vars.getvalue('time', None)))
+
+ if self._editing_host != -1:
+ self.cfg['dhcp-hosts'][self._editing_host] = x
+ else:
+ self.cfg['dhcp-hosts'].append(x)
+
+ self.backend.save_config(self.cfg)
+ self._editing_host = None
@@ -5,6 +5,7 @@
<button id="msgWarn" text="Warning" />
<button id="msgErr" text="Error" />
<button id="progress" text="Start working" />
+ <button id="btnExit" text="Exit" />
</hcontainer>
</pad>
</xml>
@@ -5,6 +5,8 @@
from ajenti.plugins.core.api import *
from ajenti.utils import *
+import sys
+
class PlaygroundPlugin(CategoryPlugin):
text = 'Playground'
@@ -25,6 +27,8 @@ def on_click(self, event, params, vars=None):
self.put_message('err', 'Error')
if params[0] == 'progress':
PlaygroundProgress(self.app).start()
+ if params[0] == 'btnExit':
+ self.app.stop()
class PlaygroundProgress(SessionPlugin):

0 comments on commit d1ae2e1

Please sign in to comment.