]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - server-bans/index.php
Add a link to patreon on the footer
[irc/unrealircd/unrealircd-webpanel.git] / server-bans / index.php
index 759aced1a6129fd01b6a54a7e41dc25110666b2b..cdb5bf71f3827b19968deb0547f86190b8c9c1e0 100644 (file)
@@ -48,7 +48,7 @@ if (!empty($_POST))
                        {
                                $ban_host = $_POST['ban_host'];
                                $ban_type = $_POST['ban_type'];
-                               $ban_soft = empty($_POST['soft']) ? false : true;
+                               $ban_soft = empty($_POST['ban_soft']) ? false : true;
                                $ban_duration = $_POST['ban_duration'] ?? 0;
                                $ban_reason = $_POST['ban_reason'] ?? '';
                                if (!str_contains($ban_host, "@"))
@@ -96,7 +96,7 @@ if (!empty($_POST))
 ?>
 <h4>Server Bans Overview</h4>
 Here are all your network bans, from K-Lines to G-Lines, it's all here.<br><br>
-
+Click on an entry to edit it.
 <!-- Top add button -->
 <p><div class="btn btn-primary" onclick="add_ban()" <?php echo (current_user_can(PERMISSION_SERVER_BAN_ADD)) ? "" : "disabled"; ?>>
 Add Ban</div></p></table>
@@ -104,7 +104,7 @@ Add Ban</div></p></table>
 <!-- Add/edit ban -->
        <div class="modal fade" id="ban_add" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
-               <form method="post">
+               <form id="ban_add_form" method="post">
                        <input name="edit_existing" type="hidden" id="edit_existing" value="">
                        <div class="modal-content">
                                <div class="modal-header">
@@ -114,7 +114,7 @@ Add Ban</div></p></table>
                                </div>
                                <div class="modal-body">
                                        <div class="form-group">
-                                               <label for="ban_host">IP / Host</label>
+                                               <label for="ban_host" id="iphost_label">IP / Host</label>
                                                <input name="ban_host" type="text" class="form-control" id="ban_host" aria-describedby="ban_host_help" value="" required>
                                                <small id="ban_host_help" class="form-text text-muted">IP or host on which the ban is applied.</small>
                                        </div>
@@ -159,7 +159,7 @@ Add Ban</div></p></table>
        <!-- The banlist table -->
        <form method="post">
        <table id="data_list" class="table-striped display responsive nowrap" style="width:100%">
-       <thead>
+       <thead class="table-primary">
                <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th>
                <th scope="col">Mask</th>
                <th scope="col">Type</th>
@@ -198,6 +198,20 @@ Add Ban</div></p></table>
        </div></form></div></div>
 
 <script>
+let form = document.getElementById("ban_add_form");
+let submitban =document.getElementById("do_add_ban");
+form.addEventListener("submit", (e) => {
+       let bantype = document.getElementById("ban_type");
+       let banhost = document.getElementById("ban_host");
+       if ((bantype.value === "zline" || bantype.value === "gzline") && banhost.value.includes("@"))
+       {
+               e.preventDefault();
+               document.getElementById("iphost_label").innerHTML = `IP / Host <span class="card alert-danger" style="color:red">Value for (G)Z-Lines MUST be a host or IP.</span>`;
+       }
+});
+
+let data_list_table = null;
+
 $(document).ready( function () {
        args = {
                'responsive': true,
@@ -211,7 +225,7 @@ $(document).ready( function () {
                },
                'columns': [
                        { 'data': 'Select', 'responsivePriority': 1 },
-                       { 'data': 'Mask', 'responsivePriority': 2 },
+                       { 'data': 'Mask', 'responsivePriority': 2, 'className':'virtuallink' },
                        { 'data': 'Type', 'responsivePriority': 3 },
                        { 'data': 'Duration', 'responsivePriority': 4 },
                        { 'data': 'Reason', 'responsivePriority': 5, 'render': DataTable.render.ellipsis(50, false) },
@@ -242,22 +256,35 @@ $(document).ready( function () {
                }
        }
 
-       var data_list_table = $('#data_list').DataTable(args);
+       data_list_table = $('#data_list').DataTable(args);
 
        $('#data_list').on( 'click', 'td', function () {
-               var data = data_list_table.row(this).data();
-               edit_ban(data);
+               edit_ban(this);
        } );
 } );
 
-       function edit_ban(data)
+       function edit_ban(e)
        {
-               $('#ban_host').val(data['Mask']);
-               if (data['Type'] == 'Global Z-Line')
+               /* The first column is the 'Select' column */
+               if (data_list_table.cell(e).index().column == 0)
+                       return;
+               /* For all the other columns we try to popup and edit screen */
+               var data = data_list_table.row(e).data();
+               $host = data['Mask'];
+               if ($host.startsWith('%'))
+               {
+                       $('#ban_host').val($host.substring(1));
+                       $('#ban_soft').prop('checked', true);
+               } else {
+                       $('#ban_host').val($host);
+                       $('#ban_soft').prop('checked', false);
+               }
+               $type = data['Type'].replace('Soft ','');
+               if ($type == 'Global Z-Line')
                        $type = 'gzline';
-               else if (data['Type'] == 'Z-Line')
+               else if ($type == 'Z-Line')
                        $type = 'zline';
-               else if (data['Type'] == 'G-Line')
+               else if ($type == 'G-Line')
                        $type = 'gline';
                else
                        $type = 'kline';
@@ -267,7 +294,6 @@ $(document).ready( function () {
                else
                        $('#ban_duration').val(data['Duration']);
                $('#ban_reason').val(data['Reason']);
-               $('#ban_soft').prop('checked', false);
                $('#do_del_ban').show();
                $('#ban_add_title').html("Edit server ban");
                $('#do_add_ban').html("Modify Ban");
@@ -285,10 +311,12 @@ $(document).ready( function () {
                $('#ban_reason').val("");
                $('#ban_soft').prop('checked', false);
                $('#do_del_ban').hide();
+               $('#ban_add_title').html("Add server ban");
+               $('#do_add_ban').html("Add Ban");
                $('#ban_add').modal('show');
        }
 
-
+       
 </script>
 
 <?php require_once '../inc/footer.php'; ?>