ts3webinterface.class.php 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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. $display_ip = checkDisplayPublicIP($getPublicIp[0]['display_public_ip'],$this->serverIP);
  567. $this->template->assign('IP', $this->serverIP);
  568. $this->template->assign('display_public_ip', $display_ip);
  569. $this->template->assign('selectvServer', $vServerList);
  570. $this->template->assign('addData', $addData);
  571. $updateAvailable = $this->checkForUpdate();
  572. $this->template->assign('updateAvailable', $updateAvailable);
  573. if( $updateAvailable != "" )
  574. {
  575. $this->template->display('updateAvailable.tpl');
  576. }
  577. $this->template->display('selectvServer.tpl');
  578. $this->template->display('footer.tpl');
  579. }
  580. else
  581. {
  582. if( isset($_GET['liveview']) ) $this->template->assign('liveviewAutoUpdate', true);
  583. else $this->template->assign('liveviewAutoUpdate', false);
  584. $this->template->display('header.tpl');
  585. $updateAvailable = $this->checkForUpdate();
  586. $this->template->assign('updateAvailable', $updateAvailable);
  587. if( $updateAvailable != "" )
  588. {
  589. $this->template->display('updateAvailable.tpl');
  590. }
  591. $infoBoxData = $this->server->r_serverinfo();
  592. $this->template->assign('data', $infoBoxData[0]);
  593. if( isset($_GET['token']) )
  594. {
  595. $addToken = array();
  596. if( isset($_GET['do']) && $_GET['do'] == 'addtoken' )
  597. {
  598. $tokenid1 = false;
  599. $tokenid2 = false;
  600. if( isset($_POST['tokentype']) )
  601. {
  602. switch((int)$_POST['tokentype'])
  603. {
  604. case 0:
  605. if( !isset($_POST['tokenid1_0']) ) break;
  606. $tokenid1 = $_POST['tokenid1_0'];
  607. $tokenid2 = 0;
  608. break;
  609. case 1:
  610. if( !isset($_POST['tokenid1_1']) || !isset($_POST['tokenid2_1']) ) break;
  611. $tokenid1 = $_POST['tokenid1_1'];
  612. $tokenid2 = $_POST['tokenid2_1'];
  613. break;
  614. }
  615. }
  616. if( $tokenid1 !== false )
  617. {
  618. if( $this->server->r_tokenadd($_POST['tokentype'], $tokenid1, $tokenid2) )
  619. {
  620. $addToken = array('OK');
  621. }
  622. else
  623. {
  624. $error = $this->server->getError();
  625. $addToken = array('ERROR', $error[2], $this->language['n_server_responded'].$error[3]);
  626. }
  627. }
  628. else
  629. {
  630. $addToken = array('ERROR', 0, $this->language['e_fill_out']);
  631. }
  632. }
  633. $this->template->assign('addToken', $addToken);
  634. $this->template->assign('tokenList', $this->server->r_tokenlist());
  635. $serverGroupList = $this->server->r_servergrouplist();
  636. $serverGroupListNames = array();
  637. for($i=0; $i<count($serverGroupList); $i++)
  638. {
  639. $serverGroupListNames[$serverGroupList[$i]['sgid']] = $serverGroupList[$i];
  640. }
  641. $this->template->assign('serverGroupList', $serverGroupList);
  642. $this->template->assign('serverGroupListNames', $serverGroupListNames);
  643. $channelGroupList = $this->server->r_channelgrouplist();
  644. $channelGroupListNames = array();
  645. for($i=0; $i<count($channelGroupList); $i++)
  646. {
  647. $channelGroupListNames[$channelGroupList[$i]['cgid']] = $channelGroupList[$i];
  648. }
  649. $this->template->assign('channelGroupList', $channelGroupList);
  650. $this->template->assign('channelGroupListNames', $channelGroupListNames);
  651. $channelList = $this->server->r_channellist();
  652. $channelListNames = array();
  653. for($i=0; $i<count($channelList); $i++)
  654. {
  655. $channelListNames[$channelList[$i]['cid']] = $channelList[$i];
  656. }
  657. $this->template->assign('channelList', $channelList);
  658. $this->template->assign('channelListNames', $channelListNames);
  659. $this->template->display('vServerToken.tpl');
  660. }
  661. else if( isset($_GET['liveview']) )
  662. {
  663. $insertResult = array();
  664. if( isset($_FILES['backup']) )
  665. {
  666. $insertResult = array('ERROR', 0, $this->language['e_upload_failed']);
  667. $filename = 'modules/TS3Admin/templates_c/channelbackup_'.rand(111,999).rand(111,999).'.txt';
  668. if( $_FILES['backup']['error'] == 0 && move_uploaded_file($_FILES['backup']['tmp_name'], $filename) )
  669. {
  670. if( $this->insertChannelBackup(file_get_contents($filename)) )
  671. {
  672. $insertResult = array('OK');
  673. }
  674. unlink($filename);
  675. }
  676. }
  677. $this->template->assign('insertResult', $insertResult);
  678. $this->template->assign('serverTree', $this->getLiveview($infoBoxData[0])); // serverinfo param for no double query
  679. $this->template->assign('banList', $this->server->r_banlist());
  680. $this->template->display('vServerLiveview.tpl');
  681. }
  682. else
  683. {
  684. global $db;
  685. $is_parent_user = FALSE;
  686. $subusers_installed = $db->isModuleInstalled('subusers');
  687. if( $subusers_installed )
  688. {
  689. if(defined('TS3WEBINTERFACE_VSERVER_ID'))
  690. $assigned_info = getAssignedServerUsers();
  691. if( isset($_POST['assign_subuser']) and
  692. in_array($_POST['user_id'],$assigned_info['subusers']) )
  693. {
  694. $db->query("INSERT INTO OGP_DB_PREFIXts3_homes
  695. (`rserver_id`, `ip`, `pwd`, `vserver_id`, `user_id`)
  696. VALUES ('".$_SESSION['rserver_id']."', '".
  697. TS3WEBINTERFACE_IP."', '".
  698. TS3WEBINTERFACE_PWD."', '".
  699. TS3WEBINTERFACE_VSERVER_ID."', '".
  700. $_POST['user_id'].
  701. "');");
  702. $assigned_info = getAssignedServerUsers();
  703. }
  704. if( isset($_POST['unassign_subuser']) and
  705. is_array($assigned_info['subusers']) and
  706. in_array($_POST['user_id'],$assigned_info['users_assigned']) and
  707. in_array($_POST['user_id'],$assigned_info['subusers']) )
  708. {
  709. $db->query( "DELETE FROM OGP_DB_PREFIXts3_homes WHERE vserver_id='".
  710. TS3WEBINTERFACE_VSERVER_ID."' AND user_id='".
  711. $_POST['user_id']."' AND rserver_id='".
  712. $_SESSION['rserver_id'].
  713. "';" );
  714. $assigned_info = getAssignedServerUsers();
  715. }
  716. if(defined('TS3WEBINTERFACE_VSERVER_ID'))
  717. {
  718. $this->template->assign('subusers_assigned', $assigned_info['subusers_assigned_list']);
  719. $this->template->assign('subusers', $assigned_info['subusers_list']);
  720. $is_parent_user = is_array($assigned_info['subusers']);
  721. }
  722. }
  723. $this->template->assign('is_parent_user', $is_parent_user);
  724. $this->template->assign('subusers_installed', $subusers_installed);
  725. $getPublicIp = $db->resultQuery("SELECT display_public_ip FROM OGP_DB_PREFIXremote_servers WHERE remote_server_id=".$_SESSION['rserver_id']);
  726. $display_ip = checkDisplayPublicIP($getPublicIp[0]['display_public_ip'],$this->serverIP);
  727. $this->template->assign('display_public_ip', $display_ip);
  728. $this->template->assign('IP', $this->serverIP);
  729. $this->template->display('vServerOverview.tpl');
  730. }
  731. $this->template->display('footer.tpl');
  732. }
  733. }
  734. }
  735. private function getLiveview($server=false)
  736. {
  737. if( !$server )
  738. {
  739. $server = $this->server->r_serverinfo();
  740. if( !$server )
  741. {
  742. $errArray = $this->server->getError();
  743. echo strtoupper($this->language['error']).' #'.$errArray[2].': '.$this->language['n_server_responded'].' \''.$errArray[3].'\'';
  744. return false;
  745. }
  746. $server = $server[0];
  747. }
  748. else
  749. {
  750. if( !empty($server[0]) )
  751. $server = $server[0];
  752. }
  753. $channels = $this->server->r_channellist(true, true, true, true);
  754. if( !$channels )
  755. {
  756. $errArray = $this->server->getError();
  757. echo strtoupper($this->language['error']).' #'.$errArray[2].': '.$this->language['n_server_responded'].' \''.$errArray[3].'\'';
  758. return false;
  759. }
  760. $clients = $this->server->r_clientlist(true, true, true, true, true);
  761. if( !$clients )
  762. {
  763. $errArray = $this->server->getError();
  764. echo strtoupper($this->language['error']).' #'.$errArray[2].': '.$this->language['n_server_responded'].' \''.$errArray[3].'\'';
  765. return false;
  766. }
  767. function sortClients($a, $b)
  768. {
  769. if( strpos(',', $a['client_servergroups']) !== false )
  770. {
  771. $aID = explode(',', $a['client_servergroups'], 2);
  772. $aID = $aID[0];
  773. }
  774. else
  775. {
  776. $aID = $a['client_servergroups'];
  777. }
  778. if( strpos(',', $b['client_servergroups']) !== false )
  779. {
  780. $bID = explode(',', $b['client_servergroups'], 2);
  781. $bID = $bID[0];
  782. }
  783. else
  784. {
  785. $bID = $b['client_servergroups'];
  786. }
  787. if( $aID > $bID ) return 1;
  788. if( $aID < $bID ) return -1;
  789. if( $aID = $bID ) return 0;
  790. }
  791. usort($clients, "sortClients");
  792. $pidStack = array(0);
  793. $lastLevel = array();
  794. $cidConnection = array();
  795. $channelNum = count($channels);
  796. for($i=0; $i<$channelNum; $i++)
  797. {
  798. $cidConnection[$channels[$i]['cid']] = $i;
  799. $channels[$i]['is_last_channel'] = false;
  800. /*if( $channels[$i]['pid'] != $pidStack[count($pidStack)-1] )
  801. {
  802. if( in_array($channels[$i]['pid'], $pidStack) )
  803. {
  804. do
  805. {
  806. array_pop($pidStack);
  807. } while( in_array($channels[$i]['pid'], $pidStack) && count($pidStack) > 1 );
  808. //$pidStack[] = $channels[$i]['pid'];
  809. $channels[$i]['is_last_channel'] = true;
  810. }
  811. else
  812. {
  813. $pidStack[] = $channels[$i]['pid'];
  814. }
  815. }*/
  816. //$channels[$i]['level'] = count($pidStack)-1;
  817. if( $channels[$i]['pid'] == 0 ) $channels[$i]['level'] = 0;
  818. else $channels[$i]['level'] = $channels[$cidConnection[$channels[$i]['pid']]]['level'] + 1;
  819. $channels[$i]['is_server'] = false;
  820. $channels[$i]['clients'] = array();
  821. $lastLevel[$channels[$i]['level']] = $i;
  822. }
  823. /*$reversedCounter = count($channels)-1;
  824. do
  825. {
  826. if( $channels[$reversedCounter]['pid'] == 0 )
  827. {
  828. $channels[$reversedCounter]['is_last_channel'] = true;
  829. break;
  830. }
  831. $reversedCounter--;
  832. } while( $reversedCounter >= 0 );*/
  833. for($i=0; $i<$channelNum; $i++)
  834. {
  835. if( !isset($channels[$i-1]) && !isset($channels[$i+1]) )
  836. {
  837. $channels[$i]['mode'] = 'l';
  838. //continue;
  839. }
  840. else if( isset($channels[$i-1]) && !isset($channels[$i+1]) )
  841. {
  842. $channels[$i]['mode'] = 'l';
  843. //continue;
  844. }
  845. else if( !isset($channels[$i-1]) && isset($channels[$i+1]) )
  846. {
  847. $channels[$i]['mode'] = 't';
  848. //continue;
  849. }
  850. else if( $channels[$i]['level'] == $channels[$i+1]['level'] )
  851. {
  852. $channels[$i]['mode'] = 't';
  853. }
  854. else if( $channels[$i]['level'] > $channels[$i+1]['level'] )
  855. {
  856. $channels[$i]['mode'] = 'l';
  857. }
  858. else
  859. {
  860. if( $lastLevel[$channels[$i]['level']] == $i )
  861. {
  862. $channels[$i]['mode'] = 'l';
  863. }
  864. else
  865. {
  866. $channels[$i]['mode'] = 't';
  867. }
  868. }
  869. //$channels[$i]['TEST'] = $i;
  870. if( $channels[$i]['pid'] != 0 )
  871. {
  872. $before = array();
  873. //$subtractLevels = 0;
  874. //$tmp = $channels[$cidConnection[$channels[$i]['pid']]];
  875. //$tmpPID = $channels[$i]['pid'];
  876. //echo $tmpPID.' ';
  877. $tmp = $channels[$cidConnection[$channels[$i]['pid']]];
  878. //echo $channels[$i]['pid'].'='.$cidConnection[$channels[$i]['pid']].' ';
  879. //var_dump($channels[$cidConnection[$channels[$i]['pid']]]['is_last_channel']);
  880. $tmpPID = $channels[$i]['pid'];
  881. //if( $tmp['mode'] == 'l' ) $subtractLevels++;
  882. if( $tmp['mode'] != 'l' )
  883. array_unshift($before, 'line_i');
  884. else
  885. array_unshift($before, 'spacer');
  886. //for($ii=$channels[$i]['level']; $ii>0; $ii--)
  887. while(true)
  888. {
  889. $tmpPID = $tmp['pid'];
  890. if( /*$tmpPID != 0 &&*/ isset($cidConnection[$tmpPID]) && isset($channels[$cidConnection[$tmpPID]]) )
  891. $tmp = $channels[$cidConnection[$tmpPID]];
  892. else
  893. break;
  894. //echo $tmpPID.' ';
  895. if( $tmp['mode'] != 'l' )
  896. array_unshift($before, 'line_i');
  897. else
  898. array_unshift($before, 'spacer');
  899. //if( $tmp['mode'] != 'l' ) break;
  900. //$subtractLevels++;
  901. }
  902. $channels[$i]['draw_before'] = $before;
  903. //print_r($before);
  904. //$channels[$i]['num_i_lines'] = $channels[$i]['level'] - $subtractLevels;
  905. //$channels[$i]['num_spacers'] = $subtractLevels;
  906. }
  907. }
  908. $clientNum = count($clients);
  909. for($i=0; $i<$clientNum; $i++)
  910. {
  911. if( $clients[$i]['client_input_hardware'] == '0' ) $clients[$i]['status_img'] = '16x16_hardware_input_muted';
  912. else if( $clients[$i]['client_output_muted'] == '1' ) $clients[$i]['status_img'] = '16x16_output_muted';
  913. else if( $clients[$i]['client_input_muted'] == '1' ) $clients[$i]['status_img'] = '16x16_input_muted';
  914. else if( $clients[$i]['client_flag_talking'] == '1') $clients[$i]['status_img'] = '16x16_player_on';
  915. else $clients[$i]['status_img'] = '16x16_player_off';
  916. $channels[$cidConnection[$clients[$i]['cid']]]['clients'][] = $clients[$i];
  917. $channels[$cidConnection[$clients[$i]['cid']]]['clients'][(count($channels[$cidConnection[$clients[$i]['cid']]]['clients']))-1]['level'] = $channels[$cidConnection[$clients[$i]['cid']]]['level'] + 1;
  918. $clients[$i]['level'] = $channels[$cidConnection[$clients[$i]['cid']]]['level'] + 1;
  919. }
  920. array_unshift($channels, array(
  921. 'channel_name' => $server['virtualserver_name'],
  922. 'cid' => $server['virtualserver_id'],
  923. 'is_server' => true
  924. ));
  925. return $channels;
  926. }
  927. private function getChannelBackupString()
  928. {
  929. $this->server->setDeEscapeResults(false);
  930. $result = $this->server->r_channellist(true, true, true, true);
  931. if( !$result )
  932. {
  933. $errArray = $ts->getError();
  934. echo 'ERROR #'.$errArray[2].': the server returned: \''.$errArray[3].'\'';
  935. return false;
  936. }
  937. $channels = array();
  938. $cidConnection = array();
  939. $channelNum = count($result);
  940. for($i=0; $i<$channelNum; $i++ )
  941. {
  942. $cidConnection[$result[$i]['cid']] = $i;
  943. $tmp = $this->server->r_channelinfo($result[$i]['cid']);
  944. if( !$tmp )
  945. {
  946. echo "channelinfo failed\n";
  947. return false;
  948. }
  949. else
  950. {
  951. $result[$i] = array_merge($result[$i], $tmp[0]);
  952. }
  953. if( $result[$i]['pid'] != 0 )
  954. {
  955. $result[$i]['pid'] = $cidConnection[$result[$i]['pid']];
  956. }
  957. if( $result[$i]['channel_order'] != 0 )
  958. {
  959. $result[$i]['channel_order'] = $cidConnection[$result[$i]['channel_order']];
  960. }
  961. unset($result[$i]['cid']);
  962. unset($result[$i]['total_clients']);
  963. unset($result[$i]['channel_filepath']);
  964. }
  965. $this->server->setDeEscapeResults(true);
  966. return json_encode($result);
  967. }
  968. private function insertChannelBackup($backup)
  969. {
  970. if( !$backup = json_decode($backup, true) )
  971. {
  972. echo "json parse error\n";
  973. return false;
  974. }
  975. $cidConnection = array();
  976. $backupNum = count($backup);
  977. for($i=0; $i<$backupNum; $i++)
  978. {
  979. $tmpCreate = array();
  980. $channelPropNum = count($backup[$i]);
  981. foreach($backup[$i] as $key => $value)
  982. {
  983. if( $key == 'pid' || $key == 'channel_order' || $key == 'channel_name' ) continue;
  984. $tmpCreate[] = array($key, $value);
  985. }
  986. $tmp = $this->server->r_channelcreate($backup[$i]['channel_name'], $tmpCreate, '', false);
  987. if( !$tmp )
  988. {
  989. echo "channelcreate error\n";
  990. return false;
  991. }
  992. else
  993. {
  994. if( $backup[$i]['pid'] != 0 )
  995. {
  996. if( $backup[$i]['channel_order'] == 0 ) $channelOrder = 0;
  997. else $channelOrder = $cidConnection[$backup[$i]['channel_order']];
  998. if( !$this->server->r_channelmove($backup[$i]['cid'], $cidConnection[$backup[$i]['pid']], $channelOrder) )
  999. {
  1000. echo "channelmove error, ".$backup[$i]['cid']." under ".$cidConnection[$backup[$i]['pid']]."\n";
  1001. return false;
  1002. }
  1003. }
  1004. }
  1005. }
  1006. return true;
  1007. }
  1008. private function resolveErrorID($id)
  1009. {
  1010. switch($id)
  1011. {
  1012. case 2568:
  1013. return $this->language['e_2568'];
  1014. break;
  1015. default:
  1016. return '';
  1017. }
  1018. }
  1019. public function parseTime($timeSeconds)
  1020. {
  1021. $timeSeconds = round($timeSeconds);
  1022. $days = floor($timeSeconds / 86400);
  1023. $daysForm = ( $days === 1 ) ? $this->language['time_day'] : $this->language['time_days'];
  1024. $hours = floor(($timeSeconds % 86400) / 3600);
  1025. $hoursForm = ( $days === 1 ) ? $this->language['time_hour'] : $this->language['time_hours'];
  1026. $minutes = floor(($timeSeconds % 3600) / 60);
  1027. $minutesForm = ( $days === 1 ) ? $this->language['time_minute'] : $this->language['time_minutes'];
  1028. $seconds = $timeSeconds % 60;
  1029. $secondsForm = ( $days === 1 ) ? $this->language['time_second'] : $this->language['time_seconds'];
  1030. return "$days $daysForm, $hours $hoursForm, $minutes $minutesForm, $seconds $secondsForm";
  1031. }
  1032. public function parseDate($timeSeconds, $add=0, $format='r')
  1033. {
  1034. if( $add != 0 ) $timeSeconds += $add;
  1035. return date($format, $timeSeconds);
  1036. }
  1037. public function convertByteToMB($num, $prec=2)
  1038. {
  1039. return round($num/1024/1024, $prec);
  1040. }
  1041. public function convertByteToKB($num, $prec=2)
  1042. {
  1043. return round($num/1024, $prec);
  1044. }
  1045. private function checkForUpdate()
  1046. {
  1047. return '';
  1048. }
  1049. }
  1050. ?>