]> git.mxchange.org Git - friendica.git/blobdiff - mod/admin.php
Merge pull request #3539 from AndyHee/20170617-admin_settings
[friendica.git] / mod / admin.php
index fb463d31c014d6dd94e030d5f5bd341c2ee16d0c..a32accaf9a89177ca0da4725c4f4509875db082e 100644 (file)
@@ -6,7 +6,8 @@
  * @brief Friendica admin
  */
 
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Core\Config;
 
 require_once("include/enotify.php");
 require_once("include/text.php");
@@ -109,6 +110,9 @@ function admin_post(App $a) {
                        case 'dbsync':
                                admin_page_dbsync_post($a);
                                break;
+                       case 'blocklist':
+                               admin_page_blocklist_post($a);
+                               break;
                }
        }
 
@@ -166,6 +170,7 @@ function admin_content(App $a) {
                'features' =>   array("admin/features/", t("Additional features") , "features"),
                'dbsync' =>     array("admin/dbsync/", t('DB updates'), "dbsync"),
                'queue'  =>     array("admin/queue/", t('Inspect Queue'), "queue"),
+               'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"),
                'federation' => array("admin/federation/", t('Federation Statistics'), "federation"),
        );
 
@@ -236,6 +241,9 @@ function admin_content(App $a) {
                        case 'federation':
                                $o = admin_page_federation($a);
                                break;
+                       case 'blocklist':
+                               $o = admin_page_blocklist($a);
+                               break;
                        default:
                                notice(t("Item not found."));
                }
@@ -252,6 +260,94 @@ function admin_content(App $a) {
        }
 }
 
+/**
+ * @brief Subpage to modify the server wide block list via the admin panel.
+ *
+ * This function generates the subpage of the admin panel to allow the
+ * modification of the node wide block/black list to block entire
+ * remote servers from communication with this node. The page allows
+ * adding, removing and editing of entries from the blocklist.
+ *
+ * @param App $a
+ * @return string
+ */
+function admin_page_blocklist(App $a) {
+       $blocklist = Config::get('system', 'blocklist');
+       $blocklistform = array();
+       if (is_array($blocklist)) {
+               foreach($blocklist as $id => $b) {
+                       $blocklistform[] = array(
+                               'domain' => array("domain[$id]", t('Blocked domain'), $b['domain'], '', t('The blocked domain'), 'required', '', ''),
+                               'reason' => array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this domain.').'('.$b['domain'].')', 'required', '', ''),
+                               'delete' => array("delete[$id]", t("Delete domain").' ('.$b['domain'].')', False , t("Check to delete this entry from the blocklist"))
+                       );
+               }
+       }
+       $t = get_markup_template("admin_blocklist.tpl");
+       return replace_macros($t, array(
+               '$title' => t('Administration'),
+               '$page' => t('Server Blocklist'),
+               '$intro' => t('This page can be used to define a black list of servers from the federated network that are not allowed to interact with your node. For all entered domains you should also give a reason why you have blocked the remote server.'),
+               '$public' => t('The list of blocked servers will be made publically available on the /friendica page so that your users and people investigating communication problems can find the reason easily.'),
+               '$addtitle' => t('Add new entry to block list'),
+               '$newdomain' => array('newentry_domain', t('Server Domain'), '', t('The domain of the new server to add to the block list. Do not include the protocol.'), 'required', '', ''),
+               '$newreason' => array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this domain.'), 'required', '', ''),
+               '$submit' => t('Add Entry'),
+               '$savechanges' => t('Save changes to the blocklist'),
+               '$currenttitle' => t('Current Entries in the Blocklist'),
+               '$thurl' => t('Blocked domain'),
+               '$threason' => t('Reason for the block'),
+               '$delentry' => t('Delete entry from blocklist'),
+               '$entries' => $blocklistform,
+               '$baseurl' => App::get_baseurl(true),
+               '$confirm_delete' => t('Delete entry from blocklist?'),
+               '$form_security_token'  => get_form_security_token("admin_blocklist")
+       ));
+}
+
+/**
+ * @brief Process send data from Admin Blocklist Page
+ *
+ * @param App $a
+ */
+function admin_page_blocklist_post(App $a) {
+       if (!x($_POST,"page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) {
+               return;
+       }
+
+       check_form_security_token_redirectOnErr('/admin/blocklist', 'admin_blocklist');
+
+       if (x($_POST['page_blocklist_save'])) {
+               //  Add new item to blocklist
+               $blocklist = get_config('system', 'blocklist');
+               $blocklist[] = array(
+                       'domain' => notags(trim($_POST['newentry_domain'])),
+                       'reason' => notags(trim($_POST['newentry_reason']))
+               );
+               Config::set('system', 'blocklist', $blocklist);
+               info(t('Server added to blocklist.').EOL);
+       } else {
+               // Edit the entries from blocklist
+               $blocklist = array();
+               foreach ($_POST['domain'] as $id => $domain) {
+                       // Trimming whitespaces as well as any lingering slashes
+                       $domain = notags(trim($domain, "\x00..\x1F/"));
+                       $reason = notags(trim($_POST['reason'][$id]));
+                       if (!x($_POST['delete'][$id])) {
+                               $blocklist[] = array(
+                                       'domain' => $domain,
+                                       'reason' => $reason
+                               );
+                       }
+               }
+               Config::set('system', 'blocklist', $blocklist);
+               info(t('Site blocklist updated.').EOL);
+       }
+       goaway('admin/blocklist');
+
+       return; // NOTREACHED
+}
+
 /**
  * @brief Subpage with some stats about "the federation" network
  *
@@ -447,21 +543,26 @@ function admin_page_summary(App $a) {
        $warningtext = array();
        if (dbm::is_result($r)) {
                $showwarning = true;
-               $warningtext[] = sprintf(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 <tt>convert_innodb.sql</tt> in the <tt>/util</tt> directory of your Friendica installation.<br />'), 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
+               $warningtext[] = sprintf(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 include/dbstructure.php 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');
+       }
+
+       if (Config::get('system', 'dbupdate', DB_UPDATE_NOT_CHECKED) == DB_UPDATE_NOT_CHECKED) {
+               require_once("include/dbstructure.php");
+               update_structure(false, true);
        }
-       // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
-       if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
-               !(strpos($db->server_info(), 'MariaDB') !== false)) {
-               $warningtext[] = t('You are using a MySQL version which does not support all features that Friendica uses. You should consider switching to MariaDB.');
+       if (Config::get('system', 'dbupdate') == DB_UPDATE_FAILED) {
+               $showwarning = true;
+               $warningtext[] = t('The database update failed. Please run "php include/dbstructure.php update" from the command line and have a look at the errors that might appear.');
        }
+
        $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
        $accounts = array(
                array(t('Normal Account'), 0),
-               array(t('Soapbox Account'), 0),
-               array(t('Community/Celebrity Account'), 0),
+               array(t('Automatic Follower Account'), 0),
+               array(t('Public Forum Account'), 0),
                array(t('Automatic Friend Account'), 0),
                array(t('Blog Account'), 0),
-               array(t('Private Forum'), 0)
+               array(t('Private Forum Account'), 0)
        );
 
        $users=0;
@@ -478,7 +579,7 @@ function admin_page_summary(App $a) {
        $r = qu("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
        $queue = (($r) ? $r[0]['total'] : 0);
 
-       $r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1");
+       $r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE NOT `done`");
        $workerqueue = (($r) ? $r[0]['total'] : 0);
 
        // We can do better, but this is a quick queue status
@@ -636,6 +737,7 @@ function admin_page_site_post(App $a) {
        $timeout                =       ((x($_POST,'timeout'))                  ? intval(trim($_POST['timeout']))               : 60);
        $maxloadavg             =       ((x($_POST,'maxloadavg'))               ? intval(trim($_POST['maxloadavg']))            : 50);
        $maxloadavg_frontend    =       ((x($_POST,'maxloadavg_frontend'))      ? intval(trim($_POST['maxloadavg_frontend']))   : 50);
+       $min_memory             =       ((x($_POST,'min_memory'))               ? intval(trim($_POST['min_memory']))            : 0);
        $optimize_max_tablesize =       ((x($_POST,'optimize_max_tablesize'))   ? intval(trim($_POST['optimize_max_tablesize'])): 100);
        $optimize_fragmentation =       ((x($_POST,'optimize_fragmentation'))   ? intval(trim($_POST['optimize_fragmentation'])): 30);
        $poco_completion        =       ((x($_POST,'poco_completion'))          ? intval(trim($_POST['poco_completion']))       : false);
@@ -653,7 +755,6 @@ function admin_page_site_post(App $a) {
        $force_ssl              =       ((x($_POST,'force_ssl'))                ? True                                          : False);
        $hide_help              =       ((x($_POST,'hide_help'))                ? True                                          : False);
        $suppress_tags          =       ((x($_POST,'suppress_tags'))            ? True                                          : False);
-       $use_fulltext_engine    =       ((x($_POST,'use_fulltext_engine'))      ? True                                          : False);
        $itemcache              =       ((x($_POST,'itemcache'))                ? notags(trim($_POST['itemcache']))             : '');
        $itemcache_duration     =       ((x($_POST,'itemcache_duration'))       ? intval($_POST['itemcache_duration'])          : 0);
        $max_comments           =       ((x($_POST,'max_comments'))             ? intval($_POST['max_comments'])                : 0);
@@ -668,6 +769,12 @@ function admin_page_site_post(App $a) {
        $worker_fastlane        =       ((x($_POST,'worker_fastlane'))          ? True                                          : False);
        $worker_frontend        =       ((x($_POST,'worker_frontend'))          ? True                                          : False);
 
+       // 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);
+               proc_run(PRIORITY_LOW, 'include/directory.php');
+       }
+
        if ($a->get_path() != "") {
                $diaspora_enabled = false;
        }
@@ -716,6 +823,7 @@ function admin_page_site_post(App $a) {
        set_config('system','ssl_policy',$ssl_policy);
        set_config('system','maxloadavg',$maxloadavg);
        set_config('system','maxloadavg_frontend',$maxloadavg_frontend);
+       set_config('system','min_memory',$min_memory);
        set_config('system','optimize_max_tablesize',$optimize_max_tablesize);
        set_config('system','optimize_fragmentation',$optimize_fragmentation);
        set_config('system','poco_completion',$poco_completion);
@@ -771,7 +879,6 @@ function admin_page_site_post(App $a) {
        set_config('system', 'allowed_email', $allowed_email);
        set_config('system', 'block_public', $block_public);
        set_config('system', 'publish_all', $force_publish);
-       set_config('system', 'directory', $global_directory);
        set_config('system', 'thread_allow', $thread_allow);
        set_config('system', 'newuser_private', $newuser_private);
        set_config('system', 'enotify_no_content', $enotify_no_content);
@@ -797,7 +904,6 @@ function admin_page_site_post(App $a) {
 
        set_config('system', 'force_ssl', $force_ssl);
        set_config('system', 'hide_help', $hide_help);
-       set_config('system', 'use_fulltext_engine', $use_fulltext_engine);
        set_config('system', 'itemcache', $itemcache);
        set_config('system', 'itemcache_duration', $itemcache_duration);
        set_config('system', 'max_comments', $max_comments);
@@ -830,7 +936,7 @@ function admin_page_site(App $a) {
        /* Installed langs */
        $lang_choices = get_available_languages();
 
-       if (strlen(get_config('system','directory_submit_url')) AND
+       if (strlen(get_config('system','directory_submit_url')) &&
                !strlen(get_config('system','directory'))) {
                        set_config('system','directory', dirname(get_config('system','directory_submit_url')));
                        del_config('system','directory_submit_url');
@@ -852,7 +958,7 @@ function admin_page_site(App $a) {
                        $f = basename($file);
 
                        // Only show allowed themes here
-                       if (($allowed_theme_list != '') AND !strstr($allowed_theme_list, $f)) {
+                       if (($allowed_theme_list != '') && !strstr($allowed_theme_list, $f)) {
                                continue;
                        }
 
@@ -1015,6 +1121,7 @@ function admin_page_site(App $a) {
                '$timeout'              => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")),
                '$maxloadavg'           => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
                '$maxloadavg_frontend'  => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")),
+               '$min_memory'           => array('min_memory', t("Minimal Memory"), ((intval(get_config('system','min_memory')) > 0)?get_config('system','min_memory'):0), t("Minimal free memory in MB for the poller. Needs access to /proc/meminfo - default 0 (deactivated).")),
                '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), $optimize_max_tablesize, t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")),
                '$optimize_fragmentation'=> array('optimize_fragmentation', t("Minimum level of fragmentation"), ((intval(get_config('system','optimize_fragmentation')) > 0)?get_config('system','optimize_fragmentation'):30), t("Minimum fragmenation level to start the automatic optimization - default value is 30%.")),
 
@@ -1026,7 +1133,6 @@ function admin_page_site(App $a) {
 
                '$nodeinfo'             => array('nodeinfo', t("Publish server information"), get_config('system','nodeinfo'), 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.")),
 
-               '$use_fulltext_engine'  => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system','use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")),
                '$suppress_tags'        => array('suppress_tags', t("Suppress Tags"), get_config('system','suppress_tags'), t("Suppress showing a list of hashtags at the end of the posting.")),
                '$itemcache'            => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), t("The item caches buffers generated bbcode and external images.")),
                '$itemcache_duration'   => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")),
@@ -1077,7 +1183,7 @@ function admin_page_dbsync(App $a) {
                goaway('admin/dbsync');
        }
 
-       if (($a->argc > 2) AND (intval($a->argv[2]) OR ($a->argv[2] === 'check'))) {
+       if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) {
                require_once("include/dbstructure.php");
                $retval = update_structure(false, true);
                if (!$retval) {
@@ -1345,8 +1451,8 @@ function admin_page_users(App $a) {
        $_setup_users = function ($e) use ($adminlist) {
                $accounts = array(
                        t('Normal Account'),
-                       t('Soapbox Account'),
-                       t('Community/Celebrity Account'),
+                       t('Automatic Follower Account'),
+                       t('Public Forum Account'),
                                                t('Automatic Friend Account')
                );
                $e['page-flags'] = $accounts[$e['page-flags']];
@@ -1557,7 +1663,7 @@ function admin_page_plugins(App $a) {
                                $show_plugin = true;
 
                                // If the addon is unsupported, then only show it, when it is enabled
-                               if ((strtolower($info["status"]) == "unsupported") AND !in_array($id,  $a->plugins)) {
+                               if ((strtolower($info["status"]) == "unsupported") && !in_array($id,  $a->plugins)) {
                                        $show_plugin = false;
                                }
 
@@ -1695,7 +1801,7 @@ function admin_page_themes(App $a) {
                        $is_supported = 1-(intval(file_exists($file.'/unsupported')));
                        $is_allowed = intval(in_array($f,$allowed_themes));
 
-                       if ($is_allowed OR $is_supported OR get_config("system", "show_unsupported_themes")) {
+                       if ($is_allowed || $is_supported || get_config("system", "show_unsupported_themes")) {
                                $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
                        }
                }