Merge branch 'bug/phpinfo-accessible-hotfix' into develop
[friendica.git/.git] / src / Module / Admin / Site.php
index 2e16cc6..a39c0c9 100644 (file)
@@ -28,10 +28,10 @@ use Friendica\Core\Theme;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Model\GContact;
+use Friendica\Model\Contact;
+use Friendica\Model\User;
 use Friendica\Module\BaseAdmin;
 use Friendica\Module\Register;
-use Friendica\Protocol\PortableContact;
 use Friendica\Util\BasePath;
 use Friendica\Util\EMailer\MailBuilder;
 use Friendica\Util\Strings;
@@ -43,7 +43,7 @@ class Site extends BaseAdmin
 {
        public static function post(array $parameters = [])
        {
-               parent::post($parameters);
+               self::checkAdminAccess();
 
                self::checkFormSecurityTokenRedirectOnError('/admin/site', 'admin_site');
 
@@ -104,12 +104,10 @@ class Site extends BaseAdmin
                        // update profile links in the format "http://server.tld"
                        update_table($a, "profile", ['photo', 'thumb'], $old_url, $new_url);
                        update_table($a, "contact", ['photo', 'thumb', 'micro', 'url', 'nurl', 'alias', 'request', 'notify', 'poll', 'confirm', 'poco', 'avatar'], $old_url, $new_url);
-                       update_table($a, "gcontact", ['url', 'nurl', 'photo', 'server_url', 'notify', 'alias'], $old_url, $new_url);
                        update_table($a, "item", ['owner-link', 'author-link', 'body', 'plink', 'tag'], $old_url, $new_url);
 
                        // update profile addresses in the format "user@server.tld"
                        update_table($a, "contact", ['addr'], $old_host, $new_host);
-                       update_table($a, "gcontact", ['connect', 'addr'], $old_host, $new_host);
 
                        // update config
                        DI::config()->set('system', 'url', $new_url);
@@ -122,7 +120,7 @@ class Site extends BaseAdmin
                        }
                        DBA::close($usersStmt);
 
-                       info("Relocation started. Could take a while to complete.");
+                       info(DI::l10n()->t("Relocation started. Could take a while to complete."));
 
                        DI::baseUrl()->redirect('admin/site');
                }
@@ -151,6 +149,7 @@ class Site extends BaseAdmin
                $allowed_sites          = (!empty($_POST['allowed_sites'])           ? Strings::escapeTags(trim($_POST['allowed_sites']))  : '');
                $allowed_email          = (!empty($_POST['allowed_email'])           ? Strings::escapeTags(trim($_POST['allowed_email']))  : '');
                $forbidden_nicknames    = (!empty($_POST['forbidden_nicknames'])     ? strtolower(Strings::escapeTags(trim($_POST['forbidden_nicknames']))) : '');
+               $system_actor_name      = (!empty($_POST['system_actor_name'])       ? Strings::escapeTags(trim($_POST['system_actor_name'])) : '');
                $no_oembed_rich_content = !empty($_POST['no_oembed_rich_content']);
                $allowed_oembed         = (!empty($_POST['allowed_oembed'])          ? Strings::escapeTags(trim($_POST['allowed_oembed'])) : '');
                $block_public           = !empty($_POST['block_public']);
@@ -176,13 +175,11 @@ class Site extends BaseAdmin
                $maxloadavg             = (!empty($_POST['maxloadavg'])             ? intval(trim($_POST['maxloadavg']))             : 20);
                $maxloadavg_frontend    = (!empty($_POST['maxloadavg_frontend'])    ? intval(trim($_POST['maxloadavg_frontend']))    : 50);
                $min_memory             = (!empty($_POST['min_memory'])             ? intval(trim($_POST['min_memory']))             : 0);
-               $optimize_max_tablesize = (!empty($_POST['optimize_max_tablesize']) ? intval(trim($_POST['optimize_max_tablesize'])) : 100);
-               $optimize_fragmentation = (!empty($_POST['optimize_fragmentation']) ? intval(trim($_POST['optimize_fragmentation'])) : 30);
-               $poco_completion        = (!empty($_POST['poco_completion'])        ? intval(trim($_POST['poco_completion']))        : false);
-               $gcontact_discovery     = (!empty($_POST['gcontact_discovery'])     ? intval(trim($_POST['gcontact_discovery']))     : GContact::DISCOVERY_NONE);
+               $optimize_tables        = (!empty($_POST['optimize_tables'])        ? intval(trim($_POST['optimize_tables']))        : false);
+               $contact_discovery      = (!empty($_POST['contact_discovery'])      ? intval(trim($_POST['contact_discovery']))      : Contact\Relation::DISCOVERY_NONE);
+               $synchronize_directory  = (!empty($_POST['synchronize_directory'])  ? intval(trim($_POST['synchronize_directory']))  : false);
                $poco_requery_days      = (!empty($_POST['poco_requery_days'])      ? intval(trim($_POST['poco_requery_days']))      : 7);
-               $poco_discovery         = (!empty($_POST['poco_discovery'])         ? intval(trim($_POST['poco_discovery']))         : PortableContact::DISABLED);
-               $poco_discovery_since   = (!empty($_POST['poco_discovery_since'])   ? intval(trim($_POST['poco_discovery_since']))   : 30);
+               $poco_discovery         = (!empty($_POST['poco_discovery'])         ? intval(trim($_POST['poco_discovery']))         : false);
                $poco_local_search      = !empty($_POST['poco_local_search']);
                $nodeinfo               = !empty($_POST['nodeinfo']);
                $dfrn_only              = !empty($_POST['dfrn_only']);
@@ -250,7 +247,7 @@ class Site extends BaseAdmin
                                DI::baseUrl()->redirect('admin/site' . $active_panel);
                        }
                } else {
-                       info(DI::l10n()->t('Invalid storage backend setting value.'));
+                       notice(DI::l10n()->t('Invalid storage backend setting value.'));
                }
 
                // Has the directory url changed? If yes, then resubmit the existing profiles there
@@ -305,13 +302,11 @@ class Site extends BaseAdmin
                DI::config()->set('system', 'maxloadavg'            , $maxloadavg);
                DI::config()->set('system', 'maxloadavg_frontend'   , $maxloadavg_frontend);
                DI::config()->set('system', 'min_memory'            , $min_memory);
-               DI::config()->set('system', 'optimize_max_tablesize', $optimize_max_tablesize);
-               DI::config()->set('system', 'optimize_fragmentation', $optimize_fragmentation);
-               DI::config()->set('system', 'poco_completion'       , $poco_completion);
-               DI::config()->set('system', 'gcontact_discovery'    , $gcontact_discovery);
+               DI::config()->set('system', 'optimize_tables'       , $optimize_tables);
+               DI::config()->set('system', 'contact_discovery'     , $contact_discovery);
+               DI::config()->set('system', 'synchronize_directory' , $synchronize_directory);
                DI::config()->set('system', 'poco_requery_days'     , $poco_requery_days);
                DI::config()->set('system', 'poco_discovery'        , $poco_discovery);
-               DI::config()->set('system', 'poco_discovery_since'  , $poco_discovery_since);
                DI::config()->set('system', 'poco_local_search'     , $poco_local_search);
                DI::config()->set('system', 'nodeinfo'              , $nodeinfo);
                DI::config()->set('config', 'sitename'              , $sitename);
@@ -362,6 +357,7 @@ class Site extends BaseAdmin
                DI::config()->set('system', 'allowed_sites'          , $allowed_sites);
                DI::config()->set('system', 'allowed_email'          , $allowed_email);
                DI::config()->set('system', 'forbidden_nicknames'    , $forbidden_nicknames);
+               DI::config()->set('system', 'system_actor_name'      , $system_actor_name);
                DI::config()->set('system', 'no_oembed_rich_content' , $no_oembed_rich_content);
                DI::config()->set('system', 'allowed_oembed'         , $allowed_oembed);
                DI::config()->set('system', 'block_public'           , $block_public);
@@ -433,8 +429,6 @@ class Site extends BaseAdmin
 
                DI::config()->set('system', 'rino_encrypt'     , $rino);
 
-               info(DI::l10n()->t('Site settings updated.') . EOL);
-
                DI::baseUrl()->redirect('admin/site' . $active_panel);
        }
 
@@ -490,20 +484,6 @@ class Site extends BaseAdmin
                        CP_USERS_AND_GLOBAL => DI::l10n()->t('Public postings from local users and the federated network')
                ];
 
-               $poco_discovery_choices = [
-                       PortableContact::DISABLED => DI::l10n()->t('Disabled'),
-                       PortableContact::USERS => DI::l10n()->t('Users'),
-                       PortableContact::USERS_GCONTACTS => DI::l10n()->t('Users, Global Contacts'),
-                       PortableContact::USERS_GCONTACTS_FALLBACK => DI::l10n()->t('Users, Global Contacts/fallback'),
-               ];
-
-               $poco_discovery_since_choices = [
-                       '30' => DI::l10n()->t('One month'),
-                       '91' => DI::l10n()->t('Three months'),
-                       '182' => DI::l10n()->t('Half a year'),
-                       '365' => DI::l10n()->t('One year'),
-               ];
-
                /* get user names to make the install a personal install of X */
                // @TODO Move to Model\User::getNames()
                $user_names = [];
@@ -553,9 +533,11 @@ class Site extends BaseAdmin
                ];
 
                $discovery_choices = [
-                       GContact::DISCOVERY_NONE => DI::l10n()->t('none'),
-                       GContact::DISCOVERY_DIRECT => DI::l10n()->t('Direct contacts'),
-                       GContact::DISCOVERY_RECURSIVE => DI::l10n()->t('Contacts of contacts')
+                       Contact\Relation::DISCOVERY_NONE => DI::l10n()->t('none'),
+                       Contact\Relation::DISCOVERY_LOCAL => DI::l10n()->t('Local contacts'),
+                       Contact\Relation::DISCOVERY_INTERACTOR => DI::l10n()->t('Interactors'),
+                       // "All" is deactivated until we are sure not to put too much stress on the fediverse with this
+                       // ContactRelation::DISCOVERY_ALL => DI::l10n()->t('All'),
                ];
 
                $diaspora_able = (DI::baseUrl()->getUrlPath() == '');
@@ -621,6 +603,7 @@ class Site extends BaseAdmin
                        // name, label, value, help string, extra data...
                        '$sitename'         => ['sitename', DI::l10n()->t('Site name'), DI::config()->get('config', 'sitename'), ''],
                        '$sender_email'     => ['sender_email', DI::l10n()->t('Sender Email'), DI::config()->get('config', 'sender_email'), DI::l10n()->t('The email address your server shall use to send notification emails from.'), '', '', 'email'],
+                       '$system_actor_name' => ['system_actor_name', DI::l10n()->t('Name of the system actor'), User::getActorName(), DI::l10n()->t("Name of the internal system account that is used to perform ActivityPub requests. This must be an unused username. If set, this can't be changed again.")],
                        '$banner'           => ['banner', DI::l10n()->t('Banner/Logo'), $banner, ''],
                        '$email_banner'     => ['email_banner', DI::l10n()->t('Email Banner/Logo'), $email_banner, ''],
                        '$shortcut_icon'    => ['shortcut_icon', DI::l10n()->t('Shortcut icon'), DI::config()->get('system', 'shortcut_icon'), DI::l10n()->t('Link to an icon that will be used for browsers.')],
@@ -676,14 +659,17 @@ class Site extends BaseAdmin
                        '$maxloadavg'             => ['maxloadavg', DI::l10n()->t('Maximum Load Average'), DI::config()->get('system', 'maxloadavg', 20), DI::l10n()->t('Maximum system load before delivery and poll processes are deferred - default %d.', 20)],
                        '$maxloadavg_frontend'    => ['maxloadavg_frontend', DI::l10n()->t('Maximum Load Average (Frontend)'), DI::config()->get('system', 'maxloadavg_frontend', 50), DI::l10n()->t('Maximum system load before the frontend quits service - default 50.')],
                        '$min_memory'             => ['min_memory', DI::l10n()->t('Minimal Memory'), DI::config()->get('system', 'min_memory', 0), DI::l10n()->t('Minimal free memory in MB for the worker. Needs access to /proc/meminfo - default 0 (deactivated).')],
-                       '$optimize_max_tablesize' => ['optimize_max_tablesize', DI::l10n()->t('Maximum table size for optimization'), $optimize_max_tablesize, DI::l10n()->t('Maximum table size (in MB) for the automatic optimization. Enter -1 to disable it.')],
-                       '$optimize_fragmentation' => ['optimize_fragmentation', DI::l10n()->t('Minimum level of fragmentation'), DI::config()->get('system', 'optimize_fragmentation', 30), DI::l10n()->t('Minimum fragmenation level to start the automatic optimization - default value is 30%.')],
+                       '$optimize_tables'        => ['optimize_tables', DI::l10n()->t('Periodically optimize tables'), DI::config()->get('system', 'optimize_tables', false), DI::l10n()->t('Periodically optimize tables like the cache and the workerqueue')],
+
+                       '$contact_discovery'      => ['contact_discovery', DI::l10n()->t('Discover followers/followings from contacts'), DI::config()->get('system', 'contact_discovery'), DI::l10n()->t('If enabled, contacts are checked for their followers and following contacts.') . '<ul>' .
+                               '<li>' . DI::l10n()->t('None - deactivated') . '</li>' .
+                               '<li>' . DI::l10n()->t('Local contacts - contacts of our local contacts are discovered for their followers/followings.') . '</li>' .
+                               '<li>' . DI::l10n()->t('Interactors - contacts of our local contacts and contacts who interacted on locally visible postings are discovered for their followers/followings.') . '</li></ul>',
+                               $discovery_choices],
+                       '$synchronize_directory'  => ['synchronize_directory', DI::l10n()->t('Synchronize the contacts with the directory server'), DI::config()->get('system', 'synchronize_directory'), DI::l10n()->t('if enabled, the system will check periodically for new contacts on the defined directory server.')],
 
-                       '$poco_completion'        => ['poco_completion', DI::l10n()->t('Periodical check of global contacts'), DI::config()->get('system', 'poco_completion'), DI::l10n()->t('If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.')],
-                       '$gcontact_discovery'     => ['gcontact_discovery', DI::l10n()->t('Discover followers/followings from global contacts'), DI::config()->get('system', 'gcontact_discovery'), DI::l10n()->t('If enabled, the global contacts are checked for new contacts among their followers and following contacts. This option will create huge masses of jobs, so it should only be activated on powerful machines.'), $discovery_choices],
                        '$poco_requery_days'      => ['poco_requery_days', DI::l10n()->t('Days between requery'), DI::config()->get('system', 'poco_requery_days'), DI::l10n()->t('Number of days after which a server is requeried for his contacts.')],
-                       '$poco_discovery'         => ['poco_discovery', DI::l10n()->t('Discover contacts from other servers'), DI::config()->get('system', 'poco_discovery'), DI::l10n()->t('Periodically query other servers for contacts. You can choose between "Users": the users on the remote system, "Global Contacts": active contacts that are known on the system. The fallback is meant for Redmatrix servers and older friendica servers, where global contacts weren\'t available. The fallback increases the server load, so the recommended setting is "Users, Global Contacts".'), $poco_discovery_choices],
-                       '$poco_discovery_since'   => ['poco_discovery_since', DI::l10n()->t('Timeframe for fetching global contacts'), DI::config()->get('system', 'poco_discovery_since'), DI::l10n()->t('When the discovery is activated, this value defines the timeframe for the activity of the global contacts that are fetched from other servers.'), $poco_discovery_since_choices],
+                       '$poco_discovery'         => ['poco_discovery', DI::l10n()->t('Discover contacts from other servers'), DI::config()->get('system', 'poco_discovery'), DI::l10n()->t('Periodically query other servers for contacts. The system queries Friendica, Mastodon and Hubzilla servers.')],
                        '$poco_local_search'      => ['poco_local_search', DI::l10n()->t('Search the local directory'), DI::config()->get('system', 'poco_local_search'), DI::l10n()->t('Search the local directory instead of the global directory. When searching locally, every search will be executed on the global directory in the background. This improves the search results when the search is repeated.')],
 
                        '$nodeinfo'               => ['nodeinfo', DI::l10n()->t('Publish server information'), DI::config()->get('system', 'nodeinfo'), DI::l10n()->t('If enabled, general server and usage data will be published. The data contains the name and version of the server, number of users with public profiles, number of posts and the activated protocols and connectors. See <a href="http://the-federation.info/">the-federation.info</a> for details.')],
@@ -718,7 +704,7 @@ class Site extends BaseAdmin
                        '$relay_server_tags'      => ['relay_server_tags', DI::l10n()->t('Server tags'), DI::config()->get('system', 'relay_server_tags'), DI::l10n()->t('Comma separated list of tags for the "tags" subscription.')],
                        '$relay_user_tags'        => ['relay_user_tags', DI::l10n()->t('Allow user tags'), DI::config()->get('system', 'relay_user_tags', true), DI::l10n()->t('If enabled, the tags from the saved searches will used for the "tags" subscription in addition to the "relay_server_tags".')],
 
-                       '$form_security_token'    => parent::getFormSecurityToken('admin_site'),
+                       '$form_security_token'    => self::getFormSecurityToken('admin_site'),
                        '$relocate_button'        => DI::l10n()->t('Start Relocation'),
                ]);
        }