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

[WebUI] add create/delete ipset page

Robert Zollner 5 лет назад
Родитель
Сommit
1b22df5cf5

+ 64 - 0
web/add/firewall/ipset/index.php

@@ -0,0 +1,64 @@
+<?php
+error_reporting(NULL);
+ob_start();
+$TAB = 'FIREWALL';
+
+// Main include
+include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
+
+// Check user
+if ($_SESSION['user'] != 'admin') {
+    header("Location: /list/user");
+    exit;
+}
+
+// Check POST request
+if (!empty($_POST['ok'])) {
+
+    // Check token
+    if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
+        header('location: /login/');
+        exit();
+    }
+
+    // Check empty fields
+    if (empty($_POST['v_ipname'])) $errors[] = __('Name');
+    if (empty($_POST['v_datasource'])) $errors[] = __('Data Source');
+    if (empty($_POST['v_ipver'])) $errors[] = __('Ip Version');
+    if (empty($_POST['v_autoupdate'])) $errors[] = __('Autoupdate');
+
+    if (!empty($errors[0])) {
+        foreach ($errors as $i => $error) {
+            if ( $i == 0 ) {
+                $error_msg = $error;
+            } else {
+                $error_msg = $error_msg.", ".$error;
+            }
+        }
+        $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
+    }
+
+    $v_ipname = $_POST['v_ipname'];
+    $v_datasource = $_POST['v_datasource'];
+    $v_ipver = $_POST['v_ipver'];
+    $v_autoupdate = $_POST['v_autoupdate'];
+
+    // Add firewall ipset list
+    if (empty($_SESSION['error_msg'])) {
+        exec (HESTIA_CMD."v-add-firewall-ipset ".escapeshellarg($v_ipname)." ".escapeshellarg($v_datasource)." ".escapeshellarg($v_ipver)." ".escapeshellarg($v_autoupdate), $output, $return_var);
+        check_return_code($return_var,$output);
+        unset($output);
+    }
+
+    // Flush field values on success
+    if (empty($_SESSION['error_msg'])) {
+        $_SESSION['ok_msg'] = __('IPSET_CREATED_OK');
+    }
+}
+
+// Render
+render_page($user, $TAB, 'add_firewall_ipset');
+
+// Flush session messages
+unset($_SESSION['error_msg']);
+unset($_SESSION['ok_msg']);

+ 35 - 0
web/delete/firewall/ipset/index.php

@@ -0,0 +1,35 @@
+<?php
+error_reporting(NULL);
+ob_start();
+session_start();
+
+// Main include
+include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
+
+// Check user
+if ($_SESSION['user'] != 'admin') {
+    header("Location: /list/user");
+    exit;
+}
+
+// Check token
+if ((!isset($_GET['token'])) || ($_SESSION['token'] != $_GET['token'])) {
+    header('location: /login/');
+    exit();
+}
+
+if (!empty($_GET['listname'])) {
+    $v_listname = $_GET['listname'];
+    exec (HESTIA_CMD."v-delete-firewall-ipset ".escapeshellarg($v_listname), $output, $return_var);
+}
+check_return_code($return_var,$output);
+unset($output);
+
+$back = $_SESSION['back'];
+if (!empty($back)) {
+    header("Location: ".$back);
+    exit;
+}
+
+header("Location: /list/firewall/ipset/");
+exit;

+ 163 - 0
web/templates/admin/add_firewall_ipset.html

@@ -0,0 +1,163 @@
+<div class="l-center edit">
+        <div class="l-sort clearfix">
+          <div class="l-unit-toolbar__buttonstrip">
+            <a class="ui-button cancel" id="btn-back" href="/list/firewall/ipset/"><i class="fas fa-arrow-left status-icon blue"></i> <?=__('Back')?></a>
+          </div>
+          <div class="l-unit-toolbar__buttonstrip float-right">
+            <a href="#" class="ui-button" title="<?=__('Save')?>" data-action="submit" data-id="vstobjects"><i class="fas fa-save status-icon purple"></i> <?=__('Save')?></a>
+          </div>
+        </div>
+      </div>
+
+    <div class="l-separator"></div>
+    <!-- /.l-separator -->
+
+    <div class="l-center animated fadeIn">
+        <?php
+          $back = $_SESSION['back'];
+          if (empty($back)) {
+            $back = "location.href='/list/firewall/ipset/'";
+          } else {
+            $back = "location.href='".$back."'";
+          }
+        ?>
+        <form id="vstobjects" name="v_add_ipset" method="post">
+            <input type="hidden" name="token" value="<?=$_SESSION['token']?>" />
+            <input type="hidden" name="ok" value="Add" />
+
+            <table class="data mode-add">
+                <tr class="data-add">
+                    <td class="data-dotted">
+                        <table class="data-col1">
+                            <tr><td></td></tr>
+                        </table>
+                    </td>
+                    <td class="data-dotted">
+                        <table class="data-col2" width="600px">
+                            <tr>
+                                <td class="step-top">
+                                    <span class="page-title"><?=__('Adding Firewall Ipset List')?></span>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>
+                                    <?php
+                                        if (!empty($_SESSION['error_msg'])) {
+                                            echo "<span class=\"vst-error\"> <i class=\"fas fa-exclamation-circle status-icon red\"></i> ".htmlentities($_SESSION['error_msg'])."</span>";
+                                        } else {
+                                            if (!empty($_SESSION['ok_msg'])) {
+                                                echo "<span class=\"vst-ok\"> <i class=\"fas fa-check-circle status-icon green\"></i> ".$_SESSION['ok_msg']."</span>";
+                                            }
+                                        }
+                                    ?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td class="vst-text step-top">
+                                    <?php print __('Ip List Name') ?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>
+                                    <input type="text" size="20" class="vst-input" name="v_ipname" maxlength="255" value="<?=htmlentities(trim($v_ipname, "'"))?>">
+                                </td>
+                            </tr>
+                            <tr>
+                                <td class="vst-text step-top">
+                                    <?php print __('Data Source') ?> <span class="optional">(<?php print __('url, script or file');?>)</span>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>
+                                    <select class="vst-list" id="datasource_list" onchange="this.nextElementSibling.value=this.value">
+                                        <option value="">clear</option>
+                                    </select>
+                                    <input type="text" size="20" class="vst-input vst-list-editor" name="v_datasource" maxlength="255" value="<?=htmlentities(trim($v_datasource, "'"))?>">
+                                </td>
+                            </tr>
+                            <tr>
+                                <td class="vst-text step-top">
+                                    <?php print __('Ip Version') ?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>
+                                    <select class="vst-list" name="v_ipver">
+                                        <option value="v4" <?php if ((!empty($v_ipver)) && ( $v_ipver == "'v4'" )) echo 'selected'?>><?=__('ip v4')?></option>
+                                        <option value="v6" <?php if ((!empty($v_ipver)) && ( $v_ipver == "'v6'" )) echo 'selected'?>><?=__('ip v6')?></option>
+                                    </select>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td class="vst-text step-top">
+                                    <?php print __('Autoupdate') ?>
+                                </td>
+                            </tr>
+                            <tr>
+                                <td>
+                                    <select class="vst-list" name="v_autoupdate">
+                                        <option value="yes" <?php if ((!empty($v_autoupdate)) && ( $v_autoupdate == "'yes'" )) echo 'selected'?>><?=__('yes')?></option>
+                                        <option value="no" <?php if ((!empty($v_autoupdate)) && ( $v_autoupdate == "'no'" )) echo 'selected'?>><?=__('no')?></option>
+                                    </select>
+                                </td>
+                            </tr>
+
+                        </table>
+                        <table class="data-col2">
+                        </table>
+                    </td>
+                </tr>
+            </table>
+        </form>
+
+    </div>
+
+    <script>
+    var country_iplists = [
+        {name: "[ipv4] Country Romania",        source:"http://ipverse.net/ipblocks/data/countries/ro.zone"},
+        {name: "[ipv4] Country Germany",        source:"http://ipverse.net/ipblocks/data/countries/de.zone"},
+        {name: "[ipv4] Country Switzerland",    source:"http://ipverse.net/ipblocks/data/countries/ch.zone"},
+        {name: "[ipv4] Country France",         source:"http://ipverse.net/ipblocks/data/countries/fr.zone"},
+        {name: "[ipv4] Country Ukraine",        source:"http://ipverse.net/ipblocks/data/countries/ua.zone"},
+        {name: "[ipv4] Country Russia",         source:"http://ipverse.net/ipblocks/data/countries/ru.zone"},
+        {name: "[ipv4] Country Spain",          source:"http://ipverse.net/ipblocks/data/countries/es.zone"},
+        {name: "[ipv4] Country United Kingdom", source:"http://ipverse.net/ipblocks/data/countries/gb.zone"},
+        {name: "[ipv4] Country United States",  source:"http://ipverse.net/ipblocks/data/countries/us.zone"},
+        {name: "[ipv4] Country China",          source:"http://ipverse.net/ipblocks/data/countries/cn.zone"},
+        {name: "[ipv4] Country India",          source:"http://ipverse.net/ipblocks/data/countries/in.zone"},
+        /*
+        {name: "[ipv6] Country Romania",        source:"http://ipverse.net/ipblocks/data/countries/ro-ipv6.zone"},
+        {name: "[ipv6] Country Germany",        source:"http://ipverse.net/ipblocks/data/countries/de-ipv6.zone"},
+        {name: "[ipv6] Country Switzerland",    source:"http://ipverse.net/ipblocks/data/countries/ch-ipv6.zone"},
+        {name: "[ipv6] Country France",         source:"http://ipverse.net/ipblocks/data/countries/fr-ipv6.zone"},
+        {name: "[ipv6] Country Ukraine",        source:"http://ipverse.net/ipblocks/data/countries/ua-ipv6.zone"},
+        {name: "[ipv6] Country Russia",         source:"http://ipverse.net/ipblocks/data/countries/ru-ipv6.zone"},
+        {name: "[ipv6] Country Spain",          source:"http://ipverse.net/ipblocks/data/countries/es-ipv6.zone"},
+        {name: "[ipv6] Country United Kingdom", source:"http://ipverse.net/ipblocks/data/countries/gb-ipv6.zone"},
+        {name: "[ipv6] Country United States",  source:"http://ipverse.net/ipblocks/data/countries/us-ipv6.zone"},
+        {name: "[ipv6] Country China",          source:"http://ipverse.net/ipblocks/data/countries/cn-ipv6.zone"},
+        {name: "[ipv6] Country India",          source:"http://ipverse.net/ipblocks/data/countries/in-ipv6.zone"},
+        */
+    ];
+
+    country_iplists.sort(function (a, b) {
+        return a.name > b.name;
+    });
+
+    $(function() {
+        var targetelement = document.getElementById('datasource_list');
+
+        // IPVERSE
+        var newEl = document.createElement("option");
+        newEl.text="IPVERSE";
+        newEl.disabled=true;
+        targetelement.appendChild(newEl);
+
+        country_iplists.forEach(iplist => {
+            var newEl = document.createElement("option");
+            newEl.text=iplist.name;
+            newEl.value=iplist.source;
+            targetelement.appendChild(newEl);
+        });
+    });
+    </script>