aboutsummaryrefslogtreecommitdiffstats
path: root/mod/regdir.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2015-04-23 19:49:41 -0700
committerfriendica <info@friendica.com>2015-04-23 19:49:41 -0700
commit6679734135fb04f4a7beccb81663bf1e9574f062 (patch)
tree887488543d98b5dd297d917718bdd99844e83ba5 /mod/regdir.php
parent08b757a22cd2804bfec8ecf682b6987b8c06ca49 (diff)
parentc696860cc53bc25558d83de5eda65d9b583da382 (diff)
downloadvolse-hubzilla-6679734135fb04f4a7beccb81663bf1e9574f062.tar.gz
volse-hubzilla-6679734135fb04f4a7beccb81663bf1e9574f062.tar.bz2
volse-hubzilla-6679734135fb04f4a7beccb81663bf1e9574f062.zip
Merge branch 'master' into tres
Conflicts: include/Contact.php include/ItemObject.php include/api.php include/attach.php include/diaspora.php include/dir_fns.php include/enotify.php include/event.php include/expire.php include/items.php include/notifier.php include/notify.php include/photos.php include/taxonomy.php include/text.php include/widgets.php include/zot.php mod/admin.php mod/channel.php mod/dirsearch.php mod/display.php mod/editwebpage.php mod/events.php mod/home.php mod/item.php mod/manage.php mod/mood.php mod/network.php mod/page.php mod/photos.php mod/ping.php mod/post.php mod/thing.php mod/viewsrc.php view/css/mod_events.css
Diffstat (limited to 'mod/regdir.php')
-rw-r--r--mod/regdir.php70
1 files changed, 52 insertions, 18 deletions
diff --git a/mod/regdir.php b/mod/regdir.php
index eecc99ca5..dce50e76a 100644
--- a/mod/regdir.php
+++ b/mod/regdir.php
@@ -1,12 +1,24 @@
<?php
-
+/**
+ * With args, register a directory server for this realm.
+ * With no args, return a JSON array of directory servers for this realm.
+ *
+ * @FIXME Not yet implemented: Some realms may require authentication to join their realm.
+ * The RED_GLOBAL realm does not require authentication.
+ * We would then need a flag in the site table to indicate that they've been
+ * validated by the PRIMARY directory for that realm. Sites claiming to be PRIMARY
+ * but are not the realm PRIMARY will be marked invalid.
+ *
+ * @param App &$a
+ */
function regdir_init(&$a) {
$result = array('success' => false);
$url = $_REQUEST['url'];
-
+ $access_token = $_REQUEST['t'];
+ $valid = 0;
// 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
@@ -16,54 +28,76 @@ function regdir_init(&$a) {
if(! $realm)
$realm = DIRECTORY_REALM;
+ if($realm === DIRECTORY_REALM) {
+ $valid = 1;
+ } else {
+ $token = get_config('system','realm_token');
+ if($token && $access_token != $token) {
+ $result['message'] = 'This realm requires an access token';
+ return;
+ }
+ $valid = 1;
+ }
+
$dirmode = intval(get_config('system','directory_mode'));
- if($dirmode == DIRECTORY_MODE_NORMAL) {
+ if ($dirmode == DIRECTORY_MODE_NORMAL) {
$ret['message'] = t('This site is not a directory server');
json_return_and_die($ret);
}
$m = null;
- if($url) {
+ 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) )) {
+ 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']);
+ $f = zot_finger('[system]@' . $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);
}
}
}
+ if(! $result['success'])
+ $valid = 0;
+
+ q("update site set site_valid = %d where site_url = '%s' limit 1",
+ intval($valid),
+ strtolower($url)
+ );
+
json_return_and_die($result);
- }
- else {
- if($dirmode == DIRECTORY_MODE_STANDALONE) {
+ } else {
+
+ // We can put this in the sql without the condition after 31 august 2015 assuming
+ // most directory servers will have updated by then
+ // This just makes sure it happens if I forget
+
+ $sql_extra = ((datetime_convert() > datetime_convert('UTC','UTC','2015-08-31')) ? ' and site_valid = 1 ' : '' );
+ 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'",
+ } else {
+ $r = q("select site_url from site where site_flags in ( 1, 2 ) and site_realm = '%s' $sql_extra ",
dbesc(get_directory_realm())
);
}
- if($r) {
+ if ($r) {
$result['success'] = true;
$result['directories'] = array();
- foreach($r as $rr)
+ 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
+} \ No newline at end of file