1
0
Fork 0

Discovery of new servers

This commit is contained in:
Michael 2017-03-12 09:13:04 +00:00
parent 32f1b2de20
commit 3a3fa017a6
2 changed files with 57 additions and 6 deletions

View file

@ -36,11 +36,14 @@ function discover_poco_run(&$argv, &$argc){
$mode = 2;
} elseif(($argc == 2) && ($argv[1] == "suggestions")) {
$mode = 3;
} elseif(($argc == 3) && ($argv[1] == "server")) {
$mode = 4;
} elseif ($argc == 1) {
$search = "";
$mode = 0;
} else
} else {
die("Unknown or missing parameter ".$argv[1]."\n");
}
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run")
@ -53,11 +56,28 @@ function discover_poco_run(&$argv, &$argc){
logger('start '.$search);
if ($mode==3)
if ($mode == 4) {
$server_url = base64_decode($argv[2]);
if ($server_url == "") {
return;
}
$server_url = filter_var($server_url, FILTER_SANITIZE_URL);
if (substr(normalise_link($server_url), 0, 7) != "http://") {
return;
}
$result = "Checking server ".$server_url." - ";
$ret = poco_check_server($server_url);
if ($ret) {
$result .= "success";
} else {
$result .= "failed";
}
logger($result, LOGGER_DEBUG);
} elseif ($mode == 3) {
update_suggestions();
elseif (($mode == 2) AND get_config('system','poco_completion'))
} elseif (($mode == 2) AND get_config('system','poco_completion')) {
discover_users();
elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) {
} elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) {
discover_directory($search);
gs_search_user($search);
} elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0)) {

View file

@ -1441,6 +1441,33 @@ function update_suggestions() {
}
}
/**
* @brief Fetch server list from remote servers and adds them when they are new.
*
* @param string $poco URL to the POCO endpoint
*/
function poco_fetch_serverlist($poco) {
$serverret = z_fetch_url($poco."/@server");
if (!$serverret["success"]) {
return;
}
$serverlist = json_decode($serverret['body']);
if (!is_array($serverlist)) {
return;
}
foreach ($serverlist AS $server) {
$server_url = str_replace("/index.php", "", $server->url);
$r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
if (!dbm::is_result($r)) {
logger("Call server check for server ".$server_url, LOGGER_DEBUG);
proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server_url));
}
}
}
function poco_discover_federation() {
$last = get_config('poco','last_federation_discovery');
@ -1456,8 +1483,9 @@ function poco_discover_federation() {
if ($serverdata) {
$servers = json_decode($serverdata);
foreach($servers->pods AS $server)
poco_check_server("https://".$server->host);
foreach ($servers->pods AS $server) {
proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode("https://".$server->host));
}
}
// Currently disabled, since the service isn't available anymore.
@ -1502,6 +1530,9 @@ function poco_discover($complete = false) {
continue;
}
// Discover new servers out there
poco_fetch_serverlist($server["poco"]);
// Fetch all users from the other server
$url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";