Merge branch 'sessions_in_db'
This commit is contained in:
commit
7261a7b1dd
|
@ -1024,6 +1024,13 @@ INSERT INTO MontageLayouts (`Name`,`Positions`) VALUES ('3 Wide', '{ "default":{
|
||||||
INSERT INTO MontageLayouts (`Name`,`Positions`) VALUES ('4 Wide', '{ "default":{"float":"left", "width":"24.5%","left":"0px","right":"0px","top":"0px","bottom":"0px"} }' );
|
INSERT INTO MontageLayouts (`Name`,`Positions`) VALUES ('4 Wide', '{ "default":{"float":"left", "width":"24.5%","left":"0px","right":"0px","top":"0px","bottom":"0px"} }' );
|
||||||
INSERT INTO MontageLayouts (`Name`,`Positions`) VALUES ('5 Wide', '{ "default":{"float":"left", "width":"19%","left":"0px","right":"0px","top":"0px","bottom":"0px"} }' );
|
INSERT INTO MontageLayouts (`Name`,`Positions`) VALUES ('5 Wide', '{ "default":{"float":"left", "width":"19%","left":"0px","right":"0px","top":"0px","bottom":"0px"} }' );
|
||||||
|
|
||||||
|
CREATE TABLE Sessions (
|
||||||
|
id char(32) not null,
|
||||||
|
access INT(10) UNSIGNED DEFAULT NULL,
|
||||||
|
data text,
|
||||||
|
PRIMARY KEY(id)
|
||||||
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
-- We generally don't alter triggers, we drop and re-create them, so let's keep them in a separate file that we can just source in update scripts.
|
-- We generally don't alter triggers, we drop and re-create them, so let's keep them in a separate file that we can just source in update scripts.
|
||||||
source @PKGDATADIR@/db/triggers.sql
|
source @PKGDATADIR@/db/triggers.sql
|
||||||
--
|
--
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
--
|
||||||
|
-- This adds Sessions Table
|
||||||
|
--
|
||||||
|
|
||||||
|
SET @s = (SELECT IF(
|
||||||
|
(SELECT COUNT(*)
|
||||||
|
FROM INFORMATION_SCHEMA.TABLES
|
||||||
|
WHERE table_name = 'Sessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
) > 0,
|
||||||
|
"SELECT 'Sessions table exists'",
|
||||||
|
"CREATE TABLE Sessions (
|
||||||
|
id char(32) not null,
|
||||||
|
access INT(10) UNSIGNED DEFAULT NULL,
|
||||||
|
data text,
|
||||||
|
PRIMARY KEY(id)
|
||||||
|
) ENGINE=InnoDB;"
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE stmt FROM @s;
|
||||||
|
EXECUTE stmt;
|
|
@ -28,7 +28,7 @@
|
||||||
%global _hardened_build 1
|
%global _hardened_build 1
|
||||||
|
|
||||||
Name: zoneminder
|
Name: zoneminder
|
||||||
Version: 1.35.8
|
Version: 1.35.9
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
Summary: A camera monitoring and analysis tool
|
Summary: A camera monitoring and analysis tool
|
||||||
Group: System Environment/Daemons
|
Group: System Environment/Daemons
|
||||||
|
|
|
@ -30,6 +30,44 @@ global $CLANG;
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p><?php echo sprintf( $CLANG['CurrentLogin'], $user['Username'] ) ?></p>
|
<p><?php echo sprintf( $CLANG['CurrentLogin'], $user['Username'] ) ?></p>
|
||||||
|
<?php if ( canView('System') ) { ?>
|
||||||
|
<p>Other logged in users:<br/>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo(translate('Username'))?></th>
|
||||||
|
<th><?php echo(translate('Last Access'))?></th>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
require_once('includes/User.php');
|
||||||
|
$result = dbQuery('SELECT * FROM Sessions');
|
||||||
|
if ( ! $result ) return;
|
||||||
|
|
||||||
|
$current_session = $_SESSION;
|
||||||
|
zm_session_start();
|
||||||
|
|
||||||
|
while ( $row = $result->fetch(PDO::FETCH_ASSOC) ) {
|
||||||
|
$_SESSION = array();
|
||||||
|
if ( ! session_decode($row['data']) ) {
|
||||||
|
ZM\Warning('Failed to decode ' . $row['data']);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( isset($_SESSION['last_time']) ) {
|
||||||
|
# This is a dead session
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$user = ZM\User::find_one(array('Username'=>$_SESSION['username']));
|
||||||
|
if ( ! $user ) {
|
||||||
|
ZM\Logger::Debug('User not found for ' . $_SESSION['username']);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<tr><td>'.$user->Username().'</td><td>'.strftime(STRF_FMT_DATETIME_SHORTER, $row['access']).'</td></tr>';
|
||||||
|
} # end while
|
||||||
|
session_abort();
|
||||||
|
$_SESSION = $current_session;
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
<?php } # end if canView(System) ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<form name="logoutForm" id="logoutForm" method="post" action="?">
|
<form name="logoutForm" id="logoutForm" method="post" action="?">
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
if ( $action == 'logout' ) {
|
if ( $action == 'logout' ) {
|
||||||
userLogout();
|
userLogout();
|
||||||
$view = 'login';
|
$view = 'login';
|
||||||
ZM\Logger::Debug("User: " . print_r($user,true));
|
|
||||||
} elseif ( $action == 'config' ) {
|
} elseif ( $action == 'config' ) {
|
||||||
$redirect = '?view=user&uid='.$user['Id'];
|
$redirect = '?view=user&uid='.$user['Id'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,4 +87,69 @@ function zm_session_clear() {
|
||||||
session_write_close();
|
session_write_close();
|
||||||
session_start();
|
session_start();
|
||||||
} // function zm_session_clear()
|
} // function zm_session_clear()
|
||||||
|
|
||||||
|
|
||||||
|
class Session {
|
||||||
|
private $db;
|
||||||
|
public function __construct() {
|
||||||
|
global $dbConn;
|
||||||
|
$this->db = $dbConn;
|
||||||
|
|
||||||
|
// Set handler to overide SESSION
|
||||||
|
session_set_save_handler(
|
||||||
|
array($this, '_open'),
|
||||||
|
array($this, '_close'),
|
||||||
|
array($this, '_read'),
|
||||||
|
array($this, '_write'),
|
||||||
|
array($this, '_destroy'),
|
||||||
|
array($this, '_gc')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Start the session
|
||||||
|
//zm_session_start();
|
||||||
|
}
|
||||||
|
public function _open() {
|
||||||
|
return $this->db ? true : false;
|
||||||
|
}
|
||||||
|
public function _close(){
|
||||||
|
// The example code closed the db connection.. I don't think we care to.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public function _read($id){
|
||||||
|
$sth = $this->db->prepare('SELECT data FROM Sessions WHERE id = :id');
|
||||||
|
$sth->bindParam(':id', $id, PDO::PARAM_STR, 32);
|
||||||
|
|
||||||
|
if ( $sth->execute() and ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) ) {
|
||||||
|
return $row['data'];
|
||||||
|
}
|
||||||
|
// Return an empty string
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
public function _write($id, $data){
|
||||||
|
// Create time stamp
|
||||||
|
$access = time();
|
||||||
|
|
||||||
|
$sth = $this->db->prepare('REPLACE INTO Sessions VALUES (:id, :access, :data)');
|
||||||
|
|
||||||
|
$sth->bindParam(':id', $id, PDO::PARAM_STR, 32);
|
||||||
|
$sth->bindParam(':access', $access, PDO::PARAM_INT);
|
||||||
|
$sth->bindParam(':data', $data);
|
||||||
|
|
||||||
|
return $sth->execute() ? true : false;
|
||||||
|
}
|
||||||
|
public function _destroy($id) {
|
||||||
|
$sth = $this->db->prepare('DELETE FROM Sessions WHERE Id = :id');
|
||||||
|
$sth->bindParam(':id', $id, PDO::PARAM_STR, 32);
|
||||||
|
return $sth->execute() ? true : false;
|
||||||
|
}
|
||||||
|
public function _gc($max) {
|
||||||
|
// Calculate what is to be deemed old
|
||||||
|
$old = time() - $max;
|
||||||
|
$sth = $this->db->prepare('DELETE * FROM Sessions WHERE access < :old');
|
||||||
|
$sth->bindParam(':old', $old, PDO::PARAM_INT);
|
||||||
|
return $sth->execute() ? true : false;
|
||||||
|
}
|
||||||
|
} # end class Session
|
||||||
|
|
||||||
|
$session = new Session;
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue