Merge branch '1702-detect-server' of github.com:annando/friendica into 1702-detect-server

This commit is contained in:
Michael 2017-02-26 23:13:42 +00:00
commit 20e07fa0ed
7 changed files with 99 additions and 18 deletions

View file

@ -40,6 +40,7 @@ Version 3.5.1
When creating new postings in the UI, focus is automatically put into the Title field [Hypolite]
We are now shipping config files for "tx" (the Transifex client) and the "EditorConfig" addon for many common editors [fabrixxm, tobiasd]
The TinyMCE richtext editor was removed [Hypolite]
We defined a coding style, PSR-2 with some adjustments
Various bugfixes
Friendica Addons:
@ -58,11 +59,12 @@ Version 3.5.1
Twitter-bridge now supports quotes and long posts when importing tweets [heluecht]
Closed Issues
1019, 1163, 1612, 1613, 2177, 2252, 2260, 2403, 2991, 2614, 2751,
2752, 2772, 2791, 2800, 2804, 2813, 2814, 2816, 2817, 2823, 2850,
2858, 2865, 2892, 2894, 2895, 2907, 2908, 2914, 2015, 2926, 2948,
2955, 2958, 2963, 2964, 2968, 2987, 2993, 3020, 3052, 3062, 3066,
3091, 3108, 3116, 3117, 3118, 3126, 3130, 3135, 3155, 3163
1019, 1163, 1612, 1613, 2103, 2177, 2252, 2260, 2403, 2991, 2614,
2751, 2752, 2772, 2791, 2800, 2804, 2813, 2814, 2816, 2817, 2823,
2850, 2858, 2865, 2892, 2894, 2895, 2907, 2908, 2914, 2015, 2926,
2948, 2955, 2958, 2963, 2964, 2968, 2987, 2993, 3020, 3052, 3062,
3066, 3091, 3108, 3113, 3116, 3117, 3118, 3126, 3130, 3135, 3155,
3163
Version 3.5 (2016-09-13)
Friendica Core:

View file

@ -146,7 +146,9 @@ class ParseUrl {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, (($check_cert) ? 2 : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$header = curl_exec($ch);
$curl_info = @curl_getinfo($ch);

View file

@ -242,7 +242,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if (!isset($database[$name]["fields"][$fieldname])) {
$sql2=db_add_table_field($fieldname, $parameters);
if ($sql3 == "") {
$sql3 = "ALTER TABLE `".$temp_name."` ".$sql2;
$sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
} else {
$sql3 .= ", ".$sql2;
}
@ -253,7 +253,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if ($current_field_definition != $new_field_definition) {
$sql2=db_modify_table_field($fieldname, $parameters);
if ($sql3 == "") {
$sql3 = "ALTER TABLE `".$temp_name."` ".$sql2;
$sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
} else {
$sql3 .= ", ".$sql2;
}

View file

@ -118,7 +118,9 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
$check_cert = get_config('system','verifyssl');
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, (($check_cert) ? 2 : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$prx = get_config('system','proxy');
if(strlen($prx)) {
@ -265,7 +267,9 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
$check_cert = get_config('system','verifyssl');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, (($check_cert) ? 2 : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$prx = get_config('system','proxy');
if(strlen($prx)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);

View file

@ -11,7 +11,6 @@ if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
}
use \Friendica\Core\Config;
use \Friendica\Core\PConfig;
require_once("boot.php");
@ -29,6 +28,8 @@ function poller_run($argv, $argc){
unset($db_host, $db_user, $db_pass, $db_data);
};
Config::load();
// Quit when in maintenance
if (Config::get('system', 'maintenance', true)) {
return;

View file

@ -680,6 +680,43 @@ function poco_to_boolean($val) {
return ($val);
}
function poco_detect_friendica_server($body) {
$server = false;
$doc = new \DOMDocument();
@$doc->loadHTML($body);
$xpath = new \DomXPath($doc);
$list = $xpath->query("//meta[@name]");
foreach ($list as $node) {
$attr = array();
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
$attr[$attribute->name] = $attribute->value;
}
}
if ($attr['name'] == 'generator') {
$version_part = explode(" ", $attr['content']);
if (count($version_part) == 2) {
if (in_array($version_part[0], array("Friendika", "Friendica"))) {
$server = array();
$server["platform"] = $version_part[0];
$server["version"] = $version_part[1];
$server["network"] = NETWORK_DFRN;
}
}
}
}
if (!$server) {
return false;
}
$server["site_name"] = $xpath->evaluate($element."//head/title/text()", $context)->item(0)->nodeValue;
return $server;
}
function poco_check_server($server_url, $network = "", $force = false) {
// Unify the server address
@ -729,7 +766,9 @@ function poco_check_server($server_url, $network = "", $force = false) {
logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$servers[0]["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
$failure = false;
$possible_failure = false;
$orig_last_failure = $last_failure;
$orig_last_contact = $last_contact;
// Check if the page is accessible via SSL.
$server_url = str_replace("http://", "https://", $server_url);
@ -750,6 +789,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
$last_failure = datetime_convert();
$failure = true;
}
$possible_failure = true;
} elseif ($network == NETWORK_DIASPORA)
$last_contact = datetime_convert();
@ -757,11 +797,12 @@ function poco_check_server($server_url, $network = "", $force = false) {
// Test for Diaspora
$serverret = z_fetch_url($server_url);
if (!$serverret["success"] OR ($serverret["body"] == ""))
if (!$serverret["success"] OR ($serverret["body"] == "")) {
$last_failure = datetime_convert();
$failure = true;
else {
} else {
$lines = explode("\n",$serverret["header"]);
if(count($lines))
if(count($lines)) {
foreach($lines as $line) {
$line = trim($line);
if(stristr($line,'X-Diaspora-Version:')) {
@ -771,6 +812,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
$network = NETWORK_DIASPORA;
$versionparts = explode("-", $version);
$version = $versionparts[0];
$last_contact = datetime_convert();
}
if(stristr($line,'Server: Mastodon')) {
@ -778,8 +820,19 @@ function poco_check_server($server_url, $network = "", $force = false) {
$network = NETWORK_OSTATUS;
// Mastodon doesn't reveal version numbers
$version = "";
$last_contact = datetime_convert();
}
}
}
$friendica_server = poco_detect_friendica_server($serverret["body"]);
if ($friendica_server) {
$platform = $friendica_server['platform'];
$network = $friendica_server['network'];
$version = $friendica_server['version'];
$site_name = $friendica_server['site_name'];
$last_contact = datetime_convert();
}
}
}
@ -793,6 +846,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
$platform = "StatusNet";
$version = trim($serverret["body"], '"');
$network = NETWORK_OSTATUS;
$last_contact = datetime_convert();
}
// Test for GNU Social
@ -802,12 +856,12 @@ function poco_check_server($server_url, $network = "", $force = false) {
$platform = "GNU Social";
$version = trim($serverret["body"], '"');
$network = NETWORK_OSTATUS;
$last_contact = datetime_convert();
}
$serverret = z_fetch_url($server_url."/api/statusnet/config.json");
if ($serverret["success"]) {
$data = json_decode($serverret["body"]);
if (isset($data->site->server)) {
$last_contact = datetime_convert();
@ -847,6 +901,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
}
}
// Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix
if (!$failure) {
$serverret = z_fetch_url($server_url."/statistics.json");
@ -922,6 +977,23 @@ function poco_check_server($server_url, $network = "", $force = false) {
}
}
if ($possible_failure AND !$failure) {
$last_failure = datetime_convert();
$failure = true;
}
if ($failure) {
$last_contact = $orig_last_contact;
} else {
$last_failure = $orig_last_failure;
}
if (($last_contact <= $last_failure) AND !$failure) {
logger("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG);
} else if (($last_contact >= $last_failure) AND $failure) {
logger("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG);
}
// Check again if the server exists
$servers = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));

View file

@ -270,8 +270,8 @@ function admin_page_federation(App $a) {
// off one % two of them are needed in the query
// Add more platforms if you like, when one returns 0 known nodes it is not
// displayed on the stats page.
$platforms = array('Friendica', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon');
$colors = array('Friendica' => '#ffc018', // orange from the logo
$platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon');
$colors = array('Friendi%%a' => '#ffc018', // orange from the logo
'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
'%%red%%' => '#c50001', // fire red from the logo
'Hubzilla' => '#43488a', // blue from the logo
@ -333,7 +333,7 @@ function admin_page_federation(App $a) {
// early friendica versions have the format x.x.xxxx where xxxx is the
// DB version stamp; those should be operated out and versions be
// conbined
if($p=='Friendica') {
if($p=='Friendi%%a') {
$newV = array();
$newVv = array();
foreach ($v as $vv) {