Skip to content

Commit 5cbf835

Browse files
authored
Fix/1549 firewall issue (hestiacp#1555)
* Fixed hestiacp#1549 * remove defer
1 parent ebd6dc9 commit 5cbf835

File tree

4 files changed

+56
-33
lines changed

4 files changed

+56
-33
lines changed

web/add/firewall/index.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
$ipset_lists_json=json_encode($ipset_lists);
3131

3232
// Check POST request
33-
if (!empty($_POST['ok'])) {
34-
35-
// Check token
33+
if (!empty($_POST['ok'])) { // Check token
3634
if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
3735
header('location: /login/');
3836
exit();
@@ -41,7 +39,7 @@
4139
// Check empty fields
4240
if (empty($_POST['v_action'])) $errors[] = _('action');
4341
if (empty($_POST['v_protocol'])) $errors[] = _('protocol');
44-
if (!isset($_POST['v_port'])) $errors[] = _('port');
42+
if (empty($_POST['v_port']) && strlen($_POST['v_port']) == 0) $errors[] = _('port');
4543
if (empty($_POST['v_ip'])) $errors[] = _('ip address');
4644
if (!empty($errors[0])) {
4745
foreach ($errors as $i => $error) {

web/edit/firewall/index.php

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,59 @@
6666
header('location: /login/');
6767
exit();
6868
}
69-
70-
$v_rule = escapeshellarg($_GET['rule']);
71-
$v_action = escapeshellarg($_POST['v_action']);
72-
$v_protocol = escapeshellarg($_POST['v_protocol']);
73-
$v_port = str_replace(" ",",", $_POST['v_port']);
74-
$v_port = preg_replace('/\,+/', ',', $v_port);
75-
$v_port = trim($v_port, ",");
76-
$v_port = escapeshellarg($v_port);
77-
$v_ip = escapeshellarg($_POST['v_ip']);
78-
$v_comment = escapeshellarg($_POST['v_comment']);
79-
80-
// Change Status
81-
exec (HESTIA_CMD."v-change-firewall-rule ".$v_rule." ".$v_action." ".$v_ip." ".$v_port." ".$v_protocol." ".$v_comment, $output, $return_var);
82-
check_return_code($return_var,$output);
83-
unset($output);
84-
85-
$v_rule = $_GET['v_rule'];
86-
$v_action = $_POST['v_action'];
87-
$v_protocol = $_POST['v_protocol'];
88-
$v_port = str_replace(" ",",", $_POST['v_port']);
89-
$v_port = preg_replace('/\,+/', ',', $v_port);
90-
$v_port = trim($v_port, ",");
91-
$v_ip = $_POST['v_ip'];
92-
$v_comment = $_POST['v_comment'];
93-
94-
// Set success message
95-
if (empty($_SESSION['error_msg'])) {
96-
$_SESSION['ok_msg'] = _('Changes has been saved.');
69+
// Check empty fields
70+
if (empty($_POST['v_action'])) $errors[] = _('action');
71+
if (empty($_POST['v_protocol'])) $errors[] = _('protocol');
72+
if (empty($_POST['v_port']) && strlen($_POST['v_port']) == 0) $errors[] = _('port');
73+
if (empty($_POST['v_ip'])) $errors[] = _('ip address');
74+
if (!empty($errors[0])) {
75+
foreach ($errors as $i => $error) {
76+
if ( $i == 0 ) {
77+
$error_msg = $error;
78+
} else {
79+
$error_msg = $error_msg.", ".$error;
80+
}
81+
}
82+
$_SESSION['error_msg'] = sprintf(_('Field "%s" can not be blank.'),$error_msg);
83+
}
84+
if (!empty($_SESSION['error_msg'])) {
85+
$v_rule = escapeshellarg($_GET['rule']);
86+
$v_action = escapeshellarg($_POST['v_action']);
87+
$v_protocol = escapeshellarg($_POST['v_protocol']);
88+
$v_port = str_replace(" ",",", $_POST['v_port']);
89+
$v_port = preg_replace('/\,+/', ',', $v_port);
90+
$v_port = trim($v_port, ",");
91+
$v_port = escapeshellarg($v_port);
92+
$v_ip = escapeshellarg($_POST['v_ip']);
93+
$v_comment = escapeshellarg($_POST['v_comment']);
94+
95+
// Change Status
96+
exec (HESTIA_CMD."v-change-firewall-rule ".$v_rule." ".$v_action." ".$v_ip." ".$v_port." ".$v_protocol." ".$v_comment, $output, $return_var);
97+
check_return_code($return_var,$output);
98+
unset($output);
99+
100+
$v_rule = $_GET['v_rule'];
101+
$v_action = $_POST['v_action'];
102+
$v_protocol = $_POST['v_protocol'];
103+
$v_port = str_replace(" ",",", $_POST['v_port']);
104+
$v_port = preg_replace('/\,+/', ',', $v_port);
105+
$v_port = trim($v_port, ",");
106+
$v_ip = $_POST['v_ip'];
107+
$v_comment = $_POST['v_comment'];
108+
109+
// Set success message
110+
if (empty($_SESSION['error_msg'])) {
111+
$_SESSION['ok_msg'] = _('Changes has been saved.');
112+
}
113+
}else{
114+
$v_rule = $_GET['v_rule'];
115+
$v_action = $_POST['v_action'];
116+
$v_protocol = $_POST['v_protocol'];
117+
$v_port = str_replace(" ",",", $_POST['v_port']);
118+
$v_port = preg_replace('/\,+/', ',', $v_port);
119+
$v_port = trim($v_port, ",");
120+
$v_ip = $_POST['v_ip'];
121+
$v_comment = $_POST['v_comment'];
97122
}
98123
}
99124

web/templates/header.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<link type="text/css" href="/css/animate.min.css?<?=JS_LATEST_UPDATE?>" rel="stylesheet" />
1010
<link type="text/css" href="/css/jquery-custom-dialogs.css?<?=JS_LATEST_UPDATE?>" rel="stylesheet" />
1111
<link type="text/css" href="/css/all.min.css?<?=JS_LATEST_UPDATE?>" rel="stylesheet" />
12+
<script type="text/javascript" src="/inc/jquery/jquery-3.5.1.min.js"></script>
1213
<script>
1314
//
1415
// GLOBAL SETTINGS

web/templates/scripts.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<script type="text/javascript" src="/inc/jquery/jquery-3.5.1.min.js"></script>
21
<script type="text/javascript" src="/js/jquery/jquery-1.7.2.min.js?<?=JS_LATEST_UPDATE?>"></script>
32
<script type="text/javascript" src="/js/jquery/jquery.cookie.js?<?=JS_LATEST_UPDATE?>"></script>
43
<script type="text/javascript" src="/js/jquery/jquery-ui-1.8.20.custom.min.js?<?=JS_LATEST_UPDATE?>"></script>

0 commit comments

Comments
 (0)