Пример #1
0
    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_odoo_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 odoo 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'>"
Пример #2
0
    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_odoo_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 odoo 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'>"
Пример #3
0
 def server(self):
     return server_config_template.render({
         'title': 'IoT -> Odoo server configuration',
         'breadcrumb': 'Configure Odoo Server',
         'hostname': subprocess.check_output('hostname').decode('utf-8').strip('\n'),
         'server_status': get_odoo_server_url() or 'Not configured yet',
         'loading_message': 'Configure Domain Server'
     })
Пример #4
0
 def server(self):
     return server_config_template.render({
         'title': 'IoT -> Odoo server configuration',
         'breadcrumb': 'Configure Odoo Server',
         'hostname': subprocess.check_output('hostname').decode('utf-8').strip('\n'),
         'server_status': get_odoo_server_url() or 'Not configured yet',
         'loading_message': 'Configure Domain Server'
     })
Пример #5
0
 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': self.get_wifi_essid(),
         'server': get_odoo_server_url(),
         'hostname': subprocess.check_output('hostname').decode('utf-8').strip('\n'),
     })
Пример #6
0
 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': self.get_wifi_essid(),
         'server': get_odoo_server_url(),
         'hostname': subprocess.check_output('hostname').decode('utf-8').strip('\n'),
     })
Пример #7
0
    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 = []

        if not iot_devices:
            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_odoo_server_url() or 'Not Configured',
            'six_terminal': self.get_six_terminal(),
            'network_status': network,
        }
Пример #8
0
 def send_layouts_list(cls):
     server = get_odoo_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)
Пример #9
0
 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': "Odoo's IoT Box - Drivers list",
         'breadcrumb': 'Drivers list',
         'drivers_list': drivers_list,
         'server': get_odoo_server_url()
     })
Пример #10
0
 def index(self):
     wifi = Path.home() / 'wifi_network.txt'
     remote_server = Path.home() / 'odoo-remote-server.conf'
     if (wifi.exists() == False or remote_server.exists() == False) and access_point():
         return configure_wizard_template.render({
             'title': 'Configure IoT Box',
             'breadcrumb': 'Configure IoT Box',
             'loading_message': 'Configuring your IoT Box',
             'ssid': self.get_wifi_essid(),
             'server': get_odoo_server_url(),
             'hostname': subprocess.check_output('hostname').decode('utf-8'),
             })
     else:
         return homepage_template.render(self.get_homepage_data())
Пример #11
0
 def index(self):
     wifi = Path.home() / 'wifi_network.txt'
     remote_server = Path.home() / 'odoo-remote-server.conf'
     if (wifi.exists() == False or remote_server.exists() == False) and access_point():
         return configure_wizard_template.render({
             'title': 'Configure IoT Box',
             'breadcrumb': 'Configure IoT Box',
             'loading_message': 'Configuring your IoT Box',
             'ssid': self.get_wifi_essid(),
             'server': get_odoo_server_url(),
             'hostname': subprocess.check_output('hostname').decode('utf-8'),
             })
     else:
         return homepage_template.render(self.get_homepage_data())
Пример #12
0
    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 = get_odoo_server_url()
        res_payload = {
            'message': 'Connecting to ' + essid,
        }
        if server:
            res_payload['server'] = {
                'url': server,
                'message': 'Redirect to Odoo Server'
            }

        return json.dumps(res_payload)
Пример #13
0
    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 = get_odoo_server_url()
        res_payload = {
            'message': 'Connecting to ' + essid,
        }
        if server:
            res_payload['server'] = {
                'url': server,
                'message': 'Redirect to Odoo Server'
            }

        return json.dumps(res_payload)
Пример #14
0
    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_odoo_server_url() or 'Not Configured',
            'network_status': network,
            }