예제 #1
0
 def load_url(self):
     if helpers.get_odoo_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_odoo_server_url(), helpers.get_mac_address()))
             urls = json.loads(response.data.decode('utf8'))
             return self.update_url(urls[self.device_identifier])
         except json.decoder.JSONDecodeError:
             return self.update_url(response.get(data.decode('utf8'), False))
         except Exception:
             pass
     return self.update_url()
예제 #2
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 = helpers.get_odoo_server_url()
        res_payload = {
            'message': 'Connecting to ' + essid,
        }
        if server:
            res_payload['server'] = {
                'url': server,
                'message': 'Redirect to Odoo Server'
            }
        else:
            res_payload['server'] = {
                'url': 'http://' + helpers.get_ip() + ':8069',
                'message': 'Redirect to IoT Box'
            }

        return json.dumps(res_payload)
예제 #3
0
    def get_homepage_data(self):
        hostname = str(socket.gethostname())
        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.replace('_', ' '),
                'message': iot_devices[device].device_identifier + iot_devices[device].get_message()
            })

        return {
            'hostname': hostname,
            'ip': helpers.get_ip(),
            'mac': helpers.get_mac_address(),
            'iot_device_status': iot_device,
            'server_status': helpers.get_odoo_server_url() or 'Not Configured',
            'six_terminal': self.get_six_terminal(),
            'network_status': network,
            'version': helpers.get_version(),
            }
 def load_url(self):
     url = None
     if helpers.get_odoo_server_url():
         # disable certifiacte verification
         urllib3.disable_warnings()
         http = urllib3.PoolManager(cert_reqs='CERT_NONE')
         try:
             response = http.request('GET', "%s/iot/box/%s/display_url" % (helpers.get_odoo_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)
예제 #5
0
파일: driver.py 프로젝트: Bk-Soft10/odoo-13
 def connect_box(self, token):
     """
     This route is called when we want that a IoT Box will be connected to a Odoo DB
     token is a base 64 encoded string and have 2 argument separate by |
     1 - url of odoo DB
     2 - token. This token will be compared to the token of Odoo. He have 1 hour lifetime
     """
     server = helpers.get_odoo_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()
예제 #6
0
파일: main.py 프로젝트: yasminejamal/odoo
    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 = helpers.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://" + helpers.get_ip(
        ) + ":8069/list_drivers'>"
예제 #7
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': helpers.get_odoo_server_url() or 'Not configured yet',
         'loading_message': 'Configure Domain Server'
     })
예제 #8
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': helpers.get_wifi_essid(),
         'server': helpers.get_odoo_server_url() or '',
         'hostname': subprocess.check_output('hostname').decode('utf-8').strip('\n'),
     })
 def run(self):
     if not helpers.get_odoo_server_url() and not helpers.access_point():
         end_time = datetime.now() + timedelta(minutes=5)
         while (datetime.now() < end_time):
             self._connect_box()
             time.sleep(10)
         self.pairing_code = False
         self.pairing_uuid = False
         self._refresh_displays()
예제 #10
0
파일: main.py 프로젝트: yasminejamal/odoo
    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 helpers.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': helpers.get_ip(),
            'mac': ":".join(i + next(h) for i in h),
            'iot_device_status': iot_device,
            'server_status': helpers.get_odoo_server_url() or 'Not Configured',
            'six_terminal': self.get_six_terminal(),
            'network_status': network,
            'version': helpers.get_version(),
        }
예제 #11
0
 def send_layouts_list(cls):
     server = helpers.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)
예제 #12
0
파일: main.py 프로젝트: karthik1710/odoo13
 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': helpers.get_odoo_server_url()
     })
예제 #13
0
 def send_alldevices(self):
     """
     This method send IoT Box and devices informations to Odoo database
     """
     server = helpers.get_odoo_server_url()
     if server:
         subject = helpers.read_file_first_line('odoo-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('Odoo server not set')
예제 #14
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 helpers.access_point():
         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_odoo_server_url(),
             'hostname': subprocess.check_output('hostname').decode('utf-8'),
             })
     else:
         return homepage_template.render(self.get_homepage_data())
예제 #15
0
 def __init__(self, device):
     super(PrinterDriver, self).__init__(device)
     self._device_type = 'printer'
     self._device_connection = self.dev['device-class'].lower()
     self._device_name = self.dev['device-make-and-model']
     self.state = {
         'status': 'connecting',
         'message': 'Connecting to printer',
         'reason': None,
     }
     self.send_status()
     if 'direct' in self._device_connection or helpers.get_odoo_server_url(
     ):
         self.add_connected_printer()
         self.print_status()
예제 #16
0
 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_odoo_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'
예제 #17
0
 def list_handlers(self):
     drivers_list = []
     for driver in os.listdir(get_resource_path('hw_drivers', 'iot_handlers/drivers')):
         if driver != '__pycache__':
             drivers_list.append(driver)
     interfaces_list = []
     for interface in os.listdir(get_resource_path('hw_drivers', 'iot_handlers/interfaces')):
         if interface != '__pycache__':
             interfaces_list.append(interface)
     return handler_list_template.render({
         'title': "Odoo's IoT Box - Handlers list",
         'breadcrumb': 'Handlers list',
         'drivers_list': drivers_list,
         'interfaces_list': interfaces_list,
         'server': helpers.get_odoo_server_url()
     })