Improve No-VPN device display in frontend, improve build env

This commit is contained in:
Kumi 2019-02-11 14:09:56 +00:00
parent ff292a96ce
commit b1145c3059
3 changed files with 35 additions and 23 deletions

View file

@ -79,14 +79,19 @@ def mkfirmware(device, path):
os.chdir(BEFORE) os.chdir(BEFORE)
os.rename(glob.glob(SRCDIR + "/bin/targets/ar71xx/generic/*squashfs-sysupgrade.bin")[0], "%s/%s.bin" % (path, device.id)) os.rename(glob.glob(SRCDIR + "/bin/targets/ar71xx/generic/*squashfs-sysupgrade.bin")[0], "%s/%s.bin" % (path, device.id))
try:
os.remove(SRCDIR + "/.kumilock") os.remove(SRCDIR + "/.kumilock")
except:
pass
os.system("rm -rf " + SRCDIR + "/files/") os.system("rm -rf " + SRCDIR + "/files/")
os.system("rm " + SRCDIR + "/bin/targets/ar71xx/generic/*") os.system("rm " + SRCDIR + "/bin/targets/ar71xx/generic/*")
device.firmware = datetime.datetime.now() device.firmware = datetime.datetime.now()
device.save() device.save()
return True return True
except Exception: except Exception as e:
os.remove(SRCDIR + "/.kumilock") os.remove(SRCDIR + "/.kumilock")
os.chdir(BEFORE) os.chdir(BEFORE)
return False return False

View file

@ -90,35 +90,41 @@ def update(request):
def ping(request, device_id): def ping(request, device_id):
if request.user.is_authenticated: if request.user.is_authenticated:
try:
device = Device.objects.get(id=device_id, organization__in=request.user.organization_set.all())
except:
device = None device = None
ajax = '{\n "status": '
for organization in Organization.objects.filter(users=request.user): ajax = '{\n "status": '
device = device or Device.objects.filter(id=device_id, organization=organization)
if not device: if not device:
ajax += "-1" ajax += "-1"
else: else:
try: try:
socket.inet_aton(device[0].curip) if device.curip:
ajax += str(1 if not os.WEXITSTATUS(os.system("ping -c1 -w1 " + device[0].curip + " > /dev/null 2>&1")) else 2 if (timezone.now() - device[0].lasttime).total_seconds() > 120 and (timezone.now() - device[0].lastbeat).total_seconds() < 60 else 0) socket.inet_aton(device.curip)
ajax += ',\n "serial": "%s"' % device[0].serial
ajax += ',\n "name": "%s"' % device[0].name if device[0].name else ""
ajax += ',\n "ip": "%s"' % device[0].curip
ajax += ',\n "time": "%i"' % (int(time.mktime(timezone.make_naive(device[0].lasttime, timezone.get_current_timezone()).timetuple())) * 1000)
ajax += ',\n "lastbeat": "%s"' % (int(time.mktime(timezone.make_naive(device[0].lastbeat, timezone.get_current_timezone()).timetuple())) * 1000)
ajax += ',\n "reboot": %i' % (1 if device[0].reboot else 0)
ajax += ',\n "update": %i' % (1 if device[0].update else 0)
ajax += ',\n "network": {'
ajax += '\n "intip": "%s"' % device[0].network.intip
ajax += ',\n "extip": "%s"' % device[0].network.extip
ajax += ',\n "name": "%s"' % (device[0].network.name if device[0].network.name else "")
ajax += '\n }'
except Exception as e: except Exception as e:
ajax += "-3" ajax += "-3"
else:
try:
ajax += str(1 if (device.curip and not os.WEXITSTATUS(os.system("ping -c1 -w1 " + device.curip + " > /dev/null 2>&1"))) else 2 if (True if not device.lasttime else (timezone.now() - device.lasttime).total_seconds() > 120) and (timezone.now() - device.lastbeat).total_seconds() < 60 else 0)
except:
ajax += "-4"
else:
ajax += ',\n "serial": "%s"' % device.serial
ajax += ',\n "name": "%s"' % device.name if device.name else ""
ajax += ',\n "ip": "%s"' % device.curip if device.curip else ""
ajax += ',\n "time": "%s"' % (None if not device.lasttime else str(int(time.mktime(timezone.make_naive(device.lasttime, timezone.get_current_timezone()).timetuple())) * 1000))
ajax += ',\n "lastbeat": "%s"' % (None if not device.lastbeat else str(int(time.mktime(timezone.make_naive(device.lastbeat, timezone.get_current_timezone()).timetuple())) * 1000))
ajax += ',\n "reboot": %i' % (1 if device.reboot else 0)
ajax += ',\n "update": %i' % (1 if device.update else 0)
ajax += ',\n "network": {'
ajax += '\n "intip": "%s"' % device.network.intip
ajax += ',\n "extip": "%s"' % device.network.extip
ajax += ',\n "name": "%s"' % (device.network.name if device.network.name else "")
ajax += '\n }'
else: else:
ajax += "-2" ajax += "-2"

View file

@ -35,7 +35,8 @@ function timeSince(obj) {
if (seconds < 120) out = seconds + " seconds " if (seconds < 120) out = seconds + " seconds "
else if (interval > 1 && interval < 120) out = out + interval + " minutes "; else if (interval > 1 && interval < 120) out = out + interval + " minutes ";
return out + "ago"; if (out) return out + "ago";
return "";
} }
function styleStatus(msg, device) { function styleStatus(msg, device) {