From 1c3d26fe83f437d4c20fe79039e25166a23cf1ec Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 26 Jan 2019 12:30:18 -0800 Subject: [PATCH 1/3] remove unused zot6 'request' verb support --- Zotlabs/Lib/Libzot.php | 2 +- Zotlabs/Web/Session.php | 39 +++++++++++++------ Zotlabs/Zot6/IHandler.php | 2 - Zotlabs/Zot6/Receiver.php | 4 -- Zotlabs/Zot6/Zot6Handler.php | 73 ------------------------------------ 5 files changed, 28 insertions(+), 92 deletions(-) diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 80741818f..4ab2c3f46 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -315,7 +315,7 @@ class Libzot { if(! $hsig_valid) { logger('http signature not valid: ' . print_r($hsig,true)); - return $result; + return false; } diff --git a/Zotlabs/Web/Session.php b/Zotlabs/Web/Session.php index 4f2a3f1f7..3a80e5d5c 100644 --- a/Zotlabs/Web/Session.php +++ b/Zotlabs/Web/Session.php @@ -15,7 +15,7 @@ class Session { private $handler = null; private $session_started = false; - + private $custom_handler = false; public function init() { $gc_probability = 50; @@ -23,25 +23,39 @@ class Session { ini_set('session.gc_probability', $gc_probability); ini_set('session.use_only_cookies', 1); ini_set('session.cookie_httponly', 1); - + + $this->custom_handler = boolval(get_config('system', 'session_custom', false)); + /* * Set our session storage functions. */ + + if ($this->custom_handler) { + /* Custom handler (files, memached, redis..) */ - $handler = new \Zotlabs\Web\SessionHandler(); + $session_save_handler = strval(get_config('system', 'session_save_handler', Null)); + $session_save_path = strval(get_config('system', 'session_save_path', Null)); + if (!$session_save_handler || !$session_save_path) { + logger('Session save handler or path not set.',LOGGER_NORMAL,LOG_ERR); + } else { + ini_set('session.save_handler', $session_save_handler); + ini_set('session.save_path', $session_save_path); + } + } else { + $handler = new \Zotlabs\Web\SessionHandler(); - $this->handler = $handler; - - $x = session_set_save_handler($handler,false); - if(! $x) - logger('Session save handler initialisation failed.',LOGGER_NORMAL,LOG_ERR); + $this->handler = $handler; + $x = session_set_save_handler($handler,false); + if(! $x) + logger('Session save handler initialisation failed.',LOGGER_NORMAL,LOG_ERR); + }; // Force cookies to be secure (https only) if this site is SSL enabled. // Must be done before session_start(). $arr = session_get_cookie_params(); - + // Note when setting cookies: set the domain to false which creates a single domain // cookie. If you use a hostname it will create a .domain.com wildcard which will // have some nasty side effects if you have any other subdomains running hubzilla. @@ -86,14 +100,15 @@ class Session { $arr = session_get_cookie_params(); - if($this->handler && $this->session_started) { + if(($this->handler || $this->custom_handler) && $this->session_started) { session_regenerate_id(true); // force SessionHandler record creation with the new session_id // which occurs as a side effect of read() - - $this->handler->read(session_id()); + if (! $this->custom_handler) { + $this->handler->read(session_id()); + } } else logger('no session handler'); diff --git a/Zotlabs/Zot6/IHandler.php b/Zotlabs/Zot6/IHandler.php index 53b6caa89..37bccb287 100644 --- a/Zotlabs/Zot6/IHandler.php +++ b/Zotlabs/Zot6/IHandler.php @@ -6,8 +6,6 @@ interface IHandler { function Notify($data,$hub); - function Request($data,$hub); - function Rekey($sender,$data,$hub); function Refresh($sender,$recipients,$hub); diff --git a/Zotlabs/Zot6/Receiver.php b/Zotlabs/Zot6/Receiver.php index 229091cb6..4eefeae21 100644 --- a/Zotlabs/Zot6/Receiver.php +++ b/Zotlabs/Zot6/Receiver.php @@ -182,10 +182,6 @@ class Receiver { switch ($this->messagetype) { - case 'request': - $this->response = $this->handler->Request($this->data,$this->hub); - break; - case 'purge': $this->response = $this->handler->Purge($this->sender,$this->recipients,$this->hub); break; diff --git a/Zotlabs/Zot6/Zot6Handler.php b/Zotlabs/Zot6/Zot6Handler.php index 941873472..b26e98607 100644 --- a/Zotlabs/Zot6/Zot6Handler.php +++ b/Zotlabs/Zot6/Zot6Handler.php @@ -11,10 +11,6 @@ class Zot6Handler implements IHandler { return self::reply_notify($data,$hub); } - function Request($data,$hub) { - return self::reply_message_request($data,$hub); - } - function Rekey($sender,$data,$hub) { return self::reply_rekey_request($sender,$data,$hub); } @@ -90,75 +86,6 @@ class Zot6Handler implements IHandler { } - - /** - * @brief Process a message request. - * - * If a site receives a comment to a post but finds they have no parent to attach it with, they - * may send a 'request' packet containing the message_id of the missing parent. This is the handler - * for that packet. We will create a message_list array of the entire conversation starting with - * the missing parent and invoke delivery to the sender of the packet. - * - * Zotlabs/Daemon/Deliver.php (for local delivery) and - * mod/post.php???? @fixme (for web delivery) detect the existence of - * this 'message_list' at the destination and split it into individual messages which are - * processed/delivered in order. - * - * - * @param array $data - * @return array - */ - - static function reply_message_request($data,$hub) { - $ret = [ 'success' => false ]; - - $message_id = EMPTY_STR; - - if(array_key_exists('data',$data)) - $ptr = $data['data']; - if(is_array($ptr) && array_key_exists(0,$ptr)) { - $ptr = $ptr[0]; - } - if(is_string($ptr)) { - $message_id = $ptr; - } - if(is_array($ptr) && array_key_exists('id',$ptr)) { - $message_id = $ptr['id']; - } - - if (! $message_id) { - $ret['message'] = 'no message_id'; - logger('no message_id'); - return $ret; - } - - $sender = $hub['hubloc_hash']; - - /* - * Find the local channel in charge of this post (the first and only recipient of the request packet) - */ - - $arr = $data['recipients'][0]; - - $c = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_hash = '%s' limit 1", - dbesc($arr['portable_id']) - ); - if (! $c) { - logger('recipient channel not found.'); - $ret['message'] .= 'recipient not found.' . EOL; - return $ret; - } - - /* - * fetch the requested conversation - */ - - $messages = zot_feed($c[0]['channel_id'],$sender_hash, [ 'message_id' => $data['message_id'], 'encoding' => 'activitystreams' ]); - - return (($messages) ? : [] ); - - } - static function rekey_request($sender,$data,$hub) { $ret = array('success' => false); From 7c155e130a0c30cc910978e2e90e2b7a9f31eec5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 26 Jan 2019 12:31:07 -0800 Subject: [PATCH 2/3] add util/admins --- util/admins | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 util/admins diff --git a/util/admins b/util/admins new file mode 100755 index 000000000..2ac625ed8 --- /dev/null +++ b/util/admins @@ -0,0 +1,63 @@ +#!/usr/bin/env php +' . PHP_EOL; + exit(1); +} + + + +require_once('include/cli_startup.php'); + +cli_startup(); + +$helpArgs = getopt('h', array('help')); +if (count($helpArgs) === 1) { + echo <<<'EndOfOutput' +adds, removes, or lists admins + +Usage: util/admins + util/admins list + util/admins add + util/admins remove + +EndOfOutput; + return; +} + +if($argc == 1) { + $r = q("select account_id, account_roles, account_email from account"); + if($r) { + foreach($r as $rr) { + echo sprintf('%4u %s %s', $rr['account_id'], $rr['account_email'],(($rr['account_roles'] & 4096) ? '*' : '')) . PHP_EOL; + } + } +} + + + +if($argc > 1 && $argv[1] === 'list') { + $r = q("select account_id, account_roles, account_email from account where (account_roles & 4096) > 0"); + if($r) { + foreach($r as $rr) { + echo sprintf('%4u %s %s', $rr['account_id'], $rr['account_email'],(($rr['account_roles'] & 4096) ? '*' : '')) . PHP_EOL; + } + } +} + + +if($argc > 2 && $argv[1] === 'add' && intval($argv[2])) { + $r = q("update account set account_roles = (account_roles | 4096) where account_id = %d", + intval($argv[2]) + ); +} + +if($argc > 2 && $argv[1] === 'remove' && intval($argv[2])) { + $r = q("update account set account_roles = (account_roles - 4096) where account_id = %d and (account_roles & 4096) > 0", + intval($argv[2]) + ); +} From f7f8416477f0685157e0b56afd973b597a7fc3f9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 27 Jan 2019 12:39:28 -0800 Subject: [PATCH 3/3] share fixes --- Zotlabs/Lib/Libzot.php | 10 +++++++--- util/admins | 6 +----- util/config | 2 +- util/pconfig | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 4ab2c3f46..0066b1ef3 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1178,14 +1178,18 @@ class Libzot { logger($AS->debug()); - $r = q("select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", + $r = q("select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s'", dbesc($AS->actor['id']) ); if($r) { - $arr['author_xchan'] = $r[0]['hubloc_hash']; + $r = zot_record_preferred($r); + $arr['author_xchan'] = $record['hubloc_hash']; + } + if(! $arr['author_xchan']) { + logger('No author!'); + return; } - $s = q("select hubloc_hash, hubloc_url from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", dbesc($env['sender']) diff --git a/util/admins b/util/admins index 2ac625ed8..ecc672a78 100755 --- a/util/admins +++ b/util/admins @@ -1,16 +1,12 @@ #!/usr/bin/env php ' . PHP_EOL; + echo 'Run admins from the top level web directory, as util/admins ' . PHP_EOL; exit(1); } - require_once('include/cli_startup.php'); cli_startup(); diff --git a/util/config b/util/config index 1851c69a6..328b294b4 100755 --- a/util/config +++ b/util/config @@ -4,7 +4,7 @@ // Red config utility if(!file_exists('include/cli_startup.php')) { - echo 'Run config from the top level Hubzilla web directory, as util/config ' . PHP_EOL; + echo 'Run config from the top level web directory, as util/config ' . PHP_EOL; exit(1); } diff --git a/util/pconfig b/util/pconfig index e3db2fc6f..5cc551e25 100755 --- a/util/pconfig +++ b/util/pconfig @@ -7,7 +7,7 @@ use Zotlabs\Lib\Libsync; if(!file_exists('include/cli_startup.php')) { - echo 'Run pconfig from the top level Hubzilla web directory, as util/pconfig ' . PHP_EOL; + echo 'Run pconfig from the top level web directory, as util/pconfig ' . PHP_EOL; exit(1); }