Guest User

Untitled

a guest
Jan 19th, 2019
1,431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. <?php
  2.  
  3. define('NB_CRONJOB', true);
  4. define('BASEDIR', dirname(__FILE__) . '/');
  5.  
  6. if (isset($_SERVER['SERVER_ADDR']))
  7. {
  8. if (!in_array($_SERVER['SERVER_ADDR'], ['127.0.0.1', '::1', 'localhost']))
  9. {
  10. die('Access deny');
  11. }
  12. }
  13.  
  14. include_once 'lib/table.php';
  15. include_once 'lib/default.php';
  16. include_once 'lib/database.php';
  17. include_once 'lib/registry.php';
  18. include_once 'lib/ts3admin.php';
  19. include_once 'lib/cache.php';
  20. include_once 'lib/tsstatus/tsstatus.php';
  21. include_once 'lib/lolapi.php';
  22.  
  23. echo '[' . date('r') . '] DEVELOPER' . PHP_EOL;
  24.  
  25. $reg = Registry::instance();
  26. $reg->config = new Table(include_once 'config.php');
  27.  
  28. try
  29. {
  30. $reg->sql = new Database($reg->config['db']['hostname'], $reg->config['db']['username'],
  31. $reg->config['db']['password'], $reg->config['db']['database']);
  32. }
  33. catch (PDOException $ex)
  34. {
  35. die('Database error: ' . $ex->getMessage());
  36. }
  37.  
  38. $ts3 = new ts3admin($reg->config['query']['hostname'],
  39. $reg->config['query']['queryport']);
  40. $ts3->connect();
  41.  
  42. if ($ts3->isConnected() == false)
  43. {
  44. die('Fatal: Failed to connect TeamSpeak3 Query!');
  45. }
  46.  
  47. if ($ts3->login($reg->config['query']['username'],
  48. $reg->config['query']['password']) == false)
  49. {
  50. die('Fatal: Failed to login to TeamSpeak3 Query!');
  51. }
  52.  
  53. if ($ts3->selectServer($reg->config['query']['loginport']) == false)
  54. {
  55. die('Fatal: Failed to select TeamSpeak3 server instance.');
  56. }
  57.  
  58. $serverinfo = ts3check($ts3->serverInfo());
  59.  
  60.  
  61. if($ts3->setName('Web <Status>') == false)
  62. {
  63. $ts3->setName('Web <Status>');
  64. }
  65.  
  66. $cache = new Cache(BASEDIR . 'lib/cache/data/');
  67.  
  68. function ts3check(array $data, $die = true)
  69. {
  70. if ($data['success'] == false)
  71. {
  72. if ($die)
  73. {
  74. die('Fatal: Failed to get data from TeamSpeak3!' . PHP_EOL . implode($data['errors'], PHP_EOL));
  75. }
  76. else
  77. {
  78. return [];
  79. }
  80. }
  81.  
  82. return $data['data'];
  83. }
  84.  
  85. // Load informations about instance
  86. $cache->set('serverinfo', $serverinfo);
  87.  
  88. // Load informations about client list
  89. $clientlist = ts3check($ts3->clientList('-uid -away -voice -times -groups -info -icon -country -ip'));
  90.  
  91. foreach ($clientlist as $k => $v)
  92. {
  93.  
  94. if ($v['client_type'] != 0)
  95. unset($clientlist[$k]);
  96. }
  97.  
  98. /////////////////////////////////////////////////////
  99.  
  100. $cache->set('clientlist', $clientlist);
  101. // [-uid] [-away] [-voice] [-times] [-groups] [-info] [-icon] [-country]
  102.  
  103. // Load informations about channel list
  104. $cache->set('channellist', ts3check($ts3->channelList()));
  105.  
  106. // Load informations about server groups
  107. $cache->set('servergrouplist', ts3check($ts3->serverGroupList()));
  108.  
  109. // Load informations about bans
  110. $cache->set('banlist', ts3check($ts3->banList(), false));
  111.  
  112.  
  113. // Generate icons
  114. include_once 'pages/cronjob/loadIcons.php';
  115.  
  116. // Generate avatars
  117. include_once 'pages/cronjob/loadAvatars.php';
  118.  
  119. // Store user informations to database
  120. $reg->sql->query('UPDATE clientinfo SET is_online = 0;');
  121. $q = $reg->sql->prepare('
  122. INSERT INTO clientinfo (database_id, unique_id, last_nickname, last_active, best_active, info, is_online, best_connections, country, client_base64HashClientUID, client_channel, timespent) VALUES
  123. (:cldbid, :uid, :nickname, NOW(), GREATEST(:best, best_active), :info, 1, :connections, :country, :client_base64HashClientUID, :client_channel, :time)
  124. ON DUPLICATE KEY UPDATE last_nickname = :nickname, last_active = :lastonline, best_active = GREATEST(:best, best_active),
  125. info = :info, is_online = 1, best_connections = :connections, country = :country, client_base64HashClientUID = :client_base64HashClientUID, client_channel = :client_channel, timespent = timespent + :time
  126. ');
  127.  
  128.  
  129. foreach ($cache->get('clientlist') as $client)
  130. {
  131.  
  132. $clientinfo = ts3check($ts3->clientInfo($client['clid']), false);
  133.  
  134. $cgroups = $ts3->channelGroupClientList(null, $clientinfo['client_database_id'], $reg->config['privateZone']['headgroup']);
  135.  
  136. if (empty($clientinfo)) continue;
  137.  
  138. $status = $q->execute([
  139. ':cldbid' => $client['client_database_id'],
  140. ':uid' => $client['client_unique_identifier'],
  141. ':nickname' => $client['client_nickname'],
  142. ':best' => $clientinfo['connection_connected_time'],
  143. ':info' => base64_encode(serialize($clientinfo)),
  144. ':time' => 1 * 60,
  145. ':lastonline' => $clientinfo['client_lastconnected'],
  146. ':connections' => $clientinfo['client_totalconnections'],
  147. ':country' => strtolower($clientinfo['client_country']),
  148. ':client_base64HashClientUID' => $clientinfo['client_base64HashClientUID'],
  149. ':client_channel' => base64_encode(serialize($cgroups['data'])),
  150. ]);
  151.  
  152. if (!$status)
  153. {
  154. var_dump($q->errorInfo());
  155. die('MySQL Error break!');
  156. }
  157. }
  158.  
  159.  
  160. // Generate channel tree HTML
  161. $tree = new TSStatus($reg->config['query']['hostname'], $reg->config['query']['queryport']);
  162. $tree->imagePath = 'images/';
  163. $tree->useServerPort($reg->config['query']['loginport']);
  164. $tree->showNicknameBox = false;
  165. $tree->setLoginPassword($reg->config['query']['username'], $reg->config['query']['password']);
  166.  
  167. $cache->set('channeltree', $tree->render());
  168.  
  169. $channelcache = new Cache(BASEDIR . 'lib/cache/channels/');
  170. foreach ($cache->get('channellist') as $channel)
  171. {
  172. $channelcache->set($channel['cid'], $tree->render($channel['cid'], 2));
  173. }
Advertisement
Add Comment
Please, Sign In to add comment