function select_information ($data)
{
	$identifier = $data['identifier'];

	$db = coren::db('handle');
	$table_session = 'auth_session';

	$identifier = "'" . mysql_real_escape_string($identifier, $db) . "'";
	$sql =
	"
		select `session`, `account`, `remote`, `secure`, `period`, `status`, `started`, `touched`, `closed`
		  from {$table_session}
		 where `session` = {$identifier}
		 order by `started` desc
		 limit 1
	";
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));

	$result = null;
	while ($row = mysql_fetch_row($res))
		$result = array(
			'session'	=> $row[0],
			'account'	=> $row[1],
			'remote'	=> $row[2],
			'secure'	=> $row[3],
			'period'	=> $row[4],
			'status'	=> $row[5],
			'started'	=> coren::db('split_date', array('value'=>$row[6])),
			'touched'	=> coren::db('split_date', array('value'=>$row[7])),
			'closed'	=> coren::db('split_date', array('value'=>$row[8])));
	mysql_free_result($res);
	return $result;
}
Ejemplo n.º 2
0
public function insert_envelopes ($data)
{
	$template   = $data['template'];
	$priority   = $data['priority'];
	$recipients = $data['recipients'];

	$db = coren::db('handle');
	$table_envelope = 'message_envelope';

	$template = "'" . mysql_real_escape_string($template, $db) . "'";
	$priority = (integer) $priority;
	$sql_values = array();
	foreach ($recipients as $recipient)
	{
		$recipient = "'" . mysql_real_escape_string($recipient, $db) . "'";
		$sql_values[] = "({$template},{$recipient},{$priority},0,0,now())";
	}
	$sql_values = implode(",", $sql_values);
	$sql =
	"
		insert into {$table_envelope} (
			 `template`
			,`recipient`
			,`priority`
			,`status`
			,`counter`
			,`injected`
		) values {$sql_values}
	";
//???	core::event('query', "Select page of articles from database.", array('query'=>$sql));
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));
}
function select_privileges ($data)
{
	$identifier = $data['identifier'];

	$db = coren::db('handle');
	$table_privilege  = 'auth_privilege'         ;
	$table_membership = 'auth_account_membership';
	$table_assignment = 'auth_assignment'        ;

	$identifier = "'" . mysql_real_escape_string($identifier, $db) . "'";
	$sql =
	"
		select {$table_privilege}.`codename`
		  from {$table_privilege} join {$table_assignment} using (`privilege`) join {$table_membership} using (`rolegroup`)
		 where {$table_membership}.`account` = {$identifier}
	";
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));

	$result = array();
	while ($row = mysql_fetch_row($res))
		$result[] = $row[0];
	mysql_free_result($res);
	return $result;
}
Ejemplo n.º 4
0
public function assign ($data)
{
	$identifier = isset($data['identifier']) ? $data['identifier'] : null;

	$privileges = coren::db('select_privileges', compact('identifier'));
	if (!is_null($this->identified_privilege)) $privileges[] = $this->identified_privilege;
	coren::grant($privileges);
}
Ejemplo n.º 5
0
public function verify ($data)
{
	//NB: logname, passwords and other fields can be not set, because verifying by other criterias.
	$logname        = isset($data['logname'       ]) ? $data['logname'       ] : null;
	$password_plain = isset($data['password_plain']) ? $data['password_plain'] : (isset($data['password']) ? $data['password'] : null);
	$password_md5   = isset($data['password_md5'  ]) ? $data['password_md5'  ] : (md5($password_plain));
//...	$sslcert        = isset($data['sslcert'       ]) ? $data['sslcert'       ] : null;
	return coren::db('verify', compact('logname', 'password_plain', 'password_md5'));
}
Ejemplo n.º 6
0
public function close ($data)
{
	$requisites = array('origin');
	$requisites = coren::event($this->event_for_session_close_context, compact('requisites'));
	$origin = isset($requisites['origin']) ? $requisites['origin'] : null;

	$identifier = coren::event($this->event_for_session_close_identifier, null);

	$code =
		(is_null($identifier) ? 'already' :
		(null));

	if (is_null($code))
	{
		coren::db('close_session', compact('identifier'));

		if (!$this->silent)
		{
			coren::event($this->event_for_session_close_successed, compact('origin', 'identifier'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-close-success', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'origin'     , $origin     ));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_close_successed),
				$this->slot_for_session_close_successed);
		}
	} else
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_session_close_failed, compact('identifier', 'origin', 'code'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-close-failure', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'code'       , $code       ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'origin'     , $origin     ));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_close_failed),
				$this->slot_for_session_close_failed);
		}
	}
}
function expire_sessions ($data)
{
	$db = coren::db('handle');
	$table_session = 'auth_session';

	$sql =
	"
		update {$table_session}
		   set `status` = 1, `closed` = now()
		 where `status` = 0 and `period` > 0
		   and (`touched` + interval `period` second) <= now()
	";
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));
}
Ejemplo n.º 8
0
function touch_session ($data)
{
	$identifier = $data['identifier'];

	$db = coren::db('handle');
	$table_session = 'auth_session';

	$identifier = "'" . mysql_real_escape_string($identifier, $db) . "'";
	$sql =
	"
		update {$table_session}
		   set `touched` = now()
		 where `session` = {$identifier}
	";
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));
}
Ejemplo n.º 9
0
function session_start ($data)
{
	$identifier  = $data['identifier'];
	$account  = $data['account'];
	$remote   = $data['remote' ];
	$secure   = $data['secure' ];
	$period   = $data['period' ];

	$db = coren::db('handle');
	$table_session = 'auth_session';

	$identifier = "'" . mysql_real_escape_string($identifier, $db) . "'";
	$account    = "'" . mysql_real_escape_string($account   , $db) . "'";
	$remote     = "'" . mysql_real_escape_string($remote    , $db) . "'";
	$secure     = $secure ? 1 : 0;
	$period     = (integer) $period;
	$sql =
	"
		insert into {$table_session} (
			 `session`
			,`account`
			,`remote`
			,`secure`
			,`period`
			,`status`
			,`started`
			,`touched`
			,`closed` 
		) values (
			 {$identifier}
			,{$account}
			,{$remote}
			,{$secure}
			,{$period}
			,default
			,now()
			,now()
			,null
		)
	";
	$res = @mysql_query($sql, $db);
	if ($res === false) if (mysql_errno($db) === 1062) throw new identify_session_start_0_exception_duplicate(mysql_error($db), mysql_errno($db));
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));
}
Ejemplo n.º 10
0
function verify ($data)
{
	$logname        = $data['logname'       ];
	$password_plain = $data['password_plain'];
	$password_md5   = $data['password_md5'  ];

	$db = coren::db('handle');
	$table_account = 'auth_account';

	$sql_logname        = "'" . mysql_real_escape_string($logname       , $db) . "'";
	$sql_password_plain = "'" . mysql_real_escape_string($password_plain, $db) . "'";
	$sql_password_md5   = "'" . mysql_real_escape_string($password_md5  , $db) . "'";

	$whereclauses = array();
	if (!is_null($password_plain)) $whereclauses[] = "(`logname` = {$sql_logname} and `password_plain` = {$sql_password_plain})";
	if (!is_null($password_md5  )) $whereclauses[] = "(`logname` = {$sql_logname} and `password_md5`   = {$sql_password_md5  })";

	if (empty($whereclauses)) return null;
	else $whereclauses = implode(" or ", $whereclauses);

	$sql =
	"
		select `account`, `disabled`, `reason`
		  from {$table_account}
		 where {$whereclauses}
		 order by `created` asc
		 limit 1
	";
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));

	$result = null;
	while ($row = mysql_fetch_row($res))
		$result = array(
			'account'	=> $row[0],
			'disabled'	=> $row[1],
			'reason'	=> $row[2]);
	mysql_free_result($res);
	return $result;
}
Ejemplo n.º 11
0
function select_information ($data)
{
	$identifiers = $data['identifiers'];
	if (empty($identifiers)) return array();

	$db = coren::db('handle');
	$table_account = 'auth_account';

	$sql_identifiers = array();
	foreach ($identifiers as $identifier)
		$sql_identifiers[] = "'" . mysql_real_escape_string($identifier, $db) . "'";
	$sql_identifiers = implode(",", $sql_identifiers);
	$sql =
	"
		select `account`, `created`, `entered`, `touched`, `disabled`, `reason`, `comment`, `logname`, `email`, `agreement`
		  from {$table_account}
		 where `account` in ({$sql_identifiers})
	";
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));

	$result = array();
	while ($row = mysql_fetch_row($res))
		$result[$row[0]] = array(
			'account'	=> $row[0],
			'created'	=> coren::db('split_date', array('value'=>$row[1])),
			'entered'	=> coren::db('split_date', array('value'=>$row[2])),
			'touched'	=> coren::db('split_date', array('value'=>$row[3])),
			'disabled'	=> $row[4],
			'reason'	=> $row[5],
			'comment'	=> $row[6],
			'logname'	=> $row[7],
			'email'		=> $row[8],
			'agreement'	=> $row[9]);
	mysql_free_result($res);
	return $result;
}
Ejemplo n.º 12
0
public function information ($data)
{
	$identifiers = isset($data['identifiers']) ? $data['identifiers'] : null;
	$identifier  = isset($data['identifier' ]) ? $data['identifier' ] : null;
	if ($singlemode = !is_null($identifier)) $identifiers = array(null => $identifier);
	if (!is_array($identifiers)) throw new exception("List of account identifiers must be an array.");
	$result = array();


	if (!is_null($this->event_for_cache_get))
	foreach ($identifiers as $index => $identifier)
	{
		if (!is_null($temp = coren::event($this->event_for_cache_get, compact('identifier'))))
		{
			$result[$index] = $temp;
			unset($identifiers[$index]);
		}
	}

	$information = empty($identifiers) ? array() : coren::db('select_information', compact('identifiers'));

	foreach ($identifiers as $index => $identifier)
	{
		if (array_key_exists($identifier, $information))
		{
			$result[$index] = $information[$identifier];
			if (!is_null($this->event_for_cache_set))
				coren::event($this->event_for_cache_set, array('identifier'=>$identifier, 'value'=>$information[$identifier]));
		} else
		{
			$result[$index] = null;
		}
	}

	return $singlemode ? $result[null] : $result;
}
Ejemplo n.º 13
0
public function detect ($data)
{
	$requisites = array('identifier');
	$requisites = coren::event($this->event_for_session_detect_identifier, compact('requisites'));
	$identifier = isset($requisites['identifier']) ? $requisites['identifier'] : null;

	if (is_null($identifier) || !is_scalar($identifier) || ($identifier == ''))
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_session_detect_skipped);
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'nothing', null);
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_detect_skipped),
				$this->slot_for_session_detect_skipped);
		}
		return;
	}

	$information = coren::db('select_information', compact('identifier'));

	$code =
		(is_null($information)            ? 'absent'  :
		(is_null($information['account']) ? 'orphan'  :
		($information['status'] == 1      ? 'expired' :
		($information['status'] == 2      ? 'closed'  :
		($information['status'] == 3      ? 'halted'  :
		($information['status'] != 0      ? 'status'  :
		(null)))))));

	if (is_null($code))
	{
		$this->identifier  = $identifier ;
		$this->information = $information;

		if (!$this->silent)
		{
			coren::event($this->event_for_session_detect_successed, compact('identifier', 'information'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-detect-success', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'information', $information));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_detect_successed),
				$this->slot_for_session_detect_successed);
		}
		return $information['account'];//NB: this stops futher handling of current event.
	} else
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_session_detect_failed, compact('identifier', 'information', 'code'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-detect-failure', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'code'       , $code       ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'information', $information));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_detect_failed),
				$this->slot_for_session_detect_failed);
		}
	}
}
Ejemplo n.º 14
0
public function mark_envelope_failure ($data)
{
	$envelope = $data['envelope'];
	$error    = $data['error'   ];
	$errno    = $data['errno'   ];
	$status   = $data['status'  ];

	$db = coren::db('handle');
	$table_envelope = 'message_envelope';

	$envelope = "'" . mysql_real_escape_string($envelope, $db) . "'";
	$error    = "'" . mysql_real_escape_string($error   , $db) . "'";
	$errno    = (integer) $errno;
	$status   = (integer) $status;
	$sql =
	"
		update {$table_envelope}
		   set `status`	    = {$status}
		     , `counter`    = `counter` + 1
		     , `last_stamp` = now()
		     , `last_error` = {$error}
		     , `last_errno` = {$errno}
		 where `envelope` = {$envelope}
	";
//???	core::event('query', "Insert article to database.", array('query'=>$sql));
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));
}
Ejemplo n.º 15
0
public function touch ($data)
{
	$identifier = isset($data['identifier']) ? $data['identifier'] : null;
	if (!is_null($identifier)) coren::db('touch_account', compact('identifier'));
}
Ejemplo n.º 16
0
public function flush ($data)
{
	if (!coren::have($this->privilege_for_flush))
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_not_authorized);
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'flush', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'not-authorized', null));
			coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name_for_not_authorized), $this->slot_for_not_authorized);
		}
//???		do nto throw here. see file ...inject... for reasoning.
//???		throw new exception("Not authorized to flush queue of messages.");
		return;
	}

	$limit = max(1, $this->limit_per_call);//min(max(1, $this->limit_per_call)/*, max(1, $this->limit_per_*), ...*/);
	$envelopes = coren::db('select_envelopes', compact('limit'));

	$reports = array();
	if (is_array($envelopes) && !empty($envelopes))
	{
		$identifiers = array();
		foreach ($envelopes as $envelope) $identifiers[] = $envelope['template'];
		$identifiers = array_unique($identifiers);
		$templates = empty($identifiers) ? array() : coren::db('select_templates', compact('identifiers'));

		foreach ($envelopes as $index => $item)
		{
			$envelope    = $item['envelope'   ];
			$template    = $item['template'   ];
			$recipient   = $item['recipient'  ];
			$current_try = $item['current_try'];
			$current_age = $item['current_age'];
			$subject = isset($templates[$template]['subject']) ? $templates[$template]['subject'] : null;
			$message = isset($templates[$template]['message']) ? $templates[$template]['message'] : null;

			try
			{
				$status = +1;
				$error = $errno = null;
				coren::event($this->event_for_send_message, compact('recipient', 'subject', 'message', 'envelope', 'template'));
			}
			catch (exception $exception)
			{
				$status = (isset($this->max_age) && ($current_age >= $this->max_age))
					||(isset($this->max_try) && ($current_try >= $this->max_try))
					? -1 : 0;
				$error  = $exception->getMessage();
				$errno  = $exception->getCode();
			}
			$reports[] = compact('envelope', 'template', 'recipient', 'error', 'errno', 'status');

			if ($this->one_by_one)
			if ($status <= 0)
			{
				coren::db('mark_envelope_failure', compact('envelope', 'error', 'errno', 'status'));
			} else
			{
				coren::db('mark_envelope_success', compact('envelope', 'status'));
			}
		}
	}

	if (!$this->one_by_one)
	{
		$envelopes = array();//NB: this is a list of identifiers of envelopes, that were successfuly sent.
		foreach ($reports as $report)
		{
			$envelope = $report['envelope'];
			$status   = $report['status'  ];
			if ($status <= 0)
			{
				$error = $report['error'];
				$errno = $report['errno'];
				coren::db('mark_envelope_failure', compact('envelope', 'error', 'errno', 'status'));
			} else
			{
				$envelopes[] = $envelope;
			}
		}
		if (!empty($envelopes))
		{
			$status = +1;
			coren::db('mark_envelope_success', compact('envelopes', 'status'));
		}
	}

	if (!$this->silent)
	{
		//!!!??? trigger event about successful or failed send! or maybe it must be dependent
		//!!!??? on one_by_one: event one-by-one, or all at once?
		//coren::event($this->event_for_flush_success, compact(???!!!));
		coren::event($this->event_for_flush_success);
	}
	if (!$this->hidden)
	{
		if (!coren::depend('_dom_builder_0'))
			throw new exception("Tool '_dom_builder_0' missed.");

		$doc = coren::xml();
		$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'flush', null);
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'limit'  , $limit));
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'max-age', $this->max_age));
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'max-try', $this->max_try));

		$eler = $ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'reports', null));
		foreach ($reports as $report)
		$eler->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'report', $report));

		$elet = $ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'templates', null));
		foreach ($templates as $identifier => $template)
		$elet->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'template', $template))
		   ->setAttributeNodeNS(_dom_builder_0::build_attribute($doc, self::namespace, $this->prefix, 'id', $identifier));

		coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name_for_flush_success), $this->slot_for_flush_success);
	}
}
Ejemplo n.º 17
0
public function inject ($data)
{
	if (!coren::have($this->privilege_for_inject))
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_not_authorized);
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'inject', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'not-authorized', null));
			coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name_for_not_authorized), $this->slot_for_not_authorized);
		}
//???		absence of authrization for some action is an error, but not an exception.
//???		exceptions are for unpredicted situations, and access violation is predicted.
//???		So this is an error, it has an event & data about error, and do nothing more,
//???		but it do not throw an exception, which breaks all workflow of the script
//???		and causes rollbacks in all databases.
//???		throw new exception("Not authorized to inject message into queue of messages.");
		return;
	}

	$priority = isset($data['priority']) ? $data['priority'] :  0; if (is_scalar($priority)) $priority = (integer) $priority; else throw new exception("Bad priority for message queue (must be integer).");
	$subject  = isset($data['subject' ]) ? $data['subject' ] : ''; if (is_scalar($subject )) $subject  = (string ) $subject ; else throw new exception("Bad subject for message queue (must be string).");
	$message  = isset($data['message' ]) ? $data['message' ] : ''; if (is_scalar($message )) $message  = (string ) $message ; else throw new exception("Bad message for message queue (must be string).");

	//??? if both [recipient] and [recipients] are set, should be send to both of them, or to [recipients] only?
	//??? now we use the second way: if [recipients] is set, then [recipient] is ignored.
	$recipient  = isset($data['recipient' ]) ? $data['recipient' ] : null;
	$recipients = isset($data['recipients']) ? $data['recipients'] : array($recipient);
	if (!is_array($recipients)) $recipients = array($recipients);//NB: $recipients will never be null here, so we don't recheck.
	$temp = array();
	foreach ($recipients as $recipient)
		if (is_null  ($recipient)) { continue; } else
		if (is_scalar($recipient)) { $temp[] = (string) $recipient; } else //NB: use recipient even if it is an empty string.
		throw new exception("Bad type of recipient in message queue (must be either null, or string).");
	$recipients = array_unique($temp);

	$template = coren::db('insert_template', compact('subject', 'message'));
	if (!empty($recipients)) coren::db('insert_envelopes', compact('template', 'priority', 'recipients'));

	if (!$this->silent)
	{
		coren::event($this->event_for_inject_success, compact('priority', 'subject', 'message', 'recipients'));
	}
	if (!$this->hidden)
	{
		if (!coren::depend('_dom_builder_0'))
			throw new exception("Tool '_dom_builder_0' missed.");

		$doc = coren::xml();
		$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'inject', compact('priority', 'subject', 'message'));
		foreach ($recipients as $recipient)
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'recipient', $recipient));
		coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name_for_inject_success), $this->slot_for_inject_success);
	}
}
Ejemplo n.º 18
0
public function parameters ($data)
{
	$db = coren::db('handle');
	$table_parameter = '`coren_parameter`';

	$sql =
	"
		select `parameter`, `value`
		  from {$table_parameter}
	";
	$res = @mysql_query($sql, $db);
	if ($res === false) throw new exception(mysql_error($db), mysql_errno($db));

	$result = array();
	while ($row = mysql_fetch_row($res))
		$result[] = array(
			'parameter'	=> $row[0],
			'value'		=> $row[1]);
	mysql_free_result($res);
	return $result;
}
Ejemplo n.º 19
0
public function start ($data)
{
	$requisites = array('origin');
	$requisites = coren::event($this->event_for_session_start_context, compact('requisites'));
	$origin = isset($requisites['origin']) ? $requisites['origin'] : null;

	$requisites = array('logname', 'password', 'remember');
	$requisites = coren::event($this->event_for_session_start_credentials, compact('requisites'));
	$logname  = isset($requisites['logname' ]) ? $requisites['logname' ] : null;
	$password = isset($requisites['password']) ? $requisites['password'] : null;
	$remember = isset($requisites['remember']) ? $requisites['remember'] : null;
	$credentials = compact('logname', 'password');

	if (!is_null($logname) && !is_null($password))
	{
		$acknowledge = coren::event($this->event_for_session_start_acknowledge, $credentials);
		$code =
			(is_null($acknowledge)    ? 'wrong'    :
			($acknowledge['disabled'] ? 'disabled' :
			(null)));
	} else
	{
		$acknowledge = null;
		$code = 'nothing';
	}

	if (is_null($code))
	{
		$trycount = max($this->trycount, 1);
		$account  = $acknowledge['account'];
		$remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
		$secure = 0;//!!!todo later: configurable default secure mode; selectable loginfo secure mode; account info with secure field.
		$period = $remember ? 0 : 60*60;//!!!todo later: configurable default period; from account settings; from credentials
		for ($i = 1; $i <= $trycount; $i++)
		{
			$identifier = coren::event($this->event_for_session_start_identifier, null);
			if (is_null($identifier)) throw new exception("Noone have generated identifier for new session.");
			try
			{
				coren::db('session_start', compact('identifier', 'account', 'remote', 'secure', 'period'));
				break;
			}
			catch (identify_session_start_0_exception_duplicate $exception)
			{
				if ($i >= $trycount) throw $exception;
			}
		}

		if (!$this->silent)
		{
			coren::event($this->event_for_session_start_successed, compact('origin', 'identifier', 'credentials', 'acknowledge', 'remote', 'secure', 'period'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-start-success', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'origin'     , $origin     ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'credentials', $credentials));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'acknowledge', $acknowledge));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'remote'     , $remote     ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'secure'     , $secure     ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'period'     , $period     ));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_start_successed),
				$this->slot_for_session_start_successed);
		}
	} else
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_session_start_failed, compact('identifier', 'origin', 'credentials', 'acknowledge', 'code'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-start-failure', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'code'       , $code       ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'origin'     , $origin     ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'credentials', $credentials));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'acknowledge', $acknowledge));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_start_failed),
				$this->slot_for_session_start_failed);
		}
	}
}
Ejemplo n.º 20
0
public function expire ($data)
{
	coren::db('expire_sessions', null);
}