diff options
author | Mario <mario@mariovavti.com> | 2019-11-15 20:29:58 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2019-11-15 20:29:58 +0000 |
commit | 965c51c2d45a98db10543c5108ac486e4fc6459e (patch) | |
tree | e0563eb6b283be784b21b8f605b62c84d9899dbc | |
parent | 5a6b14f8787927ee6ea99c622d02875811d3a74a (diff) | |
download | volse-hubzilla-965c51c2d45a98db10543c5108ac486e4fc6459e.tar.gz volse-hubzilla-965c51c2d45a98db10543c5108ac486e4fc6459e.tar.bz2 volse-hubzilla-965c51c2d45a98db10543c5108ac486e4fc6459e.zip |
sse: implement notifications for anonymous visitors (info, notice and pubs) and fix a potential memory leak
-rw-r--r-- | Zotlabs/Daemon/Cron_daily.php | 6 | ||||
-rw-r--r-- | Zotlabs/Module/Sse.php | 31 | ||||
-rw-r--r-- | Zotlabs/Module/Sse_bs.php | 32 | ||||
-rwxr-xr-x | boot.php | 29 |
4 files changed, 78 insertions, 20 deletions
diff --git a/Zotlabs/Daemon/Cron_daily.php b/Zotlabs/Daemon/Cron_daily.php index dbfcff439..b41625963 100644 --- a/Zotlabs/Daemon/Cron_daily.php +++ b/Zotlabs/Daemon/Cron_daily.php @@ -44,6 +44,12 @@ class Cron_daily { db_utcnow(), db_quoteinterval('1 YEAR') ); + // expire anonymous sse notification entries once a day + + q("delete from xconfig where xchan like '%s'", + dbesc('sse_id.%') + ); + //update statistics in config require_once('include/statistics_fns.php'); diff --git a/Zotlabs/Module/Sse.php b/Zotlabs/Module/Sse.php index 556fe2853..b227a396d 100644 --- a/Zotlabs/Module/Sse.php +++ b/Zotlabs/Module/Sse.php @@ -11,22 +11,41 @@ class Sse extends Controller { public static $uid; public static $ob_hash; + public static $sse_id; public static $vnotify; function init() { + if((observer_prohibited(true))) { + killme(); + } + + if(! intval(get_config('system','open_pubstream',1))) { + if(! get_observer_hash()) { + killme(); + } + } + // this is important! session_write_close(); - $sys = get_sys_channel(); - self::$uid = local_channel(); self::$ob_hash = get_observer_hash(); - self::$vnotify = get_pconfig(self::$uid, 'system', 'vnotify'); + self::$sse_id = false; - if(! self::$ob_hash) - return; + if(! self::$ob_hash) { + if(session_id()) { + self::$sse_id = true; + self::$ob_hash = 'sse_id.' . session_id(); + } + else { + return; + } + } + self::$vnotify = get_pconfig(self::$uid, 'system', 'vnotify'); + + $sys = get_sys_channel(); $sleep_seconds = 3; header("Content-Type: text/event-stream"); @@ -40,7 +59,7 @@ class Sse extends Controller { * Update chat presence indication (if applicable) */ - if(self::$ob_hash) { + if(! self::$sse_id) { $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1", dbesc(self::$ob_hash), dbesc($_SERVER['REMOTE_ADDR']) diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php index c7fcd0542..270e8b9b9 100644 --- a/Zotlabs/Module/Sse_bs.php +++ b/Zotlabs/Module/Sse_bs.php @@ -11,6 +11,7 @@ class Sse_bs extends Controller { public static $uid; public static $ob_hash; + public static $sse_id; public static $vnotify; public static $evdays; public static $limit; @@ -21,16 +22,26 @@ class Sse_bs extends Controller { self::$uid = local_channel(); self::$ob_hash = get_observer_hash(); + self::$sse_id = false; + + if(! self::$ob_hash) { + if(session_id()) { + self::$sse_id = true; + self::$ob_hash = 'sse_id.' . session_id(); + } + else { + return; + } + } + self::$vnotify = get_pconfig(self::$uid, 'system', 'vnotify'); self::$evdays = intval(get_pconfig(self::$uid, 'system', 'evdays')); self::$limit = 100; self::$offset = 0; self::$xchans = ''; - if(self::$ob_hash) { - set_xconfig(self::$ob_hash, 'sse', 'timestamp', datetime_convert()); - set_xconfig(self::$ob_hash, 'sse', 'language', App::$language); - } + set_xconfig(self::$ob_hash, 'sse', 'timestamp', datetime_convert()); + set_xconfig(self::$ob_hash, 'sse', 'language', App::$language); if(!empty($_GET['nquery']) && $_GET['nquery'] !== '%') { $nquery = $_GET['nquery']; @@ -69,9 +80,6 @@ class Sse_bs extends Controller { default: } - //hz_syslog('init: ' . argv(1)); - //hz_syslog('offset: ' . argv(2)); - if(self::$offset && $f) { $result = self::$f(true); json_return_and_die($result); @@ -227,6 +235,16 @@ class Sse_bs extends Controller { $result['pubs']['notifications'] = []; $result['pubs']['count'] = 0; + if((observer_prohibited(true))) { + return $result; + } + + if(! intval(get_config('system','open_pubstream',1))) { + if(! get_observer_hash()) { + return $result; + } + } + if(! isset($_SESSION['static_loadtime'])) $_SESSION['static_loadtime'] = datetime_convert(); @@ -1831,12 +1831,19 @@ function notice($s) { */ $hash = get_observer_hash(); + $sse_id = false; - if (! $hash) - return; - + if(! $hash) { + if(session_id()) { + $sse_id = true; + $hash = 'sse_id.' . session_id(); + } + else { + return; + } + } - $t = get_xconfig($hash, 'sse', 'timestamp'); + $t = get_xconfig($hash, 'sse', 'timestamp', NULL_DATE); if(datetime_convert('UTC', 'UTC', $t) < datetime_convert('UTC', 'UTC', '- 30 seconds')) { set_xconfig($hash, 'sse', 'notifications', []); @@ -1884,11 +1891,19 @@ function info($s) { */ $hash = get_observer_hash(); + $sse_id = false; - if (! $hash) - return; + if(! $hash) { + if(session_id()) { + $sse_id = true; + $hash = 'sse_id.' . session_id(); + } + else { + return; + } + } - $t = get_xconfig($hash, 'sse', 'timestamp'); + $t = get_xconfig($hash, 'sse', 'timestamp', NULL_DATE); if(datetime_convert('UTC', 'UTC', $t) < datetime_convert('UTC', 'UTC', '- 30 seconds')) { set_xconfig($hash, 'sse', 'notifications', []); |