Skip to content

Commit

Permalink
Application instance ID, 8-chars unique ID for application installati…
Browse files Browse the repository at this point in the history
…on, and function o2app_instance_id()
  • Loading branch information
tvannini committed Nov 25, 2020
1 parent 796bc1c commit 8a0e080
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
19 changes: 12 additions & 7 deletions lib/jxapp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class o2_app {
public $referer = ''; /* <alias>/<name>.php ($_SERVER['PHP_SELF']) */
public $versione = ''; /* Version (in the form v.s.r) */
public $titolo = ''; /* Text to write in the browser title bar */
public $instance_id = ''; /* Application instance unique id */
public $chr_encoding = ''; /* Character encoding (default windows-1252) */
public $default = ''; /* Document to be included when nothing to do */
public $no_login = ''; /* Failed login page */
Expand Down Expand Up @@ -355,7 +356,9 @@ class o2_app {
$this->crea_cartelle();
break;
}
$this->host = strtoupper($this->nome.'@'.gethostname());
$this->host = strtoupper($this->nome.'@'.gethostname());
// ________________________________ Set application instance unique identifier ___
$this->instance_id = hash('crc32b', $this->dir_home);
if (!$this->titolo) {
$this->titolo = $this->nome;
}
Expand Down Expand Up @@ -541,10 +544,12 @@ class o2_app {
// ____________________________________________________ Remove user tmp-folder ___
$this->dir_tmp->remove();
// _____________________________________ Remove keepalive file from system TMP ___
$tmp_d = new o2_dir(rtrim(sys_get_temp_dir(), '\\/').DIRECTORY_SEPARATOR);
$tmp_f = $tmp_d->element('jx_'.$this->session_id);
if ($tmp_d->exists($tmp_f->nome_completo)) {
unlink($tmp_f->nome_completo);
if ($this->keep_alive) {
$tmp_d = new o2_dir(rtrim(sys_get_temp_dir(), '\\/').DIRECTORY_SEPARATOR);
$tmp_f = $tmp_d->element('jx_'.$this->instance_id.'_'.$this->session_id);
if ($tmp_d->exists($tmp_f->nome_completo)) {
unlink($tmp_f->nome_completo);
}
}
// ____________________________________________________ Remove session cookies ___
if (session_id()) {
Expand Down Expand Up @@ -1046,9 +1051,9 @@ class o2_app {
}
// ___________________________________________ Delete tmp files for keep-alive ___
$tmp_dir = new o2_dir(rtrim(sys_get_temp_dir(), '\\/').DIRECTORY_SEPARATOR);
foreach ($tmp_dir->all_elements('jx_*') as $tmp_f) {
foreach ($tmp_dir->all_elements('jx_'.$this->instance_id.'_*') as $tmp_f) {
// ____________________________________________ Check if session is active ___
if (!in_array(substr($tmp_f->nome, 3), $active_sess)) {
if (!in_array(substr($tmp_f->nome, 12), $active_sess)) {
unlink($tmp_f->nome_completo);
}
}
Expand Down
16 changes: 16 additions & 0 deletions lib/jxfnx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,22 @@ function o2app_name() {
}


/**
* Returns application instance unique ID.
* This ID is a 8 characters string, unique for application home folder.
* Instance ID is useful for generating unique file names in applications shared folders.
*
* @package application
* @return string
* @see o2app_name(), o2app_alias()
*/
function o2app_instance_id() {

return $_SESSION['o2_app']->instance_id;

}


/**
* Returns application alias as an URL prefix, mostly useful to address application
* resources (images, JS libraries, ...)
Expand Down
5 changes: 3 additions & 2 deletions lib/prgs/o2sys_start.prf
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ if ($server->type == 'sqlite3') {
else {
$host = $server->server;
}
file_put_contents(rtrim(sys_get_temp_dir(), '\\/').DIRECTORY_SEPARATOR.'jx_'.o2app_sid(),
file_put_contents(rtrim(sys_get_temp_dir(), '\\/').DIRECTORY_SEPARATOR.
'jx_'.o2app_instance_id().'_'.o2app_sid(),
$server->type."\n".
$host."\n".
$server->user."\n".
Expand Down Expand Up @@ -843,6 +844,6 @@ return (true);

function o2sys_start_exp_63() {

return (o2val('sessions','run_mode') == 'WEB');
return ((o2val('sessions','run_mode') == 'WEB') && $_SESSION['o2_app']->keep_alive);
} //|o2_fine_exp|
?>

0 comments on commit 8a0e080

Please sign in to comment.