aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/deliver.php40
-rw-r--r--include/notifier.php7
-rw-r--r--include/zot.php113
-rw-r--r--install/database.sql6
-rw-r--r--mod/post.php39
-rw-r--r--version.inc2
6 files changed, 140 insertions, 67 deletions
diff --git a/include/deliver.php b/include/deliver.php
new file mode 100644
index 000000000..df1596c10
--- /dev/null
+++ b/include/deliver.php
@@ -0,0 +1,40 @@
+<?php
+
+require_once('include/cli_startup.php');
+require_once('include/zot.php');
+
+
+function deliver_run($argv, $argc) {
+
+ cli_startup();
+
+ $a = get_app();
+
+ if($argc < 2)
+ return;
+
+ logger('deliver: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
+
+ for($x = 1; $x < $argc; $x ++) {
+ $r = q("select * from outq where outq_hash = '%s' limit 1",
+ dbesc($argv[$x])
+ );
+ if($r) {
+ $result = zot_zot($r[0]['outq_posturl'],$r[0]['outq_notify']);
+ if($result['success']) {
+ zot_process_response($result, $r[0]);
+ }
+ else {
+ $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1",
+ dbesc(datetime_convert()),
+ dbesc($argv[$x])
+ );
+ }
+ }
+ }
+}
+
+if (array_search(__file__,get_included_files())===0){
+ deliver_run($argv,$argc);
+ killme();
+}
diff --git a/include/notifier.php b/include/notifier.php
index f620af10a..6a70bd738 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -184,6 +184,8 @@ function notifier_run($argv, $argc){
$s = q("select * from channel where channel_id = %d limit 1",
intval($target_item['uid'])
);
+ if($s)
+ $channel = $s[0];
if($target_item['id'] == $target_item['parent']) {
$parent_item = $target_item;
@@ -261,12 +263,13 @@ function notifier_run($argv, $argc){
foreach($hubs as $hub) {
$hash = random_string();
- $n = zot_build_packet($channel,'notify',null,(($private) ? $hub['hubloc_sitekey'],$hash);
- q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', '%s', '%s', '%s' )",
+ $n = zot_build_packet($channel,'notify',null,(($private) ? $hub['hubloc_sitekey'] : null),$hash);
+ q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )",
dbesc($hash),
intval($target_item['aid']),
intval($target_item['uid']),
dbesc($hub['hubloc_callback']),
+ intval(1),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc($n),
diff --git a/include/zot.php b/include/zot.php
index c332579c1..9e9f5099d 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -212,9 +212,9 @@ function zot_refresh($them,$channel = null) {
if($result['success']) {
- $j = json_decode($result['body']);
+ $j = json_decode($result['body'],true);
- $x = import_xchan_from_json($j);
+ $x = import_xchan($j);
if(! $x['success'])
return $x;
@@ -226,18 +226,18 @@ function zot_refresh($them,$channel = null) {
if($channel) {
$global_perms = get_perms();
- if($j->permissions->data) {
+ if($j['permissions']['data']) {
$permissions = aes_unencapsulate(array(
- 'data' => $j->permissions->data,
- 'key' => $j->permissions->key,
- 'iv' => $j->permissions->iv),
+ 'data' => $j['permissions']['data'],
+ 'key' => $j['permissions']['key'],
+ 'iv' => $j['permissions']['iv']),
$channel['channel_prvkey']);
if($permissions)
- $permissions = json_decode($permissions);
+ $permissions = json_decode($permissions,true);
logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA);
}
else
- $permissions = $j->permissions;
+ $permissions = $j['permissions'];
foreach($permissions as $k => $v) {
if($v) {
@@ -265,17 +265,17 @@ function zot_refresh($them,$channel = null) {
}
-function zot_gethub($jarr) {
+function zot_gethub($arr) {
- if($jarr->guid && $jarr->guid_sig && $jarr->url && $jarr->url_sig) {
+ if($arr['guid'] && $arr['guid_sig'] && $arr['url'] && $arr['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->url),
- dbesc($jarr->url_sig)
+ dbesc($arr['guid']),
+ dbesc($arr['guid_sig']),
+ dbesc($arr['url']),
+ dbesc($arr['url_sig'])
);
if($r && count($r))
return $r[0];
@@ -287,15 +287,15 @@ function zot_register_hub($arr) {
$result = array('success' => false);
- if($arr->hub && $arr->hub_sig && $arr->guid && $arr->guid_sig) {
+ if($arr['hub'] && $arr['hub_sig'] && $arr['guid'] && $arr['guid_sig']) {
- $guid_hash = base64url_encode(hash('whirlpool',$arr->guid . $arr->guid_sig, true));
+ $guid_hash = base64url_encode(hash('whirlpool',$arr['guid'] . $arr['guid_sig'], true));
- $x = z_fetch_url($arr->hub . '/.well-known/zot-info/?f=&hash=' . $guid_hash);
+ $x = z_fetch_url($arr['hub'] . '/.well-known/zot-info/?f=&hash=' . $guid_hash);
if($x['success']) {
- $record = json_decode($x['body']);
- $c = import_xchan_from_json($record);
+ $record = json_decode($x['body'],true);
+ $c = import_xchan($record);
if($c['success'])
$result['success'] = true;
}
@@ -427,15 +427,15 @@ function import_xchan_from_json($j) {
//
-function import_xchan($j) {
+function import_xchan($arr) {
$ret = array('success' => false);
- $xchan_hash = base64url_encode(hash('whirlpool',$j['guid'] . $j['guid_sig'], true));
+ $xchan_hash = base64url_encode(hash('whirlpool',$arr['guid'] . $arr['guid_sig'], true));
$import_photos = false;
- if(! rsa_verify($j['guid'],base64url_decode($j['guid_sig']),$j['key'])) {
- logger('import_xchan_from_json: Unable to verify channel signature for ' . $j['address']);
+ if(! rsa_verify($arr['guid'],base64url_decode($arr['guid_sig']),$arr['key'])) {
+ logger('import_xchan_from_json: Unable to verify channel signature for ' . $arr['address']);
$ret['message'] = t('Unable to verify channel signature');
return $ret;
}
@@ -445,12 +445,12 @@ function import_xchan($j) {
);
if($r) {
- if($r[0]['xchan_photo_date'] != $j['photo_updated'])
+ if($r[0]['xchan_photo_date'] != $arr['photo_updated'])
$update_photos = true;
- if($r[0]['xchan_name_date'] != $j['name_updated']) {
+ if($r[0]['xchan_name_date'] != $arr['name_updated']) {
$r = q("update xchan set xchan_name = '%s', xchan_name_date = '%s' where xchan_hash = '%s' limit 1",
- dbesc($j['name']),
- dbesc($j['name_updated']),
+ dbesc($arr['name']),
+ dbesc($arr['name_updated']),
dbesc($xchan_hash)
);
}
@@ -461,17 +461,17 @@ function import_xchan($j) {
xchan_photo_l, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_photo_date, xchan_name_date)
values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
dbesc($xchan_hash),
- dbesc($j['guid']),
- dbesc($j['guid_sig']),
- dbesc($j['key']),
- dbesc($j['photo_mimetype']),
- dbesc($j['photo']),
- dbesc($j['address']),
- dbesc($j['url']),
- dbesc($j['name']),
+ dbesc($arr['guid']),
+ dbesc($arr['guid_sig']),
+ dbesc($arr['key']),
+ dbesc($arr['photo_mimetype']),
+ dbesc($arr['photo']),
+ dbesc($arr['address']),
+ dbesc($arr['url']),
+ dbesc($arr['name']),
dbesc('zot'),
- dbesc($j['photo_updated']),
- dbesc($j['name_updated'])
+ dbesc($arr['photo_updated']),
+ dbesc($arr['name_updated'])
);
}
@@ -481,10 +481,10 @@ function import_xchan($j) {
require_once("Photo.php");
- $photos = import_profile_photo($j['photo'],0,$xchan_hash);
+ $photos = import_profile_photo($arr['photo'],0,$xchan_hash);
$r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
where xchan_hash = '%s' limit 1",
- dbesc($j['photo_updated']),
+ dbesc($arr['photo_updated']),
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
@@ -493,9 +493,9 @@ function import_xchan($j) {
);
}
- if($j['locations']) {
- foreach($j['locations'] as $location) {
- if(! rsa_verify($location['url'],base64url_decode($location['url_sig']),$j['key'])) {
+ if($arr['locations']) {
+ foreach($arr['locations'] as $location) {
+ if(! rsa_verify($location['url'],base64url_decode($location['url_sig']),$arr['key'])) {
logger('import_xchan_from_json: Unable to verify site signature for ' . $location['url']);
$ret['message'] .= sprintf( t('Unable to verify site signature for %s'), $location['url']) . EOL;
continue;
@@ -517,8 +517,8 @@ function import_xchan($j) {
$r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_flags, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey)
values ( '%s','%s','%s','%s', %d ,'%s','%s','%s','%s','%s')",
- dbesc($j['guid']),
- dbesc($j['guid_sig']),
+ dbesc($arr['guid']),
+ dbesc($arr['guid_sig']),
dbesc($xchan_hash),
dbesc($location['address']),
intval((intval($location['primary'])) ? HUBLOC_FLAGS_PRIMARY : 0),
@@ -540,3 +540,28 @@ function import_xchan($j) {
return $ret;
}
+function zot_process_response($arr,$outq) {
+ if(! $arr['success'])
+ return;
+
+ $x = json_decode($arr['body'],true);
+
+ // synchronous message types are handled immediately
+ // async messages remain in the queue until processed.
+
+ if(intval($outq['outq_async'])) {
+ $r = q("update outq set outq_delivered = 1, outq_updated = '%s' where outq_hash = '%s' and outq_channel = %d limit 1",
+ dbesc(datetime_convert()),
+ dbesc($outq['outq_hash']),
+ intval($outq['outq_channel'])
+ );
+ }
+ else {
+ $r = q("delete from outq where outq_hash = '%s' and outq_channel = %d limit 1",
+ dbesc($outq['outq_hash']),
+ intval($outq['outq_channel'])
+ );
+ }
+
+ logger('zot_process_response: ' . print_r($x,true), LOGGER_DATA);
+} \ No newline at end of file
diff --git a/install/database.sql b/install/database.sql
index c1746455d..7ab8625db 100644
--- a/install/database.sql
+++ b/install/database.sql
@@ -675,6 +675,8 @@ CREATE TABLE IF NOT EXISTS `outq` (
`outq_account` int(10) unsigned NOT NULL DEFAULT '0',
`outq_channel` int(10) unsigned NOT NULL DEFAULT '0',
`outq_posturl` char(255) NOT NULL DEFAULT '',
+ `outq_async` tinyint(1) NOT NULL DEFAULT '0',
+ `outq_delivered` tinyint(1) NOT NULL DEFAULT '0',
`outq_created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`outq_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`outq_notify` mediumtext NOT NULL,
@@ -684,7 +686,9 @@ CREATE TABLE IF NOT EXISTS `outq` (
KEY `outq_channel` (`outq_channel`),
KEY `outq_hub` (`outq_posturl`),
KEY `outq_created` (`outq_created`),
- KEY `outq_updated` (`outq_updated`)
+ KEY `outq_updated` (`outq_updated`),
+ KEY `outq_async` (`outq_async`),
+ KEY `outq_delivered` (`outq_delivered`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `pconfig` (
diff --git a/mod/post.php b/mod/post.php
index f84b641ca..320e9fdd9 100644
--- a/mod/post.php
+++ b/mod/post.php
@@ -15,23 +15,25 @@ function post_post(&$a) {
if(array_key_exists('iv',$_REQUEST)) {
// hush-hush ultra top secret mode
- $data = aes_unencapsulate($_REQUEST,get_config('system','site_prvkey'));
+ $data = json_decode(aes_unencapsulate($_REQUEST['data'],get_config('system','site_prvkey')),true);
}
else {
- $data = $_REQUEST;
+ $data = json_decode($_REQUEST['data'],true);
}
+
+
$msgtype = ((array_key_exists('type',$data)) ? $data['type'] : '');
if(array_key_exists('sender',$data)) {
- $j_sender = json_decode($data['sender']);
+ $sender = $data['sender'];
}
- $hub = zot_gethub($j_sender);
+ $hub = zot_gethub($sender);
if(! $hub) {
// (!!) this will validate the sender
- $result = zot_register_hub($j_sender);
- if((! $result['success']) || (! zot_gethub($j_sender))) {
+ $result = zot_register_hub($sender);
+ if((! $result['success']) || (! zot_gethub($sender))) {
$ret['message'] = 'Hub not available.';
logger('mod_zot: no hub');
json_return_and_die($ret);
@@ -41,29 +43,29 @@ function post_post(&$a) {
// TODO: check which hub is primary and take action if mismatched
if(array_key_exists('recipients',$data))
- $j_recipients = json_decode($data['recipients']);
+ $recipients = $data['recipients'];
if($msgtype === 'refresh') {
// remote channel info (such as permissions or photo or something)
// has been updated. Grab a fresh copy and sync it.
- if($j_recipients) {
+ if($recipients) {
// This would be a permissions update, typically for one connection
- foreach($j_recipients as $recip) {
+ foreach($recipients as $recip) {
$r = q("select channel.*,xchan.* from channel
left join xchan on channel_hash = xchan_hash
where channel_guid = '%s' and channel_guid_sig = '%s' limit 1",
- dbesc($recip->guid),
- dbesc($recip->guid_sig)
+ dbesc($recip['guid']),
+ dbesc($recip['guid_sig'])
);
$x = zot_refresh(array(
- 'xchan_guid' => $j_sender->guid,
- 'xchan_guid_sig' => $j_sender->guid_sig,
- 'hubloc_url' => $j_sender->url
+ 'xchan_guid' => $sender['guid'],
+ 'xchan_guid_sig' => $sender['guid_sig'],
+ 'hubloc_url' => $sender['url']
),$r[0]);
}
}
@@ -72,9 +74,9 @@ function post_post(&$a) {
// system wide refresh
$x = zot_refresh(array(
- 'xchan_guid' => $j_sender->guid,
- 'xchan_guid_sig' => $j_sender->guid_sig,
- 'hubloc_url' => $j_sender->url
+ 'xchan_guid' => $sender['guid'],
+ 'xchan_guid_sig' => $sender['guid_sig'],
+ 'hubloc_url' => $sender['url']
),null);
}
$ret['result'] = true;
@@ -82,13 +84,12 @@ function post_post(&$a) {
}
if($msgtype === 'notify') {
-
-
// add to receive queue
// qreceive_add($data);
$ret['result'] = true;
json_return_and_die($ret);
+
}
}
diff --git a/version.inc b/version.inc
index 6e0f616d2..a28c146b8 100644
--- a/version.inc
+++ b/version.inc
@@ -1 +1 @@
-2012-11-18.143
+2012-11-19.144