-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from JABirchall/GlobalBan
Global ban System Tested and functions as intended
- Loading branch information
Showing
13 changed files
with
311 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "AddWhitelist", | ||
"author": "JABirchall", | ||
"description": "Whitelist a user from the global ban system.", | ||
"version": "1.0", | ||
"triggers": [ | ||
"!whitelist" | ||
], | ||
"table": "whitelists", | ||
"usage": "Usage: !whitelist [uid]" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "GlobalBan", | ||
"author": "JABirchall", | ||
"description": "Submit a Global Teamspeak ban", | ||
"version": "1.0", | ||
"triggers": [ | ||
"!gban", | ||
"!globalban" | ||
], | ||
"usage": "Usage !gban [user] [reason]", | ||
"key": "5r607k124q5j43085o480a0m528m460i" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "GlobalBanList", | ||
"author": "JABirchall", | ||
"description": "Check for Global Teamspeak Ban", | ||
"version": "1.0", | ||
"triggers": [ | ||
"event" | ||
], | ||
"event": "cliententerview", | ||
"usage": false, | ||
"enabled": true, | ||
"ban": false, | ||
"alert": true, | ||
"alert_groups": [ | ||
12, | ||
13, | ||
14 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Jake | ||
* Date: 16/09/2016 | ||
* Time: 08:22 | ||
*/ | ||
|
||
namespace Plugin; | ||
|
||
use Illuminate\Database\Capsule\Manager; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Plugin\Models\Whitelist; | ||
use App\Plugin; | ||
|
||
class AddWhitelist extends Plugin implements AdvancedPluginContract | ||
{ | ||
private $server; | ||
|
||
public function isTriggered() | ||
{ | ||
if (!isset($this->info['text'])) { | ||
$this->sendOutput($this->CONFIG['usage']); | ||
|
||
return; | ||
} | ||
$this->server = $this->teamSpeak3Bot->node; | ||
|
||
Whitelist::create([ | ||
'uid' => $this->info['text'], | ||
'added_by' => $this->info['invokername'], | ||
'added_by_uid' => $this->info['invokeruid'] | ||
]); | ||
|
||
$this->sendOutput('Unique ID: %s has been successfully whitelisted.', $this->info['text']); | ||
} | ||
|
||
public function install() | ||
{ | ||
Manager::schema()->create($this->CONFIG['table'], function(Blueprint $table) { | ||
$table->increments('id'); | ||
$table->text('uid'); | ||
$table->text('added_by'); | ||
$table->text('added_by_uid'); | ||
|
||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function update($version) | ||
{ | ||
// TODO: Implement update() method. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Jake | ||
* Date: 16/09/2016 | ||
* Time: 06:18 | ||
*/ | ||
|
||
namespace Plugin; | ||
|
||
use App\Plugin; | ||
use TeamSpeak3\Ts3Exception; | ||
|
||
class GlobalBan extends Plugin implements PluginContract | ||
{ | ||
|
||
public $server; | ||
|
||
public function isTriggered() | ||
{ | ||
if (!isset($this->info['text'])) { | ||
$this->sendOutput($this->CONFIG['usage']); | ||
|
||
return; | ||
} | ||
|
||
$this->server = $this->teamSpeak3Bot->node; | ||
|
||
list($name, $reason) = $this->info['text']->split(' '); | ||
|
||
try { | ||
$client = current($this->server->clientFind($name)); | ||
$client = $this->server->clientGetById($client['clid']); | ||
}catch(Ts3Exception $e){ | ||
$message = $e->getMessage(); | ||
if ($message === "invalid clientID") { | ||
$this->sendOutput("[COLOR=red][b] There are no users online by that name"); | ||
|
||
return; | ||
} | ||
} | ||
|
||
$curl = curl_init(); | ||
|
||
$fields = [ | ||
'key' => $this->CONFIG['key'], | ||
'uid' => $client['client_unique_identifier']->toString(), | ||
'ip' => $client['connection_client_ip'], | ||
'banned_by' => $this->info['invokername'], | ||
'banned_by_uid' => $this->info['invokeruid'], | ||
'reason' => $reason, | ||
'server_name' => $this->server->toString(), | ||
'server_uid' => $this->server['virtualserver_unique_identifier'], | ||
'h' => hash_pbkdf2('sha1', sprintf("%s-%s-%s", $this->CONFIG['key'], $client['client_unique_identifier']->toString(),$this->info['invokeruid']),$this->server['virtualserver_unique_identifier'], 1, 8), | ||
|
||
]; | ||
|
||
curl_setopt($curl, CURLOPT_URL, 'http://127.0.0.1/bans/submit'); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields); | ||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1); | ||
curl_setopt($curl, CURLOPT_TIMEOUT, 5); | ||
|
||
$response = json_decode(curl_exec($curl)); | ||
if(curl_errno($curl) != 0) { | ||
$this->sendOutput(sprintf("There was a error with the request: %s", curl_error($curl))); | ||
return; | ||
} | ||
|
||
curl_close($curl); | ||
|
||
if($response->success === true) { | ||
try { | ||
$id = hash_pbkdf2("sha1", $client['client_unique_identifier']->toString(), '', 1, 8); | ||
$client->poke("[b][color=red]You are global banned by Nimda ID: #{$id}"); | ||
$client->poke("[b][color=red]Visit [url=http://support.mxgaming.com/]Global Ban Support[/url]."); | ||
$client->ban(1, "Global Ban ID #{$id} ({$reason})"); | ||
}catch(Ts3Exception $e){ | ||
return; | ||
} | ||
|
||
$this->sendOutput(sprintf("[b][color=green] Client %s successfully global banned ID #%s", $client, $id)); | ||
} elseif ($response->success === false && $response->err === 0x02) { | ||
$this->sendOutput("[COLOR=red][b]This server is not authorized to global ban, email [email protected]"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Jake | ||
* Date: 16/09/2016 | ||
* Time: 06:18 | ||
*/ | ||
|
||
namespace Plugin; | ||
|
||
|
||
use App\Plugin; | ||
use Plugin\Models\Whitelist; | ||
use TeamSpeak3\Ts3Exception; | ||
|
||
|
||
class GlobalBanList extends Plugin implements PluginContract | ||
{ | ||
|
||
private $server; | ||
|
||
public function isTriggered() | ||
{ | ||
if($this->CONFIG['enabled'] === false) { | ||
return; | ||
} | ||
|
||
$this->server = $this->teamSpeak3Bot->node; | ||
|
||
$whitelisted = Whitelist::where('uid', $this->info['client_unique_identifier']->toString())->count(); | ||
if($whitelisted >= 1) { | ||
return; | ||
} | ||
|
||
$curl = curl_init(); | ||
|
||
$fields = [ | ||
'uid' => $this->info['client_unique_identifier']->toString() | ||
]; | ||
|
||
curl_setopt($curl, CURLOPT_URL, 'http://127.0.0.1/bans/check'); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields); | ||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1); | ||
curl_setopt($curl, CURLOPT_TIMEOUT, 5); | ||
|
||
$response = json_decode(curl_exec($curl)); | ||
|
||
if(curl_errno($curl) != 0) { | ||
curl_close($curl); | ||
return; | ||
} | ||
|
||
curl_close($curl); | ||
|
||
if($response->success === false || $response->banned === false) { | ||
return; | ||
} | ||
|
||
try { | ||
$client = $this->server->clientGetByUid($this->info['client_unique_identifier']); | ||
$id = hash_pbkdf2("sha1", $this->info['client_unique_identifier']->toString(), '', 1, 8); | ||
}catch(Ts3Exception $e){ | ||
return; | ||
} | ||
|
||
if($this->CONFIG['ban'] === true && $response->uid === $this->info['client_unique_identifier']->toString()) { | ||
try { | ||
$client->poke("[b][color=red]You are globally banned by Nimda ID: #{$id}"); | ||
$client->poke("[b][color=red]Visit [url=http://support.mxgaming.com/]Global Ban Support[/url]."); | ||
$client->ban(1, "Global Ban ID #{$id} ({$response->reason})"); | ||
}catch(Ts3Exception $e){ | ||
return; | ||
} | ||
} | ||
|
||
if($this->CONFIG['alert'] === true) { | ||
$message = sprintf("[ALERT] Client %s is global banned ID #%s reason: %s\n", $client, $id, $response->reason); | ||
array_walk(array_map([$this->server, 'serverGroupGetById'], $this->CONFIG['alert_groups']), function($admin) use ($message) { | ||
$admin->message($message); | ||
}); | ||
} | ||
|
||
printf("[%s]: %s", $this->teamSpeak3Bot->carbon->now()->toTimeString(), $message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Jake | ||
* Date: 16/09/2016 | ||
* Time: 06:29 | ||
*/ | ||
|
||
namespace Plugin\Models; | ||
|
||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Whitelist extends Model | ||
{ | ||
protected $fillable = ['uid', 'added_by', 'added_by_uid',]; | ||
} |
Oops, something went wrong.