Browse Source

- Start a new session system called Sessionx

pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
17dd88d523
  1. 1
      app/assets/js/movim_session.js
  2. 71
      app/models/sessionx/Sessionx.php
  3. 287
      app/models/sessionx/SessionxDAO.php
  4. 9
      app/widgets/Connection/Connection.php
  5. 23
      app/widgets/Feed/Feed.php
  6. 2
      app/widgets/Login/Login.php
  7. 2
      app/widgets/Node/node.tpl
  8. 6
      app/widgets/Poller/poller.js
  9. 2
      bootstrap.php
  10. 6
      system/RPC.php
  11. 2
      system/Session.php
  12. 130
      system/Sessionx.php
  13. 4
      system/User.php

1
app/assets/js/movim_session.js

@ -39,6 +39,7 @@ var Session = {
},
getSession: function() {
console.log('Increase '+this.session.rid);
this.init();
this.check();
this.session.id = this.session.id+1;

71
app/models/sessionx/Sessionx.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']);*/

287
app/models/sessionx/SessionxDAO.php

@ -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');
}*/
}

9
app/widgets/Connection/Connection.php

@ -30,11 +30,14 @@ class Connection extends WidgetBase
{
if($value >= 10) {
$value = floor(($value-10)/10);
RPC::call('Session.rollback');
if($value == 0)
RPC::call('movim_fill', 'countdown', '');
else
RPC::call('movim_fill', 'countdown', t('Please wait ').$value);
else {
RPC::call('movim_fill', 'countdown', t('Please wait ').$value);
}
} else
RPC::commit();
}

23
app/widgets/Feed/Feed.php

@ -5,6 +5,29 @@ class Feed extends WidgetCommon {
function WidgetLoad()
{
$sess = Session::start(APP_NAME);
var_dump($sess->get('session'));
$s = Sessionx::start();
// We get the Server Configuration
$serverconfig = \system\Conf::getServerConf();
$s->url = $serverconfig['boshUrl'];
$s->port = 5222;
$s->host = 'movim.eu';
$s->domain = 'pod.mov.im';
$s->user = 'edhelas';
$s->ressource = 'moxl'.substr(md5(date('c')), 3, 6);
$s->init();
var_dump($s->getRid());
var_dump($s->getRid());
var_dump($s->getRid());
var_dump($s->getId());
var_dump($s->getId());
var_dump($s);
var_dump($_COOKIE);
$this->addcss('feed.css');
$this->registerEvent('opt_post', 'onStream');

2
app/widgets/Login/Login.php

@ -21,7 +21,7 @@ if (!defined('DOCUMENT_ROOT')) die('Access denied');
class Login extends WidgetBase {
function WidgetLoad()
{
{
$this->addcss('login.css');
$this->addjs('login.js');
$this->registerEvent('config', 'onConfig');

2
app/widgets/Node/node.tpl

@ -5,5 +5,5 @@
</div>
<script type="text/javascript">
{$getaffiliations}
{$getmetadata}
<!--{$getmetadata}-->
</script>

6
app/widgets/Poller/poller.js

@ -47,14 +47,14 @@ function movim_poll()
}
};
/*var poll = {
var poll = {
session: Session.getSession(true)
};
//console.log(JSON.stringify(poll));
poller.send(JSON.stringify(poll));*/
poller.send();
poller.send(JSON.stringify(poll));
//poller.send();
}
function halt_poll()

2
bootstrap.php

@ -164,6 +164,7 @@ class Bootstrap {
require_once(SYSTEM_PATH . "/i18n/i18n.php");
require_once(SYSTEM_PATH . "Session.php");
require_once(SYSTEM_PATH . "Sessionx.php");
require_once(SYSTEM_PATH . "Utils.php");
require_once(SYSTEM_PATH . "UtilsPicture.php");
require_once(SYSTEM_PATH . "Cache.php");
@ -257,6 +258,7 @@ class Bootstrap {
modl\loadModel('Caps');
modl\loadModel('Item');
modl\loadModel('Message');
modl\loadModel('Sessionx');
$db->setConnectionArray(\System\Conf::getServerConf());
$db->connect();

6
system/RPC.php

@ -95,20 +95,18 @@ class RPC
$json = file_get_contents('php://input');
$request = json_decode($json);
movim_log($request);
// We force the rid and id session number from the browser
/*
if(isset($request->session->rid)
&& isset($request->session->id)) {
global $session;
$session['rid'] = $request->session->rid;
$session['id'] = $request->session->id;
}
}*/
if(isset($_GET['do']) && $_GET['do'] == 'poll') {
moxl\ping();
} else {
// Loading the widget.
$widget_name = (string)$request->widget;

2
system/Session.php

@ -23,7 +23,7 @@ if(!class_exists('Session')):
class Session
{
protected $db;
//protected $db;
protected static $instances = array();
protected static $sid = null;
protected $container;

130
system/Sessionx.php

@ -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;
}
}

4
system/User.php

@ -96,10 +96,6 @@ class User {
{
$pd = new modl\PresenceDAO();
$pd->clearPresence($this->username);
/*if($this->isLogged()) {
$p = new moxl\PresenceUnavaiable();
$p->request();
}*/
$sess = Session::start(APP_NAME);
Session::dispose(APP_NAME);

Loading…
Cancel
Save