Skip to content

Commit 18da40d

Browse files
author
Kristan Kenney
committed
Initial commit: Per user theme selection
Add v-change-user-theme Add THEME key to user.conf and v-list-user
1 parent 3ded651 commit 18da40d

File tree

9 files changed

+137
-10
lines changed

9 files changed

+137
-10
lines changed

bin/v-add-user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ U_DATABASES='0'
235235
U_CRON_JOBS='0'
236236
U_BACKUPS='0'
237237
LANGUAGE=''
238+
THEME=''
238239
NOTIFICATIONS='no'
239240
TIME='$time'
240241
DATE='$date'" > $USER_DATA/user.conf

bin/v-change-user-theme

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# info: updates user role
3+
# options: USER ROLE
4+
# labels: hestia
5+
#
6+
# example: v-change-user-theme user theme
7+
#
8+
# Changes web UI display theme for specified user.
9+
10+
#----------------------------------------------------------#
11+
# Variable&Function #
12+
#----------------------------------------------------------#
13+
14+
# Argument definition
15+
user=$1
16+
theme=$2
17+
18+
19+
# Includes
20+
# shellcheck source=/usr/local/hestia/func/main.sh
21+
source $HESTIA/func/main.sh
22+
# shellcheck source=/usr/local/hestia/conf/hestia.conf
23+
source $HESTIA/conf/hestia.conf
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
# Reading user values
31+
source $USER_DATA/user.conf
32+
33+
is_format_valid 'user' 'theme'
34+
is_object_valid 'user' 'USER' "$user"
35+
36+
is_object_unsuspended 'user' 'USER' "$user"
37+
38+
# Perform verification if read-only mode is enabled
39+
check_hestia_demo_mode
40+
41+
#----------------------------------------------------------#
42+
# Action #
43+
#----------------------------------------------------------#
44+
45+
update_user_value "$user" '$THEME' "$theme"
46+
47+
$BIN/v-log-action "$user" "Info" "System" "User theme changed (User: $user, Theme: $theme)."
48+
49+
#----------------------------------------------------------#
50+
# Hestia #
51+
#----------------------------------------------------------#
52+
53+
exit

bin/v-list-user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ json_list() {
7878
"U_CRON_JOBS": "'$U_CRON_JOBS'",
7979
"U_BACKUPS": "'$U_BACKUPS'",
8080
"LANGUAGE": "'$LANGUAGE'",
81+
"THEME": "'$THEME'",
8182
"NOTIFICATIONS": "'$NOTIFICATIONS'",
8283
"PHPCLI": "'$PHPCLI'",
8384
"TIME": "'$TIME'",

func/syshealth.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function syshealth_update_user_config_format() {
9595
# USER CONFIGURATION
9696
# Create array of known keys in configuration file
9797
system="user"
98-
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)
98+
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)
9999
write_kv_config_file
100100
unset system
101101
unset known_keys

web/edit/user/index.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
$v_email = $data[$v_username]['CONTACT'];
4646
$v_package = $data[$v_username]['PACKAGE'];
4747
$v_language = $data[$v_username]['LANGUAGE'];
48+
$v_user_theme = $data[$v_username]['THEME'];
4849
$v_name = $data[$v_username]['NAME'];
4950
$v_shell = $data[$v_username]['SHELL'];
5051
$v_twofa = $data[$v_username]['TWOFA'];
@@ -89,6 +90,11 @@
8990
asort($languages);
9091
unset($output);
9192

93+
// List themes
94+
exec (HESTIA_CMD."v-list-sys-themes json", $output, $return_var);
95+
$themes = json_decode(implode('', $output), true);
96+
unset($output);
97+
9298
// List shells
9399
exec (HESTIA_CMD."v-list-sys-shells json", $output, $return_var);
94100
$shells = json_decode(implode('', $output), true);
@@ -226,6 +232,18 @@
226232
}
227233
}
228234

235+
// Update theme
236+
if (empty($_SESSION['error_msg'])) {
237+
if ($_POST['v_user_theme'] != $_SESSION['userTheme']) {
238+
exec (HESTIA_CMD."v-change-user-theme ".escapeshellarg($v_username)." ".escapeshellarg($_POST['v_user_theme']), $output, $return_var);
239+
check_return_code($return_var,$output);
240+
unset($_SESSION['userTheme']);
241+
unset($output);
242+
$v_user_theme = $_POST['v_user_theme'];
243+
$_SESSION['userTheme'] = $v_user_theme;
244+
}
245+
}
246+
229247
// Change NameServers
230248
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'])
231249
|| ($v_ns6 != $_POST['v_ns6']) || ($v_ns7 != $_POST['v_ns7']) || ($v_ns8 != $_POST['v_ns8']) && (empty($_SESSION['error_msg']))) {

web/login/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ function authenticate_user($user, $password, $twofa = ''){
173173
}
174174

175175
$_SESSION['userContext'] = $data[$user]['ROLE'];
176+
$_SESSION['userTheme'] = $data[$user]['THEME'];
176177

177178
// Define session user
178179
$_SESSION['user'] = key($data);

web/templates/admin/edit_user.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@
135135
<?php } ?>
136136
</td>
137137
</tr>
138-
139138
<tr>
140139
<td class="vst-text input-label">
141140
<?php print _('Language');?>
@@ -179,6 +178,29 @@
179178
</tr>
180179
<? } ?>
181180
<? } ?>
181+
<tr>
182+
<td class="vst-text input-label">
183+
<?php print _('Theme') ?>
184+
</td>
185+
</tr>
186+
<tr>
187+
<td>
188+
<select class="vst-list" name="v_user_theme">
189+
<?php
190+
foreach ($themes as $key => $value) {
191+
echo "\t\t\t\t<option value=\"".$value."\"";
192+
if ((!empty($_SESSION['userTheme'])) && ( $value == $v_user_theme )) {
193+
echo ' selected' ;
194+
}
195+
if ((!empty($_SESSION['userTheme'])) && ( $value == $_POST['v_user_theme'])){
196+
echo ' selected' ;
197+
}
198+
echo ">".$value."</option>\n";
199+
}
200+
?>
201+
</select>
202+
</td>
203+
</tr>
182204
<tr>
183205
<td class="vst-text input-label">
184206
<?php print _('Package');?>

web/templates/header.html

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
<meta charset="utf-8">
55
<link rel="icon" href="/images/favicon.ico" type="image/x-icon">
66
<title><?php echo $_SERVER['HTTP_HOST']; ?> - <?=_($TAB)?> - <?=_('Hestia Control Panel');?></title>
7-
<!-- Load base theme-->
7+
<!-- Load base system theme-->
88
<link type="text/css" rel="stylesheet" href="/css/themes/default.min.css?<?=JS_LATEST_UPDATE?>" rel="preload" />
9-
<? if ($_SESSION['THEME'] !== 'default') {?>
10-
<!-- Load provided theme -->
11-
<link type="text/css" rel="stylesheet" href="/css/themes/<?php echo $_SESSION['THEME']; ?>.min.css?<?php echo rand(); ?>" rel="preload" />
12-
<!-- Load custom theme -->
13-
<link type="text/css" rel="stylesheet" href="/css/themes/custom/<?php echo $_SESSION['THEME']; ?>.css?<?php echo rand(); ?>" rel="preload" />
9+
<? if ($_SESSION['userTheme']) {
10+
$selected_theme = $_SESSION['userTheme'];
11+
} else {
12+
$seleced_theme = $_SESSION['THEME'];
13+
}
14+
?>
15+
<!-- Load custom theme -->
16+
<? if (($_SESSION['THEME'] !== 'default') || ($_SESSION['userTheme'] !== 'default')) {?>
17+
<!-- Load HestiaCP-shipped themes (minified, updated/overwritten with updates) - ($HESTIA/web/css/themes/*.min.css) -->
18+
<link type="text/css" rel="stylesheet" href="/css/themes/<?php echo $selected_theme; ?>.min.css?<?php echo rand(); ?>" rel="preload" />
19+
<!-- Load custom theme files ($HESTIA/web/css/themes/custom/*.css) -->
20+
<link type="text/css" rel="stylesheet" href="/css/themes/custom/<?php echo $selected_theme; ?>.css?<?php echo rand(); ?>" rel="preload" />
1421
<? } ?>
1522
<link type="text/css" href="/css/dependencies/animate.min.css?<?=JS_LATEST_UPDATE?>" rel="stylesheet" rel="preload" />
1623
<link type="text/css" href="/css/dependencies/jquery-custom-dialogs.css?<?=JS_LATEST_UPDATE?>" rel="stylesheet" rel="preload" />
@@ -30,7 +37,7 @@
3037
</head>
3138
<body class="body-<?=strtolower($TAB)?> lang-<?=$_SESSION['language']?>">
3239
<?php if (($_SESSION['DEBUG_MODE']) == "true" ) {?>
33-
<div style="font-size:12px !important; padding:8px;">
40+
<div style="font-size:12px !important; padding:12px;position:sticky;top:0;z-index:3000;background-color:">
3441
<?php
3542
echo "<h3>Server Variables</h3>";
3643
foreach ($_SERVER as $key=>$val)
@@ -42,4 +49,5 @@
4249
echo "<b>".$key."= </b> ".$val." ";
4350
?>
4451
</div>
45-
<?php } ?>
52+
<?php } ?>
53+

web/templates/user/edit_user.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,29 @@
143143
</select>
144144
</td>
145145
</tr>
146+
<tr>
147+
<td class="vst-text input-label">
148+
<?php print _('Theme') ?>
149+
</td>
150+
</tr>
151+
<tr>
152+
<td>
153+
<select class="vst-list" name="v_user_theme">
154+
<?php
155+
foreach ($themes as $key => $value) {
156+
echo "\t\t\t\t<option value=\"".$value."\"";
157+
if ((!empty($_SESSION['userTheme'])) && ( $value == $v_user_theme )) {
158+
echo ' selected' ;
159+
}
160+
if ((!empty($_SESSION['userTheme'])) && ( $value == $_POST['v_user_theme'])){
161+
echo ' selected' ;
162+
}
163+
echo ">".$value."</option>\n";
164+
}
165+
?>
166+
</select>
167+
</td>
168+
</tr>
146169
<tr>
147170
<td class="vst-text input-label">
148171
<?php print _('Default Name Servers');?>

0 commit comments

Comments
 (0)