2015-08-10 15:33:57 -04:00
|
|
|
<?php
|
2015-11-11 16:41:44 -05:00
|
|
|
/**
|
2015-11-11 15:37:16 -05:00
|
|
|
* @file mod/nodeinfo.php
|
2017-01-09 07:14:25 -05:00
|
|
|
*
|
2015-11-11 15:37:16 -05:00
|
|
|
* Documentation: http://nodeinfo.diaspora.software/schema.html
|
2015-08-10 15:33:57 -04:00
|
|
|
*/
|
|
|
|
|
2017-04-30 00:07:00 -04:00
|
|
|
use Friendica\App;
|
2018-01-17 13:42:40 -05:00
|
|
|
use Friendica\Core\Addon;
|
2017-08-26 02:04:21 -04:00
|
|
|
use Friendica\Core\System;
|
2017-04-30 00:01:26 -04:00
|
|
|
use Friendica\Core\Config;
|
2018-01-26 23:09:48 -05:00
|
|
|
use Friendica\Util\Network;
|
2017-03-26 08:51:25 -04:00
|
|
|
|
2017-01-09 07:14:25 -05:00
|
|
|
function nodeinfo_wellknown(App $a) {
|
2018-01-15 08:05:12 -05:00
|
|
|
$nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
|
|
|
|
'href' => System::baseUrl().'/nodeinfo/1.0']]];
|
2015-08-10 15:33:57 -04:00
|
|
|
|
|
|
|
header('Content-type: application/json; charset=utf-8');
|
2015-08-10 15:54:57 -04:00
|
|
|
echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
2015-08-10 15:33:57 -04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-01-09 07:14:25 -05:00
|
|
|
function nodeinfo_init(App $a) {
|
2017-03-26 08:51:25 -04:00
|
|
|
if (!Config::get('system', 'nodeinfo')) {
|
2018-01-27 11:59:10 -05:00
|
|
|
System::httpExit(404);
|
2015-08-10 15:33:57 -04:00
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
2017-06-07 22:00:59 -04:00
|
|
|
if (($a->argc != 2) || ($a->argv[1] != '1.0')) {
|
2018-01-27 11:59:10 -05:00
|
|
|
System::httpExit(404);
|
2015-08-10 15:33:57 -04:00
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
2017-06-07 22:00:59 -04:00
|
|
|
$smtp = (function_exists('imap_open') && !Config::get('system', 'imap_disabled') && !Config::get('system', 'dfrn_only'));
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
$nodeinfo = [];
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['version'] = '1.0';
|
2018-01-15 08:05:12 -05:00
|
|
|
$nodeinfo['software'] = ['name' => 'friendica', 'version' => FRIENDICA_VERSION.'-'.DB_UPDATE_VERSION];
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
$nodeinfo['protocols'] = [];
|
|
|
|
$nodeinfo['protocols']['inbound'] = [];
|
|
|
|
$nodeinfo['protocols']['outbound'] = [];
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
if (Config::get('system', 'diaspora_enabled')) {
|
|
|
|
$nodeinfo['protocols']['inbound'][] = 'diaspora';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'diaspora';
|
2015-08-10 15:33:57 -04:00
|
|
|
}
|
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['protocols']['inbound'][] = 'friendica';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'friendica';
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
if (!Config::get('system', 'ostatus_disabled')) {
|
|
|
|
$nodeinfo['protocols']['inbound'][] = 'gnusocial';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'gnusocial';
|
2015-08-10 15:33:57 -04:00
|
|
|
}
|
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
$nodeinfo['services'] = [];
|
|
|
|
$nodeinfo['services']['inbound'] = [];
|
|
|
|
$nodeinfo['services']['outbound'] = [];
|
2015-08-24 01:47:42 -04:00
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
$nodeinfo['usage'] = [];
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['openRegistrations'] = ($a->config['register_policy'] != 0);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
$nodeinfo['metadata'] = ['nodeName' => $a->config['sitename']];
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
if (Config::get('system', 'nodeinfo')) {
|
2015-08-10 18:37:27 -04:00
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
$nodeinfo['usage']['users'] = ['total' => (int)Config::get('nodeinfo', 'total_users'),
|
2017-03-26 08:51:25 -04:00
|
|
|
'activeHalfyear' => (int)Config::get('nodeinfo', 'active_users_halfyear'),
|
2018-01-15 08:05:12 -05:00
|
|
|
'activeMonth' => (int)Config::get('nodeinfo', 'active_users_monthly')];
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['usage']['localPosts'] = (int)Config::get('nodeinfo', 'local_posts');
|
|
|
|
$nodeinfo['usage']['localComments'] = (int)Config::get('nodeinfo', 'local_comments');
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('appnet')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['inbound'][] = 'appnet';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('appnet') || Addon::isEnabled('buffer')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'appnet';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('blogger')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'blogger';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('dwpost')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'dreamwidth';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('fbpost') || Addon::isEnabled('buffer')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'facebook';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('statusnet')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['inbound'][] = 'gnusocial';
|
|
|
|
$nodeinfo['services']['outbound'][] = 'gnusocial';
|
|
|
|
}
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('gpluspost') || Addon::isEnabled('buffer')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'google';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('ijpost')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'insanejournal';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('libertree')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'libertree';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('buffer')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'linkedin';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('ljpost')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'livejournal';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('buffer')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'pinterest';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('posterous')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'posterous';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('pumpio')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['inbound'][] = 'pumpio';
|
|
|
|
$nodeinfo['services']['outbound'][] = 'pumpio';
|
|
|
|
}
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
if ($smtp) {
|
|
|
|
$nodeinfo['services']['outbound'][] = 'smtp';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('tumblr')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'tumblr';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'twitter';
|
|
|
|
}
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('wppost')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['services']['outbound'][] = 'wordpress';
|
|
|
|
}
|
|
|
|
$nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
|
|
|
|
$nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
|
|
|
|
$nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
|
|
|
|
$nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
|
2015-08-10 18:37:27 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['metadata']['services'] = $nodeinfo['services'];
|
2015-08-10 18:37:27 -04:00
|
|
|
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('twitter')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
$nodeinfo['metadata']['services']['inbound'][] = 'twitter';
|
|
|
|
}
|
2015-08-24 01:47:42 -04:00
|
|
|
}
|
2015-08-10 15:33:57 -04:00
|
|
|
|
|
|
|
header('Content-type: application/json; charset=utf-8');
|
2015-08-10 15:54:57 -04:00
|
|
|
echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
2015-08-10 15:33:57 -04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2016-02-07 09:11:34 -05:00
|
|
|
|
|
|
|
|
2015-08-10 15:33:57 -04:00
|
|
|
function nodeinfo_cron() {
|
2015-08-11 17:50:31 -04:00
|
|
|
|
|
|
|
$a = get_app();
|
|
|
|
|
2018-01-17 14:22:38 -05:00
|
|
|
// If the addon 'statistics_json' is enabled then disable it and actrivate nodeinfo.
|
2018-01-17 13:42:40 -05:00
|
|
|
if (Addon::isEnabled('statistics_json')) {
|
2017-03-26 08:51:25 -04:00
|
|
|
Config::set('system', 'nodeinfo', true);
|
2015-08-16 15:45:51 -04:00
|
|
|
|
2018-01-17 14:22:38 -05:00
|
|
|
$addon = 'statistics_json';
|
|
|
|
$addons = Config::get('system', 'addon');
|
|
|
|
$addons_arr = [];
|
2015-08-16 15:45:51 -04:00
|
|
|
|
2018-01-17 14:22:38 -05:00
|
|
|
if ($addons) {
|
|
|
|
$addons_arr = explode(',',str_replace(' ', '',$addons));
|
2015-08-16 15:45:51 -04:00
|
|
|
|
2018-01-17 14:22:38 -05:00
|
|
|
$idx = array_search($addon, $addons_arr);
|
2017-03-26 08:51:25 -04:00
|
|
|
if ($idx !== false) {
|
2018-01-17 14:22:38 -05:00
|
|
|
unset($addons_arr[$idx]);
|
|
|
|
Addon::uninstall($addon);
|
|
|
|
Config::set('system', 'addon', implode(', ',$addons_arr));
|
2015-08-16 15:45:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
if (!Config::get('system', 'nodeinfo')) {
|
2015-08-10 15:33:57 -04:00
|
|
|
return;
|
2017-03-26 08:51:25 -04:00
|
|
|
}
|
|
|
|
$last = Config::get('nodeinfo', 'last_calucation');
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
if ($last) {
|
2015-08-10 15:33:57 -04:00
|
|
|
// Calculate every 24 hours
|
|
|
|
$next = $last + (24 * 60 * 60);
|
2017-03-26 08:51:25 -04:00
|
|
|
if ($next > time()) {
|
|
|
|
logger('calculation intervall not reached');
|
2015-08-10 15:33:57 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-03-26 08:51:25 -04:00
|
|
|
logger('cron_start');
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-09-15 17:00:39 -04:00
|
|
|
$users = q("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
|
2016-10-03 23:51:13 -04:00
|
|
|
FROM `user`
|
|
|
|
INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
|
2016-10-14 01:45:32 -04:00
|
|
|
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
|
2016-10-03 23:51:13 -04:00
|
|
|
WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
|
|
|
|
AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
|
|
|
|
AND NOT `user`.`account_expired`");
|
2015-08-10 15:33:57 -04:00
|
|
|
if (is_array($users)) {
|
|
|
|
$total_users = count($users);
|
|
|
|
$active_users_halfyear = 0;
|
|
|
|
$active_users_monthly = 0;
|
|
|
|
|
|
|
|
$halfyear = time() - (180 * 24 * 60 * 60);
|
|
|
|
$month = time() - (30 * 24 * 60 * 60);
|
|
|
|
|
|
|
|
foreach ($users AS $user) {
|
2017-06-07 22:00:59 -04:00
|
|
|
if ((strtotime($user['login_date']) > $halfyear) ||
|
2017-03-26 08:51:25 -04:00
|
|
|
(strtotime($user['last-item']) > $halfyear)) {
|
2015-08-10 15:33:57 -04:00
|
|
|
++$active_users_halfyear;
|
2017-03-26 08:51:25 -04:00
|
|
|
}
|
2017-06-07 22:00:59 -04:00
|
|
|
if ((strtotime($user['login_date']) > $month) ||
|
2017-03-26 08:51:25 -04:00
|
|
|
(strtotime($user['last-item']) > $month)) {
|
2015-08-10 15:33:57 -04:00
|
|
|
++$active_users_monthly;
|
2017-03-26 08:51:25 -04:00
|
|
|
}
|
2015-08-10 15:33:57 -04:00
|
|
|
}
|
2017-03-26 08:51:25 -04:00
|
|
|
Config::set('nodeinfo', 'total_users', $total_users);
|
|
|
|
logger('total_users: '.$total_users, LOGGER_DEBUG);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
|
|
|
|
Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
|
2015-08-10 15:33:57 -04:00
|
|
|
}
|
|
|
|
|
2017-10-18 12:54:12 -04:00
|
|
|
$posts = q("SELECT COUNT(*) AS `local_posts` FROM `thread` WHERE `thread`.`wall` AND `thread`.`uid` != 0");
|
2016-12-10 07:28:49 -05:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
if (!is_array($posts)) {
|
2015-08-10 15:33:57 -04:00
|
|
|
$local_posts = -1;
|
2017-03-26 08:51:25 -04:00
|
|
|
} else {
|
|
|
|
$local_posts = $posts[0]['local_posts'];
|
|
|
|
}
|
|
|
|
Config::set('nodeinfo', 'local_posts', $local_posts);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
logger('local_posts: '.$local_posts, LOGGER_DEBUG);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-10-18 12:54:12 -04:00
|
|
|
$posts = q("SELECT COUNT(*) AS `local_comments` FROM `contact`
|
2017-02-04 11:16:15 -05:00
|
|
|
INNER JOIN `item` ON `item`.`contact-id` = `contact`.`id` AND `item`.`uid` = `contact`.`uid` AND
|
|
|
|
`item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')
|
|
|
|
WHERE `contact`.`self`",
|
2015-08-10 15:33:57 -04:00
|
|
|
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
|
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
if (!is_array($posts)) {
|
2015-08-10 15:33:57 -04:00
|
|
|
$local_comments = -1;
|
2017-03-26 08:51:25 -04:00
|
|
|
} else {
|
|
|
|
$local_comments = $posts[0]['local_comments'];
|
|
|
|
}
|
|
|
|
Config::set('nodeinfo', 'local_comments', $local_comments);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
|
|
|
// Now trying to register
|
2017-03-26 08:51:25 -04:00
|
|
|
$url = 'http://the-federation.info/register/'.$a->get_hostname();
|
2015-08-11 04:23:33 -04:00
|
|
|
logger('registering url: '.$url, LOGGER_DEBUG);
|
2018-01-27 11:13:41 -05:00
|
|
|
$ret = Network::fetchUrl($url);
|
2015-08-11 04:23:33 -04:00
|
|
|
logger('registering answer: '.$ret, LOGGER_DEBUG);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2017-03-26 08:51:25 -04:00
|
|
|
logger('cron_end');
|
|
|
|
Config::set('nodeinfo', 'last_calucation', time());
|
2015-08-10 15:33:57 -04:00
|
|
|
}
|