13 changed files with 528 additions and 17 deletions
-
1app/assets/js/movim_session.js
-
71app/models/sessionx/Sessionx.php
-
287app/models/sessionx/SessionxDAO.php
-
9app/widgets/Connection/Connection.php
-
23app/widgets/Feed/Feed.php
-
2app/widgets/Login/Login.php
-
2app/widgets/Node/node.tpl
-
6app/widgets/Poller/poller.js
-
2bootstrap.php
-
6system/RPC.php
-
2system/Session.php
-
130system/Sessionx.php
-
4system/User.php
@ -0,0 +1,71 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class Sessionx extends ModlModel { |
|||
public $session; |
|||
public $user; |
|||
public $ressource; |
|||
public $rid; |
|||
public $sid; |
|||
public $id; |
|||
public $url; |
|||
public $port; |
|||
public $host; |
|||
public $domain; |
|||
public $config; |
|||
public $active; |
|||
public $timestamp; |
|||
|
|||
public function __construct() { |
|||
$this->_struct = ' |
|||
{ |
|||
"session" : |
|||
{"type":"string", "size":128, "mandatory":true, "key":true }, |
|||
"user" : |
|||
{"type":"string", "size":64 }, |
|||
"ressource" : |
|||
{"type":"string", "size":64 }, |
|||
"rid" : |
|||
{"type":"int", "size":8, "mandatory":true }, |
|||
"sid" : |
|||
{"type":"int", "size":8 }, |
|||
"id" : |
|||
{"type":"int", "size":8, "mandatory":true }, |
|||
"url" : |
|||
{"type":"string", "size":128, "mandatory":true }, |
|||
"port" : |
|||
{"type":"int", "size":5, "mandatory":true }, |
|||
"host" : |
|||
{"type":"string", "size":64, "mandatory":true }, |
|||
"domain" : |
|||
{"type":"string", "size":64, "mandatory":true }, |
|||
"config" : |
|||
{"type":"text" }, |
|||
"active" : |
|||
{"type":"int", "size":4 }, |
|||
"timestamp" : |
|||
{"type":"date" } |
|||
}'; |
|||
|
|||
parent::__construct(); |
|||
} |
|||
} |
|||
/* $session = array( |
|||
'rid' => 1, |
|||
'sid' => 0, |
|||
'id' => 0, |
|||
'url' => $serverconfig['boshUrl'], |
|||
'port'=> 5222, |
|||
'host'=> $host, |
|||
'domain' => $domain, |
|||
'ressource' => 'moxl'.substr(md5(date('c')), 3, 6), |
|||
|
|||
'user' => $user, |
|||
'password' => $element['pass'], |
|||
|
|||
'proxyenabled' => $serverconfig['proxyEnabled'], |
|||
'proxyurl' => $serverconfig['proxyURL'], |
|||
'proxyport' => $serverconfig['proxyPort'], |
|||
'proxyuser' => $serverconfig['proxyUser'], |
|||
'proxypass' => $serverconfig['proxyPass']);*/ |
|||
@ -0,0 +1,287 @@ |
|||
<?php |
|||
|
|||
namespace modl; |
|||
|
|||
class SessionxDAO extends ModlSQL { |
|||
function init(Sessionx $s) { |
|||
$this->_sql = ' |
|||
update sessionx |
|||
set user = :user, |
|||
ressource = :ressource, |
|||
rid = :rid, |
|||
sid = :sid, |
|||
id = :id, |
|||
url = :url, |
|||
port = :port, |
|||
host = :host, |
|||
domain = :domain, |
|||
config = :config, |
|||
active = :active, |
|||
timestamp = :timestamp |
|||
where session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Sessionx', |
|||
array( |
|||
'session' => $s->session, |
|||
'user' => $s->user, |
|||
'ressource' => $s->ressource, |
|||
'rid' => $s->rid, |
|||
'sid' => $s->sid, |
|||
'id' => $s->id, |
|||
'url' => $s->url, |
|||
'port' => $s->port, |
|||
'host' => $s->host, |
|||
'domain' => $s->domain, |
|||
'config' => $s->config, |
|||
'active' => $s->active, |
|||
'timestamp' => $s->timestamp |
|||
) |
|||
); |
|||
|
|||
$this->run('Sessionx'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into sessionx |
|||
(session, |
|||
user, |
|||
ressource, |
|||
rid, |
|||
sid, |
|||
id, |
|||
url, |
|||
port, |
|||
host, |
|||
domain, |
|||
config, |
|||
active, |
|||
timestamp) |
|||
values |
|||
(:session, |
|||
:user, |
|||
:ressource, |
|||
:rid, |
|||
:sid, |
|||
:id, |
|||
:url, |
|||
:port, |
|||
:host, |
|||
:domain, |
|||
:config, |
|||
:active, |
|||
:timestamp)'; |
|||
|
|||
$this->prepare( |
|||
'Sessionx', |
|||
array( |
|||
'session' => $s->session, |
|||
'user' => $s->user, |
|||
'ressource' => $s->ressource, |
|||
'rid' => $s->rid, |
|||
'sid' => $s->sid, |
|||
'id' => $s->id, |
|||
'url' => $s->url, |
|||
'port' => $s->port, |
|||
'host' => $s->host, |
|||
'domain' => $s->domain, |
|||
'config' => $s->config, |
|||
'active' => $s->active, |
|||
'timestamp' => $s->timestamp |
|||
) |
|||
); |
|||
|
|||
$this->run('Sessionx'); |
|||
} |
|||
} |
|||
|
|||
function getId($session) { |
|||
$this->_sql = ' |
|||
select id from sessionx |
|||
where |
|||
session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Sessionx', |
|||
array( |
|||
'session' => $session |
|||
) |
|||
); |
|||
|
|||
$value = $this->run(null, 'array'); |
|||
$value = $value[0]['id']; |
|||
|
|||
$this->_sql = ' |
|||
update sessionx |
|||
set |
|||
id = :id |
|||
where |
|||
session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Sessionx', |
|||
array( |
|||
'session' => $session, |
|||
'id' => $value+1 |
|||
) |
|||
); |
|||
|
|||
$this->run(); |
|||
|
|||
return $value; |
|||
} |
|||
|
|||
function getRid($session) { |
|||
$this->_sql = ' |
|||
select rid from sessionx |
|||
where |
|||
session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Sessionx', |
|||
array( |
|||
'session' => $session |
|||
) |
|||
); |
|||
|
|||
$value = $this->run(null, 'array'); |
|||
$value = $value[0]['rid']; |
|||
|
|||
$this->_sql = ' |
|||
update sessionx |
|||
set |
|||
rid = :rid |
|||
where |
|||
session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Sessionx', |
|||
array( |
|||
'session' => $session, |
|||
'rid' => $value+1 |
|||
) |
|||
); |
|||
|
|||
$this->run(); |
|||
|
|||
return $value; |
|||
} |
|||
|
|||
function delete($session) { |
|||
$this->_sql = ' |
|||
delete from sessionx |
|||
where |
|||
session = :session'; |
|||
|
|||
$this->prepare( |
|||
'Sessionx', |
|||
array( |
|||
'session' => $session |
|||
) |
|||
); |
|||
|
|||
return $this->run('Sessionx'); |
|||
} |
|||
/*function set($session, $container, $name, $value, $timestamp) { |
|||
$timestamp = date(DATE_ISO8601, $timestamp); |
|||
|
|||
$this->_sql = ' |
|||
update session |
|||
set value = :value, |
|||
timestamp = :timestamp |
|||
where session = :session |
|||
and container = :container |
|||
and name = :name'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
'name' => $name, |
|||
'value' => $value, |
|||
'timestamp' => $timestamp |
|||
) |
|||
); |
|||
|
|||
$this->run('Session'); |
|||
|
|||
if(!$this->_effective) { |
|||
$this->_sql = ' |
|||
insert into session |
|||
(name, value, session, container, timestamp) |
|||
values (:name, :value, :session, :container, :timestamp)'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
'name' => $name, |
|||
'value' => $value, |
|||
'timestamp' => $timestamp |
|||
) |
|||
); |
|||
|
|||
return $this->run('Session'); |
|||
} |
|||
} |
|||
|
|||
function get($session, $container, $name) { |
|||
$this->_sql = ' |
|||
select * from session |
|||
where |
|||
session = :session |
|||
and container = :container |
|||
and name = :name'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
'name' => $name |
|||
) |
|||
); |
|||
|
|||
return $this->run('Session', 'item'); |
|||
} |
|||
|
|||
function delete($session, $container, $name) { |
|||
$this->_sql = ' |
|||
delete from session |
|||
where |
|||
session = :session |
|||
and container = :container |
|||
and name = :name'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
'name' => $name |
|||
) |
|||
); |
|||
|
|||
return $this->run('Session'); |
|||
} |
|||
|
|||
function deleteContainer($session, $container) { |
|||
$this->_sql = ' |
|||
delete from session |
|||
where |
|||
session = :session |
|||
and container = :container'; |
|||
|
|||
$this->prepare( |
|||
'Session', |
|||
array( |
|||
'session' => $session, |
|||
'container' => $container, |
|||
) |
|||
); |
|||
|
|||
return $this->run('Session'); |
|||
}*/ |
|||
} |
|||
@ -0,0 +1,130 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* @file Sessionx.php |
|||
* This file is part of Movim. |
|||
* |
|||
* @brief This class manage the Movim current Movim. It doesn't replace |
|||
* the other Session class. This class is a singleton. |
|||
* |
|||
* @author Jaussoin Timothée |
|||
* |
|||
* @version 1.0 |
|||
* @date 1 December 2013 |
|||
* |
|||
* Copyright (C)2013 Movim |
|||
* |
|||
* See COPYING for licensing information. |
|||
*/ |
|||
class Sessionx { |
|||
protected static $_sid = null; |
|||
protected static $_instance; |
|||
private $_max_age = 86400; // 24hour
|
|||
private $_timestamp; |
|||
|
|||
private $_rid; |
|||
private $_id; |
|||
|
|||
public $user; |
|||
public $ressource; |
|||
public $sessionid; |
|||
public $url; |
|||
public $port; |
|||
public $host; |
|||
public $domain; |
|||
public $active = false; |
|||
public $config; |
|||
/* |
|||
* Session generation and handling part |
|||
*/ |
|||
|
|||
protected function __construct() |
|||
{ |
|||
// Does the database exist?
|
|||
if(self::$_sid == null) { |
|||
if(isset($_COOKIE['MOVIM_SESSION_ID'])) { |
|||
self::$_sid = $_COOKIE['MOVIM_SESSION_ID']; |
|||
} else { |
|||
$this->regenerate(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected function regenerate() |
|||
{ |
|||
// Generating the session cookie's hash.
|
|||
$hash_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; |
|||
$hash = ""; |
|||
|
|||
for($i = 0; $i < 64; $i++) { |
|||
$r = mt_rand(0, strlen($hash_chars) - 1); |
|||
$hash.= $hash_chars[$r]; |
|||
} |
|||
|
|||
self::$_sid = $hash; |
|||
setcookie('MOVIM_SESSION_ID', self::$_sid, time() + $this->_max_age); |
|||
} |
|||
|
|||
public static function start() |
|||
{ |
|||
if(!isset(self::$_instance)) { |
|||
self::$_instance = new self(); |
|||
} |
|||
|
|||
return self::$_instance; |
|||
} |
|||
|
|||
/* |
|||
* Session management part |
|||
*/ |
|||
private function inject() { |
|||
$s = new modl\Sessionx(); |
|||
$s->session = self::$_sid; |
|||
$s->user = $this->user; |
|||
$s->ressource = $this->ressource; |
|||
$s->rid = $this->_rid; |
|||
$s->sid = $this->sessionid; |
|||
$s->id = $this->_id; |
|||
$s->url = $this->url; |
|||
$s->port = $this->port; |
|||
$s->host = $this->host; |
|||
$s->domain = $this->domain; |
|||
$s->config = $this->config; |
|||
$s->active = $this->active; |
|||
$s->timestamp = $this->_timestamp; |
|||
return $s; |
|||
} |
|||
|
|||
public function init() { |
|||
$this->_rid = 0; |
|||
$this->_id = 0; |
|||
$sd = new modl\SessionxDAO(); |
|||
$s = $this->inject(); |
|||
$sd->init($s); |
|||
} |
|||
|
|||
public function save() { |
|||
|
|||
} |
|||
|
|||
public function destroy() { |
|||
$sd = new modl\SessionxDAO(); |
|||
$sd->delete(self::$_sid); |
|||
} |
|||
|
|||
/* |
|||
* rid and id specific getter, theses getter autoincrement each |
|||
* time the value in the database |
|||
*/ |
|||
public function getId() { |
|||
$sd = new modl\SessionxDAO(); |
|||
$this->_id = $sd->getId(self::$_sid); |
|||
return $this->_id; |
|||
} |
|||
|
|||
public function getRid() { |
|||
$sd = new modl\SessionxDAO(); |
|||
$this->_rid = $sd->getRid(self::$_sid); |
|||
return $this->_rid; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue