Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. <?PHP
  2. require_once('libs/TeamSpeak3/TeamSpeak3.php');
  3. require_once('config.php');
  4. require_once('libs/recaptcha/src/autoload.php');
  5. require_once('libs/chadd.php');
  6.  
  7. $type = @$_GET["type"];
  8.  
  9. function getClientIp() {
  10. if (!empty($_SERVER['HTTP_CLIENT_IP']))
  11. return $_SERVER['HTTP_CLIENT_IP'];
  12. else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  13. return $_SERVER['HTTP_X_FORWARDED_FOR'];
  14. else if(!empty($_SERVER['HTTP_X_FORWARDED']))
  15. return $_SERVER['HTTP_X_FORWARDED'];
  16. else if(!empty($_SERVER['HTTP_FORWARDED_FOR']))
  17. return $_SERVER['HTTP_FORWARDED_FOR'];
  18. else if(!empty($_SERVER['HTTP_FORWARDED']))
  19. return $_SERVER['HTTP_FORWARDED'];
  20. else if(!empty($_SERVER['REMOTE_ADDR']))
  21. return $_SERVER['REMOTE_ADDR'];
  22. else
  23. return false;
  24. }
  25.  
  26. function Response($code, $header, $msg) {
  27. $resp = array(
  28. "code" => $code,
  29. "header" => $header,
  30. "msg" => $msg,
  31. );
  32. $data = json_encode($resp);
  33. echo $data;
  34. exit;
  35. }
  36.  
  37. switch($type) {
  38.  
  39. case 0:
  40.  
  41. $request = json_decode(file_get_contents("php://input"));
  42.  
  43.  
  44. $recaptcha = new \ReCaptcha\ReCaptcha($secret);
  45. $resp = $recaptcha->verify($request->captcha_resp, getClientIp());
  46.  
  47. if($resp->isSuccess()) {
  48.  
  49. if($chadd->CheckCookie())
  50. {
  51. Response(406, "Error :(", "You can't create a channel again.");
  52. }
  53.  
  54. //REPLACE bad words
  55. $request->channelname = $chadd->ReplaceBadString($badwords, $request->channelname);
  56.  
  57. if($chadd->CheckStringIP($request->channelname))
  58. {
  59. Response(403, "Error :(", "In your Channel Name is no IP Adress or Domain allowed.");
  60. }
  61.  
  62. if($chadd->CheckStringDomain($request->channelname))
  63. {
  64. Response(403, "Error :(", "In your Channel Name is no IP Adress or Domain allowed.");
  65. }
  66.  
  67. if($request->quality < 1 || $request->quality > 10)
  68. {
  69. $request->quality = 7;
  70. }
  71.  
  72. switch ($request->codec)
  73. {
  74. case 1:
  75. define("TS3_CODEC", TeamSpeak3::CODEC_OPUS_VOICE);
  76. break;
  77.  
  78. case 2:
  79. define("TS3_CODEC", TeamSpeak3::CODEC_CELT_MONO);
  80. break;
  81.  
  82. case 3:
  83. define("TS3_CODEC", TeamSpeak3::CODEC_SPEEX_ULTRAWIDEBAND);
  84. break;
  85.  
  86. default:
  87. define("TS3_CODEC", TeamSpeak3::CODEC_OPUS_VOICE);
  88. }
  89.  
  90. try {
  91.  
  92. $ts3_VirtualServer = TeamSpeak3::factory("serverquery://$ts3_username:$ts3_password@$ts3_host:$ts3_q_port/?server_port=$ts3_s_port");
  93. $ts3_VirtualServer->selfUpdate(array('client_nickname'=> $ts3_nick));
  94.  
  95. $client = $ts3_VirtualServer->clientGetByUid($request->uuid);
  96. $groups = $client["client_servergroups"];
  97. $group_matches = 0;
  98.  
  99. foreach($allowed_groups as $g)
  100. {
  101. if(in_array($g, $allowed_groups))
  102. {
  103. $group_matches++;
  104. }
  105. }
  106.  
  107. if($group_matches <= 0)
  108. {
  109. Response(403, "Not Authorized", "Not allowed to use this tool, you are not in a whitelisted group.");
  110. }
  111.  
  112. $cid = $ts3_VirtualServer->channelCreate(array(
  113. "channel_name" => $request->channelname,
  114. "channel_password" => $request->password,
  115. "channel_topic" => $channel_topic,
  116. "channel_codec" => TS3_CODEC,
  117. "channel_codec_quality" => $request->quality,
  118. "channel_flag_permanent" => FALSE,
  119. "cpid" => $cpid,
  120. "channel_description" => $channel_description,
  121. "channel_flag_semi_permanent" => TRUE
  122. ));
  123.  
  124. //log cid with IP (abuse)
  125. $usr_ip = getClientIp();
  126. $ts3_VirtualServer->logAdd("Channel $cid created from IP:$usr_ip", TeamSpeak3::LOGLEVEL_INFO);
  127.  
  128.  
  129. $token = $ts3_VirtualServer->privilegeKeyCreate(0x01, "$chadmin_group_id" ,"$cid", "TOKEN created from CHADD.");
  130.  
  131. $chadd->SetCookie();
  132.  
  133.  
  134. $resp = array(
  135. "code" => 1,
  136. "header" => "All fine! :)",
  137. "token" => (string)$token,
  138. "url" => "$server_conn_url?port=$ts3_s_port&cid=$cid&channelpassword=$request->password&token=$token",
  139. );
  140.  
  141.  
  142. $json = json_encode($resp);
  143. echo $json;
  144. exit;
  145.  
  146. }
  147.  
  148. catch (TeamSpeak3_Exception $e) {
  149. Response(500, "TS3-Error: "+ $e->getCode(), $e->getMessage());
  150. }
  151.  
  152.  
  153. } else {
  154. $errors = $resp->getErrorCodes();
  155. if(count($errors) >= 1)
  156. {
  157. Response(403, "Error :(", $errors[0]);
  158. }
  159. }
  160.  
  161. break;
  162.  
  163. case 1:
  164.  
  165. try {
  166. $ts3_VirtualServer = TeamSpeak3::factory("serverquery://$ts3_username:$ts3_password@$ts3_host:$ts3_q_port/?server_port=$ts3_s_port");
  167. $ts3_VirtualServer->selfUpdate(array('client_nickname'=> $ts3_nick));
  168. $clients = $ts3_VirtualServer->clientList(array('connection_client_ip' => getClientIp()));
  169.  
  170. $matches = count($clients);
  171. if($matches > 1 || $matches <= 0)
  172. {
  173. Response(404, "Client not found.", "Could not determine your Unique ID. Enter your Unique ID.");
  174. }
  175.  
  176. if($matches == 1)
  177. {
  178. foreach($clients as $c)
  179. {
  180.  
  181. if(count($c->getClones()) > 1)
  182. {
  183. Response(404, "Client not found.", "Could not determine your Unique ID. Enter your Unique ID.");
  184. }
  185.  
  186. $resp = array(
  187. "code" => 200,
  188. "header" => "Authenticated",
  189. "uuid" => (string)$c["client_unique_identifier"],
  190. "name" => (string)$c["client_nickname"],
  191. );
  192.  
  193. $json = json_encode($resp);
  194. echo $json;
  195. exit;
  196.  
  197. }
  198. }
  199.  
  200. }
  201. catch (TeamSpeak3_Exception $e) {
  202. Response(500, "TS3-Error: "+ $e->getCode(), $e->getMessage());
  203. }
  204.  
  205. break;
  206.  
  207. }
  208. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement