diff --git a/UI/.htaccess b/UI/.htaccess
new file mode 100644
index 0000000..bb04789
--- /dev/null
+++ b/UI/.htaccess
@@ -0,0 +1,73 @@
+# ZitiNexus Router Enrollment UI - Apache Configuration
+# This file helps serve assets correctly when document root is not set to /public/
+
+# Redirect to public directory for main pages
+RewriteEngine On
+
+# Serve assets directly from assets directory
+RewriteRule ^assets/(.*)$ assets/$1 [L]
+
+# Redirect main pages to public directory
+RewriteRule ^$ public/index.php [L]
+RewriteRule ^index\.php$ public/index.php [L]
+RewriteRule ^dashboard\.php$ public/dashboard.php [L]
+
+# Handle other requests
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule ^(.*)$ public/$1 [L]
+
+# Security: Deny access to sensitive directories
+
+
+ Require all granted
+
+
+
+
+ Require all denied
+
+
+
+ Require all denied
+
+
+
+ Require all denied
+
+
+# Set proper MIME types for assets
+
+ AddType text/css .css
+ AddType application/javascript .js
+ AddType image/png .png
+ AddType image/jpeg .jpg .jpeg
+ AddType image/gif .gif
+ AddType image/svg+xml .svg
+ AddType image/x-icon .ico
+
+
+# Enable compression for text files
+
+ AddOutputFilterByType DEFLATE text/plain
+ AddOutputFilterByType DEFLATE text/html
+ AddOutputFilterByType DEFLATE text/xml
+ AddOutputFilterByType DEFLATE text/css
+ AddOutputFilterByType DEFLATE application/xml
+ AddOutputFilterByType DEFLATE application/xhtml+xml
+ AddOutputFilterByType DEFLATE application/rss+xml
+ AddOutputFilterByType DEFLATE application/javascript
+ AddOutputFilterByType DEFLATE application/x-javascript
+
+
+# Set cache headers for static assets
+
+ ExpiresActive On
+ ExpiresByType text/css "access plus 1 month"
+ ExpiresByType application/javascript "access plus 1 month"
+ ExpiresByType image/png "access plus 1 month"
+ ExpiresByType image/jpeg "access plus 1 month"
+ ExpiresByType image/gif "access plus 1 month"
+ ExpiresByType image/svg+xml "access plus 1 month"
+ ExpiresByType image/x-icon "access plus 1 year"
+
diff --git a/UI/includes/config.php b/UI/includes/config.php
index ce4dbb4..b7533b1 100644
--- a/UI/includes/config.php
+++ b/UI/includes/config.php
@@ -144,4 +144,38 @@ function executeCommand($command, &$output = null, &$returnCode = null) {
return false;
}
+
+/**
+ * Get the correct asset path based on current directory structure
+ */
+function getAssetPath($asset) {
+ // Determine if we're in the public directory or main directory
+ $currentDir = dirname($_SERVER['SCRIPT_FILENAME']);
+ $publicDir = realpath(__DIR__ . '/../public');
+
+ if ($currentDir === $publicDir) {
+ // We're in the public directory, use relative paths
+ return '../assets/' . ltrim($asset, '/');
+ } else {
+ // We're in the main directory, use direct paths
+ return 'assets/' . ltrim($asset, '/');
+ }
+}
+
+/**
+ * Get base URL for the application
+ */
+function getBaseUrl() {
+ $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
+ $host = $_SERVER['HTTP_HOST'];
+ $scriptName = $_SERVER['SCRIPT_NAME'];
+
+ // Remove the script filename to get the base path
+ $basePath = dirname($scriptName);
+ if ($basePath === '/') {
+ $basePath = '';
+ }
+
+ return $protocol . '://' . $host . $basePath;
+}
?>
diff --git a/UI/install.sh b/UI/install.sh
index 293fd00..f2024b4 100644
--- a/UI/install.sh
+++ b/UI/install.sh
@@ -16,6 +16,7 @@ NC='\033[0m' # No Color
WEB_DIR="/var/www/ziti-enrollment"
DOMAIN="ziti-enrollment.local"
WEB_USER="www-data"
+PHP_VERSION=""
# Logging function
log() {
@@ -56,6 +57,59 @@ check_root() {
fi
}
+# Detect available PHP version
+detect_php_version() {
+ log "INFO" "Detecting available PHP version..."
+
+ # Update package cache first
+ apt update >/dev/null 2>&1
+
+ # Check for available PHP versions in order of preference
+ for version in "8.3" "8.2" "8.1" "8.0"; do
+ log "INFO" "Checking for PHP $version..."
+
+ # Check multiple ways to ensure package availability
+ if apt-cache show "php${version}" >/dev/null 2>&1 || \
+ apt-cache show "php${version}-cli" >/dev/null 2>&1 || \
+ apt list "php${version}" 2>/dev/null | grep -q "php${version}"; then
+
+ # Double-check that the FPM package exists for Nginx
+ if apt-cache show "php${version}-fpm" >/dev/null 2>&1 || \
+ apt list "php${version}-fpm" 2>/dev/null | grep -q "php${version}-fpm"; then
+ PHP_VERSION="$version"
+ log "SUCCESS" "Found PHP $PHP_VERSION with FPM support"
+ break
+ else
+ log "WARNING" "PHP $version found but FPM package not available"
+ fi
+ else
+ log "INFO" "PHP $version not available"
+ fi
+ done
+
+ if [[ -z "$PHP_VERSION" ]]; then
+ log "ERROR" "No compatible PHP version found. Available packages:"
+ apt list --installed | grep php 2>/dev/null || echo "No PHP packages found"
+ log "INFO" "Trying to install default PHP..."
+
+ # Fallback: try to install default php package
+ if apt-cache show "php" >/dev/null 2>&1; then
+ log "INFO" "Found default PHP package, will use system default"
+ # Get the default PHP version
+ PHP_VERSION=$(apt-cache show php | grep "^Depends:" | grep -o "php[0-9]\+\.[0-9]\+" | head -1 | sed 's/php//')
+ if [[ -n "$PHP_VERSION" ]]; then
+ log "SUCCESS" "Will use system default PHP $PHP_VERSION"
+ else
+ error_exit "Could not determine PHP version from default package"
+ fi
+ else
+ error_exit "No PHP packages available. Please install PHP manually first."
+ fi
+ fi
+
+ log "SUCCESS" "Selected PHP version: $PHP_VERSION"
+}
+
# Detect web server preference
detect_web_server() {
echo
@@ -82,30 +136,30 @@ detect_web_server() {
# Install web server and PHP
install_web_server() {
- log "INFO" "Installing web server and PHP..."
+ log "INFO" "Installing web server and PHP $PHP_VERSION..."
# Update package list
apt update || error_exit "Failed to update package list"
if [[ "$WEB_SERVER" == "apache" ]]; then
# Install Apache and PHP
- apt install -y apache2 php8.1 php8.1-curl php8.1-json libapache2-mod-php8.1 || error_exit "Failed to install Apache and PHP"
+ apt install -y apache2 php${PHP_VERSION} php${PHP_VERSION}-curl php${PHP_VERSION}-json libapache2-mod-php${PHP_VERSION} || error_exit "Failed to install Apache and PHP"
# Enable and start Apache
systemctl enable apache2 || error_exit "Failed to enable Apache"
systemctl start apache2 || error_exit "Failed to start Apache"
- log "SUCCESS" "Apache and PHP installed successfully"
+ log "SUCCESS" "Apache and PHP $PHP_VERSION installed successfully"
elif [[ "$WEB_SERVER" == "nginx" ]]; then
# Install Nginx and PHP-FPM
- apt install -y nginx php8.1-fpm php8.1-curl php8.1-json || error_exit "Failed to install Nginx and PHP"
+ apt install -y nginx php${PHP_VERSION}-fpm php${PHP_VERSION}-curl php${PHP_VERSION}-json || error_exit "Failed to install Nginx and PHP"
# Enable and start services
- systemctl enable nginx php8.1-fpm || error_exit "Failed to enable Nginx and PHP-FPM"
- systemctl start nginx php8.1-fpm || error_exit "Failed to start Nginx and PHP-FPM"
+ systemctl enable nginx php${PHP_VERSION}-fpm || error_exit "Failed to enable Nginx and PHP-FPM"
+ systemctl start nginx php${PHP_VERSION}-fpm || error_exit "Failed to start Nginx and PHP-FPM"
- log "SUCCESS" "Nginx and PHP-FPM installed successfully"
+ log "SUCCESS" "Nginx and PHP $PHP_VERSION installed successfully"
fi
}
@@ -182,7 +236,7 @@ server {
}
location ~ \.php$ {
- fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
+ fastcgi_pass unix:/var/run/php/php${PHP_VERSION}-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name;
include fastcgi_params;
@@ -213,9 +267,9 @@ configure_php() {
# Find PHP configuration file
if [[ "$WEB_SERVER" == "apache" ]]; then
- PHP_INI="/etc/php/8.1/apache2/php.ini"
+ PHP_INI="/etc/php/${PHP_VERSION}/apache2/php.ini"
else
- PHP_INI="/etc/php/8.1/fpm/php.ini"
+ PHP_INI="/etc/php/${PHP_VERSION}/fpm/php.ini"
fi
# Check if exec functions are disabled
@@ -228,7 +282,7 @@ configure_php() {
if [[ "$WEB_SERVER" == "apache" ]]; then
systemctl restart apache2 || error_exit "Failed to restart Apache"
else
- systemctl restart php8.1-fpm || error_exit "Failed to restart PHP-FPM"
+ systemctl restart php${PHP_VERSION}-fpm || error_exit "Failed to restart PHP-FPM"
fi
log "SUCCESS" "PHP configured successfully"
@@ -288,7 +342,7 @@ test_installation() {
log "ERROR" "Apache is not running"
fi
else
- if systemctl is-active --quiet nginx && systemctl is-active --quiet php8.1-fpm; then
+ if systemctl is-active --quiet nginx && systemctl is-active --quiet php${PHP_VERSION}-fpm; then
log "SUCCESS" "Nginx and PHP-FPM are running"
else
log "ERROR" "Nginx or PHP-FPM is not running"
@@ -346,7 +400,7 @@ show_final_info() {
echo " Check status: systemctl status apache2"
echo " View logs: tail -f /var/log/apache2/ziti-enrollment_error.log"
else
- echo " Check status: systemctl status nginx php8.1-fpm"
+ echo " Check status: systemctl status nginx php${PHP_VERSION}-fpm"
echo " View logs: tail -f /var/log/nginx/error.log"
fi
echo " Test sudo: sudo -u www-data sudo -l"
@@ -363,6 +417,9 @@ main() {
# Check if running as root
check_root
+ # Detect available PHP version
+ detect_php_version
+
# Detect web server preference
detect_web_server
diff --git a/UI/public/dashboard.php b/UI/public/dashboard.php
index 60bf09c..1c11c35 100644
--- a/UI/public/dashboard.php
+++ b/UI/public/dashboard.php
@@ -60,8 +60,8 @@ $systemStatus = $enrollmentManager->getSystemStatus();
- Dashboard
-
-
+
+
@@ -305,6 +305,6 @@ $systemStatus = $enrollmentManager->getSystemStatus();
-
+