From be03f8a89a2ca72a4224c0c8354028dd99253978 Mon Sep 17 00:00:00 2001 From: Scott King Date: Fri, 17 Nov 2023 10:51:01 -0700 Subject: [PATCH 1/2] Fix https://github.com/usmannasir/cyberpanel/issues/842 --- cli/cyberPanel.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cli/cyberPanel.py b/cli/cyberPanel.py index 7c34ece6e..45dd7b153 100755 --- a/cli/cyberPanel.py +++ b/cli/cyberPanel.py @@ -124,8 +124,7 @@ class cyberPanel: ipData = f.read() ipAddress = ipData.split('\n', 1)[0] - json_data = "[" - checker = 0 + json_data = [] for items in websites: if items.state == 0: @@ -134,14 +133,8 @@ class cyberPanel: state = "Active" dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress, 'admin': items.admin.userName, 'package': items.package.packageName, 'state': state} + json_data.append(dic) - if checker == 0: - json_data = json_data + json.dumps(dic) - checker = 1 - else: - json_data = json_data + ',' + json.dumps(dic) - - json_data = json_data + ']' final_json = json.dumps(json_data) print(final_json) From 042b858e1ce196c1834d362ea64dc4274e203e10 Mon Sep 17 00:00:00 2001 From: Scott King Date: Fri, 17 Nov 2023 10:58:27 -0700 Subject: [PATCH 2/2] use `with open()` so the file actually gets closed --- cli/cyberPanel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/cyberPanel.py b/cli/cyberPanel.py index 45dd7b153..0e3c51f8b 100755 --- a/cli/cyberPanel.py +++ b/cli/cyberPanel.py @@ -120,8 +120,8 @@ class cyberPanel: websites = Websites.objects.all() ipFile = "/etc/cyberpanel/machineIP" - f = open(ipFile) - ipData = f.read() + with open(ipFile, 'r') as f: + ipData = f.read() ipAddress = ipData.split('\n', 1)[0] json_data = []