sm_admin.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <table style="background-color:white;color:blue; margin-left:auto;margin-right:auto">
  2. <tr>
  3. <td>
  4. <?php
  5. global $db;
  6. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  7. if ( $isAdmin )
  8. $server_homes = $db->getIpPorts();
  9. else
  10. $server_homes = $db->getIpPortsForUser($_SESSION['user_id']);
  11. $supported_games = array( "Counter Strike Global Offensive",
  12. "Counter Strike Source",
  13. "Day of Defeat: Source",
  14. "Dystopia",
  15. "Garrys Mod",
  16. "Half-Life 2: Deathmatch",
  17. "Hidden: Source",
  18. "Pirates, Vikings and Knights II",
  19. "Team Fortress 2",
  20. "Team Fortress 2 Beta",
  21. "Left 4 Dead",
  22. "Left 4 Dead 2" );
  23. $admin_flags = array( "a" => "Reserved slot access.",
  24. "b" => "Generic admin; required for admins.",
  25. "c" => "Kick other players.",
  26. "d" => "Ban other players.",
  27. "e" => "Remove bans.",
  28. "f" => "Slay/harm other players.",
  29. "g" => "Change the map or major gameplay features.",
  30. "h" => "Change most cvars.",
  31. "i" => "Execute config files.",
  32. "j" => "Special chat privileges.",
  33. "k" => "Start or create votes.",
  34. "l" => "Set a password on the server.",
  35. "m" => "Use RCON commands.",
  36. "n" => "Change sv_cheats or use cheating commands." );
  37. $i = 0;
  38. foreach ($server_homes as $server_home)
  39. {
  40. if ( in_array( $server_home['game_name'], $supported_games ) )
  41. $sm_admin_server_homes[$i] = $server_home;
  42. $i++;
  43. }
  44. if( !isset( $_GET['sm_admin']) )
  45. {
  46. $select = $_GET['home_id-mod_id-ip-port'];
  47. unset( $_GET['home_id-mod_id-ip-port'] );
  48. }
  49. create_home_selector_address("util","",$sm_admin_server_homes);
  50. ?>
  51. <script type="text/javascript">
  52. var theForm = document.forms['select'];
  53. var input = document.createElement('input');
  54. input.type = 'hidden';
  55. input.name = 'sm_admin';
  56. theForm.appendChild(input);
  57. </script>
  58. </td>
  59. </tr>
  60. <?php
  61. if ( empty( $_GET['home_id-mod_id-ip-port'] ) )
  62. unset( $_GET['home_id-mod_id-ip-port'] );
  63. if( isset( $_GET['home_id-mod_id-ip-port'] ) and isset( $_GET['sm_admin'] ) )
  64. {
  65. $pieces = explode( "-", $_GET['home_id-mod_id-ip-port'] );
  66. $home_id = $pieces[0];
  67. $mod_id = $pieces[1];
  68. $ip = $pieces[2];
  69. $port = $pieces[3];
  70. if($isAdmin)
  71. $server_home = $db->getGameHome($home_id);
  72. else
  73. $server_home = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  74. $_SESSION['inmunityLvl'] = $_POST['ainmunity'];
  75. if(isset($_POST['sm_admin']))
  76. {
  77. if($_POST['asteamid'])
  78. print_failure('A steam_id is needed!');
  79. $flagsStr = "";
  80. foreach($_POST as $key => $val)
  81. {
  82. if(preg_match('/flag_/',$key))
  83. $flagsStr .= $val;
  84. }
  85. $inmunityLvl = $_POST['ainmunity'] != '0' ? $_POST['ainmunity'].':' : "";
  86. if($_POST['steamid'] == "" or $flagsStr == "")
  87. {
  88. if($_POST['steamid'] == "")
  89. print_failure('A steam_id is needed!');
  90. if($flagsStr == "")
  91. print_failure('Must select at least 1 flag!');
  92. }
  93. else
  94. {
  95. $admins_simple_location = $server_home['home_path']."/".$server_home['mods'][$mod_id]['mod_key']."/addons/sourcemod/configs/admins_simple.ini";
  96. require_once('includes/lib_remote.php');
  97. $remote = new OGPRemoteLibrary($server_home['agent_ip'], $server_home['agent_port'], $server_home['encryption_key'], $server_home['timeout']);
  98. if($remote->rfile_exists($admins_simple_location) != 1)
  99. 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!");
  100. else
  101. {
  102. $remote->remote_readfile($admins_simple_location,$file_content);
  103. $replace = FALSE;
  104. if(preg_match("/".$_POST['steamid']."/i",$file_content))
  105. $replace = TRUE;
  106. if($replace)
  107. $file_content = preg_replace("/.*".$_POST['steamid'].".*/i","\"".$_POST['steamid']."\"\t\t\"$inmunityLvl$flagsStr\"",$file_content);
  108. else
  109. $file_content .= "\n\"".$_POST['steamid']."\"\t\t\"$inmunityLvl$flagsStr\"";
  110. $remote->remote_writefile($admins_simple_location, $file_content);
  111. print_success("Admin added/changed successfully at admins_simple.ini");
  112. $remote_retval = $remote->remote_send_rcon_command( $server_home['home_id'], $ip, $port, 'rcon2', $server_home['control_password'],'',"sm_reloadadmins",$return);
  113. if ( $remote_retval === -1 )
  114. {
  115. print_failure("Failed to reload admins, the server may be down or the agent is offline.");
  116. }
  117. elseif ( $remote_retval === 1 )
  118. {
  119. if( preg_match('/Admin cache has been refreshed/i',$return) )
  120. print_success("Admin cache has been refreshed.");
  121. else
  122. print_failure("SourceMod is not properly installed in your server, the error was:<br><xmp>".$return."</xmp>");
  123. }
  124. elseif ( $remote_retval === -10 )
  125. {
  126. 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.");
  127. }
  128. }
  129. }
  130. }
  131. ?>
  132. <tr>
  133. <td>
  134. <form action="" method="post">
  135. <tr>
  136. <td>
  137. Steam_ID
  138. <input type="text" name="steamid" value="<?php echo (isset($_POST['steamid']) and $_POST['steamid'] != "") ? $_POST['steamid'] : "";?>" />
  139. </td>
  140. </tr>
  141. <tr>
  142. <td>
  143. Inmunity level
  144. <input type="number" name="ainmunity" min="0" max="99" value="<?php echo isset($_SESSION['inmunityLvl']) ? $_SESSION['inmunityLvl'] : "99";?>"/><br>
  145. <em>Every admin can have an arbitrary immunity value assigned to them.</em>
  146. <br>
  147. <em>Whether an admin can target another admin depends on who has a higher immunity value.</em>
  148. </td>
  149. </tr>
  150. <tr>
  151. <td>
  152. Admin Flags
  153. <?php
  154. $selected = ( isset( $_POST['flags'] ) and $_POST['flags'] == "custom" ) ? "selected='selected'" : "";
  155. echo "<select name='flags' onchange='this.form.submit();'>\n".
  156. "<option value='z' >Root Admin</option>\n".
  157. "<option value='custom' $selected>Customize Flags</option>\n".
  158. "</select>\n<br>\n";
  159. if( isset( $_POST['flags'] ) and $_POST['flags'] == "custom" )
  160. {
  161. foreach($admin_flags as $flag => $desc )
  162. {
  163. echo "<input type='checkbox' name='flag_$flag' value='$flag' />$desc\n<br>\n";
  164. }
  165. }
  166. else
  167. echo "<input type='hidden' name='flag_z' value='z' />";
  168. ?>
  169. </td>
  170. </tr>
  171. <tr>
  172. <td>
  173. <input name="sm_admin" value="ADD ADMIN" type="submit"/>
  174. </form>
  175. </td>
  176. </tr>
  177. <?php
  178. }
  179. else
  180. $_GET['home_id-mod_id-ip-port'] = $select;
  181. ?>
  182. </table>