]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Admin/Blocklist/Server.php
post/thread views are renamed, search bugs fixed
[friendica.git] / src / Module / Admin / Blocklist / Server.php
index 1d0dc1fb869ed1a1f539a43b044390a62084fbc1..f1c55f4124c60a9313a0d18aaa0310dbecd64dee 100644 (file)
-<?php\r
-\r
-namespace Friendica\Module\Admin\Blocklist;\r
-\r
-use Friendica\Core\Config;\r
-use Friendica\Core\L10n;\r
-use Friendica\Core\Renderer;\r
-use Friendica\Core\System;\r
-use Friendica\Module\BaseAdminModule;\r
-use Friendica\Util\Strings;\r
-\r
-class Server extends BaseAdminModule\r
-{\r
-       public static function post()\r
-       {\r
-               parent::post();\r
-\r
-               if (empty($_POST['page_blocklist_save']) && empty($_POST['page_blocklist_edit'])) {\r
-                       return;\r
-               }\r
-\r
-               parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');\r
-\r
-               if (!empty($_POST['page_blocklist_save'])) {\r
-                       //  Add new item to blocklist\r
-                       $blocklist = Config::get('system', 'blocklist');\r
-                       $blocklist[] = [\r
-                               'domain' => Strings::escapeTags(trim($_POST['newentry_domain'])),\r
-                               'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))\r
-                       ];\r
-                       Config::set('system', 'blocklist', $blocklist);\r
-                       info(L10n::t('Server added to blocklist.') . EOL);\r
-               } else {\r
-                       // Edit the entries from blocklist\r
-                       $blocklist = [];\r
-                       foreach ($_POST['domain'] as $id => $domain) {\r
-                               // Trimming whitespaces as well as any lingering slashes\r
-                               $domain = Strings::escapeTags(trim($domain, "\x00..\x1F/"));\r
-                               $reason = Strings::escapeTags(trim($_POST['reason'][$id]));\r
-                               if (empty($_POST['delete'][$id])) {\r
-                                       $blocklist[] = [\r
-                                               'domain' => $domain,\r
-                                               'reason' => $reason\r
-                                       ];\r
-                               }\r
-                       }\r
-                       Config::set('system', 'blocklist', $blocklist);\r
-                       info(L10n::t('Site blocklist updated.') . EOL);\r
-               }\r
-\r
-               self::getApp()->internalRedirect('admin/blocklist/server');\r
-       }\r
-\r
-       public static function content()\r
-       {\r
-               parent::content();\r
-\r
-               $blocklist = Config::get('system', 'blocklist');\r
-               $blocklistform = [];\r
-               if (is_array($blocklist)) {\r
-                       foreach ($blocklist as $id => $b) {\r
-                               $blocklistform[] = [\r
-                                       'domain' => ["domain[$id]", L10n::t('Blocked domain'), $b['domain'], '', L10n::t('The blocked domain'), 'required', '', ''],\r
-                                       'reason' => ["reason[$id]", L10n::t("Reason for the block"), $b['reason'], L10n::t('The reason why you blocked this domain.') . '(' . $b['domain'] . ')', 'required', '', ''],\r
-                                       'delete' => ["delete[$id]", L10n::t("Delete domain") . ' (' . $b['domain'] . ')', false, L10n::t("Check to delete this entry from the blocklist")]\r
-                               ];\r
-                       }\r
-               }\r
-\r
-               $t = Renderer::getMarkupTemplate('admin/blocklist/server.tpl');\r
-               return Renderer::replaceMacros($t, [\r
-                       '$title' => L10n::t('Administration'),\r
-                       '$page' => L10n::t('Server Blocklist'),\r
-                       '$intro' => L10n::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.'),\r
-                       '$public' => L10n::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.'),\r
-                       '$addtitle' => L10n::t('Add new entry to block list'),\r
-                       '$newdomain' => ['newentry_domain', L10n::t('Server Domain'), '', L10n::t('The domain of the new server to add to the block list. Do not include the protocol.'), 'required', '', ''],\r
-                       '$newreason' => ['newentry_reason', L10n::t('Block reason'), '', L10n::t('The reason why you blocked this domain.'), 'required', '', ''],\r
-                       '$submit' => L10n::t('Add Entry'),\r
-                       '$savechanges' => L10n::t('Save changes to the blocklist'),\r
-                       '$currenttitle' => L10n::t('Current Entries in the Blocklist'),\r
-                       '$thurl' => L10n::t('Blocked domain'),\r
-                       '$threason' => L10n::t('Reason for the block'),\r
-                       '$delentry' => L10n::t('Delete entry from blocklist'),\r
-                       '$entries' => $blocklistform,\r
-                       '$baseurl' => System::baseUrl(true),\r
-                       '$confirm_delete' => L10n::t('Delete entry from blocklist?'),\r
-                       '$form_security_token' => parent::getFormSecurityToken("admin_blocklist")\r
-               ]);\r
-       }\r
-}
\ No newline at end of file
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Admin\Blocklist;
+
+use Friendica\Core\Renderer;
+use Friendica\DI;
+use Friendica\Module\BaseAdmin;
+use Friendica\Util\Strings;
+
+class Server extends BaseAdmin
+{
+       public static function post(array $parameters = [])
+       {
+               self::checkAdminAccess();
+
+               if (empty($_POST['page_blocklist_save']) && empty($_POST['page_blocklist_edit'])) {
+                       return;
+               }
+
+               self::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');
+
+               if (!empty($_POST['page_blocklist_save'])) {
+                       //  Add new item to blocklist
+                       $blocklist = DI::config()->get('system', 'blocklist');
+                       $blocklist[] = [
+                               'domain' => Strings::escapeTags(trim($_POST['newentry_domain'])),
+                               'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))
+                       ];
+                       DI::config()->set('system', 'blocklist', $blocklist);
+                       info(DI::l10n()->t('Server domain pattern added to blocklist.'));
+               } else {
+                       // Edit the entries from blocklist
+                       $blocklist = [];
+                       foreach ($_POST['domain'] as $id => $domain) {
+                               // Trimming whitespaces as well as any lingering slashes
+                               $domain = Strings::escapeTags(trim($domain, "\x00..\x1F/"));
+                               $reason = Strings::escapeTags(trim($_POST['reason'][$id]));
+                               if (empty($_POST['delete'][$id])) {
+                                       $blocklist[] = [
+                                               'domain' => $domain,
+                                               'reason' => $reason
+                                       ];
+                               }
+                       }
+                       DI::config()->set('system', 'blocklist', $blocklist);
+               }
+
+               DI::baseUrl()->redirect('admin/blocklist/server');
+       }
+
+       public static function content(array $parameters = [])
+       {
+               parent::content($parameters);
+
+               $blocklist = DI::config()->get('system', 'blocklist');
+               $blocklistform = [];
+               if (is_array($blocklist)) {
+                       foreach ($blocklist as $id => $b) {
+                               $blocklistform[] = [
+                                       'domain' => ["domain[$id]", DI::l10n()->t('Blocked server domain pattern'), $b['domain'], '', DI::l10n()->t('Required'), '', ''],
+                                       'reason' => ["reason[$id]", DI::l10n()->t("Reason for the block"), $b['reason'], '', DI::l10n()->t('Required'), '', ''],
+                                       'delete' => ["delete[$id]", DI::l10n()->t("Delete server domain pattern") . ' (' . $b['domain'] . ')', false, DI::l10n()->t("Check to delete this entry from the blocklist")]
+                               ];
+                       }
+               }
+
+               $t = Renderer::getMarkupTemplate('admin/blocklist/server.tpl');
+               return Renderer::replaceMacros($t, [
+                       '$title' => DI::l10n()->t('Administration'),
+                       '$page' => DI::l10n()->t('Server Domain Pattern Blocklist'),
+                       '$intro' => DI::l10n()->t('This page can be used to define a blocklist of server domain patterns from the federated network that are not allowed to interact with your node. For each domain pattern you should also provide the reason why you block it.'),
+                       '$public' => DI::l10n()->t('The list of blocked server domain patterns will be made publically available on the <a href="/friendica">/friendica</a> page so that your users and people investigating communication problems can find the reason easily.'),
+                       '$syntax' => DI::l10n()->t('<p>The server domain pattern syntax is case-insensitive shell wildcard, comprising the following special characters:</p>
+<ul>
+       <li><code>*</code>: Any number of characters</li>
+       <li><code>?</code>: Any single character</li>
+       <li><code>[&lt;char1&gt;&lt;char2&gt;...]</code>: char1 or char2</li>
+</ul>'),
+                       '$addtitle' => DI::l10n()->t('Add new entry to block list'),
+                       '$newdomain' => ['newentry_domain', DI::l10n()->t('Server Domain Pattern'), '', DI::l10n()->t('The domain pattern of the new server to add to the block list. Do not include the protocol.'), DI::l10n()->t('Required'), '', ''],
+                       '$newreason' => ['newentry_reason', DI::l10n()->t('Block reason'), '', DI::l10n()->t('The reason why you blocked this server domain pattern.'), DI::l10n()->t('Required'), '', ''],
+                       '$submit' => DI::l10n()->t('Add Entry'),
+                       '$savechanges' => DI::l10n()->t('Save changes to the blocklist'),
+                       '$currenttitle' => DI::l10n()->t('Current Entries in the Blocklist'),
+                       '$thurl' => DI::l10n()->t('Blocked server domain pattern'),
+                       '$threason' => DI::l10n()->t('Reason for the block'),
+                       '$delentry' => DI::l10n()->t('Delete entry from blocklist'),
+                       '$entries' => $blocklistform,
+                       '$baseurl' => DI::baseUrl()->get(true),
+                       '$confirm_delete' => DI::l10n()->t('Delete entry from blocklist?'),
+                       '$form_security_token' => self::getFormSecurityToken("admin_blocklist")
+               ]);
+       }
+}