$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")
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)) {
}
}
+/**
+ * @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');
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.
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";