From 3f27c8bb0ac4aa92783c1c21136fd78c6dfd098e Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 24 Feb 2017 19:41:07 +0100 Subject: [PATCH 1/4] issues closed --- CHANGELOG | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 096d27f37c..ef8f124ca6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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: From da8a48f89eae1efe34ce2bafc8cb230a9b7933be Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 25 Feb 2017 13:59:24 +0000 Subject: [PATCH 2/4] Bugfix: the curl option CURLOPT_SSL_VERIFYHOST is problematic --- include/ParseUrl.php | 4 +++- include/network.php | 8 ++++++-- include/poller.php | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/ParseUrl.php b/include/ParseUrl.php index 3a2fe9d53c..e9ac527a1a 100644 --- a/include/ParseUrl.php +++ b/include/ParseUrl.php @@ -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); diff --git a/include/network.php b/include/network.php index 03f65a5190..749f996f8c 100644 --- a/include/network.php +++ b/include/network.php @@ -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); diff --git a/include/poller.php b/include/poller.php index e8bfb88389..8be4c1835c 100644 --- a/include/poller.php +++ b/include/poller.php @@ -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; From 6bd59cd094bef799a7b1692228e67ad5783e129a Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Feb 2017 08:36:05 +0000 Subject: [PATCH 3/4] Bugfix: "ALTER IGNORE" was missing on structure and index change --- include/dbstructure.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index f8d084437b..1e4790de2e 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -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; } From 2a8a5a6d880e087df3127b5fe36f6090a489b5a6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Feb 2017 18:19:20 +0000 Subject: [PATCH 4/4] Improved server vitality detection --- include/socgraph.php | 80 +++++++++++++++++++++++++++++++++++++++++--- mod/admin.php | 6 ++-- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index a0dd88df2d..ff9467748f 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -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))); diff --git a/mod/admin.php b/mod/admin.php index 1475130834..fffc8bf818 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -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) {