Exemplo n.º 1
0
	function addRoles($parent_role = null)
	{
		$roles_table = new Roles();

		// we start this recursive funtion by looking for roles with no parent.

		if (is_null($parent_role)) $roles = $roles_table->fetchParentless();
		else $roles = $roles_table->fetchImmediateChildren($parent_role);

		foreach ($roles as $role)
		{
			// Add the role and specifiy that as the parent. On the first pass, this is null.

			if (!$this->hasRole($role->id))
			{
				RivetyCore_Log::info("Adding role ".$role->shortname);
				$this->addRole(new Zend_Acl_Role($role->id), $parent_role);
			}
			if (count($roles_table->fetchImmediateChildren($role->id)) > 0)
			{
				$this->addRoles($role->id);
			}
		}
	}
Exemplo n.º 2
0
		function go($action, $params, $url = null)
		{
			$params['Action'] = $action;
			
			if(!$url) $url = $this->_server;
			
			$params['AWSAccessKeyId'] = $this->_key;
			$params['SignatureVersion'] = 1;
			$params['Timestamp'] = gmdate("Y-m-d\TH:i:s\Z");
			$params['Version'] = "2008-01-01";
			uksort($params, "strnatcasecmp");

			$toSign = "";
			foreach($params as $key => $val){
				$toSign .= $key . $val;
			}
			$sha1 = $this->hasher($toSign);
			$sig  = $this->base64($sha1);
			$params['Signature'] = $sig;

			RivetyCore_Log::report('sqs go params',$params,Zend_Log::INFO);
			$output = RivetyCore_Url::get ($url,$params);
			
			$xmlstr =$output['output'];
			RivetyCore_Log::report("output from sqs", $output,Zend_Log::DEBUG);
			try{
				$xml = new SimpleXMLElement($xmlstr);
				
				if($output['http_code'] == 200 and !isset($xml->Errors)){			
					RivetyCore_Log::report("xml from sqs", $xml,Zend_Log::DEBUG);
					return $xml;
				} else {
					return false;
				}
			} catch(Exception $ex) {
				return false;
			}
		}		
Exemplo n.º 3
0
	function setup($module_id) {
		$basepath = Zend_Registry::get("basepath");
		$module_dir = $basepath."/modules";
		$full_dir = $module_dir."/".$module_id;
		$subdirs = array("models", "plugins", "controllers", "lib");
		$tmp_include_path = "";
		try{
			$module_cfg = $this->parseIni($module_id);

			if (is_dir($full_dir)) {
			   	foreach ($subdirs as $subdir) {
					$includable_dir = $full_dir."/".$subdir;
					if (is_dir($includable_dir)) {
						$tmp_include_path .= PATH_SEPARATOR.$includable_dir;
					}
				}
				set_include_path(get_include_path().$tmp_include_path);
			}

			$this->upgradeDatabase($module_id);
			$this->setDefaultConfig($module_id);

			$ap = RivetyCore_Plugin::getInstance();

			if (count($module_cfg['plugins']) > 0) {
				foreach ($module_cfg['plugins'] as $hook => $plugin) {
					$hook_type = substr($hook, 0, strpos($hook, "."));
					$hook_name = substr($hook, strpos($hook, ".") + 1);
					$callback_class = substr($plugin, 0, strpos($plugin, "::"));
					$callback_method = substr($plugin, strpos($plugin, "::") + 2);
					if ($hook_type == "filter") {
						$ap->addFilter($hook_name, $callback_class, $callback_method, 10);
					}
					if ($hook_type == "action") {
						$ap->addAction($hook_name, $callback_class, $callback_method, 10);
					}
				}
			}
		} catch (Exception $e) {
			RivetyCore_Log::report("Could not set up ".$module_id, $e, Zend_Log::ERR);
			// $where = $this->getAdapter()->quoteInto("id = ?", $module_id);
			// $this->delete($where);
		}
	}
Exemplo n.º 4
0
	}
	else
	{
		$ex_type = trim(substr($ex->getMessage(), 0, strpos($ex->getMessage(), " ")));
		switch ($ex_type)
		{
		case "MISSING_LIBS":
			header("Location: /errordocuments/error_LIBS.html");
		break;
		case "CANT_WRITE":
			header("Location: /errordocuments/error_CANTWRITE.html");
		break;
		case "DIR_MISSING":
			header("Location: /errordocuments/error_DIRMISSING.html");
		break;
		default:
			if ($isInstalled)
			{
				header("Location: /errordocuments/error_500.html");
				RivetyCore_Log::report("Frontcontroller Error", $ex, Zend_Log::EMERG);
			}
			else
			{
				d($ex->getMessage());
				dd($ex);
			}
		break;
		}
	}
}
Exemplo n.º 5
0
	if (is_null(@$config['application']['host_id'])) $host_id = null;
	else $host_id = $config['application']['host_id'];

	if ($is_cli) $log_filename = $config['application']['log_filename_cli'];
	else $log_filename = $config['application']['log_filename'];

	Zend_Registry::set('basepath', $basepath);
	Zend_Registry::set('config_file', $config_file);
	Zend_Registry::set('host_id', $host_id);

	// create logger
	$writer = new Zend_Log_Writer_Stream($log_filename);
	$filter = new Zend_Log_Filter_Priority($log_level);
	$writer->addFilter($filter);
	RivetyCore_Log::registerLogger('rivety', $writer, true);
	RivetyCore_Log::report("Log Started", null, Zend_Log::INFO);

	// Create Plugin Manager
	$RivetyCore_plugin = RivetyCore_Plugin::getInstance();

	// define constants
	$constants = new Constants();
	set_include_path(get_include_path() . PATH_SEPARATOR . $config['application']['addtl_includes']);
	$databases = new Zend_Config_Ini($config_file, 'databases');
	$dbAdapters = array();
	foreach ($databases->db as $config_name => $db)
	{
		$dbAdapters[$config_name] = Zend_Db::factory($db->adapter, $db->config->toArray());
		if ((boolean)$db->config->default)
		{
			Zend_Db_Table::setDefaultAdapter($dbAdapters[$config_name]);
Exemplo n.º 6
0
	function fetchImmediateChildren($id){
		$roles_roles_table = new RolesRoles();
		
		$child_roles = $roles_roles_table->fetchAll($roles_roles_table->select()->where("inherits_role_id = ?",$id));
		
		if(count($child_roles) > 0){
			$role_select = $this->select();
			foreach($child_roles as $child_role){
				$role_select->orWhere("id = ?",$child_role->role_id);
			}
			RivetyCore_Log::debug($role_select->assemble());
			return $this->fetchAll($role_select);
		}		
		   
	}
Exemplo n.º 7
0
	function sendEmail($subject, $to_address, $template, $params = null, $to_name = null, $isHtml = false) {
		$useAuth = RivetyCore_Registry::get('smtp_use_auth');

		if (array_key_exists('from_email', $params)) {
			$site_from_email = $params['from_email'];
		} else {
			$site_from_email = RivetyCore_Registry::get('site_from_email');
		}

		// TODO - shouldn't this be from_name instead of from_email ?
		if (array_key_exists('from_name', $params)) {
			$site_from = $params['from_name'];
		} else {
			$site_from = RivetyCore_Registry::get('site_from');
		}

		$smtp = RivetyCore_Registry::get('smtp_server');
		$username = RivetyCore_Registry::get('smtp_username');
		$password = RivetyCore_Registry::get('smtp_password');
		$ssl = RivetyCore_Registry::get('smtp_ssl_type');  //tls
		$smtp_port = RivetyCore_Registry::get('smtp_port');

		$config = array();
		if ($useAuth == 1) {
			$config = array(
				'auth' => 'login',
          		'username' => $username,
          		'password' => $password,
				'ssl' => $ssl,
				'port' => (int)$smtp_port);
		}
		try {
          	$mailTransport = new Zend_Mail_Transport_Smtp($smtp, $config); // defines gmail smtp infrastructure as default for any email message originated by Zend_Mail.
          	Zend_Mail::setDefaultTransport($mailTransport);
			$mail = new Zend_Mail();
			foreach ($params as $key => $value) {
				$this->_smarty->assign($key, $value);
			}
			$message = $this->_smarty->fetch($template);

			if ($isHtml) {
				$mail->setBodyHtml($message);
			} else {
				$mail->setBodyText($message);
			}

			$mail->setFrom($site_from_email, $site_from);
			if (!is_null($to_name) && trim($to_name) != '') {
				$mail->addTo($to_address, $to_name);
			} else {
				$mail->addTo($to_address);
			}
			$mail->setSubject($subject);
			$mail->setReturnPath(RivetyCore_Registry::get('site_from_email'));
			$id_part = substr($site_from_email, strpos('@', $site_from_email));
			$message_id = md5(uniqid()).$id_part;
			//$mail->addHeader('Message-Id', $message_id);

			$mail->send();

		} catch (Exception $e) {
			RivetyCore_Log::report('email: could not send', $e, Zend_Log::ERR);
		}
	}
Exemplo n.º 8
0
	public function write($id, $value) {
		$sessions_table = new Sessions();
		$lifetime = (int)RivetyCore_Registry::get('session_timeout');
		$expiration = time() + $lifetime;
		
		$data = array(
			'id' => $id,
			'value' => $value,
			'expiration' => $expiration,
		);
		
		$where = $sessions_table->getAdapter()->quoteInto('id = ?', $id);
		if($sessions_table->getCountByWhereClause($where) > 0){
			
			$sessions_table->update($data, $where);
			RivetyCore_Log::info("Session handler: updated session " .$id);
		} else {			
			$id = $sessions_table->insert($data);
			RivetyCore_Log::info("Session handler: updating session " .$id);
		}
	}
Exemplo n.º 9
0
	static function doAction($hook, $params) {
		RivetyCore_Log::report("RivetyCore_Plugin: Action hook fired - " . $hook, null, Zend_Log::INFO);
		RivetyCore_Log::report("RivetyCore_Plugin: Action hook fired - " . $hook . " - params: ", $params);	
		$plugins = Zend_Registry::get('plugin_actions');
		if (array_key_exists($hook, $plugins)) {
			$priority = array();
			$functions = array();
			foreach ($plugins[$hook] as $key => $function) {
				$priority[$key] = $function['priority'];
				$functions[$key] = $function;
			}
			
			array_multisort($priority, SORT_ASC, $functions, SORT_ASC, $plugins[$hook]);
			RivetyCore_Log::report("RivetyCore_Plugin: Action priority arrays for " . $hook, array('priority' => $priority, 'functions' => $functions, 'plugins-' . $hook => $plugins[$hook]), Zend_Log::DEBUG);
			foreach ($plugins[$hook] as $action) {
				$class_name = $action['class_name'];
				$function_name = $action['function_name'];
				$class = new $class_name;
				RivetyCore_Log::report("RivetyCore_Plugin: Action " . $hook . " is calling " . $class_name . "::" . $function_name, null, Zend_Log::INFO);
				$class->$function_name($params);
			}
		}
	}
Exemplo n.º 10
0
	/**
	 * Unregister's a logger
	 *
	 * @static
	 * @access public
	 * @param string $loggerName Logical name of the logger
	 */
	public static function unregisterLogger($loggerName)
	{
		if (!in_array($loggerName,array_keys(self::$instances))) return false;
		unset(self::$instances[$loggerName]);
		if (self::getDefaultLoggerName() == $loggerName) self::$defaultLogger = null;
	}
Exemplo n.º 11
0
	function indexAction()
	{
		$modules_table = new Modules('modules');
		$request = new RivetyCore_Request($this->getRequest());

		if ($request->has("id") and $request->has("perform"))
		{
			switch ($request->perform)
			{
				case "enable":
					if (!$modules_table->isEnabled($request->id))
					{
						if ($modules_table->enable($request->id))
						{
							if (!is_null($modules_table->success))
							{
								$this->view->success = $modules_table->success;
							}
							else
							{
								$this->view->success = "Module \"".$request->id ."\" enabled.";
							}
						}
					}
					else
					{
						$this->view->notice = "Module \"".$request->id ."\" is already enabled.";
					}
					break;
				case "disable":
					if($modules_table->isEnabled($request->id)){
						  if($modules_table->disable($request->id)){
							if(!is_null($modules_table->success)){
								$this->view->success = $modules_table->success;
							} else {
								$this->view->success = "Module \"".$request->id ."\" disabled.";
							}
						  }
					} else {
						$this->view->notice = "Module \"".$request->id ."\" is already disabled.";
					}
					break;
				case "install":
					if (!$modules_table->exists($request->id))
					{
						if ($modules_table->install($request->id))
						{
							if (!is_null($modules_table->success))
							{
								$this->view->success = $modules_table->success;
							}
							else
							{
								$this->view->success = "Module \"".$request->id ."\" installed.";
							}
						}
					}
					else
					{
						$this->view->notice = "Module \"".$request->id ."\" is already installed.";
					}
					break;
				case "uninstall":
					if ($modules_table->exists($request->id))
					{
						if($modules_table->disable($request->id))
						{
							if($modules_table->uninstall($request->id))
							{
								if(!is_null($modules_table->success))
								{
									$this->view->success = $modules_table->success;
								}
								else
								{
									$this->view->success = "Module \"".$request->id ."\" disabled and uninstalled.";
								}
							}
						}
					}
					else
					{
						$this->view->notice = "Module \"".$request->id ."\" is not installed.";
					}
					break;
			}
			if (count($modules_table->errors) > 0)
			{
				$this->view->errors = $modules_table->errors;
			}
			if (!is_null($modules_table->notice))
			{
				$this->view->notice = $modules_table->notice;
			}
		}
		$basepath = Zend_Registry::get('basepath');
		$module_dir = $basepath."/modules";
		$o_module_dir = dir($module_dir);
		$available_modules = array();

		while (false !== ($entry = $o_module_dir->read()))
		{
			if (substr($entry, 0, 1) != ".")
			{
				if ($entry != "default")
				{
					$full_dir = $module_dir . "/" . $entry;
					if (file_exists($full_dir . "/module.ini") and !$modules_table->exists($entry))
					{
						$tmp_module = $modules_table->parseIni($entry);
						$tmp_module['id'] = $entry;
						$tmp_module['available'] = true;
						$available_modules[] = $tmp_module;
					}
				}
			}
		}
		$o_module_dir->close();
		$tmp_modules = array();
		$modules = $modules_table->fetchAll(null, "id");
		if (count($modules) > 0)
		{
			$tmp_modules = array();
			foreach ($modules as $module)
			{
				$module = $module->toArray();
				try
				{
					$config = $modules_table->parseIni($module['id']);
					foreach ($config as $key => $val)
					{
						$module[$key] = $val;
					}
					$module['available'] = false;
					$tmp_modules[] = $module;
				}
				catch (Exception $e)
				{
					RivetyCore_Log::report("Could not set up " . $module, $e, Zend_Log::ERR);
				}
			}
		}
		$this->view->modules = array_merge($tmp_modules, $available_modules);
		$this->view->breadcrumbs = array('Manage Rivety Modules' => null);
	}