diff --git a/dhcp-hosts.dpto2 b/dhcp-hosts.dpto2 index ea4f14a..025aa50 100644 --- a/dhcp-hosts.dpto2 +++ b/dhcp-hosts.dpto2 @@ -98,7 +98,7 @@ ff:ff:ff:ff:ff:fe,10.6.122.95 00:23:54:8c:65:13,10.6.122.96,set:client0023548c6513 ff:ff:ff:ff:ff:fe,10.6.122.97 ff:ff:ff:ff:ff:fe,10.6.122.98 -# {"reserved-by": "Zelda"} +# {"color": "purple", "reserved-by": "Zelda"} ff:ff:ff:ff:ff:fe,10.6.122.99 ff:ff:ff:ff:ff:fe,10.6.122.100 # {"reserved-by": "Andy"} diff --git a/dhcp-opts.dpto2 b/dhcp-opts.dpto2 index b60d303..2b25027 100644 --- a/dhcp-opts.dpto2 +++ b/dhcp-opts.dpto2 @@ -1,2 +1,2 @@ -tag:client0023548c6513,option:router,10.6.122.96 tag:client122442232445,option:router,10.6.122.2 +tag:client0023548c6513,option:router,10.6.122.96 diff --git a/main.py b/main.py index e527e06..a658988 100755 --- a/main.py +++ b/main.py @@ -231,7 +231,7 @@ def parse_dchp_host(line): tag = p[4:] return DhcpHostLine(macs, ip, tag) -Ip = namedtuple("Ip","reserved_by dhcp_pool locked macs gw") +Ip = namedtuple("Ip","reserved_by dhcp_pool locked macs gw color") def load_ips(): ipmap = {} @@ -241,14 +241,16 @@ def load_ips(): dhcp_pool=True, locked=False, macs=[], - gw=None + gw=None, + color=None ) ipmap[0] = ipmap[255] = Ip( reserved_by="", dhcp_pool=False, locked=False, macs=[], - gw=None + gw=None, + color=None ) prefix = None @@ -288,7 +290,8 @@ def load_ips(): dhcp_pool=False, locked=meta.get("locked",False), macs=r.macs, - gw=gws.get(r.tag, None) + gw=gws.get(r.tag, None), + color = meta.get("color", None) ) meta = {} ipmap["prefix"] = prefix @@ -327,6 +330,8 @@ def write_dhcp_files(ipmap): meta['reserved-by'] = ip.reserved_by if ip.locked: meta['locked'] = True + if ip.color: + meta['color'] = ip.color print("# " + json.dumps(meta), file=f) if len(ip.macs) == 0: macs = impossible_mac @@ -355,6 +360,7 @@ def write_dhcp_files(ipmap): @app.route("/ip/", methods=['GET', 'POST']) @login_required def ip(last_byte): + valid_colors = "black red gold green blue purple".split() if request.method == 'POST': # ImmutableMultiDict([('reserved-by', 'Andy'), # ('dhcp-client', 'mac'), @@ -371,6 +377,8 @@ def ip(last_byte): macs = parse_macs(request.form.get('dhcp-client-mac', '')) gw = request.form.get('dhcp-gw','')[:15] gw = gw if ip_re.match(gw) else None + color = request.form.get('label-color', '')[:20] + color = color if color in valid_colors else None with exclusive_lock: ipmap = load_ips() @@ -381,6 +389,7 @@ def ip(last_byte): locked=False, macs=macs, gw=gw, + color=color ) write_dhcp_files(ipmap) reload_dnsmasq() @@ -392,6 +401,7 @@ def ip(last_byte): return render_template( "ip.html", addr=addr, + valid_colors=valid_colors, meta=ipmap[last_byte], ) diff --git a/static/css/dpto2.css b/static/css/dpto2.css index 50b8a2f..464a308 100644 --- a/static/css/dpto2.css +++ b/static/css/dpto2.css @@ -24,7 +24,7 @@ div.ips-cell { display: inline-flex; flex-direction: column; justify-content: center; - background-color: #faf4fa; + background-color: #fffcff; width: 54px; height: 54px; margin: 0px; @@ -64,10 +64,11 @@ green darkgreen */ .c-black { color: #444; } -.c-blue { color: darkblue; } -.c-purple { color: purple; } -.c-red { color: darkred; } -.c-green { color: darkgreen; } +.c-red { color: #ff4141; } +.c-gold { color: #ffb400; } +.c-blue { color: #3d7bc7; } +.c-purple { color: #c55bba; } +.c-green { color: #36ae36; } .color-sample { font-size: x-large; @@ -80,6 +81,13 @@ green darkgreen border-bottom: 2px solid black; } +[disabled] .color-sample { + color: lightgrey; +} +[disabled] .color-sample.selected { + border-bottom: 2px solid lightgrey; +} + span.ip { position: absolute; bottom: 2px; @@ -103,7 +111,7 @@ div.ips-cell.dhcp-pool.hover { background-color: #acdccc; } div.ips-cell.hover { - background-color: #eae4ea; + background-color: #f6f0f6; } div.ips-cell.unusable { background-image: url(../img/unusable.png) diff --git a/templates/ip.html b/templates/ip.html index 9b5d85d..f8304e2 100644 --- a/templates/ip.html +++ b/templates/ip.html @@ -24,30 +24,36 @@
-
-
+
+ -
-
- - - - - -
-
+
+
+ {% set meta_color = "black" %} + {% if meta.color %}{% set meta_color = meta.color %}{% endif %} + + {% for color in valid_colors %} + + {% endfor %} + +
+ +
@@ -117,7 +123,7 @@ diff --git a/templates/ips.html b/templates/ips.html index 47bb394..e7836aa 100644 --- a/templates/ips.html +++ b/templates/ips.html @@ -35,7 +35,10 @@ {%- if ipmap[ip].dhcp_pool %} dhcp-pool{% endif -%} ">
-
+
{% if ipmap[ip].dhcp_pool %} DHCP {% else %}