def load_drivers(self): subprocess.check_call("sudo mount -o remount,rw /", shell=True) subprocess.check_call("sudo mount -o remount,rw /root_bypass_ramdisks", shell=True) mac = subprocess.check_output("/sbin/ifconfig eth0 |grep -Eo ..\(\:..\){5}", shell=True).decode('utf-8').split('\n')[0] #response = requests.get(url, auth=(username, db_uuid.split('\n')[0]), stream=True) server = get_eagle_server_url() if server: urllib3.disable_warnings() pm = urllib3.PoolManager(cert_reqs='CERT_NONE') resp = False server = server + '/iot/get_drivers' try: resp = pm.request('POST', server, fields={'mac': mac}) except Exception as e: _logger.error('Could not reach configured server') _logger.error('A error encountered : %s ' % e) if resp and resp.data: zip_file = zipfile.ZipFile(io.BytesIO(resp.data)) zip_file.extractall(get_resource_path('hw_drivers', 'drivers')) subprocess.check_call("sudo service eagle restart", shell=True) subprocess.check_call("sudo mount -o remount,ro /", shell=True) subprocess.check_call("sudo mount -o remount,ro /root_bypass_ramdisks", shell=True) return "<meta http-equiv='refresh' content='20; url=http://" + get_ip() + ":8069/list_drivers'>"
def get_homepage_data(self): hostname = str(socket.gethostname()) mac = get_mac() h = iter(hex(mac)[2:].zfill(12)) ssid = subprocess.check_output('iwconfig 2>&1 | grep \'ESSID:"\' | sed \'s/.*"\\(.*\\)"/\\1/\'', shell=True).decode('utf-8').rstrip() wired = subprocess.check_output('cat /sys/class/net/eth0/operstate', shell=True).decode('utf-8').strip('\n') if wired == 'up': network = 'Ethernet' elif ssid: if access_point(): network = 'Wifi access point' else: network = 'Wifi : ' + ssid else: network = 'Not Connected' pos_device = self.get_pos_device_status() iot_device = [] for status in pos_device: if pos_device[status]['status'] == 'connected': iot_device.append({ 'name': status, 'type': 'device', 'message': ' '.join(pos_device[status]['messages']) }) for device in iot_devices: iot_device.append({ 'name': iot_devices[device].device_name + ' : ' + str(iot_devices[device].data['value']), 'type': iot_devices[device].device_type, 'message': iot_devices[device].device_identifier + iot_devices[device].get_message() }) return { 'hostname': hostname, 'ip': get_ip(), 'mac': ":".join(i + next(h) for i in h), 'iot_device_status': iot_device, 'server_status': get_eagle_server_url() or 'Not Configured', 'network_status': network, }
def access_point(): return get_ip() == '10.11.12.1'
def connect_to_server(self, token, iotname): url = token.split('|')[0] token = token.split('|')[1] reboot = 'reboot' subprocess.check_call([get_resource_path('point_of_sale', 'tools/posbox/configuration/connect_to_server.sh'), url, iotname, token, reboot]) return 'http://' + get_ip() + ':8069'
def clear_drivers_list(self): os.system(get_resource_path('point_of_sale', 'tools/posbox/configuration/clear_drivers_list.sh')) return "<meta http-equiv='refresh' content='0; url=http://" + get_ip() + ":8069/list_drivers'>"