ts3webinterface.class.php 34 KB

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