from .signals import * def makewificonfig(device): output = "" i = 1 for wifi in device.wifi.all(): output += """config wifi-iface option network 'wwan%i' option ssid '%s' option encryption 'psk2' option device 'radio1' option mode 'sta' option key '%s' """ % (i, wifi.ssid, wifi.key) i += 1 return output def heartbeathandler(device, ip): if device.update: sigRebootDevice(device.serial, None, False) device.reboot = False code = """. /etc/vpnsecret if /usr/bin/wget -O/tmp/update.bin https://admin360.kumi.host/update --post-data "secret=$SECRET" --no-check-certificate 2>/var/log/wget; then /sbin/sysupgrade -F -n /tmp/update.bin fi """ elif device.model.wwan and ((not device.wireless) or device.wireless < device.changed): code = """ . /etc/vpnsecret if /usr/bin/wget -O/tmp/wireless.in https://admin360.kumi.host/wireless --post-data "secret=$SECRET" --no-check-certificate 2>/var/log/wget; then while read p do echo $p >/tmp/wireless.line if /bin/grep wifi-iface /tmp/wireless.line && ! /bin/grep radio /tmp/wireless.line; then break fi echo $p >>/tmp/wireless.og done >/tmp/wireless.og /bin/cp /tmp/wireless.og /etc/config/wireless /sbin/uci commit /etc/config/wireless /bin/rm /tmp/wireless.* fi """ device.lastbeat = timezone.now() elif device.reboot: code = "/sbin/reboot" else: code = "" device.lastbeat = timezone.now() if ip: device.lasttime = timezone.now() device.curip = ip device.save() return code