@@ -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
0 commit comments