Skip to content

Commit fa9fbbc

Browse files
committed
hestiacp#766 Creates .bash_aliases with a alias to the wanted php Please note crontab / cronjobs are not affected
1 parent d69e80d commit fa9fbbc

File tree

4 files changed

+217
-15
lines changed

4 files changed

+217
-15
lines changed

bin/v-change-user-php-cli

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# info: add php version to .bash_aliases
3+
# options: USER VERSION
4+
5+
# add line to .bash_aliases to set default php incase of multiPHP
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
user=$1
14+
version=$2
15+
16+
17+
# Includes
18+
source $HESTIA/func/main.sh
19+
source $HESTIA/conf/hestia.conf
20+
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
# Reading user values
27+
source $USER_DATA/user.conf
28+
29+
FILE=$HOMEDIR/$user/.bash_aliases
30+
31+
is_format_valid 'user'
32+
is_object_valid 'user' 'USER' "$user"
33+
is_object_unsuspended 'user' 'USER' "$user"
34+
35+
# Verify php version format
36+
if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
37+
echo "The php version format is invalid, it should look like [0-9].[0-9]..."
38+
exit
39+
fi
40+
41+
# Check if php version is supported
42+
if [ ! -f "$HESTIA_INSTALL_DIR/multiphp/$WEB_SYSTEM/PHP-${version//.}.sh" ]; then
43+
echo "Version is currently not supported or does not exist..."
44+
exit
45+
fi
46+
47+
if grep -q "alias php='env php$version'" "$FILE"; then
48+
echo "PHP CLI Already defined"
49+
exit;
50+
fi
51+
52+
#----------------------------------------------------------#
53+
# Action #
54+
#----------------------------------------------------------#
55+
56+
#create .bash_aliases is not exsists
57+
if [ ! -f "$FILE" ]; then
58+
touch "$FILE"
59+
fi
60+
61+
sed -i "/alias php='env/d" "$FILE"
62+
63+
echo "alias php='env php$version'" >> $FILE
64+
65+
# Change language
66+
if [ -z "$(grep PHPCLI $USER_DATA/user.conf)" ]; then
67+
sed -i "s/^TIME/PHPCLI='$version'\nTIME/g" $USER_DATA/user.conf
68+
else
69+
update_user_value "$user" '$PHPCLI' "$version"
70+
fi
71+
72+
#----------------------------------------------------------#
73+
# Hestia #
74+
#----------------------------------------------------------#
75+
76+
exit

bin/v-list-sys-php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
# info: listing availble PHP versions installed
3+
# options: [FORMAT]
4+
#
5+
# List /etc/php/* version check if folder fpm is avalible
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
format=${1-shell}
14+
15+
# Includes
16+
source $HESTIA/func/main.sh
17+
source $HESTIA/conf/hestia.conf
18+
19+
# JSON list function
20+
json_list() {
21+
i=1
22+
objects=$(echo "$versions" |wc -w)
23+
echo '['
24+
for version in $versions; do
25+
if [ "$i" -lt "$objects" ]; then
26+
echo -e "\t\"$version\","
27+
else
28+
echo -e "\t\"$version\""
29+
fi
30+
(( ++i))
31+
done
32+
echo "]"
33+
}
34+
35+
# SHELL list function
36+
shell_list() {
37+
echo "VERSION"
38+
echo "--------"
39+
for version in $versions; do
40+
echo "$version"
41+
done
42+
}
43+
44+
# PLAIN list function
45+
plain_list() {
46+
for version in $versions; do
47+
echo "$version"
48+
done
49+
}
50+
51+
# CSV list function
52+
csv_list() {
53+
echo "VERSION"
54+
for version in $versions; do
55+
echo "$version"
56+
done
57+
}
58+
59+
60+
#----------------------------------------------------------#
61+
# Action #
62+
#----------------------------------------------------------#
63+
64+
# List trough /etc/php
65+
versions_list=$(ls -d /etc/php/*)
66+
versions=()
67+
for version in $versions_list; do
68+
if [ -d "$version/fpm" ]
69+
then
70+
version=$(echo $version | cut -d'/' -f4);
71+
versions+=" $version"
72+
fi
73+
done
74+
75+
# Listing data
76+
case $format in
77+
json) json_list ;;
78+
plain) plain_list ;;
79+
csv) csv_list ;;
80+
shell) shell_list ;;
81+
esac
82+
83+
84+
#----------------------------------------------------------#
85+
# Hestia #
86+
#----------------------------------------------------------#
87+
88+
exit

web/edit/user/index.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
$v_shell = $data[$v_username]['SHELL'];
3939
$v_twofa = $data[$v_username]['TWOFA'];
4040
$v_qrcode = $data[$v_username]['QRCODE'];
41+
$v_phpcli = $data[$v_username]['PHPCLI'];
4142
$v_ns = $data[$v_username]['NS'];
4243
$nameservers = explode(",", $v_ns);
4344
$v_ns1 = $nameservers[0];
@@ -73,6 +74,14 @@
7374
$shells = json_decode(implode('', $output), true);
7475
unset($output);
7576

77+
//List PHP Versions
78+
// List supported php versions
79+
exec (HESTIA_CMD."v-list-sys-php json", $output, $return_var);
80+
$php_versions = json_decode(implode('', $output), true);
81+
unset($output);
82+
83+
84+
7685
// Are you admin?
7786
7887
// Check POST request
@@ -131,6 +140,14 @@
131140
unset($output);
132141
}
133142

143+
// Change phpcli (admin only)
144+
if (($v_phpcli != $_POST['v_phpcli']) && ($_SESSION['user'] == 'admin') && (empty($_SESSION['error_msg']))) {
145+
$v_phpcli = escapeshellarg($_POST['v_phpcli']);
146+
exec (HESTIA_CMD."v-change-user-php-cli ".escapeshellarg($v_username)." ".$v_phpcli, $output, $return_var);
147+
check_return_code($return_var,$output);
148+
unset($output);
149+
}
150+
134151
// Change language
135152
if (($v_language != $_POST['v_language']) && (empty($_SESSION['error_msg']))) {
136153
$v_language = escapeshellarg($_POST['v_language']);

web/templates/admin/edit_user.html

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
<a class="ui-button cancel" id="btn-back" href="/list/user/"><i class="fas fa-arrow-left status-icon blue"></i> <?=__('Back')?></a>
55
</div>
66
<div class="l-unit-toolbar__buttonstrip float-right">
7+
<?php
8+
if (!empty($_SESSION['error_msg'])) {
9+
echo "<span class=\"vst-error\"> → ".htmlentities($_SESSION['error_msg'])."</span>";
10+
} else {
11+
if (!empty($_SESSION['ok_msg'])) {
12+
echo "<span class=\"vst-ok\"> → ".$_SESSION['ok_msg']."</span>";
13+
}
14+
}
15+
?>
716
<a href="#" class="ui-button" title="<?=__('Save')?>" data-action="submit" data-id="vstobjects"><i class="fas fa-save status-icon purple"></i> <?=__('Save')?></a>
817
</div>
918
</div>
@@ -41,20 +50,7 @@
4150
<td class="step-top">
4251
<span class="page-title"><?=__('Editing User')?></span>
4352
</td>
44-
</tr>
45-
<tr>
46-
<td>
47-
<?php
48-
if (!empty($_SESSION['error_msg'])) {
49-
echo "<span class=\"vst-error\"> <i class=\"fas fa-exclamation-circle status-icon red\"></i> ".htmlentities($_SESSION['error_msg'])."</span>";
50-
} else {
51-
if (!empty($_SESSION['ok_msg'])) {
52-
echo "<span class=\"vst-ok\"> <i class=\"fas fa-check-circle status-icon green\"></i> ".$_SESSION['ok_msg']."</span>";
53-
}
54-
}
55-
?>
56-
</td>
57-
</tr>
53+
</tr>
5854
<tr>
5955
<td class="vst-text step-top">
6056
<?php print __('Username');?>
@@ -78,7 +74,7 @@
7874
</tr>
7975
<tr>
8076
<td>
81-
<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>
77+
<label><input type="checkbox" class="vst-checkbox password-option" name="v_twofa" <?php if(!empty($v_twofa)) echo "checked=yes" ?> onclick="App.Actions.WEB.toggle_twofa(this)"> <?php print __('Enable 2FA');?></label>
8278
<?php if (!empty($v_twofa)) { ?>
8379
<p><?php echo __('2FA Reset Code:').' '.$v_twofa; ?></br></p>
8480
<p><?php echo __('Please scan the code below in your 2FA application:'); ?></p>
@@ -137,6 +133,31 @@
137133
</select>
138134
</td>
139135
</tr>
136+
<tr>
137+
<td class="vst-text input-label">
138+
<?php print __('PHP_CLI');?>
139+
</td>
140+
</tr>
141+
<tr>
142+
<td>
143+
<select class="vst-list" name="v_phpcli">
144+
<?php
145+
foreach ($php_versions as $key => $value) {
146+
$php = explode('-',$value);
147+
echo "\t\t\t\t<option value=\"".$value."\"";
148+
$svalue = "'".$value."'";
149+
if ((!empty($v_phpcli)) && ( $value == $v_phpcli ) || ($svalue == $v_phpcli)){
150+
echo ' selected' ;
151+
}
152+
if ((empty($v_phpcli)) && ($value == DEFAULT_PHP_VERSION)){
153+
echo ' selected' ;
154+
}
155+
echo ">".htmlentities($value)."</option>\n";
156+
}
157+
?>
158+
</select>
159+
</td>
160+
</tr>
140161
<tr>
141162
<td class="vst-text input-label">
142163
<?php print __('Language');?>

0 commit comments

Comments
 (0)