From 9beebd4141cb9538b6c710dec1d23c8a7b149786 Mon Sep 17 00:00:00 2001 From: vifo Date: Mon, 22 Jan 2024 15:32:19 +0100 Subject: [PATCH] [FIX] iot: Generate new password at launch Generate a new password at launch for security reasons 3696215 closes odoo/odoo#150776 X-original-commit: 5e985abdd2a10f359438b5d4f276778e17559f24 Signed-off-by: Quentin Lejeune (qle) Signed-off-by: Yaroslav Soroko (yaso) --- addons/hw_drivers/main.py | 3 +- addons/hw_drivers/tools/helpers.py | 50 ++++++++++++++---------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/addons/hw_drivers/main.py b/addons/hw_drivers/main.py index 9987824d52f..7f21d15d56a 100644 --- a/addons/hw_drivers/main.py +++ b/addons/hw_drivers/main.py @@ -89,8 +89,9 @@ class Manager(Thread): """ helpers.start_nginx_server() - if platform.system() == 'Linux': + if platform.system() == 'Linux' and helpers.get_odoo_server_url(): helpers.check_git_branch() + helpers.generate_password() is_certificate_ok, certificate_details = helpers.get_certificate_status() if not is_certificate_ok: _logger.warning("An error happened when trying to get the HTTPS certificate: %s", diff --git a/addons/hw_drivers/tools/helpers.py b/addons/hw_drivers/tools/helpers.py index 0bfc2dece75..5a1fb547bf3 100644 --- a/addons/hw_drivers/tools/helpers.py +++ b/addons/hw_drivers/tools/helpers.py @@ -130,37 +130,35 @@ def check_git_branch(): checkout to match it if needed. """ server = get_odoo_server_url() - if server: - urllib3.disable_warnings() - http = urllib3.PoolManager(cert_reqs='CERT_NONE') - try: - response = http.request( - 'POST', - server + "/web/webclient/version_info", - body = '{}', - headers = {'Content-type': 'application/json'} - ) + urllib3.disable_warnings() + http = urllib3.PoolManager(cert_reqs='CERT_NONE') + try: + response = http.request('POST', + server + "/web/webclient/version_info", + body='{}', + headers={'Content-type': 'application/json'} + ) - if response.status == 200: - git = ['git', '--work-tree=/home/pi/odoo/', '--git-dir=/home/pi/odoo/.git'] + if response.status == 200: + git = ['git', '--work-tree=/home/pi/odoo/', '--git-dir=/home/pi/odoo/.git'] - db_branch = json.loads(response.data)['result']['server_serie'].replace('~', '-') - if not subprocess.check_output(git + ['ls-remote', 'origin', db_branch]): - db_branch = 'master' + db_branch = json.loads(response.data)['result']['server_serie'].replace('~', '-') + if not subprocess.check_output(git + ['ls-remote', 'origin', db_branch]): + db_branch = 'master' - local_branch = subprocess.check_output(git + ['symbolic-ref', '-q', '--short', 'HEAD']).decode('utf-8').rstrip() + local_branch = subprocess.check_output(git + ['symbolic-ref', '-q', '--short', 'HEAD']).decode('utf-8').rstrip() - if db_branch != local_branch: - with writable(): - subprocess.check_call(["rm", "-rf", "/home/pi/odoo/addons/hw_drivers/iot_handlers/drivers/*"]) - subprocess.check_call(["rm", "-rf", "/home/pi/odoo/addons/hw_drivers/iot_handlers/interfaces/*"]) - subprocess.check_call(git + ['branch', '-m', db_branch]) - subprocess.check_call(git + ['remote', 'set-branches', 'origin', db_branch]) - os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/posbox_update.sh') + if db_branch != local_branch: + with writable(): + subprocess.check_call(["rm", "-rf", "/home/pi/odoo/addons/hw_drivers/iot_handlers/drivers/*"]) + subprocess.check_call(["rm", "-rf", "/home/pi/odoo/addons/hw_drivers/iot_handlers/interfaces/*"]) + subprocess.check_call(git + ['branch', '-m', db_branch]) + subprocess.check_call(git + ['remote', 'set-branches', 'origin', db_branch]) + os.system('/home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/posbox_update.sh') - except Exception as e: - _logger.error('Could not reach configured server') - _logger.error('A error encountered : %s ' % e) + except Exception as e: + _logger.error('Could not reach configured server') + _logger.error('A error encountered : %s ', e) def check_image(): """