def get_homepage_data(self): hostname = str(socket.gethostname()) mac = get_mac() h = iter(hex(mac)[2:].zfill(12)) ssid = helpers.get_ssid() wired = subprocess.check_output(['cat', '/sys/class/net/eth0/operstate']).decode('utf-8').strip('\n') if wired == 'up': network = 'Ethernet' elif ssid: if helpers.access_point(): network = 'Wifi access point' else: network = 'Wifi : ' + ssid else: network = 'Not Connected' iot_device = [] 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': helpers.get_ip(), 'mac': ":".join(i + next(h) for i in h), 'iot_device_status': iot_device, 'server_status': helpers.get_eagle_server_url() or 'Not Configured', 'six_terminal': self.get_six_terminal(), 'network_status': network, 'version': helpers.get_version(), }
def connect_box(self, token): """ This route is called when we want that a IoT Box will be connected to a Eagle DB token is a base 64 encoded string and have 2 argument separate by | 1 - url of eagle DB 2 - token. This token will be compared to the token of Eagle. He have 1 hour lifetime """ server = helpers.get_eagle_server_url() image = get_resource_path('hw_drivers', 'static/img', 'False.jpg') if server == '': credential = b64decode(token).decode('utf-8').split('|') url = credential[0] token = credential[1] if len(credential) > 2: # IoT Box send token with db_uuid and enterprise_code only since V13 db_uuid = credential[2] enterprise_code = credential[3] helpers.add_credential(db_uuid, enterprise_code) try: subprocess.check_call([ get_resource_path( 'point_of_sale', 'tools/posbox/configuration/connect_to_server.sh'), url, '', token, 'noreboot' ]) helpers.check_certificate() m.send_alldevices() m.load_drivers() image = get_resource_path('hw_drivers', 'static/img', 'True.jpg') except subprocess.CalledProcessError as e: _logger.error('A error encountered : %s ' % e.output) if os.path.isfile(image): with open(image, 'rb') as f: return f.read()
def server(self): return server_config_template.render({ 'title': 'IoT -> Eagle server configuration', 'breadcrumb': 'Configure Eagle Server', 'hostname': subprocess.check_output('hostname').decode('utf-8').strip('\n'), 'server_status': helpers.get_eagle_server_url() or 'Not configured yet', 'loading_message': 'Configure Domain Server' })
def step_by_step_configure_page(self): return configure_wizard_template.render({ 'title': 'Configure IoT Box', 'breadcrumb': 'Configure IoT Box', 'loading_message': 'Configuring your IoT Box', 'ssid': helpers.get_wifi_essid(), 'server': helpers.get_eagle_server_url(), 'hostname': subprocess.check_output('hostname').decode('utf-8').strip('\n'), })
def load_url(self): url = None if helpers.get_eagle_server_url(): # disable certifiacte verification urllib3.disable_warnings() http = urllib3.PoolManager(cert_reqs='CERT_NONE') try: response = http.request( 'GET', "%s/iot/box/%s/screen_url" % (helpers.get_eagle_server_url(), helpers.get_mac_address())) if response.status == 200: data = json.loads(response.data.decode('utf8')) url = data[self.device_identifier] except json.decoder.JSONDecodeError: url = response.data.decode('utf8') except Exception: pass return self.update_url(url)
def send_layouts_list(cls): server = helpers.get_eagle_server_url() if server: urllib3.disable_warnings() pm = urllib3.PoolManager(cert_reqs='CERT_NONE') server = server + '/iot/keyboard_layouts' try: pm.request('POST', server, fields={'available_layouts': json.dumps(cls.available_layouts)}) except Exception as e: _logger.error('Could not reach configured server') _logger.error('A error encountered : %s ' % e)
def list_drivers(self): drivers_list = [] for driver in os.listdir(get_resource_path('hw_drivers', 'drivers')): if driver != '__pycache__': drivers_list.append(driver) return driver_list_template.render({ 'title': "Eagle's IoT Box - Drivers list", 'breadcrumb': 'Drivers list', 'drivers_list': drivers_list, 'server': helpers.get_eagle_server_url() })
def send_alldevices(self): """ This method send IoT Box and devices informations to Eagle database """ server = helpers.get_eagle_server_url() if server: subject = helpers.read_file_first_line('eagle-subject.conf') if subject: domain = helpers.get_ip().replace('.', '-') + subject.strip('*') else: domain = helpers.get_ip() iot_box = { 'name': socket.gethostname(), 'identifier': helpers.get_mac_address(), 'ip': domain, 'token': helpers.get_token(), 'version': helpers.get_version() } devices_list = {} for device in iot_devices: identifier = iot_devices[device].device_identifier devices_list[identifier] = { 'name': iot_devices[device].device_name, 'type': iot_devices[device].device_type, 'manufacturer': iot_devices[device].device_manufacturer, 'connection': iot_devices[device].device_connection, } data = { 'params': { 'iot_box': iot_box, 'devices': devices_list, } } # disable certifiacte verification urllib3.disable_warnings() http = urllib3.PoolManager(cert_reqs='CERT_NONE') try: http.request('POST', server + "/iot/setup", body=json.dumps(data).encode('utf8'), headers={ 'Content-type': 'application/json', 'Accept': 'text/plain' }) except Exception as e: _logger.error('Could not reach configured server') _logger.error('A error encountered : %s ' % e) else: _logger.warning('Eagle server not set')
def connect_to_server(self, token, iotname): if token: credential = token.split('|') url = credential[0] token = credential[1] if len(credential) > 2: # IoT Box send token with db_uuid and enterprise_code only since V13 db_uuid = credential[2] enterprise_code = credential[3] helpers.add_credential(db_uuid, enterprise_code) else: url = helpers.get_eagle_server_url() token = helpers.get_token() reboot = 'reboot' subprocess.check_call([get_resource_path('point_of_sale', 'tools/posbox/configuration/connect_to_server.sh'), url, iotname, token, reboot]) return 'http://' + helpers.get_ip() + ':8069'
def connect_to_wifi(self, essid, password, persistent=False): if persistent: persistent = "1" else: persistent = "" subprocess.check_call([get_resource_path('point_of_sale', 'tools/posbox/configuration/connect_to_wifi.sh'), essid, password, persistent]) server = helpers.get_eagle_server_url() res_payload = { 'message': 'Connecting to ' + essid, } if server: res_payload['server'] = { 'url': server, 'message': 'Redirect to Eagle Server' } else: res_payload['server'] = { 'url': 'http://' + helpers.get_ip() + ':8069', 'message': 'Redirect to IoT Box' } return json.dumps(res_payload)