Skip to content

Commit 1b22df5

Browse files
committed
[WebUI] add create/delete ipset page
1 parent 71290ee commit 1b22df5

File tree

3 files changed

+262
-0
lines changed

3 files changed

+262
-0
lines changed

web/add/firewall/ipset/index.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
error_reporting(NULL);
3+
ob_start();
4+
$TAB = 'FIREWALL';
5+
6+
// Main include
7+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
8+
9+
// Check user
10+
if ($_SESSION['user'] != 'admin') {
11+
header("Location: /list/user");
12+
exit;
13+
}
14+
15+
// Check POST request
16+
if (!empty($_POST['ok'])) {
17+
18+
// Check token
19+
if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
20+
header('location: /login/');
21+
exit();
22+
}
23+
24+
// Check empty fields
25+
if (empty($_POST['v_ipname'])) $errors[] = __('Name');
26+
if (empty($_POST['v_datasource'])) $errors[] = __('Data Source');
27+
if (empty($_POST['v_ipver'])) $errors[] = __('Ip Version');
28+
if (empty($_POST['v_autoupdate'])) $errors[] = __('Autoupdate');
29+
30+
if (!empty($errors[0])) {
31+
foreach ($errors as $i => $error) {
32+
if ( $i == 0 ) {
33+
$error_msg = $error;
34+
} else {
35+
$error_msg = $error_msg.", ".$error;
36+
}
37+
}
38+
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
39+
}
40+
41+
$v_ipname = $_POST['v_ipname'];
42+
$v_datasource = $_POST['v_datasource'];
43+
$v_ipver = $_POST['v_ipver'];
44+
$v_autoupdate = $_POST['v_autoupdate'];
45+
46+
// Add firewall ipset list
47+
if (empty($_SESSION['error_msg'])) {
48+
exec (HESTIA_CMD."v-add-firewall-ipset ".escapeshellarg($v_ipname)." ".escapeshellarg($v_datasource)." ".escapeshellarg($v_ipver)." ".escapeshellarg($v_autoupdate), $output, $return_var);
49+
check_return_code($return_var,$output);
50+
unset($output);
51+
}
52+
53+
// Flush field values on success
54+
if (empty($_SESSION['error_msg'])) {
55+
$_SESSION['ok_msg'] = __('IPSET_CREATED_OK');
56+
}
57+
}
58+
59+
// Render
60+
render_page($user, $TAB, 'add_firewall_ipset');
61+
62+
// Flush session messages
63+
unset($_SESSION['error_msg']);
64+
unset($_SESSION['ok_msg']);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
error_reporting(NULL);
3+
ob_start();
4+
session_start();
5+
6+
// Main include
7+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
8+
9+
// Check user
10+
if ($_SESSION['user'] != 'admin') {
11+
header("Location: /list/user");
12+
exit;
13+
}
14+
15+
// Check token
16+
if ((!isset($_GET['token'])) || ($_SESSION['token'] != $_GET['token'])) {
17+
header('location: /login/');
18+
exit();
19+
}
20+
21+
if (!empty($_GET['listname'])) {
22+
$v_listname = $_GET['listname'];
23+
exec (HESTIA_CMD."v-delete-firewall-ipset ".escapeshellarg($v_listname), $output, $return_var);
24+
}
25+
check_return_code($return_var,$output);
26+
unset($output);
27+
28+
$back = $_SESSION['back'];
29+
if (!empty($back)) {
30+
header("Location: ".$back);
31+
exit;
32+
}
33+
34+
header("Location: /list/firewall/ipset/");
35+
exit;
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<div class="l-center edit">
2+
<div class="l-sort clearfix">
3+
<div class="l-unit-toolbar__buttonstrip">
4+
<a class="ui-button cancel" id="btn-back" href="/list/firewall/ipset/"><i class="fas fa-arrow-left status-icon blue"></i> <?=__('Back')?></a>
5+
</div>
6+
<div class="l-unit-toolbar__buttonstrip float-right">
7+
<a href="#" class="ui-button" title="<?=__('Save')?>" data-action="submit" data-id="vstobjects"><i class="fas fa-save status-icon purple"></i> <?=__('Save')?></a>
8+
</div>
9+
</div>
10+
</div>
11+
12+
<div class="l-separator"></div>
13+
<!-- /.l-separator -->
14+
15+
<div class="l-center animated fadeIn">
16+
<?php
17+
$back = $_SESSION['back'];
18+
if (empty($back)) {
19+
$back = "location.href='/list/firewall/ipset/'";
20+
} else {
21+
$back = "location.href='".$back."'";
22+
}
23+
?>
24+
<form id="vstobjects" name="v_add_ipset" method="post">
25+
<input type="hidden" name="token" value="<?=$_SESSION['token']?>" />
26+
<input type="hidden" name="ok" value="Add" />
27+
28+
<table class="data mode-add">
29+
<tr class="data-add">
30+
<td class="data-dotted">
31+
<table class="data-col1">
32+
<tr><td></td></tr>
33+
</table>
34+
</td>
35+
<td class="data-dotted">
36+
<table class="data-col2" width="600px">
37+
<tr>
38+
<td class="step-top">
39+
<span class="page-title"><?=__('Adding Firewall Ipset List')?></span>
40+
</td>
41+
</tr>
42+
<tr>
43+
<td>
44+
<?php
45+
if (!empty($_SESSION['error_msg'])) {
46+
echo "<span class=\"vst-error\"> <i class=\"fas fa-exclamation-circle status-icon red\"></i> ".htmlentities($_SESSION['error_msg'])."</span>";
47+
} else {
48+
if (!empty($_SESSION['ok_msg'])) {
49+
echo "<span class=\"vst-ok\"> <i class=\"fas fa-check-circle status-icon green\"></i> ".$_SESSION['ok_msg']."</span>";
50+
}
51+
}
52+
?>
53+
</td>
54+
</tr>
55+
<tr>
56+
<td class="vst-text step-top">
57+
<?php print __('Ip List Name') ?>
58+
</td>
59+
</tr>
60+
<tr>
61+
<td>
62+
<input type="text" size="20" class="vst-input" name="v_ipname" maxlength="255" value="<?=htmlentities(trim($v_ipname, "'"))?>">
63+
</td>
64+
</tr>
65+
<tr>
66+
<td class="vst-text step-top">
67+
<?php print __('Data Source') ?> <span class="optional">(<?php print __('url, script or file');?>)</span>
68+
</td>
69+
</tr>
70+
<tr>
71+
<td>
72+
<select class="vst-list" id="datasource_list" onchange="this.nextElementSibling.value=this.value">
73+
<option value="">clear</option>
74+
</select>
75+
<input type="text" size="20" class="vst-input vst-list-editor" name="v_datasource" maxlength="255" value="<?=htmlentities(trim($v_datasource, "'"))?>">
76+
</td>
77+
</tr>
78+
<tr>
79+
<td class="vst-text step-top">
80+
<?php print __('Ip Version') ?>
81+
</td>
82+
</tr>
83+
<tr>
84+
<td>
85+
<select class="vst-list" name="v_ipver">
86+
<option value="v4" <?php if ((!empty($v_ipver)) && ( $v_ipver == "'v4'" )) echo 'selected'?>><?=__('ip v4')?></option>
87+
<option value="v6" <?php if ((!empty($v_ipver)) && ( $v_ipver == "'v6'" )) echo 'selected'?>><?=__('ip v6')?></option>
88+
</select>
89+
</td>
90+
</tr>
91+
<tr>
92+
<td class="vst-text step-top">
93+
<?php print __('Autoupdate') ?>
94+
</td>
95+
</tr>
96+
<tr>
97+
<td>
98+
<select class="vst-list" name="v_autoupdate">
99+
<option value="yes" <?php if ((!empty($v_autoupdate)) && ( $v_autoupdate == "'yes'" )) echo 'selected'?>><?=__('yes')?></option>
100+
<option value="no" <?php if ((!empty($v_autoupdate)) && ( $v_autoupdate == "'no'" )) echo 'selected'?>><?=__('no')?></option>
101+
</select>
102+
</td>
103+
</tr>
104+
105+
</table>
106+
<table class="data-col2">
107+
</table>
108+
</td>
109+
</tr>
110+
</table>
111+
</form>
112+
113+
</div>
114+
115+
<script>
116+
var country_iplists = [
117+
{name: "[ipv4] Country Romania", source:"http://ipverse.net/ipblocks/data/countries/ro.zone"},
118+
{name: "[ipv4] Country Germany", source:"http://ipverse.net/ipblocks/data/countries/de.zone"},
119+
{name: "[ipv4] Country Switzerland", source:"http://ipverse.net/ipblocks/data/countries/ch.zone"},
120+
{name: "[ipv4] Country France", source:"http://ipverse.net/ipblocks/data/countries/fr.zone"},
121+
{name: "[ipv4] Country Ukraine", source:"http://ipverse.net/ipblocks/data/countries/ua.zone"},
122+
{name: "[ipv4] Country Russia", source:"http://ipverse.net/ipblocks/data/countries/ru.zone"},
123+
{name: "[ipv4] Country Spain", source:"http://ipverse.net/ipblocks/data/countries/es.zone"},
124+
{name: "[ipv4] Country United Kingdom", source:"http://ipverse.net/ipblocks/data/countries/gb.zone"},
125+
{name: "[ipv4] Country United States", source:"http://ipverse.net/ipblocks/data/countries/us.zone"},
126+
{name: "[ipv4] Country China", source:"http://ipverse.net/ipblocks/data/countries/cn.zone"},
127+
{name: "[ipv4] Country India", source:"http://ipverse.net/ipblocks/data/countries/in.zone"},
128+
/*
129+
{name: "[ipv6] Country Romania", source:"http://ipverse.net/ipblocks/data/countries/ro-ipv6.zone"},
130+
{name: "[ipv6] Country Germany", source:"http://ipverse.net/ipblocks/data/countries/de-ipv6.zone"},
131+
{name: "[ipv6] Country Switzerland", source:"http://ipverse.net/ipblocks/data/countries/ch-ipv6.zone"},
132+
{name: "[ipv6] Country France", source:"http://ipverse.net/ipblocks/data/countries/fr-ipv6.zone"},
133+
{name: "[ipv6] Country Ukraine", source:"http://ipverse.net/ipblocks/data/countries/ua-ipv6.zone"},
134+
{name: "[ipv6] Country Russia", source:"http://ipverse.net/ipblocks/data/countries/ru-ipv6.zone"},
135+
{name: "[ipv6] Country Spain", source:"http://ipverse.net/ipblocks/data/countries/es-ipv6.zone"},
136+
{name: "[ipv6] Country United Kingdom", source:"http://ipverse.net/ipblocks/data/countries/gb-ipv6.zone"},
137+
{name: "[ipv6] Country United States", source:"http://ipverse.net/ipblocks/data/countries/us-ipv6.zone"},
138+
{name: "[ipv6] Country China", source:"http://ipverse.net/ipblocks/data/countries/cn-ipv6.zone"},
139+
{name: "[ipv6] Country India", source:"http://ipverse.net/ipblocks/data/countries/in-ipv6.zone"},
140+
*/
141+
];
142+
143+
country_iplists.sort(function (a, b) {
144+
return a.name > b.name;
145+
});
146+
147+
$(function() {
148+
var targetelement = document.getElementById('datasource_list');
149+
150+
// IPVERSE
151+
var newEl = document.createElement("option");
152+
newEl.text="IPVERSE";
153+
newEl.disabled=true;
154+
targetelement.appendChild(newEl);
155+
156+
country_iplists.forEach(iplist => {
157+
var newEl = document.createElement("option");
158+
newEl.text=iplist.name;
159+
newEl.value=iplist.source;
160+
targetelement.appendChild(newEl);
161+
});
162+
});
163+
</script>

0 commit comments

Comments
 (0)