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