Browse Source

Initial commit: Per user theme selection

Add v-change-user-theme
Add THEME key to user.conf and v-list-user
Kristan Kenney 5 years ago
parent
commit
18da40d8ad

+ 1 - 0
bin/v-add-user

@@ -235,6 +235,7 @@ U_DATABASES='0'
 U_CRON_JOBS='0'
 U_BACKUPS='0'
 LANGUAGE=''
+THEME=''
 NOTIFICATIONS='no'
 TIME='$time'
 DATE='$date'" > $USER_DATA/user.conf

+ 53 - 0
bin/v-change-user-theme

@@ -0,0 +1,53 @@
+#!/bin/bash
+# info: updates user role
+# options: USER ROLE
+# labels: hestia
+#
+# example: v-change-user-theme user theme
+#
+# Changes web UI display theme for specified user.
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+user=$1
+theme=$2
+
+
+# Includes
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# shellcheck source=/usr/local/hestia/conf/hestia.conf
+source $HESTIA/conf/hestia.conf
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Reading user values
+source $USER_DATA/user.conf
+
+is_format_valid 'user' 'theme'
+is_object_valid 'user' 'USER' "$user"
+
+is_object_unsuspended 'user' 'USER' "$user"
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+update_user_value "$user" '$THEME' "$theme"
+
+$BIN/v-log-action "$user" "Info" "System" "User theme changed (User: $user, Theme: $theme)."
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+exit

+ 1 - 0
bin/v-list-user

@@ -78,6 +78,7 @@ json_list() {
         "U_CRON_JOBS": "'$U_CRON_JOBS'",
         "U_BACKUPS": "'$U_BACKUPS'",
         "LANGUAGE": "'$LANGUAGE'",
+        "THEME": "'$THEME'",
         "NOTIFICATIONS": "'$NOTIFICATIONS'",
         "PHPCLI": "'$PHPCLI'",
         "TIME": "'$TIME'",

+ 1 - 1
func/syshealth.sh

@@ -95,7 +95,7 @@ function syshealth_update_user_config_format() {
     # USER CONFIGURATION
     # Create array of known keys in configuration file
     system="user"
-    known_keys=(NAME PACKAGE CONTACT CRON_REPORTS MD5 RKEY TWOFA QRCODE PHPCLI ROLE SUSPENDED SUSPENDED_USERS SUSPENDED_WEB SUSPENDED_DNS SUSPENDED_MAIL SUSPENDED_DB SUSPENDED_CRON IP_AVAIL IP_OWNED U_USERS U_DISK U_DISK_DIRS U_DISK_WEB U_DISK_MAIL U_DISK_DB U_BANDWIDTH U_WEB_DOMAINS U_WEB_SSL U_WEB_ALIASES U_DNS_DOMAINS U_DNS_RECORDS U_MAIL_DKIM U_MAIL_DKIM U_MAIL_ACCOUNTS U_MAIL_DOMAINS U_MAIL_SSL U_DATABASES U_CRON_JOBS U_BACKUPS LANGUAGE NOTIFICATIONS TIME DATE)
+    known_keys=(NAME PACKAGE CONTACT CRON_REPORTS MD5 RKEY TWOFA QRCODE PHPCLI ROLE SUSPENDED SUSPENDED_USERS SUSPENDED_WEB SUSPENDED_DNS SUSPENDED_MAIL SUSPENDED_DB SUSPENDED_CRON IP_AVAIL IP_OWNED U_USERS U_DISK U_DISK_DIRS U_DISK_WEB U_DISK_MAIL U_DISK_DB U_BANDWIDTH U_WEB_DOMAINS U_WEB_SSL U_WEB_ALIASES U_DNS_DOMAINS U_DNS_RECORDS U_MAIL_DKIM U_MAIL_DKIM U_MAIL_ACCOUNTS U_MAIL_DOMAINS U_MAIL_SSL U_DATABASES U_CRON_JOBS U_BACKUPS LANGUAGE THEME NOTIFICATIONS TIME DATE)
     write_kv_config_file
     unset system
     unset known_keys

+ 18 - 0
web/edit/user/index.php

@@ -45,6 +45,7 @@ $v_password = "";
 $v_email = $data[$v_username]['CONTACT'];
 $v_package = $data[$v_username]['PACKAGE'];
 $v_language = $data[$v_username]['LANGUAGE'];
+$v_user_theme = $data[$v_username]['THEME'];
 $v_name = $data[$v_username]['NAME'];
 $v_shell = $data[$v_username]['SHELL'];
 $v_twofa = $data[$v_username]['TWOFA'];
@@ -89,6 +90,11 @@ foreach($language as $lang){
 asort($languages);
 unset($output);
 
+// List themes
+exec (HESTIA_CMD."v-list-sys-themes json", $output, $return_var);
+$themes = json_decode(implode('', $output), true);
+unset($output);
+
 // List shells
 exec (HESTIA_CMD."v-list-sys-shells json", $output, $return_var);
 $shells = json_decode(implode('', $output), true);
@@ -226,6 +232,18 @@ if (!empty($_POST['save'])) {
             }
     }
 
+    // Update theme
+    if (empty($_SESSION['error_msg'])) {
+        if ($_POST['v_user_theme'] != $_SESSION['userTheme']) {
+            exec (HESTIA_CMD."v-change-user-theme ".escapeshellarg($v_username)." ".escapeshellarg($_POST['v_user_theme']), $output, $return_var);
+            check_return_code($return_var,$output);
+            unset($_SESSION['userTheme']);
+            unset($output);
+            $v_user_theme = $_POST['v_user_theme'];
+            $_SESSION['userTheme'] = $v_user_theme;
+        }
+    }
+
     // Change NameServers
     if (($v_ns1 != $_POST['v_ns1']) || ($v_ns2 != $_POST['v_ns2']) || ($v_ns3 != $_POST['v_ns3']) || ($v_ns4 != $_POST['v_ns4']) || ($v_ns5 != $_POST['v_ns5'])
  || ($v_ns6 != $_POST['v_ns6']) || ($v_ns7 != $_POST['v_ns7']) || ($v_ns8 != $_POST['v_ns8']) && (empty($_SESSION['error_msg']))) {

+ 1 - 0
web/login/index.php

@@ -173,6 +173,7 @@ function authenticate_user($user, $password, $twofa = ''){
                 }
                 
                 $_SESSION['userContext'] = $data[$user]['ROLE'];
+                $_SESSION['userTheme'] = $data[$user]['THEME'];
 
                 // Define session user
                 $_SESSION['user'] = key($data);

+ 23 - 1
web/templates/admin/edit_user.html

@@ -135,7 +135,6 @@
                                     <?php } ?>
                                 </td>
                             </tr>
-
                             <tr>
                                 <td class="vst-text input-label">
                                     <?php print _('Language');?>
@@ -179,6 +178,29 @@
                                 </tr>
                                 <? } ?>
                             <? } ?>
+                            <tr>
+                                <td class="vst-text input-label">
+                                    <?php print _('Theme') ?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>
+                                    <select class="vst-list" name="v_user_theme">
+                                        <?php
+                                            foreach ($themes as $key => $value) {
+                                                echo "\t\t\t\t<option value=\"".$value."\"";
+                                                if ((!empty($_SESSION['userTheme'])) && ( $value == $v_user_theme )) {
+                                                    echo ' selected' ;
+                                                }
+                                                if ((!empty($_SESSION['userTheme'])) && ( $value == $_POST['v_user_theme'])){
+                                                    echo ' selected' ;
+                                                }
+                                                echo ">".$value."</option>\n";
+                                            }
+                                        ?>
+                                    </select>
+                                </td>
+                            </tr>
                             <tr>
                                 <td class="vst-text input-label">
                                     <?php print _('Package');?>

+ 16 - 8
web/templates/header.html

@@ -4,13 +4,20 @@
   <meta charset="utf-8">
   <link rel="icon" href="/images/favicon.ico" type="image/x-icon">
   <title><?php echo $_SERVER['HTTP_HOST']; ?> - <?=_($TAB)?> - <?=_('Hestia Control Panel');?></title>
-  <!-- Load base theme-->
+  <!-- Load base system theme-->
   <link type="text/css" rel="stylesheet" href="/css/themes/default.min.css?<?=JS_LATEST_UPDATE?>" rel="preload" />
-  <? if ($_SESSION['THEME'] !== 'default') {?>
-    <!-- Load provided theme -->
-    <link type="text/css" rel="stylesheet" href="/css/themes/<?php echo $_SESSION['THEME']; ?>.min.css?<?php echo rand(); ?>" rel="preload" />
-    <!-- Load custom theme -->
-    <link type="text/css" rel="stylesheet" href="/css/themes/custom/<?php echo $_SESSION['THEME']; ?>.css?<?php echo rand(); ?>" rel="preload" />
+  <? if ($_SESSION['userTheme']) {
+        $selected_theme = $_SESSION['userTheme']; 
+     } else {
+        $seleced_theme = $_SESSION['THEME'];
+     } 
+  ?>
+  <!-- Load custom theme -->
+  <? if (($_SESSION['THEME'] !== 'default') || ($_SESSION['userTheme'] !== 'default')) {?>
+    <!-- Load HestiaCP-shipped themes (minified, updated/overwritten with updates) - ($HESTIA/web/css/themes/*.min.css) -->
+    <link type="text/css" rel="stylesheet" href="/css/themes/<?php echo $selected_theme; ?>.min.css?<?php echo rand(); ?>" rel="preload" />
+    <!-- Load custom theme files ($HESTIA/web/css/themes/custom/*.css) -->
+    <link type="text/css" rel="stylesheet" href="/css/themes/custom/<?php echo $selected_theme; ?>.css?<?php echo rand(); ?>" rel="preload" />
   <? } ?>
   <link type="text/css" href="/css/dependencies/animate.min.css?<?=JS_LATEST_UPDATE?>" rel="stylesheet" rel="preload" />
   <link type="text/css" href="/css/dependencies/jquery-custom-dialogs.css?<?=JS_LATEST_UPDATE?>" rel="stylesheet" rel="preload" />
@@ -30,7 +37,7 @@
 </head>
 <body class="body-<?=strtolower($TAB)?> lang-<?=$_SESSION['language']?>">
     <?php if (($_SESSION['DEBUG_MODE']) == "true" ) {?>
-    <div style="font-size:12px !important; padding:8px;">
+    <div style="font-size:12px !important; padding:12px;position:sticky;top:0;z-index:3000;background-color:">
         <?php
             echo "<h3>Server Variables</h3>";
             foreach ($_SERVER as $key=>$val)
@@ -42,4 +49,5 @@
             echo "<b>".$key."= </b> ".$val."  ";
         ?>
     </div>
-<?php } ?>
+<?php } ?>
+

+ 23 - 0
web/templates/user/edit_user.html

@@ -143,6 +143,29 @@
                                     </select>
                                 </td>
                             </tr>
+                            <tr>
+                                <td class="vst-text input-label">
+                                    <?php print _('Theme') ?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>
+                                    <select class="vst-list" name="v_user_theme">
+                                        <?php
+                                            foreach ($themes as $key => $value) {
+                                                echo "\t\t\t\t<option value=\"".$value."\"";
+                                                if ((!empty($_SESSION['userTheme'])) && ( $value == $v_user_theme )) {
+                                                    echo ' selected' ;
+                                                }
+                                                if ((!empty($_SESSION['userTheme'])) && ( $value == $_POST['v_user_theme'])){
+                                                    echo ' selected' ;
+                                                }
+                                                echo ">".$value."</option>\n";
+                                            }
+                                        ?>
+                                    </select>
+                                </td>
+                            </tr>
                             <tr>
                                 <td class="vst-text input-label">
                                     <?php print _('Default Name Servers');?>