Read dhcp_hosts file
This commit is contained in:
parent
7dbab7dd74
commit
cb5b171018
7 changed files with 221 additions and 7 deletions
132
dhcp-hosts.dpto2
Normal file
132
dhcp-hosts.dpto2
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
# { "reserved-by": "Andy", "locked": true }
|
||||||
|
5c:f9:ff:ff:ff:ff,00:23:ff:ff:ff:ff,10.6.122.35,set:client5cf9ffffffff
|
||||||
|
|
||||||
|
# lara
|
||||||
|
00:e0:ff:ff:ff:ff,4c:72:ff:ff:ff:ff,10.0.0.1
|
||||||
|
# { "reserved-by": "Andy" }
|
||||||
|
f0:e0:ff:ff:ff:ff,10.0.0.132
|
||||||
|
|
||||||
|
# nexus 5
|
||||||
|
f8:a9:ff:ff:ff:ff,10.0.0.36,set:clientf8a9ffffffff
|
||||||
|
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.2
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.3
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.4
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.5
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.6
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.7
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.8
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.9
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.10
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.11
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.12
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.13
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.14
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.15
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.16
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.17
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.18
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.19
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.20
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.21
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.22
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.23
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.24
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.25
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.27
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.30
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.31
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.32
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.34
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.37
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.38
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.39
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.40
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.41
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.42
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.43
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.44
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.45
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.46
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.47
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.48
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.49
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.50
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.51
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.52
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.53
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.54
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.55
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.56
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.57
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.58
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.59
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.60
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.61
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.62
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.63
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.64
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.65
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.66
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.67
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.68
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.69
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.70
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.71
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.72
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.73
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.74
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.75
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.76
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.77
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.78
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.79
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.80
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.81
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.82
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.83
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.84
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.85
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.86
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.87
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.88
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.89
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.90
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.91
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.92
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.93
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.94
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.95
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.96
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.97
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.98
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.99
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.100
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.101
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.102
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.103
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.104
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.105
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.106
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.107
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.108
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.109
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.110
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.111
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.112
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.113
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.114
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.115
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.116
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.117
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.118
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.119
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.120
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.121
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.122
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.123
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.124
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.125
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.126
|
||||||
|
ff:ff:ff:ff:ff:fe,10.0.0.127
|
||||||
|
|
1
dhcp-opts.dpto2
Normal file
1
dhcp-opts.dpto2
Normal file
|
@ -0,0 +1 @@
|
||||||
|
tag:client5cf9ffffffff,option:router,10.0.0.1
|
51
main.py
51
main.py
|
@ -3,6 +3,7 @@
|
||||||
from flask import Flask, request, abort, make_response, \
|
from flask import Flask, request, abort, make_response, \
|
||||||
render_template, redirect, url_for, \
|
render_template, redirect, url_for, \
|
||||||
json, jsonify, session, flash
|
json, jsonify, session, flash
|
||||||
|
from collections import namedtuple
|
||||||
import hashlib
|
import hashlib
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -162,9 +163,54 @@ def list_users():
|
||||||
lines = render_users_tree(tree)
|
lines = render_users_tree(tree)
|
||||||
return render_template("users.html", users=lines)
|
return render_template("users.html", users=lines)
|
||||||
|
|
||||||
|
mac_re = re.compile("(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}")
|
||||||
|
ip_re = re.compile("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
|
||||||
|
DhcpHostLine = namedtuple("DhcpHostLine","macs ip")
|
||||||
|
|
||||||
|
def parse_dchp_host(line):
|
||||||
|
macs = []
|
||||||
|
ip = ""
|
||||||
|
parts = line.split(",")
|
||||||
|
for p in parts:
|
||||||
|
p = p.strip()
|
||||||
|
m = mac_re.match(p)
|
||||||
|
if m:
|
||||||
|
macs.append(m.group(0))
|
||||||
|
m = ip_re.match(p)
|
||||||
|
if m:
|
||||||
|
ip = m.group(0)
|
||||||
|
return DhcpHostLine(macs, ip)
|
||||||
|
|
||||||
|
Ip = namedtuple("Ip","reserved_by dhcp")
|
||||||
|
|
||||||
@app.route("/ips")
|
@app.route("/ips")
|
||||||
def ips():
|
def ips():
|
||||||
return render_template("ips.html")
|
ipmap = {}
|
||||||
|
for i in range(1,255):
|
||||||
|
ipmap[i] = Ip("",True)
|
||||||
|
ipmap[0] = ipmap[255] = Ip("", False)
|
||||||
|
with open(dhcp_hosts_file) as f:
|
||||||
|
meta = {}
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
if line.startswith("#"):
|
||||||
|
try:
|
||||||
|
meta = json.loads(line[1:])
|
||||||
|
except:
|
||||||
|
meta = {}
|
||||||
|
continue
|
||||||
|
if not isinstance(meta,dict):
|
||||||
|
meta = {}
|
||||||
|
continue
|
||||||
|
if re.match("^[0-9a-fA-F]{2}:",line):
|
||||||
|
r = parse_dchp_host(line)
|
||||||
|
ip = int(r.ip.split(".")[-1])
|
||||||
|
ipmap[ip] = Ip(meta.get("reserved-by",""), False)
|
||||||
|
return render_template("ips.html", ipmap=ipmap)
|
||||||
|
|
||||||
|
@app.route("/ip/<int:addr>")
|
||||||
|
def ip(addr):
|
||||||
|
return render_template("ip.html", ip=addr)
|
||||||
|
|
||||||
@app.route("/logout")
|
@app.route("/logout")
|
||||||
def logout():
|
def logout():
|
||||||
|
@ -174,6 +220,7 @@ def logout():
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if "debug" in sys.argv:
|
if "debug" in sys.argv:
|
||||||
users_file = "users.dpto2"
|
users_file = "users.dpto2"
|
||||||
dhcp_hosts_file = "dhcp_hosts.dpto2"
|
dhcp_hosts_file = "dhcp-hosts.dpto2"
|
||||||
|
dhcp_opts_file = "dhcp-opts.dpto2"
|
||||||
app.debug = True
|
app.debug = True
|
||||||
app.run(host="0.0.0.0")
|
app.run(host="0.0.0.0")
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 204 B After Width: | Height: | Size: 200 B |
20
templates/ip.html
Normal file
20
templates/ip.html
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Subir Circuito{% endblock %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
{{ super() }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<h3>Asignación de 10.6.122.{{ ip }}</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<form action="" class="form-horizontal" method="POST">
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -23,17 +23,17 @@
|
||||||
{%- if col == 7 %} ips-ver-half{% endif %}
|
{%- if col == 7 %} ips-ver-half{% endif %}
|
||||||
{%- if row == 7 %} ips-hor-half{% endif %}
|
{%- if row == 7 %} ips-hor-half{% endif %}
|
||||||
{% if unusable %} unusable{% endif %}
|
{% if unusable %} unusable{% endif %}
|
||||||
{%- if 216 <= ip <= 239 %} dhcp-pool{% endif -%}
|
{%- if ipmap[ip].dhcp %} dhcp-pool{% endif -%}
|
||||||
">
|
">
|
||||||
<div class="name">
|
<div class="name">
|
||||||
{% if 99 <= ip <= 103 or ip == 96%}
|
{% if ipmap[ip].dhcp %}
|
||||||
Andy
|
|
||||||
{% elif 216 <= ip <= 239 %}
|
|
||||||
DHCP
|
DHCP
|
||||||
|
{% else %}
|
||||||
|
{{ ipmap[ip].reserved_by }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if usable %}
|
{% if usable %}
|
||||||
{% if ip == 14 or ip == 99 %}
|
{% 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 %}
|
||||||
<span class="ip">.{{ row*16 + col }}</span>
|
<span class="ip">.{{ row*16 + col }}</span>
|
||||||
|
|
14
users.dpto2
Normal file
14
users.dpto2
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Sample users file, all hashes below are for the password "password"
|
||||||
|
guest Cleartext-Password := "jpqfvxat"
|
||||||
|
ateijelo NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C"
|
||||||
|
apiad NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by ateijelo
|
||||||
|
pepe NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by ateijelo
|
||||||
|
yudy NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by ateijelo
|
||||||
|
dvd NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by apiad
|
||||||
|
coto NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by dvd
|
||||||
|
amy NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by dvd
|
||||||
|
lapepa NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by pepe
|
||||||
|
Bolufe NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by apiad
|
||||||
|
hydn NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C"
|
||||||
|
oscarluis NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by hydn
|
||||||
|
luilver NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by pepe
|
Loading…
Reference in a new issue