]> git.mxchange.org Git - friendica.git/blobdiff - mod/admin.php
Moved functions out of boot.php into class
[friendica.git] / mod / admin.php
index da50007131535e5ddcda2c885accb10cdfc5de62..ade6b0cad1cac91507958f6e3e8fd7615a45129b 100644 (file)
@@ -14,15 +14,17 @@ use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Theme;
 use Friendica\Core\Worker;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Module\Login;
 use Friendica\Module\Tos;
+use Friendica\Util\Arrays;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
+use Friendica\Util\Network;
 
 require_once 'include/enotify.php';
 require_once 'include/text.php';
@@ -75,7 +77,7 @@ function admin_post(App $a)
                                break;
                        case 'themes':
                                if ($a->argc < 2) {
-                                       if (is_ajax()) {
+                                       if ($a->isAjax()) {
                                                return;
                                        }
                                        goaway('admin/');
@@ -105,7 +107,7 @@ function admin_post(App $a)
                                }
 
                                info(L10n::t('Theme settings updated.'));
-                               if (is_ajax()) {
+                               if ($a->isAjax()) {
                                        return;
                                }
                                $return_path = 'admin/themes/' . $theme;
@@ -284,7 +286,7 @@ function admin_content(App $a)
                $o = admin_page_summary($a);
        }
 
-       if (is_ajax()) {
+       if ($a->isAjax()) {
                echo $o;
                killme();
                return '';
@@ -471,14 +473,14 @@ function admin_page_contactblock(App $a)
 {
        $condition = ['uid' => 0, 'blocked' => true];
 
-       $total = dba::count('contact', $condition);
+       $total = DBA::count('contact', $condition);
 
-       $a->set_pager_total($total);
-       $a->set_pager_itemspage(30);
+       $a->setPagerTotal($total);
+       $a->setPagerItemsPage(30);
 
-       $statement = dba::select('contact', [], $condition, ['limit' => [$a->pager['start'], $a->pager['itemspage']]]);
+       $statement = DBA::select('contact', [], $condition, ['limit' => [$a->pager['start'], $a->pager['itemspage']]]);
 
-       $contacts = dba::inArray($statement);
+       $contacts = DBA::toArray($statement);
 
        $t = get_markup_template('admin/contactblock.tpl');
        $o = replace_macros($t, [
@@ -745,10 +747,18 @@ function admin_page_federation(App $a)
 function admin_page_queue(App $a)
 {
        // get content from the queue table
-       $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last`
-                       FROM `queue` AS `q`, `contact` AS `c`
-                       WHERE `c`.`id` = `q`.`cid`
-                       ORDER BY `q`.`cid`, `q`.`created`;");
+       $entries = DBA::p("SELECT `contact`.`name`, `contact`.`nurl`,
+                `queue`.`id`, `queue`.`network`, `queue`.`created`, `queue`.`last`
+                FROM `queue` INNER JOIN `contact` ON `contact`.`id` = `queue`.`cid`
+                ORDER BY `queue`.`cid`, `queue`.`created`");
+
+       $r = [];
+       while ($entry = DBA::fetch($entries)) {
+               $entry['created'] = DateTimeFormat::local($entry['created']);
+               $entry['last'] = DateTimeFormat::local($entry['last']);
+               $r[] = $entry;
+       }
+       DBA::close($entries);
 
        $t = get_markup_template('admin/queue.tpl');
        return replace_macros($t, [
@@ -780,8 +790,16 @@ function admin_page_queue(App $a)
 function admin_page_workerqueue(App $a)
 {
        // get jobs from the workerqueue table
-       $statement = dba::select('workerqueue', ['id', 'parameter', 'created', 'priority'], ['done' => 0], ['order'=> ['priority']]);
-       $r = dba::inArray($statement);
+       $entries = DBA::select('workerqueue', ['id', 'parameter', 'created', 'priority'], ['done' => 0], ['order'=> ['priority']]);
+
+       $r = [];
+       while ($entry = DBA::fetch($entries)) {
+               // fix GH-5469. ref: src/Core/Worker.php:217
+               $entry['parameter'] = Arrays::recursiveImplode(json_decode($entry['parameter'], true), ': ');
+               $entry['created'] = DateTimeFormat::local($entry['created']);
+               $r[] = $entry;
+       }
+       DBA::close($entries);
 
        $t = get_markup_template('admin/workerqueue.tpl');
        return replace_macros($t, [
@@ -811,10 +829,10 @@ function admin_page_workerqueue(App $a)
 function admin_page_summary(App $a)
 {
        // are there MyISAM tables in the DB? If so, trigger a warning message
-       $r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1", dbesc(dba::database_name()));
+       $r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1", DBA::escape(DBA::databaseName()));
        $showwarning = false;
        $warningtext = [];
-       if (DBM::is_result($r)) {
+       if (DBA::isResult($r)) {
                $showwarning = true;
                $warningtext[] = L10n::t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php bin/console.php dbstructure toinnodb</tt> of your Friendica installation for an automatic conversion.<br />', 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
        }
@@ -848,7 +866,15 @@ function admin_page_summary(App $a)
        // Legacy config file warning
        if (file_exists('.htconfig.php')) {
                $showwarning = true;
-               $warningtext[] = L10n::t('Friencia\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from <code>.htconfig.php</code>.');
+               $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from <code>.htconfig.php</code>. See <a href="%s">the Config help page</a> for help with the transition.', $a->getBaseURL() . '/help/Config');
+       }
+
+       // Check server vitality
+       if (!admin_page_server_vital()) {
+               $showwarning = true;
+               $well_known = $a->getBaseURL() . '/.well-known/host-meta';
+               $warningtext[] = L10n::t('<a href="%s">%s</a> is not reachable on your system. This is a severe configuration issue that prevents server to server communication. See <a href="%s">the installation page</a> for help.',
+                       $well_known, $well_known, $a->getBaseURL() . '/help/Install');
        }
 
        $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
@@ -883,6 +909,15 @@ function admin_page_summary(App $a)
        $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue];
 
 
+       $r = q("SHOW variables LIKE 'max_allowed_packet'");
+       $max_allowed_packet = (($r) ? $r[0]['Value'] : 0);
+
+       $server_settings = ['label' => L10n::t('Server Settings'), 
+                               'php' => ['upload_max_filesize' => ini_get('upload_max_filesize'), 
+                                                 'post_max_size' => ini_get('post_max_size'), 
+                                                 'memory_limit' => ini_get('memory_limit')], 
+                               'mysql' => ['max_allowed_packet' => $max_allowed_packet]];
+
        $t = get_markup_template('admin/summary.tpl');
        return replace_macros($t, [
                '$title' => L10n::t('Administration'),
@@ -897,6 +932,7 @@ function admin_page_summary(App $a)
                '$codename' => FRIENDICA_CODENAME,
                '$build' => Config::get('system', 'build'),
                '$addons' => [L10n::t('Active addons'), $a->addons],
+               '$serversettings' => $server_settings,
                '$showwarning' => $showwarning,
                '$warningtext' => $warningtext
        ]);
@@ -944,8 +980,8 @@ function admin_page_site_post(App $a)
 
                function update_table($table_name, $fields, $old_url, $new_url)
                {
-                       $dbold = dbesc($old_url);
-                       $dbnew = dbesc($new_url);
+                       $dbold = DBA::escape($old_url);
+                       $dbnew = DBA::escape($new_url);
 
                        $upd = [];
                        foreach ($fields as $f) {
@@ -956,8 +992,8 @@ function admin_page_site_post(App $a)
 
                        $r = q("UPDATE %s SET %s;", $table_name, $upds);
 
-                       if (!DBM::is_result($r)) {
-                               notice("Failed updating '$table_name': " . dba::errorMessage());
+                       if (!DBA::isResult($r)) {
+                               notice("Failed updating '$table_name': " . DBA::errorMessage());
                                goaway('admin/site');
                        }
                }
@@ -976,7 +1012,7 @@ function admin_page_site_post(App $a)
                // update config
                Config::set('system', 'hostname', parse_url($new_url,  PHP_URL_HOST));
                Config::set('system', 'url', $new_url);
-               $a->set_baseurl($new_url);
+               $a->setBaseURL($new_url);
 
                // send relocate
                $users = q("SELECT `uid` FROM `user` WHERE `account_removed` = 0 AND `account_expired` = 0");
@@ -1088,7 +1124,7 @@ function admin_page_site_post(App $a)
                Worker::add(PRIORITY_LOW, 'Directory');
        }
 
-       if ($a->get_path() != "") {
+       if ($a->getURLPath() != "") {
                $diaspora_enabled = false;
        }
        if ($ssl_policy != intval(Config::get('system', 'ssl_policy'))) {
@@ -1225,7 +1261,7 @@ function admin_page_site_post(App $a)
        Config::set('system', 'dbclean-expire-unclaimed', $dbclean_unclaimed);
 
        if ($itemcache != '') {
-               $itemcache = App::realpath($itemcache);
+               $itemcache = App::getRealPath($itemcache);
        }
 
        Config::set('system', 'itemcache', $itemcache);
@@ -1233,13 +1269,13 @@ function admin_page_site_post(App $a)
        Config::set('system', 'max_comments', $max_comments);
 
        if ($temppath != '') {
-               $temppath = App::realpath($temppath);
+               $temppath = App::getRealPath($temppath);
        }
 
        Config::set('system', 'temppath', $temppath);
 
        if ($basepath != '') {
-               $basepath = App::realpath($basepath);
+               $basepath = App::getRealPath($basepath);
        }
 
        Config::set('system', 'basepath', $basepath);
@@ -1383,9 +1419,9 @@ function admin_page_site(App $a)
        ];
 
        if (empty(Config::get('config', 'hostname'))) {
-               Config::set('config', 'hostname', $a->get_hostname());
+               Config::set('config', 'hostname', $a->getHostName());
        }
-       $diaspora_able = ($a->get_path() == "");
+       $diaspora_able = ($a->getURLPath() == "");
 
        $optimize_max_tablesize = Config::get('system', 'optimize_max_tablesize', -1);
 
@@ -1452,7 +1488,7 @@ function admin_page_site(App $a)
                '$community_page_style' => ['community_page_style', L10n::t("Community pages for visitors"), Config::get('system','community_page_style'), L10n::t("Which community pages should be available for visitors. Local users always see both pages."), $community_page_style_choices],
                '$max_author_posts_community_page' => ['max_author_posts_community_page', L10n::t("Posts per user on community page"), Config::get('system','max_author_posts_community_page'), L10n::t("The maximum number of posts per user on the community page. \x28Not valid for 'Global Community'\x29")],
                '$ostatus_disabled'     => ['ostatus_disabled', L10n::t("Enable OStatus support"), !Config::get('system','ostatus_disabled'), L10n::t("Provide built-in OStatus \x28StatusNet, GNU Social etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")],
-               '$ostatus_full_threads' => ['ostatus_full_threads', L10n::t("Only import OStatus threads from our contacts"), Config::get('system','ostatus_full_threads'), L10n::t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")],
+               '$ostatus_full_threads' => ['ostatus_full_threads', L10n::t("Only import OStatus/ActivityPub threads from our contacts"), Config::get('system','ostatus_full_threads'), L10n::t("Normally we import every content from our OStatus and ActivityPub contacts. With this option we only store threads that are started by a contact that is known on our system.")],
                '$ostatus_not_able'     => L10n::t("OStatus support can only be enabled if threading is enabled."),
                '$diaspora_able'        => $diaspora_able,
                '$diaspora_not_able'    => L10n::t("Diaspora support can't be enabled because Friendica was installed into a sub directory."),
@@ -1576,7 +1612,7 @@ function admin_page_dbsync(App $a)
        $failed = [];
        $r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' ");
 
-       if (DBM::is_result($r)) {
+       if (DBA::isResult($r)) {
                foreach ($r as $rr) {
                        $upd = intval(substr($rr['k'], 7));
                        if ($upd < 1139 || $rr['v'] === 'success') {
@@ -1672,11 +1708,14 @@ function admin_page_users_post(App $a)
                $body = sprintf($body, System::baseUrl(), $user['email'], $result['password'], Config::get('config', 'sitename'));
 
                notification([
-                       'type' => SYSTEM_EMAIL,
+                       'type'     => SYSTEM_EMAIL,
+                       'language' => $user['language'],
+                       'to_name'  => $user['username'],
                        'to_email' => $user['email'],
-                       'subject' => L10n::t('Registration details for %s', Config::get('config', 'sitename')),
+                       'uid'      => $user['uid'],
+                       'subject'  => L10n::t('Registration details for %s', Config::get('config', 'sitename')),
                        'preamble' => $preamble,
-                       'body' => $body]);
+                       'body'     => $body]);
        }
 
        if (x($_POST, 'page_users_block')) {
@@ -1725,8 +1764,8 @@ function admin_page_users(App $a)
 {
        if ($a->argc > 2) {
                $uid = $a->argv[3];
-               $user = dba::selectFirst('user', ['username', 'blocked'], ['uid' => $uid]);
-               if (!DBM::is_result($user)) {
+               $user = DBA::selectFirst('user', ['username', 'blocked'], ['uid' => $uid]);
+               if (!DBA::isResult($user)) {
                        notice('User not found' . EOL);
                        goaway('admin/users');
                        return ''; // NOTREACHED
@@ -1762,8 +1801,8 @@ function admin_page_users(App $a)
        /* get users */
        $total = q("SELECT COUNT(*) AS `total` FROM `user` WHERE 1");
        if (count($total)) {
-               $a->set_pager_total($total[0]['total']);
-               $a->set_pager_itemspage(100);
+               $a->setPagerTotal($total[0]['total']);
+               $a->setPagerItemsPage(100);
        }
 
        /* ordering */
@@ -1802,25 +1841,23 @@ function admin_page_users(App $a)
        $adminlist = explode(",", str_replace(" ", "", Config::get('config', 'admin_email')));
        $_setup_users = function ($e) use ($adminlist) {
                $page_types = [
-                       PAGE_NORMAL => L10n::t('Normal Account Page'),
-                       PAGE_SOAPBOX => L10n::t('Soapbox Page'),
-                       PAGE_COMMUNITY => L10n::t('Public Forum'),
-                       PAGE_FREELOVE => L10n::t('Automatic Friend Page'),
-                       PAGE_PRVGROUP => L10n::t('Private Forum')
+                       Contact::PAGE_NORMAL    => L10n::t('Normal Account Page'),
+                       Contact::PAGE_SOAPBOX   => L10n::t('Soapbox Page'),
+                       Contact::PAGE_COMMUNITY => L10n::t('Public Forum'),
+                       Contact::PAGE_FREELOVE  => L10n::t('Automatic Friend Page'),
+                       Contact::PAGE_PRVGROUP  => L10n::t('Private Forum')
                ];
                $account_types = [
-                       ACCOUNT_TYPE_PERSON => L10n::t('Personal Page'),
-                       ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
-                       ACCOUNT_TYPE_NEWS => L10n::t('News Page'),
-                       ACCOUNT_TYPE_COMMUNITY => L10n::t('Community Forum')
+                       Contact::ACCOUNT_TYPE_PERSON       => L10n::t('Personal Page'),
+                       Contact::ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
+                       Contact::ACCOUNT_TYPE_NEWS         => L10n::t('News Page'),
+                       Contact::ACCOUNT_TYPE_COMMUNITY    => L10n::t('Community Forum')
                ];
 
-
-
-               $e['page-flags-raw'] = $e['page-flags'];
+               $e['page_flags_raw'] = $e['page-flags'];
                $e['page-flags'] = $page_types[$e['page-flags']];
 
-               $e['account-type-raw'] = ($e['page_flags_raw'] == 0) ? $e['account-type'] : -1;
+               $e['account_type_raw'] = ($e['page_flags_raw'] == 0) ? $e['account-type'] : -1;
                $e['account-type'] = ($e['page_flags_raw'] == 0) ? $account_types[$e['account-type']] : "";
 
                $e['register_date'] = Temporal::getRelativeDate($e['register_date']);
@@ -1829,8 +1866,10 @@ function admin_page_users(App $a)
                $e['is_admin'] = in_array($e['email'], $adminlist);
                $e['is_deletable'] = (intval($e['uid']) != local_user());
                $e['deleted'] = ($e['account_removed'] ? Temporal::getRelativeDate($e['account_expires_on']) : False);
+
                return $e;
        };
+
        $users = array_map($_setup_users, $users);
 
 
@@ -1876,6 +1915,7 @@ function admin_page_users(App $a)
                '$deny' => L10n::t('Deny'),
                '$delete' => L10n::t('Delete'),
                '$block' => L10n::t('Block'),
+               '$blocked' => L10n::t('User blocked'),
                '$unblock' => L10n::t('Unblock'),
                '$siteadmin' => L10n::t('Site admin'),
                '$accountexpired' => L10n::t('Account expired'),
@@ -2351,11 +2391,12 @@ function admin_page_logs_post(App $a)
 function admin_page_logs(App $a)
 {
        $log_choices = [
-               LOGGER_NORMAL   => 'Normal',
-               LOGGER_TRACE    => 'Trace',
-               LOGGER_DEBUG    => 'Debug',
-               LOGGER_DATA     => 'Data',
-               LOGGER_ALL      => 'All'
+               LOGGER_WARNING => 'Warning',
+               LOGGER_INFO    => 'Info',
+               LOGGER_TRACE   => 'Trace',
+               LOGGER_DEBUG   => 'Debug',
+               LOGGER_DATA    => 'Data',
+               LOGGER_ALL     => 'All'
        ];
 
        if (ini_get('log_errors')) {
@@ -2495,7 +2536,7 @@ function admin_page_features_post(App $a)
  */
 function admin_page_features(App $a)
 {
-       if ((argc() > 1) && (argv(1) === 'features')) {
+       if (($a->argc > 1) && ($a->argv[1] === 'features')) {
                $arr = [];
                $features = Feature::get(false);
 
@@ -2522,3 +2563,9 @@ function admin_page_features(App $a)
                return $o;
        }
 }
+
+function admin_page_server_vital()
+{
+       // Fetch the host-meta to check if this really is a vital server
+       return Network::curl(System::baseUrl() . '/.well-known/host-meta')->isSuccess();
+}