Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.0KB

  1. <?php
  2. require_once("boot.php");
  3. require_once('include/Scrape.php');
  4. require_once('include/socgraph.php');
  5. function gprobe_run(&$argv, &$argc){
  6. global $a, $db;
  7. if(is_null($a)) {
  8. $a = new App;
  9. }
  10. if(is_null($db)) {
  11. @include(".htconfig.php");
  12. require_once("include/dba.php");
  13. $db = new dba($db_host, $db_user, $db_pass, $db_data);
  14. unset($db_host, $db_user, $db_pass, $db_data);
  15. };
  16. require_once('include/session.php');
  17. require_once('include/datetime.php');
  18. load_config('config');
  19. load_config('system');
  20. $a->set_baseurl(get_config('system','url'));
  21. load_hooks();
  22. if($argc != 2)
  23. return;
  24. $url = hex2bin($argv[1]);
  25. $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
  26. dbesc(normalise_link($url))
  27. );
  28. logger("gprobe start for ".normalise_link($url), LOGGER_DEBUG);
  29. if (!count($r)) {
  30. // Is it a DDoS attempt?
  31. $urlparts = parse_url($url);
  32. $result = Cache::get("gprobe:".$urlparts["host"]);
  33. if (!is_null($result)) {
  34. $result = unserialize($result);
  35. if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
  36. logger("DDoS attempt detected for ".$urlparts["host"]." by ".$_SERVER["REMOTE_ADDR"].". server data: ".print_r($_SERVER, true), LOGGER_DEBUG);
  37. return;
  38. }
  39. }
  40. $arr = probe_url($url);
  41. if (is_null($result))
  42. Cache::set("gprobe:".$urlparts["host"],serialize($arr));
  43. if (!in_array($arr["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))
  44. update_gcontact($arr);
  45. $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
  46. dbesc(normalise_link($url))
  47. );
  48. }
  49. if(count($r)) {
  50. // Check for accessibility and do a poco discovery
  51. if (poco_last_updated($r[0]['url'], true) AND ($r[0]["network"] == NETWORK_DFRN))
  52. poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
  53. }
  54. logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
  55. return;
  56. }
  57. if (array_search(__file__,get_included_files())===0){
  58. gprobe_run($_SERVER["argv"],$_SERVER["argc"]);
  59. killme();
  60. }