+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";
+require_once "Classes/class-log.php";
+require_once "Classes/class-message.php";
+require_once "Classes/class-rpc.php";
+
+do_log($_POST);
+
+if (!empty($_POST)) {
+
+ if ($sf = $_POST['sf_add']) // if it was a spamfilter entry
+ {
+ /* get targets */
+ $targets = []; // empty arrae
+ foreach($_POST as $key => $value)
+ {
+ if (substr($key, 0, 7) == "target_")
+ $targets[] = str_replace(["target_", "_"], ["", "-"], $key);
+ }
+ if (empty($targets))
+ Message::Fail("No target was specified");
+
+ if (!isset($_POST['sf_bantype']))
+ Message::Fail("No action was chosen");
+
+ else
+ {
+
+ $bantype = $_POST['sf_bantype'];
+ $targ_chars = "";
+ foreach($targets as $targ)
+ {
+ switch ($targ) {
+ case "channel":
+ $targ_chars .= "c";
+ break;
+ case "private":
+ $targ_chars .= "p";
+ break;
+ case "channel-notice":
+ $targ_chars .= "N";
+ break;
+ case "private-notice":
+ $targ_chars .= "n";
+ break;
+ case "part":
+ $targ_chars .= "P";
+ break;
+ case "quit":
+ $targ_chars .= "q";
+ break;
+ case "dcc":
+ $targ_chars .= "d";
+ break;
+ case "away":
+ $targ_chars .= "a";
+ break;
+ case "topic":
+ $targ_chars .= "t";
+ break;
+ case "messagetag":
+ $targ_chars .= "T";
+ break;
+ case "user":
+ $targ_chars .= "u";
+ break;
+ }
+ }
+ /* 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;
+ }
+ $match_type = $_POST['matchtype']; // should default to 'simple'
+ $reason = isset($_POST['ban_reason']) ? $_POST['ban_reason'] : "No reason";
+ $soft = (isset($_POST['soft'])) ? true : false;
+ if ($soft)
+ $targ_chars = "%" . $targ_chars;
+ if ($rpc->spamfilter()->add($sf, $match_type, $targ_chars, $bantype, $duration, $reason))
+ Message::Success("Added spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]");
+ else
+ Message::Fail("Could not add spamfilter entry \"$sf\" [match type: $match_type] [targets: $targ_chars] [reason: $reason]: $rpc->error");
+ }
+
+ }
+
+ else if (!($bantype = $_POST['bantype'])) // if it was a ban entry
+ {
+ }
+ else if (!($users = $_POST["userch"]))
+ {
+ /* check if this came from our Server Bans tab. */
+ if (!($iphost = $_POST['tkl_add']))
+ Message::Fail("No user was specified");
+
+ 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");
+ }
+ }
+ else /* It came from the Users tab */
+ {
+ foreach ($_POST["userch"] as $user)
+ {
+ $user = base64_decode($user);
+ $bantype = (isset($_POST['bantype'])) ? $_POST['bantype'] : NULL;
+ if (!$bantype) /* shouldn't happen? */
+ {
+ Message::Fail("An error occured");
+ return;
+ }
+ $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;
+ }
+
+ $nick = $rpc->user()->get($user);
+ if (!$nick)
+ {
+ Message::Fail("Could not find that user. Maybe they disconnected after you clicked this?");
+ return;
+ }
+
+ $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($user, $bantype, $duration, $reason))
+ {
+ $c = $nick->client;
+ Message::Success($c->name . " (*@".$c->hostname.") has been $bantype" . "d $msg_msg: $reason");
+ }
+ }
+ }
+
+ if (!empty($_POST['tklch']))
+ 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");
+ }
+ }
+
+ if (!empty($_POST['sf']))
+ foreach ($_POST as $key => $value) {
+ foreach ($value as $tok) {
+ $tok = explode(",", $tok);
+ $name = base64_decode($tok[0]);
+ $match_type = base64_decode($tok[1]);
+ $spamfilter_targets = base64_decode($tok[2]);
+ $ban_action = base64_decode($tok[3]);
+ if ($rpc->spamfilter()->delete($name, $match_type, $spamfilter_targets, $ban_action))
+ Message::Success("Spamfilter on $name has been removed");
+ else
+ Message::Fail("Unable to remove spamfilter on $name: $rpc->error");
+ }
+ }
+}
+
+rpc_pop_lists();