<?php
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
/*------------------------------------------------------------------------------
     The contents of this file are subject to the Mozilla Public License
     Version 1.1 (the "License"); you may not use this file except in
     compliance with the License. You may obtain a copy of the License at
     http://www.mozilla.org/MPL/

     Software distributed under the License is distributed on an "AS IS"
     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
     License for the specific language governing rights and limitations
     under the License.

     The Original Code is fun_up.php, released on 2003-03-31.

     The Initial Developer of the Original Code is The QuiX project.

     Alternatively, the contents of this file may be used under the terms
     of the GNU General Public License Version 2 or later (the "GPL"), in
     which case the provisions of the GPL are applicable instead of
     those above. If you wish to allow use of your version of this file only
     under the terms of the GPL and not to allow others to use
     your version of this file under the MPL, indicate your decision by
     deleting  the provisions above and replace  them with the notice and
     other provisions required by the GPL.  If you do not delete
     the provisions above, a recipient may use your version of this file
     under either the MPL or the GPL."
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
Author: Mambo Dev Team
	  Soeren

Comment:
	New for MamboXplorer
	Replaces the missing System Info Panel in Mambo >= 4.5.2
	Have Fun...
------------------------------------------------------------------------------*/
//------------------------------------------------------------------------------


/**
* @package mamboXplorer
*/

function get_php_setting($val) {
	$r =  (ini_get($val) == '1' ? 1 : 0);
	return $r ? 'ON' : 'OFF';
}

function get_server_software() {
	if (isset($_SERVER['SERVER_SOFTWARE'])) {
		return $_SERVER['SERVER_SOFTWARE'];
	} else if (($sf = getenv('SERVER_SOFTWARE'))) {
		return $sf;
	} else {
		return 'n/a';
	}
}

function system_info( $option ) {
	global $mosConfig_absolute_path, $database, $_VERSION;
	//$tab = mosGetParam( $_REQUEST, 'tab', 'tab1' );
	$width = 400;	// width of 100%
	$tabs = new mosTabs(0);
	?><br/><div class="sectionname" align="left">
	<img src="images/systeminfo.png" border="0" align="center" alt="SystemInfo" /> Mambo System Info</div>
	<br/>
	<?php
	$tabs->startPane("sysinfo");
	$tabs->startTab("System Info","system-page");
	?>
	<table class="adminform">
	<tr>
		<td valign="top" width="250">
		<b>
		PHP built On:
		</b>
		</td>
		<td>
		<?php echo php_uname(); ?>
		</td>
	</tr>
	<tr>
		<td>
		<b>
		Database Version:
		</b>
		</td>
		<td>
		<?php echo mysql_get_server_info(); ?> 
		</td>
	</tr>
	<tr>
		<td>
		<b>
		PHP Version:
		</b>
		</td>
		<td>
		<?php echo phpversion(); ?>
		</td>
	</tr>
	<tr>
		<td>
		<b>
		Web Server:
		</b>
		</td>
		<td>
		<?php echo get_server_software(); ?>
		</td>
	</tr>
	<tr>
		<td>
		<b>
		WebServer to PHP interface:
		</b>
		</td>
		<td>
		<?php echo php_sapi_name(); ?>
		</td>
	</tr>
	<tr>
		<td>
		<b>
		Mambo Version:
		</b>
		</td>
		<td>
		<?php echo $_VERSION->PRODUCT .' '. $_VERSION->RELEASE .'.'. $_VERSION->DEV_LEVEL .' '
. $_VERSION->DEV_STATUS
.' [ '.$_VERSION->CODENAME .' ] '. $_VERSION->RELDATE .' '
. $_VERSION->RELTIME .' '. $_VERSION->RELTZ; ?>
		</td>
	</tr>
	<tr>
		<td>
		<b>
		User Agent:
		</b>
		</td>
		<td>
		<?php echo phpversion() <= "4.2.1" ? getenv( "HTTP_USER_AGENT" ) : $_SERVER['HTTP_USER_AGENT'];?>
		</td>
	</tr>
	<tr>
		<td valign="top">
		<b>
		Relevant PHP Settings:
		</b>
		</td>
		<td> 
			<table cellspacing="1" cellpadding="1" border="0">
			<tr>
				<td>
				Safe Mode:
				</td>
				<td>
				<?php echo get_php_setting('safe_mode'); ?>
				</td>
			</tr>
			<tr>
				<td>
				Open basedir:
				</td>
				<td>
				<?php echo (($ob = ini_get('open_basedir')) ? $ob : 'none'); ?>
				</td>
			</tr>
			<tr>
				<td>
				Display Errors:
				</td>
				<td>
				<?php echo get_php_setting('display_errors'); ?>
				</td>
			</tr>
			<tr>
				<td>
				Short Open Tags:
				</td>
				<td>
				<?php echo get_php_setting('short_open_tag'); ?>
				</td>
			</tr>
			<tr>
				<td>
				File Uploads:
				</td>
				<td>
				<?php echo get_php_setting('file_uploads'); ?>
				</td>
			</tr>
			<tr>
				<td>
				Magic Quotes:
				</td>
				<td>
				<?php echo get_php_setting('magic_quotes_gpc'); ?>
				</td>
			</tr>
			<tr>
				<td>
				Register Globals:
				</td>
				<td>
				<?php echo get_php_setting('register_globals'); ?>
				</td>
			</tr>
			<tr>
				<td>
				Output Buffering:
				</td>
				<td>
				<?php echo get_php_setting('output_buffering'); ?>
				</td>
			</tr>
			<tr>
				<td>
				Session save path:
				</td>
				<td>
				<?php echo (($sp=ini_get('session.save_path'))?$sp:'none'); ?>
				</td>
			</tr>
			<tr>
				<td>
				Session auto start:
				</td>
				<td>
				<?php echo intval( ini_get( 'session.auto_start' ) ); ?>
				</td>
			</tr>
			<tr>
				<td>
				XML enabled:
				</td>
				<td>
				<?php echo extension_loaded('xml')?'Yes':'No'; ?>
				</td>
			</tr>
			<tr>
				<td>
				Zlib enabled:
				</td>
				<td>
				<?php echo extension_loaded('zlib')?'Yes':'No'; ?>
				</td>
			</tr>
			<tr>
				<td>
				Disabled Functions:
				</td>
				<td>
				<?php echo (($df=ini_get('disable_functions'))?$df:'none'); ?>
				</td>
			</tr>
			<?php
			$query = "SELECT name FROM #__mambots"
			. "\nWHERE folder='editors' AND published='1'"
			. "\nLIMIT 1";
			$database->setQuery( $query );
			$editor = $database->loadResult();
			?>
			<tr>
				<td>
				WYSIWYG Editor:
				</td>
				<td>
				<?php echo $editor; ?>
				</td>
			</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td valign="top">
		<b>
		Configuration File:
		</b>
		</td>
		<td>
		<?php
		$cf = file( "$mosConfig_absolute_path/configuration.php" );
		foreach ($cf as $k=>$v) {
			if (eregi( 'mosConfig_host', $v)) {
				$cf[$k] = '$mosConfig_host = \'xxxxxx\'';
			} else if (eregi( 'mosConfig_user', $v)) {
				$cf[$k] = '$mosConfig_user = \'xxxxxx\'';
			} else if (eregi( 'mosConfig_password', $v)) {
				$cf[$k] = '$mosConfig_password = \'xxxxxx\'';
			} else if (eregi( 'mosConfig_db ', $v)) {
				$cf[$k] = '$mosConfig_db = \'xxxxxx\'';
			} else if (eregi( '<?php', $v)) {
				$cf[$k] = '&lt;?php';
			}
		}
		echo implode( "<br />", $cf );
		?>
		</td>
	</tr>
	</table>
	<?php
	$tabs->endTab();
	$tabs->startTab("PHP Info","php-page");
	?>
	<table class="adminform">
	<tr>
		<th colspan="2">
		PHP Information
		</th>
	</tr>
	<tr>
		<td>
		<?php
		ob_start();
		phpinfo(INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES);
		$phpinfo = ob_get_contents();
		ob_end_clean();
		preg_match_all('#<body[^>]*>(.*)</body>#siU', $phpinfo, $output);
		$output = preg_replace('#<table#', '<table class="adminlist" align="center"', $output[1][0]);
		$output = preg_replace('#(\w),(\w)#', '\1, \2', $output);
		$output = preg_replace('#border="0" cellpadding="3" width="600"#', 'border="0" cellspacing="1" cellpadding="4" width="95%"', $output);
		$output = preg_replace('#<hr />#', '', $output);
		echo $output;
		?>
		</td>
	</tr>
	</table>
	<?php
	$tabs->endTab();
	$tabs->startTab('Permissions','perms');
	?>
	<table class="adminform">
	  <tr>
		<th colspan="2"> Directory Permissions</th>
	  </tr>
	  <tr>
		<td>
	<strong>For all Mambo functions and features to work ALL of the following directories should be writeable:</strong>
		<?php
		  mosHTML::writableCell( 'administrator/backups' );
		  mosHTML::writableCell( 'administrator/components' );
		  mosHTML::writableCell( 'administrator/modules' );
		  mosHTML::writableCell( 'administrator/templates' );
		  mosHTML::writableCell( 'cache' );
		  mosHTML::writableCell( 'components' );
		  mosHTML::writableCell( 'images' );
		  mosHTML::writableCell( 'images/banners' );
		  mosHTML::writableCell( 'images/stories' );
		  mosHTML::writableCell( 'language' );
		  mosHTML::writableCell( 'mambots' );
		  mosHTML::writableCell( 'mambots/content' );
		  mosHTML::writableCell( 'mambots/search' );
		  mosHTML::writableCell( 'media' );
		  mosHTML::writableCell( 'modules' );
		  mosHTML::writableCell( 'templates' );
?>
	
		</td>
	  </tr>
	</table>
	<?php
	$tabs->endTab();		
	$tabs->endPane();
	?>
	<?php 
}
show_header("Mambo System Info&nbsp;&nbsp;<a href=\"index2.php?option=$option\">[ Back ]</a>");
system_info( $option );
?>
