aboutsummaryrefslogtreecommitdiffstats
path: root/mod
diff options
context:
space:
mode:
Diffstat (limited to 'mod')
-rw-r--r--mod/admin.php2
-rw-r--r--mod/connedit.php50
-rw-r--r--mod/directory.php11
-rw-r--r--mod/dirsearch.php19
-rw-r--r--mod/prate.php66
-rw-r--r--mod/prep.php75
-rw-r--r--mod/rate.php158
-rw-r--r--mod/ratings.php103
-rw-r--r--mod/ratingsearch.php58
-rw-r--r--mod/regdir.php69
-rw-r--r--mod/zfinger.php9
11 files changed, 498 insertions, 122 deletions
diff --git a/mod/admin.php b/mod/admin.php
index ec922cc72..e1808fd55 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -562,7 +562,7 @@ function admin_page_dbsync(&$a) {
if(count($r)) {
foreach($r as $rr) {
$upd = intval(substr($rr['k'],8));
- if($upd < 1139 || $rr['v'] === 'success')
+ if($rr['v'] === 'success')
continue;
$failed[] = $upd;
}
diff --git a/mod/connedit.php b/mod/connedit.php
index 8c0212afe..2c4c0cef8 100644
--- a/mod/connedit.php
+++ b/mod/connedit.php
@@ -117,7 +117,7 @@ function connedit_post(&$a) {
if($rating > 10)
$rating = 10;
- $rating_text = escape_tags($_REQUEST['rating_text']);
+ $rating_text = trim(escape_tags($_REQUEST['rating_text']));
$abook_my_perms = 0;
@@ -131,26 +131,35 @@ function connedit_post(&$a) {
$new_friend = false;
if(! $is_self) {
- $z = q("select * from xlink where xlink_xchan = '%s' and xlink_xlink = '%s' and xlink_static = 1 limit 1",
+
+ $signed = $orig_record[0]['abook_xchan'] . '.' . $rating . '.' . $rating_text;
+
+ $sig = base64url_encode(rsa_sign($signed,$channel['channel_prvkey']));
+
+ $z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
dbesc($channel['channel_hash']),
dbesc($orig_record[0]['abook_xchan'])
);
+
+
if($z) {
$record = $z[0]['xlink_id'];
- $w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_updated = '%s'
+ $w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_sig = '%s', xlink_updated = '%s'
where xlink_id = %d",
intval($rating),
dbesc($rating_text),
+ dbesc($sig),
dbesc(datetime_convert()),
intval($record)
);
}
else {
- $w = q("insert into xlink ( xlink_xchan, xlink_link, xlink_rating, xlink_rating_text, xlink_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', 1 ) ",
+ $w = q("insert into xlink ( xlink_xchan, xlink_link, xlink_rating, xlink_rating_text, xlink_sig, xlink_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', '%s', 1 ) ",
dbesc($channel['channel_hash']),
dbesc($orig_record[0]['abook_xchan']),
intval($rating),
dbesc($rating_text),
+ dbesc($sig),
dbesc(datetime_convert())
);
$z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
@@ -161,7 +170,7 @@ function connedit_post(&$a) {
$record = $z[0]['xlink_id'];
}
if($record) {
- proc_run('php','include/notifier.php','rating',$record);
+ proc_run('php','include/ratenotif.php','rating',$record);
}
}
@@ -171,13 +180,11 @@ function connedit_post(&$a) {
}
- $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_rating = %d, abook_rating_text = '%s', abook_flags = %d
+ $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_flags = %d
where abook_id = %d AND abook_channel = %d",
dbesc($profile_id),
intval($abook_my_perms),
intval($closeness),
- intval($rating),
- dbesc($rating_text),
intval($abook_flags),
intval($contact_id),
intval(local_channel())
@@ -315,6 +322,7 @@ function connedit_content(&$a) {
return login();
}
+ $channel = $a->get_channel();
$my_perms = get_channel_default_perms(local_channel());
$role = get_pconfig(local_channel(),'system','permissions_role');
if($role) {
@@ -563,8 +571,22 @@ function connedit_content(&$a) {
));
}
+ $rating_val = 0;
+ $rating_text = '';
+
+ $xl = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1",
+ dbesc($channel['channel_hash']),
+ dbesc($contact['xchan_hash'])
+ );
+
+ if($xl) {
+ $rating_val = intval($xl[0]['xlink_rating']);
+ $rating_text = $xl[0]['xlink_rating_text'];
+ }
+
+
$poco_rating = get_config('system','poco_rating_enable');
- $poco_rating = 0;
+
// if unset default to enabled
if($poco_rating === false)
$poco_rating = true;
@@ -572,7 +594,7 @@ function connedit_content(&$a) {
if($poco_rating) {
$rating = replace_macros(get_markup_template('rating_slider.tpl'),array(
'$min' => -10,
- '$val' => (($contact['abook_rating']) ? $contact['abook_rating'] : 0),
+ '$val' => $rating_val
));
}
else {
@@ -612,11 +634,11 @@ function connedit_content(&$a) {
'$viewprof' => t('View Profile'),
'$clickme' => t('Click to open/close'),
'$lbl_slider' => t('Slide to adjust your degree of friendship'),
- '$lbl_rating' => t('Rating (this information may be public)'),
- '$lbl_rating_txt' => t('Optionally explain your rating (this information may be public)'),
- '$rating_txt' => $contact['abook_rating_text'],
+ '$lbl_rating' => t('Rating (this information is public)'),
+ '$lbl_rating_txt' => t('Optionally explain your rating (this information is public)'),
+ '$rating_txt' => $rating_text,
'$rating' => $rating,
- '$rating_val' => $contact['abook_rating'],
+ '$rating_val' => $rating_val,
'$slide' => $slide,
'$tabs' => $t,
'$tab_str' => $tab_str,
diff --git a/mod/directory.php b/mod/directory.php
index 21940d57b..329e255cf 100644
--- a/mod/directory.php
+++ b/mod/directory.php
@@ -190,6 +190,11 @@ function directory_content(&$a) {
$page_type = '';
+ if($rr['total_ratings'])
+ $total_ratings = sprintf( tt("%d rating", "%d ratings", $rr['total_ratings']), $rr['total_ratings']);
+ else
+ $total_ratings = '';
+
$profile = $rr;
if ((x($profile,'locale') == 1)
@@ -247,7 +252,7 @@ function directory_content(&$a) {
'public_forum' => $rr['public_forum'],
'photo' => $rr['photo'],
'hash' => $rr['hash'],
- 'alttext' => $rr['name'] . ' ' . $rr['address'],
+ 'alttext' => $rr['name'] . ((local_channel() || remote_channel()) ? ' ' . $rr['address'] : ''),
'name' => $rr['name'],
'details' => $pdesc . $details,
'profile' => $profile,
@@ -255,6 +260,9 @@ function directory_content(&$a) {
'nickname' => substr($rr['address'],0,strpos($rr['address'],'@')),
'location' => $location,
'gender' => $gender,
+ 'total_ratings' => $total_ratings,
+ 'viewrate' => true,
+ 'canrate' => ((local_channel()) ? true : false),
'pdesc' => $pdesc,
'marital' => $marital,
'homepage' => $homepage,
@@ -269,6 +277,7 @@ function directory_content(&$a) {
'keywords' => $out,
'ignlink' => $suggest ? $a->get_baseurl() . '/directory?ignore=' . $rr['hash'] : '',
'ignore_label' => "Don't suggest",
+ 'safe' => $safe_mode
);
$arr = array('contact' => $rr, 'entry' => $entry);
diff --git a/mod/dirsearch.php b/mod/dirsearch.php
index 52a3d02cf..5a0a7cee8 100644
--- a/mod/dirsearch.php
+++ b/mod/dirsearch.php
@@ -12,7 +12,6 @@ function dirsearch_content(&$a) {
$ret = array('success' => false);
- // If you've got a public directory server, you probably shouldn't block public access
$dirmode = intval(get_config('system','directory_mode'));
@@ -210,6 +209,24 @@ function dirsearch_content(&$a) {
);
}
}
+ $r = q("select * from xlink where xlink_static = 1 and xlink_updated >= '%s' ",
+ dbesc($sync)
+ );
+ if($r) {
+ $spkt['ratings'] = array();
+ foreach($r as $rr) {
+ $spkt['ratings'][] = array(
+ 'type' => 'rating',
+ 'encoding' => 'zot',
+ 'channel' => $rr['xlink_xchan'],
+ 'target' => $rr['xlink_link'],
+ 'rating' => intval($rr['xlink_rating']),
+ 'rating_text' => $rr['xlink_rating_text'],
+ 'signature' => $rr['xlink_sig'],
+ 'edited' => $rr['xlink_updated']
+ );
+ }
+ }
json_return_and_die($spkt);
}
else {
diff --git a/mod/prate.php b/mod/prate.php
index 28703d414..b89d16f42 100644
--- a/mod/prate.php
+++ b/mod/prate.php
@@ -1,13 +1,35 @@
<?php
+function prate_init(&$a) {
+ if($_SERVER['REQUEST_METHOD'] === 'post')
+ return;
+
+ if(! local_channel())
+ return;
+
+ $channel = $a->get_channel();
+
+ $target = argv(1);
+ if(! $target)
+ return;
+
+ $r = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1",
+ dbesc($channel['channel_hash']),
+ dbesc($target)
+ );
+ if($r)
+ json_return_and_die(array('rating' => $r[0]['xlink_rating'],'rating_text' => $r[0]['xlink_rating_text']));
+ killme();
+}
function prate_post(&$a) {
+
if(! local_channel())
return;
$channel = $a->get_channel();
- $target = $_REQUEST['target'];
+ $target = trim($_REQUEST['target']);
if(! $target)
return;
@@ -20,28 +42,35 @@ function prate_post(&$a) {
if($rating > 10)
$rating = 10;
- $rating_text = escape_tags($_REQUEST['rating_text']);
+ $rating_text = trim(escape_tags($_REQUEST['rating_text']));
+
+ $signed = $target . '.' . $rating . '.' . $rating_text;
+
+ $sig = base64url_encode(rsa_sign($signed,$channel['channel_prvkey']));
+
- $z = q("select * from xlink where xlink_xchan = '%s' and xlink_xlink = '%s' and xlink_static = 1 limit 1",
+ $z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
dbesc($channel['channel_hash']),
dbesc($target)
);
if($z) {
$record = $z[0]['xlink_id'];
- $w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_updated = '%s'
+ $w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_sig = '%s', xlink_updated = '%s'
where xlink_id = %d",
intval($rating),
dbesc($rating_text),
+ dbesc($sig),
dbesc(datetime_convert()),
intval($record)
);
}
else {
- $w = q("insert into xlink ( xlink_xchan, xlink_link, xlink_rating, xlink_rating_text, xlink_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', 1 ) ",
+ $w = q("insert into xlink ( xlink_xchan, xlink_link, xlink_rating, xlink_rating_text, xlink_sig, xlink_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', '%s', 1 ) ",
dbesc($channel['channel_hash']),
dbesc($target),
intval($rating),
dbesc($rating_text),
+ dbesc($sig),
dbesc(datetime_convert())
);
$z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
@@ -52,32 +81,10 @@ function prate_post(&$a) {
$record = $z[0]['xlink_id'];
}
if($record) {
- proc_run('php','include/notifier.php','rating',$record);
+ proc_run('php','include/ratenotif.php','rating',$record);
}
- $x = q("select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
- dbesc($target),
- intval($local_channel())
- );
- if($x) {
- $w = q("update abook set abook_rating = %d, abook_rating_text = '%s' where abook_xchan = '%s' and abook_channel = %d",
- intval($rating),
- dbesc($rating_text),
- dbesc($target),
- intval(local_channel())
- );
- $x = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
- dbesc($target),
- intval($local_channel())
- );
- if($x) {
- unset($x[0]['abook_id']);
- unset($x[0]['abook_account']);
- unset($x[0]['abook_channel']);
- build_sync_packet(0, array('abook' => array($x[0])));
- }
- }
- return;
+ json_return_and_die(array('result' => true));;
}
@@ -89,3 +96,4 @@ function prate_post(&$a) {
+
diff --git a/mod/prep.php b/mod/prep.php
deleted file mode 100644
index 896717826..000000000
--- a/mod/prep.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-
-
-function prep_init(&$a) {
-
- $poco_rating = get_config('system','poco_rating_enable');
- // if unset default to enabled
- if($poco_rating === false)
- $poco_rating = true;
-
- if(! $poco_rating)
- return;
-
- if(argc() > 1)
- $hash = argv(1);
-
- if(! $hash) {
- notice('Must supply a channel identififier.');
- return;
- }
-
- if(strpos($hash,'@')) {
- $r = q("select * from hubloc where hubloc_addr = '%s' limit 1",
- dbesc($hash)
- );
- if($r)
- $hash = $r[0]['hubloc_hash'];
- }
-
- $p = q("select * from xchan where xchan_hash like '%s'",
- dbesc($hash . '%')
- );
-
- if($p)
- $a->poi = $p[0];
-
-}
-
-
-
-
-
-function prep_content(&$a) {
-
-
- $poco_rating = get_config('system','poco_rating_enable');
- // if unset default to enabled
- if($poco_rating === false)
- $poco_rating = true;
-
- if(! $poco_rating)
- return;
-
- if(! $a->poi)
- return;
-
- $r = q("select * from xlink left join xchan on xlink_xchan = xchan_hash where xlink_link like '%s' and xlink_rating != 0",
- dbesc($a->poi['xchan_hash'])
- );
-
- if(! $r)
- notice( t('No ratings available') . EOL);
-
-
- $o = replace_macros(get_markup_template('prep.tpl'),array(
- '$header' => t('Ratings'),
- '$rating_lbl' => t('Rating: ' ),
- '$rating_text_lbl' => t('Description: '),
- '$raters' => $r
- ));
-
- return $o;
-}
-
- \ No newline at end of file
diff --git a/mod/rate.php b/mod/rate.php
new file mode 100644
index 000000000..694b88ddd
--- /dev/null
+++ b/mod/rate.php
@@ -0,0 +1,158 @@
+<?php
+
+
+function rate_init(&$a) {
+
+ if(! local_channel())
+ return;
+
+ $channel = $a->get_channel();
+
+ $target = $_REQUEST['target'];
+ if(! $target)
+ return;
+
+ $a->data['target'] = $target;
+
+ if($target) {
+ $r = q("SELECT * FROM xchan where xchan_hash like '%s' LIMIT 1",
+ dbesc($target)
+ );
+ if($r) {
+ $a->poi = $r[0];
+ }
+ }
+
+
+ return;
+
+}
+
+
+function rate_post(&$a) {
+
+ if(! local_channel())
+ return;
+
+ if(! $a->data['target'])
+ return;
+
+ if(! $_REQUEST['execute'])
+ return;
+
+ $channel = $a->get_channel();
+
+ $rating = intval($_POST['rating']);
+ if($rating < (-10))
+ $rating = (-10);
+ if($rating > 10)
+ $rating = 10;
+
+ $rating_text = trim(escape_tags($_REQUEST['rating_text']));
+
+ $signed = $a->data['target'] . '.' . $rating . '.' . $rating_text;
+
+ $sig = base64url_encode(rsa_sign($signed,$channel['channel_prvkey']));
+
+ $z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
+ dbesc($channel['channel_hash']),
+ dbesc($a->data['target'])
+ );
+
+ if($z) {
+ $record = $z[0]['xlink_id'];
+ $w = q("update xlink set xlink_rating = '%d', xlink_rating_text = '%s', xlink_sig = '%s', xlink_updated = '%s'
+ where xlink_id = %d",
+ intval($rating),
+ dbesc($rating_text),
+ dbesc($sig),
+ dbesc(datetime_convert()),
+ intval($record)
+ );
+ }
+ else {
+ $w = q("insert into xlink ( xlink_xchan, xlink_link, xlink_rating, xlink_rating_text, xlink_sig, xlink_updated, xlink_static ) values ( '%s', '%s', %d, '%s', '%s', '%s', 1 ) ",
+ dbesc($channel['channel_hash']),
+ dbesc($a->data['target']),
+ intval($rating),
+ dbesc($rating_text),
+ dbesc($sig),
+ dbesc(datetime_convert())
+ );
+ $z = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1 limit 1",
+ dbesc($channel['channel_hash']),
+ dbesc($a->data['target'])
+ );
+ if($z)
+ $record = $z[0]['xlink_id'];
+ }
+
+ if($record) {
+ proc_run('php','include/ratenotif.php','rating',$record);
+ }
+
+}
+
+
+
+function rate_content(&$a) {
+
+ if(! local_channel()) {
+ notice( t('Permission denied.') . EOL);
+ return;
+ }
+
+// if(! $a->data['target']) {
+// notice( t('No recipients.') . EOL);
+// return;
+// }
+
+ $poco_rating = get_config('system','poco_rating_enable');
+ if((! $poco_rating) && ($poco_rating !== false)) {
+ notice('Ratings are disabled on this site.');
+ return;
+ }
+
+ $channel = $a->get_channel();
+
+ $r = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 1",
+ dbesc($channel['channel_hash']),
+ dbesc($a->data['target'])
+ );
+ if($r)
+ $a->data['xlink'] = $r[0];
+
+ $rating_val = $r[0]['xlink_rating'];
+ $rating_text = $r[0]['xlink_rating_text'];
+
+
+ // if unset default to enabled
+ if($poco_rating === false)
+ $poco_rating = true;
+
+ if($poco_rating) {
+ $rating = replace_macros(get_markup_template('rating_slider.tpl'),array(
+ '$min' => -10,
+ '$val' => $rating_val
+ ));
+ }
+ else {
+ $rating = false;
+ }
+
+ $o = replace_macros(get_markup_template('rating_form.tpl'),array(
+ '$header' => t('Rating'),
+ 'target' => $a->data['target'],
+ '$tgt_name' => (($a->poi && $a->poi['xchan_name']) ? $a->poi['xchan_name'] : sprintf( t('Remote Channel [%s] (not yet known on this site)'), substr($a->data['target'],0,16))),
+ '$lbl_rating' => t('Rating (this information is public)'),
+ '$lbl_rating_txt' => t('Optionally explain your rating (this information is public)'),
+ '$rating_txt' => $rating_text,
+ '$rating' => $rating,
+ '$rating_val' => $rating_val,
+ '$slide' => $slide,
+ '$submit' => t('Submit')
+ ));
+
+ return $o;
+
+} \ No newline at end of file
diff --git a/mod/ratings.php b/mod/ratings.php
new file mode 100644
index 000000000..fe7865778
--- /dev/null
+++ b/mod/ratings.php
@@ -0,0 +1,103 @@
+<?php
+
+require_once('include/dir_fns.php');
+
+function ratings_init(&$a) {
+
+ if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
+ return;
+ }
+
+ if(local_channel())
+ load_contact_links(local_channel());
+
+ $dirmode = intval(get_config('system','directory_mode'));
+
+ $x = find_upstream_directory($dirmode);
+ if($x)
+ $url = $x['url'];
+
+ $poco_rating = get_config('system','poco_rating_enable');
+ // if unset default to enabled
+ if($poco_rating === false)
+ $poco_rating = true;
+
+ if(! $poco_rating)
+ return;
+
+ if(argc() > 1)
+ $hash = argv(1);
+
+ if(! $hash) {
+ notice('Must supply a channel identififier.');
+ return;
+ }
+
+ $results = false;
+
+ $x = z_fetch_url($url . '/ratingsearch/' . $hash);
+
+
+ if($x['success'])
+ $results = json_decode($x['body'],true);
+
+
+ if((! $results) || (! $results['success'])) {
+
+ notice('No results.');
+ return;
+ }
+
+ $a->poi = $results['target'];
+
+ $friends = array();
+ $others = array();
+
+ if($results['ratings']) {
+ foreach($results['ratings'] as $n) {
+ if(is_array($a->contacts) && array_key_exists($n['xchan_hash'],$a->contacts))
+ $friends[] = $n;
+ else
+ $others[] = $n;
+ }
+ }
+
+ $a->data = array_merge($friends,$others);
+
+ if(! $a->data) {
+ notice( t('No ratings') . EOL);
+ }
+
+ return;
+}
+
+
+
+
+
+function ratings_content(&$a) {
+
+ if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
+ notice( t('Public access denied.') . EOL);
+ return;
+ }
+
+ $poco_rating = get_config('system','poco_rating_enable');
+ // if unset default to enabled
+ if($poco_rating === false)
+ $poco_rating = true;
+
+ if(! $poco_rating)
+ return;
+
+ $o = replace_macros(get_markup_template('prep.tpl'),array(
+ '$header' => t('Ratings'),
+ '$rating_lbl' => t('Rating: ' ),
+ '$rating_text_lbl' => t('Description: '),
+ '$raters' => $a->data
+ ));
+
+ return $o;
+}
+
+ \ No newline at end of file
diff --git a/mod/ratingsearch.php b/mod/ratingsearch.php
new file mode 100644
index 000000000..ec2db570b
--- /dev/null
+++ b/mod/ratingsearch.php
@@ -0,0 +1,58 @@
+<?php
+
+
+function ratingsearch_init(&$a) {
+
+ $ret = array('success' => false);
+
+ $dirmode = intval(get_config('system','directory_mode'));
+
+ if($dirmode == DIRECTORY_MODE_NORMAL) {
+ $ret['message'] = 'This site is not a directory server.';
+ json_return_and_die($ret);
+ }
+
+ if(argc() > 1)
+ $hash = argv(1);
+
+ if(! $hash) {
+ $ret['message'] = 'No channel identifier';
+ json_return_and_die($ret);
+ }
+
+ if(strpos($hash,'@')) {
+ $r = q("select * from hubloc where hubloc_addr = '%s' limit 1",
+ dbesc($hash)
+ );
+ if($r)
+ $hash = $r[0]['hubloc_hash'];
+ }
+
+ $p = q("select * from xchan where xchan_hash like '%s'",
+ dbesc($hash . '%')
+ );
+
+ if($p)
+ $ret['target'] = $p[0];
+ else {
+ $ret['message'] = 'channel not found';
+ json_return_and_die($ret);
+ }
+
+ $ret['success'] = true;
+
+ $r = q("select * from xlink left join xchan on xlink_xchan = xchan_hash
+ where xlink_link = '%s' and xlink_rating != 0 and xlink_static = 1 order by xchan_name asc",
+ dbesc($p[0]['xchan_hash'])
+ );
+
+ if($r) {
+ $ret['ratings'] = $r;
+ }
+ else
+ $ret['ratings'] = array();
+
+ json_return_and_die($ret);
+
+}
+
diff --git a/mod/regdir.php b/mod/regdir.php
new file mode 100644
index 000000000..eecc99ca5
--- /dev/null
+++ b/mod/regdir.php
@@ -0,0 +1,69 @@
+<?php
+
+
+function regdir_init(&$a) {
+
+ $result = array('success' => false);
+
+ $url = $_REQUEST['url'];
+
+
+ // we probably don't need the realm as we will find out in the probe.
+ // What we may want to die is throw an error if you're trying to register in a different realm
+ // so this configuration issue can be discovered.
+
+ $realm = $_REQUEST['realm'];
+ if(! $realm)
+ $realm = DIRECTORY_REALM;
+
+ $dirmode = intval(get_config('system','directory_mode'));
+
+ if($dirmode == DIRECTORY_MODE_NORMAL) {
+ $ret['message'] = t('This site is not a directory server');
+ json_return_and_die($ret);
+ }
+
+ $m = null;
+ if($url) {
+ $m = parse_url($url);
+
+ if((! $m) || (! @dns_get_record($m['host'], DNS_A + DNS_CNAME + DNS_PTR)) || (! filter_var($m['host'], FILTER_VALIDATE_IP) )) {
+ $result['message'] = 'unparseable url';
+ json_return_and_die($result);
+ }
+
+ $f = zot_finger('sys@' . $m['host']);
+ if($f['success']) {
+ $j = json_decode($f['body'],true);
+ if($j['success'] && $j['guid']) {
+ $x = import_xchan($j);
+ if($x['success']) {
+ $result['success'] = true;
+ json_return_and_die($result);
+ }
+ }
+ }
+
+ json_return_and_die($result);
+ }
+ else {
+ if($dirmode == DIRECTORY_MODE_STANDALONE) {
+ $r = array(array('site_url' => z_root()));
+ }
+ else {
+ $r = q("select site_url from site where site_flags in ( 1, 2 ) and site_realm = '%s'",
+ dbesc(get_directory_realm())
+ );
+ }
+ if($r) {
+ $result['success'] = true;
+ $result['directories'] = array();
+ foreach($r as $rr)
+ $result['directories'][] = $rr['site_url'];
+ json_return_and_die($result);
+ }
+ }
+ json_return_and_die($result);
+
+
+} \ No newline at end of file
diff --git a/mod/zfinger.php b/mod/zfinger.php
index 6f4febc6f..f4b7efd96 100644
--- a/mod/zfinger.php
+++ b/mod/zfinger.php
@@ -99,13 +99,14 @@ function zfinger_init(&$a) {
$id = $e['channel_id'];
+ $sys_channel = (($e['channel_pageflags'] & PAGE_SYSTEM) ? true : false);
$special_channel = (($e['channel_pageflags'] & PAGE_PREMIUM) ? true : false);
$adult_channel = (($e['channel_pageflags'] & PAGE_ADULT) ? true : false);
$censored = (($e['channel_pageflags'] & PAGE_CENSORED) ? true : false);
$searchable = (($e['channel_pageflags'] & PAGE_HIDDEN) ? false : true);
$deleted = (($e['xchan_flags'] & XCHAN_FLAGS_DELETED) ? true : false);
- if($deleted || $censored)
+ if($deleted || $censored || $sys_channel)
$searchable = false;
$public_forum = false;
@@ -237,6 +238,12 @@ function zfinger_init(&$a) {
$dirmode = get_config('system','directory_mode');
if(($dirmode === false) || ($dirmode == DIRECTORY_MODE_NORMAL))
$ret['site']['directory_mode'] = 'normal';
+
+ // downgrade mis-configured primaries
+
+ if($dirmode == DIRECTORY_MODE_PRIMARY && z_root() != get_directory_primary())
+ $dirmode = DIRECTORY_MODE_SECONDARY;
+
if($dirmode == DIRECTORY_MODE_PRIMARY)
$ret['site']['directory_mode'] = 'primary';
elseif($dirmode == DIRECTORY_MODE_SECONDARY)