PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/index.php

https://gitlab.com/zanzilan/bgpanel
PHP | 427 lines | 333 code | 44 blank | 50 comment | 25 complexity | e261a9de2624dec9f116c3435a1d5542 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * LICENSE:
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. *
  19. * @categories Games/Entertainment, Systems Administration
  20. * @package Bright Game Panel
  21. * @author warhawk3407 <warhawk3407@gmail.com> @NOSPAM
  22. * @copyleft 2013
  23. * @license GNU General Public License version 3.0 (GPLv3)
  24. * @version (Release 0) DEVELOPER BETA 8
  25. * @link http://www.bgpanel.net/
  26. */
  27. $page = 'index';
  28. $tab = 0;
  29. $return = 'index.php';
  30. require("../configuration.php");
  31. require("./include.php");
  32. $title = T_('Home');
  33. //---------------------------------------------------------+
  34. //Personal Notes :
  35. $rows = query_fetch_assoc( "SELECT `adminid`, `notes` FROM `".DBPREFIX."admin` WHERE `adminid` = '".$_SESSION['adminid']."' LIMIT 1" );
  36. //---------------------------------------------------------+
  37. //Online Users :
  38. $unixLastMin = time() - 1 * 60;
  39. $onlineClients = mysql_query( "SELECT `clientid`, `username` FROM `".DBPREFIX."client` WHERE `lastactivity` >= '".$unixLastMin."'" ); //We select all clients active in the last minute (based on unix timestamp)
  40. $onlineAdmins = mysql_query( "SELECT `adminid`, `username` FROM `".DBPREFIX."admin` WHERE `lastactivity` >= '".$unixLastMin."'" ); //Same 4 admins
  41. unset($unixLastMin);
  42. //---------------------------------------------------------+
  43. //Servers :
  44. $servers = mysql_query( "SELECT * FROM `".DBPREFIX."server` WHERE `status` = 'Active' && `panelstatus` = 'Started' ORDER BY `name`" );
  45. //---------------------------------------------------------+
  46. //Boxes :
  47. $boxes = mysql_query( "SELECT `boxid`, `name`, `cache` FROM `".DBPREFIX."box` ORDER BY `name`" );
  48. $cron = query_fetch_assoc( "SELECT `value` FROM `".DBPREFIX."config` WHERE `setting` = 'lastcronrun' LIMIT 1" );
  49. //---------------------------------------------------------+
  50. //Last 15 Actions :
  51. $logs = mysql_query( "SELECT * FROM `".DBPREFIX."log` ORDER BY `logid` DESC LIMIT 15" );
  52. include("./bootstrap/header.php");
  53. /**
  54. * Notifications
  55. */
  56. include("./bootstrap/notifications.php");
  57. ?>
  58. <div class="row-fluid">
  59. <div class="span12">
  60. <div id="charts">
  61. <div id="players">
  62. <?php
  63. if (query_numrows( "SELECT `timestamp`, `cache` FROM `".DBPREFIX."boxData` WHERE `timestamp` >= '".(time() - (60 * 60 * 24 * 7 * 4 + CRONDELAY))."'" ) != 0)
  64. {
  65. ?>
  66. <script type="text/javascript">
  67. $(document).ready(function() {
  68. $.getJSON('api.boxdata.json.php?api_key=<?php echo API_KEY; ?>&task=players', function(data) {
  69. // Create the chart
  70. players = new Highcharts.StockChart({
  71. chart : {
  72. renderTo : 'players'
  73. },
  74. title : {
  75. text : 'Players'
  76. },
  77. xAxis: {
  78. gapGridLineWidth: 0
  79. },
  80. rangeSelector : {
  81. buttons : [{
  82. type : 'day',
  83. count : 1,
  84. text : '1D'
  85. }, {
  86. type : 'week',
  87. count : 1,
  88. text : '1W'
  89. }, {
  90. type : 'month',
  91. count : 1,
  92. text : '1M'
  93. }, {
  94. type : 'all',
  95. count : 1,
  96. text : 'All'
  97. }],
  98. selected : 0,
  99. inputEnabled : false
  100. },
  101. series : [{
  102. name : 'Players',
  103. type : 'area',
  104. data : data,
  105. threshold : null,
  106. gapSize: 5,
  107. tooltip : {
  108. valueDecimals : 2
  109. },
  110. fillColor : {
  111. linearGradient : {
  112. x1: 0,
  113. y1: 0,
  114. x2: 0,
  115. y2: 1
  116. },
  117. stops : [[0, Highcharts.getOptions().colors[0]], [1, 'rgba(254,254,254,254)']]
  118. }
  119. }]
  120. });
  121. });
  122. });
  123. </script>
  124. <script src="../bootstrap/js/highstock.js"></script>
  125. <script src="../bootstrap/js/modules/exporting.js"></script>
  126. <div id="players"></div>
  127. <?php
  128. }
  129. else
  130. {
  131. ?>
  132. <img class="playersChart" data-original="../bootstrap/img/nodata.png" src="../bootstrap/img/wait.gif" style="display: inline; padding-left: 20px;">
  133. <script>
  134. // delayed rendering
  135. $(document).ready(function() {
  136. $("img.playersChart").lazyload();
  137. });
  138. </script>
  139. <?php
  140. }
  141. ?>
  142. </div>
  143. </div><!-- /charts -->
  144. </div><!-- /span -->
  145. </div><!-- /row-fluid -->
  146. <hr>
  147. <div class="row-fluid">
  148. <div class="span4">
  149. <div id="twitter">
  150. <legend>Twitter</legend>
  151. <blockquote>
  152. <p>An easy way to get the latest updates, announcements and blog articles of the BPanel project</p>
  153. </blockquote>
  154. <a href="http://www.twitter.com/BrightGamePanel" class="btn btn-block" type="button" style="margin-bottom: 10px;">Follow @BrightGamePanel</a>
  155. </div><!-- /twitter -->
  156. </div><!-- /span -->
  157. <div class="span3">
  158. <div id="usersonline">
  159. <legend><?php echo T_('Online Users'); ?></legend>
  160. <table class="table table-striped table-bordered table-condensed">
  161. <thead>
  162. <tr>
  163. <th> <?php echo T_('Privilege'); ?> </th>
  164. <th> <?php echo T_('Username'); ?> </th>
  165. </tr>
  166. </thead>
  167. <tbody>
  168. <?php
  169. while ($rowsonlineClients = mysql_fetch_assoc($onlineClients))
  170. {
  171. ?>
  172. <tr>
  173. <td> <?php echo T_('Client'); ?> </td>
  174. <td> <a href="clientsummary.php?id=<?php echo $rowsonlineClients['clientid']; ?>"><?php echo htmlspecialchars($rowsonlineClients['username'], ENT_QUOTES); ?></a> </td>
  175. </tr>
  176. <?php
  177. }
  178. unset($onlineClients);
  179. while ($rowsonlineAdmins = mysql_fetch_assoc($onlineAdmins))
  180. {
  181. ?>
  182. <tr>
  183. <td> <?php echo T_('Admin'); ?> </td>
  184. <td> <?php echo htmlspecialchars($rowsonlineAdmins['username'], ENT_QUOTES); ?> </td>
  185. </tr>
  186. <?php
  187. }
  188. unset($onlineAdmins);
  189. ?>
  190. </tbody>
  191. </table>
  192. </div><!-- /usersonline -->
  193. </div><!-- /span -->
  194. <div class="span5">
  195. <div id="notes">
  196. <legend><?php echo T_('Personal Notes'); ?></legend>
  197. <form method="post" action="process.php">
  198. <input type="hidden" name="task" value="personalnotes" />
  199. <input type="hidden" name="adminid" value="<?php echo $_SESSION['adminid']; ?>" />
  200. <div style="text-align: center;">
  201. <textarea name="notes" class="textarea span11"><?php echo htmlspecialchars($rows['notes'], ENT_QUOTES); ?></textarea>
  202. </div>
  203. <div style="text-align: center; margin-top: 18px;">
  204. <button type="submit" class="btn"><?php echo T_('Save'); ?></button>
  205. </div>
  206. </form>
  207. </div><!-- /notes -->
  208. </div><!-- /span -->
  209. </div><!-- /row-fluid -->
  210. <div class="row-fluid">
  211. <div class="span4">
  212. <div id="game">
  213. <legend><?php echo T_('Active Game Servers'); ?></legend>
  214. <table class="table table-striped table-bordered table-condensed">
  215. <thead>
  216. <tr>
  217. <th> <?php echo T_('Server Name'); ?> </th>
  218. <th> <?php echo T_('Net Status'); ?> </th>
  219. </tr>
  220. </thead>
  221. <tbody>
  222. <?php
  223. while ($rowsServers = mysql_fetch_assoc($servers))
  224. {
  225. $serverIp = query_fetch_assoc( "SELECT `ip` FROM `".DBPREFIX."boxIp` WHERE `ipid` = '".$rowsServers['ipid']."' LIMIT 1" );
  226. $type = query_fetch_assoc( "SELECT `querytype` FROM `".DBPREFIX."game` WHERE `gameid` = '".$rowsServers['gameid']."' LIMIT 1");
  227. ###
  228. //---------------------------------------------------------+
  229. //Querying the server
  230. include_once("../libs/lgsl/lgsl_class.php");
  231. ###
  232. $lgsl = lgsl_query_live($type['querytype'], $serverIp['ip'], NULL, $rowsServers['queryport'], NULL, 's');
  233. ###
  234. if (@$lgsl['b']['status'] == '1')
  235. {
  236. ?>
  237. <tr>
  238. <td> <a href="serversummary.php?id=<?php echo $rowsServers['serverid']; ?>"><?php echo htmlspecialchars($rowsServers['name'], ENT_QUOTES); ?></a> </td>
  239. <td> <span class="label label-success"><?php echo T_('Online'); ?></span> </td>
  240. </tr>
  241. <?php
  242. }
  243. else
  244. {
  245. ?>
  246. <tr>
  247. <td> <a href="serversummary.php?id=<?php echo $rowsServers['serverid']; ?>"><?php echo htmlspecialchars($rowsServers['name'], ENT_QUOTES); ?></a> </td>
  248. <td> <span class="label label-important"><?php echo T_('Offline'); ?></span> </td>
  249. </tr>
  250. <?php
  251. }
  252. unset($lgsl, $serverIp, $type);
  253. }
  254. unset($servers);
  255. ?>
  256. </tbody>
  257. </table>
  258. </div><!-- /game -->
  259. </div><!-- /span -->
  260. <div class="span8">
  261. <div id="game">
  262. <legend><?php echo T_('Boxes'); ?></legend>
  263. <table class="table table-striped table-bordered table-condensed">
  264. <thead>
  265. <tr>
  266. <th> <?php echo T_('Box Name'); ?> </th>
  267. <th> <?php echo T_('Load Average'); ?> </th>
  268. <th> <?php echo T_('HDD Usage'); ?> </th>
  269. <th colspan="2"> <?php echo T_('Bandwith Usage'); ?> </th>
  270. <th> <?php echo T_('Uptime'); ?> </th>
  271. </tr>
  272. </thead>
  273. <tbody>
  274. <?php
  275. /**
  276. * BOXES
  277. */
  278. while ($rowsBoxes = mysql_fetch_assoc($boxes))
  279. {
  280. $cache = unserialize(gzuncompress($rowsBoxes['cache']));
  281. ?>
  282. <tr>
  283. <td> <a href="boxsummary.php?id=<?php echo $rowsBoxes['boxid']; ?>"><?php echo htmlspecialchars($rowsBoxes['name'], ENT_QUOTES); ?></a> </td>
  284. <td> <span class="badge badge-<?php
  285. if (substr($cache["{$rowsBoxes['boxid']}"]['loadavg']['loadavg'], 0, -3) < $cache["{$rowsBoxes['boxid']}"]['cpu']['cores']) {
  286. echo 'info';
  287. } else if (substr($cache["{$rowsBoxes['boxid']}"]['loadavg']['loadavg'], 0, -3) == $cache["{$rowsBoxes['boxid']}"]['cpu']['cores']) {
  288. echo 'warning';
  289. } else { echo 'important'; }
  290. ?>"><?php echo $cache["{$rowsBoxes['boxid']}"]['loadavg']['loadavg']; ?></span> </td>
  291. <td> <span class="badge badge-<?php
  292. if ($cache["{$rowsBoxes['boxid']}"]['hdd']['usage'] < 65) {
  293. echo 'info';
  294. } else if ($cache["{$rowsBoxes['boxid']}"]['hdd']['usage'] < 85) {
  295. echo 'warning';
  296. } else { echo 'important'; }
  297. ?>"><?php echo $cache["{$rowsBoxes['boxid']}"]['hdd']['usage']; ?>&nbsp;%</span> </td>
  298. <td> RX:&nbsp;<?php echo bytesToSize($cache["{$rowsBoxes['boxid']}"]['bandwidth']['rx_usage']); ?>/s </td>
  299. <td> TX:&nbsp;<?php echo bytesToSize($cache["{$rowsBoxes['boxid']}"]['bandwidth']['tx_usage']); ?>/s </td>
  300. <td> <?php echo $cache["{$rowsBoxes['boxid']}"]['uptime']['uptime']; ?> </td>
  301. </tr>
  302. <?php
  303. unset($cache);
  304. }
  305. unset($boxes);
  306. ?>
  307. </tbody>
  308. </table>
  309. <div class="well"><?php echo T_('Last Update'); ?> : <span class="label"><?php echo formatDate($cron['value']); ?></span><?php
  310. if ($cron['value'] == 'Never')
  311. {
  312. echo "\t\t\t<br />".T_('Setup the cron job to enable box monitoring!');
  313. }
  314. unset($cron);
  315. ?></div>
  316. </div><!-- /game -->
  317. </div><!-- /span -->
  318. </div><!-- /row-fluid -->
  319. <div class="row-fluid">
  320. <div class="span12">
  321. <div id="logs">
  322. <legend><?php echo T_('Last 15 Actions'); ?></legend>
  323. <div style="text-align: center; margin-bottom: 5px;">
  324. <a href="utilitieslog.php" class="btn btn-primary"><?php echo T_('View All'); ?></a>
  325. </div>
  326. <table id="logstable" class="zebra-striped">
  327. <thead>
  328. <tr>
  329. <th><?php echo T_('ID'); ?></th>
  330. <th><?php echo T_('Message'); ?></th>
  331. <th><?php echo T_('Name'); ?></th>
  332. <th><?php echo T_('IP'); ?></th>
  333. <th><?php echo T_('Timestamp'); ?></th>
  334. </tr>
  335. </thead>
  336. <tbody>
  337. <?php
  338. if (mysql_num_rows($logs) == 0)
  339. {
  340. ?>
  341. <tr>
  342. <td colspan="5"><div style="text-align: center;"><span class="label label-warning"><?php echo T_('No Logs Found'); ?></span></div></td>
  343. </tr>
  344. <?php
  345. }
  346. while ($rowsLogs = mysql_fetch_assoc($logs))
  347. {
  348. ?>
  349. <tr>
  350. <td><?php echo $rowsLogs['logid']; ?></td>
  351. <td><?php echo htmlspecialchars($rowsLogs['message'], ENT_QUOTES); ?></td>
  352. <td><?php echo htmlspecialchars($rowsLogs['name'], ENT_QUOTES); ?></td>
  353. <td><?php echo $rowsLogs['ip']; ?></td>
  354. <td><?php echo formatDate($rowsLogs['timestamp']); ?></td>
  355. </tr>
  356. <?php
  357. }
  358. ?>
  359. </tbody>
  360. </table>
  361. <?php
  362. if (mysql_num_rows($logs) != 0)
  363. {
  364. ?>
  365. <script type="text/javascript">
  366. $(document).ready(function() {
  367. // call the tablesorter plugin
  368. $("#logstable").tablesorter({
  369. // sort on the first column
  370. sortList: [[0,1]]
  371. });
  372. });
  373. </script>
  374. <?php
  375. }
  376. unset($logs);
  377. ?>
  378. </div><!-- /logs -->
  379. </div><!-- /span -->
  380. </div><!-- /row-fluid -->
  381. <?php
  382. include("./bootstrap/footer.php");
  383. ?>