diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index e8798ff3f..e62ba6d4f 100644 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -33,14 +33,14 @@ - + - + diff --git a/install/install.py b/install/install.py index 2abd86778..1402a8bb9 100644 --- a/install/install.py +++ b/install/install.py @@ -1070,6 +1070,64 @@ class preFlightsChecks: self.stdOut(f"ERROR: {msg} [downloadCustomBinary]", 0) return False + def downloadCDNLibraries(self): + """ + Download CDN libraries (qrious, chart.js) locally to eliminate tracking prevention warnings. + These files are downloaded before collectstatic runs so they're included in the static files. + Tries latest version of qrious first, falls back to hardcoded version if latest fails. + """ + try: + custom_js_dir = '/usr/local/CyberCP/baseTemplate/static/baseTemplate/custom-js' + + # Ensure directory exists + if not os.path.exists(custom_js_dir): + os.makedirs(custom_js_dir, mode=0o755) + + # Download qrious.min.js - try latest first, fallback to known working version + qrious_path = os.path.join(custom_js_dir, 'qrious.min.js') + qrious_urls = [ + 'https://cdn.jsdelivr.net/npm/qrious@latest/dist/qrious.min.js', # Try latest first + 'https://cdn.jsdelivr.net/npm/qrious@4.0.2/dist/qrious.min.js' # Fallback to known working version + ] + qrious_downloaded = False + for qrious_url in qrious_urls: + command = f'wget -q --timeout=30 {qrious_url} -O {qrious_path}' + result = self.call(command, self.distro, command, command, 0, 0, os.EX_OSERR) + if result == 0 and os.path.exists(qrious_path) and os.path.getsize(qrious_path) > 1000: # At least 1KB + os.chmod(qrious_path, 0o644) + version_info = "latest" if "latest" in qrious_url else "4.0.2" + logging.InstallLog.writeToFile(f"Downloaded qrious.min.js ({version_info})", 0) + qrious_downloaded = True + break + if not qrious_downloaded: + logging.InstallLog.writeToFile("Warning: Failed to download qrious.min.js, continuing anyway", 0) + + # Download chart.js - try latest first, fallback to known working version + chartjs_path = os.path.join(custom_js_dir, 'chart.umd.min.js') + chartjs_urls = [ + 'https://cdn.jsdelivr.net/npm/chart.js@latest/dist/chart.umd.min.js', # Try latest first + 'https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js' # Fallback to known working version + ] + chartjs_downloaded = False + for chartjs_url in chartjs_urls: + command = f'wget -q --timeout=30 {chartjs_url} -O {chartjs_path}' + result = self.call(command, self.distro, command, command, 0, 0, os.EX_OSERR) + if result == 0 and os.path.exists(chartjs_path) and os.path.getsize(chartjs_path) > 100000: # At least 100KB + os.chmod(chartjs_path, 0o644) + version_info = "latest" if "latest" in chartjs_url else "4.4.1" + logging.InstallLog.writeToFile(f"Downloaded chart.umd.min.js ({version_info})", 0) + chartjs_downloaded = True + # Create copy for chart.js compatibility (some code may expect chart.js name) + chartjs_compat_path = os.path.join(custom_js_dir, 'chart.js') + if not os.path.exists(chartjs_compat_path): + shutil.copy2(chartjs_path, chartjs_compat_path) + break + if not chartjs_downloaded: + logging.InstallLog.writeToFile("Warning: Failed to download chart.umd.min.js, continuing anyway", 0) + + except Exception as msg: + logging.InstallLog.writeToFile(f"Warning: Error downloading CDN libraries: {str(msg)}, continuing anyway", 0) + def installCustomOLSBinaries(self): """Install custom OpenLiteSpeed binaries with PHP config support""" try: @@ -2826,6 +2884,9 @@ password="%s" if not os.path.exists("/usr/local/CyberCP/public"): os.mkdir("/usr/local/CyberCP/public") + # Download CDN libraries before collectstatic runs + self.downloadCDNLibraries() + command = f"{python_path} manage.py collectstatic --noinput --clear" preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR) diff --git a/plogical/upgrade.py b/plogical/upgrade.py index cacfeacf5..7523bf319 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -1607,6 +1607,66 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout'; Upgrade.stdOut("Failed to setup CLI [setupCLI]") return 0 + @staticmethod + def downloadCDNLibraries(): + """ + Download CDN libraries (qrious, chart.js) locally to eliminate tracking prevention warnings. + These files are downloaded before collectstatic runs so they're included in the static files. + Tries latest version first, falls back to hardcoded version if latest fails. + """ + try: + custom_js_dir = '/usr/local/CyberCP/baseTemplate/static/baseTemplate/custom-js' + + # Ensure directory exists + if not os.path.exists(custom_js_dir): + os.makedirs(custom_js_dir, mode=0o755) + + # Download qrious.min.js - try latest first, fallback to known working version + qrious_path = os.path.join(custom_js_dir, 'qrious.min.js') + qrious_urls = [ + 'https://cdn.jsdelivr.net/npm/qrious@latest/dist/qrious.min.js', # Try latest first + 'https://cdn.jsdelivr.net/npm/qrious@4.0.2/dist/qrious.min.js' # Fallback to known working version + ] + qrious_downloaded = False + for qrious_url in qrious_urls: + command = f'wget -q --timeout=30 {qrious_url} -O {qrious_path}' + result = subprocess.call(shlex.split(command)) + if result == 0 and os.path.exists(qrious_path) and os.path.getsize(qrious_path) > 1000: # At least 1KB + os.chmod(qrious_path, 0o644) + version_info = "latest" if "latest" in qrious_url else "4.0.2" + Upgrade.stdOut(f"Downloaded qrious.min.js ({version_info})", 0) + qrious_downloaded = True + break + if not qrious_downloaded: + Upgrade.stdOut("Warning: Failed to download qrious.min.js, continuing anyway", 0) + + # Download chart.js - try latest first, fallback to known working version + chartjs_path = os.path.join(custom_js_dir, 'chart.umd.min.js') + chartjs_urls = [ + 'https://cdn.jsdelivr.net/npm/chart.js@latest/dist/chart.umd.min.js', # Try latest first + 'https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js' # Fallback to known working version + ] + chartjs_downloaded = False + for chartjs_url in chartjs_urls: + command = f'wget -q --timeout=30 {chartjs_url} -O {chartjs_path}' + result = subprocess.call(shlex.split(command)) + if result == 0 and os.path.exists(chartjs_path) and os.path.getsize(chartjs_path) > 100000: # At least 100KB + os.chmod(chartjs_path, 0o644) + version_info = "latest" if "latest" in chartjs_url else "4.4.1" + Upgrade.stdOut(f"Downloaded chart.umd.min.js ({version_info})", 0) + chartjs_downloaded = True + # Create copy for chart.js compatibility (some code may expect chart.js name) + chartjs_compat_path = os.path.join(custom_js_dir, 'chart.js') + if not os.path.exists(chartjs_compat_path): + shutil.copy2(chartjs_path, chartjs_compat_path) + break + if not chartjs_downloaded: + Upgrade.stdOut("Warning: Failed to download chart.umd.min.js, continuing anyway", 0) + + except BaseException as msg: + ErrorSanitizer.log_error_securely(msg, 'downloadCDNLibraries') + Upgrade.stdOut(f"Warning: Error downloading CDN libraries: {str(msg)}, continuing anyway", 0) + @staticmethod def staticContent(): @@ -1618,6 +1678,9 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout'; if not os.path.exists("/usr/local/CyberCP/public"): os.mkdir("/usr/local/CyberCP/public") + # Download CDN libraries before collectstatic runs + Upgrade.downloadCDNLibraries() + cwd = os.getcwd() os.chdir('/usr/local/CyberCP') diff --git a/websiteFunctions/templates/websiteFunctions/website.html b/websiteFunctions/templates/websiteFunctions/website.html index 97a271777..252926266 100644 --- a/websiteFunctions/templates/websiteFunctions/website.html +++ b/websiteFunctions/templates/websiteFunctions/website.html @@ -2535,7 +2535,8 @@ {% block footer_scripts %} {{ block.super }} - + +