<?php
include($O__libPath . "/functions/server/O__tableMaker.php");
include($O__libPath . "/functions/server/O__backupData.php");
include($O__libPath . "/functions/server/O__tagGet.php");

// Load settings
$O__fileData = O__XMLdata($O__DBpath . "/pageTypes/" . $O__PT . "/configs/settings.xml", 0, 0);
unset($O__fileData);

$O__systemMsg = "";

function O__systemInfoGet($O__tableTitle,$O__path){
	global $O__userID, $O__signLog, $O__libPath;
	
	$O__output = "";
	$O__colLabels = array($O__tableTitle,"Version");
	$O__filesArray = O__dirToArray($O__path);
	sort($O__filesArray);
	
	for($i=0;$i<count($O__filesArray);$i++){		
		$O__data[$i][0] = substr($O__filesArray[$i][0],0,-4);
		$O__dataPath = $O__path . "/" . $O__filesArray[$i][0];
		$O__dataString = O__tagGet($O__dataPath,"<outscirt>","</outscirt>",1);
				
		$O__dataXML = simplexml_load_string($O__dataString);
		if ($O__dataXML === false){ // If XML is invalid, log the error and insert unknown
			if ($O__signLog == 1){ O__logger("errors",$O__dataPath,"Error",$O__userID,"Bad XML: O__sysInfoGet could not load embedded XML."); }
			$O__data[$i][1] = "unknown";
		} else {
			$O__data[$i][1] = $O__dataXML->version;
		}				
	}

	$O__output .= O__tableMaker($O__colLabels,$O__data,"O__table","O__tablePageTypes",0) . "<br>";
	return $O__output;
}

function O__createOutput(){
	global $O__DBpath, $O__libPath, $O__PT, $O__systemMsg;

	$O__output = "<h2>System Information</h2>";
	$O__output .= $O__systemMsg;

	// OutSCIRT Origin Package
	$O__dataString = O__tagGet("./index.php","<outscirt>","</outscirt>",1);
	$O__dataXML = O__XMLdata("./index.php",$O__dataString,1);
	//$O__version = "unknown";
	$O__version = $O__dataXML->version;

	// O__header
	$O__dataString = O__tagGet("./libraries/system/O__header.php","<outscirt>","</outscirt>",1);
	$O__dataXML = O__XMLdata("./libraries/system/O__header.php",$O__dataString,1);
	//$O__headerVersion = "unknown";
	$O__headerVersion = $O__dataXML->version;

	// O__errorOut
	$O__dataString = O__tagGet("./O__errorOut.php","<outscirt>","</outscirt>",1);
	$O__dataXML = O__XMLdata("./O__errorOut.php",$O__dataString,1);
	//$O__errorOutVersion = "unknown";
	$O__errorOutVersion = $O__dataXML->version;
	

	// Technology Info
	$O__data = array();
	$O__colLabels = array("Technology","Details");
	$O__data[0][0] = "PHP";
	$O__data[0][1] = "version " . phpversion();
	$O__data[1][0] = "Webserver";
	$O__data[1][1] = $_SERVER["SERVER_SOFTWARE"];
	$O__data[2][0] = "Operating System";
	$O__data[2][1] = php_uname("s");
	$O__output .= O__tableMaker($O__colLabels,$O__data,"O__table","O__tablePageTypes",0) . "<br>";
	unset($O__data);
	
	//OutSCIRT Info
	$O__colLabels = array("OutSCIRT: Core Info","Version");
	$O__data[0][0] = "OutSCIRT Origin Package";
	$O__data[0][1] = $O__version;
	$O__data[1][0] = "O__header";
	$O__data[1][1] = $O__headerVersion;
	$O__data[2][0] = "O__errorOut";
	$O__data[2][1] = $O__errorOutVersion;
	$O__output .= O__tableMaker($O__colLabels,$O__data,"O__table","O__tablePageTypes",0) . "<br>";
	
	// OutSCIRT Info
	$O__output .= O__systemInfoGet("Functions: Client", $O__libPath . "/functions/client");
	$O__output .= O__systemInfoGet("Functions: Server", $O__libPath . "/functions/server");
	$O__output .= O__systemInfoGet("Layouts", $O__DBpath . "/layouts");
	$O__output .= O__systemInfoGet("Themes", $O__DBpath . "/themes");
	return $O__output; 
}

if(isset($_POST["O__operation"])){ O__operations(); }
$O__output = O__createOutput();
?>
