X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/33f512fa30c06fa488c42e68f9bc9f401300a5ab..20d2aa3421da71c96892c926d3fafe39c0b66f16:/server-bans/index.php diff --git a/server-bans/index.php b/server-bans/index.php index f379571..cdb5bf7 100644 --- a/server-bans/index.php +++ b/server-bans/index.php @@ -1,18 +1,20 @@ $value) { - foreach ($value as $tok) { - $tok = explode(",", $tok); + if (!current_user_can(PERMISSION_SERVER_BAN_DEL)) + { + Message::Fail("Could not delete: Permission denied"); + } + else { + foreach ($_POST['tklch'] as $key => $value) { + $tok = explode(",", $value); $ban = base64_decode($tok[0]); $type = base64_decode($tok[1]); $success = false; @@ -31,60 +33,58 @@ if (!empty($_POST)) } } } - elseif (isset($_POST['tkl_add']) && !empty($_POST['tkl_add'])) + elseif (isset($_POST['do_add_ban'])) { - if (!($iphost = $_POST['tkl_add'])) - Message::Fail("No mask was specified"); - else if (!($bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : false)) + if (!current_user_can(PERMISSION_SERVER_BAN_ADD)) { - 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 ($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"); + Message::Fail("Could not add: Permission denied"); + } + else + { + if (empty($_POST['ban_host']) || empty($_POST['ban_type'])) + { + Message::Fail("Unable to add Server Ban: No host or ban type selected"); } else - Message::Fail("The $bantype against \"$iphost\" could not be added: $rpc->error"); + { + $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"); + } + } } } elseif (isset($_POST['search_types']) && !empty($_POST['search_types'])) @@ -93,139 +93,86 @@ if (!empty($_POST)) } } -$tkl = $rpc->serverban()->getAll(); -foreach ($rpc->serverbanexception()->getAll() as $v) - $tkl[] = $v; ?>

Server Bans Overview

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

-

- - + + +