<commit_before><?php
/**
 * =============================================================================
 * Banlist page
 *
 * @author SteamFriends Development Team
 * @version 1.0.0
 * @copyright SourceBans (C)2007 SteamFriends.com.  All rights reserved.
 * @package SourceBans
 * @link http://www.sourcebans.net
 *
 * @version $Id: page.banlist.php 292 2009-07-19 19:49:35Z peace-maker $
 * =============================================================================
 */
global $theme;
if(!defined("IN_SB")){echo "You should not be here. Only follow links!";die();}
$BansPerPage = SB_BANS_PER_PAGE;
$servers = array();
global $userbank;
function setPostKey()
{
	if(isset($_SERVER['REMOTE_IP']))
		$_SESSION['banlist_postkey'] = md5($_SERVER['REMOTE_IP'].time().rand(0,100000));
	else
		$_SESSION['banlist_postkey'] = md5(time().rand(0,100000));
}
if (!isset($_SESSION['banlist_postkey']) || strlen($_SESSION['banlist_postkey']) < 4)
	setPostKey();

$page = 1;
$pagelink = "";

PruneBans();

if (isset($_GET['page']) && $_GET['page'] > 0)
{
	$page = intval($_GET['page']);
	$pagelink = "&page=".$page;
}

if (isset($_GET['a']) && $_GET['a'] == "unban" && isset($_GET['id']))
{
	if ($_GET['key'] != $_SESSION['banlist_postkey'])
		die("Possible hacking attempt (URL Key mismatch)");
	//we have a multiple unban asking
	if(isset($_GET['bulk']))
		$bids = explode(",",$_GET['id']);
	else
		$bids = array($_GET['id']);
	$ucount = 0;
	$fail = 0;
	foreach($bids AS $bid) {
		$bid = intval($bid);
		$res = $GLOBALS['db']->Execute("SELECT a.aid, a.gid FROM `".DB_PREFIX."_bans` b INNER JOIN ".DB_PREFIX."_admins a ON a.aid = b.aid WHERE bid = '".$bid."';");
		if (!$userbank->HasAccess(ADMIN_OWNER|ADMIN_UNBAN) &&
		    !($userbank->HasAccess(ADMIN_UNBAN_OWN_BANS) && $res->fields['aid'] == $userbank->GetAid()) &&
		    !($userbank->HasAccess(ADMIN_UNBAN_GROUP_BANS) && $res->fields['gid'] == $userbank->GetProperty('gid')))
		{
			$fail++;
			if(!isset($_GET['bulk']))
				die("You don't have access to this");
			continue;
		}

		$row = $GLOBALS['db']->GetRow("SELECT b.ip, b.authid, 
										b.name, b.created, b.sid, b.type, m.steam_universe, UNIX_TIMESTAMP() as now
										FROM ".DB_PREFIX."_bans b
										LEFT JOIN ".DB_PREFIX."_servers s ON s.sid = b.sid
										LEFT JOIN ".DB_PREFIX."_mods m ON m.mid = s.modid
										WHERE b.bid = ? AND (b.length = '0' OR b.ends > UNIX_TIMESTAMP()) AND b.RemoveType IS NULL",array($bid));
		if(empty($row) || !$row) {
			$fail++;
			if(!isset($_GET['bulk'])) {
				echo "<script>ShowBox('Player Not Unbanned', 'The player was not unbanned, either already unbanned or not a valid ban.', 'red', 'index.php?p=banlist$pagelink');</script>";
				PageDie();
			}
			continue;
		}
		$unbanReason = htmlspecialchars(trim($_GET['ureason']));
		$ins = $GLOBALS['db']->Execute("UPDATE `".DB_PREFIX."_bans` SET
										`RemovedBy` = ?,
										`RemoveType` = 'U',
										`RemovedOn` = UNIX_TIMESTAMP(),
										`ureason` = ?
										WHERE `bid` = ?;",
										array( $userbank->GetAid(), $unbanReason, $bid));

		$protestsunban = $GLOBALS['db']->Execute("UPDATE `".DB_PREFIX."_protests` SET archiv = '4' WHERE bid = '".$bid."';");

		$blocked = $GLOBALS['db']->GetAll("SELECT s.sid, m.steam_universe FROM `".DB_PREFIX."_banlog` bl INNER JOIN ".DB_PREFIX."_servers s ON s.sid = bl.sid INNER JOIN ".DB_PREFIX."_mods m ON m.mid = s.modid WHERE bl.bid=? AND (UNIX_TIMESTAMP() - bl.time <= 300)",array($bid));
		foreach($blocked as $tempban)
		{
			SendRconSilent(($row['type']==0?"removeid STEAM_" . $tempban['steam_universe'] . substr($row['authid'], 6):"removeip ".$row['ip']), $tempban['sid']);
		}
		if(((int)$row['now'] - (int)$row['created']) <= 300 && $row['sid'] != "0" && !in_array_dim($row['sid'], $blocked))
			SendRconSilent(($row['type']==0?"removeid STEAM_" . $row['steam_universe'] . substr($row['authid'], 6):"removeip ".$row['ip']), $row['sid']);

		if($res){
			if(!isset($_GET['bulk']))
				echo "<script>ShowBox('Player Unbanned', '".StripQuotes($row['name'])." (" . ($row['type']==0?$row['authid']:$row['ip']) . ") has been unbanned from SourceBans.', 'green', 'index.php?p=banlist$pagelink');</script>";
			$log = new CSystemLog("m", "Player Unbanned", "'".StripQuotes($row['name'])."' (" . ($row['type']==0?$row['authid']:$row['ip']) . ") has been unbanned");
			$ucount++;
		}else{
			if(!isset($_GET['bulk']))
				echo "<script>ShowBox('Player NOT Unbanned', 'There was an error unbanning ".StripQuotes($row['name'])."', 'red', 'index.php?p=banlist$pagelink', true);</script>";
			$fail++;
		}
	}
	if(isset($_GET['bulk']))
		echo "<script>ShowBox('Players Unbanned', '$ucount players has been unbanned from SourceBans.<br>$fail failed.', 'green', 'index.php?p=banlist$pagelink');</script>";
}
else if(isset($_GET['a']) && $_GET['a'] == "delete")
{
	if ($_GET['key'] != $_SESSION['banlist_postkey'])
		die("Possible hacking attempt (URL Key mismatch)");

	if (!$userbank->HasAccess(ADMIN_OWNER|ADMIN_DELETE_BAN))
	{
		echo "<script>ShowBox('Error', 'You do not have access to this.', 'red', 'index.php?p=banlist$pagelink');</script>";
		PageDie();
	}
	//we have a multiple ban delete asking
	if(isset($_GET['bulk']))
		$bids = explode(",",$_GET['id']);
	else
		$bids = array($_GET['id']);
	$dcount = 0;
	$fail = 0;
	foreach($bids AS $bid) {
		$bid = intval($bid);
		$demres = $GLOBALS['db']->Execute("SELECT filename FROM `".DB_PREFIX."_demos` WHERE `demid` = ?",
									array( $bid ));
		@unlink(SB_DEMOS."/".$demres->fields["filename"]);
		$blocked = $GLOBALS['db']->GetAll("SELECT s.sid, m.steam_universe FROM `".DB_PREFIX."_banlog` bl INNER JOIN ".DB_PREFIX."_servers s ON s.sid = bl.sid INNER JOIN ".DB_PREFIX."_mods m ON m.mid = s.modid WHERE bl.bid=? AND (UNIX_TIMESTAMP() - bl.time <= 300)",array($bid));
		$steam = $GLOBALS['db']->GetRow("SELECT b.name, b.authid, b.created, b.sid, b.RemoveType, b.ip, b.type, m.steam_universe, UNIX_TIMESTAMP() AS now
										FROM ".DB_PREFIX."_bans b 
										LEFT JOIN ".DB_PREFIX."_servers s ON s.sid = b.sid
										LEFT JOIN ".DB_PREFIX."_mods m ON m.mid = s.modid 
										WHERE b.bid=?",array($bid));
		$block = $GLOBALS['db']->Execute("DELETE FROM `".DB_PREFIX."_banlog` WHERE bid = ?",array($bid));
		$res = $GLOBALS['db']->Execute("DELETE FROM `".DB_PREFIX."_bans` WHERE `bid` = ?",
									array( $bid ));
		if(empty($steam['RemoveType']))
		{
			foreach($blocked as $tempban)
			{
				SendRconSilent(($steam['type']==0?"removeid STEAM_" . $tempban['steam_universe'] . substr($steam['authid'], 6):"removeip ".$steam['ip']), $tempban['sid']);
			}
			if(((int)$steam['now'] - (int)$steam['created']) <= 300 && $steam['sid'] != "0" && !in_array_dim($steam['sid'], $blocked))
				SendRconSilent(($steam['type']==0?"removeid STEAM_" . $steam['steam_universe'] . substr($steam['authid'], 6):"removeip ".$steam['ip']), $steam['sid']);
		}

		if($res){
			if(!isset($_GET['bulk']))
				echo "<script>ShowBox('Ban Deleted', 'The ban for \'".StripQuotes($steam['name'])."\' (".($steam['type']==0?$steam['authid']:$steam['ip']).") has been deleted from SourceBans', 'green', 'index.php?p=banlist$pagelink');</script>";
			$log = new CSystemLog("m", "Ban Deleted", "Ban '".StripQuotes($steam['name'])."' (" . ($steam['type']==0?$steam['authid']:$steam['ip']) . ") has been deleted.");<commit_msg>* Fixed stripping incorrect number of chars from steamid on unban rcon. (Only removed STEAM_ instead of STEAM_X) (refs #1595)<commit_after><?php
/**
 * =============================================================================
 * Banlist page
 *
 * @author SteamFriends Development Team
 * @version 1.0.0
 * @copyright SourceBans (C)2007 SteamFriends.com.  All rights reserved.
 * @package SourceBans
 * @link http://www.sourcebans.net
 *
 * @version $Id: page.banlist.php 292 2009-07-19 19:49:35Z peace-maker $
 * =============================================================================
 */
global $theme;
if(!defined("IN_SB")){echo "You should not be here. Only follow links!";die();}
$BansPerPage = SB_BANS_PER_PAGE;
$servers = array();
global $userbank;
function setPostKey()
{
	if(isset($_SERVER['REMOTE_IP']))
		$_SESSION['banlist_postkey'] = md5($_SERVER['REMOTE_IP'].time().rand(0,100000));
	else
		$_SESSION['banlist_postkey'] = md5(time().rand(0,100000));
}
if (!isset($_SESSION['banlist_postkey']) || strlen($_SESSION['banlist_postkey']) < 4)
	setPostKey();

$page = 1;
$pagelink = "";

PruneBans();

if (isset($_GET['page']) && $_GET['page'] > 0)
{
	$page = intval($_GET['page']);
	$pagelink = "&page=".$page;
}

if (isset($_GET['a']) && $_GET['a'] == "unban" && isset($_GET['id']))
{
	if ($_GET['key'] != $_SESSION['banlist_postkey'])
		die("Possible hacking attempt (URL Key mismatch)");
	//we have a multiple unban asking
	if(isset($_GET['bulk']))
		$bids = explode(",",$_GET['id']);
	else
		$bids = array($_GET['id']);
	$ucount = 0;
	$fail = 0;
	foreach($bids AS $bid) {
		$bid = intval($bid);
		$res = $GLOBALS['db']->Execute("SELECT a.aid, a.gid FROM `".DB_PREFIX."_bans` b INNER JOIN ".DB_PREFIX."_admins a ON a.aid = b.aid WHERE bid = '".$bid."';");
		if (!$userbank->HasAccess(ADMIN_OWNER|ADMIN_UNBAN) &&
		    !($userbank->HasAccess(ADMIN_UNBAN_OWN_BANS) && $res->fields['aid'] == $userbank->GetAid()) &&
		    !($userbank->HasAccess(ADMIN_UNBAN_GROUP_BANS) && $res->fields['gid'] == $userbank->GetProperty('gid')))
		{
			$fail++;
			if(!isset($_GET['bulk']))
				die("You don't have access to this");
			continue;
		}

		$row = $GLOBALS['db']->GetRow("SELECT b.ip, b.authid, 
										b.name, b.created, b.sid, b.type, m.steam_universe, UNIX_TIMESTAMP() as now
										FROM ".DB_PREFIX."_bans b
										LEFT JOIN ".DB_PREFIX."_servers s ON s.sid = b.sid
										LEFT JOIN ".DB_PREFIX."_mods m ON m.mid = s.modid
										WHERE b.bid = ? AND (b.length = '0' OR b.ends > UNIX_TIMESTAMP()) AND b.RemoveType IS NULL",array($bid));
		if(empty($row) || !$row) {
			$fail++;
			if(!isset($_GET['bulk'])) {
				echo "<script>ShowBox('Player Not Unbanned', 'The player was not unbanned, either already unbanned or not a valid ban.', 'red', 'index.php?p=banlist$pagelink');</script>";
				PageDie();
			}
			continue;
		}
		$unbanReason = htmlspecialchars(trim($_GET['ureason']));
		$ins = $GLOBALS['db']->Execute("UPDATE `".DB_PREFIX."_bans` SET
										`RemovedBy` = ?,
										`RemoveType` = 'U',
										`RemovedOn` = UNIX_TIMESTAMP(),
										`ureason` = ?
										WHERE `bid` = ?;",
										array( $userbank->GetAid(), $unbanReason, $bid));

		$protestsunban = $GLOBALS['db']->Execute("UPDATE `".DB_PREFIX."_protests` SET archiv = '4' WHERE bid = '".$bid."';");

		$blocked = $GLOBALS['db']->GetAll("SELECT s.sid, m.steam_universe FROM `".DB_PREFIX."_banlog` bl INNER JOIN ".DB_PREFIX."_servers s ON s.sid = bl.sid INNER JOIN ".DB_PREFIX."_mods m ON m.mid = s.modid WHERE bl.bid=? AND (UNIX_TIMESTAMP() - bl.time <= 300)",array($bid));
		foreach($blocked as $tempban)
		{
			SendRconSilent(($row['type']==0?"removeid STEAM_" . $tempban['steam_universe'] . substr($row['authid'], 7):"removeip ".$row['ip']), $tempban['sid']);
		}
		if(((int)$row['now'] - (int)$row['created']) <= 300 && $row['sid'] != "0" && !in_array_dim($row['sid'], $blocked))
			SendRconSilent(($row['type']==0?"removeid STEAM_" . $row['steam_universe'] . substr($row['authid'], 7):"removeip ".$row['ip']), $row['sid']);

		if($res){
			if(!isset($_GET['bulk']))
				echo "<script>ShowBox('Player Unbanned', '".StripQuotes($row['name'])." (" . ($row['type']==0?$row['authid']:$row['ip']) . ") has been unbanned from SourceBans.', 'green', 'index.php?p=banlist$pagelink');</script>";
			$log = new CSystemLog("m", "Player Unbanned", "'".StripQuotes($row['name'])."' (" . ($row['type']==0?$row['authid']:$row['ip']) . ") has been unbanned");
			$ucount++;
		}else{
			if(!isset($_GET['bulk']))
				echo "<script>ShowBox('Player NOT Unbanned', 'There was an error unbanning ".StripQuotes($row['name'])."', 'red', 'index.php?p=banlist$pagelink', true);</script>";
			$fail++;
		}
	}
	if(isset($_GET['bulk']))
		echo "<script>ShowBox('Players Unbanned', '$ucount players has been unbanned from SourceBans.<br>$fail failed.', 'green', 'index.php?p=banlist$pagelink');</script>";
}
else if(isset($_GET['a']) && $_GET['a'] == "delete")
{
	if ($_GET['key'] != $_SESSION['banlist_postkey'])
		die("Possible hacking attempt (URL Key mismatch)");

	if (!$userbank->HasAccess(ADMIN_OWNER|ADMIN_DELETE_BAN))
	{
		echo "<script>ShowBox('Error', 'You do not have access to this.', 'red', 'index.php?p=banlist$pagelink');</script>";
		PageDie();
	}
	//we have a multiple ban delete asking
	if(isset($_GET['bulk']))
		$bids = explode(",",$_GET['id']);
	else
		$bids = array($_GET['id']);
	$dcount = 0;
	$fail = 0;
	foreach($bids AS $bid) {
		$bid = intval($bid);
		$demres = $GLOBALS['db']->Execute("SELECT filename FROM `".DB_PREFIX."_demos` WHERE `demid` = ?",
									array( $bid ));
		@unlink(SB_DEMOS."/".$demres->fields["filename"]);
		$blocked = $GLOBALS['db']->GetAll("SELECT s.sid, m.steam_universe FROM `".DB_PREFIX."_banlog` bl INNER JOIN ".DB_PREFIX."_servers s ON s.sid = bl.sid INNER JOIN ".DB_PREFIX."_mods m ON m.mid = s.modid WHERE bl.bid=? AND (UNIX_TIMESTAMP() - bl.time <= 300)",array($bid));
		$steam = $GLOBALS['db']->GetRow("SELECT b.name, b.authid, b.created, b.sid, b.RemoveType, b.ip, b.type, m.steam_universe, UNIX_TIMESTAMP() AS now
										FROM ".DB_PREFIX."_bans b 
										LEFT JOIN ".DB_PREFIX."_servers s ON s.sid = b.sid
										LEFT JOIN ".DB_PREFIX."_mods m ON m.mid = s.modid 
										WHERE b.bid=?",array($bid));
		$block = $GLOBALS['db']->Execute("DELETE FROM `".DB_PREFIX."_banlog` WHERE bid = ?",array($bid));
		$res = $GLOBALS['db']->Execute("DELETE FROM `".DB_PREFIX."_bans` WHERE `bid` = ?",
									array( $bid ));
		if(empty($steam['RemoveType']))
		{
			foreach($blocked as $tempban)
			{
				SendRconSilent(($steam['type']==0?"removeid STEAM_" . $tempban['steam_universe'] . substr($steam['authid'], 7):"removeip ".$steam['ip']), $tempban['sid']);
			}
			if(((int)$steam['now'] - (int)$steam['created']) <= 300 && $steam['sid'] != "0" && !in_array_dim($steam['sid'], $blocked))
				SendRconSilent(($steam['type']==0?"removeid STEAM_" . $steam['steam_universe'] . substr($steam['authid'], 7):"removeip ".$steam['ip']), $steam['sid']);
		}

		if($res){
			if(!isset($_GET['bulk']))
				echo "<script>ShowBox('Ban Deleted', 'The ban for \'".StripQuotes($steam['name'])."\' (".($steam['type']==0?$steam['authid']:$steam['ip']).") has been deleted from SourceBans', 'green', 'index.php?p=banlist$pagelink');</script>";
			$log = new CSystemLog("m", "Ban Deleted", "Ban '".StripQuotes($steam['name'])."' (" . ($steam['type']==0?$steam['authid']:$steam['ip']) . ") has been deleted.");
{'fraction_non_alphanumeric': 0.2528790136837827, 'fraction_numerical': 0.010432190760059613, 'mean_word_length': 4.746594005449591, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6418487', 'n_tokens_mistral': 6143, 'n_tokens_neox': 5413, 'n_words': 1064}