]> git.mxchange.org Git - friendica.git/blobdiff - mod/admin.php
Tweak storage selection in admin page
[friendica.git] / mod / admin.php
index c0ad281d3b5e3a1ee9998751734d35e2103a7d7b..7ee48f592ef252920f5c40ef8d6cf59602124793 100644 (file)
@@ -15,6 +15,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
+use Friendica\Core\StorageManager;
 use Friendica\Core\System;
 use Friendica\Core\Theme;
 use Friendica\Core\Update;
@@ -25,13 +26,34 @@ use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Register;
 use Friendica\Model\User;
+use Friendica\Module;
 use Friendica\Module\Login;
 use Friendica\Module\Tos;
+use Friendica\Protocol\PortableContact;
 use Friendica\Util\Arrays;
+use Friendica\Util\BasePath;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
+use Psr\Log\LogLevel;
+
+/**
+ * Sets the current theme for theme settings pages.
+ *
+ * This needs to be done before the post() or content() methods are called.
+ *
+ * @param App $a
+ */
+function admin_init(App $a)
+{
+       if ($a->argc > 2 && $a->argv[1] == 'themes') {
+               $theme = $a->argv[2];
+               if (is_file("view/theme/$theme/config.php")) {
+                       $a->setCurrentTheme($theme);
+               }
+       }
+}
 
 /**
  * @brief Process send data from the admin panels subpages
@@ -44,7 +66,8 @@ use Friendica\Util\Temporal;
  * return the HTML for the pages of the admin panel.
  *
  * @param App $a
- *
+ * @throws ImagickException
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_post(App $a)
 {
@@ -89,15 +112,8 @@ function admin_post(App $a)
 
                                $theme = $a->argv[2];
                                if (is_file("view/theme/$theme/config.php")) {
-                                       $a->setCurrentTheme($theme);
-
-                                       require_once "view/theme/$theme/theme.php";
                                        require_once "view/theme/$theme/config.php";
 
-                                       $init = $theme . '_init';
-                                       if (function_exists($init)) {
-                                               $init($a);
-                                       }
                                        if (function_exists('theme_admin_post')) {
                                                theme_admin_post($a);
                                        }
@@ -150,6 +166,7 @@ function admin_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_content(App $a)
 {
@@ -188,7 +205,6 @@ function admin_content(App $a)
                        'tos'          => ['admin/tos/'         , L10n::t('Terms of Service')        , 'tos']]],
                'database' => [L10n::t('Database'), [
                        'dbsync'       => ['admin/dbsync/'      , L10n::t('DB updates')              , 'dbsync'],
-                       'queue'        => ['admin/queue/'       , L10n::t('Inspect Queue')           , 'queue'],
                        'deferred'     => ['admin/deferred/'    , L10n::t('Inspect Deferred Workers'), 'deferred'],
                        'workerqueue'  => ['admin/workerqueue/' , L10n::t('Inspect worker Queue')    , 'workerqueue']]],
                'tools' => [L10n::t('Tools'), [
@@ -257,9 +273,6 @@ function admin_content(App $a)
                        case 'dbsync':
                                $o = admin_page_dbsync($a);
                                break;
-                       case 'queue':
-                               $o = admin_page_queue($a);
-                               break;
                        case 'deferred':
                                $o = admin_page_workerqueue($a, true);
                                break;
@@ -290,8 +303,7 @@ function admin_content(App $a)
 
        if ($a->isAjax()) {
                echo $o;
-               killme();
-               return '';
+               exit();
        } else {
                return $o;
        }
@@ -302,6 +314,7 @@ function admin_content(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_tos(App $a)
 {
@@ -324,6 +337,7 @@ function admin_page_tos(App $a)
  * @brief Process send data from Admin TOS Page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_tos_post(App $a)
 {
@@ -356,6 +370,7 @@ function admin_page_tos_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_blocklist(App $a)
 {
@@ -396,6 +411,7 @@ function admin_page_blocklist(App $a)
  * @brief Process send data from Admin Blocklist Page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_blocklist_post(App $a)
 {
@@ -440,6 +456,8 @@ function admin_page_blocklist_post(App $a)
  * @brief Process data send by the contact block admin page
  *
  * @param App $a
+ * @throws ImagickException
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_contactblock_post(App $a)
 {
@@ -472,6 +490,7 @@ function admin_page_contactblock_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_contactblock(App $a)
 {
@@ -524,6 +543,7 @@ function admin_page_contactblock(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_deleteitem(App $a)
 {
@@ -548,6 +568,7 @@ function admin_page_deleteitem(App $a)
  * URLs like the full /display URL to make the process more easy for the admin.
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_deleteitem_post(App $a)
 {
@@ -587,6 +608,7 @@ function admin_page_deleteitem_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_federation(App $a)
 {
@@ -654,6 +676,8 @@ function admin_page_federation(App $a)
                                do {
                                        $part = array_pop($parts);
                                } while (!empty($parts) && ((strlen($part) >= 40) || (strlen($part) <= 3)));
+                               // only take the x.x.x part of the version, not the "release" after the dash
+                               $part = array_shift(explode('-', $part));
 
                                if (!empty($part)) {
                                        if (empty($compacted[$part])) {
@@ -761,51 +785,6 @@ function admin_page_federation(App $a)
        ]);
 }
 
-/**
- * @brief Admin Inspect Queue Page
- *
- * Generates a page for the admin to have a look into the current queue of
- * postings that are not deliverable. Shown are the name and url of the
- * recipient, the delivery network and the dates when the posting was generated
- * and the last time tried to deliver the posting.
- *
- * The returned string holds the content of the page.
- *
- * @param App $a
- * @return string
- */
-function admin_page_queue(App $a)
-{
-       // get content from the queue table
-       $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 = Renderer::getMarkupTemplate('admin/queue.tpl');
-       return Renderer::replaceMacros($t, [
-               '$title' => L10n::t('Administration'),
-               '$page' => L10n::t('Inspect Queue'),
-               '$count' => count($r),
-               'id_header' => L10n::t('ID'),
-               '$to_header' => L10n::t('Recipient Name'),
-               '$url_header' => L10n::t('Recipient Profile'),
-               '$network_header' => L10n::t('Network'),
-               '$created_header' => L10n::t('Created'),
-               '$last_header' => L10n::t('Last Tried'),
-               '$info' => L10n::t('This page lists the content of the queue for outgoing postings. These are postings the initial delivery failed for. They will be resend later and eventually deleted if the delivery fails permanently.'),
-               '$entries' => $r,
-       ]);
-}
-
 /**
  * @brief Admin Inspect Worker Queue Page
  *
@@ -815,7 +794,9 @@ function admin_page_queue(App $a)
  * The returned string holds the content of the page.
  *
  * @param App $a
+ * @param     $deferred
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_workerqueue(App $a, $deferred)
 {
@@ -865,6 +846,7 @@ function admin_page_workerqueue(App $a, $deferred)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_summary(App $a)
 {
@@ -887,12 +869,16 @@ function admin_page_summary(App $a)
        }
 
        if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
-               DBStructure::update(false, true);
+               DBStructure::update($a->getBasePath(), false, true);
        }
        if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
                $showwarning = true;
                $warningtext[] = L10n::t('The database update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear.');
        }
+       if (Config::get('system', 'update') == Update::FAILED) {
+               $showwarning = true;
+               $warningtext[] = L10n::t('The last update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear. (Some of the errors are possibly inside the logfile.)');
+       }
 
        $last_worker_call = Config::get('system', 'last_worker_execution', false);
        if (!$last_worker_call) {
@@ -908,6 +894,10 @@ function admin_page_summary(App $a)
                $showwarning = true;
                $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.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');
        }
+       if (file_exists('config/local.ini.php')) {
+               $showwarning = true;
+               $warningtext[] = L10n::t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from <code>config/local.ini.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()) {
@@ -937,8 +927,6 @@ function admin_page_summary(App $a)
 
        $pending = Register::getPendingCount();
 
-       $queue = DBA::count('queue', []);
-
        $deferred = DBA::count('workerqueue', ["`executed` <= ? AND NOT `done` AND `next_try` > ?",
                DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
 
@@ -947,7 +935,7 @@ function admin_page_summary(App $a)
 
        // We can do better, but this is a quick queue status
 
-       $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'deferred' => $deferred, 'workerq' => $workerqueue];
+       $queues = ['label' => L10n::t('Message queues'), 'deferred' => $deferred, 'workerq' => $workerqueue];
 
 
        $r = q("SHOW variables LIKE 'max_allowed_packet'");
@@ -983,6 +971,7 @@ function admin_page_summary(App $a)
  * @brief Process send data from Admin Site Page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_site_post(App $a)
 {
@@ -1052,7 +1041,9 @@ function admin_page_site_post(App $a)
                update_table($a, "gcontact", ['connect', 'addr'], $old_host, $new_host);
 
                // update config
-               Config::set('system', 'hostname', parse_url($new_url, PHP_URL_HOST));
+               $configFileSaver = new \Friendica\Util\Config\ConfigFileSaver($a->getBasePath());
+               $configFileSaver->addConfigValue('config', 'hostname', parse_url($new_url, PHP_URL_HOST));
+               $configFileSaver->saveToConfigFile();
                Config::set('system', 'url', $new_url);
                $a->setBaseURL($new_url);
 
@@ -1070,12 +1061,11 @@ function admin_page_site_post(App $a)
        // end relocate
 
        $sitename         = (!empty($_POST['sitename'])         ? Strings::escapeTags(trim($_POST['sitename']))      : '');
-       $hostname         = (!empty($_POST['hostname'])         ? Strings::escapeTags(trim($_POST['hostname']))      : '');
        $sender_email     = (!empty($_POST['sender_email'])     ? Strings::escapeTags(trim($_POST['sender_email']))  : '');
        $banner           = (!empty($_POST['banner'])           ? trim($_POST['banner'])                             : false);
        $shortcut_icon    = (!empty($_POST['shortcut_icon'])    ? Strings::escapeTags(trim($_POST['shortcut_icon'])) : '');
        $touch_icon       = (!empty($_POST['touch_icon'])       ? Strings::escapeTags(trim($_POST['touch_icon']))    : '');
-       $info             = (!empty($_POST['info'])             ? trim($_POST['info'])                               : false);
+       $additional_info  = (!empty($_POST['additional_info'])  ? trim($_POST['additional_info'])                    : '');
        $language         = (!empty($_POST['language'])         ? Strings::escapeTags(trim($_POST['language']))      : '');
        $theme            = (!empty($_POST['theme'])            ? Strings::escapeTags(trim($_POST['theme']))         : '');
        $theme_mobile     = (!empty($_POST['theme_mobile'])     ? Strings::escapeTags(trim($_POST['theme_mobile']))  : '');
@@ -1114,14 +1104,14 @@ function admin_page_site_post(App $a)
        $proxyuser              = (!empty($_POST['proxyuser'])              ? Strings::escapeTags(trim($_POST['proxyuser'])) : '');
        $proxy                  = (!empty($_POST['proxy'])                  ? Strings::escapeTags(trim($_POST['proxy']))     : '');
        $timeout                = (!empty($_POST['timeout'])                ? intval(trim($_POST['timeout']))                : 60);
-       $maxloadavg             = (!empty($_POST['maxloadavg'])             ? intval(trim($_POST['maxloadavg']))             : 50);
+       $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);
        $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']))         : 0);
+       $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_local_search      = !empty($_POST['poco_local_search']);
        $nodeinfo               = !empty($_POST['nodeinfo']);
@@ -1141,7 +1131,6 @@ function admin_page_site_post(App $a)
        $itemcache_duration     = (!empty($_POST['itemcache_duration'])     ? intval($_POST['itemcache_duration'])            : 0);
        $max_comments           = (!empty($_POST['max_comments'])           ? intval($_POST['max_comments'])                  : 0);
        $temppath               = (!empty($_POST['temppath'])               ? Strings::escapeTags(trim($_POST['temppath']))   : '');
-       $basepath               = (!empty($_POST['basepath'])               ? Strings::escapeTags(trim($_POST['basepath']))   : '');
        $singleuser             = (!empty($_POST['singleuser'])             ? Strings::escapeTags(trim($_POST['singleuser'])) : '');
        $proxy_disabled         = !empty($_POST['proxy_disabled']);
        $only_tag_search        = !empty($_POST['only_tag_search']);
@@ -1161,6 +1150,46 @@ function admin_page_site_post(App $a)
        $relay_user_tags   = !empty($_POST['relay_user_tags']);
        $active_panel      = (!empty($_POST['active_panel'])      ? "#" . Strings::escapeTags(trim($_POST['active_panel'])) : '');
 
+       /**
+        * @var $storagebackend \Friendica\Model\Storage\IStorage
+        */
+       $storagebackend    = Strings::escapeTags(trim(defaults($_POST, 'storagebackend', '')));
+
+       // save storage backend form
+       if (!is_null($storagebackend) && $storagebackend != "") {
+               if (!StorageManager::setBackend($storagebackend)) {
+                       info(L10n::t('Invalid storage backend setting value.'));
+               } else {
+                       $storage_opts = $storagebackend::getOptions();
+                       $storage_form_prefix=preg_replace('|[^a-zA-Z0-9]|' ,'', $storagebackend);
+                       $storage_opts_data = [];
+                       foreach($storage_opts as $name => $info) {
+                               $fieldname = $storage_form_prefix . '_' . $name;
+                               switch ($info[0]) { // type
+                               case 'checkbox':
+                               case 'yesno':
+                                       $value = !empty($_POST[$fieldname]);
+                                       break;
+                               default:
+                                       $value = defaults($_POST, $fieldname, '');
+                               }
+                               $storage_opts_data[$name] = $value;
+                       }
+                       unset($name);
+                       unset($info);
+
+                       $storage_form_errors = $storagebackend::saveOptions($storage_opts_data);
+                       if (count($storage_form_errors)) {
+                               foreach($storage_form_errors as $name => $err) {
+                                       notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
+                               }
+                               $a->internalRedirect('admin/site' . $active_panel);
+                       }
+               }
+       }
+
+
+
        // Has the directory url changed? If yes, then resubmit the existing profiles there
        if ($global_directory != Config::get('system', 'directory') && ($global_directory != '')) {
                Config::set('system', 'directory', $global_directory);
@@ -1222,7 +1251,6 @@ function admin_page_site_post(App $a)
        Config::set('system', 'poco_local_search'     , $poco_local_search);
        Config::set('system', 'nodeinfo'              , $nodeinfo);
        Config::set('config', 'sitename'              , $sitename);
-       Config::set('config', 'hostname'              , $hostname);
        Config::set('config', 'sender_email'          , $sender_email);
        Config::set('system', 'suppress_tags'         , $suppress_tags);
        Config::set('system', 'shortcut_icon'         , $shortcut_icon);
@@ -1234,10 +1262,10 @@ function admin_page_site_post(App $a)
                Config::set('system', 'banner', $banner);
        }
 
-       if ($info == "") {
+       if (empty($additional_info)) {
                Config::delete('config', 'info');
        } else {
-               Config::set('config', 'info', $info);
+               Config::set('config', 'info', $additional_info);
        }
        Config::set('system', 'language', $language);
        Config::set('system', 'theme', $theme);
@@ -1305,7 +1333,7 @@ function admin_page_site_post(App $a)
        Config::set('system', 'dbclean-expire-unclaimed', $dbclean_unclaimed);
 
        if ($itemcache != '') {
-               $itemcache = App::getRealPath($itemcache);
+               $itemcache = BasePath::getRealPath($itemcache);
        }
 
        Config::set('system', 'itemcache', $itemcache);
@@ -1313,16 +1341,11 @@ function admin_page_site_post(App $a)
        Config::set('system', 'max_comments', $max_comments);
 
        if ($temppath != '') {
-               $temppath = App::getRealPath($temppath);
+               $temppath = BasePath::getRealPath($temppath);
        }
 
        Config::set('system', 'temppath', $temppath);
 
-       if ($basepath != '') {
-               $basepath = App::getRealPath($basepath);
-       }
-
-       Config::set('system', 'basepath'         , $basepath);
        Config::set('system', 'proxy_disabled'   , $proxy_disabled);
        Config::set('system', 'only_tag_search'  , $only_tag_search);
 
@@ -1353,6 +1376,7 @@ function admin_page_site_post(App $a)
  *
  * @param  App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_site(App $a)
 {
@@ -1405,10 +1429,10 @@ function admin_page_site(App $a)
        ];
 
        $poco_discovery_choices = [
-               "0" => L10n::t("Disabled"),
-               "1" => L10n::t("Users"),
-               "2" => L10n::t("Users, Global Contacts"),
-               "3" => L10n::t("Users, Global Contacts/fallback"),
+               PortableContact::DISABLED => L10n::t("Disabled"),
+               PortableContact::USERS => L10n::t("Users"),
+               PortableContact::USERS_GCONTACTS => L10n::t("Users, Global Contacts"),
+               PortableContact::USERS_GCONTACTS_FALLBACK => L10n::t("Users, Global Contacts/fallback"),
        ];
 
        $poco_discovery_since_choices = [
@@ -1434,7 +1458,7 @@ function admin_page_site(App $a)
                $banner = '<a href="https://friendi.ca"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>';
        }
 
-       $info = Config::get('config', 'info');
+       $additional_info = Config::get('config', 'info');
 
        // Automatically create temporary paths
        get_temppath();
@@ -1444,9 +1468,9 @@ function admin_page_site(App $a)
 
        /* Register policy */
        $register_choices = [
-               REGISTER_CLOSED => L10n::t("Closed"),
-               REGISTER_APPROVE => L10n::t("Requires approval"),
-               REGISTER_OPEN => L10n::t("Open")
+               Module\Register::CLOSED => L10n::t("Closed"),
+               Module\Register::APPROVE => L10n::t("Requires approval"),
+               Module\Register::OPEN => L10n::t("Open")
        ];
 
        $ssl_choices = [
@@ -1461,9 +1485,6 @@ function admin_page_site(App $a)
                "develop" => L10n::t("check the development version")
        ];
 
-       if (empty(Config::get('config', 'hostname'))) {
-               Config::set('config', 'hostname', $a->getHostName());
-       }
        $diaspora_able = ($a->getURLPath() == "");
 
        $optimize_max_tablesize = Config::get('system', 'optimize_max_tablesize', -1);
@@ -1472,6 +1493,41 @@ function admin_page_site(App $a)
                $optimize_max_tablesize = -1;
        }
 
+       /* storage backend */
+       $storage_backends = StorageManager::listBackends();
+       /**
+        * @var $storage_current_backend \Friendica\Model\Storage\IStorage
+        */
+       $storage_current_backend = StorageManager::getBackend();
+
+       $storage_backends_choices = [];
+
+       // show legacy option only if it is the current backend:
+       // once changed can't be selected anymore
+       if ($storage_current_backend == '') {
+               $storage_backends_choices[''] = L10n::t('Database (legacy)');
+       };
+
+       foreach($storage_backends as $name=>$class) {
+               $storage_backends_choices[$class] = $name;
+       }
+       unset($storage_backends);
+
+       // build storage config form,
+       $storage_form_prefix=preg_replace('|[^a-zA-Z0-9]|' ,'', $storage_current_backend);
+
+       $storage_form = [];
+       if (!is_null($storage_current_backend) && $storage_current_backend != "") {
+               foreach ($storage_current_backend::getOptions() as $name => $info) {
+                       $type = $info[0];
+                       $info[0] = $storage_form_prefix . '_' . $name;
+                       $info['type'] = $type;
+                       $info['field'] = 'field_' . $type . '.tpl';
+                       $storage_form[$name] = $info;
+               }
+       }
+
+
        $t = Renderer::getMarkupTemplate('admin/site.tpl');
        return Renderer::replaceMacros($t, [
                '$title'             => L10n::t('Administration'),
@@ -1492,12 +1548,11 @@ function admin_page_site(App $a)
 
                // name, label, value, help string, extra data...
                '$sitename'         => ['sitename', L10n::t("Site name"), Config::get('config', 'sitename'), ''],
-               '$hostname'         => ['hostname', L10n::t("Host name"), Config::get('config', 'hostname'), ""],
                '$sender_email'     => ['sender_email', L10n::t("Sender Email"), Config::get('config', 'sender_email'), L10n::t("The email address your server shall use to send notification emails from."), "", "", "email"],
                '$banner'           => ['banner', L10n::t("Banner/Logo"), $banner, ""],
                '$shortcut_icon'    => ['shortcut_icon', L10n::t("Shortcut icon"), Config::get('system', 'shortcut_icon'), L10n::t("Link to an icon that will be used for browsers.")],
                '$touch_icon'       => ['touch_icon', L10n::t("Touch icon"), Config::get('system', 'touch_icon'), L10n::t("Link to an icon that will be used for tablets and mobiles.")],
-               '$info'             => ['info', L10n::t('Additional Info'), $info, L10n::t('For public servers: you can add additional information here that will be listed at %s/servers.', get_server())],
+               '$additional_info'  => ['additional_info', L10n::t('Additional Info'), $additional_info, L10n::t('For public servers: you can add additional information here that will be listed at %s/servers.', get_server())],
                '$language'         => ['language', L10n::t("System language"), Config::get('system', 'language'), "", $lang_choices],
                '$theme'            => ['theme', L10n::t("System theme"), Config::get('system', 'theme'), L10n::t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices],
                '$theme_mobile'     => ['theme_mobile', L10n::t("Mobile system theme"), Config::get('system', 'mobile-theme', '---'), L10n::t("Theme for mobile devices"), $theme_choices_mobile],
@@ -1505,6 +1560,9 @@ function admin_page_site(App $a)
                '$force_ssl'        => ['force_ssl', L10n::t("Force SSL"), Config::get('system', 'force_ssl'), L10n::t("Force all Non-SSL requests to SSL - Attention: on some systems it could lead to endless loops.")],
                '$hide_help'        => ['hide_help', L10n::t("Hide help entry from navigation menu"), Config::get('system', 'hide_help'), L10n::t("Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.")],
                '$singleuser'       => ['singleuser', L10n::t("Single user instance"), Config::get('system', 'singleuser', '---'), L10n::t("Make this instance multi-user or single-user for the named user"), $user_names],
+
+               '$storagebackend'   => ['storagebackend', L10n::t("File storage backend"), $storage_current_backend, L10n::t('The backend used to store uploaded data. If you change the storage backend, you can manually move the existing files. If you do not do so, the files uploaded before the change will still be available at the old backend. Please see <a href="/help/Settings#1_2_3_1">the settings documentation</a> for more information about the choices and the moving procedure.'), $storage_backends_choices],
+               '$storageform'      => $storage_form,
                '$maximagesize'     => ['maximagesize', L10n::t("Maximum image size"), Config::get('system', 'maximagesize'), L10n::t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")],
                '$maximagelength'   => ['maximagelength', L10n::t("Maximum image length"), Config::get('system', 'max_image_length'), L10n::t("Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.")],
                '$jpegimagequality' => ['jpegimagequality', L10n::t("JPEG image quality"), Config::get('system', 'jpeg_quality'), L10n::t("Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.")],
@@ -1543,7 +1601,7 @@ function admin_page_site(App $a)
                '$proxyuser'              => ['proxyuser', L10n::t("Proxy user"), Config::get('system', 'proxyuser'), ""],
                '$proxy'                  => ['proxy', L10n::t("Proxy URL"), Config::get('system', 'proxy'), ""],
                '$timeout'                => ['timeout', L10n::t("Network timeout"), Config::get('system', 'curl_timeout', 60), L10n::t("Value is in seconds. Set to 0 for unlimited \x28not recommended\x29.")],
-               '$maxloadavg'             => ['maxloadavg', L10n::t("Maximum Load Average"), Config::get('system', 'maxloadavg', 50), L10n::t("Maximum system load before delivery and poll processes are deferred - default 50.")],
+               '$maxloadavg'             => ['maxloadavg', L10n::t("Maximum Load Average"), Config::get('system', 'maxloadavg', 20), L10n::t("Maximum system load before delivery and poll processes are deferred - default %d.", 20)],
                '$maxloadavg_frontend'    => ['maxloadavg_frontend', L10n::t("Maximum Load Average \x28Frontend\x29"), Config::get('system', 'maxloadavg_frontend', 50), L10n::t("Maximum system load before the frontend quits service - default 50.")],
                '$min_memory'             => ['min_memory', L10n::t("Minimal Memory"), Config::get('system', 'min_memory', 0), L10n::t("Minimal free memory in MB for the worker. Needs access to /proc/meminfo - default 0 \x28deactivated\x29.")],
                '$optimize_max_tablesize' => ['optimize_max_tablesize', L10n::t("Maximum table size for optimization"), $optimize_max_tablesize, L10n::t("Maximum table size \x28in MB\x29 for the automatic optimization. Enter -1 to disable it.")],
@@ -1551,7 +1609,7 @@ function admin_page_site(App $a)
 
                '$poco_completion'        => ['poco_completion', L10n::t("Periodical check of global contacts"), Config::get('system', 'poco_completion'), L10n::t("If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.")],
                '$poco_requery_days'      => ['poco_requery_days', L10n::t("Days between requery"), Config::get('system', 'poco_requery_days'), L10n::t("Number of days after which a server is requeried for his contacts.")],
-               '$poco_discovery'         => ['poco_discovery', L10n::t("Discover contacts from other servers"), (string)intval(Config::get('system', 'poco_discovery')), 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 recommened setting is 'Users, Global Contacts'."), $poco_discovery_choices],
+               '$poco_discovery'         => ['poco_discovery', L10n::t("Discover contacts from other servers"), (string)intval(Config::get('system', 'poco_discovery')), 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', L10n::t("Timeframe for fetching global contacts"), (string)intval(Config::get('system', 'poco_discovery_since')), 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_local_search'      => ['poco_local_search', L10n::t("Search the local directory"), Config::get('system', 'poco_local_search'), 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.")],
 
@@ -1567,7 +1625,6 @@ function admin_page_site(App $a)
                '$itemcache_duration'     => ['itemcache_duration', L10n::t("Cache duration in seconds"), Config::get('system', 'itemcache_duration'), L10n::t("How long should the cache files be hold? Default value is 86400 seconds \x28One day\x29. To disable the item cache, set the value to -1.")],
                '$max_comments'           => ['max_comments', L10n::t("Maximum numbers of comments per post"), Config::get('system', 'max_comments'), L10n::t("How much comments should be shown for each post? Default value is 100.")],
                '$temppath'               => ['temppath', L10n::t("Temp path"), Config::get('system', 'temppath'), L10n::t("If you have a restricted system where the webserver can't access the system temp path, enter another path here.")],
-               '$basepath'               => ['basepath', L10n::t("Base path to installation"), Config::get('system', 'basepath'), L10n::t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot.")],
                '$proxy_disabled'         => ['proxy_disabled', L10n::t("Disable picture proxy"), Config::get('system', 'proxy_disabled'), L10n::t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwidth.")],
                '$only_tag_search'        => ['only_tag_search', L10n::t("Only search in tags"), Config::get('system', 'only_tag_search'), L10n::t("On large systems the text search can slow down the system extremely.")],
 
@@ -1603,7 +1660,8 @@ function admin_page_site(App $a)
  *
  * @param App $a
  * @return string
- * */
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
 function admin_page_dbsync(App $a)
 {
        $o = '';
@@ -1619,7 +1677,7 @@ function admin_page_dbsync(App $a)
        }
 
        if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) {
-               $retval = DBStructure::update(false, true);
+               $retval = DBStructure::update($a->getBasePath(), false, true);
                if ($retval === '') {
                        $o .= L10n::t("Database structure update %s was successfully applied.", DB_UPDATE_VERSION) . "<br />";
                        Config::set('database', 'last_successful_update', DB_UPDATE_VERSION);
@@ -1693,6 +1751,7 @@ function admin_page_dbsync(App $a)
  * @brief Process data send by Users admin page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_users_post(App $a)
 {
@@ -1752,7 +1811,7 @@ function admin_page_users_post(App $a)
                        Thank you and welcome to %4$s.'));
 
                $preamble = sprintf($preamble, $user['username'], Config::get('config', 'sitename'));
-               $body = sprintf($body, System::baseUrl(), $user['email'], $result['password'], Config::get('config', 'sitename'));
+               $body = sprintf($body, System::baseUrl(), $user['nickname'], $result['password'], Config::get('config', 'sitename'));
 
                notification([
                        'type'     => SYSTEM_EMAIL,
@@ -1810,6 +1869,7 @@ function admin_page_users_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_users(App $a)
 {
@@ -1887,17 +1947,18 @@ function admin_page_users(App $a)
        $adminlist = explode(",", str_replace(" ", "", Config::get('config', 'admin_email')));
        $_setup_users = function ($e) use ($adminlist) {
                $page_types = [
-                       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')
+                       User::PAGE_FLAGS_NORMAL    => L10n::t('Normal Account Page'),
+                       User::PAGE_FLAGS_SOAPBOX   => L10n::t('Soapbox Page'),
+                       User::PAGE_FLAGS_COMMUNITY => L10n::t('Public Forum'),
+                       User::PAGE_FLAGS_FREELOVE  => L10n::t('Automatic Friend Page'),
+                       User::PAGE_FLAGS_PRVGROUP  => L10n::t('Private Forum')
                ];
                $account_types = [
-                       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')
+                       User::ACCOUNT_TYPE_PERSON       => L10n::t('Personal Page'),
+                       User::ACCOUNT_TYPE_ORGANISATION => L10n::t('Organisation Page'),
+                       User::ACCOUNT_TYPE_NEWS         => L10n::t('News Page'),
+                       User::ACCOUNT_TYPE_COMMUNITY    => L10n::t('Community Forum'),
+                       User::ACCOUNT_TYPE_RELAY        => L10n::t('Relay'),
                ];
 
                $e['page_flags_raw'] = $e['page-flags'];
@@ -2008,6 +2069,7 @@ function admin_page_users(App $a)
  * @param App   $a
  * @param array $addons_admin A list of admin addon names
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_addons(App $a, array $addons_admin)
 {
@@ -2213,6 +2275,7 @@ function rebuild_theme_table($themes)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_themes(App $a)
 {
@@ -2306,16 +2369,8 @@ function admin_page_themes(App $a)
 
                $admin_form = '';
                if (is_file("view/theme/$theme/config.php")) {
-                       $a->setCurrentTheme($theme);
-
-                       require_once "view/theme/$theme/theme.php";
                        require_once "view/theme/$theme/config.php";
 
-                       $init = $theme . "_init";
-                       if (function_exists($init)) {
-                               $init($a);
-                       }
-
                        if (function_exists('theme_admin')) {
                                $admin_form = theme_admin($a);
                        }
@@ -2391,6 +2446,7 @@ function admin_page_themes(App $a)
  * @brief Prosesses data send by Logs admin page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_logs_post(App $a)
 {
@@ -2399,7 +2455,7 @@ function admin_page_logs_post(App $a)
 
                $logfile   = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
                $debugging = !empty($_POST['debugging']);
-               $loglevel  = (!empty($_POST['loglevel']) ? intval(trim($_POST['loglevel'])) : 0);
+               $loglevel  = defaults($_POST, 'loglevel', LogLevel::ERROR);
 
                Config::set('system', 'logfile', $logfile);
                Config::set('system', 'debugging', $debugging);
@@ -2426,16 +2482,16 @@ function admin_page_logs_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_logs(App $a)
 {
        $log_choices = [
-               Logger::WARNING => 'Warning',
-               Logger::INFO    => 'Info',
-               Logger::TRACE   => 'Trace',
-               Logger::DEBUG   => 'Debug',
-               Logger::DATA    => 'Data',
-               Logger::ALL     => 'All'
+               LogLevel::ERROR   => 'Error',
+               LogLevel::WARNING => 'Warning',
+               LogLevel::NOTICE  => 'Notice',
+               LogLevel::INFO    => 'Info',
+               LogLevel::DEBUG   => 'Debug',
        ];
 
        if (ini_get('log_errors')) {
@@ -2482,6 +2538,7 @@ function admin_page_logs(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_viewlogs(App $a)
 {
@@ -2525,6 +2582,7 @@ function admin_page_viewlogs(App $a)
  * @brief Prosesses data send by the features admin page
  *
  * @param App $a
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_features_post(App $a)
 {
@@ -2572,6 +2630,7 @@ function admin_page_features_post(App $a)
  *
  * @param App $a
  * @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function admin_page_features(App $a)
 {