Ejemplo n.º 1
0
	function actionFinish(&$system, $args)
	{
		global $abspath, $db_prefix, $root_id, $anonymous_id;
		$db_prefix = $this->db['prefix'];
		
		if (empty($args['theme']))
		{
			$system->addAlert("You must enter select a theme");
			return;
		}
		
		if (empty($args['imgsize']))
		{
			$system->addAlert("You must enter a imagesize");
			return;
		}
		
		if (empty($args['thumbsize']))
		{
			$system->addAlert("You must enter a thumbnailsize");
			return;
		}
		
		if (empty($args['default_lang']))
		{
			$system->addAlert("You must enter a default language");
			return;
		}
		
		if (empty($args['default_path']))
		{
			$system->addAlert("You must enter a default path");
			return;
		}
		
		if (empty($args['password']))
		{
			$system->addAlert("You must enter a password");
			return;
		}
		
		unset($args['action']);
		$this->config = $args;
		
		
		$logtext = "";
			
		if (!$db_conn = mysql_pconnect($this->db['adress'], $this->db['username'], $this->db['password']))
		{
			$system->addAlert("Error connecting to MySQL: " . mysql_errno() . " " . mysql_error());
			return;
		}
			
		if (!mysql_select_db($this->db['name']))
		{
			if (mysql_query("CREATE DATABASE `".$this->db['name']."`"))
				$logtext .= "Database ".$this->db['name']." created.<br/>";
			else
			{
				$system->addAlert("Failed to create database ".$this->db['name'].". Error: " . mysql_errno() . " " . mysql_error());
				return;
			}
		}

		mysql_select_db($this->db['name']);
		
		$files = GetSubfiles("$abspath/scripts/install/db");
		foreach ($files as $file)
		{
			$query = "DROP TABLE IF EXISTS `".$this->db['prefix'].basename($file, ".sql")."`";
			mysql_query($query);
		
			$query = str_replace("%PREFIX%", $this->db['prefix'], implode("", file("$abspath/scripts/install/db/$file")));
			
			if (mysql_query($query))
				$logtext .= "Imported $file successfully.<br/>";
			else
			{
				$system->addAlert("Failed to import $file. Error: " . mysql_errno() . " " . mysql_error()."\n$query");
				return;
			}
		}
		
		$xml = new mXml();
		
		$files = GetSubfiles("$abspath/scripts/install/classes");
		foreach ($files as $file)
		{
			$filedata = getFileData($file, "$abspath/scripts/install/classes/$file");
			$msgid = $xml->parseXML(array("node_id" => 0, "data" => $filedata));
			
			$logtext .= mMsg::getText($msgid);
			
			if (mMsg::isError($msgid))
			{
				$system->addAlert(mMsg::getError($msgid));
				return;
			}
			else
				$logtext .= "Imported $file successfully.<br/>";
		}

		$files = GetSubfiles("$abspath/scripts/install/objects");
		foreach ($files as $file)
		{
			$filedata = getFileData($file, "$abspath/scripts/install/objects/$file");
			$msgid = $xml->parseXML(array("node_id" => 0, "data" => $filedata));
			
			$logtext .= mMsg::getText($msgid);
			
			if (mMsg::isError($msgid))
			{
				$system->addAlert(mMsg::getError($msgid));
				return;
			}
			else
				$logtext .= "Imported $file successfully.<br/>";
		}
		
		$root_id = 1;
		
		$admin_group_id = createGroup("admins", "Administrators group", true);
		$anon_group_id = createGroup("anonymous", "Anonymous group", false);
		
		$anon_user_id = createUserSimple("Anonymous", "anonymous", "", "", "anonymous", false);
		$anonymous_id = $anon_user_id;
		$admin_user_id = createUserSimple("Administrator", "admin", $this->config['password'], "", "admins", true);
		
		
		$files = GetSubfiles("$abspath/cache");
		foreach ($files as $file)
			unlink("$abspath/cache/$file");
			
		$files = GetSubfiles("$abspath/files");
		foreach ($files as $file)
			unlink("$abspath/files/$file");
			
		$files = GetSubfiles("$abspath/thumbnails");
		foreach ($files as $file)
			unlink("$abspath/thumbnails/$file");
		
		// Insert initial objects
/*
		$root_obj = new mObject();
		$root_obj->setClassName("folder");
		$root_obj->loadVars();
		$root_obj->setLanguage("eng");
		$root_obj->setName("root");
		$root_obj->setIcon("murrix");
		$root_obj->setRights("all=r");
		
		$root_obj->setVarValue("description", "This is the root node");

		if ($root_obj->save())
		{
			$root_obj->setMeta("initial_rights", "admins=rwc");
			$logtext .= "Created ".$root_obj->getName().".<br/>";
		}
		else
		{
			$logtext .= "Failed to create ".$root_obj->getName().".<br/>";
			$logtext .= $root_obj->error;
			$this->done = false;
		}

		$home_obj = new mObject();
		$home_obj->setClassName("folder");
		$home_obj->loadVars();
		$home_obj->setLanguage("eng");
		$home_obj->setName("home");
		$home_obj->setIcon("home");
		$home_obj->setRights("all=r");

		$home_obj->setVarValue("description", "This folder contain home folders");
		
		if ($home_obj->save())
		{
			$home_obj->linkWithNode($root_obj->getNodeId());
			$logtext .= "Created ".$home_obj->getName().".<br/>";
		}
		else
		{
			$logtext .= "Failed to create ".$home_obj->getName().".<br/>";
			$logtext .= $home_obj->error;
			$this->done = false;
		}
		
		$users_home_obj = new mObject();
		$users_home_obj->setClassName("folder");
		$users_home_obj->loadVars();
		$users_home_obj->setLanguage("eng");
		$users_home_obj->setName("users");
		$users_home_obj->setIcon("user");
		$users_home_obj->setRights("all=r");

		$users_home_obj->setVarValue("description", "This folder contain home folders");
		
		if ($users_home_obj->save())
		{
			$users_home_obj->linkWithNode($home_obj->getNodeId());
			$logtext .= "Created ".$users_home_obj->getName().".<br/>";
		}
		else
		{
			$logtext .= "Failed to create ".$users_home_obj->getName().".<br/>";
			$logtext .= $users_home_obj->error;
			$this->done = false;
		}
		
		$group_home_obj = new mObject();
		$group_home_obj->setClassName("folder");
		$group_home_obj->loadVars();
		$group_home_obj->setLanguage("eng");
		$group_home_obj->setName("groups");
		$group_home_obj->setIcon("group2");
		$group_home_obj->setRights("all=r");

		$users_home_obj->setVarValue("description", "This folder contain group folders");
		
		if ($group_home_obj->save())
		{
			$group_home_obj->linkWithNode($home_obj->getNodeId());
			$logtext .= "Created ".$group_home_obj->getName().".<br/>";
		}
		else
		{
			$logtext .= "Failed to create ".$group_home_obj->getName().".<br/>";
			$logtext .= $group_home_obj->error;
			$this->done = false;
		}
		
		$adminhome_obj = new mObject();
		$adminhome_obj->setClassName("folder");
		$adminhome_obj->loadVars();
		$adminhome_obj->setLanguage("eng");
		$adminhome_obj->setName($this->admin_username);
		$adminhome_obj->setRights("admins=rwc");

		$adminhome_obj->setVarValue("description", "This is the home for ".$this->admin_username);
		
		if ($adminhome_obj->save())
		{
			$adminhome_obj->linkWithNode($users_home_obj->getNodeId());
			$logtext .= "Created ".$adminhome_obj->getName().".<br/>";
			
			$administrator->home_id = $adminhome_obj->getNodeId();
			$administrator->save();
		}
		else
		{
			$logtext .= "Failed to create ".$adminhome_obj->getName().".<br/>";
			$logtext .= $adminhome_obj->error;
			$this->done = false;
		}
		
		$adminshome_obj = new mObject();
		$adminshome_obj->setClassName("folder");
		$adminshome_obj->loadVars();
		$adminshome_obj->setLanguage("eng");
		$adminshome_obj->setName("admins");
		$adminshome_obj->setRights("admins=rwc");

		$adminshome_obj->setVarValue("description", "This is the home for admins");
		
		if ($adminshome_obj->save())
		{
			$adminshome_obj->linkWithNode($group_home_obj->getNodeId());
			$logtext .= "Created ".$adminshome_obj->getName().".<br/>";
			
			$administrator_group->home_id = $adminshome_obj->getNodeId();
			$administrator_group->save();
		}
		else
		{
			$logtext .= "Failed to create ".$adminshome_obj->getName().".<br/>";
			$logtext .= $adminshome_obj->error;
			$this->done = false;
		}
		
		$public_obj = new mObject();
		$public_obj->setClassName("folder");
		$public_obj->loadVars();
		$public_obj->setLanguage("eng");
		$public_obj->setName("public");
		$public_obj->setRights("all=r");

		$public_obj->setVarValue("description", "This folder is readable by anyone");
		
		if ($public_obj->save())
		{
			$public_obj->linkWithNode($root_obj->getNodeId());
			$logtext .= "Created ".$public_obj->getName().".<br/>";
		}
		else
		{
			$logtext .= "Failed to create ".$public_obj->getName().".<br/>";
			$logtext .= $public_obj->error;
			$this->done = false;
		}
		*/
		
		
		
		setSetting("ROOT_NODE_ID",	1,				"any");
		setSetting("ANONYMOUS_ID",	$anonymous->id,			"any");
		setSetting("TRANSPORT",		$this->config['transport'],	"any");
		setSetting("DEFAULT_THEME",	$this->config['theme'],		"any");
		
		setSetting("IMGSIZE",		$this->config['imgsize'],	$this->config['theme']);
		setSetting("THUMBSIZE",		$this->config['thumbsize'],	$this->config['theme']);
		setSetting("INSTANTTHUMBS",	$this->config['instantthumbs'],	$this->config['theme']);
		setSetting("DEFAULT_PATH",	$this->config['default_path'],	$this->config['theme']);
		setSetting("DEFAULT_LANG",	$this->config['default_lang'],	$this->config['theme']);

		$confdata = "<?\n";
		$confdata .= "\$mysql_address = \"".$this->db['adress']."\";\n";
		$confdata .= "\$mysql_user = \"".$this->db['username']."\";\n";
		$confdata .= "\$mysql_pass = \"".$this->db['password']."\";\n";
		$confdata .= "\$mysql_db = \"".$this->db['name']."\";\n";
		$confdata .= "\$db_prefix = \"".$this->db['prefix']."\";\n";
		$confdata .= "?>";

		if (is_writable($abspath))
		{
			$conffile = fopen("$abspath/config.inc.php", "w");
			fwrite($conffile, $confdata);
			fclose($conffile);
			chmod("$abspath/config.inc.php", 0600);
			$logtext .= "Wrote config, $abspath/config.inc.php.<br/>";
		}
		else
		{
			$logtext .= "Unable to write config file.<br/>";
			$logtext .= "Please put the folowing into \"config.inc.php\" and place it in MURRiXs rootpath:<br/>";
			$logtext .= "<br/>";
			$logtext .= nl2br(htmlentities($confdata));
			$logtext .= "<br/>";
		}
		
		$logtext .= "Installation complete!<br/>";
		
		
		$data = compiletpl("finish", array("logtext"=>$logtext));
		$system->setZoneData($this->zone, utf8e($data));
		
		$data = compiletpl("menu", array("action"=>"finish"));
		$system->setZoneData("zone_menu", utf8e($data));
	}
Ejemplo n.º 2
0
	function actionImport_xml(&$system, $args)
	{
		$object = new mObject($this->getNodeId($args));

		if ($object->getNodeId() == 0 || !$object->hasRight("write"))
		{
			$system->addAlert(ucf(i18n("you do not have enough rights")));
			return;
		}
	
		if (empty($args['file']))
		{
			$system->addAlert(ucf(i18n("you must upload a file to import")));
			return;
		}
		
		list($filename, $full_filename) = explode(":", $args['file']);
		$filedata = getFileData($filename, $full_filename);
		
		
		$logtext = "<strong>Beginning import from xml file</strong> - ".date("Y-m-d H:i:s")."<hr/>";
		
		$xml = new mXml();
		
		$msgid = $xml->parseXML(array("node_id" => $object->getNodeId(), "data" => $filedata));
		
		$logtext .= mMsg::getText($msgid);
		
		$logtext .= "<hr/><strong>Finished import</strong> - ".date("Y-m-d H:i:s")."<br/><br/>";
		
		$system->paddZoneData("zone_import_log", utf8e($logtext));
	}