Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('NB_CRONJOB', true);
- define('BASEDIR', dirname(__FILE__) . '/');
- if (isset($_SERVER['SERVER_ADDR']))
- {
- if (!in_array($_SERVER['SERVER_ADDR'], ['127.0.0.1', '::1', 'localhost']))
- {
- die('Access deny');
- }
- }
- include_once 'lib/table.php';
- include_once 'lib/default.php';
- include_once 'lib/database.php';
- include_once 'lib/registry.php';
- include_once 'lib/ts3admin.php';
- include_once 'lib/cache.php';
- include_once 'lib/tsstatus/tsstatus.php';
- include_once 'lib/lolapi.php';
- echo '[' . date('r') . '] DEVELOPER' . PHP_EOL;
- $reg = Registry::instance();
- $reg->config = new Table(include_once 'config.php');
- try
- {
- $reg->sql = new Database($reg->config['db']['hostname'], $reg->config['db']['username'],
- $reg->config['db']['password'], $reg->config['db']['database']);
- }
- catch (PDOException $ex)
- {
- die('Database error: ' . $ex->getMessage());
- }
- $ts3 = new ts3admin($reg->config['query']['hostname'],
- $reg->config['query']['queryport']);
- $ts3->connect();
- if ($ts3->isConnected() == false)
- {
- die('Fatal: Failed to connect TeamSpeak3 Query!');
- }
- if ($ts3->login($reg->config['query']['username'],
- $reg->config['query']['password']) == false)
- {
- die('Fatal: Failed to login to TeamSpeak3 Query!');
- }
- if ($ts3->selectServer($reg->config['query']['loginport']) == false)
- {
- die('Fatal: Failed to select TeamSpeak3 server instance.');
- }
- $serverinfo = ts3check($ts3->serverInfo());
- if($ts3->setName('Web <Status>') == false)
- {
- $ts3->setName('Web <Status>');
- }
- $cache = new Cache(BASEDIR . 'lib/cache/data/');
- function ts3check(array $data, $die = true)
- {
- if ($data['success'] == false)
- {
- if ($die)
- {
- die('Fatal: Failed to get data from TeamSpeak3!' . PHP_EOL . implode($data['errors'], PHP_EOL));
- }
- else
- {
- return [];
- }
- }
- return $data['data'];
- }
- // Load informations about instance
- $cache->set('serverinfo', $serverinfo);
- // Load informations about client list
- $clientlist = ts3check($ts3->clientList('-uid -away -voice -times -groups -info -icon -country -ip'));
- foreach ($clientlist as $k => $v)
- {
- if ($v['client_type'] != 0)
- unset($clientlist[$k]);
- }
- /////////////////////////////////////////////////////
- $cache->set('clientlist', $clientlist);
- // [-uid] [-away] [-voice] [-times] [-groups] [-info] [-icon] [-country]
- // Load informations about channel list
- $cache->set('channellist', ts3check($ts3->channelList()));
- // Load informations about server groups
- $cache->set('servergrouplist', ts3check($ts3->serverGroupList()));
- // Load informations about bans
- $cache->set('banlist', ts3check($ts3->banList(), false));
- // Generate icons
- include_once 'pages/cronjob/loadIcons.php';
- // Generate avatars
- include_once 'pages/cronjob/loadAvatars.php';
- // Store user informations to database
- $reg->sql->query('UPDATE clientinfo SET is_online = 0;');
- $q = $reg->sql->prepare('
- 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
- (:cldbid, :uid, :nickname, NOW(), GREATEST(:best, best_active), :info, 1, :connections, :country, :client_base64HashClientUID, :client_channel, :time)
- ON DUPLICATE KEY UPDATE last_nickname = :nickname, last_active = :lastonline, best_active = GREATEST(:best, best_active),
- info = :info, is_online = 1, best_connections = :connections, country = :country, client_base64HashClientUID = :client_base64HashClientUID, client_channel = :client_channel, timespent = timespent + :time
- ');
- foreach ($cache->get('clientlist') as $client)
- {
- $clientinfo = ts3check($ts3->clientInfo($client['clid']), false);
- $cgroups = $ts3->channelGroupClientList(null, $clientinfo['client_database_id'], $reg->config['privateZone']['headgroup']);
- if (empty($clientinfo)) continue;
- $status = $q->execute([
- ':cldbid' => $client['client_database_id'],
- ':uid' => $client['client_unique_identifier'],
- ':nickname' => $client['client_nickname'],
- ':best' => $clientinfo['connection_connected_time'],
- ':info' => base64_encode(serialize($clientinfo)),
- ':time' => 1 * 60,
- ':lastonline' => $clientinfo['client_lastconnected'],
- ':connections' => $clientinfo['client_totalconnections'],
- ':country' => strtolower($clientinfo['client_country']),
- ':client_base64HashClientUID' => $clientinfo['client_base64HashClientUID'],
- ':client_channel' => base64_encode(serialize($cgroups['data'])),
- ]);
- if (!$status)
- {
- var_dump($q->errorInfo());
- die('MySQL Error break!');
- }
- }
- // Generate channel tree HTML
- $tree = new TSStatus($reg->config['query']['hostname'], $reg->config['query']['queryport']);
- $tree->imagePath = 'images/';
- $tree->useServerPort($reg->config['query']['loginport']);
- $tree->showNicknameBox = false;
- $tree->setLoginPassword($reg->config['query']['username'], $reg->config['query']['password']);
- $cache->set('channeltree', $tree->render());
- $channelcache = new Cache(BASEDIR . 'lib/cache/channels/');
- foreach ($cache->get('channellist') as $channel)
- {
- $channelcache->set($channel['cid'], $tree->render($channel['cid'], 2));
- }
Advertisement
Add Comment
Please, Sign In to add comment