Show leased ips in the ips page

This commit is contained in:
Andy Teijelo 2016-07-05 13:02:34 -04:00
parent 591080c395
commit 7577e83915
3 changed files with 38 additions and 1 deletions

29
main.py
View file

@ -23,6 +23,7 @@ app.secret_key = "6ab77f3c45447429c2ae163c260a626029519a66450e474c"
users_file = "/etc/freeradius/dpto2/users" users_file = "/etc/freeradius/dpto2/users"
dhcp_hosts_file = "/etc/dnsmasq.d/dpto2/dhcp-hosts" dhcp_hosts_file = "/etc/dnsmasq.d/dpto2/dhcp-hosts"
dhcp_opts_file = "/etc/dnsmasq.d/dpto2/dhcp-opts" dhcp_opts_file = "/etc/dnsmasq.d/dpto2/dhcp-opts"
dnsmasq_leases = "/var/lib/misc/dnsmasq.leases"
impossible_mac = "ff:ff:ff:ff:ff:fe" impossible_mac = "ff:ff:ff:ff:ff:fe"
class Lock: class Lock:
@ -310,11 +311,37 @@ def load_ips():
ipmap["prefix"] = prefix ipmap["prefix"] = prefix
return ipmap return ipmap
def load_leases():
leases = {}
with open(dnsmasq_leases) as f:
for line in f:
parts = line.strip().split()
try:
ip = int(parts[2].split(".")[-1])
except IndexError:
continue
except ValueError:
continue
try:
lease = [
int(parts[0]), # expiration timestamp
parts[1], # client mac address
parts[2], # leased ip
parts[3], # host name or * if no name sent
parts[4], # client id or * if no id sent
]
except IndexError:
# line is shorter than I thought, skippping
continue
leases[ip] = lease
return leases
@app.route("/ips") @app.route("/ips")
@login_required @login_required
def ips(): def ips():
ipmap = load_ips() ipmap = load_ips()
return render_template("ips.html", ipmap=ipmap) leases = load_leases()
return render_template("ips.html", ipmap=ipmap, leases=leases)
def parse_macs(macs): def parse_macs(macs):
r = [] r = []

View file

@ -103,6 +103,13 @@ span.lock {
color: #aaa; color: #aaa;
font-size: small; font-size: small;
} }
span.leased {
position: absolute;
bottom: 2px;
left: 0.6em;
color: #66BB6A;
font-size: x-small;
}
div.ips-cell.dhcp-pool { div.ips-cell.dhcp-pool {
background-color: #bed; background-color: #bed;

View file

@ -51,6 +51,9 @@
{% if ipmap[ip].locked %} {% if ipmap[ip].locked %}
<span class="lock"><i class="fa fa-lock"></i></span> <span class="lock"><i class="fa fa-lock"></i></span>
{% endif %} {% endif %}
{% if not ipmap[ip].locked and ip in leases %}
<span class="leased"><i class="fa fa-circle"></i></span>
{% endif %}
<span class="ip">.{{ row*16 + col }}</span> <span class="ip">.{{ row*16 + col }}</span>
{% endif %} {% endif %}
</div> </div>