Explorar o código

Migrated from sf.net

DieFeM %!s(int64=9) %!d(string=hai) anos
achega
46b0f70c91

+ 108 - 0
modules/util/ma_admin.php

@@ -0,0 +1,108 @@
+<table style="background-color:white;color:blue; margin-left:auto;margin-right:auto">
+<tr>
+<td>
+<?php 
+global $db;
+
+$isAdmin = $db->isAdmin( $_SESSION['user_id'] );
+
+if ( $isAdmin )
+		$server_homes = $db->getIpPorts();
+	else
+		$server_homes = $db->getIpPortsForUser($_SESSION['user_id']);
+		
+$supported_games = array( "Counter Strike Global Offensive",
+						  "Counter Strike Source",
+						  "Day of Defeat: Source",
+						  "Half-Life 2: Deathmatch",
+						  "Team Fortress 2",
+						  "Team Fortress 2 Beta" );
+
+$i = 0;		
+foreach ($server_homes as $server_home)
+{
+	if ( in_array( $server_home['game_name'], $supported_games ) )
+		$ma_admin_server_homes[$i] = $server_home;
+	$i++;
+}
+
+if( isset( $_GET['sm_admin']) )
+	unset( $_GET['home_id-mod_id-ip-port'] );
+create_home_selector_address("util","",$ma_admin_server_homes);
+?>
+</td>
+</tr>
+<?php
+if ( empty( $_GET['home_id-mod_id-ip-port'] ) )
+	 unset( $_GET['home_id-mod_id-ip-port'] );
+if( isset( $_GET['home_id-mod_id-ip-port']) and !isset( $_GET['sm_admin']) )
+{
+	$pieces = explode( "-", $_GET['home_id-mod_id-ip-port'] );
+	$post_home_id = $pieces[0];
+	$post_mod_id = $pieces[1];
+	$ip = $pieces[2];
+	$port = $pieces[3];
+
+	if (isset($_POST['mani']))
+	{
+		if($_POST['asteamid'] == "" or $_POST['aname'] == "")
+		{
+			if($_POST['steamid'] == "")
+				print_failure('A steam_id is needed!');
+			if($_POST['aname'] == "")
+				print_failure('A nickname is needed!');
+		}
+		else
+		{
+			if($isAdmin) 
+				$server_home = $db->getGameHome($post_home_id);
+			else
+				$server_home = $db->getUserGameHome($_SESSION['user_id'],$post_home_id);
+			
+			$asteamid = '"'.$_POST['asteamid'].'"';
+			$rcommand = 'ma_client addclient '.$_POST['aname'].'; ma_client addsteam '.$_POST['aname'].' '.$asteamid.'; ma_client setaflag '.$_POST['aname'].' +#';
+			require_once('includes/lib_remote.php');
+			$remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
+			
+			$remote_retval = $remote->remote_send_rcon_command( $server_home['home_id'], $ip, $port, 'rcon2', $server_home['control_password'],'',$rcommand,$return);
+			if ( $remote_retval === -1 )
+			{
+				print_failure("Failed adding admin, the server may be down or the agent is offline.");
+			}
+			elseif ( $remote_retval === 1 )
+			{
+				if( preg_match('/Unknown command "ma_client"/i',$return) )
+					print_failure("Mani Admin Plugin is not properly installed in your server, the error was:<br><xmp>Unknown command \"ma_client\"</xmp>");
+				else
+					print_success("Admin added successfully.");
+			}
+			elseif ( $remote_retval === -10 )
+			{
+				print_failure("You must set the control password (rcon password) in order to add admins.");
+			}
+		}
+	}
+?>
+<tr>
+<td>
+<form action="" method="post">
+NickName
+<input type="text" name="aname" value="<?php echo (isset($_POST['aname']) and $_POST['aname'] != "") ? $_POST['aname'] : "";?>"/>
+</td>
+</tr>
+<tr>
+<td>
+Steam_ID
+<input type="text" name="asteamid" value="<?php echo (isset($_POST['asteamid']) and $_POST['asteamid'] != "") ? $_POST['asteamid'] : "";?>"/>
+</td>
+</tr>
+<tr>
+<td>
+<input name="mani" value="ADD ADMIN" type="submit"/>
+</form>
+</td>
+</tr>
+<?php
+}
+?>
+</table>

+ 32 - 0
modules/util/module.php

@@ -0,0 +1,32 @@
+<?php
+/*
+ *
+ * OGP - Open Game Panel
+ * Copyright (C) Copyright (C) 2008 - 2012 The OGP Development Team
+ *
+ * http://www.opengamepanel.org/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+
+// Module general information
+$module_title = "Util";
+$module_version = "1.0";
+$db_version = 0;
+$module_required = TRUE;
+$module_menus = array( array( 'subpage' => '', 'name'=>'Util', 'group'=>'user' ) );
+?>
+

+ 54 - 0
modules/util/ping.php

@@ -0,0 +1,54 @@
+<?php
+create_home_selector("util","",$server_homes); 
+if( isset( $_GET['home_id']) )
+{
+	
+	if ( isset($_SERVER["REMOTE_ADDR"]) )
+	{
+		$client_ip = $_SERVER["REMOTE_ADDR"];
+	}
+	elseif ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )
+	{
+		$client_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
+	} 
+	elseif( isset($_SERVER["HTTP_CLIENT_IP"]) )
+	{
+		$client_ip = $_SERVER["HTTP_CLIENT_IP"]; 
+	}
+	?>
+	<form method="post" action="">
+	<input name="ping" type="submit" value="PING SERVER" />
+	</form>
+	<?php 
+	if(isset($_POST['ping']))
+	{
+		$ip = $client_ip;
+		
+		if(!empty($ip)) 
+		{
+			$ping = "";
+			$home_info = $db->getGameHomeWithoutMods($server_home['home_id']);
+			require_once('includes/lib_remote.php');
+			$remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
+			$os = $remote->what_os();
+			if(preg_match("/CYGWIN/",$os)) 
+			{
+				$exec = $remote->exec("ping -n 1 -l 64 ".$ip);
+				$ping = end(explode(" ", $exec ));
+			}
+			else 
+			{
+				$exec = $remote->exec("ping -c 1 -s 64 -t 64 ".$ip);
+				$array = explode("/", end(explode("=", $exec )) );
+				$ping = ceil($array[1]) . 'ms';
+			}
+		}
+		?><p style="color:blue;text-align:center;">Server IP: <?php 
+		echo $server_home['agent_ip'];
+		echo " --> ".$ping." --> ";
+		?>Your IP: <?php 
+		echo $ip;
+		?></p><?php 
+	}
+}
+?>

+ 195 - 0
modules/util/sm_admin.php

@@ -0,0 +1,195 @@
+<table style="background-color:white;color:blue; margin-left:auto;margin-right:auto">
+<tr>
+<td>
+<?php 
+global $db;
+
+$isAdmin = $db->isAdmin( $_SESSION['user_id'] );
+
+if ( $isAdmin )
+		$server_homes = $db->getIpPorts();
+	else
+		$server_homes = $db->getIpPortsForUser($_SESSION['user_id']);
+		
+$supported_games = array( "Counter Strike Global Offensive",
+						  "Counter Strike Source",
+						  "Day of Defeat: Source",
+						  "Dystopia",
+						  "Garrys Mod",
+						  "Half-Life 2: Deathmatch",
+						  "Hidden: Source",
+						  "Pirates, Vikings and Knights II",
+						  "Team Fortress 2",
+						  "Team Fortress 2 Beta",
+						  "Left 4 Dead",
+						  "Left 4 Dead 2" );
+
+
+$admin_flags = array( "a" => "Reserved slot access.",
+					  "b" => "Generic admin; required for admins.",
+					  "c" => "Kick other players.",
+					  "d" => "Ban other players.",
+					  "e" => "Remove bans.",
+					  "f" => "Slay/harm other players.",
+					  "g" => "Change the map or major gameplay features.",
+					  "h" => "Change most cvars.",
+					  "i" => "Execute config files.",
+					  "j" => "Special chat privileges.",
+					  "k" => "Start or create votes.",
+					  "l" => "Set a password on the server.",
+					  "m" => "Use RCON commands.",
+					  "n" => "Change sv_cheats or use cheating commands." );
+
+$i = 0;		
+foreach ($server_homes as $server_home)
+{
+	if ( in_array( $server_home['game_name'], $supported_games ) )
+		$sm_admin_server_homes[$i] = $server_home;
+	$i++;
+}
+if( !isset( $_GET['sm_admin']) )
+{
+	$select = $_GET['home_id-mod_id-ip-port'];
+	unset( $_GET['home_id-mod_id-ip-port'] );
+}
+create_home_selector_address("util","",$sm_admin_server_homes);
+
+?>
+<script type="text/javascript">
+var theForm = document.forms['select'];
+var input = document.createElement('input');
+    input.type = 'hidden';
+    input.name = 'sm_admin';
+    theForm.appendChild(input);
+</script>
+</td>
+</tr>
+<?php
+if ( empty( $_GET['home_id-mod_id-ip-port'] ) )
+	 unset( $_GET['home_id-mod_id-ip-port'] );
+if( isset( $_GET['home_id-mod_id-ip-port'] ) and isset( $_GET['sm_admin'] ) )
+{
+	$pieces = explode( "-", $_GET['home_id-mod_id-ip-port'] );
+	$home_id = $pieces[0];
+	$mod_id = $pieces[1];
+	$ip = $pieces[2];
+	$port = $pieces[3];
+		
+	if($isAdmin) 
+		$server_home = $db->getGameHome($home_id);
+	else
+		$server_home = $db->getUserGameHome($_SESSION['user_id'],$home_id);
+
+	$_SESSION['inmunityLvl'] = $_POST['ainmunity'];
+	if(isset($_POST['sm_admin']))
+	{
+		if($_POST['asteamid'])
+			print_failure('A steam_id is needed!');
+		
+		$flagsStr = "";
+		foreach($_POST as $key => $val)
+		{
+			if(preg_match('/flag_/',$key))
+				$flagsStr .= $val;
+		}
+		$inmunityLvl = $_POST['ainmunity'] != '0' ? $_POST['ainmunity'].':' : "";
+		if($_POST['steamid'] == "" or $flagsStr == "")
+		{
+			if($_POST['steamid'] == "")
+				print_failure('A steam_id is needed!');
+			if($flagsStr == "")
+				print_failure('Must select at least 1 flag!');
+		}
+		else
+		{
+			$admins_simple_location = $server_home['home_path']."/".$server_home['mods'][$mod_id]['mod_key']."/addons/sourcemod/configs/admins_simple.ini";
+			require_once('includes/lib_remote.php');
+			$remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
+			if($remote->rfile_exists($admins_simple_location) != 1)
+				print_failure("SourceMod is not properly installed in your server,<br>/".$server_home['mods'][$mod_id]['mod_key']."/addons/sourcemod/configs/admins_simple.ini does not exist!");
+			else
+			{
+				$remote->remote_readfile($admins_simple_location,$file_content);
+				
+				$replace = FALSE;
+				if(preg_match("/".$_POST['steamid']."/i",$file_content))
+					$replace = TRUE;
+					
+				if($replace)
+					$file_content = preg_replace("/.*".$_POST['steamid'].".*/i","\"".$_POST['steamid']."\"\t\t\"$inmunityLvl$flagsStr\"",$file_content);
+				else
+					$file_content .= "\n\"".$_POST['steamid']."\"\t\t\"$inmunityLvl$flagsStr\"";
+				
+				$remote->remote_writefile($admins_simple_location, $file_content);
+				print_success("Admin added/changed successfully at admins_simple.ini");
+				$remote_retval = $remote->remote_send_rcon_command( $server_home['home_id'], $ip, $port, 'rcon2', $server_home['control_password'],'',"sm_reloadadmins",$return);
+				if ( $remote_retval === -1 )
+				{
+					print_failure("Failed to reload admins, the server may be down or the agent is offline.");
+				}
+				elseif ( $remote_retval === 1 )
+				{
+					if( preg_match('/Admin cache has been refreshed/i',$return) )
+						print_success("Admin cache has been refreshed.");
+					else
+						print_failure("SourceMod is not properly installed in your server, the error was:<br><xmp>".$return."</xmp>");
+				}
+				elseif ( $remote_retval === -10 )
+				{
+					print_failure("You must set the control password (rcon password)<br>in order to reload admins without restarting the server,<br>the new admin will be loaded once the server is restarted.");
+				}
+			}
+		}
+	}
+?>
+<tr>
+<td>
+<form action="" method="post">
+<tr>
+<td>
+Steam_ID
+<input type="text" name="steamid" value="<?php echo (isset($_POST['steamid']) and $_POST['steamid'] != "") ? $_POST['steamid'] : "";?>" />
+</td>
+</tr>
+<tr>
+<td>
+Inmunity level
+<input type="number" name="ainmunity" min="0" max="99" value="<?php echo isset($_SESSION['inmunityLvl']) ? $_SESSION['inmunityLvl'] : "99";?>"/><br>
+<em>Every admin can have an arbitrary immunity value assigned to them.</em>
+<br>
+<em>Whether an admin can target another admin depends on who has a higher immunity value.</em>
+</td>
+</tr>
+<tr>
+<td>
+Admin Flags
+<?php
+$selected = ( isset( $_POST['flags'] ) and $_POST['flags'] == "custom" ) ? "selected='selected'" : "";
+echo "<select name='flags' onchange='this.form.submit();'>\n".
+	 "<option value='z' >Root Admin</option>\n".
+	 "<option value='custom' $selected>Customize Flags</option>\n".
+	 "</select>\n<br>\n";
+if( isset( $_POST['flags'] ) and $_POST['flags'] == "custom" )
+{
+	foreach($admin_flags as $flag => $desc )
+	{
+		echo "<input type='checkbox' name='flag_$flag' value='$flag' />$desc\n<br>\n";
+	}
+}
+else
+	echo "<input type='hidden' name='flag_z' value='z' />";
+?>
+</td>
+</tr>
+<tr>
+<td>
+<input name="sm_admin" value="ADD ADMIN" type="submit"/>
+</form>
+</td>
+</tr>
+<?php
+}
+else
+	$_GET['home_id-mod_id-ip-port'] = $select;
+?>
+</table>

+ 105 - 0
modules/util/steamid_converter.php

@@ -0,0 +1,105 @@
+<?php /*
+SteamID conversion tool by 8088 & KoST
+For more info, visit AlliedModders @ http://forums.alliedmods.net/showthread.php?t=60899
+*/
+?>
+<form method="get" action="">
+	<div >
+		<fieldset style="color:white;background-color:DarkSlateGray">
+			<legend  style="background-color:DarkSlateGray;color:white">Input</legend>
+			<table>
+				<tbody style="color:white;background-color:DarkSlateGray">
+					<tr>
+						<td>SteamID / FriendID / customURL:<br>
+							<input type="hidden" size="70" name="m" value="<?php echo $_GET['m']; ?>">
+							<input type="text" size="70" name="s" value="<?php echo htmlentities(stripslashes(@$_GET['s']),ENT_QUOTES); ?>">
+						</td>
+					</tr>
+					<tr>
+						<td align="right">
+							<input class="button" type="submit" accesskey="s" value="Submit">
+						</td>
+					</tr>
+				</tbody>
+			</table>
+		</fieldset>
+	</div>
+</form>
+
+<?php
+$ret=get_input_type(@$_GET['s']);
+if ($ret==''){
+
+}else if (is_string($ret)){
+	echo '<div><fieldset style="background-color:DarkSlateGray;color:white"><legend style="background-color:DarkSlateGray;color:white">Output</legend><table><tbody style="background-color:DarkSlateGray;color:white"><tr><td>';
+	echo $ret;
+	echo '</td></tr></tbody></table></fieldset>';
+	if ($_GET['s']!=='') {	echo $notice; }
+	echo '</div>';
+}else if (is_array($ret)){
+	echo '<div><fieldset style="background-color:DarkSlateGray;color:white"><legend style="background-color:DarkSlateGray;color:white">Output</legend><table><tbody style="background-color:DarkSlateGray;color:white"><tr><td>';
+	convert($ret['type'],$ret['data']);
+	echo '</td></tr></tbody></table></fieldset>';
+	if ($_GET['s']!=='') {	echo @$notice;}
+	echo '</div>';
+}
+
+function convert($type,$data){
+	switch($type){
+		case 'steamid':
+		$main='http://steamcommunity.com/profiles/'.bcadd((($data['auth']*2)+$data['server']),'76561197960265728');
+		echo 'FriendID: <a href="'.$main.'" title="Visit Steam Community page" target="blank">'.bcadd((($data['auth']*2)+$data['server']),'76561197960265728').'</a>';
+		break;
+		case 'friendid':
+		if (substr($data,-1)%2==0) $server=0; else $server=1;
+		$auth=bcsub($data,'76561197960265728');
+		if (bccomp($auth,'0')!=1) {echo "Error: invalid FriendID or SteamID";return;}
+		$auth=bcsub($auth,$server);
+		$auth=bcdiv($auth,2);
+		echo "SteamID for VALVe's GoldSrc and Source Orange Box Engine games:<br>".
+			 'STEAM_0:'.$server.':'.$auth;
+		echo "<br><br>SteamID for VALVe's newer games:<br>".
+			 'STEAM_1:'.$server.':'.$auth;
+		break;
+	}
+}
+
+function get_input_type($data){
+	$data=strtolower(trim($data));
+	if ($data!='') {
+		if (strlen($data)>80) return "too long";
+		if (substr($data,0,7)=='steam_0' or substr($data,0,7)=='steam_1') {
+			$tmp=explode(':',$data);
+			if ((count($tmp)==3) && is_numeric($tmp[1]) && is_numeric($tmp[2])){
+				return array('type'=>'steamid','data'=>array('auth'=>$tmp[2],'server'=>$tmp[1]));
+			}else{
+				return "Error: invalid SteamID";
+			}
+		}else if ($p=strrpos($data,'/')){
+			$tmp=explode('/',$data);
+			foreach ($tmp as $item){
+				if (is_numeric($item)){
+					$a=$item;
+					break;
+				}
+			}
+			if ((is_numeric($a)) && (preg_match('/7656119/', $a))) return array('type'=>'friendid','data'=>$a);
+			else {
+				$xml = @simplexml_load_file($data."?xml=1");
+				$steamid64=$xml->steamID64;
+				if (!preg_match('/7656119/', $steamid64)) return "Error: invalid link";
+				else return array('type'=>'friendid','data'=>$steamid64);
+			}
+		}else if ((is_numeric($data)) && (preg_match('/7656119/', $data))){
+			return array('type'=>'friendid','data'=>$data);
+		}else{
+			$xml = @simplexml_load_file("http://steamcommunity.com/id/".$data."?xml=1");
+			$steamid64=$xml->steamID64;
+			if (!preg_match('/7656119/', $steamid64)) return "Error: invalid input";
+			else return array('type'=>'friendid','data'=>$steamid64);
+		}
+	}else{
+		return "";
+	}
+}
+?>

+ 80 - 0
modules/util/util.php

@@ -0,0 +1,80 @@
+<?php
+/*
+ *
+ * OGP - Open Game Panel
+ * Copyright (C) Copyright (C) 2008 - 2012 The OGP Development Team
+ *
+ * http://www.opengamepanel.org/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ */
+ 
+ 
+function exec_ogp_module() 
+{
+?>
+<h2>Util</h2>
+	<table style="margin-left:auto;margin-right:auto">
+		<tr style="background-color:black">
+			<td style="background-color:cyan; text-align:center;">
+				<h1>Add an admin on SourceMod</h1>
+			</td>
+		</tr>
+		<tr >	
+			<td style="background-color:cyan; text-align:center;">
+			<?php  require("modules/util/sm_admin.php"); ?>
+			</td>
+		</tr>
+		<tr style="background-color:black">
+			<td style="background-color:orange; text-align:center;">
+				<h1>Add an admin on Mani Admin Plugin</h1>
+			</td>
+		</tr>
+		<tr >	
+			<td style="background-color:orange; text-align:center;">
+			<?php  require("modules/util/ma_admin.php"); ?>
+			</td>
+		</tr>
+		<tr style="background-color:black">
+			<td style="background-color:green; text-align:center;">
+				<h1>Ping Servers</h1>
+			</td>
+		</tr>
+		<tr>
+			<td style="background-color:green; text-align:center;">
+				<?php  require("modules/util/ping.php"); ?>
+			</td>
+		</tr>
+		<tr style="background-color:DarkSlateGray">
+			<td style="background-color:DarkSlateGray;text-align:center;">
+				<h1 style="color:white;" >SteamID Converter</h1>
+			</td>
+		</tr>
+		<tr>
+			<td>
+			<?php  require("modules/util/steamid_converter.php"); ?>
+			</td>
+		</tr>
+		<tr>
+			<td>
+				&nbsp;</b><br><br>
+			</td>
+		</tr>
+	</table>
+
+<?php
+}
+?>