Merge branch 'develop' into rewrites/coding-convention-split2
This commit is contained in:
+64
-31
@@ -18,6 +18,8 @@ require_once('include/network.php');
|
||||
*/
|
||||
class Probe {
|
||||
|
||||
private static $baseurl;
|
||||
|
||||
/**
|
||||
* @brief Rearrange the array so that it always has the same order
|
||||
*
|
||||
@@ -54,6 +56,9 @@ class Probe {
|
||||
*/
|
||||
private function xrd($host) {
|
||||
|
||||
// Reset the static variable
|
||||
self::$baseurl = '';
|
||||
|
||||
$ssl_url = "https://".$host."/.well-known/host-meta";
|
||||
$url = "http://".$host."/.well-known/host-meta";
|
||||
|
||||
@@ -102,6 +107,9 @@ class Probe {
|
||||
elseif ($attributes["rel"] == "lrdd")
|
||||
$xrd_data["lrdd"] = $attributes["template"];
|
||||
}
|
||||
|
||||
self::$baseurl = "http://".$host;
|
||||
|
||||
return $xrd_data;
|
||||
}
|
||||
|
||||
@@ -169,6 +177,8 @@ class Probe {
|
||||
|
||||
$path_parts = explode("/", trim($parts["path"], "/"));
|
||||
|
||||
$nick = array_pop($path_parts);
|
||||
|
||||
do {
|
||||
$lrdd = self::xrd($host);
|
||||
$host .= "/".array_shift($path_parts);
|
||||
@@ -192,6 +202,19 @@ class Probe {
|
||||
$path = str_replace('{uri}', urlencode("acct:".$uri), $link);
|
||||
$webfinger = self::webfinger($path);
|
||||
}
|
||||
|
||||
// Special treatment for Mastodon
|
||||
// Problem is that Mastodon uses an URL format like http://domain.tld/@nick
|
||||
// But the webfinger for this format fails.
|
||||
if (!$webfinger AND isset($nick)) {
|
||||
// Mastodon uses a "@" as prefix for usernames in their url format
|
||||
$nick = ltrim($nick, '@');
|
||||
|
||||
$addr = $nick."@".$host;
|
||||
|
||||
$path = str_replace('{uri}', urlencode("acct:".$addr), $link);
|
||||
$webfinger = self::webfinger($path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($webfinger["links"]))
|
||||
@@ -258,8 +281,13 @@ class Probe {
|
||||
$data['nick'] = trim(substr($data['nick'], 0, strpos($data['nick'], ' ')));
|
||||
}
|
||||
|
||||
if (!isset($data["network"]))
|
||||
if (self::$baseurl != "") {
|
||||
$data["baseurl"] = self::$baseurl;
|
||||
}
|
||||
|
||||
if (!isset($data["network"])) {
|
||||
$data["network"] = NETWORK_PHANTOM;
|
||||
}
|
||||
|
||||
$data = self::rearrange_data($data);
|
||||
|
||||
@@ -286,6 +314,7 @@ class Probe {
|
||||
dbesc(normalise_link($data['url']))
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -301,7 +330,34 @@ class Probe {
|
||||
* @return array uri data
|
||||
*/
|
||||
private function detect($uri, $network, $uid) {
|
||||
if (strstr($uri, '@')) {
|
||||
$parts = parse_url($uri);
|
||||
|
||||
if (isset($parts["scheme"]) AND isset($parts["host"]) AND isset($parts["path"])) {
|
||||
|
||||
/// @todo: Ports?
|
||||
$host = $parts["host"];
|
||||
|
||||
if ($host == 'twitter.com') {
|
||||
return array("network" => NETWORK_TWITTER);
|
||||
}
|
||||
$lrdd = self::xrd($host);
|
||||
|
||||
$path_parts = explode("/", trim($parts["path"], "/"));
|
||||
|
||||
while (!$lrdd AND (sizeof($path_parts) > 1)) {
|
||||
$host .= "/".array_shift($path_parts);
|
||||
$lrdd = self::xrd($host);
|
||||
}
|
||||
if (!$lrdd) {
|
||||
return self::feed($uri);
|
||||
}
|
||||
$nick = array_pop($path_parts);
|
||||
|
||||
// Mastodon uses a "@" as prefix for usernames in their url format
|
||||
$nick = ltrim($nick, '@');
|
||||
|
||||
$addr = $nick."@".$host;
|
||||
} elseif (strstr($uri, '@')) {
|
||||
// If the URI starts with "mailto:" then jump directly to the mail detection
|
||||
if (strpos($url,'mailto:') !== false) {
|
||||
$uri = str_replace('mailto:', '', $url);
|
||||
@@ -317,42 +373,19 @@ class Probe {
|
||||
$host = substr($uri,strpos($uri, '@') + 1);
|
||||
$nick = substr($uri,0, strpos($uri, '@'));
|
||||
|
||||
if (strpos($uri, '@twitter.com'))
|
||||
if (strpos($uri, '@twitter.com')) {
|
||||
return array("network" => NETWORK_TWITTER);
|
||||
|
||||
}
|
||||
$lrdd = self::xrd($host);
|
||||
|
||||
if (!$lrdd)
|
||||
if (!$lrdd) {
|
||||
return self::mail($uri, $uid);
|
||||
|
||||
}
|
||||
$addr = $uri;
|
||||
} else {
|
||||
$parts = parse_url($uri);
|
||||
if (!isset($parts["scheme"]) OR
|
||||
!isset($parts["host"]) OR
|
||||
!isset($parts["path"]))
|
||||
return false;
|
||||
|
||||
/// @todo: Ports?
|
||||
$host = $parts["host"];
|
||||
|
||||
if ($host == 'twitter.com')
|
||||
return array("network" => NETWORK_TWITTER);
|
||||
|
||||
$lrdd = self::xrd($host);
|
||||
|
||||
$path_parts = explode("/", trim($parts["path"], "/"));
|
||||
|
||||
while (!$lrdd AND (sizeof($path_parts) > 1)) {
|
||||
$host .= "/".array_shift($path_parts);
|
||||
$lrdd = self::xrd($host);
|
||||
}
|
||||
if (!$lrdd)
|
||||
return self::feed($uri);
|
||||
|
||||
$nick = array_pop($path_parts);
|
||||
$addr = $nick."@".$host;
|
||||
return false;
|
||||
}
|
||||
|
||||
$webfinger = false;
|
||||
|
||||
/// @todo Do we need the prefix "acct:" or "acct://"?
|
||||
|
||||
+9
-5
@@ -352,6 +352,7 @@ use \Friendica\Core\Config;
|
||||
}
|
||||
}
|
||||
}
|
||||
logger('API call not implemented: '.$a->query_string);
|
||||
throw new NotImplementedException();
|
||||
} catch (HTTPException $e) {
|
||||
header("HTTP/1.1 {$e->httpcode} {$e->httpdesc}");
|
||||
@@ -2720,6 +2721,7 @@ use \Friendica\Core\Config;
|
||||
return api_format_data('config', $type, array('config' => $config));
|
||||
|
||||
}
|
||||
api_register_func('api/gnusocial/config','api_statusnet_config',false);
|
||||
api_register_func('api/statusnet/config','api_statusnet_config',false);
|
||||
|
||||
function api_statusnet_version($type) {
|
||||
@@ -2728,6 +2730,7 @@ use \Friendica\Core\Config;
|
||||
|
||||
return api_format_data('version', $type, array('version' => $fake_statusnet_version));
|
||||
}
|
||||
api_register_func('api/gnusocial/version','api_statusnet_version',false);
|
||||
api_register_func('api/statusnet/version','api_statusnet_version',false);
|
||||
|
||||
/**
|
||||
@@ -3963,7 +3966,7 @@ use \Friendica\Core\Config;
|
||||
$multi_profiles = feature_enabled(api_user(),'multi_profiles');
|
||||
$directory = get_config('system', 'directory');
|
||||
|
||||
// get data of the specified profile id or all profiles of the user if not specified
|
||||
// get data of the specified profile id or all profiles of the user if not specified
|
||||
if ($profileid != 0) {
|
||||
$r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d",
|
||||
intval(api_user()),
|
||||
@@ -3971,11 +3974,10 @@ use \Friendica\Core\Config;
|
||||
// error message if specified gid is not in database
|
||||
if (!dbm::is_result($r))
|
||||
throw new BadRequestException("profile_id not available");
|
||||
}
|
||||
else
|
||||
} else {
|
||||
$r = q("SELECT * FROM `profile` WHERE `uid` = %d",
|
||||
intval(api_user()));
|
||||
|
||||
}
|
||||
// loop through all returned profiles and retrieve data and users
|
||||
$k = 0;
|
||||
foreach ($r as $rr) {
|
||||
@@ -4002,9 +4004,11 @@ use \Friendica\Core\Config;
|
||||
}
|
||||
|
||||
// return settings, authenticated user and profiles data
|
||||
$self = q("SELECT `nurl` FROM `contact` WHERE `uid`= %d AND `self` LIMIT 1", intval(api_user()));
|
||||
|
||||
$result = array('multi_profiles' => $multi_profiles ? true : false,
|
||||
'global_dir' => $directory,
|
||||
'friendica_owner' => api_get_user($a, intval(api_user())),
|
||||
'friendica_owner' => api_get_user($a, $self[0]['nurl']),
|
||||
'profiles' => $profiles);
|
||||
return api_format_data("friendica_profiles", $type, array('$result' => $result));
|
||||
}
|
||||
|
||||
@@ -59,15 +59,6 @@ function diaspora2bb($s) {
|
||||
|
||||
$s = str_replace('#', '#', $s);
|
||||
|
||||
$search = array(" \n", "\n ");
|
||||
$replace = array("\n", "\n");
|
||||
do {
|
||||
$oldtext = $s;
|
||||
$s = str_replace($search, $replace, $s);
|
||||
} while ($oldtext != $s);
|
||||
|
||||
$s = str_replace("\n\n", '<br>', $s);
|
||||
|
||||
$s = html2bbcode($s);
|
||||
|
||||
// protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands
|
||||
|
||||
+41
-222
@@ -1,28 +1,24 @@
|
||||
<?php
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once('include/photos.php');
|
||||
require_once('include/user.php');
|
||||
|
||||
function cron_run(&$argv, &$argc){
|
||||
global $a;
|
||||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('mod/nodeinfo.php');
|
||||
require_once('include/post_update.php');
|
||||
|
||||
// Poll contacts with specific parameters
|
||||
if ($argc > 1) {
|
||||
cron_poll_contacts($argc, $argv);
|
||||
return;
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cron');
|
||||
|
||||
$poll_interval = intval(get_config('system','cron_interval'));
|
||||
if(! $poll_interval)
|
||||
if (! $poll_interval) {
|
||||
$poll_interval = 10;
|
||||
|
||||
if($last) {
|
||||
}
|
||||
if ($last) {
|
||||
$next = $last + ($poll_interval * 60);
|
||||
if($next > time()) {
|
||||
logger('cron intervall not reached');
|
||||
@@ -33,19 +29,16 @@ function cron_run(&$argv, &$argc){
|
||||
logger('cron: start');
|
||||
|
||||
// run queue delivery process in the background
|
||||
|
||||
proc_run(PRIORITY_NEGLIGIBLE, "include/queue.php");
|
||||
|
||||
// run the process to discover global contacts in the background
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php");
|
||||
|
||||
// run the process to update locally stored global contacts in the background
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "checkcontact");
|
||||
|
||||
// Expire and remove user entries
|
||||
cron_expire_and_remove_users();
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "expire_and_remove_users");
|
||||
|
||||
// Check OStatus conversations
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
|
||||
@@ -59,14 +52,22 @@ function cron_run(&$argv, &$argc){
|
||||
// update nodeinfo data
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo");
|
||||
|
||||
// once daily run birthday_updates and then expire in background
|
||||
// Clear cache entries
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "clear_cache");
|
||||
|
||||
// Repair missing Diaspora values in contacts
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "repair_diaspora");
|
||||
|
||||
// Repair entries in the database
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "repair_database");
|
||||
|
||||
// once daily run birthday_updates and then expire in background
|
||||
$d1 = get_config('system','last_expire_day');
|
||||
$d2 = intval(datetime_convert('UTC','UTC','now','d'));
|
||||
|
||||
if($d2 != intval($d1)) {
|
||||
|
||||
update_contact_birthdays();
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_contact_birthdays");
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server");
|
||||
|
||||
@@ -78,18 +79,9 @@ function cron_run(&$argv, &$argc){
|
||||
|
||||
proc_run(PRIORITY_MEDIUM, 'include/dbclean.php');
|
||||
|
||||
cron_update_photo_albums();
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
|
||||
}
|
||||
|
||||
// Clear cache entries
|
||||
cron_clear_cache($a);
|
||||
|
||||
// Repair missing Diaspora values in contacts
|
||||
cron_repair_diaspora($a);
|
||||
|
||||
// Repair entries in the database
|
||||
cron_repair_database();
|
||||
|
||||
// Poll contacts
|
||||
cron_poll_contacts($argc, $argv);
|
||||
|
||||
@@ -100,39 +92,6 @@ function cron_run(&$argv, &$argc){
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the cached values for the number of photo albums per user
|
||||
*/
|
||||
function cron_update_photo_albums() {
|
||||
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`");
|
||||
if (!dbm::is_result($r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($r AS $user) {
|
||||
photo_albums($user['uid'], true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Expire and remove user entries
|
||||
*/
|
||||
function cron_expire_and_remove_users() {
|
||||
// expire any expired accounts
|
||||
q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0
|
||||
AND `account_expires_on` > '%s'
|
||||
AND `account_expires_on` < UTC_TIMESTAMP()", dbesc(NULL_DATE));
|
||||
|
||||
// delete user and contact records for recently removed accounts
|
||||
$r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
|
||||
if ($r) {
|
||||
foreach($r as $user) {
|
||||
q("DELETE FROM `contact` WHERE `uid` = %d", intval($user['uid']));
|
||||
q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Poll contacts for unreceived messages
|
||||
*
|
||||
@@ -145,14 +104,15 @@ function cron_poll_contacts($argc, $argv) {
|
||||
$force = false;
|
||||
$restart = false;
|
||||
|
||||
if (($argc > 1) && ($argv[1] == 'force'))
|
||||
if (($argc > 1) && ($argv[1] == 'force')) {
|
||||
$force = true;
|
||||
|
||||
}
|
||||
if (($argc > 1) && ($argv[1] == 'restart')) {
|
||||
$restart = true;
|
||||
$generation = intval($argv[2]);
|
||||
if (!$generation)
|
||||
if (!$generation) {
|
||||
killme();
|
||||
}
|
||||
}
|
||||
|
||||
if (($argc > 1) && intval($argv[1])) {
|
||||
@@ -171,9 +131,9 @@ function cron_poll_contacts($argc, $argv) {
|
||||
// we are unable to match those posts with a Diaspora GUID and prevent duplicates.
|
||||
|
||||
$abandon_days = intval(get_config('system','account_abandon_days'));
|
||||
if($abandon_days < 1)
|
||||
if ($abandon_days < 1) {
|
||||
$abandon_days = 0;
|
||||
|
||||
}
|
||||
$abandon_sql = (($abandon_days)
|
||||
? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days))
|
||||
: ''
|
||||
@@ -244,185 +204,44 @@ function cron_poll_contacts($argc, $argv) {
|
||||
|
||||
switch ($contact['priority']) {
|
||||
case 5:
|
||||
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 month"))
|
||||
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 month")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week"))
|
||||
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
|
||||
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour"))
|
||||
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour"))
|
||||
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour")) {
|
||||
$update = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!$update)
|
||||
if (!$update) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
logger("Polling ".$contact["network"]." ".$contact["id"]." ".$contact["nick"]." ".$contact["name"]);
|
||||
|
||||
if (($contact['network'] == NETWORK_FEED) AND ($contact['priority'] <= 3)) {
|
||||
proc_run(PRIORITY_MEDIUM, 'include/onepoll.php', $contact['id']);
|
||||
proc_run(PRIORITY_MEDIUM, 'include/onepoll.php', intval($contact['id']));
|
||||
} else {
|
||||
proc_run(PRIORITY_LOW, 'include/onepoll.php', $contact['id']);
|
||||
proc_run(PRIORITY_LOW, 'include/onepoll.php', intval($contact['id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear cache entries
|
||||
*
|
||||
* @param App $a
|
||||
*/
|
||||
function cron_clear_cache(App $a) {
|
||||
|
||||
$last = get_config('system','cache_last_cleared');
|
||||
|
||||
if($last) {
|
||||
$next = $last + (3600); // Once per hour
|
||||
$clear_cache = ($next <= time());
|
||||
} else
|
||||
$clear_cache = true;
|
||||
|
||||
if (!$clear_cache)
|
||||
return;
|
||||
|
||||
// clear old cache
|
||||
Cache::clear();
|
||||
|
||||
// clear old item cache files
|
||||
clear_cache();
|
||||
|
||||
// clear cache for photos
|
||||
clear_cache($a->get_basepath(), $a->get_basepath()."/photo");
|
||||
|
||||
// clear smarty cache
|
||||
clear_cache($a->get_basepath()."/view/smarty3/compiled", $a->get_basepath()."/view/smarty3/compiled");
|
||||
|
||||
// clear cache for image proxy
|
||||
if (!get_config("system", "proxy_disabled")) {
|
||||
clear_cache($a->get_basepath(), $a->get_basepath()."/proxy");
|
||||
|
||||
$cachetime = get_config('system','proxy_cache_time');
|
||||
if (!$cachetime) $cachetime = PROXY_DEFAULT_TIME;
|
||||
|
||||
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
|
||||
}
|
||||
|
||||
// Delete the cached OEmbed entries that are older than one year
|
||||
q("DELETE FROM `oembed` WHERE `created` < NOW() - INTERVAL 3 MONTH");
|
||||
|
||||
// Delete the cached "parse_url" entries that are older than one year
|
||||
q("DELETE FROM `parsed_url` WHERE `created` < NOW() - INTERVAL 3 MONTH");
|
||||
|
||||
// Maximum table size in megabyte
|
||||
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
|
||||
if ($max_tablesize == 0)
|
||||
$max_tablesize = 100 * 1000000; // Default are 100 MB
|
||||
|
||||
if ($max_tablesize > 0) {
|
||||
// Minimum fragmentation level in percent
|
||||
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
|
||||
if ($fragmentation_level == 0)
|
||||
$fragmentation_level = 0.3; // Default value is 30%
|
||||
|
||||
// Optimize some tables that need to be optimized
|
||||
$r = q("SHOW TABLE STATUS");
|
||||
foreach($r as $table) {
|
||||
|
||||
// Don't optimize tables that are too large
|
||||
if ($table["Data_length"] > $max_tablesize)
|
||||
continue;
|
||||
|
||||
// Don't optimize empty tables
|
||||
if ($table["Data_length"] == 0)
|
||||
continue;
|
||||
|
||||
// Calculate fragmentation
|
||||
$fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]);
|
||||
|
||||
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
|
||||
|
||||
// Don't optimize tables that needn't to be optimized
|
||||
if ($fragmentation < $fragmentation_level)
|
||||
continue;
|
||||
|
||||
// So optimize it
|
||||
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
|
||||
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
|
||||
}
|
||||
}
|
||||
|
||||
set_config('system','cache_last_cleared', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Repair missing values in Diaspora contacts
|
||||
*
|
||||
* @param App $a
|
||||
*/
|
||||
function cron_repair_diaspora(App $a) {
|
||||
$r = q("SELECT `id`, `url` FROM `contact`
|
||||
WHERE `network` = '%s' AND (`batch` = '' OR `notify` = '' OR `poll` = '' OR pubkey = '')
|
||||
ORDER BY RAND() LIMIT 50", dbesc(NETWORK_DIASPORA));
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r AS $contact) {
|
||||
if (poco_reachable($contact["url"])) {
|
||||
$data = probe_url($contact["url"]);
|
||||
if ($data["network"] == NETWORK_DIASPORA) {
|
||||
logger("Repair contact ".$contact["id"]." ".$contact["url"], LOGGER_DEBUG);
|
||||
q("UPDATE `contact` SET `batch` = '%s', `notify` = '%s', `poll` = '%s', pubkey = '%s' WHERE `id` = %d",
|
||||
dbesc($data["batch"]), dbesc($data["notify"]), dbesc($data["poll"]), dbesc($data["pubkey"]),
|
||||
intval($contact["id"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Do some repairs in database entries
|
||||
*
|
||||
*/
|
||||
function cron_repair_database() {
|
||||
|
||||
// Sometimes there seem to be issues where the "self" contact vanishes.
|
||||
// We haven't found the origin of the problem by now.
|
||||
$r = q("SELECT `uid` FROM `user` WHERE NOT EXISTS (SELECT `uid` FROM `contact` WHERE `contact`.`uid` = `user`.`uid` AND `contact`.`self`)");
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r AS $user) {
|
||||
logger('Create missing self contact for user '.$user['uid']);
|
||||
user_create_self_contact($user['uid']);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the parent if it wasn't set. (Shouldn't happen - but does sometimes)
|
||||
// This call is very "cheap" so we can do it at any time without a problem
|
||||
q("UPDATE `item` INNER JOIN `item` AS `parent` ON `parent`.`uri` = `item`.`parent-uri` AND `parent`.`uid` = `item`.`uid` SET `item`.`parent` = `parent`.`id` WHERE `item`.`parent` = 0");
|
||||
|
||||
// There was an issue where the nick vanishes from the contact table
|
||||
q("UPDATE `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` SET `nick` = `nickname` WHERE `self` AND `nick`=''");
|
||||
|
||||
// Update the global contacts for local users
|
||||
$r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`");
|
||||
if (dbm::is_result($r))
|
||||
foreach ($r AS $user)
|
||||
update_gcontact_for_user($user["uid"]);
|
||||
|
||||
/// @todo
|
||||
/// - remove thread entries without item
|
||||
/// - remove sign entries without item
|
||||
/// - remove children when parent got lost
|
||||
/// - set contact-id in item when not present
|
||||
}
|
||||
|
||||
+247
-1
@@ -8,10 +8,17 @@ function cronjobs_run(&$argv, &$argc){
|
||||
require_once('include/ostatus.php');
|
||||
require_once('include/post_update.php');
|
||||
require_once('mod/nodeinfo.php');
|
||||
require_once('include/photos.php');
|
||||
require_once('include/user.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/Probe.php');
|
||||
|
||||
// No parameter set? So return
|
||||
if ($argc <= 1)
|
||||
if ($argc <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger("Starting cronjob ".$argv[1], LOGGER_DEBUG);
|
||||
|
||||
// Check OStatus conversations
|
||||
// Check only conversations with mentions (for a longer time)
|
||||
@@ -39,5 +46,244 @@ function cronjobs_run(&$argv, &$argc){
|
||||
return;
|
||||
}
|
||||
|
||||
// Expire and remove user entries
|
||||
if ($argv[1] == 'expire_and_remove_users') {
|
||||
cron_expire_and_remove_users();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($argv[1] == 'update_contact_birthdays') {
|
||||
update_contact_birthdays();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($argv[1] == 'update_photo_albums') {
|
||||
cron_update_photo_albums();
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear cache entries
|
||||
if ($argv[1] == 'clear_cache') {
|
||||
cron_clear_cache($a);
|
||||
return;
|
||||
}
|
||||
|
||||
// Repair missing Diaspora values in contacts
|
||||
if ($argv[1] == 'repair_diaspora') {
|
||||
cron_repair_diaspora($a);
|
||||
return;
|
||||
}
|
||||
|
||||
// Repair entries in the database
|
||||
if ($argv[1] == 'repair_database') {
|
||||
cron_repair_database();
|
||||
return;
|
||||
}
|
||||
|
||||
logger("Xronjob ".$argv[1]." is unknown.", LOGGER_DEBUG);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the cached values for the number of photo albums per user
|
||||
*/
|
||||
function cron_update_photo_albums() {
|
||||
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`");
|
||||
if (!dbm::is_result($r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($r AS $user) {
|
||||
photo_albums($user['uid'], true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Expire and remove user entries
|
||||
*/
|
||||
function cron_expire_and_remove_users() {
|
||||
// expire any expired accounts
|
||||
q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0
|
||||
AND `account_expires_on` > '%s'
|
||||
AND `account_expires_on` < UTC_TIMESTAMP()", dbesc(NULL_DATE));
|
||||
|
||||
// delete user and contact records for recently removed accounts
|
||||
$r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $user) {
|
||||
q("DELETE FROM `contact` WHERE `uid` = %d", intval($user['uid']));
|
||||
q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear cache entries
|
||||
*
|
||||
* @param App $a
|
||||
*/
|
||||
function cron_clear_cache(App $a) {
|
||||
|
||||
$last = get_config('system','cache_last_cleared');
|
||||
|
||||
if ($last) {
|
||||
$next = $last + (3600); // Once per hour
|
||||
$clear_cache = ($next <= time());
|
||||
} else {
|
||||
$clear_cache = true;
|
||||
}
|
||||
|
||||
if (!$clear_cache) {
|
||||
return;
|
||||
}
|
||||
|
||||
// clear old cache
|
||||
Cache::clear();
|
||||
|
||||
// clear old item cache files
|
||||
clear_cache();
|
||||
|
||||
// clear cache for photos
|
||||
clear_cache($a->get_basepath(), $a->get_basepath()."/photo");
|
||||
|
||||
// clear smarty cache
|
||||
clear_cache($a->get_basepath()."/view/smarty3/compiled", $a->get_basepath()."/view/smarty3/compiled");
|
||||
|
||||
// clear cache for image proxy
|
||||
if (!get_config("system", "proxy_disabled")) {
|
||||
clear_cache($a->get_basepath(), $a->get_basepath()."/proxy");
|
||||
|
||||
$cachetime = get_config('system','proxy_cache_time');
|
||||
if (!$cachetime) {
|
||||
$cachetime = PROXY_DEFAULT_TIME;
|
||||
}
|
||||
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
|
||||
}
|
||||
|
||||
// Delete the cached OEmbed entries that are older than one year
|
||||
q("DELETE FROM `oembed` WHERE `created` < NOW() - INTERVAL 3 MONTH");
|
||||
|
||||
// Delete the cached "parse_url" entries that are older than one year
|
||||
q("DELETE FROM `parsed_url` WHERE `created` < NOW() - INTERVAL 3 MONTH");
|
||||
|
||||
// Maximum table size in megabyte
|
||||
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
|
||||
if ($max_tablesize == 0) {
|
||||
$max_tablesize = 100 * 1000000; // Default are 100 MB
|
||||
}
|
||||
if ($max_tablesize > 0) {
|
||||
// Minimum fragmentation level in percent
|
||||
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
|
||||
if ($fragmentation_level == 0) {
|
||||
$fragmentation_level = 0.3; // Default value is 30%
|
||||
}
|
||||
|
||||
// Optimize some tables that need to be optimized
|
||||
$r = q("SHOW TABLE STATUS");
|
||||
foreach ($r as $table) {
|
||||
|
||||
// Don't optimize tables that are too large
|
||||
if ($table["Data_length"] > $max_tablesize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't optimize empty tables
|
||||
if ($table["Data_length"] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Calculate fragmentation
|
||||
$fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]);
|
||||
|
||||
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
|
||||
|
||||
// Don't optimize tables that needn't to be optimized
|
||||
if ($fragmentation < $fragmentation_level) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// So optimize it
|
||||
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
|
||||
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
|
||||
}
|
||||
}
|
||||
|
||||
set_config('system','cache_last_cleared', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Repair missing values in Diaspora contacts
|
||||
*
|
||||
* @param App $a
|
||||
*/
|
||||
function cron_repair_diaspora(App $a) {
|
||||
|
||||
$starttime = time();
|
||||
|
||||
$r = q("SELECT `id`, `url` FROM `contact`
|
||||
WHERE `network` = '%s' AND (`batch` = '' OR `notify` = '' OR `poll` = '' OR pubkey = '')
|
||||
ORDER BY RAND() LIMIT 50", dbesc(NETWORK_DIASPORA));
|
||||
if (!dbm::is_result($r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($r AS $contact) {
|
||||
// Quit the loop after 3 minutes
|
||||
if (time() > ($starttime + 180)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!poco_reachable($contact["url"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = Probe::uri($contact["url"]);
|
||||
if ($data["network"] != NETWORK_DIASPORA) {
|
||||
continue;
|
||||
}
|
||||
|
||||
logger("Repair contact ".$contact["id"]." ".$contact["url"], LOGGER_DEBUG);
|
||||
q("UPDATE `contact` SET `batch` = '%s', `notify` = '%s', `poll` = '%s', pubkey = '%s' WHERE `id` = %d",
|
||||
dbesc($data["batch"]), dbesc($data["notify"]), dbesc($data["poll"]), dbesc($data["pubkey"]),
|
||||
intval($contact["id"]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Do some repairs in database entries
|
||||
*
|
||||
*/
|
||||
function cron_repair_database() {
|
||||
|
||||
// Sometimes there seem to be issues where the "self" contact vanishes.
|
||||
// We haven't found the origin of the problem by now.
|
||||
$r = q("SELECT `uid` FROM `user` WHERE NOT EXISTS (SELECT `uid` FROM `contact` WHERE `contact`.`uid` = `user`.`uid` AND `contact`.`self`)");
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r AS $user) {
|
||||
logger('Create missing self contact for user '.$user['uid']);
|
||||
user_create_self_contact($user['uid']);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the parent if it wasn't set. (Shouldn't happen - but does sometimes)
|
||||
// This call is very "cheap" so we can do it at any time without a problem
|
||||
q("UPDATE `item` INNER JOIN `item` AS `parent` ON `parent`.`uri` = `item`.`parent-uri` AND `parent`.`uid` = `item`.`uid` SET `item`.`parent` = `parent`.`id` WHERE `item`.`parent` = 0");
|
||||
|
||||
// There was an issue where the nick vanishes from the contact table
|
||||
q("UPDATE `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` SET `nick` = `nickname` WHERE `self` AND `nick`=''");
|
||||
|
||||
// Update the global contacts for local users
|
||||
$r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`");
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r AS $user) {
|
||||
update_gcontact_for_user($user["uid"]);
|
||||
}
|
||||
}
|
||||
|
||||
/// @todo
|
||||
/// - remove thread entries without item
|
||||
/// - remove sign entries without item
|
||||
/// - remove children when parent got lost
|
||||
/// - set contact-id in item when not present
|
||||
}
|
||||
|
||||
+58
-151
@@ -1,94 +1,52 @@
|
||||
<?php
|
||||
|
||||
require_once('library/ASNValue.class.php');
|
||||
require_once('library/asn1.php');
|
||||
require_once 'library/ASNValue.class.php';
|
||||
require_once 'library/asn1.php';
|
||||
|
||||
// supported algorithms are 'sha256', 'sha1'
|
||||
|
||||
function rsa_sign($data,$key,$alg = 'sha256') {
|
||||
|
||||
$sig = '';
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '>=') || $alg === 'sha1') {
|
||||
openssl_sign($data,$sig,$key,(($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg));
|
||||
}
|
||||
else {
|
||||
if(strlen($key) < 1024 || extension_loaded('gmp')) {
|
||||
require_once('library/phpsec/Crypt/RSA.php');
|
||||
$rsa = new CRYPT_RSA();
|
||||
$rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
|
||||
$rsa->setHash($alg);
|
||||
$rsa->loadKey($key);
|
||||
$sig = $rsa->sign($data);
|
||||
}
|
||||
else {
|
||||
logger('rsa_sign: insecure algorithm used. Please upgrade PHP to 5.3');
|
||||
openssl_private_encrypt(hex2bin('3031300d060960864801650304020105000420') . hash('sha256',$data,true), $sig, $key);
|
||||
}
|
||||
}
|
||||
function rsa_sign($data, $key, $alg = 'sha256') {
|
||||
openssl_sign($data, $sig, $key, (($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg));
|
||||
return $sig;
|
||||
}
|
||||
|
||||
function rsa_verify($data,$sig,$key,$alg = 'sha256') {
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '>=') || $alg === 'sha1') {
|
||||
$verify = openssl_verify($data,$sig,$key,(($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg));
|
||||
}
|
||||
else {
|
||||
if(strlen($key) <= 300 || extension_loaded('gmp')) {
|
||||
require_once('library/phpsec/Crypt/RSA.php');
|
||||
$rsa = new CRYPT_RSA();
|
||||
$rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
|
||||
$rsa->setHash($alg);
|
||||
$rsa->loadKey($key);
|
||||
$verify = $rsa->verify($data,$sig);
|
||||
}
|
||||
else {
|
||||
// fallback sha256 verify for PHP < 5.3 and large key lengths
|
||||
$rawsig = '';
|
||||
openssl_public_decrypt($sig,$rawsig,$key);
|
||||
$verify = (($rawsig && substr($rawsig,-32) === hash('sha256',$data,true)) ? true : false);
|
||||
}
|
||||
}
|
||||
return $verify;
|
||||
function rsa_verify($data, $sig, $key, $alg = 'sha256') {
|
||||
return openssl_verify($data, $sig, $key, (($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg));
|
||||
}
|
||||
|
||||
function DerToPem($Der, $Private = false) {
|
||||
//Encode:
|
||||
$Der = base64_encode($Der);
|
||||
//Split lines:
|
||||
$lines = str_split($Der, 65);
|
||||
$body = implode("\n", $lines);
|
||||
//Get title:
|
||||
$title = $Private ? 'RSA PRIVATE KEY' : 'PUBLIC KEY';
|
||||
//Add wrapping:
|
||||
$result = "-----BEGIN {$title}-----\n";
|
||||
$result .= $body . "\n";
|
||||
$result .= "-----END {$title}-----\n";
|
||||
|
||||
function DerToPem($Der, $Private=false)
|
||||
{
|
||||
//Encode:
|
||||
$Der = base64_encode($Der);
|
||||
//Split lines:
|
||||
$lines = str_split($Der, 65);
|
||||
$body = implode("\n", $lines);
|
||||
//Get title:
|
||||
$title = $Private? 'RSA PRIVATE KEY' : 'PUBLIC KEY';
|
||||
//Add wrapping:
|
||||
$result = "-----BEGIN {$title}-----\n";
|
||||
$result .= $body . "\n";
|
||||
$result .= "-----END {$title}-----\n";
|
||||
|
||||
return $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
function DerToRsa($Der)
|
||||
{
|
||||
//Encode:
|
||||
$Der = base64_encode($Der);
|
||||
//Split lines:
|
||||
$lines = str_split($Der, 64);
|
||||
$body = implode("\n", $lines);
|
||||
//Get title:
|
||||
$title = 'RSA PUBLIC KEY';
|
||||
//Add wrapping:
|
||||
$result = "-----BEGIN {$title}-----\n";
|
||||
$result .= $body . "\n";
|
||||
$result .= "-----END {$title}-----\n";
|
||||
|
||||
return $result;
|
||||
function DerToRsa($Der) {
|
||||
//Encode:
|
||||
$Der = base64_encode($Der);
|
||||
//Split lines:
|
||||
$lines = str_split($Der, 64);
|
||||
$body = implode("\n", $lines);
|
||||
//Get title:
|
||||
$title = 'RSA PUBLIC KEY';
|
||||
//Add wrapping:
|
||||
$result = "-----BEGIN {$title}-----\n";
|
||||
$result .= $body . "\n";
|
||||
$result .= "-----END {$title}-----\n";
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
function pkcs8_encode($Modulus,$PublicExponent) {
|
||||
function pkcs8_encode($Modulus, $PublicExponent) {
|
||||
//Encode key sequence
|
||||
$modulus = new ASNValue(ASNValue::TAG_INTEGER);
|
||||
$modulus->SetIntBuffer($Modulus);
|
||||
@@ -111,8 +69,7 @@ function pkcs8_encode($Modulus,$PublicExponent) {
|
||||
return $PublicDER;
|
||||
}
|
||||
|
||||
|
||||
function pkcs1_encode($Modulus,$PublicExponent) {
|
||||
function pkcs1_encode($Modulus, $PublicExponent) {
|
||||
//Encode key sequence
|
||||
$modulus = new ASNValue(ASNValue::TAG_INTEGER);
|
||||
$modulus->SetIntBuffer($Modulus);
|
||||
@@ -126,22 +83,20 @@ function pkcs1_encode($Modulus,$PublicExponent) {
|
||||
return $bitStringValue;
|
||||
}
|
||||
|
||||
|
||||
function metopem($m,$e) {
|
||||
$der = pkcs8_encode($m,$e);
|
||||
$key = DerToPem($der,false);
|
||||
function metopem($m, $e) {
|
||||
$der = pkcs8_encode($m, $e);
|
||||
$key = DerToPem($der, false);
|
||||
return $key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function pubrsatome($key,&$m,&$e) {
|
||||
require_once('library/asn1.php');
|
||||
require_once('include/salmon.php');
|
||||
|
||||
$lines = explode("\n",$key);
|
||||
$lines = explode("\n", $key);
|
||||
unset($lines[0]);
|
||||
unset($lines[count($lines)]);
|
||||
$x = base64_decode(implode('',$lines));
|
||||
$x = base64_decode(implode('', $lines));
|
||||
|
||||
$r = ASN_BASE::parseASNString($x);
|
||||
|
||||
@@ -151,21 +106,21 @@ function pubrsatome($key,&$m,&$e) {
|
||||
|
||||
|
||||
function rsatopem($key) {
|
||||
pubrsatome($key,$m,$e);
|
||||
return(metopem($m,$e));
|
||||
pubrsatome($key, $m, $e);
|
||||
return metopem($m, $e);
|
||||
}
|
||||
|
||||
function pemtorsa($key) {
|
||||
pemtome($key,$m,$e);
|
||||
return(metorsa($m,$e));
|
||||
pemtome($key, $m, $e);
|
||||
return metorsa($m, $e);
|
||||
}
|
||||
|
||||
function pemtome($key,&$m,&$e) {
|
||||
function pemtome($key, &$m, &$e) {
|
||||
require_once('include/salmon.php');
|
||||
$lines = explode("\n",$key);
|
||||
$lines = explode("\n", $key);
|
||||
unset($lines[0]);
|
||||
unset($lines[count($lines)]);
|
||||
$x = base64_decode(implode('',$lines));
|
||||
$x = base64_decode(implode('', $lines));
|
||||
|
||||
$r = ASN_BASE::parseASNString($x);
|
||||
|
||||
@@ -173,82 +128,36 @@ function pemtome($key,&$m,&$e) {
|
||||
$e = base64url_decode($r[0]->asnData[1]->asnData[0]->asnData[1]->asnData);
|
||||
}
|
||||
|
||||
function metorsa($m,$e) {
|
||||
$der = pkcs1_encode($m,$e);
|
||||
function metorsa($m, $e) {
|
||||
$der = pkcs1_encode($m, $e);
|
||||
$key = DerToRsa($der);
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
function salmon_key($pubkey) {
|
||||
pemtome($pubkey,$m,$e);
|
||||
return 'RSA' . '.' . base64url_encode($m,true) . '.' . base64url_encode($e,true) ;
|
||||
pemtome($pubkey, $m, $e);
|
||||
return 'RSA' . '.' . base64url_encode($m, true) . '.' . base64url_encode($e, true) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(! function_exists('aes_decrypt')) {
|
||||
// DEPRECATED IN 3.4.1
|
||||
function aes_decrypt($val,$ky)
|
||||
{
|
||||
$key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
for($a=0;$a<strlen($ky);$a++)
|
||||
$key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
|
||||
$mode = MCRYPT_MODE_ECB;
|
||||
$enc = MCRYPT_RIJNDAEL_128;
|
||||
$dec = @mcrypt_decrypt($enc, $key, $val, $mode, @mcrypt_create_iv( @mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM ) );
|
||||
return rtrim($dec,(( ord(substr($dec,strlen($dec)-1,1))>=0 and ord(substr($dec, strlen($dec)-1,1))<=16)? chr(ord( substr($dec,strlen($dec)-1,1))):null));
|
||||
}}
|
||||
|
||||
|
||||
if(! function_exists('aes_encrypt')) {
|
||||
// DEPRECATED IN 3.4.1
|
||||
function aes_encrypt($val,$ky)
|
||||
{
|
||||
$key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
for($a=0;$a<strlen($ky);$a++)
|
||||
$key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
|
||||
$mode=MCRYPT_MODE_ECB;
|
||||
$enc=MCRYPT_RIJNDAEL_128;
|
||||
$val=str_pad($val, (16*(floor(strlen($val) / 16)+(strlen($val) % 16==0?2:1))), chr(16-(strlen($val) % 16)));
|
||||
return mcrypt_encrypt($enc, $key, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM));
|
||||
}}
|
||||
|
||||
function pkcs5_pad ($text, $blocksize)
|
||||
{
|
||||
$pad = $blocksize - (strlen($text) % $blocksize);
|
||||
return $text . str_repeat(chr($pad), $pad);
|
||||
}
|
||||
|
||||
function pkcs5_unpad($text)
|
||||
{
|
||||
$pad = ord($text{strlen($text)-1});
|
||||
if ($pad > strlen($text)) return false;
|
||||
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
|
||||
return substr($text, 0, -1 * $pad);
|
||||
}
|
||||
|
||||
|
||||
function new_keypair($bits) {
|
||||
|
||||
$openssl_options = array(
|
||||
'digest_alg' => 'sha1',
|
||||
'private_key_bits' => $bits,
|
||||
'encrypt_key' => false
|
||||
'encrypt_key' => false
|
||||
);
|
||||
|
||||
$conf = get_config('system','openssl_conf_file');
|
||||
if($conf)
|
||||
$conf = get_config('system', 'openssl_conf_file');
|
||||
if ($conf) {
|
||||
$openssl_options['config'] = $conf;
|
||||
|
||||
}
|
||||
$result = openssl_pkey_new($openssl_options);
|
||||
|
||||
if(empty($result)) {
|
||||
if (empty($result)) {
|
||||
logger('new_keypair: failed');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get private key
|
||||
|
||||
$response = array('prvkey' => '', 'pubkey' => '');
|
||||
|
||||
openssl_pkey_export($result, $response['prvkey']);
|
||||
@@ -258,6 +167,4 @@ function new_keypair($bits) {
|
||||
$response['pubkey'] = $pkey["key"];
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
|
||||
+29
-8
@@ -931,6 +931,30 @@ class dfrn {
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief encrypts data via AES
|
||||
*
|
||||
* @param string $data The data that is to be encrypted
|
||||
* @param string $key The AES key
|
||||
*
|
||||
* @return string encrypted data
|
||||
*/
|
||||
private static function aes_encrypt($data, $key) {
|
||||
return openssl_encrypt($data, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief decrypts data via AES
|
||||
*
|
||||
* @param string $encrypted The encrypted data
|
||||
* @param string $key The AES key
|
||||
*
|
||||
* @return string decrypted data
|
||||
*/
|
||||
public static function aes_decrypt($encrypted, $key) {
|
||||
return openssl_decrypt($encrypted, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delivers the atom content to the contacts
|
||||
*
|
||||
@@ -958,11 +982,6 @@ class dfrn {
|
||||
$rino = get_config('system', 'rino_encrypt');
|
||||
$rino = intval($rino);
|
||||
|
||||
// use RINO1 if mcrypt isn't installed and RINO2 was selected
|
||||
if ($rino == 2 and !function_exists('mcrypt_create_iv')) {
|
||||
$rino = 1;
|
||||
}
|
||||
|
||||
logger("Local rino version: ". $rino, LOGGER_DEBUG);
|
||||
|
||||
$ssl_val = intval(get_config('system','ssl_policy'));
|
||||
@@ -1093,8 +1112,8 @@ class dfrn {
|
||||
switch ($rino_remote_version) {
|
||||
case 1:
|
||||
// Deprecated rino version!
|
||||
$key = substr(random_string(), 0, 16);
|
||||
$data = aes_encrypt($postvars['data'],$key);
|
||||
$key = openssl_random_pseudo_bytes(16);
|
||||
$data = self::aes_encrypt($postvars['data'], $key);
|
||||
break;
|
||||
case 2:
|
||||
// RINO 2 based on php-encryption
|
||||
@@ -1458,7 +1477,9 @@ class dfrn {
|
||||
$poco["photo"] = $author["avatar"];
|
||||
$poco["hide"] = $hide;
|
||||
$poco["contact-type"] = $contact["contact-type"];
|
||||
update_gcontact($poco);
|
||||
$gcid = update_gcontact($poco);
|
||||
|
||||
link_gcontact($gcid, $importer["uid"], $contact["id"]);
|
||||
}
|
||||
|
||||
return($author);
|
||||
|
||||
+48
-31
@@ -10,17 +10,17 @@
|
||||
|
||||
use \Friendica\Core\Config;
|
||||
|
||||
require_once("include/items.php");
|
||||
require_once("include/bb2diaspora.php");
|
||||
require_once("include/Scrape.php");
|
||||
require_once("include/Contact.php");
|
||||
require_once("include/Photo.php");
|
||||
require_once("include/socgraph.php");
|
||||
require_once("include/group.php");
|
||||
require_once("include/xml.php");
|
||||
require_once("include/datetime.php");
|
||||
require_once("include/queue_fn.php");
|
||||
require_once("include/cache.php");
|
||||
require_once 'include/items.php';
|
||||
require_once 'include/bb2diaspora.php';
|
||||
require_once 'include/Scrape.php';
|
||||
require_once 'include/Contact.php';
|
||||
require_once 'include/Photo.php';
|
||||
require_once 'include/socgraph.php';
|
||||
require_once 'include/group.php';
|
||||
require_once 'include/xml.php';
|
||||
require_once 'include/datetime.php';
|
||||
require_once 'include/queue_fn.php';
|
||||
require_once 'include/cache.php';
|
||||
|
||||
/**
|
||||
* @brief This class contain functions to create and send Diaspora XML files
|
||||
@@ -160,6 +160,32 @@ class Diaspora {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief encrypts data via AES
|
||||
*
|
||||
* @param string $key The AES key
|
||||
* @param string $iv The IV (is used for CBC encoding)
|
||||
* @param string $data The data that is to be encrypted
|
||||
*
|
||||
* @return string encrypted data
|
||||
*/
|
||||
private static function aes_encrypt($key, $iv, $data) {
|
||||
return openssl_encrypt($data, 'aes-256-cbc', str_pad($key, 32, "\0"), OPENSSL_RAW_DATA, str_pad($iv, 16, "\0"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief decrypts data via AES
|
||||
*
|
||||
* @param string $key The AES key
|
||||
* @param string $iv The IV (is used for CBC encoding)
|
||||
* @param string $encrypted The encrypted data
|
||||
*
|
||||
* @return string decrypted data
|
||||
*/
|
||||
private static function aes_decrypt($key, $iv, $encrypted) {
|
||||
return openssl_decrypt($encrypted,'aes-256-cbc', str_pad($key, 32, "\0"), OPENSSL_RAW_DATA,str_pad($iv, 16, "\0"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: Decodes incoming Diaspora message
|
||||
*
|
||||
@@ -199,10 +225,7 @@ class Diaspora {
|
||||
$outer_iv = base64_decode($j_outer_key_bundle->iv);
|
||||
$outer_key = base64_decode($j_outer_key_bundle->key);
|
||||
|
||||
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $outer_key, $ciphertext, MCRYPT_MODE_CBC, $outer_iv);
|
||||
|
||||
|
||||
$decrypted = pkcs5_unpad($decrypted);
|
||||
$decrypted = self::aes_decrypt($outer_key, $outer_iv, $ciphertext);
|
||||
|
||||
logger('decrypted: '.$decrypted, LOGGER_DEBUG);
|
||||
$idom = parse_xml_string($decrypted,false);
|
||||
@@ -261,8 +284,7 @@ class Diaspora {
|
||||
// Decode the encrypted blob
|
||||
|
||||
$inner_encrypted = base64_decode($data);
|
||||
$inner_decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $inner_encrypted, MCRYPT_MODE_CBC, $inner_iv);
|
||||
$inner_decrypted = pkcs5_unpad($inner_decrypted);
|
||||
$inner_decrypted = self::aes_decrypt($inner_aes_key, $inner_iv, $inner_encrypted);
|
||||
}
|
||||
|
||||
if (!$author_link) {
|
||||
@@ -1848,18 +1870,15 @@ class Diaspora {
|
||||
intval($importer["uid"])
|
||||
);
|
||||
|
||||
if ($searchable) {
|
||||
poco_check($contact["url"], $name, NETWORK_DIASPORA, $image_url, $about, $location, $gender, $keywords, "",
|
||||
datetime_convert(), 2, $contact["id"], $importer["uid"]);
|
||||
}
|
||||
|
||||
$gcontact = array("url" => $contact["url"], "network" => NETWORK_DIASPORA, "generation" => 2,
|
||||
"photo" => $image_url, "name" => $name, "location" => $location,
|
||||
"about" => $about, "birthday" => $birthday, "gender" => $gender,
|
||||
"addr" => $author, "nick" => $nick, "keywords" => $keywords,
|
||||
"hide" => !$searchable, "nsfw" => $nsfw);
|
||||
|
||||
update_gcontact($gcontact);
|
||||
$gcid = update_gcontact($gcontact);
|
||||
|
||||
link_gcontact($gcid, $importer["uid"], $contact["id"]);
|
||||
|
||||
logger("Profile of contact ".$contact["id"]." stored for user ".$importer["uid"], LOGGER_DEBUG);
|
||||
|
||||
@@ -2621,20 +2640,19 @@ class Diaspora {
|
||||
return false;
|
||||
}
|
||||
|
||||
$inner_aes_key = random_string(32);
|
||||
$inner_aes_key = openssl_random_pseudo_bytes(32);
|
||||
$b_inner_aes_key = base64_encode($inner_aes_key);
|
||||
$inner_iv = random_string(16);
|
||||
$inner_iv = openssl_random_pseudo_bytes(16);
|
||||
$b_inner_iv = base64_encode($inner_iv);
|
||||
|
||||
$outer_aes_key = random_string(32);
|
||||
$outer_aes_key = openssl_random_pseudo_bytes(32);
|
||||
$b_outer_aes_key = base64_encode($outer_aes_key);
|
||||
$outer_iv = random_string(16);
|
||||
$outer_iv = openssl_random_pseudo_bytes(16);
|
||||
$b_outer_iv = base64_encode($outer_iv);
|
||||
|
||||
$handle = self::my_handle($user);
|
||||
|
||||
$padded_data = pkcs5_pad($msg,16);
|
||||
$inner_encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $padded_data, MCRYPT_MODE_CBC, $inner_iv);
|
||||
$inner_encrypted = self::aes_encrypt($inner_aes_key, $inner_iv, $msg);
|
||||
|
||||
$b64_data = base64_encode($inner_encrypted);
|
||||
|
||||
@@ -2656,9 +2674,8 @@ class Diaspora {
|
||||
"author_id" => $handle));
|
||||
|
||||
$decrypted_header = xml::from_array($xmldata, $xml, true);
|
||||
$decrypted_header = pkcs5_pad($decrypted_header,16);
|
||||
|
||||
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $outer_aes_key, $decrypted_header, MCRYPT_MODE_CBC, $outer_iv);
|
||||
$ciphertext = self::aes_encrypt($outer_aes_key, $outer_iv, $decrypted_header);
|
||||
|
||||
$outer_json = json_encode(array("iv" => $b_outer_iv, "key" => $b_outer_aes_key));
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ function discover_poco_run(&$argv, &$argc) {
|
||||
- update_server: Frequently check the first 250 servers for vitality.
|
||||
- update_server_directory: Discover the given server id for their contacts
|
||||
- poco_load: Load POCO data from a given POCO address
|
||||
- check_profile: Update remote profile data
|
||||
*/
|
||||
|
||||
if (($argc > 2) && ($argv[1] == "dirsearch")) {
|
||||
@@ -33,6 +34,8 @@ function discover_poco_run(&$argv, &$argc) {
|
||||
$mode = 6;
|
||||
} elseif (($argc > 5) && ($argv[1] == "poco_load")) {
|
||||
$mode = 7;
|
||||
} elseif (($argc == 3) && ($argv[1] == "check_profile")) {
|
||||
$mode = 8;
|
||||
} elseif ($argc == 1) {
|
||||
$search = "";
|
||||
$mode = 0;
|
||||
@@ -42,7 +45,12 @@ function discover_poco_run(&$argv, &$argc) {
|
||||
|
||||
logger('start '.$search);
|
||||
|
||||
if ($mode == 7) {
|
||||
if ($mode == 8) {
|
||||
$profile_url = base64_decode($argv[2]);
|
||||
if ($profile_url != "") {
|
||||
poco_last_updated($profile_url, true);
|
||||
}
|
||||
} elseif ($mode == 7) {
|
||||
if ($argc == 6) {
|
||||
$url = base64_decode($argv[5]);
|
||||
} else {
|
||||
@@ -121,7 +129,9 @@ function update_server() {
|
||||
function discover_users() {
|
||||
logger("Discover users", LOGGER_DEBUG);
|
||||
|
||||
$users = q("SELECT `url`, `created`, `updated`, `last_failure`, `last_contact`, `server_url` FROM `gcontact`
|
||||
$starttime = time();
|
||||
|
||||
$users = q("SELECT `url`, `created`, `updated`, `last_failure`, `last_contact`, `server_url`, `network` FROM `gcontact`
|
||||
WHERE `last_contact` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
|
||||
`last_failure` < UTC_TIMESTAMP - INTERVAL 1 MONTH AND
|
||||
`network` IN ('%s', '%s', '%s', '%s', '') ORDER BY rand()",
|
||||
@@ -155,14 +165,19 @@ function discover_users() {
|
||||
continue;
|
||||
}
|
||||
|
||||
$server_url = poco_detect_server($user["url"]);
|
||||
$force_update = false;
|
||||
|
||||
if ($user["server_url"] != "") {
|
||||
|
||||
$force_update = (normalise_link($user["server_url"]) != normalise_link($server_url));
|
||||
|
||||
$server_url = $user["server_url"];
|
||||
} else {
|
||||
$server_url = poco_detect_server($user["url"]);
|
||||
}
|
||||
if (($server_url == "") OR poco_check_server($server_url, $gcontacts[0]["network"])) {
|
||||
logger('Check user '.$user["url"]);
|
||||
poco_last_updated($user["url"], true);
|
||||
|
||||
if ((($server_url == "") AND ($user["network"] == NETWORK_FEED)) OR $force_update OR poco_check_server($server_url, $user["network"])) {
|
||||
logger('Check profile '.$user["url"]);
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "check_profile", base64_encode($user["url"]));
|
||||
|
||||
if (++$checked > 100) {
|
||||
return;
|
||||
@@ -171,6 +186,11 @@ function discover_users() {
|
||||
q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(datetime_convert()), dbesc(normalise_link($user["url"])));
|
||||
}
|
||||
|
||||
// Quit the loop after 3 minutes
|
||||
if (time() > ($starttime + 180)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +237,14 @@ function discover_directory($search) {
|
||||
if ($data["network"] == NETWORK_DFRN) {
|
||||
logger("Profile ".$jj->url." is reachable (".$search.")", LOGGER_DEBUG);
|
||||
logger("Add profile ".$jj->url." to local directory (".$search.")", LOGGER_DEBUG);
|
||||
poco_check($data["url"], $data["name"], $data["network"], $data["photo"], "", "", "", $jj->tags, $data["addr"], "", 0);
|
||||
|
||||
if ($jj->tags != "") {
|
||||
$data["keywords"] = $jj->tags;
|
||||
}
|
||||
|
||||
$data["server_url"] = $data["baseurl"];
|
||||
|
||||
update_gcontact($data);
|
||||
} else {
|
||||
logger("Profile ".$jj->url." is not responding or no Friendica contact - but network ".$data["network"], LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
+29
-8
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* @file include/html2bbcode.php
|
||||
* @brief Converter for HTML to BBCode
|
||||
*
|
||||
*
|
||||
* Made by: ike@piratenpartei.de
|
||||
* Originally made for the syncom project: http://wiki.piratenpartei.de/Syncom
|
||||
* https://github.com/annando/Syncom
|
||||
@@ -79,16 +79,25 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb)
|
||||
return($replace);
|
||||
}
|
||||
|
||||
function _replace_code_cb($m){
|
||||
return "<code>".str_replace("\n","<br>\n",$m[1]). "</code>";
|
||||
}
|
||||
|
||||
function html2bbcode($message)
|
||||
{
|
||||
|
||||
$message = str_replace("\r", "", $message);
|
||||
|
||||
$message = preg_replace_callback("|<pre><code>([^<]*)</code></pre>|ism", "_replace_code_cb", $message);
|
||||
// Removing code blocks before the whitespace removal processing below
|
||||
$codeblocks = [];
|
||||
$message = preg_replace_callback('#<pre><code(?: class="([^"]*)")?>(.*)</code></pre>#iUs',
|
||||
function ($matches) use (&$codeblocks) {
|
||||
$return = '[codeblock-' . count($codeblocks) . ']';
|
||||
|
||||
$prefix = '[code]';
|
||||
if ($matches[1] != '') {
|
||||
$prefix = '[code=' . $matches[1] . ']';
|
||||
}
|
||||
$codeblocks[] = $prefix . $matches[2] . '[/code]';
|
||||
return $return;
|
||||
}
|
||||
, $message);
|
||||
|
||||
$message = str_replace(array(
|
||||
"<li><p>",
|
||||
@@ -232,7 +241,6 @@ function html2bbcode($message)
|
||||
node2bbcode($doc, 'audio', array('src'=>'/(.+)/'), '[audio]$1', '[/audio]');
|
||||
node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]');
|
||||
|
||||
node2bbcode($doc, 'code', array(), '[code]', '[/code]');
|
||||
node2bbcode($doc, 'key', array(), '[code]', '[/code]');
|
||||
|
||||
$message = $doc->saveHTML();
|
||||
@@ -302,6 +310,19 @@ function html2bbcode($message)
|
||||
// Handling Yahoo style of mails
|
||||
$message = str_replace('[hr][b]From:[/b]', '[quote][b]From:[/b]', $message);
|
||||
|
||||
return(trim($message));
|
||||
// Restore code blocks
|
||||
$message = preg_replace_callback('#\[codeblock-([0-9]+)\]#iU',
|
||||
function ($matches) use ($codeblocks) {
|
||||
$return = '';
|
||||
if (isset($codeblocks[intval($matches[1])])) {
|
||||
$return = $codeblocks[$matches[1]];
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
, $message);
|
||||
|
||||
$message = trim($message);
|
||||
|
||||
return $message;
|
||||
}
|
||||
?>
|
||||
|
||||
+7
-18
@@ -17,10 +17,10 @@ function oembed_replacecb($matches){
|
||||
|
||||
/**
|
||||
* @brief Get data from an URL to embed its content.
|
||||
*
|
||||
*
|
||||
* @param string $embedurl The URL from which the data should be fetched.
|
||||
* @param bool $no_rich_type If set to true rich type content won't be fetched.
|
||||
*
|
||||
*
|
||||
* @return bool|object Returns object with embed content or false if no embedable
|
||||
* content exists
|
||||
*/
|
||||
@@ -41,8 +41,8 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
|
||||
// These media files should now be caught in bbcode.php
|
||||
// left here as a fallback in case this is called from another source
|
||||
|
||||
$noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm");
|
||||
$ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION);
|
||||
$noexts = array("mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm");
|
||||
$ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);
|
||||
|
||||
|
||||
if (is_null($txt)) {
|
||||
@@ -74,21 +74,10 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
|
||||
}
|
||||
}
|
||||
|
||||
if ($txt==false || $txt=="") {
|
||||
$embedly = Config::get("system", "embedly");
|
||||
if ($embedly != "") {
|
||||
// try embedly service
|
||||
$ourl = "https://api.embed.ly/1/oembed?key=".$embedly."&url=".urlencode($embedurl);
|
||||
$txt = fetch_url($ourl);
|
||||
$txt = trim($txt);
|
||||
|
||||
logger("oembed_fetch_url: ".$txt, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
$txt=trim($txt);
|
||||
|
||||
if ($txt[0]!="{") {
|
||||
$txt='{"type":"error"}';
|
||||
if ($txt[0] != "{") {
|
||||
$txt = '{"type":"error"}';
|
||||
} else { //save in cache
|
||||
$j = json_decode($txt);
|
||||
if ($j->type != "error") {
|
||||
|
||||
+10
-8
@@ -132,9 +132,6 @@ class ostatus {
|
||||
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["alias"]),
|
||||
dbesc($contact["about"]), dbesc($contact["location"]),
|
||||
dbesc(datetime_convert()), intval($contact["id"]));
|
||||
|
||||
poco_check($contact["url"], $contact["name"], $contact["network"], $author["author-avatar"], $contact["about"], $contact["location"],
|
||||
"", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]);
|
||||
}
|
||||
|
||||
if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['avatar'])) {
|
||||
@@ -163,7 +160,9 @@ class ostatus {
|
||||
$contact["generation"] = 2;
|
||||
$contact["hide"] = false; // OStatus contacts are never hidden
|
||||
$contact["photo"] = $author["author-avatar"];
|
||||
update_gcontact($contact);
|
||||
$gcid = update_gcontact($contact);
|
||||
|
||||
link_gcontact($gcid, $contact["uid"], $contact["id"]);
|
||||
}
|
||||
|
||||
return($author);
|
||||
@@ -808,6 +807,9 @@ class ostatus {
|
||||
|
||||
/// @todo This function is totally ugly and has to be rewritten totally
|
||||
|
||||
// Import all threads or only threads that were started by our followers?
|
||||
$all_threads = !get_config('system','ostatus_full_threads');
|
||||
|
||||
$item_stored = -1;
|
||||
|
||||
$conversation_url = self::fetch_conversation($self, $conversation_url);
|
||||
@@ -816,8 +818,8 @@ class ostatus {
|
||||
// Don't do a completion on liked content
|
||||
if (((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) OR
|
||||
($item["verb"] == ACTIVITY_LIKE) OR ($conversation_url == "")) {
|
||||
$item_stored = item_store($item, true);
|
||||
return($item_stored);
|
||||
$item_stored = item_store($item, $all_threads);
|
||||
return $item_stored;
|
||||
}
|
||||
|
||||
// Get the parent
|
||||
@@ -897,7 +899,7 @@ class ostatus {
|
||||
|
||||
if (!sizeof($items)) {
|
||||
if (count($item) > 0) {
|
||||
$item_stored = item_store($item, true);
|
||||
$item_stored = item_store($item, $all_threads);
|
||||
|
||||
if ($item_stored) {
|
||||
logger("Conversation ".$conversation_url." couldn't be fetched. Item uri ".$item["uri"]." stored: ".$item_stored, LOGGER_DEBUG);
|
||||
@@ -1195,7 +1197,7 @@ class ostatus {
|
||||
}
|
||||
}
|
||||
|
||||
$item_stored = item_store($item, true);
|
||||
$item_stored = item_store($item, $all_threads);
|
||||
if ($item_stored) {
|
||||
logger("Uri ".$item["uri"]." wasn't found in conversation ".$conversation_url, LOGGER_DEBUG);
|
||||
self::store_conversation($item_stored, $conversation_url);
|
||||
|
||||
+201
-191
@@ -34,7 +34,7 @@ require_once("include/Photo.php");
|
||||
*/
|
||||
function poco_load($cid, $uid = 0, $zcid = 0, $url = null) {
|
||||
// Call the function "poco_load_worker" via the worker
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "poco_load", $cid, $uid, $zcid, base64_encode($url));
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "poco_load", intval($cid), intval($uid), intval($zcid), base64_encode($url));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,27 +159,27 @@ function poco_load_worker($cid, $uid, $zcid, $url) {
|
||||
if (isset($entry->contactType) AND ($entry->contactType >= 0))
|
||||
$contact_type = $entry->contactType;
|
||||
|
||||
// If you query a Friendica server for its profiles, the network has to be Friendica
|
||||
/// TODO It could also be a Redmatrix server
|
||||
//if ($uid == 0)
|
||||
// $network = NETWORK_DFRN;
|
||||
$gcontact = array("url" => $profile_url,
|
||||
"name" => $name,
|
||||
"network" => $network,
|
||||
"photo" => $profile_photo,
|
||||
"about" => $about,
|
||||
"location" => $location,
|
||||
"gender" => $gender,
|
||||
"keywords" => $keywords,
|
||||
"connect" => $connect_url,
|
||||
"updated" => $updated,
|
||||
"contact-type" => $contact_type,
|
||||
"generation" => $generation);
|
||||
|
||||
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid, $uid, $zcid);
|
||||
try {
|
||||
$gcontact = sanitize_gcontact($gcontact);
|
||||
$gcid = update_gcontact($gcontact);
|
||||
|
||||
$gcontact = array("url" => $profile_url, "contact-type" => $contact_type, "generation" => $generation);
|
||||
update_gcontact($gcontact);
|
||||
|
||||
// Update the Friendica contacts. Diaspora is doing it via a message. (See include/diaspora.php)
|
||||
// Deactivated because we now update Friendica contacts in dfrn.php
|
||||
//if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
|
||||
// q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
|
||||
// WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
|
||||
// dbesc($location),
|
||||
// dbesc($about),
|
||||
// dbesc($keywords),
|
||||
// dbesc($gender),
|
||||
// dbesc(normalise_link($profile_url)),
|
||||
// dbesc(NETWORK_DFRN));
|
||||
link_gcontact($gcid, $uid, $cid, $zcid);
|
||||
} catch (Exception $e) {
|
||||
logger($e->getMessage(), LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
logger("poco_load: loaded $total entries",LOGGER_DEBUG);
|
||||
|
||||
@@ -190,172 +190,158 @@ function poco_load_worker($cid, $uid, $zcid, $url) {
|
||||
);
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Sanitize the given gcontact data
|
||||
*
|
||||
* @param array $gcontact array with gcontact data
|
||||
* @throw Exception
|
||||
*
|
||||
* Generation:
|
||||
* 0: No definition
|
||||
* 1: Profiles on this server
|
||||
* 2: Contacts of profiles on this server
|
||||
* 3: Contacts of contacts of profiles on this server
|
||||
* 4: ...
|
||||
*
|
||||
*/
|
||||
function sanitize_gcontact($gcontact) {
|
||||
|
||||
function poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid = 0, $uid = 0, $zcid = 0) {
|
||||
if ($gcontact['url'] == "") {
|
||||
throw new Exception('URL is empty');
|
||||
}
|
||||
|
||||
// Generation:
|
||||
// 0: No definition
|
||||
// 1: Profiles on this server
|
||||
// 2: Contacts of profiles on this server
|
||||
// 3: Contacts of contacts of profiles on this server
|
||||
// 4: ...
|
||||
|
||||
$gcid = "";
|
||||
|
||||
if ($profile_url == "")
|
||||
return $gcid;
|
||||
|
||||
$urlparts = parse_url($profile_url);
|
||||
if (!isset($urlparts["scheme"]))
|
||||
return $gcid;
|
||||
$urlparts = parse_url($gcontact['url']);
|
||||
if (!isset($urlparts["scheme"])) {
|
||||
throw new Exception("This (".$gcontact['url'].") doesn't seem to be an url.");
|
||||
}
|
||||
|
||||
if (in_array($urlparts["host"], array("www.facebook.com", "facebook.com", "twitter.com",
|
||||
"identi.ca", "alpha.app.net")))
|
||||
return $gcid;
|
||||
"identi.ca", "alpha.app.net"))) {
|
||||
throw new Exception('Contact from a non federated network ignored. ('.$gcontact['url'].')');
|
||||
}
|
||||
|
||||
// Don't store the statusnet connector as network
|
||||
// We can't simply set this to NETWORK_OSTATUS since the connector could have fetched posts from friendica as well
|
||||
if ($network == NETWORK_STATUSNET)
|
||||
$network = "";
|
||||
if ($gcontact['network'] == NETWORK_STATUSNET) {
|
||||
$gcontact['network'] = "";
|
||||
}
|
||||
|
||||
// Assure that there are no parameter fragments in the profile url
|
||||
if (in_array($network, array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")))
|
||||
$profile_url = clean_contact_url($profile_url);
|
||||
if (in_array($gcontact['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) {
|
||||
$gcontact['url'] = clean_contact_url($gcontact['url']);
|
||||
}
|
||||
|
||||
$alternate = poco_alternate_ostatus_url($profile_url);
|
||||
|
||||
$orig_updated = $updated;
|
||||
$alternate = poco_alternate_ostatus_url($gcontact['url']);
|
||||
|
||||
// The global contacts should contain the original picture, not the cached one
|
||||
if (($generation != 1) AND stristr(normalise_link($profile_photo), normalise_link(App::get_baseurl()."/photo/"))) {
|
||||
$profile_photo = "";
|
||||
if (($gcontact['generation'] != 1) AND stristr(normalise_link($gcontact['photo']), normalise_link(App::get_baseurl()."/photo/"))) {
|
||||
$gcontact['photo'] = "";
|
||||
}
|
||||
|
||||
$r = q("SELECT `network` FROM `contact` WHERE `nurl` = '%s' AND `network` != '' AND `network` != '%s' LIMIT 1",
|
||||
dbesc(normalise_link($profile_url)), dbesc(NETWORK_STATUSNET)
|
||||
);
|
||||
if (dbm::is_result($r)) {
|
||||
$network = $r[0]["network"];
|
||||
}
|
||||
|
||||
if (($network == "") OR ($network == NETWORK_OSTATUS)) {
|
||||
$r = q("SELECT `network`, `url` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `network` != '' AND `network` != '%s' LIMIT 1",
|
||||
dbesc($profile_url), dbesc(normalise_link($profile_url)), dbesc(NETWORK_STATUSNET)
|
||||
if (!isset($gcontact['network'])) {
|
||||
$r = q("SELECT `network` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s' AND `network` != '' AND `network` != '%s' LIMIT 1",
|
||||
dbesc(normalise_link($gcontact['url'])), dbesc(NETWORK_STATUSNET)
|
||||
);
|
||||
if (dbm::is_result($r)) {
|
||||
$network = $r[0]["network"];
|
||||
//$profile_url = $r[0]["url"];
|
||||
$gcontact['network'] = $r[0]["network"];
|
||||
}
|
||||
|
||||
if (($gcontact['network'] == "") OR ($gcontact['network'] == NETWORK_OSTATUS)) {
|
||||
$r = q("SELECT `network`, `url` FROM `contact` WHERE `uid` = 0 AND `alias` IN ('%s', '%s') AND `network` != '' AND `network` != '%s' LIMIT 1",
|
||||
dbesc($gcontact['url']), dbesc(normalise_link($gcontact['url'])), dbesc(NETWORK_STATUSNET)
|
||||
);
|
||||
if (dbm::is_result($r)) {
|
||||
$gcontact['network'] = $r[0]["network"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$gcontact['server_url'] = '';
|
||||
$gcontact['network'] = '';
|
||||
|
||||
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
|
||||
dbesc(normalise_link($profile_url))
|
||||
dbesc(normalise_link($gcontact['url']))
|
||||
);
|
||||
|
||||
if (count($x)) {
|
||||
if (($network == "") AND ($x[0]["network"] != NETWORK_STATUSNET)) {
|
||||
$network = $x[0]["network"];
|
||||
if (!isset($gcontact['network']) AND ($x[0]["network"] != NETWORK_STATUSNET)) {
|
||||
$gcontact['network'] = $x[0]["network"];
|
||||
}
|
||||
if ($updated <= NULL_DATE) {
|
||||
$updated = $x[0]["updated"];
|
||||
if ($gcontact['updated'] <= NULL_DATE) {
|
||||
$gcontact['updated'] = $x[0]["updated"];
|
||||
}
|
||||
if (!isset($gcontact['server_url']) AND (normalise_link($x[0]["server_url"]) != normalise_link($x[0]["url"]))) {
|
||||
$gcontact['server_url'] = $x[0]["server_url"];
|
||||
}
|
||||
if (!isset($gcontact['addr'])) {
|
||||
$gcontact['addr'] = $x[0]["addr"];
|
||||
}
|
||||
$created = $x[0]["created"];
|
||||
$server_url = $x[0]["server_url"];
|
||||
$nick = $x[0]["nick"];
|
||||
$addr = $x[0]["addr"];
|
||||
$alias = $x[0]["alias"];
|
||||
$notify = $x[0]["notify"];
|
||||
} else {
|
||||
$created = NULL_DATE;
|
||||
$server_url = "";
|
||||
|
||||
$urlparts = parse_url($profile_url);
|
||||
$nick = end(explode("/", $urlparts["path"]));
|
||||
$addr = "";
|
||||
$alias = "";
|
||||
$notify = "";
|
||||
}
|
||||
|
||||
if ((($network == "") OR ($name == "") OR ($addr == "") OR ($profile_photo == "") OR ($server_url == "") OR $alternate)
|
||||
AND poco_reachable($profile_url, $server_url, $network, false)) {
|
||||
$data = probe_url($profile_url);
|
||||
if ((!isset($gcontact['network']) OR !isset($gcontact['name']) OR !isset($gcontact['addr']) OR !isset($gcontact['photo']) OR !isset($gcontact['server_url']) OR $alternate)
|
||||
AND poco_reachable($gcontact['url'], $gcontact['server_url'], $gcontact['network'], false)) {
|
||||
$data = Probe::uri($gcontact['url']);
|
||||
|
||||
$orig_profile = $profile_url;
|
||||
if ($data["network"] == NETWORK_PHANTOM) {
|
||||
throw new Exception('Probing for URL '.$gcontact['url'].' failed');
|
||||
}
|
||||
|
||||
$network = $data["network"];
|
||||
$name = $data["name"];
|
||||
$nick = $data["nick"];
|
||||
$addr = $data["addr"];
|
||||
$alias = $data["alias"];
|
||||
$notify = $data["notify"];
|
||||
$profile_url = $data["url"];
|
||||
$profile_photo = $data["photo"];
|
||||
$server_url = $data["baseurl"];
|
||||
$orig_profile = $gcontact['url'];
|
||||
|
||||
if ($alternate AND ($network == NETWORK_OSTATUS)) {
|
||||
$gcontact["server_url"] = $data["baseurl"];
|
||||
|
||||
$gcontact = array_merge($gcontact, $data);
|
||||
|
||||
if ($alternate AND ($gcontact['network'] == NETWORK_OSTATUS)) {
|
||||
// Delete the old entry - if it exists
|
||||
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($orig_profile)));
|
||||
if ($r) {
|
||||
q("DELETE FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($orig_profile)));
|
||||
q("DELETE FROM `glink` WHERE `gcid` = %d", intval($r[0]["id"]));
|
||||
}
|
||||
|
||||
// possibly create a new entry
|
||||
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid, $uid, $zcid);
|
||||
}
|
||||
}
|
||||
|
||||
if ($alternate AND ($network == NETWORK_OSTATUS))
|
||||
return $gcid;
|
||||
|
||||
if (count($x) AND ($x[0]["network"] == "") AND ($network != "")) {
|
||||
q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($network),
|
||||
dbesc(normalise_link($profile_url))
|
||||
);
|
||||
if (!isset($gcontact['name']) OR !isset($gcontact['photo'])) {
|
||||
throw new Exception('No name and photo for URL '.$gcontact['url']);
|
||||
}
|
||||
|
||||
if (($name == "") OR ($profile_photo == ""))
|
||||
return $gcid;
|
||||
if (!in_array($gcontact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
|
||||
throw new Exception('No federated network ('.$gcontact['network'].') detected for URL '.$gcontact['url']);
|
||||
}
|
||||
|
||||
if (!in_array($network, array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
|
||||
return $gcid;
|
||||
if (!isset($gcontact['server_url'])) {
|
||||
// We check the server url to be sure that it is a real one
|
||||
$server_url = poco_detect_server($gcontact['url']);
|
||||
|
||||
logger("profile-check generation: ".$generation." Network: ".$network." URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG);
|
||||
|
||||
// We check the server url to be sure that it is a real one
|
||||
$server_url2 = poco_detect_server($profile_url);
|
||||
|
||||
// We are no sure that it is a correct URL. So we use it in the future
|
||||
if ($server_url2 != "") {
|
||||
$server_url = $server_url2;
|
||||
// We are now sure that it is a correct URL. So we use it in the future
|
||||
if ($server_url != "") {
|
||||
$gcontact['server_url'] = $server_url;
|
||||
}
|
||||
}
|
||||
|
||||
// The server URL doesn't seem to be valid, so we don't store it.
|
||||
if (!poco_check_server($server_url, $network)) {
|
||||
$server_url = "";
|
||||
if (!poco_check_server($gcontact['server_url'], $gcontact['network'])) {
|
||||
$gcontact['server_url'] = "";
|
||||
}
|
||||
|
||||
$gcontact = array("url" => $profile_url,
|
||||
"addr" => $addr,
|
||||
"alias" => $alias,
|
||||
"name" => $name,
|
||||
"network" => $network,
|
||||
"photo" => $profile_photo,
|
||||
"about" => $about,
|
||||
"location" => $location,
|
||||
"gender" => $gender,
|
||||
"keywords" => $keywords,
|
||||
"server_url" => $server_url,
|
||||
"connect" => $connect_url,
|
||||
"notify" => $notify,
|
||||
"updated" => $updated,
|
||||
"generation" => $generation);
|
||||
return $gcontact;
|
||||
}
|
||||
|
||||
$gcid = update_gcontact($gcontact);
|
||||
/**
|
||||
* @brief Link the gcontact entry with user, contact and global contact
|
||||
*
|
||||
* @param integer $gcid Global contact ID
|
||||
* @param integer $cid Contact ID
|
||||
* @param integer $uid User ID
|
||||
* @param integer $zcid Global Contact ID
|
||||
* *
|
||||
*/
|
||||
function link_gcontact($gcid, $uid = 0, $cid = 0, $zcid = 0) {
|
||||
|
||||
if(!$gcid)
|
||||
return $gcid;
|
||||
if ($gcid <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d LIMIT 1",
|
||||
intval($cid),
|
||||
@@ -363,8 +349,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
|
||||
intval($gcid),
|
||||
intval($zcid)
|
||||
);
|
||||
if (! dbm::is_result($r)) {
|
||||
q("INSERT INTO `glink` (`cid`,`uid`,`gcid`,`zcid`, `updated`) VALUES (%d,%d,%d,%d, '%s') ",
|
||||
if (!dbm::is_result($r)) {
|
||||
q("INSERT INTO `glink` (`cid`, `uid`, `gcid`, `zcid`, `updated`) VALUES (%d, %d, %d, %d, '%s') ",
|
||||
intval($cid),
|
||||
intval($uid),
|
||||
intval($gcid),
|
||||
@@ -380,8 +366,6 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
|
||||
intval($zcid)
|
||||
);
|
||||
}
|
||||
|
||||
return $gcid;
|
||||
}
|
||||
|
||||
function poco_reachable($profile, $server = "", $network = "", $force = false) {
|
||||
@@ -479,15 +463,26 @@ function poco_last_updated($profile, $force = false) {
|
||||
$gcontacts = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'",
|
||||
dbesc(normalise_link($profile)));
|
||||
|
||||
if ($gcontacts[0]["created"] <= NULL_DATE) {
|
||||
q("UPDATE `gcontact` SET `created` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(datetime_convert()), dbesc(normalise_link($profile)));
|
||||
if (!dbm::is_result($gcontacts)) {
|
||||
return false;
|
||||
}
|
||||
if ($gcontacts[0]["server_url"] != "") {
|
||||
|
||||
$contact = array("url" => $profile);
|
||||
|
||||
if ($gcontacts[0]["created"] <= NULL_DATE) {
|
||||
$contact['created'] = datetime_convert();
|
||||
}
|
||||
|
||||
if ($force) {
|
||||
$server_url = normalise_link(poco_detect_server($profile));
|
||||
}
|
||||
|
||||
if (($server_url == '') AND ($gcontacts[0]["server_url"] != "")) {
|
||||
$server_url = $gcontacts[0]["server_url"];
|
||||
}
|
||||
if (($server_url == '') OR ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"])) {
|
||||
$server_url = poco_detect_server($profile);
|
||||
|
||||
if (!$force AND (($server_url == '') OR ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"]))) {
|
||||
$server_url = normalise_link(poco_detect_server($profile));
|
||||
}
|
||||
|
||||
if (!in_array($gcontacts[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_FEED, NETWORK_OSTATUS, ""))) {
|
||||
@@ -497,67 +492,64 @@ function poco_last_updated($profile, $force = false) {
|
||||
|
||||
if ($server_url != "") {
|
||||
if (!poco_check_server($server_url, $gcontacts[0]["network"], $force)) {
|
||||
|
||||
if ($force)
|
||||
if ($force) {
|
||||
q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(datetime_convert()), dbesc(normalise_link($profile)));
|
||||
}
|
||||
|
||||
logger("Profile ".$profile.": Server ".$server_url." wasn't reachable.", LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
q("UPDATE `gcontact` SET `server_url` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($server_url), dbesc(normalise_link($profile)));
|
||||
$contact['server_url'] = $server_url;
|
||||
}
|
||||
|
||||
if (in_array($gcontacts[0]["network"], array("", NETWORK_FEED))) {
|
||||
$server = q("SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''",
|
||||
dbesc(normalise_link($server_url)));
|
||||
|
||||
if ($server)
|
||||
q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($server[0]["network"]), dbesc(normalise_link($profile)));
|
||||
else
|
||||
if ($server) {
|
||||
$contact['network'] = $server[0]["network"];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// noscrape is really fast so we don't cache the call.
|
||||
if (($gcontacts[0]["server_url"] != "") AND ($gcontacts[0]["nick"] != "")) {
|
||||
if (($server_url != "") AND ($gcontacts[0]["nick"] != "")) {
|
||||
|
||||
// Use noscrape if possible
|
||||
$server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($gcontacts[0]["server_url"])));
|
||||
$server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url)));
|
||||
|
||||
if ($server) {
|
||||
$noscraperet = z_fetch_url($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
|
||||
|
||||
if ($noscraperet["success"] AND ($noscraperet["body"] != "")) {
|
||||
if ($noscraperet["success"] AND ($noscraperet["body"] != "")) {
|
||||
|
||||
$noscrape = json_decode($noscraperet["body"], true);
|
||||
|
||||
if (is_array($noscrape)) {
|
||||
$contact = array("url" => $profile,
|
||||
"network" => $server[0]["network"],
|
||||
"generation" => $gcontacts[0]["generation"]);
|
||||
$contact["network"] = $server[0]["network"];
|
||||
|
||||
if (isset($noscrape["fn"]))
|
||||
if (isset($noscrape["fn"])) {
|
||||
$contact["name"] = $noscrape["fn"];
|
||||
|
||||
if (isset($noscrape["comm"]))
|
||||
}
|
||||
if (isset($noscrape["comm"])) {
|
||||
$contact["community"] = $noscrape["comm"];
|
||||
|
||||
}
|
||||
if (isset($noscrape["tags"])) {
|
||||
$keywords = implode(" ", $noscrape["tags"]);
|
||||
if ($keywords != "")
|
||||
if ($keywords != "") {
|
||||
$contact["keywords"] = $keywords;
|
||||
}
|
||||
}
|
||||
|
||||
$location = formatted_location($noscrape);
|
||||
if ($location)
|
||||
if ($location) {
|
||||
$contact["location"] = $location;
|
||||
|
||||
if (isset($noscrape["dfrn-notify"]))
|
||||
}
|
||||
if (isset($noscrape["dfrn-notify"])) {
|
||||
$contact["notify"] = $noscrape["dfrn-notify"];
|
||||
|
||||
}
|
||||
// Remove all fields that are not present in the gcontact table
|
||||
unset($noscrape["fn"]);
|
||||
unset($noscrape["key"]);
|
||||
@@ -595,12 +587,14 @@ function poco_last_updated($profile, $force = false) {
|
||||
}
|
||||
|
||||
// If we only can poll the feed, then we only do this once a while
|
||||
if (!$force AND !poco_do_update($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) {
|
||||
if (!$force AND !poco_do_update($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) {
|
||||
logger("Profile ".$profile." was last updated at ".$gcontacts[0]["updated"]." (cached)", LOGGER_DEBUG);
|
||||
|
||||
update_gcontact($contact);
|
||||
return $gcontacts[0]["updated"];
|
||||
}
|
||||
|
||||
$data = probe_url($profile);
|
||||
$data = Probe::uri($profile);
|
||||
|
||||
// Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711)
|
||||
// Then check the other link and delete this one
|
||||
@@ -612,10 +606,18 @@ function poco_last_updated($profile, $force = false) {
|
||||
q("DELETE FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profile)));
|
||||
q("DELETE FROM `glink` WHERE `gcid` = %d", intval($gcontacts[0]["id"]));
|
||||
|
||||
poco_check($data["url"], $data["name"], $data["network"], $data["photo"], $gcontacts[0]["about"], $gcontacts[0]["location"],
|
||||
$gcontacts[0]["gender"], $gcontacts[0]["keywords"], $data["addr"], $gcontacts[0]["updated"], $gcontacts[0]["generation"]);
|
||||
$gcontact = array_merge($gcontacts[0], $data);
|
||||
|
||||
poco_last_updated($data["url"], $force);
|
||||
$gcontact["server_url"] = $data["baseurl"];
|
||||
|
||||
try {
|
||||
$gcontact = sanitize_gcontact($gcontact);
|
||||
update_gcontact($gcontact);
|
||||
|
||||
poco_last_updated($data["url"], $force);
|
||||
} catch (Exception $e) {
|
||||
logger($e->getMessage(), LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
logger("Profile ".$profile." was deleted", LOGGER_DEBUG);
|
||||
return false;
|
||||
@@ -629,21 +631,10 @@ function poco_last_updated($profile, $force = false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$contact = array("generation" => $gcontacts[0]["generation"]);
|
||||
|
||||
$contact = array_merge($contact, $data);
|
||||
|
||||
$contact["server_url"] = $data["baseurl"];
|
||||
|
||||
unset($contact["batch"]);
|
||||
unset($contact["poll"]);
|
||||
unset($contact["request"]);
|
||||
unset($contact["confirm"]);
|
||||
unset($contact["poco"]);
|
||||
unset($contact["priority"]);
|
||||
unset($contact["pubkey"]);
|
||||
unset($contact["baseurl"]);
|
||||
|
||||
update_gcontact($contact);
|
||||
|
||||
$feedret = z_fetch_url($data["poll"]);
|
||||
@@ -686,9 +677,10 @@ function poco_last_updated($profile, $force = false) {
|
||||
q("UPDATE `gcontact` SET `updated` = '%s', `last_contact` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(dbm::date($last_updated)), dbesc(dbm::date()), dbesc(normalise_link($profile)));
|
||||
|
||||
if (($gcontacts[0]["generation"] == 0))
|
||||
if (($gcontacts[0]["generation"] == 0)) {
|
||||
q("UPDATE `gcontact` SET `generation` = 9 WHERE `nurl` = '%s'",
|
||||
dbesc(normalise_link($profile)));
|
||||
}
|
||||
|
||||
logger("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
|
||||
|
||||
@@ -1769,7 +1761,7 @@ function poco_discover($complete = false) {
|
||||
}
|
||||
|
||||
logger('Update directory from server '.$server['url'].' with ID '.$server['id'], LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server_directory", $server['id']);
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server_directory", intval($server['id']));
|
||||
|
||||
if (!$complete AND (--$no_of_queries == 0)) {
|
||||
break;
|
||||
@@ -1889,10 +1881,26 @@ function poco_discover_server($data, $default_generation = 0) {
|
||||
$success = true;
|
||||
|
||||
logger("Store profile ".$profile_url, LOGGER_DEBUG);
|
||||
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, 0, 0, 0);
|
||||
|
||||
$gcontact = array("url" => $profile_url, "contact-type" => $contact_type, "generation" => $generation);
|
||||
update_gcontact($gcontact);
|
||||
$gcontact = array("url" => $profile_url,
|
||||
"name" => $name,
|
||||
"network" => $network,
|
||||
"photo" => $profile_photo,
|
||||
"about" => $about,
|
||||
"location" => $location,
|
||||
"gender" => $gender,
|
||||
"keywords" => $keywords,
|
||||
"connect" => $connect_url,
|
||||
"updated" => $updated,
|
||||
"contact-type" => $contact_type,
|
||||
"generation" => $generation);
|
||||
|
||||
try {
|
||||
$gcontact = sanitize_gcontact($gcontact);
|
||||
update_gcontact($gcontact);
|
||||
} catch (Exception $e) {
|
||||
logger($e->getMessage(), LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
logger("Done for profile ".$profile_url, LOGGER_DEBUG);
|
||||
}
|
||||
@@ -2187,6 +2195,8 @@ function update_gcontact_from_probe($url) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data["server_url"] = $data["baseurl"];
|
||||
|
||||
update_gcontact($data);
|
||||
}
|
||||
|
||||
|
||||
+1
-18
@@ -97,13 +97,6 @@ function create_user($arr) {
|
||||
if(mb_strlen($username) < 3)
|
||||
$result['message'] .= t('Name too short.') . EOL;
|
||||
|
||||
// I don't really like having this rule, but it cuts down
|
||||
// on the number of auto-registrations by Russian spammers
|
||||
|
||||
// Using preg_match was completely unreliable, due to mixed UTF-8 regex support
|
||||
// $no_utf = get_config('system','no_utf');
|
||||
// $pat = (($no_utf) ? '/^[a-zA-Z]* [a-zA-Z]*$/' : '/^\p{L}* \p{L}*$/u' );
|
||||
|
||||
// So now we are just looking for a space in the full name.
|
||||
|
||||
$loose_reg = get_config('system','no_regfullname');
|
||||
@@ -182,17 +175,7 @@ function create_user($arr) {
|
||||
$prvkey = $keys['prvkey'];
|
||||
$pubkey = $keys['pubkey'];
|
||||
|
||||
/**
|
||||
*
|
||||
* Create another keypair for signing/verifying
|
||||
* salmon protocol messages. We have to use a slightly
|
||||
* less robust key because this won't be using openssl
|
||||
* but the phpseclib. Since it is PHP interpreted code
|
||||
* it is not nearly as efficient, and the larger keys
|
||||
* will take several minutes each to process.
|
||||
*
|
||||
*/
|
||||
|
||||
// Create another keypair for signing/verifying salmon protocol messages.
|
||||
$sres = new_keypair(512);
|
||||
$sprvkey = $sres['prvkey'];
|
||||
$spubkey = $sres['pubkey'];
|
||||
|
||||
Reference in New Issue
Block a user