Working on the IP assignation page

This commit is contained in:
Andy Teijelo Pérez 2015-11-06 11:58:05 -05:00
parent 3bbd1e3168
commit ca70df5736
7 changed files with 422 additions and 161 deletions

View file

@ -1,132 +1,242 @@
# { "reserved-by": "Andy", "locked": true } ff:ff:ff:ff:ff:fe,10.6.122.1
5c:f9:ff:ff:ff:ff,00:23:ff:ff:ff:ff,10.6.122.35,set:client5cf9ffffffff ff:ff:ff:ff:ff:fe,10.6.122.2
ff:ff:ff:ff:ff:fe,10.6.122.3
# lara ff:ff:ff:ff:ff:fe,10.6.122.4
00:e0:ff:ff:ff:ff,4c:72:ff:ff:ff:ff,10.0.0.1 ff:ff:ff:ff:ff:fe,10.6.122.5
ff:ff:ff:ff:ff:fe,10.6.122.6
ff:ff:ff:ff:ff:fe,10.6.122.7
ff:ff:ff:ff:ff:fe,10.6.122.8
ff:ff:ff:ff:ff:fe,10.6.122.9
ff:ff:ff:ff:ff:fe,10.6.122.10
ff:ff:ff:ff:ff:fe,10.6.122.11
ff:ff:ff:ff:ff:fe,10.6.122.12
ff:ff:ff:ff:ff:fe,10.6.122.13
# { "reserved-by": "WiFi dpto2", "locked": true }
ff:ff:ff:ff:ff:fe,10.6.122.14
ff:ff:ff:ff:ff:fe,10.6.122.15
ff:ff:ff:ff:ff:fe,10.6.122.16
ff:ff:ff:ff:ff:fe,10.6.122.17
ff:ff:ff:ff:ff:fe,10.6.122.18
ff:ff:ff:ff:ff:fe,10.6.122.19
ff:ff:ff:ff:ff:fe,10.6.122.20
ff:ff:ff:ff:ff:fe,10.6.122.21
ff:ff:ff:ff:ff:fe,10.6.122.22
ff:ff:ff:ff:ff:fe,10.6.122.23
ff:ff:ff:ff:ff:fe,10.6.122.24
ff:ff:ff:ff:ff:fe,10.6.122.25
ff:ff:ff:ff:ff:fe,10.6.122.26
ff:ff:ff:ff:ff:fe,10.6.122.27
ff:ff:ff:ff:ff:fe,10.6.122.28
ff:ff:ff:ff:ff:fe,10.6.122.29
ff:ff:ff:ff:ff:fe,10.6.122.30
ff:ff:ff:ff:ff:fe,10.6.122.31
ff:ff:ff:ff:ff:fe,10.6.122.32
ff:ff:ff:ff:ff:fe,10.6.122.33
ff:ff:ff:ff:ff:fe,10.6.122.34
ff:ff:ff:ff:ff:fe,10.6.122.35
ff:ff:ff:ff:ff:fe,10.6.122.36
ff:ff:ff:ff:ff:fe,10.6.122.37
ff:ff:ff:ff:ff:fe,10.6.122.38
ff:ff:ff:ff:ff:fe,10.6.122.39
ff:ff:ff:ff:ff:fe,10.6.122.40
ff:ff:ff:ff:ff:fe,10.6.122.41
ff:ff:ff:ff:ff:fe,10.6.122.42
ff:ff:ff:ff:ff:fe,10.6.122.43
ff:ff:ff:ff:ff:fe,10.6.122.44
ff:ff:ff:ff:ff:fe,10.6.122.45
ff:ff:ff:ff:ff:fe,10.6.122.46
ff:ff:ff:ff:ff:fe,10.6.122.47
ff:ff:ff:ff:ff:fe,10.6.122.48
ff:ff:ff:ff:ff:fe,10.6.122.49
ff:ff:ff:ff:ff:fe,10.6.122.50
ff:ff:ff:ff:ff:fe,10.6.122.51
ff:ff:ff:ff:ff:fe,10.6.122.52
ff:ff:ff:ff:ff:fe,10.6.122.53
ff:ff:ff:ff:ff:fe,10.6.122.54
ff:ff:ff:ff:ff:fe,10.6.122.55
ff:ff:ff:ff:ff:fe,10.6.122.56
ff:ff:ff:ff:ff:fe,10.6.122.57
ff:ff:ff:ff:ff:fe,10.6.122.58
ff:ff:ff:ff:ff:fe,10.6.122.59
ff:ff:ff:ff:ff:fe,10.6.122.60
ff:ff:ff:ff:ff:fe,10.6.122.61
ff:ff:ff:ff:ff:fe,10.6.122.62
ff:ff:ff:ff:ff:fe,10.6.122.63
ff:ff:ff:ff:ff:fe,10.6.122.64
ff:ff:ff:ff:ff:fe,10.6.122.65
ff:ff:ff:ff:ff:fe,10.6.122.66
ff:ff:ff:ff:ff:fe,10.6.122.67
ff:ff:ff:ff:ff:fe,10.6.122.68
ff:ff:ff:ff:ff:fe,10.6.122.69
ff:ff:ff:ff:ff:fe,10.6.122.70
ff:ff:ff:ff:ff:fe,10.6.122.71
ff:ff:ff:ff:ff:fe,10.6.122.72
ff:ff:ff:ff:ff:fe,10.6.122.73
ff:ff:ff:ff:ff:fe,10.6.122.74
ff:ff:ff:ff:ff:fe,10.6.122.75
ff:ff:ff:ff:ff:fe,10.6.122.76
ff:ff:ff:ff:ff:fe,10.6.122.77
ff:ff:ff:ff:ff:fe,10.6.122.78
ff:ff:ff:ff:ff:fe,10.6.122.79
ff:ff:ff:ff:ff:fe,10.6.122.80
ff:ff:ff:ff:ff:fe,10.6.122.81
ff:ff:ff:ff:ff:fe,10.6.122.82
ff:ff:ff:ff:ff:fe,10.6.122.83
ff:ff:ff:ff:ff:fe,10.6.122.84
ff:ff:ff:ff:ff:fe,10.6.122.85
ff:ff:ff:ff:ff:fe,10.6.122.86
ff:ff:ff:ff:ff:fe,10.6.122.87
ff:ff:ff:ff:ff:fe,10.6.122.88
ff:ff:ff:ff:ff:fe,10.6.122.89
ff:ff:ff:ff:ff:fe,10.6.122.90
ff:ff:ff:ff:ff:fe,10.6.122.91
ff:ff:ff:ff:ff:fe,10.6.122.92
ff:ff:ff:ff:ff:fe,10.6.122.93
ff:ff:ff:ff:ff:fe,10.6.122.94
ff:ff:ff:ff:ff:fe,10.6.122.95
# { "reserved-by": "Andy" } # { "reserved-by": "Andy" }
f0:e0:ff:ff:ff:ff,10.0.0.132 00:23:54:8c:65:13,10.6.122.96
ff:ff:ff:ff:ff:fe,10.6.122.97
# nexus 5 ff:ff:ff:ff:ff:fe,10.6.122.98
f8:a9:ff:ff:ff:ff,10.0.0.36,set:clientf8a9ffffffff ff:ff:ff:ff:ff:fe,10.6.122.99
ff:ff:ff:ff:ff:fe,10.6.122.100
ff:ff:ff:ff:ff:fe,10.0.0.2 ff:ff:ff:ff:ff:fe,10.6.122.101
ff:ff:ff:ff:ff:fe,10.0.0.3 ff:ff:ff:ff:ff:fe,10.6.122.102
ff:ff:ff:ff:ff:fe,10.0.0.4 ff:ff:ff:ff:ff:fe,10.6.122.103
ff:ff:ff:ff:ff:fe,10.0.0.5 ff:ff:ff:ff:ff:fe,10.6.122.104
ff:ff:ff:ff:ff:fe,10.0.0.6 ff:ff:ff:ff:ff:fe,10.6.122.105
ff:ff:ff:ff:ff:fe,10.0.0.7 ff:ff:ff:ff:ff:fe,10.6.122.106
ff:ff:ff:ff:ff:fe,10.0.0.8 ff:ff:ff:ff:ff:fe,10.6.122.107
ff:ff:ff:ff:ff:fe,10.0.0.9 ff:ff:ff:ff:ff:fe,10.6.122.108
ff:ff:ff:ff:ff:fe,10.0.0.10 ff:ff:ff:ff:ff:fe,10.6.122.109
ff:ff:ff:ff:ff:fe,10.0.0.11 ff:ff:ff:ff:ff:fe,10.6.122.110
ff:ff:ff:ff:ff:fe,10.0.0.12 ff:ff:ff:ff:ff:fe,10.6.122.111
ff:ff:ff:ff:ff:fe,10.0.0.13 ff:ff:ff:ff:ff:fe,10.6.122.112
ff:ff:ff:ff:ff:fe,10.0.0.14 ff:ff:ff:ff:ff:fe,10.6.122.113
ff:ff:ff:ff:ff:fe,10.0.0.15 ff:ff:ff:ff:ff:fe,10.6.122.114
ff:ff:ff:ff:ff:fe,10.0.0.16 ff:ff:ff:ff:ff:fe,10.6.122.115
ff:ff:ff:ff:ff:fe,10.0.0.17 ff:ff:ff:ff:ff:fe,10.6.122.116
ff:ff:ff:ff:ff:fe,10.0.0.18 ff:ff:ff:ff:ff:fe,10.6.122.117
ff:ff:ff:ff:ff:fe,10.0.0.19 ff:ff:ff:ff:ff:fe,10.6.122.118
ff:ff:ff:ff:ff:fe,10.0.0.20 ff:ff:ff:ff:ff:fe,10.6.122.119
ff:ff:ff:ff:ff:fe,10.0.0.21 ff:ff:ff:ff:ff:fe,10.6.122.120
ff:ff:ff:ff:ff:fe,10.0.0.22 ff:ff:ff:ff:ff:fe,10.6.122.121
ff:ff:ff:ff:ff:fe,10.0.0.23 ff:ff:ff:ff:ff:fe,10.6.122.122
ff:ff:ff:ff:ff:fe,10.0.0.24 ff:ff:ff:ff:ff:fe,10.6.122.123
ff:ff:ff:ff:ff:fe,10.0.0.25 ff:ff:ff:ff:ff:fe,10.6.122.124
ff:ff:ff:ff:ff:fe,10.0.0.27 ff:ff:ff:ff:ff:fe,10.6.122.125
ff:ff:ff:ff:ff:fe,10.0.0.30 ff:ff:ff:ff:ff:fe,10.6.122.126
ff:ff:ff:ff:ff:fe,10.0.0.31 ff:ff:ff:ff:ff:fe,10.6.122.127
ff:ff:ff:ff:ff:fe,10.0.0.32 ff:ff:ff:ff:ff:fe,10.6.122.128
ff:ff:ff:ff:ff:fe,10.0.0.34 ff:ff:ff:ff:ff:fe,10.6.122.129
ff:ff:ff:ff:ff:fe,10.0.0.37 ff:ff:ff:ff:ff:fe,10.6.122.130
ff:ff:ff:ff:ff:fe,10.0.0.38 ff:ff:ff:ff:ff:fe,10.6.122.131
ff:ff:ff:ff:ff:fe,10.0.0.39 ff:ff:ff:ff:ff:fe,10.6.122.132
ff:ff:ff:ff:ff:fe,10.0.0.40 ff:ff:ff:ff:ff:fe,10.6.122.133
ff:ff:ff:ff:ff:fe,10.0.0.41 ff:ff:ff:ff:ff:fe,10.6.122.134
ff:ff:ff:ff:ff:fe,10.0.0.42 ff:ff:ff:ff:ff:fe,10.6.122.135
ff:ff:ff:ff:ff:fe,10.0.0.43 ff:ff:ff:ff:ff:fe,10.6.122.136
ff:ff:ff:ff:ff:fe,10.0.0.44 ff:ff:ff:ff:ff:fe,10.6.122.137
ff:ff:ff:ff:ff:fe,10.0.0.45 ff:ff:ff:ff:ff:fe,10.6.122.138
ff:ff:ff:ff:ff:fe,10.0.0.46 ff:ff:ff:ff:ff:fe,10.6.122.139
ff:ff:ff:ff:ff:fe,10.0.0.47 ff:ff:ff:ff:ff:fe,10.6.122.140
ff:ff:ff:ff:ff:fe,10.0.0.48 ff:ff:ff:ff:ff:fe,10.6.122.141
ff:ff:ff:ff:ff:fe,10.0.0.49 ff:ff:ff:ff:ff:fe,10.6.122.142
ff:ff:ff:ff:ff:fe,10.0.0.50 ff:ff:ff:ff:ff:fe,10.6.122.143
ff:ff:ff:ff:ff:fe,10.0.0.51 ff:ff:ff:ff:ff:fe,10.6.122.144
ff:ff:ff:ff:ff:fe,10.0.0.52 ff:ff:ff:ff:ff:fe,10.6.122.145
ff:ff:ff:ff:ff:fe,10.0.0.53 ff:ff:ff:ff:ff:fe,10.6.122.146
ff:ff:ff:ff:ff:fe,10.0.0.54 ff:ff:ff:ff:ff:fe,10.6.122.147
ff:ff:ff:ff:ff:fe,10.0.0.55 ff:ff:ff:ff:ff:fe,10.6.122.148
ff:ff:ff:ff:ff:fe,10.0.0.56 ff:ff:ff:ff:ff:fe,10.6.122.149
ff:ff:ff:ff:ff:fe,10.0.0.57 ff:ff:ff:ff:ff:fe,10.6.122.150
ff:ff:ff:ff:ff:fe,10.0.0.58 ff:ff:ff:ff:ff:fe,10.6.122.151
ff:ff:ff:ff:ff:fe,10.0.0.59 ff:ff:ff:ff:ff:fe,10.6.122.152
ff:ff:ff:ff:ff:fe,10.0.0.60 ff:ff:ff:ff:ff:fe,10.6.122.153
ff:ff:ff:ff:ff:fe,10.0.0.61 ff:ff:ff:ff:ff:fe,10.6.122.154
ff:ff:ff:ff:ff:fe,10.0.0.62 ff:ff:ff:ff:ff:fe,10.6.122.155
ff:ff:ff:ff:ff:fe,10.0.0.63 ff:ff:ff:ff:ff:fe,10.6.122.156
ff:ff:ff:ff:ff:fe,10.0.0.64 ff:ff:ff:ff:ff:fe,10.6.122.157
ff:ff:ff:ff:ff:fe,10.0.0.65 ff:ff:ff:ff:ff:fe,10.6.122.158
ff:ff:ff:ff:ff:fe,10.0.0.66 ff:ff:ff:ff:ff:fe,10.6.122.159
ff:ff:ff:ff:ff:fe,10.0.0.67 ff:ff:ff:ff:ff:fe,10.6.122.160
ff:ff:ff:ff:ff:fe,10.0.0.68 ff:ff:ff:ff:ff:fe,10.6.122.161
ff:ff:ff:ff:ff:fe,10.0.0.69 ff:ff:ff:ff:ff:fe,10.6.122.162
ff:ff:ff:ff:ff:fe,10.0.0.70 ff:ff:ff:ff:ff:fe,10.6.122.163
ff:ff:ff:ff:ff:fe,10.0.0.71 ff:ff:ff:ff:ff:fe,10.6.122.164
ff:ff:ff:ff:ff:fe,10.0.0.72 ff:ff:ff:ff:ff:fe,10.6.122.165
ff:ff:ff:ff:ff:fe,10.0.0.73 ff:ff:ff:ff:ff:fe,10.6.122.166
ff:ff:ff:ff:ff:fe,10.0.0.74 ff:ff:ff:ff:ff:fe,10.6.122.167
ff:ff:ff:ff:ff:fe,10.0.0.75 ff:ff:ff:ff:ff:fe,10.6.122.168
ff:ff:ff:ff:ff:fe,10.0.0.76 ff:ff:ff:ff:ff:fe,10.6.122.169
ff:ff:ff:ff:ff:fe,10.0.0.77 ff:ff:ff:ff:ff:fe,10.6.122.170
ff:ff:ff:ff:ff:fe,10.0.0.78 ff:ff:ff:ff:ff:fe,10.6.122.171
ff:ff:ff:ff:ff:fe,10.0.0.79 ff:ff:ff:ff:ff:fe,10.6.122.172
ff:ff:ff:ff:ff:fe,10.0.0.80 ff:ff:ff:ff:ff:fe,10.6.122.173
ff:ff:ff:ff:ff:fe,10.0.0.81 ff:ff:ff:ff:ff:fe,10.6.122.174
ff:ff:ff:ff:ff:fe,10.0.0.82 ff:ff:ff:ff:ff:fe,10.6.122.175
ff:ff:ff:ff:ff:fe,10.0.0.83 ff:ff:ff:ff:ff:fe,10.6.122.176
ff:ff:ff:ff:ff:fe,10.0.0.84 ff:ff:ff:ff:ff:fe,10.6.122.177
ff:ff:ff:ff:ff:fe,10.0.0.85 ff:ff:ff:ff:ff:fe,10.6.122.178
ff:ff:ff:ff:ff:fe,10.0.0.86 ff:ff:ff:ff:ff:fe,10.6.122.179
ff:ff:ff:ff:ff:fe,10.0.0.87 ff:ff:ff:ff:ff:fe,10.6.122.180
ff:ff:ff:ff:ff:fe,10.0.0.88 ff:ff:ff:ff:ff:fe,10.6.122.181
ff:ff:ff:ff:ff:fe,10.0.0.89 ff:ff:ff:ff:ff:fe,10.6.122.182
ff:ff:ff:ff:ff:fe,10.0.0.90 ff:ff:ff:ff:ff:fe,10.6.122.183
ff:ff:ff:ff:ff:fe,10.0.0.91 ff:ff:ff:ff:ff:fe,10.6.122.184
ff:ff:ff:ff:ff:fe,10.0.0.92 ff:ff:ff:ff:ff:fe,10.6.122.185
ff:ff:ff:ff:ff:fe,10.0.0.93 ff:ff:ff:ff:ff:fe,10.6.122.186
ff:ff:ff:ff:ff:fe,10.0.0.94 ff:ff:ff:ff:ff:fe,10.6.122.187
ff:ff:ff:ff:ff:fe,10.0.0.95 ff:ff:ff:ff:ff:fe,10.6.122.188
ff:ff:ff:ff:ff:fe,10.0.0.96 ff:ff:ff:ff:ff:fe,10.6.122.189
ff:ff:ff:ff:ff:fe,10.0.0.97 ff:ff:ff:ff:ff:fe,10.6.122.190
ff:ff:ff:ff:ff:fe,10.0.0.98 ff:ff:ff:ff:ff:fe,10.6.122.191
ff:ff:ff:ff:ff:fe,10.0.0.99 ff:ff:ff:ff:ff:fe,10.6.122.192
ff:ff:ff:ff:ff:fe,10.0.0.100 ff:ff:ff:ff:ff:fe,10.6.122.193
ff:ff:ff:ff:ff:fe,10.0.0.101 ff:ff:ff:ff:ff:fe,10.6.122.194
ff:ff:ff:ff:ff:fe,10.0.0.102 ff:ff:ff:ff:ff:fe,10.6.122.195
ff:ff:ff:ff:ff:fe,10.0.0.103 ff:ff:ff:ff:ff:fe,10.6.122.196
ff:ff:ff:ff:ff:fe,10.0.0.104 ff:ff:ff:ff:ff:fe,10.6.122.197
ff:ff:ff:ff:ff:fe,10.0.0.105 ff:ff:ff:ff:ff:fe,10.6.122.198
ff:ff:ff:ff:ff:fe,10.0.0.106 ff:ff:ff:ff:ff:fe,10.6.122.199
ff:ff:ff:ff:ff:fe,10.0.0.107 ff:ff:ff:ff:ff:fe,10.6.122.200
ff:ff:ff:ff:ff:fe,10.0.0.108 ff:ff:ff:ff:ff:fe,10.6.122.201
ff:ff:ff:ff:ff:fe,10.0.0.109 ff:ff:ff:ff:ff:fe,10.6.122.202
ff:ff:ff:ff:ff:fe,10.0.0.110 ff:ff:ff:ff:ff:fe,10.6.122.203
ff:ff:ff:ff:ff:fe,10.0.0.111 ff:ff:ff:ff:ff:fe,10.6.122.204
ff:ff:ff:ff:ff:fe,10.0.0.112 ff:ff:ff:ff:ff:fe,10.6.122.205
ff:ff:ff:ff:ff:fe,10.0.0.113 ff:ff:ff:ff:ff:fe,10.6.122.206
ff:ff:ff:ff:ff:fe,10.0.0.114 ff:ff:ff:ff:ff:fe,10.6.122.207
ff:ff:ff:ff:ff:fe,10.0.0.115 ff:ff:ff:ff:ff:fe,10.6.122.208
ff:ff:ff:ff:ff:fe,10.0.0.116 ff:ff:ff:ff:ff:fe,10.6.122.209
ff:ff:ff:ff:ff:fe,10.0.0.117 ff:ff:ff:ff:ff:fe,10.6.122.210
ff:ff:ff:ff:ff:fe,10.0.0.118 ff:ff:ff:ff:ff:fe,10.6.122.211
ff:ff:ff:ff:ff:fe,10.0.0.119 ff:ff:ff:ff:ff:fe,10.6.122.212
ff:ff:ff:ff:ff:fe,10.0.0.120 ff:ff:ff:ff:ff:fe,10.6.122.213
ff:ff:ff:ff:ff:fe,10.0.0.121 ff:ff:ff:ff:ff:fe,10.6.122.214
ff:ff:ff:ff:ff:fe,10.0.0.122 ff:ff:ff:ff:ff:fe,10.6.122.215
ff:ff:ff:ff:ff:fe,10.0.0.123 ff:ff:ff:ff:ff:fe,10.6.122.231
ff:ff:ff:ff:ff:fe,10.0.0.124 ff:ff:ff:ff:ff:fe,10.6.122.232
ff:ff:ff:ff:ff:fe,10.0.0.125 ff:ff:ff:ff:ff:fe,10.6.122.233
ff:ff:ff:ff:ff:fe,10.0.0.126 ff:ff:ff:ff:ff:fe,10.6.122.234
ff:ff:ff:ff:ff:fe,10.0.0.127 ff:ff:ff:ff:ff:fe,10.6.122.235
ff:ff:ff:ff:ff:fe,10.6.122.236
ff:ff:ff:ff:ff:fe,10.6.122.237
ff:ff:ff:ff:ff:fe,10.6.122.238
ff:ff:ff:ff:ff:fe,10.6.122.239
ff:ff:ff:ff:ff:fe,10.6.122.240
ff:ff:ff:ff:ff:fe,10.6.122.241
ff:ff:ff:ff:ff:fe,10.6.122.242
ff:ff:ff:ff:ff:fe,10.6.122.243
ff:ff:ff:ff:ff:fe,10.6.122.244
ff:ff:ff:ff:ff:fe,10.6.122.245
ff:ff:ff:ff:ff:fe,10.6.122.246
ff:ff:ff:ff:ff:fe,10.6.122.247
ff:ff:ff:ff:ff:fe,10.6.122.248
ff:ff:ff:ff:ff:fe,10.6.122.249
ff:ff:ff:ff:ff:fe,10.6.122.250
ff:ff:ff:ff:ff:fe,10.6.122.251
ff:ff:ff:ff:ff:fe,10.6.122.252
ff:ff:ff:ff:ff:fe,10.6.122.253
ff:ff:ff:ff:ff:fe,10.6.122.254
ff:ff:ff:ff:ff:fe,10.6.122.255

76
main.py
View file

@ -4,6 +4,9 @@ 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 from collections import namedtuple
from subprocess import check_call, call
from fcntl import flock, LOCK_EX, LOCK_SH, LOCK_UN
import hashlib import hashlib
import random import random
import shutil import shutil
@ -12,7 +15,6 @@ import sys
import re import re
import os import os
from subprocess import check_call, call
#app = Flask("ISABEL-2 Verifier") # That app name breaks Ubuntu 14.04 :-o #app = Flask("ISABEL-2 Verifier") # That app name breaks Ubuntu 14.04 :-o
app = Flask("main") app = Flask("main")
@ -22,6 +24,27 @@ users_file = "/etc/freeradius/users.dpto2"
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"
class Lock:
def __init__(self, lockfile):
self.lockfile = lockfile
def __enter__(self):
flock(self.lockfile, LOCK_EX)
def __exit__(self, exc_type, exc_val, exc_tb):
flock(self.lockfile, LOCK_UN)
class SharedLock(Lock):
def __init__(self, lockfile):
super().__init__(lockfile)
def __enter__(self, exc_type, exc_val, exc_tb):
flock(self.lockfile, LOCK_SH)
lock_file = open("/run/lock/dpto2.lock","w")
exclusive_lock = Lock(lock_file)
shared_lock = SharedLock(lock_file)
def reload_freeradius(): def reload_freeradius():
call("./reload_freeradius") call("./reload_freeradius")
@ -29,18 +52,22 @@ def delete_user(deluser):
f = open(users_file) f = open(users_file)
lines = f.readlines() lines = f.readlines()
f.close() f.close()
f = open(users_file,"w") timestamp = time.time()
tempfile = "{}.{}".format(users_file, timestamp)
f = open(tempfile,"w")
for line in lines: for line in lines:
if line.startswith(deluser): if line.startswith(deluser):
continue continue
f.write(line) f.write(line)
f.close() f.close()
shutil.move(tempfile, users_file)
reload_freeradius() reload_freeradius()
def nthash(password): def nthash(password):
return hashlib.new('md4',password.encode('utf-16le')).hexdigest().upper() return hashlib.new('md4',password.encode('utf-16le')).hexdigest().upper()
def create_user(username, password, creator): def create_user(username, password, creator):
with exclusive_lock:
f = open(users_file,"a") f = open(users_file,"a")
f.write('{} NT-Password := "{}" # created by {} \n'.format(username, nthash(password), creator)) f.write('{} NT-Password := "{}" # created by {} \n'.format(username, nthash(password), creator))
f.close() f.close()
@ -165,30 +192,35 @@ def list_users():
mac_re = re.compile("(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}") 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}") ip_re = re.compile("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
DhcpHostLine = namedtuple("DhcpHostLine","macs ip") DhcpHostLine = namedtuple("DhcpHostLine","macs ip tag")
def parse_dchp_host(line): def parse_dchp_host(line):
macs = [] macs = []
ip = "" ip = ""
tag = ""
parts = line.split(",") parts = line.split(",")
for p in parts: for p in parts:
p = p.strip() p = p.strip()
m = mac_re.match(p) m = mac_re.match(p)
if m: if m:
macs.append(m.group(0)) macs.append(m.group(0))
continue
m = ip_re.match(p) m = ip_re.match(p)
if m: if m:
ip = m.group(0) ip = m.group(0)
return DhcpHostLine(macs, ip) continue
if p.startswith("set:"):
tag = p[4:]
return DhcpHostLine(macs, ip, tag)
Ip = namedtuple("Ip","reserved_by dhcp") Ip = namedtuple("Ip","reserved_by dhcp locked")
@app.route("/ips") def load_ips():
def ips():
ipmap = {} ipmap = {}
for i in range(1,255): for i in range(1,255):
ipmap[i] = Ip("",True) ipmap[i] = Ip("",True,False)
ipmap[0] = ipmap[255] = Ip("", False) ipmap[0] = ipmap[255] = Ip("", False, False)
prefix = None
with open(dhcp_hosts_file) as f: with open(dhcp_hosts_file) as f:
meta = {} meta = {}
for line in f: for line in f:
@ -205,13 +237,31 @@ def ips():
if re.match("^[0-9a-fA-F]{2}:",line): if re.match("^[0-9a-fA-F]{2}:",line):
r = parse_dchp_host(line) r = parse_dchp_host(line)
ip = int(r.ip.split(".")[-1]) ip = int(r.ip.split(".")[-1])
ipmap[ip] = Ip(meta.get("reserved-by",""), False) if prefix is None:
prefix = ".".join(r.ip.split(".")[:-1])
ipmap[ip] = Ip(
reserved_by=meta.get("reserved-by",""),
dhcp=False,
locked=meta.get("locked",False)
)
meta = {} meta = {}
ipmap["prefix"] = prefix
return ipmap
@app.route("/ips")
def ips():
ipmap = load_ips()
return render_template("ips.html", ipmap=ipmap) return render_template("ips.html", ipmap=ipmap)
@app.route("/ip/<int:addr>") @app.route("/ip/<int:last_byte>")
def ip(addr): def ip(last_byte):
return render_template("ip.html", ip=addr) ipmap = load_ips()
addr = "{}.{}".format(ipmap["prefix"], last_byte)
return render_template(
"ip.html",
addr=addr,
meta=ipmap[last_byte],
)
@app.route("/logout") @app.route("/logout")
def logout(): def logout():

View file

@ -14,8 +14,10 @@ div.main-container {
div.ips-row { div.ips-row {
margin-bottom: 0px; margin-bottom: 0px;
display: flex; display: flex;
align-items: stretch;
flex-direction: row; flex-direction: row;
justify-content: center; justify-content: center;
max-height: 54px;
/*line-height: 0;*/ /*line-height: 0;*/
} }
div.ips-cell { div.ips-cell {
@ -23,8 +25,8 @@ div.ips-cell {
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
background-color: #faf4fa; background-color: #faf4fa;
width: 60px; width: 54px;
height: 60px; height: 54px;
margin: 0px; margin: 0px;
border-bottom: 1px solid lightgray; border-bottom: 1px solid lightgray;
border-right: 1px solid lightgray; border-right: 1px solid lightgray;
@ -47,7 +49,8 @@ div.ips-cell.ips-bottom,div.ips-hor-half {
} }
div.name { div.name {
max-height: 70px; /* max-height: 52px; */
font-size: small;
} }
span.ip { span.ip {
position: absolute; position: absolute;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 200 B

After

Width:  |  Height:  |  Size: 182 B

View file

@ -8,13 +8,106 @@
{% block content %} {% block content %}
<div class="row"> <div class="row">
<h3>Asignación de 10.6.122.{{ ip }}</h3> <h3>Asignación de {{ addr }}</h3>
</div> </div>
<div class="row"> {% if meta.locked %}
<form action="" class="form-horizontal" method="POST"> <div class="alert alert-warning"><i class="fa fa-lock"></i> Esta dirección está reservada por <i>Ilúvatar</i></div>
{% endif %}
<div class="row">
<form class="form-horizontal" method="POST">
{% if meta.locked %}
<fieldset disabled>
{% endif %}
<div class="form-group">
<div class="col-xs-6">
<input type="checkbox" id="reserved" name="reserved"
{% if meta.reserved_by -%}
checked="checked"
{%- endif -%}>
<label for="reserved">Reservado a:</label>
<input type="text" class="form-control"
id="reserved-by" name="reserved-by"
{% if meta.reserved_by -%}
value="{{ meta.reserved_by }}"
{%- else -%}
disabled
{%- endif -%}
>
</div> </div>
<div class="form-group">
<div class="col-xs-11">
<input type="checkbox" id="dhcp" name="dhcp"></input>
<label for="dhcp">Ofrecer por DHCP</label>
<fieldset id="dhcp-fieldset" disabled>
<div class="form-group">
<div class="col-sm-offset-1">
<input type="radio" id="dhcp-client-any" name="dhcp-client" value="any">
<label for="dhcp-client-any">A cualquier dispositivo</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1">
<input type="radio" id="dhcp-client-specific" name="dhcp-client" value="mac">
<label for="dhcp-client-specific">A un dispositivo específico</label>
<div class="form-group">
<fieldset id="dhcp-specific-fieldset" disabled>
<div>
<label for="dhcp-client-mac" class="col-sm-4 control-label">MAC:</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="dhcp-client-mac"
placeholder="aa:bb:cc:dd:ee:ff"/>
</div>
</div>
<div>
<label for="dhcp-custom-gw" class="col-sm-4 control-label">
Gateway alternativo:
</label>
<div class="col-sm-5">
<input type="text" class="form-control" name="dhcp-client-mac"
placeholder="10.6.122.1"/>
</div>
</div>
</fieldset>
</div>
</div>
</div>
</fieldset>
</div>
</div>
{% if create_error %}
<center>
<p>Error: {{ errormsg }}</p>
</center>
{% endif %}
<div class="form-group">
<button type="submit" class="btn btn-default">Guardar</button>
</div>
{% if meta.locked %}
<fieldset disabled>
{% endif %}
</form> </form>
</div> </div>
<div class="row">
<a href="{{ url_for('ips') }}">Regresar</a>
</div>
<script>
$(function() {
$("#reserved").change(function() {
$("#reserved-by").prop("disabled", !$(this).prop("checked"));
})
$("#dhcp").change(function() {
$("#dhcp-fieldset").prop("disabled", !$(this).prop("checked"));
})
$("input[type=radio]").change(function() {
$("#dhcp-specific-fieldset").prop("disabled", !$("#dhcp-client-specific").prop("checked"));
})
$("input").change()
});
</script>
{% endblock %} {% endblock %}

View file

@ -25,6 +25,7 @@
{% if unusable %} unusable{% endif %} {% if unusable %} unusable{% endif %}
{%- if ipmap[ip].dhcp %} dhcp-pool{% endif -%} {%- if ipmap[ip].dhcp %} dhcp-pool{% endif -%}
"> ">
<div style="display: inline-block; max-height: 52px;">
<div class="name"> <div class="name">
{% if ipmap[ip].dhcp %} {% if ipmap[ip].dhcp %}
DHCP DHCP
@ -32,6 +33,8 @@
{{ ipmap[ip].reserved_by }} {{ ipmap[ip].reserved_by }}
{% endif %} {% endif %}
</div> </div>
<div style="height: 10px;"></div>
</div>
{% if usable %} {% if usable %}
{% 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>

View file

@ -12,3 +12,5 @@ Bolufe NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by apiad
hydn NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" hydn NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C"
oscarluis NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by hydn oscarluis NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by hydn
luilver NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by pepe luilver NT-Password := "8846F7EAEE8FB117AD06BDD830B7586C" # created by pepe
perico NT-Password := "70A3D0B8621E601DCCA59F8E23A11B75" # created by ateijelo
qwer NT-Password := "E5810F3C99AE2ABB2232ED8458A61309" # created by ateijelo