diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/notifier.php | 67 | ||||
-rw-r--r-- | include/permissions.php | 4 | ||||
-rw-r--r-- | include/zot.php | 18 |
3 files changed, 62 insertions, 27 deletions
diff --git a/include/notifier.php b/include/notifier.php index dd56750c8..1878c2a98 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -40,42 +40,75 @@ require_once('include/html2plain.php'); * wall-new (in photos.php, item.php) * * and ITEM_ID is the id of the item in the database that needs to be sent to others. + * + * ZOT + * permission_updated abook_id + * */ +require_once('include/cli_startup.php'); +require_once('include/zot.php'); + function notifier_run($argv, $argc){ - global $a, $db; - if(is_null($a)){ - $a = new App; - } - - if(is_null($db)) { - @include(".htconfig.php"); - require_once("dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - } + cli_startup(); + + $a = get_app(); require_once("session.php"); require_once("datetime.php"); require_once('include/items.php'); require_once('include/bbcode.php'); - load_config('config'); - load_config('system'); - - load_hooks(); - if($argc < 3) return; - $a->set_baseurl(get_config('system','url')); logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG); $cmd = $argv[1]; + $item_id = $argv[2]; + + $extra = (($argc > 3) ? $argv[3] : null); + + if($cmd == 'permission_update') { + // Get the recipient + $r = q("select abook.*, hubloc.* from abook + left join hubloc on hubloc_hash = abook_xchan + where abook_id = %d limit 1", + intval($item_id) + ); + if($r) { + // Get the sender + $s = q("select * from channel where channel_id = %d limit 1", + intval($r[0]['abook_channel']) + ); + if($s) { + + // send a refresh message to each hub they have registered here + $h = q("select * from hubloc where hubloc_hash = '%s'", + dbesc($r[0]['hubloc_hash']) + ); + if($h) { + foreach($h as $hh) { + $result = zot_notify($s[0],$hh['hubloc_callback'],'refresh',array(array( + 'guid' => $hh['hubloc_guid'], + 'guid_sig' => $hh['hubloc_guid_sig'], + 'url' => $hh['hubloc_url']) + )); + // should probably queue these + } + } + } + } + } + +return; + + + switch($cmd) { case 'mail': default: diff --git a/include/permissions.php b/include/permissions.php index ca44ac4ad..0502d7e2e 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -135,7 +135,7 @@ function get_all_perms($uid,$observer,$internal_use = true) { // Check if this is a write permission and they are being ignored // This flag is only visible internally. - if(($internal_use) && (! $global_perms[$permission][2]) && ($x[0]['abook_flags'] & ABOOK_FLAG_IGNORED)) { + if(($internal_use) && (! $global_perms[$perm_name][2]) && ($x[0]['abook_flags'] & ABOOK_FLAG_IGNORED)) { $ret[$perm_name] = false; continue; } @@ -149,7 +149,7 @@ function get_all_perms($uid,$observer,$internal_use = true) { // Permission granted to certain channels. Let's see if the observer is one of them if(($r) && ($r[0][$channel_perm] & PERMS_SPECIFIC)) { - if(($x) && ($x[0]['abook_my_perms'] & $global_perms[$permission][1])) { + if(($x) && ($x[0]['abook_my_perms'] & $global_perms[$perm_name][1])) { $ret[$perm_name] = true; continue; } diff --git a/include/zot.php b/include/zot.php index 63508b749..b11961861 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1,5 +1,6 @@ <?php +require_once('include/crypto.php'); /** * * @function zot_new_uid($channel_nick) @@ -65,9 +66,9 @@ function zot_notify($channel,$url,$type = 'notify',$recipients = null, $remote_k 'type' => $type, 'sender' => json_encode(array( 'guid' => $channel['channel_guid'], - 'guid_sig' => base64url_encode($guid,$channel['prvkey']), - 'hub' => z_root(), - 'hub_sig' => base64url_encode(z_root,$channel['prvkey']) + 'guid_sig' => base64url_encode(rsa_sign($channel['channel_guid'],$channel['channel_prvkey'])), + 'url' => z_root(), + 'url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'])) )), 'callback' => '/post', 'version' => ZOT_REVISION @@ -82,7 +83,7 @@ function zot_notify($channel,$url,$type = 'notify',$recipients = null, $remote_k $params = aes_encapsulate($params,$remote_key); } - $x = z_post_url($url,$prams); + $x = z_post_url($url,$params); return($x); } @@ -211,7 +212,7 @@ function zot_refresh($them,$channel = null) { } } - $r = q("update abook set their_perms = %d + $r = q("update abook set abook_their_perms = %d where abook_xchan = '%s' and abook_channel = %d limit 1", intval($their_perms), dbesc($channel['channel_hash']), @@ -229,15 +230,16 @@ function zot_refresh($them,$channel = null) { function zot_gethub($jarr) { - if($jarr->guid && $jarr->guid_sig && $jarr->hub && $jarr->hub_sig) { + + if($jarr->guid && $jarr->guid_sig && $jarr->url && $jarr->url_sig) { $r = q("select * from hubloc where hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' limit 1", dbesc($jarr->guid), dbesc($jarr->guid_sig), - dbesc($jarr->hub), - dbesc($jarr->hub_sig) + dbesc($jarr->url), + dbesc($jarr->url_sig) ); if($r && count($r)) return $r[0]; |