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()
def _connect_to_server(self, url, token, db_uuid, enterprise_code): if db_uuid and enterprise_code: helpers.add_credential(db_uuid, enterprise_code) # Save DB URL and token subprocess.check_call([get_resource_path('point_of_sale', 'tools/posbox/configuration/connect_to_server.sh'), url, '', token, 'noreboot']) # Notify the DB, so that the kanban view already shows the IoT Box m.send_alldevices() # Restart to checkout the git branch, get a certificate, load the IoT handlers... subprocess.check_call(["sudo", "service", "odoo", "restart"])
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'
def save_credential(self, db_uuid, enterprise_code): helpers.add_credential(db_uuid, enterprise_code) subprocess.check_call(["sudo", "service", "odoo", "restart"]) return "<meta http-equiv='refresh' content='20; url=http://" + helpers.get_ip() + ":8069'>"