]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Separate Server Bans tab
authorValerie Pond <redacted>
Mon, 9 Jan 2023 02:13:39 +0000 (02:13 +0000)
committerValerie Pond <redacted>
Mon, 9 Jan 2023 02:13:39 +0000 (02:13 +0000)
hook.php
index.php
misc/strings.php [new file with mode: 0644]
tkl.php [new file with mode: 0644]
users.php

index 50254544087ca0301d0b43e7ff822034a49f36c6..97d06a1f957c2bff2d4a234ba7a88c231df7a62d 100644 (file)
--- a/hook.php
+++ b/hook.php
@@ -22,7 +22,7 @@ define('HOOKTYPE_NAVBAR', 100); /* The Hook for the navigation bar */
  * 
  * Example 3:
  * Calling the Hook using a static class method:
- * Hook::func(HOOKTYPE_NAVBAR, ['class_name', 'method']);
+ * Hook::func(HOOKTYPE_NAVBAR, 'classname::method');
  * 
  */
 class Hook {
index ef7c0d604d06c73725e8af8fd246c03d8b8c7104..28d71c011b40a4d2b879f16d37630dbf7f5b0fc6 100644 (file)
--- a/index.php
+++ b/index.php
   <a data-tab-target="#News" href="#News">News</a>
 </div> 
 <?php
+require_once "misc/strings.php";
 define('UPATH', dirname(__FILE__));
+
+define('RELATIVE_PATH', get_relative_path(UPATH));
 require_once "config.php";
 require_once UPATH . '/vendor/autoload.php';
 require_once "connection.php";
diff --git a/misc/strings.php b/misc/strings.php
new file mode 100644 (file)
index 0000000..9678bda
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+/** Splits up a string by a space
+ * (chr 32)
+ *
+ * Syntax:
+ * split($string)
+ * 
+ * Returns:
+ * array $tokens
+ */
+function split($str, $delimiter = " ") : Array
+{
+       return explode($delimiter,$str);
+}
+
+function glue($array, $delimiter = " ")
+{
+       $string = "";
+       foreach($array as $str)
+       {
+               if (!$str)
+                       continue;
+               $string .= $str.$delimiter;
+       }
+       return trim($string,$delimiter);
+}
+
+function get_relative_path($filename)
+{
+    $relativepath = split($filename, "/");
+    foreach($relativepath as &$tok)
+    {
+        $isFinal = ($tok == "html") ? 1 : 0;
+        $tok = NULL;
+        if ($isFinal)
+            break;
+    }
+    $relativepath = glue($relativepath,"/");
+    return $relativepath;
+}
\ No newline at end of file
diff --git a/tkl.php b/tkl.php
new file mode 100644 (file)
index 0000000..8227e91
--- /dev/null
+++ b/tkl.php
@@ -0,0 +1,178 @@
+<?php
+require_once "common.php";
+
+require_once "header.php";
+
+if (!empty($_POST))
+{
+
+       do_log($_POST);
+
+       if (!empty($_POST['tklch'])) // User has asked to delete these tkls
+       {
+               foreach ($_POST as $key => $value) {
+                       foreach ($value as $tok) {
+                               $tok = explode(",", $tok);
+                               $ban = base64_decode($tok[0]);
+                               $type = base64_decode($tok[1]);
+                               if ($rpc->serverban()->delete($ban, $type))
+                                       Message::Success("$type has been removed for $ban");
+                               else
+                                       Message::Fail("Unable to remove $type on $ban: $rpc->error");
+                       }
+               }
+       }
+       else if (!($iphost = $_POST['tkl_add']))
+                       Message::Fail("No user was specified");
+       else if (!($bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : false))
+       {
+               Message::Fail("Unable to add Server Ban: No ban type selected");
+       }
+       else /* It did */
+       {
+               
+               if ((
+                               $bantype == "gline" ||
+                               $bantype == "gzline" ||
+                               $bantype == "shun" ||
+                               $bantype == "eline"
+                       ) && strpos($iphost, "@") == false) // doesn't have full mask
+                       $iphost = "*@" . $iphost;
+
+               $soft = ($_POST['soft']) ? true : false;
+
+               if ($soft)
+                       $iphost = "%" . $iphost;
+               /* duplicate code for now [= */
+               $banlen_w = (isset($_POST['banlen_w'])) ? $_POST['banlen_w'] : NULL;
+               $banlen_d = (isset($_POST['banlen_d'])) ? $_POST['banlen_d'] : NULL;
+               $banlen_h = (isset($_POST['banlen_h'])) ? $_POST['banlen_h'] : NULL;
+               $duration = "";
+               if (!$banlen_d && !$banlen_h && !$banlen_w)
+                       $duration .= "0";
+               
+               else
+               {
+                       if ($banlen_w)
+                               $duration .= $banlen_w;
+                       if ($banlen_d)
+                               $duration .= $banlen_d;
+                       if ($banlen_h)
+                               $duration .= $banlen_h;
+               }
+               $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for ".rpc_convert_duration_string($duration);
+               $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason";
+               if ($rpc->serverban()->add($iphost, $bantype, $duration, $reason))
+               {
+                       Message::Success("Host / IP: $iphost has been $bantype" . "d $msg_msg: $reason");
+               }
+               else
+                       Message::Fail("The $bantype against \"$iphost\" could not be added: $rpc->error");
+       }
+}
+
+$tkl = $rpc->serverban()->getAll();
+?>
+<div class="tkl_add_boxheader">
+               Add Server Ban
+       </div>
+       <div class="tkl_add_form">
+               
+               <form action="tkl.php" method="post">
+                       <div class="align_label">IP / Host:</div><input class="input_text" type="text" id="tkl_add" name="tkl_add"><br>
+                       <div class="align_label">Ban Type:</div><select name="bantype" id="bantype">
+                               <option value=""></option>
+                               <optgroup label="Bans">
+                                       <option value="kline">Kill Line (KLine)</option>
+                                       <option value="gline">Global Kill Line (GLine)</option>
+                                       <option value="zline">Zap Line (ZLine)</option>
+                                       <option value="gzline">Global Zap Line (GZLine)</option>
+                                       
+                               </optgroup>
+                               <optgroup label="Restrictions">
+                                       <option value="local-qline">Reserve Nick Locally(QLine)</option>
+                                       <option value="qline">Reserve Nick Globally (QLine)</option>
+                                       <option value="shun">Shun</option>
+
+                               </optgroup>
+                               <optgroup label="Settings">
+                                       <option value="except">Global Exception (ELine)</option>
+                                       <option value="local-exception">Local Exception (ELine)</option>
+                               </optgroup>
+                       </select><br>
+                       <div class="align_label"><label for="banlen_w">Duration: </label></div>
+                                       <select name="banlen_w" id="banlen_w">
+                                                       <?php
+                                                       for ($i = 0; $i <= 56; $i++)
+                                                       {
+                                                               if (!$i)
+                                                                       echo "<option value=\"0w\"></option>";
+                                                               else
+                                                               {
+                                                                       $w = ($i == 1) ? "week" : "weeks";
+                                                                       echo "<option value=\"$i" . "w\">$i $w" . "</option>";
+                                                               }
+                                                       }
+                                                       ?>
+                                       </select>
+                                       <select name="banlen_d" id="banlen_d">
+                                                       <?php
+                                                       for ($i = 0; $i <= 31; $i++)
+                                                       {
+                                                               if (!$i)
+                                                                       echo "<option value=\"0d\"></option>";
+                                                               else
+                                                               {
+                                                                       $d = ($i == 1) ? "day" : "days";
+                                                                       echo "<option value=\"$i" . "d\">$i $d" . "</option>";
+                                                               }
+                                                       }
+                                                       ?>
+                                       </select>
+                                       <select name="banlen_h" id="banlen_h">
+                                                       <?php
+                                                       for ($i = 0; $i <= 24; $i++)
+                                                       {
+                                                               if (!$i)
+                                                                       echo "<option value=\"0d\"></option>";
+                                                               else
+                                                               {
+                                                                       $h = ($i == 1) ? "hour" : "hours";
+                                                                       echo "<option value=\"$i" . "h\">$i $h" . "</option>";
+                                                               }
+                                                       }
+                                                       ?>
+                                       </select>
+                                       <br><div class="align_label"><label for="ban_reason">Reason: </label></div>
+                                       <input class="input_text" type="text" id="ban_reason" name="ban_reason"><br>
+                                       <input class="input_text" type="checkbox" id="soft" name="soft">Don't affect logged-in users (soft)
+                                       <div class="align_right_button_tkl_add"><input class="cute_button" type="submit" id="submit" value="Submit"></div>
+               </form>
+       </div>
+       <table class='users_overview'>
+       <form action="" method="post">
+       <th><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" />Select all</th>
+       <th>Mask</th>
+       <th>Type</th>
+       <th>Set By</th>
+       <th>Set On</th>
+       <th>Expires</th>
+       <th>Duration</th>
+       <th>Reason</th>
+       
+       <?php
+               foreach($tkl as $tkl)
+               {
+                       echo "<tr>";
+                       echo "<td><input type=\"checkbox\" value='" . base64_encode($tkl->name).",".base64_encode($tkl->type) . "' name=\"tklch[]\"></td>";
+                       echo "<td>".$tkl->name."</td>";
+                       echo "<td>".$tkl->type_string."</td>";
+                       echo "<td>".$tkl->set_by."</td>";
+                       echo "<td>".$tkl->set_at_string."</td>";
+                       echo "<td>".$tkl->expire_at_string."</td>";
+                       echo "<td>".$tkl->duration_string."</td>";
+                       echo "<td>".$tkl->reason."</td>";
+               }
+       ?></table><p><input class="cute_button" type="submit" value="Delete selected"></p></form></div></div>
+
+<?php require_once 'footer.php'; ?>
index d27188036ce03efe6e753a82ba709eaea06b26ae..dbefa3d5e27e50a23e6c71c1a11fd1edced037e8 100644 (file)
--- a/users.php
+++ b/users.php
@@ -6,7 +6,7 @@ require_once "header.php";
 if (!empty($_POST))
 {
        do_log($_POST);
-
+       $bantype = $_POST['bantype'];
        if (isset($_POST['userch']))
        {
                foreach ($_POST["userch"] as $user)
@@ -62,7 +62,7 @@ $users = $rpc->user()->getAll();
        <table class='users_filter'>
        <th class="thuf">Filter by: </th>
        <th>
-               <form action="" method="post">
+               <form action="users.php" method="post">
                        Nick: <input name="uf_nick" id="uf_nick" type="text">
                        <input class="cute_button2" type="submit" value="Search">
                </form>