Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane James Rose */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('system_view_info') || permission_exists('system_view_cpu') || permission_exists('system_view_hdd') || permission_exists('system_view_ram') || permission_exists('system_view_backup')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //additional includes require_once "resources/header.php"; //set the page title $document['title'] = $text['title-sys-status']; // OS Support // // For each section below wrap in an OS detection statement like: // if (stristr(PHP_OS, 'Linux')) {} // // Some possibilites for PHP_OS... // // CYGWIN_NT-5.1 // Darwin // FreeBSD // HP-UX // IRIX64 // Linux // NetBSD // OpenBSD // SunOS // Unix // WIN32 // WINNT // Windows // //system information echo "".$text['header-sys-status'].""; echo "

"; echo "\n"; echo "\n"; echo " \n"; echo "\n"; if (permission_exists('system_view_info')) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; $git_path = normalize_path_to_os($_SERVER['PROJECT_ROOT']."/.git"); if(file_exists($git_path)){ $git_exe = 'git'; if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') { $git_exe = shell_exec('which git'); } exec($git_exe.' --git-dir='.$git_path.' status', $dummy, $returnCode); if($returnCode){ echo "\n"; echo " \n"; echo " \n"; echo "\n"; }else{ $git_branch = shell_exec($git_exe.' --git-dir='.$git_path.' name-rev --name-only HEAD'); rtrim($git_branch); $git_commit = shell_exec($git_exe.' --git-dir='.$git_path.' rev-parse HEAD'); rtrim($git_commit); $git_origin = shell_exec($git_exe.' --git-dir='.$git_path.' config --get remote.origin.url'); rtrim($git_origin); $git_origin = preg_replace('/\.git$/','',$git_origin); $git_status = shell_exec($git_exe.' --git-dir='.$git_path.' status | grep "Your branch"'); rtrim($git_status); $git_age = shell_exec($git_exe.' --git-dir='.$git_path.' log --pretty=format:%at "HEAD^!"'); rtrim($git_age); $git_date = DateTime::createFromFormat('U', $git_age); $git_age = $git_date->diff(new DateTime('now')); echo "\n"; echo " \n"; echo " \n"; echo "\n"; } } echo "\n"; echo " \n"; echo " \n"; echo "\n"; $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $switch_version = event_socket_request($fp, 'api version'); preg_match("/FreeSWITCH Version (\d+\.\d+\.\d+(?:\.\d+)?).*\(.*?(\d+\w+)\s*\)/", $switch_version, $matches); $switch_version = $matches[1]; $switch_bits = $matches[2]; echo "\n"; echo " \n"; echo " \n"; echo "\n"; preg_match("/\(git\s*(.*?)\s*\d+\w+\s*\)/", $switch_version, $matches); $switch_git_info = $matches[1]; if(strlen($switch_git_info) > 0){ echo "\n"; echo " \n"; echo " \n"; echo "\n"; } } echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo "\n"; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { echo "\n"; } else { echo "\n"; } if (strlen($os_name) > 0) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; } if (strlen($os_version) > 0) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; } if (strlen($os_kernel) > 0) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; } unset($os_name, $os_version, $os_kernel); echo "\n"; if (strlen($tmp_result) > 0) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; } unset($tmp_result); } echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".$text['title-sys-info']."
\n"; echo " ".$text['label-version']."\n"; echo " \n"; echo " ".software::version()."\n"; echo "
\n"; echo " ".$text['label-git_info']."\n"; echo " \n"; echo " ".$text['label-git_corrupted']."\n"; echo "
\n"; echo " ".$text['label-git_info']."\n"; echo " \n"; echo " ".$text['label-git_branch'].": ".$git_branch."
\n"; echo " ".$text['label-git_commit'].": ".$git_commit."
\n"; echo " ".$text['label-git_origin'].": ".$git_origin."
\n"; echo " ".$text['label-git_status'].": ".$git_status.$git_age->format(' %R%a days ago')."
\n"; echo "
\n"; echo " ".$text['label-path']."\n"; echo " \n"; echo " ".$_SERVER['PROJECT_ROOT']."\n"; echo "
\n"; echo " ".$text['label-switch']." ".$text['label-version']."\n"; echo " $switch_version ($switch_bits)
\n"; echo " ".$text['label-switch']." ".$text['label-git_info']."\n"; echo " $switch_git_info
\n"; echo " ".$text['label-php']." ".$text['label-version']."\n"; echo " ".phpversion()."
".$text['title-os-info']."
\n"; echo " ".$text['label-os']." \n"; echo " \n"; echo " ".$os_name." \n"; echo "
\n"; echo " ".$text['label-version']." \n"; echo " \n"; echo " ".$os_version." \n"; echo "
\n"; echo " ".$text['label-kernel']." \n"; echo " \n"; echo " ".$os_kernel." \n"; echo "
\n"; echo " Uptime\n"; echo " \n"; echo " ".$tmp_result." \n"; echo "
\n"; echo " Date\n"; echo " \n"; echo " ".date('r')." \n"; echo "
\n"; echo "

"; //memory information if (permission_exists('system_view_ram')) { //linux if (stristr(PHP_OS, 'Linux')) { echo "\n"; if (strlen($shell_result) > 0) { echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".$text['title-mem']."
\n"; echo " ".$text['label-mem']."\n"; echo " \n"; echo "
\n";
				echo "$shell_result
"; echo "
\n"; unset($shell_result); echo "
\n"; echo "

"; } } //freebsd if (stristr(PHP_OS, 'FreeBSD')) { echo "\n"; if (strlen($shell_result) > 0) { echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".$text['title-mem']."
\n"; echo " ".$text['label-mem']."\n"; echo " \n"; echo "
\n";
				echo "$shell_result
"; echo "
\n"; unset($shell_result); echo "
\n"; echo "

"; } } //Windows if (stristr(PHP_OS, 'WIN')) { echo "\n"; if (strlen($shell_result) > 0) { echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".$text['Physical Memory']."
\n"; echo " ".$text['label-mem']." \n"; echo " \n"; echo " $shell_result mb\n"; echo "
\n"; echo "

"; } } } //cpu information if (permission_exists('system_view_cpu')) { //linux if (stristr(PHP_OS, 'Linux')) { echo "\n"; if (strlen($shell_result) > 0) { echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".$text['title-cpu']."
\n"; echo " ".$text['label-cpu']."\n"; echo " \n"; echo "
\n";

				//$last_line = shell_exec($shell_cmd, $shell_result);
				//foreach ($shell_result as $value) {
				//	echo substr($value, 0, 100);
				//	echo "
"; //} echo "$shell_result
"; echo "
\n"; unset($shell_result); echo "
\n"; echo "

"; } } //freebsd if (stristr(PHP_OS, 'FreeBSD')) { echo "\n"; if (strlen($shell_result) > 0) { echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".$text['title-cpu']."
\n"; echo " ".$text['label-cpu']."\n"; echo " \n"; echo "
\n";
				echo "$shell_result
"; echo "
\n"; unset($shell_result); echo "
\n"; echo "

"; } } } //drive space if (permission_exists('system_view_hdd')) { if (stristr(PHP_OS, 'Linux') || stristr(PHP_OS, 'FreeBSD')) { echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".$text['title-drive']."
\n"; echo " ".$text['label-drive']." \n"; echo " \n"; echo "
\n";
			echo "$shell_result
"; echo "
\n"; echo "
\n"; } else if (stristr(PHP_OS, 'WIN')) { //disk_free_space returns the number of bytes available on the drive; //1 kilobyte = 1024 byte //1 megabyte = 1024 kilobyte $drive_letter = substr($_SERVER["DOCUMENT_ROOT"], 0, 2); $disk_size = round(disk_total_space($drive_letter)/1024/1024, 2); $disk_size_free = round(disk_free_space($drive_letter)/1024/1024, 2); $disk_percent_available = round(($disk_size_free/$disk_size) * 100, 2); echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
".$text['label-drive']."
\n"; echo " ".$text['label-drive-capacity']." \n"; echo " \n"; echo " $disk_size mb\n"; echo "
\n"; echo " ".$text['label-drive-free']." \n"; echo " \n"; echo " $disk_size_free mb\n"; echo "
\n"; echo " ".$text['label-drive-percent']." \n"; echo " \n"; echo " $disk_percent_available% \n"; echo "
\n"; } echo "

"; } //memcache information if (permission_exists("system_view_memcache") && file_exists($_SERVER["PROJECT_ROOT"]."/app/sip_status/app_config.php")){ echo "\n"; echo " \n"; echo " \n"; echo " \n"; $memcache_fail = false; $mod = new modules; if ($mod -> active("mod_memcache")) { $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $switch_cmd = "memcache status verbose"; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); $memcache_lines = preg_split('/\n/', $switch_result); foreach($memcache_lines as $memcache_line) { if (strlen(trim($memcache_line)) > 0 && substr_count($memcache_line, ': ') > 0) { $memcache_temp = explode(': ', $memcache_line); $memcache_status[$memcache_temp[0]] = $memcache_temp[1]; } } if (is_array($memcache_status) && sizeof($memcache_status) > 0) { foreach($memcache_status as $memcache_field => $memcache_value) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; } } else { $memcache_fail = true; } } else { $memcache_fail = true; } } else { $memcache_fail = true; } if ($memcache_fail) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; } echo "
".$text['title-memcache']."
".$memcache_field."".$memcache_value."
".$text['label-memcache_status']."".$text['message-unavailable']."
\n"; echo "

\n"; } //include the footer require_once "resources/footer.php"; ?>