Merge branch 'dev' of /home/macgirvin/osada into dev

This commit is contained in:
zotlabs 2019-01-27 14:39:41 -08:00
commit 8760b6d741
8 changed files with 96 additions and 97 deletions

View file

@ -315,7 +315,7 @@ class Libzot {
if(! $hsig_valid) {
logger('http signature not valid: ' . print_r($hsig,true));
return $result;
return false;
}
@ -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'])

View file

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

View file

@ -6,8 +6,6 @@ interface IHandler {
function Notify($data,$hub);
function Request($data,$hub);
function Rekey($sender,$data,$hub);
function Refresh($sender,$recipients,$hub);

View file

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

View file

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

59
util/admins Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env php
<?php
if(!file_exists('include/cli_startup.php')) {
echo 'Run admins from the top level web directory, as util/admins <args>' . 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 <account_id>
util/admins remove <account_id>
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])
);
}

View file

@ -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 <args>' . PHP_EOL;
echo 'Run config from the top level web directory, as util/config <args>' . PHP_EOL;
exit(1);
}

View file

@ -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 <args>' . PHP_EOL;
echo 'Run pconfig from the top level web directory, as util/pconfig <args>' . PHP_EOL;
exit(1);
}