Skip to content

Commit e1eefeb

Browse files
committed
Add platform-specific OpenLiteSpeed binaries with SHA256 checksum verification
This update adds automatic platform detection and checksum verification for OpenLiteSpeed custom binaries during installation and upgrade. Changes: - Add detectPlatform() method to detect RHEL 8, RHEL 9, and Ubuntu - Update binary URLs to use platform-specific paths: * RHEL 8: /binaries/rhel8/ * RHEL 9: /binaries/rhel9/ * Ubuntu: /binaries/ubuntu/ - Add SHA256 checksum verification to downloadCustomBinary() - Update installCustomOLSBinaries() to use platform-specific checksums Binary Versions (OpenLiteSpeed v1.8.4.1 - Module v2.0.4): - RHEL 8 Module: 1cc71f54d8ae5937d0bd2b2dd27678b47f09f4f7afed2583bbd3493ddd05877f - RHEL 9 Module: 127227db81bcbebf80b225fc747b69cfcd4ad2f01cea486aa02d5c9ba6c18109 - Ubuntu Module: d070952fcfe27fac2f2c95db9ae31252071bade2cdcff19cf3b3f7812fa9413a - All Binary: a6e07671ee1c9bcc7f2d12de9e95139315cf288709fb23bf431eb417299ad4e9 Files modified: - install/installCyberPanel.py - plogical/upgrade.py
1 parent 4650fa2 commit e1eefeb

File tree

2 files changed

+204
-30
lines changed

2 files changed

+204
-30
lines changed

install/installCyberPanel.py

Lines changed: 102 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,42 @@ def detectArchitecture(self):
224224
logging.InstallLog.writeToFile(str(msg) + " [detectArchitecture]")
225225
return False
226226

227-
def downloadCustomBinary(self, url, destination):
228-
"""Download custom binary file"""
227+
def detectPlatform(self):
228+
"""Detect OS platform for binary selection (rhel8, rhel9, ubuntu)"""
229+
try:
230+
# Check for Ubuntu
231+
if os.path.exists('/etc/lsb-release'):
232+
with open('/etc/lsb-release', 'r') as f:
233+
content = f.read()
234+
if 'Ubuntu' in content or 'ubuntu' in content:
235+
return 'ubuntu'
236+
237+
# Check for RHEL-based distributions
238+
if os.path.exists('/etc/os-release'):
239+
with open('/etc/os-release', 'r') as f:
240+
content = f.read().lower()
241+
242+
# Check for version 8.x (RHEL, AlmaLinux, Rocky, CloudLinux, CentOS 8)
243+
if 'version="8.' in content or 'version_id="8.' in content:
244+
if any(distro in content for distro in ['red hat', 'almalinux', 'rocky', 'cloudlinux', 'centos']):
245+
return 'rhel8'
246+
247+
# Check for version 9.x
248+
if 'version="9.' in content or 'version_id="9.' in content:
249+
if any(distro in content for distro in ['red hat', 'almalinux', 'rocky', 'cloudlinux', 'centos']):
250+
return 'rhel9'
251+
252+
# Default to rhel9 if can't detect (safer default for newer systems)
253+
InstallCyberPanel.stdOut("WARNING: Could not detect platform, defaulting to rhel9", 1)
254+
return 'rhel9'
255+
256+
except Exception as msg:
257+
logging.InstallLog.writeToFile(str(msg) + " [detectPlatform]")
258+
InstallCyberPanel.stdOut(f"ERROR detecting platform: {msg}, defaulting to rhel9", 1)
259+
return 'rhel9'
260+
261+
def downloadCustomBinary(self, url, destination, expected_sha256=None):
262+
"""Download custom binary file with optional checksum verification"""
229263
try:
230264
InstallCyberPanel.stdOut(f"Downloading {os.path.basename(destination)}...", 1)
231265

@@ -242,7 +276,27 @@ def downloadCustomBinary(self, url, destination):
242276
InstallCyberPanel.stdOut(f"Downloaded successfully ({file_size / (1024*1024):.2f} MB)", 1)
243277
else:
244278
InstallCyberPanel.stdOut(f"Downloaded successfully ({file_size / 1024:.2f} KB)", 1)
245-
return True
279+
280+
# Verify checksum if provided
281+
if expected_sha256:
282+
InstallCyberPanel.stdOut("Verifying checksum...", 1)
283+
import hashlib
284+
sha256_hash = hashlib.sha256()
285+
with open(destination, "rb") as f:
286+
for byte_block in iter(lambda: f.read(4096), b""):
287+
sha256_hash.update(byte_block)
288+
actual_sha256 = sha256_hash.hexdigest()
289+
290+
if actual_sha256 == expected_sha256:
291+
InstallCyberPanel.stdOut("Checksum verified successfully", 1)
292+
return True
293+
else:
294+
InstallCyberPanel.stdOut(f"ERROR: Checksum mismatch!", 1)
295+
InstallCyberPanel.stdOut(f"Expected: {expected_sha256}", 1)
296+
InstallCyberPanel.stdOut(f"Got: {actual_sha256}", 1)
297+
return False
298+
else:
299+
return True
246300
else:
247301
InstallCyberPanel.stdOut(f"ERROR: Downloaded file too small ({file_size} bytes)", 1)
248302
return False
@@ -261,19 +315,52 @@ def installCustomOLSBinaries(self):
261315
InstallCyberPanel.stdOut("Installing Custom OpenLiteSpeed Binaries", 1)
262316
InstallCyberPanel.stdOut("=" * 50, 1)
263317

264-
# URLs for custom binaries
265-
OLS_BINARY_URL = "https://cyberpanel.net/openlitespeed-phpconfig-x86_64"
266-
MODULE_URL = "https://cyberpanel.net/cyberpanel_ols_x86_64.so"
267-
OLS_BINARY_PATH = "/usr/local/lsws/bin/openlitespeed"
268-
MODULE_PATH = "/usr/local/lsws/modules/cyberpanel_ols.so"
269-
270318
# Check architecture
271319
if not self.detectArchitecture():
272320
InstallCyberPanel.stdOut("WARNING: Custom binaries only available for x86_64", 1)
273321
InstallCyberPanel.stdOut("Skipping custom binary installation", 1)
274322
InstallCyberPanel.stdOut("Standard OLS will be used", 1)
275323
return True # Not a failure, just skip
276324

325+
# Detect platform
326+
platform = self.detectPlatform()
327+
InstallCyberPanel.stdOut(f"Detected platform: {platform}", 1)
328+
329+
# Platform-specific URLs and checksums (OpenLiteSpeed v1.8.4.1 - v2.0.4)
330+
BINARY_CONFIGS = {
331+
'rhel8': {
332+
'url': 'https://cyberpanel.net/binaries/rhel8/openlitespeed-phpconfig-x86_64-rhel8',
333+
'sha256': 'a6e07671ee1c9bcc7f2d12de9e95139315cf288709fb23bf431eb417299ad4e9',
334+
'module_url': 'https://cyberpanel.net/binaries/rhel8/cyberpanel_ols_x86_64_rhel8.so',
335+
'module_sha256': '1cc71f54d8ae5937d0bd2b2dd27678b47f09f4f7afed2583bbd3493ddd05877f'
336+
},
337+
'rhel9': {
338+
'url': 'https://cyberpanel.net/binaries/rhel9/openlitespeed-phpconfig-x86_64-rhel9',
339+
'sha256': 'a6e07671ee1c9bcc7f2d12de9e95139315cf288709fb23bf431eb417299ad4e9',
340+
'module_url': 'https://cyberpanel.net/binaries/rhel9/cyberpanel_ols_x86_64_rhel9.so',
341+
'module_sha256': 'b5841fa6863bbd9dbac4017acfa946bd643268d6ca0cf16a0cd2f717cfb30330'
342+
},
343+
'ubuntu': {
344+
'url': 'https://cyberpanel.net/binaries/ubuntu/openlitespeed-phpconfig-x86_64-ubuntu',
345+
'sha256': 'c6a6b4dddd63a4e4ac9b1b51f6db5bd79230f3219e39397de173518ced198d36',
346+
'module_url': 'https://cyberpanel.net/binaries/ubuntu/cyberpanel_ols_x86_64_ubuntu.so',
347+
'module_sha256': 'd070952fcfe27fac2f2c95db9ae31252071bade2cdcff19cf3b3f7812fa9413a'
348+
}
349+
}
350+
351+
config = BINARY_CONFIGS.get(platform)
352+
if not config:
353+
InstallCyberPanel.stdOut(f"ERROR: No binaries available for platform {platform}", 1)
354+
InstallCyberPanel.stdOut("Skipping custom binary installation", 1)
355+
return True # Not fatal
356+
357+
OLS_BINARY_URL = config['url']
358+
OLS_BINARY_SHA256 = config['sha256']
359+
MODULE_URL = config['module_url']
360+
MODULE_SHA256 = config['module_sha256']
361+
OLS_BINARY_PATH = "/usr/local/lsws/bin/openlitespeed"
362+
MODULE_PATH = "/usr/local/lsws/modules/cyberpanel_ols.so"
363+
277364
# Create backup
278365
from datetime import datetime
279366
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
@@ -293,15 +380,15 @@ def installCustomOLSBinaries(self):
293380

294381
InstallCyberPanel.stdOut("Downloading custom binaries...", 1)
295382

296-
# Download OpenLiteSpeed binary
297-
if not self.downloadCustomBinary(OLS_BINARY_URL, tmp_binary):
298-
InstallCyberPanel.stdOut("ERROR: Failed to download OLS binary", 1)
383+
# Download OpenLiteSpeed binary with checksum verification
384+
if not self.downloadCustomBinary(OLS_BINARY_URL, tmp_binary, OLS_BINARY_SHA256):
385+
InstallCyberPanel.stdOut("ERROR: Failed to download or verify OLS binary", 1)
299386
InstallCyberPanel.stdOut("Continuing with standard OLS", 1)
300387
return True # Not fatal, continue with standard OLS
301388

302-
# Download module
303-
if not self.downloadCustomBinary(MODULE_URL, tmp_module):
304-
InstallCyberPanel.stdOut("ERROR: Failed to download module", 1)
389+
# Download module with checksum verification
390+
if not self.downloadCustomBinary(MODULE_URL, tmp_module, MODULE_SHA256):
391+
InstallCyberPanel.stdOut("ERROR: Failed to download or verify module", 1)
305392
InstallCyberPanel.stdOut("Continuing with standard OLS", 1)
306393
return True # Not fatal, continue with standard OLS
307394

plogical/upgrade.py

Lines changed: 102 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,42 @@ def detectArchitecture():
631631
return False
632632

633633
@staticmethod
634-
def downloadCustomBinary(url, destination):
635-
"""Download custom binary file"""
634+
def detectPlatform():
635+
"""Detect OS platform for binary selection (rhel8, rhel9, ubuntu)"""
636+
try:
637+
# Check for Ubuntu
638+
if os.path.exists('/etc/lsb-release'):
639+
with open('/etc/lsb-release', 'r') as f:
640+
content = f.read()
641+
if 'Ubuntu' in content or 'ubuntu' in content:
642+
return 'ubuntu'
643+
644+
# Check for RHEL-based distributions
645+
if os.path.exists('/etc/os-release'):
646+
with open('/etc/os-release', 'r') as f:
647+
content = f.read().lower()
648+
649+
# Check for version 8.x (RHEL, AlmaLinux, Rocky, CloudLinux, CentOS 8)
650+
if 'version="8.' in content or 'version_id="8.' in content:
651+
if any(distro in content for distro in ['red hat', 'almalinux', 'rocky', 'cloudlinux', 'centos']):
652+
return 'rhel8'
653+
654+
# Check for version 9.x
655+
if 'version="9.' in content or 'version_id="9.' in content:
656+
if any(distro in content for distro in ['red hat', 'almalinux', 'rocky', 'cloudlinux', 'centos']):
657+
return 'rhel9'
658+
659+
# Default to rhel9 if can't detect (safer default for newer systems)
660+
Upgrade.stdOut("WARNING: Could not detect platform, defaulting to rhel9", 0)
661+
return 'rhel9'
662+
663+
except Exception as msg:
664+
Upgrade.stdOut(f"ERROR detecting platform: {msg}, defaulting to rhel9", 0)
665+
return 'rhel9'
666+
667+
@staticmethod
668+
def downloadCustomBinary(url, destination, expected_sha256=None):
669+
"""Download custom binary file with optional checksum verification"""
636670
try:
637671
Upgrade.stdOut(f"Downloading {os.path.basename(destination)}...", 0)
638672

@@ -649,7 +683,27 @@ def downloadCustomBinary(url, destination):
649683
Upgrade.stdOut(f"Downloaded successfully ({file_size / (1024*1024):.2f} MB)", 0)
650684
else:
651685
Upgrade.stdOut(f"Downloaded successfully ({file_size / 1024:.2f} KB)", 0)
652-
return True
686+
687+
# Verify checksum if provided
688+
if expected_sha256:
689+
Upgrade.stdOut("Verifying checksum...", 0)
690+
import hashlib
691+
sha256_hash = hashlib.sha256()
692+
with open(destination, "rb") as f:
693+
for byte_block in iter(lambda: f.read(4096), b""):
694+
sha256_hash.update(byte_block)
695+
actual_sha256 = sha256_hash.hexdigest()
696+
697+
if actual_sha256 == expected_sha256:
698+
Upgrade.stdOut("Checksum verified successfully", 0)
699+
return True
700+
else:
701+
Upgrade.stdOut(f"ERROR: Checksum mismatch!", 0)
702+
Upgrade.stdOut(f"Expected: {expected_sha256}", 0)
703+
Upgrade.stdOut(f"Got: {actual_sha256}", 0)
704+
return False
705+
else:
706+
return True
653707
else:
654708
Upgrade.stdOut(f"ERROR: Downloaded file too small ({file_size} bytes)", 0)
655709
return False
@@ -668,19 +722,52 @@ def installCustomOLSBinaries():
668722
Upgrade.stdOut("Installing Custom OpenLiteSpeed Binaries", 0)
669723
Upgrade.stdOut("=" * 50, 0)
670724

671-
# URLs for custom binaries
672-
OLS_BINARY_URL = "https://cyberpanel.net/openlitespeed-phpconfig-x86_64"
673-
MODULE_URL = "https://cyberpanel.net/cyberpanel_ols_x86_64.so"
674-
OLS_BINARY_PATH = "/usr/local/lsws/bin/openlitespeed"
675-
MODULE_PATH = "/usr/local/lsws/modules/cyberpanel_ols.so"
676-
677725
# Check architecture
678726
if not Upgrade.detectArchitecture():
679727
Upgrade.stdOut("WARNING: Custom binaries only available for x86_64", 0)
680728
Upgrade.stdOut("Skipping custom binary installation", 0)
681729
Upgrade.stdOut("Standard OLS will be used", 0)
682730
return True # Not a failure, just skip
683731

732+
# Detect platform
733+
platform = Upgrade.detectPlatform()
734+
Upgrade.stdOut(f"Detected platform: {platform}", 0)
735+
736+
# Platform-specific URLs and checksums (OpenLiteSpeed v1.8.4.1 - v2.0.4)
737+
BINARY_CONFIGS = {
738+
'rhel8': {
739+
'url': 'https://cyberpanel.net/binaries/rhel8/openlitespeed-phpconfig-x86_64-rhel8',
740+
'sha256': 'a6e07671ee1c9bcc7f2d12de9e95139315cf288709fb23bf431eb417299ad4e9',
741+
'module_url': 'https://cyberpanel.net/binaries/rhel8/cyberpanel_ols_x86_64_rhel8.so',
742+
'module_sha256': '1cc71f54d8ae5937d0bd2b2dd27678b47f09f4f7afed2583bbd3493ddd05877f'
743+
},
744+
'rhel9': {
745+
'url': 'https://cyberpanel.net/binaries/rhel9/openlitespeed-phpconfig-x86_64-rhel9',
746+
'sha256': 'a6e07671ee1c9bcc7f2d12de9e95139315cf288709fb23bf431eb417299ad4e9',
747+
'module_url': 'https://cyberpanel.net/binaries/rhel9/cyberpanel_ols_x86_64_rhel9.so',
748+
'module_sha256': 'b5841fa6863bbd9dbac4017acfa946bd643268d6ca0cf16a0cd2f717cfb30330'
749+
},
750+
'ubuntu': {
751+
'url': 'https://cyberpanel.net/binaries/ubuntu/openlitespeed-phpconfig-x86_64-ubuntu',
752+
'sha256': 'c6a6b4dddd63a4e4ac9b1b51f6db5bd79230f3219e39397de173518ced198d36',
753+
'module_url': 'https://cyberpanel.net/binaries/ubuntu/cyberpanel_ols_x86_64_ubuntu.so',
754+
'module_sha256': 'd070952fcfe27fac2f2c95db9ae31252071bade2cdcff19cf3b3f7812fa9413a'
755+
}
756+
}
757+
758+
config = BINARY_CONFIGS.get(platform)
759+
if not config:
760+
Upgrade.stdOut(f"ERROR: No binaries available for platform {platform}", 0)
761+
Upgrade.stdOut("Skipping custom binary installation", 0)
762+
return True # Not fatal
763+
764+
OLS_BINARY_URL = config['url']
765+
OLS_BINARY_SHA256 = config['sha256']
766+
MODULE_URL = config['module_url']
767+
MODULE_SHA256 = config['module_sha256']
768+
OLS_BINARY_PATH = "/usr/local/lsws/bin/openlitespeed"
769+
MODULE_PATH = "/usr/local/lsws/modules/cyberpanel_ols.so"
770+
684771
# Create backup
685772
from datetime import datetime
686773
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
@@ -700,15 +787,15 @@ def installCustomOLSBinaries():
700787

701788
Upgrade.stdOut("Downloading custom binaries...", 0)
702789

703-
# Download OpenLiteSpeed binary
704-
if not Upgrade.downloadCustomBinary(OLS_BINARY_URL, tmp_binary):
705-
Upgrade.stdOut("ERROR: Failed to download OLS binary", 0)
790+
# Download OpenLiteSpeed binary with checksum verification
791+
if not Upgrade.downloadCustomBinary(OLS_BINARY_URL, tmp_binary, OLS_BINARY_SHA256):
792+
Upgrade.stdOut("ERROR: Failed to download or verify OLS binary", 0)
706793
Upgrade.stdOut("Continuing with standard OLS", 0)
707794
return True # Not fatal, continue with standard OLS
708795

709-
# Download module
710-
if not Upgrade.downloadCustomBinary(MODULE_URL, tmp_module):
711-
Upgrade.stdOut("ERROR: Failed to download module", 0)
796+
# Download module with checksum verification
797+
if not Upgrade.downloadCustomBinary(MODULE_URL, tmp_module, MODULE_SHA256):
798+
Upgrade.stdOut("ERROR: Failed to download or verify module", 0)
712799
Upgrade.stdOut("Continuing with standard OLS", 0)
713800
return True # Not fatal, continue with standard OLS
714801

0 commit comments

Comments
 (0)