From b1a92d620ebf760a3cfd83f6fb62990494d3ad60 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 1 Feb 2015 15:10:52 -0800 Subject: two tracks proceeding in parallel - first adding the ability to store a digital signature with ratings so that directories can pass them around, second provide some directory registration functions so we can obtain a list of directories from somewhere (to pass ratings around between them). This gives the primary directory role some value as that is where you register your directory. --- boot.php | 15 ++++++++++- include/poller.php | 4 +++ install/schema_mysql.sql | 1 + install/schema_postgres.sql | 1 + install/update.php | 9 ++++++- mod/regdir.php | 64 +++++++++++++++++++++++++++++++++++++++++++++ mod/zfinger.php | 9 ++++++- version.inc | 2 +- 8 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 mod/regdir.php diff --git a/boot.php b/boot.php index 96dee2c46..2f8d1c08f 100755 --- a/boot.php +++ b/boot.php @@ -49,7 +49,7 @@ define ( 'RED_PLATFORM', 'redmatrix' ); define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'ZOT_REVISION', 1 ); -define ( 'DB_UPDATE_VERSION', 1135 ); +define ( 'DB_UPDATE_VERSION', 1136 ); /** * Constant with a HTML line break. @@ -2194,6 +2194,19 @@ function get_directory_realm() { return DIRECTORY_REALM; } +/** + * @brief Return the primary directory server. + * + * @return string + */ +function get_directory_primary() { + if($x = get_config('system', 'directory_primary')) + return $x; + + return DIRECTORY_FALLBACK_MASTER; +} + + /** * @brief return relative date of last completed poller execution diff --git a/include/poller.php b/include/poller.php index dc310fe16..fd78ce087 100644 --- a/include/poller.php +++ b/include/poller.php @@ -164,6 +164,10 @@ function poller_run($argv, $argc){ db_utcnow(), db_quoteinterval('14 DAY') ); + $dirmode = intval(get_config('system','directory_mode')); + if($dirmode == DIRECTORY_MODE_SECONDARY) { + logger('regdir: ' . print_r(z_fetch_url(get_directory_primary() . '/regdir?f=&url=' . z_root() . '&realm=' . get_directory_realm()),true)); + } /** * End Cron Weekly diff --git a/install/schema_mysql.sql b/install/schema_mysql.sql index ba41073f8..8addc0af9 100644 --- a/install/schema_mysql.sql +++ b/install/schema_mysql.sql @@ -1533,6 +1533,7 @@ CREATE TABLE IF NOT EXISTS `xlink` ( `xlink_rating_text` TEXT NOT NULL DEFAULT '', `xlink_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `xlink_static` tinyint(1) NOT NULL DEFAULT '0', + `xlink_sig` text NOT NULL DEFAULT '', PRIMARY KEY (`xlink_id`), KEY `xlink_xchan` (`xlink_xchan`), KEY `xlink_link` (`xlink_link`), diff --git a/install/schema_postgres.sql b/install/schema_postgres.sql index 2fcc7f9ba..b68a7cb97 100644 --- a/install/schema_postgres.sql +++ b/install/schema_postgres.sql @@ -1146,6 +1146,7 @@ CREATE TABLE "xlink" ( "xlink_rating_text" TEXT NOT NULL DEFAULT '', "xlink_updated" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00', "xlink_static" numeric(1) NOT NULL DEFAULT '0', + "xlink_sig" text NOT NULL DEFAULT '', PRIMARY KEY ("xlink_id") ); create index "xlink_xchan" on xlink ("xlink_xchan"); diff --git a/install/update.php b/install/update.php index 597da4e3b..4cd1ced5d 100644 --- a/install/update.php +++ b/install/update.php @@ -1,6 +1,6 @@ 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 { + $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) diff --git a/version.inc b/version.inc index 7386960a0..b7a74f141 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2015-01-31.933 +2015-02-01.934 -- cgit v1.2.3