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