"TeaSpeak Provisioning", "description" => "TeaSpeak provisioning Module for TeaSpeak servers", "version" => "2.1.4", "author" => "planetteaspeak.de", "language" => "english", "fields" => array( "key" => array ("FriendlyName" => "Licensekey", "Type" => "text", "Size" => "25", "Description" => "Enter your paid Licensekey", "Default" => "Lease-"), )); return $configarray; } function teamspeak_check_license($licensekey, $localkey='') { // ----------------------------------- // -- Configuration Values -- // ----------------------------------- // Enter the url to your WHMCS installation here $whmcsurl = 'https://planetteaspeak.de'; // Must match what is specified in the MD5 Hash Verification field // of the licensing product that will be used with this check. $licensing_secret_key = 'ab4a3ffa672b4a25dbb6c48571b94655'; // The number of days to wait between performing remote license checks $localkeydays = 15; // The number of days to allow failover for after local key expiry $allowcheckfaildays = 5; // ----------------------------------- // -- Do not edit below this line -- // ----------------------------------- $check_token = time() . md5(mt_rand(1000000000, 9999999999) . $licensekey); $checkdate = date("Ymd"); $domain = $_SERVER['SERVER_NAME']; $usersip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; $dirpath = dirname(__FILE__); $verifyfilepath = 'modules/servers/licensing/verify.php'; $localkeyvalid = false; if ($localkey) { $localkey = str_replace("\n", '', $localkey); # Remove the line breaks $localdata = substr($localkey, 0, strlen($localkey) - 32); # Extract License Data $md5hash = substr($localkey, strlen($localkey) - 32); # Extract MD5 Hash if ($md5hash == md5($localdata . $licensing_secret_key)) { $localdata = strrev($localdata); # Reverse the string $md5hash = substr($localdata, 0, 32); # Extract MD5 Hash $localdata = substr($localdata, 32); # Extract License Data $localdata = base64_decode($localdata); $localkeyresults = unserialize($localdata); $originalcheckdate = $localkeyresults['checkdate']; if ($md5hash == md5($originalcheckdate . $licensing_secret_key)) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $localkeydays, date("Y"))); if ($originalcheckdate > $localexpiry) { $localkeyvalid = true; $results = $localkeyresults; $validdomains = explode(',', $results['validdomain']); if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } $validips = explode(',', $results['validip']); if (!in_array($usersip, $validips)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } $validdirs = explode(',', $results['validdirectory']); if (!in_array($dirpath, $validdirs)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } } } } } if (!$localkeyvalid) { $responseCode = 0; $postfields = array( 'licensekey' => $licensekey, 'domain' => $domain, 'ip' => $usersip, 'dir' => $dirpath, ); if ($check_token) $postfields['check_token'] = $check_token; $query_string = ''; foreach ($postfields AS $k=>$v) { $query_string .= $k.'='.urlencode($v).'&'; } if (function_exists('curl_exec')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $whmcsurl . $verifyfilepath); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } else { $responseCodePattern = '/^HTTP\/\d+\.\d+\s+(\d+)/'; $fp = @fsockopen($whmcsurl, 80, $errno, $errstr, 5); if ($fp) { $newlinefeed = "\r\n"; $header = "POST ".$whmcsurl . $verifyfilepath . " HTTP/1.0" . $newlinefeed; $header .= "Host: ".$whmcsurl . $newlinefeed; $header .= "Content-type: application/x-www-form-urlencoded" . $newlinefeed; $header .= "Content-length: ".@strlen($query_string) . $newlinefeed; $header .= "Connection: close" . $newlinefeed . $newlinefeed; $header .= $query_string; $data = $line = ''; @stream_set_timeout($fp, 20); @fputs($fp, $header); $status = @socket_get_status($fp); while (!@feof($fp)&&$status) { $line = @fgets($fp, 1024); $patternMatches = array(); if (!$responseCode && preg_match($responseCodePattern, trim($line), $patternMatches) ) { $responseCode = (empty($patternMatches[1])) ? 0 : $patternMatches[1]; } $data .= $line; $status = @socket_get_status($fp); } @fclose ($fp); } } if ($responseCode != 200) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y"))); if ($originalcheckdate > $localexpiry) { $results = $localkeyresults; } else { $results = array(); $results['status'] = "Invalid"; $results['description'] = "Remote Check Failed"; return $results; } } else { preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $matches); $results = array(); foreach ($matches[1] AS $k=>$v) { $results[$v] = $matches[2][$k]; } } if (!is_array($results)) { die("Invalid License Server Response"); } if ($results['md5hash']) { if ($results['md5hash'] != md5($licensing_secret_key . $check_token)) { $results['status'] = "Invalid"; $results['description'] = "MD5 Checksum Verification Failed"; return $results; } } if ($results['status'] == "Active") { $results['checkdate'] = $checkdate; $data_encoded = serialize($results); $data_encoded = base64_encode($data_encoded); $data_encoded = md5($checkdate . $licensing_secret_key) . $data_encoded; $data_encoded = strrev($data_encoded); $data_encoded = $data_encoded . md5($data_encoded . $licensing_secret_key); $data_encoded = wordwrap($data_encoded, 80, "\n", true); $results['localkey'] = $data_encoded; } $results['remotecheck'] = true; } unset($postfields,$data,$matches,$whmcsurl,$licensing_secret_key,$checkdate,$usersip,$localkeydays,$allowcheckfaildays,$md5hash); return $results; } function teamspeak_activate() { try { if (!Capsule::schema()->hasTable('modwhmcs_teamspeak_backups')) { Capsule::schema()->create('modwhmcs_teamspeak_backups', function ($table) { $table->increments('id'); $table->integer('sid')->nullable(); $table->integer('port'); $table->mediumText('data')->nullable(); $table->timestamp('date')->nullable(); }); } if (!Capsule::schema()->hasTable('modwhmcs_teamspeak_settings')) { Capsule::schema()->create('modwhmcs_teamspeak_settings', function ($table) { $table->increments('id'); $table->mediumInteger('minport'); $table->mediumInteger('maxport'); $table->mediumText('servername')->nullable(); $table->longText('servermsgwelcome')->nullable(); $table->longText('servermsg')->nullable(); $table->integer('servermsgmode'); $table->longText('bannerlinkurl')->nullable(); $table->longText('bannerimgurl')->nullable(); $table->integer('bannermode'); $table->longText('buttonlinkurl')->nullable(); $table->longText('buttonimgurl')->nullable(); $table->longText('buttonmsgtooltip')->nullable(); $table->bigInteger('uploadquota'); $table->bigInteger('downloadquota'); $table->bigInteger('uploadbandwidth'); $table->bigInteger('downloadbandwidth'); $table->integer('enabletsdns'); $table->longText('domaintsdns')->nullable(); $table->longText('urlapi')->nullable(); $table->longText('keyapi')->nullable(); }); Capsule::table('modwhmcs_teamspeak_settings')->insert(array('minport' => 9987, 'maxport' => 999999, 'servername' => 'TeaSpeak Server by Voice4You.org', 'servermsgwelcome' => 'Welcome to Tea(m)Speak, check [URL]teaspeak.de[/URL] for latest information', 'servermsgmode' => 0, 'bannermode' => 0, 'uploadquota' => -1, 'downloadquota' => -1, 'uploadbandwidth' => -1, 'downloadbandwidth' => -1, 'enabletsdns' => 0)); } } catch (Exception $e) { return array('status' => 'error', 'description' => 'It was not possible to create the table. Check your database'); } return array('status' => 'success'); } function teamspeak_deactivate() { try { Capsule::schema()->dropIfExists('modwhmcs_teamspeak_settings'); } catch (Exception $e) { return array('status' => 'error', 'description' => 'The table could not be deleted. Check your database'); } return array('status' => 'success'); } function teamspeak_output($vars) { $license = Capsule::table('tbladdonmodules')->where('module', 'teamspeak')->where('setting', 'license')->value('value'); $listServers = Capsule::table('tblservers')->where('type', 'teamspeak')->get(); $servers = array(); foreach ($listServers as $key => $server) { $servers[$key] = new stdClass(); $servers[$key]->name = $server->name; $servers[$key]->ipaddress = $server->ipaddress; $servers[$key]->port = ($server->port ? $server->port : 10101); $servers[$key]->username = $server->username; $servers[$key]->password = $server->password; } $alert = array(); $names = array(); foreach ($servers as $server) { $names[$server->name] = md5($server->name); } $licensekey = $vars['key']; $localkey = ''; // Validate the license key information $results = teamspeak_check_license($licensekey, $localkey); // Raw output of results for debugging purpose //echo ''; // Interpret response switch ($results['status']) { case "Active": // get new local key and save it somewhere $localkeydata = $results['localkey']; break; case "Invalid": # die("License key is Invalid"); #break; case "Expired": #die("License key is Expired"); #break; case "Suspended": # die("License key is Suspended"); #break; default: #die("Invalid Response"); #break; } $output = ''; if (!isset($_GET['display'])) { $output .= ""; } if (isset($_POST['action']) && $_POST['action'] == 'savesettings') { try { if (!Capsule::table('modwhmcs_teamspeak_settings')->where('id', 1)->update(array('minport' => $_POST['minport'], 'maxport' => $_POST['maxport'], 'servername' => $_POST['servername'], 'servermsgwelcome' => $_POST['servermsgwelcome'], 'servermsg' => $_POST['servermsg'], 'servermsgmode' => $_POST['servermsgmode'], 'bannerlinkurl' => $_POST['bannerlinkurl'], 'bannerimgurl' => $_POST['bannerimgurl'], 'bannermode' => $_POST['bannermode'], 'buttonlinkurl' => $_POST['buttonlinkurl'], 'buttonimgurl' => $_POST['buttonimgurl'], 'buttonmsgtooltip' => $_POST['buttonmsgtooltip'], 'uploadquota' => $_POST['uploadquota'], 'downloadquota' => $_POST['downloadquota'], 'uploadbandwidth' => $_POST['uploadbandwidth'], 'downloadbandwidth' => $_POST['downloadbandwidth'], 'enabletsdns' => $_POST['enabletsdns'], 'domaintsdns' => $_POST['domaintsdns'], 'urlapi' => $_POST['urlapi'], 'keyapi' => $_POST['keyapi']))) { throw new Exception('Settings cannot be saved'); } } catch (Exception $e) { $alert['status'] = 'error'; $alert['alert'] = $e->getMessage(); } $alert['status'] = 'success'; $alert['alert'] = 'The settings have been saved'; } $update = file_get_contents('https://voice4you.org/updater/teaspeak_version.txt'); if($update != $vars['version']){ $output .= "
| # | ".$vars['_lang']['servers_name']." | ".$vars['_lang']['ip_address']." | ServerQuery Port | ".$vars['_lang']['manage']." |
|---|---|---|---|---|
| {$i} | "; $output .= "{$server->name} | "; $output .= "{$server->ipaddress} | "; $output .= "{$server->port} | "; $output .= "TeaSpeak TSDNS |
".$vars['_lang']['alert_ops_something_happened']."
{$alert['alert']}".$vars['_lang']['alert_congratulations_everything_worked']."
{$alert['alert']}".$vars['_lang']['alert_ops_something_happened']."
{$alert['alert']}".$vars['_lang']['alert_congratulations_everything_worked']."
{$alert['alert']}| # | ".$vars['_lang']['servers_name']." | ".$vars['_lang']['port']." | ".$vars['_lang']['slot']." | ".$vars['_lang']['status']." | ".$vars['_lang']['uptime']." | ".$vars['_lang']['manage']." |
|---|---|---|---|---|---|---|
| {$server['virtualserver_id']} | {$server['virtualserver_name']} | {$server['virtualserver_port']} | {$server['virtualserver_maxclients']} | " . ucfirst($server['virtualserver_status']) . " | " . $server['virtualserver_uptime'] . " | "; if ($server['virtualserver_status'] != 'online') { $output .= " ".$vars['_lang']['start'].""; } else { $output .= " ".$vars['_lang']['stop'].""; } $output .= " ".$vars['_lang']['delete'].""; $output .= " |
| ".$vars['_lang']['error_no_servers']." | ||||||
| # | ".$vars['_lang']['zone']." | ".$vars['_lang']['destination']." | ".$vars['_lang']['manage']." |
|---|---|---|---|
| {$server->id} | {$server->zone} | {$server->target} | zone) . "\" aria-expanded=\"false\" aria-controls=\"" . md5($server->zone) . "\"> ".$vars['_lang']['edit']." zone) . "\" aria-expanded=\"false\" aria-controls=\"del" . md5($server->zone) . "\"> ".$vars['_lang']['delete']." |
| ".$vars['_lang']['error_no_zones']." | |||
".$vars['_lang']['alert_ops_something_happened']."
{$alert['alert']}".$vars['_lang']['alert_congratulations_everything_worked']."
{$alert['alert']}