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-04-30 00:01:26 -04:00
|
|
|
use Friendica\Core\Config;
|
2018-10-29 17:20:46 -04:00
|
|
|
use Friendica\Core\Logger;
|
2018-07-19 22:15:21 -04:00
|
|
|
use Friendica\Core\System;
|
2018-07-20 08:19:26 -04:00
|
|
|
use Friendica\Database\DBA;
|
2018-01-26 23:09:48 -05:00
|
|
|
use Friendica\Util\Network;
|
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
|
|
|
|
2018-07-15 15:04:48 -04:00
|
|
|
$nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED;
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-07-07 17:46:30 -04:00
|
|
|
$nodeinfo['metadata'] = ['nodeName' => Config::get('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('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('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';
|
|
|
|
}
|
2018-07-14 12:08:06 -04:00
|
|
|
|
|
|
|
$nodeinfo['metadata']['explicitContent'] = Config::get('system', 'explicit_content', false) == true;
|
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-05-22 16:10:18 -04:00
|
|
|
// If the addon 'statistics_json' is enabled then disable it and activate 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
|
|
|
}
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-10-29 17:20:46 -04:00
|
|
|
Logger::log('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)) {
|
2018-05-22 16:10:18 -04:00
|
|
|
$total_users = count($users);
|
|
|
|
$active_users_halfyear = 0;
|
|
|
|
$active_users_monthly = 0;
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-05-22 16:10:18 -04:00
|
|
|
$halfyear = time() - (180 * 24 * 60 * 60);
|
|
|
|
$month = time() - (30 * 24 * 60 * 60);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-05-22 16:10:18 -04:00
|
|
|
foreach ($users AS $user) {
|
|
|
|
if ((strtotime($user['login_date']) > $halfyear) ||
|
|
|
|
(strtotime($user['last-item']) > $halfyear)) {
|
|
|
|
++$active_users_halfyear;
|
|
|
|
}
|
|
|
|
if ((strtotime($user['login_date']) > $month) ||
|
|
|
|
(strtotime($user['last-item']) > $month)) {
|
|
|
|
++$active_users_monthly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Config::set('nodeinfo', 'total_users', $total_users);
|
|
|
|
Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
|
|
|
|
Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
|
2016-12-10 07:28:49 -05:00
|
|
|
|
2018-10-30 09:58:45 -04:00
|
|
|
Logger::log('total_users: ' . $total_users . '/' . $active_users_halfyear. '/' . $active_users_monthly, Logger::DEBUG);
|
2017-03-26 08:51:25 -04:00
|
|
|
}
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-07-20 08:19:26 -04:00
|
|
|
$local_posts = DBA::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]);
|
2018-05-22 16:10:18 -04:00
|
|
|
Config::set('nodeinfo', 'local_posts', $local_posts);
|
2018-10-30 09:58:45 -04:00
|
|
|
Logger::log('local_posts: ' . $local_posts, Logger::DEBUG);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-07-20 08:19:26 -04:00
|
|
|
$local_comments = DBA::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]);
|
2017-03-26 08:51:25 -04:00
|
|
|
Config::set('nodeinfo', 'local_comments', $local_comments);
|
2018-10-30 09:58:45 -04:00
|
|
|
Logger::log('local_comments: ' . $local_comments, Logger::DEBUG);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
|
|
|
// Now trying to register
|
2018-10-09 13:58:58 -04:00
|
|
|
$url = 'http://the-federation.info/register/'.$a->getHostName();
|
2018-10-30 09:58:45 -04:00
|
|
|
Logger::log('registering url: '.$url, Logger::DEBUG);
|
2018-01-27 11:13:41 -05:00
|
|
|
$ret = Network::fetchUrl($url);
|
2018-10-30 09:58:45 -04:00
|
|
|
Logger::log('registering answer: '.$ret, Logger::DEBUG);
|
2015-08-10 15:33:57 -04:00
|
|
|
|
2018-10-29 17:20:46 -04:00
|
|
|
Logger::log('cron_end');
|
2015-08-10 15:33:57 -04:00
|
|
|
}
|