summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2016-11-26 12:17:49 +0100
committerPiotr Dobrowolski <admin@tastycode.pl>2016-11-26 12:17:49 +0100
commitec6cf1afd2184ff03ad257fa7b4b6908311af423 (patch)
tree860d75e10e9c89067a693dcc8b71b96b7d6b4c2c
parent9b19bb8a81c5e4954c1dbb5c4fcfc906480b7db7 (diff)
downloadcheckinator-ec6cf1afd2184ff03ad257fa7b4b6908311af423.tar.gz
checkinator-ec6cf1afd2184ff03ad257fa7b4b6908311af423.tar.bz2
checkinator-ec6cf1afd2184ff03ad257fa7b4b6908311af423.zip
Random fixes, kektops support
-rw-r--r--at.py34
-rw-r--r--templates/main.html5
2 files changed, 32 insertions, 7 deletions
diff --git a/at.py b/at.py
index d7e2b38..06b0fd5 100644
--- a/at.py
+++ b/at.py
@@ -27,7 +27,10 @@ from functools import wraps
def v4addr():
- r_addr = request.remote_addr
+ if request.headers.getlist("X-Forwarded-For"):
+ r_addr = request.headers.getlist("X-Forwarded-For")[-1]
+ else:
+ r_addr = request.remote_addr
if r_addr.startswith('::ffff:'):
r_addr = r_addr[7:]
return r_addr
@@ -39,6 +42,8 @@ def restrict_ip(prefix='', exclude=[]):
def func(*a, **kw):
r_addr = v4addr()
if not r_addr.startswith(prefix) or r_addr in exclude:
+ app.logger.info('got IP %s, rejecting',r_addr)
+
abort(403)
return f(*a, **kw)
return func
@@ -162,14 +167,17 @@ class MtimeUpdater(Updater):
def file_changed(self, f):
pass
+ def _trigger_update(self):
+ app.logger.info('Lease file changed, updating')
+ with open(self.lease_file, 'r') as f:
+ self.file_changed(f)
+
def run(self):
while True:
try:
mtime = os.stat(self.lease_file).st_mtime
if mtime > self.last_modified:
- app.logger.info('Lease file changed, updating')
- with open(self.lease_file, 'r') as f:
- self.file_changed(f)
+ self._trigger_update()
self.last_modified = mtime
sleep(3.0)
except Exception as e:
@@ -190,6 +198,8 @@ class DhcpdUpdater(MtimeUpdater):
lease = False
# for use by next-line logic
ip = None
+ hwaddr = None
+ atime = None
for line in f:
line = line.split('#')[0]
cmd = line.strip().split()
@@ -207,8 +217,9 @@ class DhcpdUpdater(MtimeUpdater):
hwaddr = cmd[2][:-1]
if(field.startswith('}')):
lease = False
- if hwaddr:
+ if hwaddr is not None and atime is not None:
self.update(hwaddr, atime, ip, name)
+ hwaddr, atime = None, None
elif cmd[0] == 'lease':
ip = cmd[1]
name, hwaddr, atime = [None] * 3
@@ -232,6 +243,7 @@ def list_all():
}
result['users'] = map(prettify_user, result['users'])
result['unknown'] = len(result['unknown'])
+ result['kektops'] = len(result['kektops'])
res = make_response(json.dumps(result), 200)
res.headers['Access-Control-Allow-Origin'] = '*'
return res
@@ -241,7 +253,15 @@ def now_at():
devices = app.updater.get_active_devices()
device_infos = list(get_device_infos(g.db, devices.keys()))
device_infos.sort(key=lambda di: devices.__getitem__)
- unknown = set(devices.keys()) - set(d.hwaddr for d in device_infos)
+ all_unknown = set(devices.keys()) - set(d.hwaddr for d in device_infos)
+ # das kektop sorting maschine
+ kektops = set()
+ unknown = set()
+ for u in all_unknown:
+ if u.startswith('90:e6:ba:84'):
+ kektops.add(u)
+ else:
+ unknown.add(u)
users = {}
for info in device_infos:
@@ -249,7 +269,7 @@ def now_at():
users[info.owner] = devices[info.hwaddr][0]
users_sorted = sorted(users.items(), key=lambda (u, a): a, reverse=True)
- return dict(users=users_sorted, unknown=unknown)
+ return dict(users=users_sorted, unknown=unknown, kektops=kektops)
restrict_to_hs = restrict_ip(prefix=app.config['CLAIMABLE_PREFIX'],
diff --git a/templates/main.html b/templates/main.html
index 629db02..f49d90b 100644
--- a/templates/main.html
+++ b/templates/main.html
@@ -19,6 +19,11 @@ Now at hackerspace
{% pluralize %}
There are {{ n_unk }} unknown devices operating.
{% endtrans %}
+ {% trans n_kek=kektops|length %}
+ There is {{ n_kek }} unknown kektop operating.
+ {% pluralize %}
+ There are {{ n_kek }} unknown kektops operating.
+ {% endtrans %}
<hr>
<a href="claim">Claim this device!</a>
{% endblock %}