X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/2421056f724a011ee38a0249edb2802d4c7bd925..20d2aa3421da71c96892c926d3fafe39c0b66f16:/server-bans/index.php diff --git a/server-bans/index.php b/server-bans/index.php index 93baeba..cdb5bf7 100644 --- a/server-bans/index.php +++ b/server-bans/index.php @@ -5,7 +5,8 @@ require_once "../inc/header.php"; if (!empty($_POST)) { require_once "../inc/connection.php"; - if (isset($_POST['tklch']) && !empty($_POST['tklch'])) // User has asked to delete these tkls + + if (!empty($_POST['tklch'])) // User has asked to delete these tkls { if (!current_user_can(PERMISSION_SERVER_BAN_DEL)) { @@ -32,7 +33,7 @@ if (!empty($_POST)) } } } - elseif (isset($_POST['tkl_add']) && !empty($_POST['tkl_add'])) + elseif (isset($_POST['do_add_ban'])) { if (!current_user_can(PERMISSION_SERVER_BAN_ADD)) { @@ -40,58 +41,49 @@ if (!empty($_POST)) } else { - if (!($iphost = $_POST['tkl_add'])) - Message::Fail("No mask was specified"); - else if (!($bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : false)) + if (empty($_POST['ban_host']) || empty($_POST['ban_type'])) { - 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; + Message::Fail("Unable to add Server Ban: No host or ban type selected"); + } else + { + $ban_host = $_POST['ban_host']; + $ban_type = $_POST['ban_type']; + $ban_soft = empty($_POST['ban_soft']) ? false : true; + $ban_duration = $_POST['ban_duration'] ?? 0; + $ban_reason = $_POST['ban_reason'] ?? ''; + if (!str_contains($ban_host, "@")) + $ban_host = "*@$ban_host"; // prefix ban with *@ if no @ present + if ($ban_soft) + $ban_host = "%$ban_host"; // prefix ban with % if soft-ban + if ($rpc->serverban()->add($ban_host, $ban_type, $ban_duration, $ban_reason)) + { + Message::Success("Ban added on ".htmlspecialchars($ban_host)); + } else { + $success = false; + if (($rpc->errno == -1001) && !empty($_POST['edit_existing'])) + { + // existing one = del + add + // and yeah we do this after add() fails because then we now + // at least the syntax and fields and everything are OK. + // This so we don't accidentally remove a ban and the add fails + // causing the edit to result in a deletion. + $e = explode(":", $_POST['edit_existing'], 2); + if (count($e) == 2) + { + if ($rpc->serverban()->delete($e[1], $e[0])) + { + /* Good, now try the add operation */ + if ($rpc->serverban()->add($ban_host, $ban_type, $ban_duration, $ban_reason)) + { + Message::Success("Ban successfully modified: ".htmlspecialchars($ban_host)); + $success = true; + } + } + } + } + if (!$success) + Message::Fail("The ".htmlspecialchars($ban_type)." on ".htmlspecialchars($ban_host)." could not be added: $rpc->error / $rpc->errno"); } - $msg_msg = ($duration == "0" || $duration == "0w0d0h") ? "permanently" : "for " . rpc_convert_duration_string($duration); - $reason = (isset($_POST['ban_reason'])) ? $_POST['ban_reason'] : "No reason"; - if ($bantype == "qline") { - if ($rpc->nameban()->add($iphost, $reason, $duration)) - Message::Success("Name Ban set against \"$iphost\": $reason"); - else - Message::Fail("Name Ban could not be set against \"$iphost\": $rpc->error"); - } elseif ($bantype == "except") { - if ($rpc->serverbanexception()->add($iphost, "", $duration, $reason)) - Message::Success("Exception set for \"$iphost\": $reason"); - else - Message::Fail("Exception could not be set \"$iphost\": $rpc->error"); - } else 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"); } } } @@ -104,95 +96,70 @@ if (!empty($_POST)) ?>

Server Bans Overview

Here are all your network bans, from K-Lines to G-Lines, it's all here.

- -

-