From 0d6f75704bc4ae3ed0c1b57bce4de577e8a56eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Thu, 13 Mar 2025 12:07:18 +0100 Subject: [PATCH] CMXX - Multisite setup --- .gitignore | 4 +- api.php | 2 +- assets/functions.php | 55 +- cronjob.php | 2 +- dashboard.php | 1 - equipments.php | 6 +- index.php | 34 +- login.php | 189 +- pricelists.php | 2 +- products_attributes.php | 6 +- products_attributes_manage.php | 6 +- register.php | 4 +- reset.php | 2 +- settings.php | 4 +- settings/config.php | 55 + settings/veliti/config.php | 55 + settings/veliti/settingsprofiles.php | 27 + style/.DS_Store | Bin 0 -> 6148 bytes style/admin_login.css | 172 ++ style/veliti/.DS_Store | Bin 0 -> 6148 bytes style/veliti/VeLiTi-Logo2.png | Bin 0 -> 2761 bytes style/veliti/VeLiTi.png | Bin 0 -> 5850 bytes style/veliti/veliti.css | 2877 ++++++++++++++++++++++++++ style/veliti/veliti_intro.png | Bin 0 -> 170794 bytes style/veliti/veliti_login.css | 172 ++ unscribe.php | 2 +- 26 files changed, 3471 insertions(+), 206 deletions(-) create mode 100644 settings/config.php create mode 100644 settings/veliti/config.php create mode 100644 settings/veliti/settingsprofiles.php create mode 100644 style/.DS_Store create mode 100644 style/admin_login.css create mode 100644 style/veliti/.DS_Store create mode 100755 style/veliti/VeLiTi-Logo2.png create mode 100644 style/veliti/VeLiTi.png create mode 100644 style/veliti/veliti.css create mode 100644 style/veliti/veliti_intro.png create mode 100644 style/veliti/veliti_login.css diff --git a/.gitignore b/.gitignore index 80e923d..683cde9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ marketing/ firmware/ log/ assets/images/products/ -settings/config.php +settings/config_redirector.php settings/settings.php variable_scan.php +settings/veliti/config_redirector.php +settings/veliti/settings.php diff --git a/api.php b/api.php index a1991f9..b2fc8fd 100644 --- a/api.php +++ b/api.php @@ -14,7 +14,7 @@ $input = stream_get_contents($post_data_curl); //------------------------------------------ require_once './assets/functions.php'; include './settings/settings.php'; -include './settings/config.php'; +include './settings/config_redirector.php'; //------------------------------------------ // Header security - enabled via config diff --git a/assets/functions.php b/assets/functions.php index 014e56b..1400e79 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -46,7 +46,7 @@ require dirname(__FILE__).'/mail/Exception.php'; // +++++++++++++++++++++++++++++++++++++++++++++++++++++++ function send_mail($to, $subject, $message, $attachment, $attachment_name){ - include_once dirname(__FILE__,2).'/settings/config.php'; + include_once dirname(__FILE__,2).'/settings/config_redirector.php'; $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; @@ -250,6 +250,9 @@ function template_header($title, $selected = 'assets', $selected_child = 'view') $icon_image = icon_image; $admin_links = menu($selected,$selected_child); + $domain = getDomainName($_SERVER['SERVER_NAME']); + $custom_css = (file_exists(dirname(__FILE__,2).'/style/'.$domain.'/'.$domain.'.css') ? './style/'.$domain.'/'.$domain.'.css' : './style/admin.css'); + $user = ucfirst($_SESSION['username']); if (filter_var($user, FILTER_VALIDATE_EMAIL)){ $user = substr($user, 0, strpos($user, "@")); @@ -286,7 +289,7 @@ echo << $title - + @@ -891,7 +894,7 @@ function getWhereclauselvl2($table_name,$permission,$partner,$method){ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ function getProfile($profile, $permission){ - include_once dirname(__FILE__,2).'/settings/config.php'; + include_once dirname(__FILE__,2).'/settings/config_redirector.php'; if ($profile != ''){ $profile = (defined($profile)) ? constant($profile) : standard_profile; @@ -2124,7 +2127,7 @@ function uploadrequest($key){ // debuglog //------------------------------------------ function debuglog($error){ - include_once dirname(__FILE__,2).'/settings/config.php'; + include_once dirname(__FILE__,2).'/settings/config_redirector.php'; $test = $error.PHP_EOL; $filelocation = dirname(__FILE__,2).'/log/log_'.date('d').'.txt'; error_log($test, 3, $filelocation); @@ -3871,7 +3874,6 @@ function createGiftCart($pdo, $orderID, $giftcard_categoryID,$accounthierarchy){ //======================================= // findGitCommitHash //======================================= - function findShortGitCommitHash($string) { // Step 1: Find all hexadecimal sequences preg_match_all('/[0-9a-f]+/i', $string, $matches); @@ -3909,4 +3911,47 @@ function compareCommitCodes($stringA, $stringB) { // Case 4: Neither has commit code return ""; +} +//======================================= +// Function to find the first existing view +//======================================= + +function findExistingView($viewsArray, $defaultView, $ignoreViews) { + foreach ($viewsArray as $view) { + + $file_to_check = $view.'.php'; + + if (in_array($view, $ignoreViews)) { + continue; + } + + if (file_exists($file_to_check)) { + return $view; + } + } + // If no view exists, return the default + return $defaultView; +} +//======================================= +// Function to find the domain +//======================================= +function getDomainName($hostname) { + // Extract the domain parts + $parts = explode('.', $hostname); + $count = count($parts); + + // For hostnames with enough parts to have a subdomain (at least 3 parts) + if ($count >= 3) { + // Return the second-to-last and third-to-last parts + return $parts[$count - 2]; + } + // For hostnames with just domain and TLD (2 parts) + else if ($count == 2) { + // Return just the domain part (without the TLD) + return $parts[0]; + } + // If it's a single part hostname + else { + return $hostname; + } } \ No newline at end of file diff --git a/cronjob.php b/cronjob.php index 1d7ddf7..c24bf19 100644 --- a/cronjob.php +++ b/cronjob.php @@ -3,7 +3,7 @@ define('secure_34563$52', true); include_once './assets/functions.php'; include_once './settings/settings.php'; -include_once './settings/config.php'; +include_once './settings/config_redirector.php'; if (debug && debug_id == $_SESSION['id']){ ini_set('display_errors', '1'); diff --git a/dashboard.php b/dashboard.php index 6379a65..c76ed46 100644 --- a/dashboard.php +++ b/dashboard.php @@ -15,7 +15,6 @@ if (isAllowed('dashboard',$_SESSION['profile'],$_SESSION['permission'],'R') === header('location: index.php'); exit; } - //Return QueryTotal from API $api_url = '/v1/equipments/totals='; $query_total_equipment = ioServer($api_url,''); diff --git a/equipments.php b/equipments.php index ec3335c..ef07fd8 100644 --- a/equipments.php +++ b/equipments.php @@ -53,13 +53,15 @@ $responses = ioServer($api_url,''); if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;} //Return QueryTotal from API -$api_url = '/v1/equipments/'.$GET_VALUES.'&totals='; +$total_url = ((!empty($GET_VALUES) && $GET_VALUES !='') ? '&totals=' : 'totals=' ); +$api_url = '/v1/equipments/'.$GET_VALUES.$total_url; $query_total = ioServer($api_url,''); //Decode Payload if (!empty($query_total)){$query_total = decode_payload($query_total);}else{$query_total = null;} //Get Products related to assets -$api_url = '/v1/equipments/'.$GET_VALUES.'&products='; +$product_url = ((!empty($GET_VALUES) && $GET_VALUES !='') ? '&products=' : 'products=' ); +$api_url = '/v1/equipments/'.$GET_VALUES.$product_url; $query_products = ioServer($api_url,''); //Decode Payload if (!empty($query_products)){$query_products = decode_payload($query_products);}else{$query_products = null;} diff --git a/index.php b/index.php index c327186..7d0d1c5 100644 --- a/index.php +++ b/index.php @@ -4,9 +4,11 @@ define('secure_admin_342642', true); if (session_status() == PHP_SESSION_NONE) { session_start(); } - +//===================================== //INCLUDE CONSTANTS -include dirname(__FILE__).'/settings/config.php'; +//===================================== + +include dirname(__FILE__).'/settings/config_redirector.php'; if (debug && debug_id == $_SESSION['id']){ ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); @@ -17,7 +19,10 @@ if (debug && debug_id == $_SESSION['id']){ include dirname(__FILE__).'/assets/functions.php'; include dirname(__FILE__).'/settings/settings.php'; +//===================================== //TRANSLATION FILE LOCATION +//===================================== + if (isset($_GET['language']) && $_GET['language'] !=''){ //INCLUDE LANGUAGE FILE $api_file_language = './settings/translations/translations_'.strtoupper($_GET['language']).'.php'; @@ -31,6 +36,9 @@ if (isset($_GET['language']) && $_GET['language'] !=''){ //DEFINE LANGUAGE $_SESSION['country_code'] = 'US'; } + + //REMOVE FROM GET TO AVOID THAT LANGUAGE IS USED IN GET_VALUES FUNCTION + unset($_GET['language']); } elseif(isset($_SESSION['country_code'])){ $api_file_language = './settings/translations/translations_'.strtoupper($_SESSION['country_code']).'.php'; @@ -45,8 +53,9 @@ elseif(isset($_SESSION['country_code'])){ //DEFINE LANGUAGE $_SESSION['country_code'] = 'US'; } - +//===================================== // Determine the base URL +//===================================== $base_url = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] === 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ? 'https' : 'http'; $base_url .= '://' . rtrim($_SERVER['HTTP_HOST'], '/'); $base_url .= $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 || strpos($_SERVER['HTTP_HOST'], ':') !== false ? '' : ':' . $_SERVER['SERVER_PORT']; @@ -54,6 +63,9 @@ $base_url .= '/' . ltrim(substr(str_replace('\\', '/', realpath(__DIR__)), strle define('base_url', rtrim($base_url, '/') . '/'); +//===================================== +//CHECK USER SESSION +//===================================== if (!isset($_SESSION['loggedin'])) { header('location: login.php'); die(); @@ -65,15 +77,27 @@ if (isset($_GET['page']) && $_GET['page'] == 'logout') { die(); } -// Page is set to home (home.php) by default, so when the visitor visits that will be the page they see. -$page = isset($_GET['page']) && file_exists($_GET['page'] . '.php') ? $_GET['page'] : 'dashboard'; +//===================================== +//DEFINE WHERE TO SEND THE USER TO. GET first assigned view in the profile if not available use dashboard +//===================================== +$allowed_views = explode(',',$_SESSION['profile']); +$ignoreViews = ['profile','assets','sales']; +$allowed_views = findExistingView($allowed_views, 'dashboard', $ignoreViews); + +//===================================== +//FORWARD THE USER TO THE CORRECT PAGE +//===================================== +$page = isset($_GET['page']) && file_exists($_GET['page'] . '.php') ? $_GET['page'] : $allowed_views; // Output error variable $error = ''; // Include the requested page include $page . '.php'; +//===================================== //debuglog +//===================================== + if (debug){ $message = $date.';'.json_encode($_GET).';'.$_SESSION['username']; debuglog($message); diff --git a/login.php b/login.php index 51fe1e2..22dc620 100644 --- a/login.php +++ b/login.php @@ -2,10 +2,14 @@ include './assets/functions.php'; include './settings/settings.php'; -include './settings/config.php'; +include './settings/config_redirector.php'; include_once './settings/translations/translations_US.php'; - +//========================================= +//GET DOMAIN FOR CORRECT STYLING AND SETTINGS +$domain = getDomainName($_SERVER['SERVER_NAME']); +$custom_css = (file_exists(dirname(__FILE__).'/style/'.$domain.'/'.$domain.'_login.css') ? './style/'.$domain.'/'.$domain.'_login.css' : './style/admin_login.css'); + // Check if the user is already logged in, if yes then redirect him to welcome page if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ header("location: index.php"); @@ -87,181 +91,12 @@ echo' - -'.site_title.' - - + + '.site_title.' + + - + '; //Maintenance mode notification message @@ -279,7 +114,7 @@ echo'
'.site_title.' -

Customer Portal

+

'.site_name.'

'; if (maintenance_mode) diff --git a/pricelists.php b/pricelists.php index 26d68ec..fb44949 100644 --- a/pricelists.php +++ b/pricelists.php @@ -75,7 +75,7 @@ $view .= '
} $view .= '
- '.($button_create_pricelist ?? '').' + '.($button_create_pricelist ?? 'Create pricelist').'