Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

526 lines
16 KiB

2 years ago
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. James Rose <james.o.rose@gmail.com>
  21. */
  22. //includes
  23. include "root.php";
  24. require_once "resources/require.php";
  25. require_once "resources/check_auth.php";
  26. //check permissions
  27. if (permission_exists('system_view_info')
  28. || permission_exists('system_view_cpu')
  29. || permission_exists('system_view_hdd')
  30. || permission_exists('system_view_ram')
  31. || permission_exists('system_view_backup')) {
  32. //access granted
  33. }
  34. else {
  35. echo "access denied";
  36. exit;
  37. }
  38. //add multi-lingual support
  39. $language = new text;
  40. $text = $language->get();
  41. //additional includes
  42. require_once "resources/header.php";
  43. //set the page title
  44. $document['title'] = $text['title-sys-status'];
  45. // OS Support
  46. //
  47. // For each section below wrap in an OS detection statement like:
  48. // if (stristr(PHP_OS, 'Linux')) {}
  49. //
  50. // Some possibilites for PHP_OS...
  51. //
  52. // CYGWIN_NT-5.1
  53. // Darwin
  54. // FreeBSD
  55. // HP-UX
  56. // IRIX64
  57. // Linux
  58. // NetBSD
  59. // OpenBSD
  60. // SunOS
  61. // Unix
  62. // WIN32
  63. // WINNT
  64. // Windows
  65. //
  66. //system information
  67. echo "<b>".$text['header-sys-status']."</b>";
  68. echo "<br><br>";
  69. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  70. echo "<tr>\n";
  71. echo " <th class='th' colspan='2' align='left'>".$text['title-sys-info']."</th>\n";
  72. echo "</tr>\n";
  73. if (permission_exists('system_view_info')) {
  74. echo "<tr>\n";
  75. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  76. echo " ".$text['label-version']."\n";
  77. echo " </td>\n";
  78. echo " <td class=\"row_style1\">\n";
  79. echo " ".software::version()."\n";
  80. echo " </td>\n";
  81. echo "</tr>\n";
  82. $git_path = normalize_path_to_os($_SERVER['PROJECT_ROOT']."/.git");
  83. if(file_exists($git_path)){
  84. $git_exe = 'git';
  85. if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') { $git_exe = shell_exec('which git'); }
  86. exec($git_exe.' --git-dir='.$git_path.' status', $dummy, $returnCode);
  87. if($returnCode){
  88. echo "<tr>\n";
  89. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  90. echo " ".$text['label-git_info']."\n";
  91. echo " </td>\n";
  92. echo " <td class=\"row_style1\">\n";
  93. echo " ".$text['label-git_corrupted']."\n";
  94. echo " </td>\n";
  95. echo "</tr>\n";
  96. }else{
  97. $git_branch = shell_exec($git_exe.' --git-dir='.$git_path.' name-rev --name-only HEAD');
  98. rtrim($git_branch);
  99. $git_commit = shell_exec($git_exe.' --git-dir='.$git_path.' rev-parse HEAD');
  100. rtrim($git_commit);
  101. $git_origin = shell_exec($git_exe.' --git-dir='.$git_path.' config --get remote.origin.url');
  102. rtrim($git_origin);
  103. $git_origin = preg_replace('/\.git$/','',$git_origin);
  104. $git_status = shell_exec($git_exe.' --git-dir='.$git_path.' status | grep "Your branch"');
  105. rtrim($git_status);
  106. $git_age = shell_exec($git_exe.' --git-dir='.$git_path.' log --pretty=format:%at "HEAD^!"');
  107. rtrim($git_age);
  108. $git_date = DateTime::createFromFormat('U', $git_age);
  109. $git_age = $git_date->diff(new DateTime('now'));
  110. echo "<tr>\n";
  111. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  112. echo " ".$text['label-git_info']."\n";
  113. echo " </td>\n";
  114. echo " <td class=\"row_style1\">\n";
  115. echo " ".$text['label-git_branch'].": ".$git_branch."<br>\n";
  116. echo " ".$text['label-git_commit'].": <a href='$git_origin/commit/$git_commit'>".$git_commit."</a><br>\n";
  117. echo " ".$text['label-git_origin'].": ".$git_origin."<br>\n";
  118. echo " ".$text['label-git_status'].": ".$git_status.$git_age->format(' %R%a days ago')."<br>\n";
  119. echo " </td>\n";
  120. echo "</tr>\n";
  121. }
  122. }
  123. echo "<tr>\n";
  124. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  125. echo " ".$text['label-path']."\n";
  126. echo " </td>\n";
  127. echo " <td class=\"row_style1\">\n";
  128. echo " ".$_SERVER['PROJECT_ROOT']."\n";
  129. echo " </td>\n";
  130. echo "</tr>\n";
  131. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  132. if ($fp) {
  133. $switch_version = event_socket_request($fp, 'api version');
  134. preg_match("/FreeSWITCH Version (\d+\.\d+\.\d+(?:\.\d+)?).*\(.*?(\d+\w+)\s*\)/", $switch_version, $matches);
  135. $switch_version = $matches[1];
  136. $switch_bits = $matches[2];
  137. echo "<tr>\n";
  138. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  139. echo " ".$text['label-switch']." ".$text['label-version']."\n";
  140. echo " </td>\n";
  141. echo " <td class=\"row_style1\">$switch_version ($switch_bits)</td>\n";
  142. echo "</tr>\n";
  143. preg_match("/\(git\s*(.*?)\s*\d+\w+\s*\)/", $switch_version, $matches);
  144. $switch_git_info = $matches[1];
  145. if(strlen($switch_git_info) > 0){
  146. echo "<tr>\n";
  147. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  148. echo " ".$text['label-switch']." ".$text['label-git_info']."\n";
  149. echo " </td>\n";
  150. echo " <td class=\"row_style1\">$switch_git_info</td>\n";
  151. echo "</tr>\n";
  152. }
  153. }
  154. echo "<tr>\n";
  155. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  156. echo " ".$text['label-php']." ".$text['label-version']."\n";
  157. echo " </td>\n";
  158. echo " <td class=\"row_style1\">".phpversion()."</td>\n";
  159. echo "</tr>\n";
  160. echo "<tr>\n";
  161. echo " <th class='th' colspan='2' align='left' style='padding-top:2em'>".$text['title-os-info']."</th>\n";
  162. echo "</tr>\n";
  163. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  164. echo "<!--\n";
  165. $data = explode("\n",shell_exec('systeminfo /FO CSV 2> nul'));
  166. $data = array_combine(str_getcsv($data[0]), str_getcsv($data[1]));
  167. $os_name = $data['OS Name'];
  168. $os_version = $data['OS Version'];
  169. unset($data);
  170. echo "-->\n";
  171. }
  172. else {
  173. echo "<!--\n";
  174. $os_kernel = shell_exec('uname -a');
  175. $os_name = shell_exec('lsb_release -is');
  176. $os_version = shell_exec('lsb_release -rs');
  177. echo "-->\n";
  178. }
  179. if (strlen($os_name) > 0) {
  180. echo "<tr>\n";
  181. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  182. echo " ".$text['label-os']." \n";
  183. echo " </td>\n";
  184. echo " <td class=\"row_style1\">\n";
  185. echo " ".$os_name." \n";
  186. echo " </td>\n";
  187. echo "</tr>\n";
  188. }
  189. if (strlen($os_version) > 0) {
  190. echo "<tr>\n";
  191. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  192. echo " ".$text['label-version']." \n";
  193. echo " </td>\n";
  194. echo " <td class=\"row_style1\">\n";
  195. echo " ".$os_version." \n";
  196. echo " </td>\n";
  197. echo "</tr>\n";
  198. }
  199. if (strlen($os_kernel) > 0) {
  200. echo "<tr>\n";
  201. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  202. echo " ".$text['label-kernel']." \n";
  203. echo " </td>\n";
  204. echo " <td class=\"row_style1\">\n";
  205. echo " ".$os_kernel." \n";
  206. echo " </td>\n";
  207. echo "</tr>\n";
  208. }
  209. unset($os_name, $os_version, $os_kernel);
  210. echo "<!--\n";
  211. $tmp_result = shell_exec('uptime');
  212. echo "-->\n";
  213. if (strlen($tmp_result) > 0) {
  214. echo "<tr>\n";
  215. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  216. echo " Uptime\n";
  217. echo " </td>\n";
  218. echo " <td class=\"row_style1\">\n";
  219. echo " ".$tmp_result." \n";
  220. echo " </td>\n";
  221. echo "</tr>\n";
  222. }
  223. unset($tmp_result);
  224. }
  225. echo "<tr>\n";
  226. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  227. echo " Date\n";
  228. echo " </td>\n";
  229. echo " <td class=\"row_style1\">\n";
  230. echo " ".date('r')." \n";
  231. echo " </td>\n";
  232. echo "</tr>\n";
  233. echo "</table>\n";
  234. echo "<br /><br>";
  235. //memory information
  236. if (permission_exists('system_view_ram')) {
  237. //linux
  238. if (stristr(PHP_OS, 'Linux')) {
  239. echo "<!--\n";
  240. $shell_cmd = 'free -hw';
  241. $shell_result = shell_exec($shell_cmd);
  242. echo "-->\n";
  243. if (strlen($shell_result) > 0) {
  244. echo "<table width=\"100%\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\">\n";
  245. echo "<tr>\n";
  246. echo " <th colspan='2' align='left' valign='top'>".$text['title-mem']."</th>\n";
  247. echo "</tr>\n";
  248. echo "<tr>\n";
  249. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  250. echo " ".$text['label-mem']."\n";
  251. echo " </td>\n";
  252. echo " <td class=\"row_style1\">\n";
  253. echo " <pre>\n";
  254. echo "$shell_result<br>";
  255. echo "</pre>\n";
  256. unset($shell_result);
  257. echo " </td>\n";
  258. echo "</tr>\n";
  259. echo "</table>\n";
  260. echo "<br /><br />";
  261. }
  262. }
  263. //freebsd
  264. if (stristr(PHP_OS, 'FreeBSD')) {
  265. echo "<!--\n";
  266. $shell_cmd = 'sysctl vm.vmtotal';
  267. $shell_result = shell_exec($shell_cmd);
  268. echo "-->\n";
  269. if (strlen($shell_result) > 0) {
  270. echo "<table width=\"100%\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\">\n";
  271. echo "<tr>\n";
  272. echo " <th colspan='2' align='left' valign='top'>".$text['title-mem']."</th>\n";
  273. echo "</tr>\n";
  274. echo "<tr>\n";
  275. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  276. echo " ".$text['label-mem']."\n";
  277. echo " </td>\n";
  278. echo " <td class=\"row_style1\">\n";
  279. echo " <pre>\n";
  280. echo "$shell_result<br>";
  281. echo "</pre>\n";
  282. unset($shell_result);
  283. echo " </td>\n";
  284. echo "</tr>\n";
  285. echo "</table>\n";
  286. echo "<br /><br />";
  287. }
  288. }
  289. //Windows
  290. if (stristr(PHP_OS, 'WIN')) {
  291. echo "<!--\n";
  292. // connect to WMI
  293. $wmi = new COM('WinMgmts:root/cimv2');
  294. // Query this Computer for Total Physical RAM
  295. $res = $wmi->ExecQuery('Select TotalPhysicalMemory from Win32_ComputerSystem');
  296. // Fetch the first item from the results
  297. $system = $res->ItemIndex(0);
  298. $shell_result = round($system->TotalPhysicalMemory / 1024 /1024, 0);
  299. echo "-->\n";
  300. if (strlen($shell_result) > 0) {
  301. echo "<table width=\"100%\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\">\n";
  302. echo "<tr>\n";
  303. echo " <th class='th' colspan='2' align='left'>".$text['Physical Memory']."</th>\n";
  304. echo "</tr>\n";
  305. echo "<tr>\n";
  306. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  307. echo " ".$text['label-mem']." \n";
  308. echo " </td>\n";
  309. echo " <td class=\"row_style1\">\n";
  310. echo " $shell_result mb\n";
  311. echo " </td>\n";
  312. echo "</tr>\n";
  313. echo "</table>\n";
  314. echo "<br /><br />";
  315. }
  316. }
  317. }
  318. //cpu information
  319. if (permission_exists('system_view_cpu')) {
  320. //linux
  321. if (stristr(PHP_OS, 'Linux')) {
  322. echo "<!--\n";
  323. $shell_cmd = "ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'";
  324. $shell_result = shell_exec($shell_cmd);
  325. echo "-->\n";
  326. if (strlen($shell_result) > 0) {
  327. echo "<table width=\"100%\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\">\n";
  328. echo "<tr>\n";
  329. echo " <th class='th' colspan='2' align='left' valign='top'>".$text['title-cpu']."</th>\n";
  330. echo "</tr>\n";
  331. echo "<tr>\n";
  332. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  333. echo " ".$text['label-cpu']."\n";
  334. echo " </td>\n";
  335. echo " <td class=\"row_style1\">\n";
  336. echo " <pre>\n";
  337. //$last_line = shell_exec($shell_cmd, $shell_result);
  338. //foreach ($shell_result as $value) {
  339. // echo substr($value, 0, 100);
  340. // echo "<br />";
  341. //}
  342. echo "$shell_result<br>";
  343. echo "</pre>\n";
  344. unset($shell_result);
  345. echo " </td>\n";
  346. echo "</tr>\n";
  347. echo "</table>\n";
  348. echo "<br /><br />";
  349. }
  350. }
  351. //freebsd
  352. if (stristr(PHP_OS, 'FreeBSD')) {
  353. echo "<!--\n";
  354. $shell_cmd = 'top';
  355. $shell_result = shell_exec($shell_cmd);
  356. echo "-->\n";
  357. if (strlen($shell_result) > 0) {
  358. echo "<table width=\"100%\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\">\n";
  359. echo "<tr>\n";
  360. echo " <th class='th' colspan='2' align='left' valign='top'>".$text['title-cpu']."</th>\n";
  361. echo "</tr>\n";
  362. echo "<tr>\n";
  363. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  364. echo " ".$text['label-cpu']."\n";
  365. echo " </td>\n";
  366. echo " <td class=\"row_style1\">\n";
  367. echo " <pre>\n";
  368. echo "$shell_result<br>";
  369. echo "</pre>\n";
  370. unset($shell_result);
  371. echo " </td>\n";
  372. echo "</tr>\n";
  373. echo "</table>\n";
  374. echo "<br /><br />";
  375. }
  376. }
  377. }
  378. //drive space
  379. if (permission_exists('system_view_hdd')) {
  380. if (stristr(PHP_OS, 'Linux') || stristr(PHP_OS, 'FreeBSD')) {
  381. echo "<!--\n";
  382. $shell_cmd = 'df -hP --total';
  383. $shell_result = shell_exec($shell_cmd);
  384. echo "-->\n";
  385. echo "<table width=\"100%\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\">\n";
  386. echo "<tr>\n";
  387. echo " <th class='th' colspan='2' align='left'>".$text['title-drive']."</th>\n";
  388. echo "</tr>\n";
  389. echo "<tr>\n";
  390. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  391. echo " ".$text['label-drive']." \n";
  392. echo " </td>\n";
  393. echo " <td class=\"row_style1\">\n";
  394. echo "<pre>\n";
  395. echo "$shell_result<br>";
  396. echo "</pre>\n";
  397. echo " </td>\n";
  398. echo "</tr>\n";
  399. echo "</table>\n";
  400. } else if (stristr(PHP_OS, 'WIN')) {
  401. //disk_free_space returns the number of bytes available on the drive;
  402. //1 kilobyte = 1024 byte
  403. //1 megabyte = 1024 kilobyte
  404. $drive_letter = substr($_SERVER["DOCUMENT_ROOT"], 0, 2);
  405. $disk_size = round(disk_total_space($drive_letter)/1024/1024, 2);
  406. $disk_size_free = round(disk_free_space($drive_letter)/1024/1024, 2);
  407. $disk_percent_available = round(($disk_size_free/$disk_size) * 100, 2);
  408. echo "<table width=\"100%\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\">\n";
  409. echo "<tr>\n";
  410. echo " <th class='th' colspan='2' align='left'>".$text['label-drive']."</th>\n";
  411. echo "</tr>\n";
  412. echo "<tr>\n";
  413. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  414. echo " ".$text['label-drive-capacity']." \n";
  415. echo " </td>\n";
  416. echo " <td class=\"row_style1\">\n";
  417. echo " $disk_size mb\n";
  418. echo " </td>\n";
  419. echo "</tr>\n";
  420. echo "<tr>\n";
  421. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  422. echo " ".$text['label-drive-free']." \n";
  423. echo " </td>\n";
  424. echo " <td class=\"row_style1\">\n";
  425. echo " $disk_size_free mb\n";
  426. echo " </td>\n";
  427. echo "</tr>\n";
  428. echo "<tr>\n";
  429. echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
  430. echo " ".$text['label-drive-percent']." \n";
  431. echo " </td>\n";
  432. echo " <td class=\"row_style1\">\n";
  433. echo " $disk_percent_available% \n";
  434. echo " </td>\n";
  435. echo "</tr>\n";
  436. echo "</table>\n";
  437. }
  438. echo "<br /><br />";
  439. }
  440. //memcache information
  441. if (permission_exists("system_view_memcache") && file_exists($_SERVER["PROJECT_ROOT"]."/app/sip_status/app_config.php")){
  442. echo "<table width='100%' border='0' cellpadding='7' cellspacing='0'>\n";
  443. echo " <tr>\n";
  444. echo " <th class='th' colspan='2' align='left'>".$text['title-memcache']."</th>\n";
  445. echo " </tr>\n";
  446. $memcache_fail = false;
  447. $mod = new modules;
  448. if ($mod -> active("mod_memcache")) {
  449. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  450. if ($fp) {
  451. $switch_cmd = "memcache status verbose";
  452. $switch_result = event_socket_request($fp, 'api '.$switch_cmd);
  453. $memcache_lines = preg_split('/\n/', $switch_result);
  454. foreach($memcache_lines as $memcache_line) {
  455. if (strlen(trim($memcache_line)) > 0 && substr_count($memcache_line, ': ') > 0) {
  456. $memcache_temp = explode(': ', $memcache_line);
  457. $memcache_status[$memcache_temp[0]] = $memcache_temp[1];
  458. }
  459. }
  460. if (is_array($memcache_status) && sizeof($memcache_status) > 0) {
  461. foreach($memcache_status as $memcache_field => $memcache_value) {
  462. echo "<tr>\n";
  463. echo " <td width='20%' class='vncell' style='text-align: left;'>".$memcache_field."</td>\n";
  464. echo " <td class='row_style1'>".$memcache_value."</td>\n";
  465. echo "</tr>\n";
  466. }
  467. }
  468. else { $memcache_fail = true; }
  469. }
  470. else { $memcache_fail = true; }
  471. }
  472. else { $memcache_fail = true; }
  473. if ($memcache_fail) {
  474. echo "<tr>\n";
  475. echo " <td width='20%' class='vncell' style='text-align: left;'>".$text['label-memcache_status']."</td>\n";
  476. echo " <td class='row_style1'>".$text['message-unavailable']."</td>\n";
  477. echo "</tr>\n";
  478. }
  479. echo "</table>\n";
  480. echo "<br /><br />\n";
  481. }
  482. //include the footer
  483. require_once "resources/footer.php";
  484. ?>