<?php
/*<outscirt><version>20201122</version></outscirt>*/

include("./libraries/functions/server/O__dataWrite.php");
?>

<html>
<head>
<title>OutSCIRT Setup</title>
</head>
<body>
<h1>OutSCIRT Setup</h1>

<ol>
	<!-- START: Create .ini file -->
	<li><b>Creating .ini file</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/system/ini.php";
		if (!file_exists($O__tempFilePath)) { 
			$O__iniFile = "<?php\r\n";
			$O__iniFile .= "/**********\r\n";
			$O__iniFile .= "System paths\r\n";
			$O__iniFile .= "**********/\r\n";
			$O__iniFile .= "\$O__rootPath = \"" . getcwd() . "\"; //Example: /var/www/html or C:/OutSCIRT \r\n";
			$O__iniFile .= "\$O__DBpath = \$O__rootPath . \"/DB\";\r\n";
			$O__iniFile .= "\$O__libPath = \$O__rootPath . \"/libraries\";\r\n";
			$O__iniFile .= "\$O__filePaths = array( // PageType accessible paths\r\n";
			$O__iniFile .= "\tarray(\$O__rootPath . \"/files\", \"Web Files\"),\r\n";
			$O__iniFile .= "\tarray(\$O__DBpath . \"/pageTypes/O__blog/areas\", \"Blog Content\"),\r\n";
			$O__iniFile .= "\tarray(\$O__DBpath . \"/pageTypes/O__page/areas\", \"Page Content\")\r\n";
			$O__iniFile .= ");\r\n";
			$O__iniFile .= "\$O__usersDataPath = \$O__DBpath . \"/pageTypes/O__users/data/\";\r\n";
			$O__iniFile .= "\$O__backupsPath = \$O__DBpath . \"/backups\";\r\n";
			
			$O__iniFile .= "\r\n/**********\r\n";
			$O__iniFile .= "Caching and overrides\r\n";
			$O__iniFile .= "**********/\r\n";
			$O__iniFile .= "ini_set(\"session.cache_limiter\",\"public\");\r\n";
			$O__iniFile .= "session_cache_limiter(false);\r\n";
			
			$O__iniFile .= "\r\n/**********\r\n";
			$O__iniFile .= "Authentication and sessions\r\n";
			$O__iniFile .= "**********/\r\n";
			$O__iniFile .= "\$O__useSessions = 1;\r\n";
			$O__iniFile .= "\$O__cookieExpire = (86400 * 30);\r\n";
			$O__iniFile .= "\$O__cookiePath = \"/\";\r\n";
			$O__iniFile .= "\$O__userID = \"anonymous\";  // default\r\n";
			
			$O__iniFile .= "\r\n/**********\r\n";
			$O__iniFile .= "Errors and logging\r\n";
			$O__iniFile .= "**********/\r\n";
			$O__iniFile .= "\$O__signLog = 1;\r\n";
			$O__iniFile .= "\$O__errorDisplayOff = 1;\r\n";
			$O__iniFile .= "\$O__logPath = \$O__DBpath . \"/pageTypes/O__logs/data/\";\r\n";
			$O__iniFile .= "\$O__logFileMax = 24; // in KBs\r\n";
			
			$O__iniFile .= "\r\n/**********\r\n";
			$O__iniFile .= "Misc preferences\r\n";
			$O__iniFile .= "**********/\r\n";
			$O__iniFile .= "\$O__xCryptMethod = \"md5\";\r\n";
			$O__iniFile .= "date_default_timezone_set(\"America/Los_Angeles\");\r\n";
			$O__iniFile .= "\$O__aliasCheck = 1;\r\n";
			$O__iniFile .= "\$O__redirectCheck = 1;\r\n";
			$O__iniFile .= "\$O__redirectSecureForce = 0;\r\n";
			
			$O__iniFile .= "\r\n/**********\r\n";
			$O__iniFile .= "HTML\r\n";
			$O__iniFile .= "**********/\r\n";
			$O__iniFile .= "\$O__docType  = \"html\";\r\n";
			$O__iniFile .= "\$O__lang = \"\";\r\n";
			$O__iniFile .= "\$O__xmlns = \"\"; // Example: http://www.w3.org/1999/xhtml\r\n";
			$O__iniFile .= "\$O__xmlLang = \$O__lang;\r\n";
			$O__iniFile .= "\$O__bodyID = \"O__pageBody\";\r\n";
			$O__iniFile .= "?>\r\n";

			O__dataWrite($O__tempFilePath,$O__iniFile);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  ini.php file exists!  Existing file NOT overwritten.<br><br></li>
	<?php } ?>
	<!-- END: Create .ini file -->

	<!-- START: Create "access" log file-->
	<li><b>Creating "access" log file</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__logs/data/access";
		if (!file_exists($O__tempFilePath)) {
			$O_logLine = "Date: " . date("Y-m-d") . "\tTime: " . date("h:i:s") . "\tPage: O__setup\tStatus: Success\tUser: MACHINE\tIP: " . $_SERVER["REMOTE_ADDR"] . "\tNotes: Initial OutSCIRT setup";
			O__dataWrite($O__tempFilePath,$O_logLine);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "access" file exists! Existing file NOT overwritten.<br><br></li>
	<?php } ?>
	<!-- END: Create "access" log file-->

	<!-- START: Create "errors" log file-->
	<li><b>Creating "errors" log file</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__logs/data/errors";
		if (!file_exists($O__tempFilePath)) {
			$O_logLine = "Date: " . date("Y-m-d") . "\tTime: " . date("h:i:s") . "\tPage: O__setup\tStatus: Success\tUser: MACHINE\tIP: " . $_SERVER["REMOTE_ADDR"] . "\tNotes: Initial OutSCIRT setup";
			O__dataWrite($O__tempFilePath,$O_logLine);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "errors" file exists! Existing file NOT overwritten.<br><br></li>
	<?php }	?>
	<!-- END: Create "errors" log file-->

	<!-- START: Create backups directory-->
	<li><b>Creating directory for storing file backups</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/backups";
		if (!file_exists($O__tempFilePath)) {
			mkdir($O__tempFilePath, 0700);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "backups" directory exists! Existing directory has not been replaced.<br><br></li>
	<?php } ?>
	<!-- END: Create backups directory-->

	<!-- START: Create temp directory-->
	<li><b>Creating directory for storing temporary files</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/temp";
		if (!file_exists($O__tempFilePath)) {
			mkdir($O__tempFilePath, 0700);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "temp" directory exists! Existing directory has not been replaced.<br><br></li>
	<?php } ?>
	<!-- END: Create temp directory-->

	<!-- START: Create sessions directory -->
	<li><b>Creating directory for storing sessions</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__users/data/sessions";
		if (!file_exists($O__tempFilePath)) {
			mkdir($O__tempFilePath, 0700);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "sessions" directory exists! Existing directory has not been replaced.<br><br></li>
	<?php } ?>
	<!-- END: Create sessions directory -->

	<!-- START: Create users directory -->
	<li><b>Creating directory for storing users</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__users/data/users";
		if (!file_exists($O__tempFilePath)) {
			mkdir($O__tempFilePath, 0700);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "users" directory exists! Existing directory has not been replaced.<br><br></li>
	<?php } ?>
	<!-- END: Create users directory -->

	<!-- START: Create groups directory -->
	<li><b>Creating directory for storing groups</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__users/data/groups";
		if (!file_exists($O__tempFilePath)) {
			mkdir($O__tempFilePath, 0700);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "groups" directory exists! Existing directory has not been replaced.<br><br></li>
	<?php } ?>
	<!-- END: Create groups directory -->

	<!-- START: Create default administrator group -->
	<li><b>Creating default administrator group</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__users/data/groups/administrator.xml";
		if (!file_exists($O__tempFilePath)) {
			$O__userAcct = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";	
			$O__userAcct .= "\t<group>\r\n";
			$O__userAcct .= "\t\t\t<name>Administrator</name>\r\n";
			$O__userAcct .= "\t\t\t<protected>1</protected>\r\n";
			$O__userAcct .= "\t<permissions>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__blog</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>manage,display,edit</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__page</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>manage,display,edit</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__dataParser</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>manage,display,edit</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__aliases</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>edit</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__kiosk</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>manage,display,edit</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__redirects</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>edit</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__users</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>manage,edit,editGroup</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__screensaver</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__pageTypes</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>manage</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__logs</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display,manage</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__login</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>login,verify,logout</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__files</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display,manage</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__text</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>editor,update</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__launch</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__updateMode</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__private</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__menu</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display,edit,manage</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__settings</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>edit</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__sysInfo</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t</permissions>\r\n";	
			$O__userAcct .= "\t</group>\r\n";

			O__dataWrite($O__tempFilePath,$O__userAcct);
	?>
	SUCCESS!  Administrator group has been created!<br><br></li>
	<?php } else { ?>
	FAILED!  Administrator group exists and has not been changed.<br><br></li>
	<?php } ?>
	<!-- END: Create default administrator group -->

	<!-- START: Create default administrator user -->
	<li><b>Creating default administrator</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__users/data/users/b718adec73e04ce3ec720dd11a06a308.xml";
		if (!file_exists($O__tempFilePath)) {
			$O__userAcct = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";	
			$O__userAcct .= "\t<user>\r\n";
			$O__userAcct .= "\t\t\t<name>ID</name>\r\n";
			$O__userAcct .= "\t\t\t<nameFirst>OutSCIRT</nameFirst>\r\n";
			$O__userAcct .= "\t\t\t<nameLast>Administrator</nameLast>\r\n";
			$O__userAcct .= "\t\t\t<pw>319f4d26e3c536b5dd871bb2c52e3178</pw>\r\n";
			$O__userAcct .= "\t\t\t<groups>administrator</groups>\r\n";
			$O__userAcct .= "\t</user>\r\n";

			O__dataWrite($O__tempFilePath,$O__userAcct);
	?>
	SUCCESS!  Your username is "ID" and your password is "PASSWORD".  Please change these immediately upon logging in!<br><br></li>
	<?php } else { ?>
	FAILED!  Default user exists and has not been changed.<br><br></li>
	<?php } ?>
	<!-- END: Create default administrator -->
	
	<!-- START: Create "anonymous" group-->
	<li><b>Creating "anonymous" group</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__users/data/groups/anonymous.xml";
		if (!file_exists($O__tempFilePath)) {
			$O__userAcct = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
			$O__userAcct .= "<group>\r\n";
			$O__userAcct .= "\t<name>Anonymous</name>\r\n";
			$O__userAcct .= "\t<protected>0</protected>\r\n";
			$O__userAcct .= "\t<permissions>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__login</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>login,verify,logout</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__page</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t\t<pageType>\r\n";
			$O__userAcct .= "\t\t\t<name>O__blog</name>\r\n";
			$O__userAcct .= "\t\t\t<actions>display</actions>\r\n";
			$O__userAcct .= "\t\t</pageType>\r\n";
			$O__userAcct .= "\t</permissions>\r\n";
			$O__userAcct .= "</group>\r\n";

			O__dataWrite($O__tempFilePath,$O__userAcct);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "anonymous" group exists and has not been changed.<br><br></li>
	<?php } ?>
	<!-- END: Create "anonymous" group -->
	
	<!-- START: Create "anonymous" user -->
	<li><b>Creating "anonymous" user</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/pageTypes/O__users/data/users/294de3557d9d00b3d2d8a1e6aab028cf.xml";
		if (!file_exists($O__tempFilePath)) {
			$O__userAcct = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
			$O__userAcct .= "<user>\r\n";
			$O__userAcct .= "\t<name>anonymous</name>\r\n";
			$O__userAcct .= "\t<nameFirst>anonymous</nameFirst>\r\n";
			$O__userAcct .= "\t<nameLast>anonymous</nameLast>\r\n";
			$O__userAcct .= "\t<pw>294de3557d9d00b3d2d8a1e6aab028cf294de3557d9d00b3d2d8a1e6aab028cf294de3557d9d00b3d2d8a1e6aab028cf</pw>\r\n";
			$O__userAcct .= "\t<groups>anonymous</groups>\r\n";
			$O__userAcct .= "</user>\r\n";

			O__dataWrite($O__tempFilePath,$O__userAcct);
	?>
	SUCCESS!<br><br></li>
	<?php } else { ?>
	FAILED!  "anonymous" user exists and has not been changed.<br><br></li>
	<?php } ?>
	<!-- END: Create "anonymous" user -->

	<!-- START: Move O__setup.php to backups folder -->
	<li><b>Moving O__setup.php to backups folder</b> ... <br><u>Status</u>: 
	<?php
		$O__tempFilePath = "./DB/backups";
		if (file_exists($O__tempFilePath)) {
			rename("./O__setup.php", "./DB/backups/O__setup.php");
	?>
	SUCCESS!  For security purposes, the O__setup.php file has been moved to the backups folder.  If you wish to run the setup again, you must first manually move this file back to the root directory.<br><br></li>
	<?php } else { ?>
	FAILED!  The "backups" directory does not exist and so the O__setup.php file has not been moved to it.<br><br></li>
	<?php } ?>
	<!-- END: Move O__setup.php to backups folder -->
</ol>

<p>Setup complete! <b>Please note any errors above, and make corrections to permissions as needed!</b></p>

<p><i>Note: For additional security, please manually move the ./DB and ./libraries directories to a folder that is not accessible through a web browser; i.e., served up directly by the web server. Make sure the new paths to these directories are updated in the ini.php file.  Then, update the path to the ini.php file in ./index.php to point to the new location.</i></p>

<p><a href="./O__login/login">Click here to continue to the login page</a></p>
</body>
</html>
