Skip to content

Commit e300ea6

Browse files
committed
changed empty string to “allow-all” to allow all ips
Disable api will clear the allowed ip list
1 parent 3abbf7a commit e300ea6

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

bin/v-change-sys-api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ if [ "$status" = "enable" ]; then
4444
else
4545
if [ $API = "yes" ]; then
4646
$HESTIA/bin/v-change-sys-config-value "API" "no"
47+
$HESTIA/bin/v-change-sys-config-value "API_ALLOWED_IP" ""
4748
sed -i 's|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA/web/api/index.php
4849
fi
4950
fi

func/upgrade.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ upgrade_health_check() {
151151
fi
152152
# API Allowed IP
153153
if [ -z "$API_ALLOWED_IP" ]; then
154-
echo "[ ! ] Adding missing variable to hestia.conf: API_ALLOWED_IP ('')"
155-
$BIN/v-change-sys-config-value "API_ALLOWED_IP" "127.0.0.1"
154+
echo "[ ! ] Adding missing variable to hestia.conf: API_ALLOWED_IP ('allow-all')"
155+
$BIN/v-change-sys-config-value "API_ALLOWED_IP" "allow-all"
156156
fi
157157

158158
echo "[ * ] Health check complete. Starting upgrade from $VERSION to $new_version..."

web/api/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ function api($hst_hash, $hst_user, $hst_password, $hst_returncode, $hst_cmd, $hs
4545
echo 'Error: authentication failed';
4646
exit;
4747
}
48-
if ( $settings['config']['API_ALLOWED_IP'] != '' ){
48+
if ( $settings['config']['API_ALLOWED_IP'] != 'allow-all' ){
4949
$ip_list = explode(',',$settings['config']['API_ALLOWED_IP']);
50+
$ip_list[] = '127.0.0.1';
5051
if ( !in_array(get_real_user_ip(), $ip_list)){
5152
echo 'Error: authentication failed';
5253
exit;

web/edit/server/index.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -694,24 +694,16 @@
694694
$v_security_adv = 'yes';
695695
}
696696
}
697-
if (empty($_SESSION['error_msg'])) {
698-
if ($_POST['v_api'] != $_SESSION['API']) {
699-
$api_status = 'disable';
700-
if ($_POST['v_api'] == 'yes'){
701-
$api_status = 'enable';
702-
}
703-
exec (HESTIA_CMD."v-change-sys-api ".escapeshellarg($api_status), $output, $return_var);
704-
check_return_code($return_var,$output);
705-
unset($output);
706-
if (empty($_SESSION['error_msg'])) $v_login_style = $_POST['v_api'];
707-
$v_security_adv = 'yes';
708-
}
709-
}
697+
710698
if (empty($_SESSION['error_msg'])) {
711699
if ($_POST['v_api_allowed_ip'] != $_SESSION['API_ALLOWED_IP']) {
712700
$ips = array();
713701
foreach(explode("\n",$_POST['v_api_allowed_ip']) as $ip){
714-
if(filter_var(trim($ip), FILTER_VALIDATE_IP)){
702+
if ($ip != "allow-all") {
703+
if(filter_var(trim($ip), FILTER_VALIDATE_IP)){
704+
$ips[] = trim($ip);
705+
}
706+
}else{
715707
$ips[] = trim($ip);
716708
}
717709
}
@@ -724,6 +716,21 @@
724716
}
725717
}
726718
}
719+
720+
if (empty($_SESSION['error_msg'])) {
721+
if ($_POST['v_api'] != $_SESSION['API']) {
722+
$api_status = 'disable';
723+
if ($_POST['v_api'] == 'yes'){
724+
$api_status = 'enable';
725+
}
726+
exec (HESTIA_CMD."v-change-sys-api ".escapeshellarg($api_status), $output, $return_var);
727+
check_return_code($return_var,$output);
728+
unset($output);
729+
if (empty($_SESSION['error_msg'])) $v_login_style = $_POST['v_api'];
730+
$v_security_adv = 'yes';
731+
}
732+
}
733+
727734
// Update SSL certificate
728735
if ((!empty($_POST['v_ssl_crt'])) && (empty($_SESSION['error_msg']))) {
729736
if (($v_ssl_crt != str_replace("\r\n", "\n", $_POST['v_ssl_crt'])) || ($v_ssl_key != str_replace("\r\n", "\n", $_POST['v_ssl_key']))) {

0 commit comments

Comments
 (0)