Просмотр исходного кода

Add v-change-user-config-value

Kristan Kenney 5 лет назад
Родитель
Сommit
a302fbcbd6
3 измененных файлов с 101 добавлено и 18 удалено
  1. 55 0
      bin/v-change-user-config-value
  2. 3 0
      web/edit/user/index.php
  3. 43 18
      web/templates/pages/edit_user.html

+ 55 - 0
bin/v-change-user-config-value

@@ -0,0 +1,55 @@
+#!/bin/bash
+# info: changes user configuration value
+# options: USER KEY VALUE
+# labels: hestia
+#
+# example: v-change-user-config-value admin ROLE admin
+#
+# Changes key/value for specified user.
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+user=$1
+key="$2"
+value="$3"
+
+# 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                             #
+#----------------------------------------------------------#
+
+# Set theme value
+check_ckey=$(grep "^${key^^}" $USER_DATA/user.conf)
+if [ -z "$check_ckey" ]; then
+    # Rebuild user configuration to repair missing value
+    $BIN/v-rebuild-user $user
+fi
+update_user_value "$user" "${key^^}" "$value"
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+exit

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

@@ -53,6 +53,9 @@ $v_twofa = $data[$v_username]['TWOFA'];
 $v_qrcode = $data[$v_username]['QRCODE'];
 $v_phpcli = $data[$v_username]['PHPCLI'];
 $v_role = $data[$v_username]['ROLE'];
+$v_login_disabled = $data[$v_username]['LOGIN_DISABLED'];
+$v_login_use_iplist = $data[$v_username]['LOGIN_USE_IPLIST'];
+$v_login_allowed_ips = $data[$v_username]['LOGIN_ALLOW_IPS'];
 $v_ns = $data[$v_username]['NS'];
 $nameservers = explode(",", $v_ns);
 $v_ns1 = $nameservers[0];

+ 43 - 18
web/templates/pages/edit_user.html

@@ -130,23 +130,53 @@
                                 </td>
                             </tr>
                             <tr>
-                                <td class="vst-text">
-                                    <?php print _('Your password must have at least');?>:
-                                    <ul>
-                                        <li><?php print _('8 characters long');?></li>
-                                        <li><?php print _('1 uppercase & 1 lowercase character');?></li>
-                                        <li><?php print _('1 number');?></li>
-                                    </ul>
+                                <td>
+                                    <table id="password-details">
+                                        <tr>
+                                            <td class="vst-text">
+                                                <?php print _('Your password must have at least');?>:
+                                                <ul>
+                                                    <li><?php print _('8 characters long');?></li>
+                                                    <li><?php print _('1 uppercase & 1 lowercase character');?></li>
+                                                    <li><?php print _('1 number');?></li>
+                                                </ul>
+                                            </td>
+                                        </tr>
+                                        <tr>
+                                            <td>
+                                                <label><input type="checkbox" class="vst-checkbox password-option" name="v_twofa" <?php if(!empty($v_twofa)) echo "checked=yes" ?>><?php print _('Enable 2FA');?></label>
+                                                <?php if (!empty($v_twofa)) { ?>
+                                                <p><?php echo _('2FA Reset Code:').' '.$v_twofa; ?></br></p>
+                                                <p><?php echo _('Please scan the code below in your 2FA application:'); ?></p>
+                                                <div><img class="qr-code" src="<?php echo $v_qrcode; ?>"></div>
+                                                <?php } ?>
+                                            </td>
+                                        </tr>
+                                    </table>
+                                </td>
+                            </tr>
+                            <? if ($_SESSION['userContext'] === 'admin') {?>
+                                <tr>
+                                    <td>
+                                        <label><input type="checkbox" size="20" class="vst-checkbox" onclick="javascript:elementHideShow('password-details')" name="v_login_disabled" <?php if ((isset($data[$user]['LOGIN_DISABLED'])) && (!empty($data[$user]['LOGIN_DISABLED'])) && ($data[$user]['LOGIN_DISABLED'] == "yes")) echo "checked=yes" ?>><?php print _('User can not log in to Control Panel');?></label>
+                                    </td>
+                                </tr>
+                            <? } ?>
+                            <tr>
+                                <td>
+                                    <label><input type="checkbox" size="20" class="vst-checkbox" onclick="javascript:elementHideShow('ip-allowlist')" name="v_login_use_iplist" <?php if ($data[$user]['LOGIN_USE_IPLIST'] === "yes") echo "checked=yes" ?>><?php print _('Only allow logins from certain IP addresses');?></label>
                                 </td>
                             </tr>
                             <tr>
                                 <td>
-                                    <label><input type="checkbox" class="vst-checkbox password-option" name="v_twofa" <?php if(!empty($v_twofa)) echo "checked=yes" ?>><?php print _('Enable 2FA');?></label>
-                                    <?php if (!empty($v_twofa)) { ?>
-                                    <p><?php echo _('2FA Reset Code:').' '.$v_twofa; ?></br></p>
-                                    <p><?php echo _('Please scan the code below in your 2FA application:'); ?></p>
-                                    <div><img class="qr-code" src="<?php echo $v_qrcode; ?>"></div>
-                                    <?php } ?>
+                                    <table id="ip-allowlist" style="<? if ($data[$user]['LOGIN_USE_IPLIST'] === 'yes') { echo 'display: table-cell;'; } else { echo 'display: none;'; } ?>">
+                                        <tr>
+                                            <td>
+                                                <input type="text" size="20" class="vst-input" name="v_login_allowed_ups" value="<?=htmlentities(trim($v_login_allowed_ips, "'"))?>">
+                                                <input type="hidden" name="v_login_allowed_ips" value="<?=htmlentities(trim($v_login_allowed_ips, "'"))?>">
+                                            </td>
+                                        </tr>
+                                    </table>
                                 </td>
                             </tr>
                             <tr>
@@ -192,11 +222,6 @@
                                 </tr>
                                 <? } ?>
                             <? } ?>
-                            <tr>
-                                <td>
-                                    <label><input type="checkbox" size="20" class="vst-checkbox" name="v_user_login_disabled" <?php if ((isset($data[$user]['LOGIN_DISABLED'])) && (!empty($data[$user]['LOGIN_DISABLED'])) && ($data[$user]['LOGIN_DISABLED'] == "yes")) echo "checked=yes" ?>><?php print _('User can not log in to Control Panel');?></label>
-                                </td>
-                            </tr>
                             <? if ($_SESSION['POLICY_USER_CHANGE_THEME'] !== 'no') {?>
                             <tr>
                                 <td class="vst-text input-label">