use \Friendica\Core\Config;
- require_once("boot.php");
- require_once("include/socgraph.php");
+ require_once('include/socgraph.php');
+ require_once('include/datetime.php');
function discover_poco_run(&$argv, &$argc){
- global $a, $db;
-
- if(is_null($a)) {
- $a = new App;
- }
-
- if(is_null($db)) {
- @include(".htconfig.php");
- require_once("include/dba.php");
- $db = new dba($db_host, $db_user, $db_pass, $db_data);
- unset($db_host, $db_user, $db_pass, $db_data);
- };
-
- require_once('include/session.php');
- require_once('include/datetime.php');
-
- Config::load();
-
- // Don't check this stuff if the function is called by the poller
- if (App::callstack() != "poller_run")
- if ($a->maxload_reached())
- return;
- if(($argc > 2) && ($argv[1] == "dirsearch")) {
+ /*
+ This function can be called in these ways:
+ - dirsearch <search pattern>: Searches for "search pattern" in the directory. "search pattern" is url encoded.
+ - checkcontact: Updates gcontact entries
+ - suggestions: Discover other servers for their contacts.
+ - server <poco url>: Searches for the poco server list. "poco url" is base64 encoded.
+ - update_server: Frequently check the first 250 servers for vitality.
+ */
+
+ if (($argc > 2) && ($argv[1] == "dirsearch")) {
$search = urldecode($argv[2]);
$mode = 1;
} elseif(($argc == 2) && ($argv[1] == "checkcontact")) {
} 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")
- if (App::is_already_running('discover_poco'.$mode.urlencode($search), 'include/discover_poco.php', 1140))
- return;
-
- $a->set_baseurl(get_config('system','url'));
-
- load_hooks();
-
logger('start '.$search);
- if ($mode==3)
+ if ($mode == 5) {
+ update_server();
+ } elseif ($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)) {