From ae35e160931c420076a0fbe5ef31f3f57761e1ad Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Fri, 15 Feb 2019 11:52:55 +0100 Subject: [PATCH] [IMP] IoT : Automatic registration of the IoT Box in HTTPS without certificate When we are on HTTPS and we want to connect a box with the scan we need to accept manually the certificate of the box. With this commit we don't need to accept manually the certificate. We don't have problem of mixed content if we use the onload method of Image object So we load a image and put on parameter the token of the odoo DB to make a connection. --- addons/hw_drivers/controllers/driver.py | 41 ++++++++++++------------ addons/hw_drivers/static/img/False.jpg | Bin 0 -> 546 bytes addons/hw_drivers/static/img/True.jpg | Bin 0 -> 542 bytes 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 addons/hw_drivers/static/img/False.jpg create mode 100644 addons/hw_drivers/static/img/True.jpg diff --git a/addons/hw_drivers/controllers/driver.py b/addons/hw_drivers/controllers/driver.py index 0fbc9962e56..64d45a1fcfc 100755 --- a/addons/hw_drivers/controllers/driver.py +++ b/addons/hw_drivers/controllers/driver.py @@ -88,27 +88,28 @@ class StatusController(http.Controller): req['result']['session_id'] = req['session_id'] return req['result'] - @http.route('/hw_drivers/box/connect', type='json', auth='none', cors='*', csrf=False) + @http.route('/hw_drivers/box/connect', type='http', auth='none', cors='*', csrf=False, save_session=False) def connect_box(self, token): - server = "" # read from file - try: - f = open('/home/pi/odoo-remote-server.conf', 'r') - for line in f: - server += line - f.close() - server = server.split('\n')[0] - except: - server = '' - if server: - return 'This IoTBox has already been connected' - else: - iotname = '' - token = token.split('|')[1] - url = token.split('|')[0] - reboot = 'noreboot' - subprocess.call([home() + '/odoo/addons/point_of_sale/tools/posbox/configuration/connect_to_server.sh', url, iotname, token, reboot]) - send_iot_box_device(False) - return 'IoTBox connected' + """ + 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 = get_odoo_server_url() + image = get_resource_path('hw_drivers', 'static/img', 'False.jpg') + if server == '': + token = b64decode(token).decode('utf-8') + url, token = token.split('|') + try: + subprocess.check_call([get_resource_path('point_of_sale', 'tools/posbox/configuration/connect_to_server.sh'), url, '', token, 'noreboot']) + m.send_alldevices() + 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() #---------------------------------------------------------- # Drivers diff --git a/addons/hw_drivers/static/img/False.jpg b/addons/hw_drivers/static/img/False.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8f8e6489b30a389e475551b03ade16dc9257cfe1 GIT binary patch literal 546 zcmb78u^izoN#@|~P>({p-c^|Kg1Yq_h>i>!(ND?`Gh2UGSyM46ADv=e=9x0 zYXk&I9>SCKl%5c|KfX)zI{exqy~0X@aMA(vFaf#^=ziKy8PseiB}NV4{{|#cMf(8p l1?-GyRhx*N09D7MZEr|E)7{l4_Xk?JL#;Nzo=^r}J^_c1N>Ts- literal 0 HcmV?d00001 diff --git a/addons/hw_drivers/static/img/True.jpg b/addons/hw_drivers/static/img/True.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0488574a699b8dcf2e9cdd48ac8896aa339d3805 GIT binary patch literal 542 zcmb7=sE2fY_bi*omlvb)J zlqt)ecE&kttgY&Suj)`+>qkBeV@k;#9F9kEJcucFpO9ovq54YoV`Z!OZ{-IB4Fe-7 zKm?M3@*@)W$9HL7$6s6I7dS}}UV4D;kIN48Kg|ten$4udqyxg=fFx>Z7a+cXtr5L; d6R{Pb_Gt3i8j_FncgsDU{Ju^bU`Hea&mS2iNcjK& literal 0 HcmV?d00001