ts3webinterface.class.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. <?php
  2. /**
  3. * ts3webinterface.class.php <br />
  4. * ------------------------- <br />
  5. * begin : Sunday, Dec 24, 2009 <br />
  6. * copyright : (C) 2009-2010 RK Programming <br />
  7. * email : [email protected] <br />
  8. * version : 0.3.6 <br />
  9. * last modified : Tuesday, Dec 29, 2009 <br />
  10. *
  11. * @author RK Programming <[email protected]>
  12. * @copyright Copyright (c) 2009-2010, Robin K.
  13. * @version 0.3.6
  14. TS3webinterface is free software. You can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation, version 1.3.
  17. **/
  18. define('TS3WEBINTERFACE_VERSION', '0.3.6');
  19. require_once('ts3remote.class.php');
  20. function getAssignedServerUsers()
  21. {
  22. global $db;
  23. $ts3vservers = $db->resultQuery("SELECT * FROM OGP_DB_PREFIXts3_homes
  24. WHERE vserver_id='".
  25. TS3WEBINTERFACE_VSERVER_ID."' AND rserver_id=".
  26. $_SESSION['rserver_id'] );
  27. if($ts3vservers != FALSE)
  28. {
  29. $users_assigned = array();
  30. foreach($ts3vservers as $ts3vserver)
  31. {
  32. if($ts3vserver['user_id'] != $_SESSION['user_id'])
  33. $users_assigned[] = $ts3vserver['user_id'];
  34. }
  35. }
  36. $subusers = $db->getUsersSubUsersIds($_SESSION['user_id']);
  37. $subusersb = array();
  38. $subusers_list = array();
  39. if(is_array($subusers))
  40. {
  41. foreach($subusers as $subuser)
  42. {
  43. if(!in_array($subuser,$users_assigned))
  44. $subusers_list[] = $db->getUserById($subuser);
  45. $subusersb[] = $subuser;
  46. }
  47. if(empty($subusers_list))
  48. $subusers_list = FALSE;
  49. }
  50. if(is_array($users_assigned))
  51. {
  52. $subusers_assigned_list = array();
  53. foreach($users_assigned as $user_assigned)
  54. {
  55. if(in_array($user_assigned,$subusersb))
  56. $subusers_assigned_list[] = $db->getUserById($user_assigned);
  57. }
  58. if(empty($subusers_assigned_list))
  59. $subusers_assigned_list = FALSE;
  60. }
  61. return array('users_assigned' => $users_assigned,
  62. 'subusers' => $subusersb,
  63. 'subusers_assigned_list' => $subusers_assigned_list,
  64. 'subusers_list' => $subusers_list);
  65. }
  66. class TS3webinterface
  67. {
  68. private $serverIP;
  69. private $serverPort;
  70. private $server;
  71. private $errorString;
  72. private $session;
  73. private $template;
  74. private $language;
  75. function __construct($ip, $port)
  76. {
  77. global $db;
  78. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  79. $this->loadLanguage();
  80. $this->server = new TS3remote($ip, $port);
  81. // CHECK IF CONNECTED
  82. $tmpConnectError = $this->server->getError();
  83. if( !empty($tmpConnectError) )
  84. {
  85. die($this->language['error'].' '.$tmpConnectError[1].': '.$tmpConnectError[2]);
  86. }
  87. $this->server->r_clientupdate(array(array('client_nickname', 'TS3webinterface Client | by Prookie')));
  88. $this->server->setDeEscapeResults(true);
  89. $this->template = null;
  90. $this->serverIP = $ip;
  91. $this->serverPort = $port;
  92. $this->errorString = '';
  93. $this->session = $_SESSION;
  94. if( !isset($this->session['loggedin']) ) $this->session['loggedin'] = false;
  95. if( !isset($this->session['lvserver']) ) $this->session['lvserver'] = 0;
  96. if( !isset($this->session['luser']) ) $this->session['luser'] = '';
  97. if( !isset($this->session['lpwd']) ) $this->session['lpwd'] = '';
  98. if( !isset($this->session['lastaction']) ) $this->session['lastaction'] = 0;
  99. $user = TS3WEBINTERFACE_NAME;
  100. $password = TS3WEBINTERFACE_PWD;
  101. if( !empty($user) && !empty($password) )
  102. {
  103. if( $this->checkLoginData(TS3WEBINTERFACE_NAME, TS3WEBINTERFACE_PWD) )
  104. {
  105. $this->session['loggedin'] = true;
  106. $this->session['luser'] = TS3WEBINTERFACE_NAME;
  107. $this->session['lpwd'] = TS3WEBINTERFACE_PWD;
  108. if ( !$isAdmin )
  109. $this->session['lvserver'] = TS3WEBINTERFACE_VSERVER_ID;
  110. $this->session['lastaction'] = time();
  111. }
  112. }
  113. if( $isAdmin AND isset( $_GET['changevServer'] ) )
  114. {
  115. $this->session['lvserver'] = 0;
  116. }
  117. else if( $isAdmin AND isset( $_POST['vserverSubmit'] ) && !empty( $_POST['vserver'] ) )
  118. {
  119. $this->session['lvserver'] = $_POST['vserver'];
  120. }
  121. if( $this->checkSession() )
  122. {
  123. if( !$this->login() )
  124. {
  125. echo 'TS3webinterface ERROR: '.$this->errorString;
  126. $this->renewSession();
  127. }
  128. else
  129. {
  130. $this->switchAction();
  131. }
  132. }
  133. else
  134. {
  135. $this->initSmarty();
  136. $this->template->assign('title', $this->language['title'].' :: Login');
  137. $this->template->display('header.tpl');
  138. $this->template->display('loginForm.tpl');
  139. $this->template->display('footer.tpl');
  140. }
  141. $this->server->disconnect();
  142. }
  143. function __destruct()
  144. {
  145. $_SESSION = $this->session;
  146. }
  147. private function initSmarty()
  148. {
  149. require_once('smarty/Smarty.class.php');
  150. $this->template = new Smarty();
  151. $this->template->compile_check = true;
  152. $this->template->debugging = false;
  153. $this->template->template_dir = dirname(__FILE__) .'/templates';
  154. $this->template->compile_dir = dirname(__FILE__) .'/templates_c';
  155. if( is_array($this->language) )
  156. {
  157. $this->template->assign('lang', $this->language);
  158. }
  159. else
  160. {
  161. die('TS3webinterface ERROR: no language file available');
  162. }
  163. $this->template->assign_by_ref('webinterface', $this, array('parseTime', 'parseDate', 'convertByteToMB', 'convertByteToKB'));
  164. }
  165. private function loadLanguage($lang=false)
  166. {
  167. $constants = get_defined_constants(true);
  168. $this->language = $constants['user'];
  169. }
  170. public function getError()
  171. {
  172. $tmp = $this->errorString;
  173. $this->errorString = '';
  174. return $tmp;
  175. }
  176. private function renewSession()
  177. {
  178. $this->session['loggedin'] = false;
  179. $this->session['lvserver'] = 0;
  180. $this->session['luser'] = '';
  181. $this->session['lpwd'] = '';
  182. $this->session['lastaction'] = 0;
  183. }
  184. private function checkSession()
  185. {
  186. if( $this->session['loggedin'] === true && $this->session['luser'] != '' &&
  187. $this->session['lpwd'] != '' && (time()-1800 < $this->session['lastaction']) )
  188. {
  189. $this->session['lastaction'] = time();
  190. return true;
  191. }
  192. else if( time()-1800 <= $this->session['lastaction'] )
  193. {
  194. $this->errorString .= '['.$this->language['e_session_timedout'].']';
  195. $this->renewSession();
  196. return false;
  197. }
  198. else
  199. {
  200. $this->renewSession();
  201. return false;
  202. }
  203. }
  204. private function checkLoginData($user, $pwd, $vserver=false)
  205. {
  206. if( !$this->server->isConnected() ) return false;
  207. if( $vserver )
  208. {
  209. if( !$this->server->r_use($vserver) )
  210. {
  211. $this->errorString .= '['.$this->language['e_conn_vserver'].']';
  212. return false;
  213. }
  214. }
  215. if( !$this->server->r_login($user, $pwd) )
  216. {
  217. $this->errorString .= '['.$this->language['e_conn_serverquery'].']';
  218. return false;
  219. }
  220. return true;
  221. }
  222. private function login($vserver=true)
  223. {
  224. if( !$this->server->isConnected() ) return false;
  225. if( $vserver )
  226. {
  227. if( !$this->server->r_use($this->session['lvserver']) )
  228. {
  229. $this->errorString .= '['.$this->language['e_conn_vserver'].']';
  230. return false;
  231. }
  232. }
  233. if( !$this->server->r_login($this->session['luser'], $this->session['lpwd']) )
  234. {
  235. $this->errorString .= '['.$this->language['e_conn_serverquery'].']';
  236. return false;
  237. }
  238. return true;
  239. }
  240. private function switchAction()
  241. {
  242. global $db;
  243. if( isset($_GET['getchannelbackup']) && $this->session['lvserver'] != 0 )
  244. {
  245. if( $channelBackupString = $this->getChannelBackupString() )
  246. {
  247. header('Content-Disposition: attachment; filename="ts3wi_channelbackup_vserver'.$this->session['lvserver'].'.txt"');
  248. header('Content-Type: x-type/subtype');
  249. echo $channelBackupString;
  250. }
  251. $this->server->disconnect();
  252. exit();
  253. }
  254. if( isset($_POST['ajaxRequest']) )
  255. {
  256. $response = '';
  257. switch($_POST['do'])
  258. {
  259. case 'serveredit':
  260. if( !empty($_POST['serverprop']) && isset($_POST['value']) )
  261. {
  262. if( $this->server->r_serveredit(array(array($_POST['serverprop'], $_POST['value']))) )
  263. {
  264. $response = array('OK', $_POST['serverprop'], $_POST['value']);
  265. }
  266. else
  267. {
  268. $error = $this->server->getError();
  269. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  270. if( $resolvedError = $this->resolveErrorID($error[2]) )
  271. {
  272. $response[2] .= "\n\n".$resolvedError;
  273. }
  274. }
  275. }
  276. else
  277. {
  278. $response = array('ERROR', 2, 'missing arguments');
  279. }
  280. break;
  281. case 'serverupdate':
  282. if( !empty($_POST['serverprop']) )
  283. {
  284. if( $tmp = $this->server->r_serverinfo() )
  285. {
  286. $tmp = $tmp[0];
  287. $response = array('OK');
  288. if( !is_array($_POST['serverprop']) ) $_POST['serverprop'] = array($_POST['serverprop']);
  289. for($i=0; $i<count($_POST['serverprop']); $i++)
  290. {
  291. if( $_POST['serverprop'][$i] == 'virtualserver_uptime' )
  292. {
  293. $tmp[$_POST['serverprop'][$i]] = $this->parseTime($tmp[$_POST['serverprop'][$i]]);
  294. }
  295. else if( $_POST['serverprop'][$i] == 'connection_bytes_sent_total' || $_POST['serverprop'][$i] == 'connection_bytes_received_total' )
  296. {
  297. $tmp[$_POST['serverprop'][$i]] = $this->convertByteToMB($tmp[$_POST['serverprop'][$i]]);
  298. }
  299. else if( $_POST['serverprop'][$i] == 'connection_bandwidth_sent_last_second_total' || $_POST['serverprop'][$i] == 'connection_bandwidth_received_last_second_total'
  300. || $_POST['serverprop'][$i] == 'connection_bandwidth_sent_last_minute_total' || $_POST['serverprop'][$i] == 'connection_bandwidth_received_last_minute_total' )
  301. {
  302. $tmp[$_POST['serverprop'][$i]] = $this->convertByteToKB($tmp[$_POST['serverprop'][$i]]);
  303. }
  304. $response[] = array($_POST['serverprop'][$i], $tmp[$_POST['serverprop'][$i]]);
  305. }
  306. }
  307. else
  308. {
  309. $error = $this->server->getError();
  310. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  311. }
  312. }
  313. else
  314. {
  315. $response = array('ERROR', 2, 'missing arguments');
  316. }
  317. break;
  318. case 'startserver':
  319. case 'stopserver':
  320. if( !empty($_POST['serverid']) )
  321. {
  322. $actionDone = '';
  323. if( $_POST['do'] == 'startserver' )
  324. {
  325. $tmp = $this->server->r_serverstart($_POST['serverid']);
  326. $actionDone = 'serverstart';
  327. }
  328. else if( $_POST['do'] == 'stopserver' )
  329. {
  330. $tmp = $this->server->r_serverstop($_POST['serverid']);
  331. $actionDone = 'serverstop';
  332. }
  333. if( $tmp )
  334. {
  335. $response = array('OK', $_POST['serverid'], $actionDone);
  336. }
  337. else
  338. {
  339. $error = $this->server->getError();
  340. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  341. }
  342. }
  343. else
  344. {
  345. $response = array('ERROR', 2, 'missing arguments');
  346. }
  347. break;
  348. case 'deleteserver':
  349. if( !empty($_POST['serverid']) )
  350. {
  351. $this->server->r_serverstop($_POST['serverid']);
  352. if( $this->server->r_serverdelete($_POST['serverid']) )
  353. {
  354. $response = array('OK', $_POST['serverid'], 'serverdelete');
  355. }
  356. else
  357. {
  358. $error = $this->server->getError();
  359. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  360. }
  361. }
  362. else
  363. {
  364. $response = array('ERROR', 2, 'missing arguments');
  365. }
  366. break;
  367. case 'deletetoken':
  368. if( !empty($_POST['token']) )
  369. {
  370. if( $this->server->r_tokendelete($_POST['token']) )
  371. {
  372. $response = array('OK', $_POST['token']);
  373. }
  374. else
  375. {
  376. $error = $this->server->getError();
  377. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  378. }
  379. }
  380. else
  381. {
  382. $response = array('ERROR', 2, 'missing arguments');
  383. }
  384. break;
  385. case 'serverviewupdate':
  386. $this->initSmarty();
  387. $this->template->assign('serverTree', $this->getLiveview());
  388. $this->template->display('liveview.tpl');
  389. break;
  390. case 'clientkick':
  391. if( !empty($_POST['clid']) )
  392. {
  393. if( $this->server->r_clientkick($_POST['clid']) )
  394. {
  395. $response = array('OK', $_POST['clid']);
  396. }
  397. else
  398. {
  399. $error = $this->server->getError();
  400. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  401. }
  402. }
  403. else
  404. {
  405. $response = array('ERROR', 2, 'missing arguments');
  406. }
  407. break;
  408. case 'clientban':
  409. if( isset($_POST['clid']) && isset($_POST['duration']) && isset($_POST['reason']) )
  410. {
  411. if( $this->server->r_banclient($_POST['clid'], $_POST['duration'], $_POST['reason']) )
  412. {
  413. $response = array('OK', $_POST['clid']);
  414. }
  415. else
  416. {
  417. $error = $this->server->getError();
  418. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  419. }
  420. }
  421. else
  422. {
  423. $response = array('ERROR', 2, 'missing arguments');
  424. }
  425. break;
  426. case 'clientmove':
  427. if( !empty($_POST['clid']) && !empty($_POST['cid']) )
  428. {
  429. if( $this->server->r_clientmove($_POST['clid'], $_POST['cid']) )
  430. {
  431. $response = array('OK', $_POST['clid'], $_POST['cid']);
  432. }
  433. else
  434. {
  435. $error = $this->server->getError();
  436. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  437. }
  438. }
  439. else
  440. {
  441. $response = array('ERROR', 2, 'missing arguments');
  442. }
  443. break;
  444. case 'clientpoke':
  445. if( !empty($_POST['clid']) && isset($_POST['msg']) )
  446. {
  447. if( $this->server->r_clientpoke($_POST['clid'], $_POST['msg']) )
  448. {
  449. $response = array('OK', $_POST['clid']);
  450. }
  451. else
  452. {
  453. $error = $this->server->getError();
  454. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  455. }
  456. }
  457. else
  458. {
  459. $response = array('ERROR', 2, 'missing arguments');
  460. }
  461. break;
  462. case 'clientmsg':
  463. if( !empty($_POST['cid']) && !empty($_POST['mode']) && isset($_POST['msg']) )
  464. {
  465. if( $this->server->r_sendtextmessage($_POST['mode'], $_POST['cid'], $_POST['msg']) )
  466. {
  467. $response = array('OK', $_POST['cid'], $_POST['mode']);
  468. }
  469. else
  470. {
  471. $error = $this->server->getError();
  472. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  473. }
  474. }
  475. else
  476. {
  477. $response = array('ERROR', 2, 'missing arguments');
  478. }
  479. break;
  480. case 'deleteban':
  481. if( !empty($_POST['banid']) )
  482. {
  483. if( $this->server->r_bandel($_POST['banid']) )
  484. {
  485. $response = array('OK', $_POST['banid']);
  486. }
  487. else
  488. {
  489. $error = $this->server->getError();
  490. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  491. }
  492. }
  493. else
  494. {
  495. $response = array('ERROR', 2, 'missing arguments');
  496. }
  497. break;
  498. case 'addban':
  499. if( isset($_POST['ip']) && isset($_POST['name']) && isset($_POST['uid']) && isset($_POST['reason']) && isset($_POST['duration']) )
  500. {
  501. if( $this->server->r_banadd($_POST['ip'], $_POST['name'], $_POST['uid'], $_POST['duration'], $_POST['reason']) )
  502. {
  503. $response = array('OK');
  504. }
  505. else
  506. {
  507. $error = $this->server->getError();
  508. $response = array('ERROR', $error[2], $this->language['n_server_responded'].' '.$error[3]);
  509. }
  510. }
  511. else
  512. {
  513. $response = array('ERROR', 2, 'missing arguments');
  514. }
  515. break;
  516. case 'banlistupdate':
  517. $this->initSmarty();
  518. if( is_array($this->language) )
  519. $this->template->assign('lang', $this->language);
  520. else
  521. die('TS3webinterface ERROR: no language file available');
  522. $this->template->assign('banList', $this->server->r_banlist());
  523. $this->template->display('banlist.tpl');
  524. break;
  525. default:
  526. $response = array('ERROR', 1, 'unknown action requested');
  527. }
  528. if( !empty($response) )
  529. echo json_encode($response);
  530. }
  531. else
  532. {
  533. // normal
  534. $this->initSmarty();
  535. if( $this->session['lvserver'] == 0 )
  536. {
  537. $this->template->display('header.tpl');
  538. $addData = array();
  539. if( isset($_GET['do']) && $_GET['do'] == 'addserver' )
  540. {
  541. if( isset($_POST['serverAddSubmit']) && !empty($_POST['servername']) && !empty($_POST['serverslots']) )
  542. {
  543. if( $addData = $this->server->r_servercreate($_POST['servername'], array(array('virtualserver_maxclients', $_POST['serverslots']))) )
  544. {
  545. $addData = $addData[0];
  546. array_unshift($addData, 'OK');
  547. }
  548. else
  549. {
  550. $error = $this->server->getError();
  551. $addData = array('ERROR', $error[2], $this->language['n_server_responded'].$error[3]);
  552. }
  553. }
  554. else
  555. {
  556. $addData = array('ERROR', 0, $this->language['e_fill_out']);
  557. }
  558. }
  559. $vServerList = $this->server->r_serverlist();
  560. if( !isset($vServerList[0]) )
  561. {
  562. $tmp = array($vServerList);
  563. $vServerList = $tmp;
  564. }
  565. $getPublicIp = $db->resultQuery("SELECT display_public_ip FROM OGP_DB_PREFIXremote_servers WHERE remote_server_id=".$_SESSION['rserver_id']);
  566. if($getPublicIp){
  567. $display_ip = checkDisplayPublicIP($getPublicIp[0]['display_public_ip'],$this->serverIP);
  568. }else{
  569. $display_ip = $this->serverIP;
  570. }
  571. $this->template->assign('IP', $this->serverIP);
  572. $this->template->assign('display_public_ip', $display_ip);
  573. $this->template->assign('selectvServer', $vServerList);
  574. $this->template->assign('addData', $addData);
  575. $updateAvailable = $this->checkForUpdate();
  576. $this->template->assign('updateAvailable', $updateAvailable);
  577. if( $updateAvailable != "" )
  578. {
  579. $this->template->display('updateAvailable.tpl');
  580. }
  581. $this->template->display('selectvServer.tpl');
  582. $this->template->display('footer.tpl');
  583. }
  584. else
  585. {
  586. if( isset($_GET['liveview']) ) $this->template->assign('liveviewAutoUpdate', true);
  587. else $this->template->assign('liveviewAutoUpdate', false);
  588. $this->template->display('header.tpl');
  589. $updateAvailable = $this->checkForUpdate();
  590. $this->template->assign('updateAvailable', $updateAvailable);
  591. if( $updateAvailable != "" )
  592. {
  593. $this->template->display('updateAvailable.tpl');
  594. }
  595. $infoBoxData = $this->server->r_serverinfo();
  596. $this->template->assign('data', $infoBoxData[0]);
  597. if( isset($_GET['token']) )
  598. {
  599. $addToken = array();
  600. if( isset($_GET['do']) && $_GET['do'] == 'addtoken' )
  601. {
  602. $tokenid1 = false;
  603. $tokenid2 = false;
  604. if( isset($_POST['tokentype']) )
  605. {
  606. switch((int)$_POST['tokentype'])
  607. {
  608. case 0:
  609. if( !isset($_POST['tokenid1_0']) ) break;
  610. $tokenid1 = $_POST['tokenid1_0'];
  611. $tokenid2 = 0;
  612. break;
  613. case 1:
  614. if( !isset($_POST['tokenid1_1']) || !isset($_POST['tokenid2_1']) ) break;
  615. $tokenid1 = $_POST['tokenid1_1'];
  616. $tokenid2 = $_POST['tokenid2_1'];
  617. break;
  618. }
  619. }
  620. if( $tokenid1 !== false )
  621. {
  622. if( $this->server->r_tokenadd($_POST['tokentype'], $tokenid1, $tokenid2) )
  623. {
  624. $addToken = array('OK');
  625. }
  626. else
  627. {
  628. $error = $this->server->getError();
  629. $addToken = array('ERROR', $error[2], $this->language['n_server_responded'].$error[3]);
  630. }
  631. }
  632. else
  633. {
  634. $addToken = array('ERROR', 0, $this->language['e_fill_out']);
  635. }
  636. }
  637. $this->template->assign('addToken', $addToken);
  638. $this->template->assign('tokenList', $this->server->r_tokenlist());
  639. $serverGroupList = $this->server->r_servergrouplist();
  640. $serverGroupListNames = array();
  641. for($i=0; $i<count($serverGroupList); $i++)
  642. {
  643. $serverGroupListNames[$serverGroupList[$i]['sgid']] = $serverGroupList[$i];
  644. }
  645. $this->template->assign('serverGroupList', $serverGroupList);
  646. $this->template->assign('serverGroupListNames', $serverGroupListNames);
  647. $channelGroupList = $this->server->r_channelgrouplist();
  648. $channelGroupListNames = array();
  649. for($i=0; $i<count($channelGroupList); $i++)
  650. {
  651. $channelGroupListNames[$channelGroupList[$i]['cgid']] = $channelGroupList[$i];
  652. }
  653. $this->template->assign('channelGroupList', $channelGroupList);
  654. $this->template->assign('channelGroupListNames', $channelGroupListNames);
  655. $channelList = $this->server->r_channellist();
  656. $channelListNames = array();
  657. for($i=0; $i<count($channelList); $i++)
  658. {
  659. $channelListNames[$channelList[$i]['cid']] = $channelList[$i];
  660. }
  661. $this->template->assign('channelList', $channelList);
  662. $this->template->assign('channelListNames', $channelListNames);
  663. $this->template->display('vServerToken.tpl');
  664. }
  665. else if( isset($_GET['liveview']) )
  666. {
  667. $insertResult = array();
  668. if( isset($_FILES['backup']) )
  669. {
  670. $insertResult = array('ERROR', 0, $this->language['e_upload_failed']);
  671. $filename = 'modules/TS3Admin/templates_c/channelbackup_'.rand(111,999).rand(111,999).'.txt';
  672. if( $_FILES['backup']['error'] == 0 && move_uploaded_file($_FILES['backup']['tmp_name'], $filename) )
  673. {
  674. if( $this->insertChannelBackup(file_get_contents($filename)) )
  675. {
  676. $insertResult = array('OK');
  677. }
  678. unlink($filename);
  679. }
  680. }
  681. $this->template->assign('insertResult', $insertResult);
  682. $this->template->assign('serverTree', $this->getLiveview($infoBoxData[0])); // serverinfo param for no double query
  683. $this->template->assign('banList', $this->server->r_banlist());
  684. $this->template->display('vServerLiveview.tpl');
  685. }
  686. else
  687. {
  688. global $db;
  689. $is_parent_user = FALSE;
  690. $subusers_installed = $db->isModuleInstalled('subusers');
  691. if( $subusers_installed )
  692. {
  693. if(defined('TS3WEBINTERFACE_VSERVER_ID'))
  694. $assigned_info = getAssignedServerUsers();
  695. if( isset($_POST['assign_subuser']) and
  696. in_array($_POST['user_id'],$assigned_info['subusers']) )
  697. {
  698. $db->query("INSERT INTO OGP_DB_PREFIXts3_homes
  699. (`rserver_id`, `ip`, `pwd`, `vserver_id`, `user_id`)
  700. VALUES ('".$_SESSION['rserver_id']."', '".
  701. TS3WEBINTERFACE_IP."', '".
  702. TS3WEBINTERFACE_PWD."', '".
  703. TS3WEBINTERFACE_VSERVER_ID."', '".
  704. $_POST['user_id'].
  705. "');");
  706. $assigned_info = getAssignedServerUsers();
  707. }
  708. if( isset($_POST['unassign_subuser']) and
  709. is_array($assigned_info['subusers']) and
  710. in_array($_POST['user_id'],$assigned_info['users_assigned']) and
  711. in_array($_POST['user_id'],$assigned_info['subusers']) )
  712. {
  713. $db->query( "DELETE FROM OGP_DB_PREFIXts3_homes WHERE vserver_id='".
  714. TS3WEBINTERFACE_VSERVER_ID."' AND user_id='".
  715. $_POST['user_id']."' AND rserver_id='".
  716. $_SESSION['rserver_id'].
  717. "';" );
  718. $assigned_info = getAssignedServerUsers();
  719. }
  720. if(defined('TS3WEBINTERFACE_VSERVER_ID'))
  721. {
  722. $this->template->assign('subusers_assigned', $assigned_info['subusers_assigned_list']);
  723. $this->template->assign('subusers', $assigned_info['subusers_list']);
  724. $is_parent_user = is_array($assigned_info['subusers']);
  725. }
  726. }
  727. $this->template->assign('is_parent_user', $is_parent_user);
  728. $this->template->assign('subusers_installed', $subusers_installed);
  729. $getPublicIp = $db->resultQuery("SELECT display_public_ip FROM OGP_DB_PREFIXremote_servers WHERE remote_server_id=".$_SESSION['rserver_id']);
  730. if($getPublicIp){
  731. $display_ip = checkDisplayPublicIP($getPublicIp[0]['display_public_ip'],$this->serverIP);
  732. }else{
  733. $display_ip = $this->serverIP;
  734. }
  735. $this->template->assign('display_public_ip', $display_ip);
  736. $this->template->assign('IP', $this->serverIP);
  737. $this->template->display('vServerOverview.tpl');
  738. }
  739. $this->template->display('footer.tpl');
  740. }
  741. }
  742. }
  743. private function getLiveview($server=false)
  744. {
  745. if( !$server )
  746. {
  747. $server = $this->server->r_serverinfo();
  748. if( !$server )
  749. {
  750. $errArray = $this->server->getError();
  751. echo strtoupper($this->language['error']).' #'.$errArray[2].': '.$this->language['n_server_responded'].' \''.$errArray[3].'\'';
  752. return false;
  753. }
  754. $server = $server[0];
  755. }
  756. else
  757. {
  758. if( !empty($server[0]) )
  759. $server = $server[0];
  760. }
  761. $channels = $this->server->r_channellist(true, true, true, true);
  762. if( !$channels )
  763. {
  764. $errArray = $this->server->getError();
  765. echo strtoupper($this->language['error']).' #'.$errArray[2].': '.$this->language['n_server_responded'].' \''.$errArray[3].'\'';
  766. return false;
  767. }
  768. $clients = $this->server->r_clientlist(true, true, true, true, true);
  769. if( !$clients )
  770. {
  771. $errArray = $this->server->getError();
  772. echo strtoupper($this->language['error']).' #'.$errArray[2].': '.$this->language['n_server_responded'].' \''.$errArray[3].'\'';
  773. return false;
  774. }
  775. function sortClients($a, $b)
  776. {
  777. if( strpos(',', $a['client_servergroups']) !== false )
  778. {
  779. $aID = explode(',', $a['client_servergroups'], 2);
  780. $aID = $aID[0];
  781. }
  782. else
  783. {
  784. $aID = $a['client_servergroups'];
  785. }
  786. if( strpos(',', $b['client_servergroups']) !== false )
  787. {
  788. $bID = explode(',', $b['client_servergroups'], 2);
  789. $bID = $bID[0];
  790. }
  791. else
  792. {
  793. $bID = $b['client_servergroups'];
  794. }
  795. if( $aID > $bID ) return 1;
  796. if( $aID < $bID ) return -1;
  797. if( $aID = $bID ) return 0;
  798. }
  799. usort($clients, "sortClients");
  800. $pidStack = array(0);
  801. $lastLevel = array();
  802. $cidConnection = array();
  803. $channelNum = count($channels);
  804. for($i=0; $i<$channelNum; $i++)
  805. {
  806. $cidConnection[$channels[$i]['cid']] = $i;
  807. $channels[$i]['is_last_channel'] = false;
  808. /*if( $channels[$i]['pid'] != $pidStack[count($pidStack)-1] )
  809. {
  810. if( in_array($channels[$i]['pid'], $pidStack) )
  811. {
  812. do
  813. {
  814. array_pop($pidStack);
  815. } while( in_array($channels[$i]['pid'], $pidStack) && count($pidStack) > 1 );
  816. //$pidStack[] = $channels[$i]['pid'];
  817. $channels[$i]['is_last_channel'] = true;
  818. }
  819. else
  820. {
  821. $pidStack[] = $channels[$i]['pid'];
  822. }
  823. }*/
  824. //$channels[$i]['level'] = count($pidStack)-1;
  825. if( $channels[$i]['pid'] == 0 ) $channels[$i]['level'] = 0;
  826. else $channels[$i]['level'] = $channels[$cidConnection[$channels[$i]['pid']]]['level'] + 1;
  827. $channels[$i]['is_server'] = false;
  828. $channels[$i]['clients'] = array();
  829. $lastLevel[$channels[$i]['level']] = $i;
  830. }
  831. /*$reversedCounter = count($channels)-1;
  832. do
  833. {
  834. if( $channels[$reversedCounter]['pid'] == 0 )
  835. {
  836. $channels[$reversedCounter]['is_last_channel'] = true;
  837. break;
  838. }
  839. $reversedCounter--;
  840. } while( $reversedCounter >= 0 );*/
  841. for($i=0; $i<$channelNum; $i++)
  842. {
  843. if( !isset($channels[$i-1]) && !isset($channels[$i+1]) )
  844. {
  845. $channels[$i]['mode'] = 'l';
  846. //continue;
  847. }
  848. else if( isset($channels[$i-1]) && !isset($channels[$i+1]) )
  849. {
  850. $channels[$i]['mode'] = 'l';
  851. //continue;
  852. }
  853. else if( !isset($channels[$i-1]) && isset($channels[$i+1]) )
  854. {
  855. $channels[$i]['mode'] = 't';
  856. //continue;
  857. }
  858. else if( $channels[$i]['level'] == $channels[$i+1]['level'] )
  859. {
  860. $channels[$i]['mode'] = 't';
  861. }
  862. else if( $channels[$i]['level'] > $channels[$i+1]['level'] )
  863. {
  864. $channels[$i]['mode'] = 'l';
  865. }
  866. else
  867. {
  868. if( $lastLevel[$channels[$i]['level']] == $i )
  869. {
  870. $channels[$i]['mode'] = 'l';
  871. }
  872. else
  873. {
  874. $channels[$i]['mode'] = 't';
  875. }
  876. }
  877. //$channels[$i]['TEST'] = $i;
  878. if( $channels[$i]['pid'] != 0 )
  879. {
  880. $before = array();
  881. //$subtractLevels = 0;
  882. //$tmp = $channels[$cidConnection[$channels[$i]['pid']]];
  883. //$tmpPID = $channels[$i]['pid'];
  884. //echo $tmpPID.' ';
  885. $tmp = $channels[$cidConnection[$channels[$i]['pid']]];
  886. //echo $channels[$i]['pid'].'='.$cidConnection[$channels[$i]['pid']].' ';
  887. //var_dump($channels[$cidConnection[$channels[$i]['pid']]]['is_last_channel']);
  888. $tmpPID = $channels[$i]['pid'];
  889. //if( $tmp['mode'] == 'l' ) $subtractLevels++;
  890. if( $tmp['mode'] != 'l' )
  891. array_unshift($before, 'line_i');
  892. else
  893. array_unshift($before, 'spacer');
  894. //for($ii=$channels[$i]['level']; $ii>0; $ii--)
  895. while(true)
  896. {
  897. $tmpPID = $tmp['pid'];
  898. if( /*$tmpPID != 0 &&*/ isset($cidConnection[$tmpPID]) && isset($channels[$cidConnection[$tmpPID]]) )
  899. $tmp = $channels[$cidConnection[$tmpPID]];
  900. else
  901. break;
  902. //echo $tmpPID.' ';
  903. if( $tmp['mode'] != 'l' )
  904. array_unshift($before, 'line_i');
  905. else
  906. array_unshift($before, 'spacer');
  907. //if( $tmp['mode'] != 'l' ) break;
  908. //$subtractLevels++;
  909. }
  910. $channels[$i]['draw_before'] = $before;
  911. //print_r($before);
  912. //$channels[$i]['num_i_lines'] = $channels[$i]['level'] - $subtractLevels;
  913. //$channels[$i]['num_spacers'] = $subtractLevels;
  914. }
  915. }
  916. $clientNum = count($clients);
  917. for($i=0; $i<$clientNum; $i++)
  918. {
  919. if( $clients[$i]['client_input_hardware'] == '0' ) $clients[$i]['status_img'] = '16x16_hardware_input_muted';
  920. else if( $clients[$i]['client_output_muted'] == '1' ) $clients[$i]['status_img'] = '16x16_output_muted';
  921. else if( $clients[$i]['client_input_muted'] == '1' ) $clients[$i]['status_img'] = '16x16_input_muted';
  922. else if( $clients[$i]['client_flag_talking'] == '1') $clients[$i]['status_img'] = '16x16_player_on';
  923. else $clients[$i]['status_img'] = '16x16_player_off';
  924. $channels[$cidConnection[$clients[$i]['cid']]]['clients'][] = $clients[$i];
  925. $channels[$cidConnection[$clients[$i]['cid']]]['clients'][(count($channels[$cidConnection[$clients[$i]['cid']]]['clients']))-1]['level'] = $channels[$cidConnection[$clients[$i]['cid']]]['level'] + 1;
  926. $clients[$i]['level'] = $channels[$cidConnection[$clients[$i]['cid']]]['level'] + 1;
  927. }
  928. array_unshift($channels, array(
  929. 'channel_name' => $server['virtualserver_name'],
  930. 'cid' => $server['virtualserver_id'],
  931. 'is_server' => true
  932. ));
  933. return $channels;
  934. }
  935. private function getChannelBackupString()
  936. {
  937. $this->server->setDeEscapeResults(false);
  938. $result = $this->server->r_channellist(true, true, true, true);
  939. if( !$result )
  940. {
  941. $errArray = $ts->getError();
  942. echo 'ERROR #'.$errArray[2].': the server returned: \''.$errArray[3].'\'';
  943. return false;
  944. }
  945. $channels = array();
  946. $cidConnection = array();
  947. $channelNum = count($result);
  948. for($i=0; $i<$channelNum; $i++ )
  949. {
  950. $cidConnection[$result[$i]['cid']] = $i;
  951. $tmp = $this->server->r_channelinfo($result[$i]['cid']);
  952. if( !$tmp )
  953. {
  954. echo "channelinfo failed\n";
  955. return false;
  956. }
  957. else
  958. {
  959. $result[$i] = array_merge($result[$i], $tmp[0]);
  960. }
  961. if( $result[$i]['pid'] != 0 )
  962. {
  963. $result[$i]['pid'] = $cidConnection[$result[$i]['pid']];
  964. }
  965. if( $result[$i]['channel_order'] != 0 )
  966. {
  967. $result[$i]['channel_order'] = $cidConnection[$result[$i]['channel_order']];
  968. }
  969. unset($result[$i]['cid']);
  970. unset($result[$i]['total_clients']);
  971. unset($result[$i]['channel_filepath']);
  972. }
  973. $this->server->setDeEscapeResults(true);
  974. return json_encode($result);
  975. }
  976. private function insertChannelBackup($backup)
  977. {
  978. if( !$backup = json_decode($backup, true) )
  979. {
  980. echo "json parse error\n";
  981. return false;
  982. }
  983. $cidConnection = array();
  984. $backupNum = count($backup);
  985. for($i=0; $i<$backupNum; $i++)
  986. {
  987. $tmpCreate = array();
  988. $channelPropNum = count($backup[$i]);
  989. foreach($backup[$i] as $key => $value)
  990. {
  991. if( $key == 'pid' || $key == 'channel_order' || $key == 'channel_name' ) continue;
  992. $tmpCreate[] = array($key, $value);
  993. }
  994. $tmp = $this->server->r_channelcreate($backup[$i]['channel_name'], $tmpCreate, '', false);
  995. if( !$tmp )
  996. {
  997. echo "channelcreate error\n";
  998. return false;
  999. }
  1000. else
  1001. {
  1002. if( $backup[$i]['pid'] != 0 )
  1003. {
  1004. if( $backup[$i]['channel_order'] == 0 ) $channelOrder = 0;
  1005. else $channelOrder = $cidConnection[$backup[$i]['channel_order']];
  1006. if( !$this->server->r_channelmove($backup[$i]['cid'], $cidConnection[$backup[$i]['pid']], $channelOrder) )
  1007. {
  1008. echo "channelmove error, ".$backup[$i]['cid']." under ".$cidConnection[$backup[$i]['pid']]."\n";
  1009. return false;
  1010. }
  1011. }
  1012. }
  1013. }
  1014. return true;
  1015. }
  1016. private function resolveErrorID($id)
  1017. {
  1018. switch($id)
  1019. {
  1020. case 2568:
  1021. return $this->language['e_2568'];
  1022. break;
  1023. default:
  1024. return '';
  1025. }
  1026. }
  1027. public function parseTime($timeSeconds)
  1028. {
  1029. $timeSeconds = round($timeSeconds);
  1030. $days = floor($timeSeconds / 86400);
  1031. $daysForm = ( $days === 1 ) ? $this->language['time_day'] : $this->language['time_days'];
  1032. $hours = floor(($timeSeconds % 86400) / 3600);
  1033. $hoursForm = ( $days === 1 ) ? $this->language['time_hour'] : $this->language['time_hours'];
  1034. $minutes = floor(($timeSeconds % 3600) / 60);
  1035. $minutesForm = ( $days === 1 ) ? $this->language['time_minute'] : $this->language['time_minutes'];
  1036. $seconds = $timeSeconds % 60;
  1037. $secondsForm = ( $days === 1 ) ? $this->language['time_second'] : $this->language['time_seconds'];
  1038. return "$days $daysForm, $hours $hoursForm, $minutes $minutesForm, $seconds $secondsForm";
  1039. }
  1040. public function parseDate($timeSeconds, $add=0, $format='r')
  1041. {
  1042. if( $add != 0 ) $timeSeconds += $add;
  1043. return date($format, $timeSeconds);
  1044. }
  1045. public function convertByteToMB($num, $prec=2)
  1046. {
  1047. return round($num/1024/1024, $prec);
  1048. }
  1049. public function convertByteToKB($num, $prec=2)
  1050. {
  1051. return round($num/1024, $prec);
  1052. }
  1053. private function checkForUpdate()
  1054. {
  1055. return '';
  1056. }
  1057. }
  1058. ?>