3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Admin\Blocklist;
24 use Friendica\Core\Renderer;
26 use Friendica\Module\BaseAdmin;
27 use Friendica\Util\Strings;
29 class Server extends BaseAdmin
31 public static function post(array $parameters = [])
33 parent::post($parameters);
35 if (empty($_POST['page_blocklist_save']) && empty($_POST['page_blocklist_edit'])) {
39 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');
41 if (!empty($_POST['page_blocklist_save'])) {
42 // Add new item to blocklist
43 $blocklist = DI::config()->get('system', 'blocklist');
45 'domain' => Strings::escapeTags(trim($_POST['newentry_domain'])),
46 'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))
48 DI::config()->set('system', 'blocklist', $blocklist);
49 info(DI::l10n()->t('Server domain pattern added to blocklist.') . EOL);
51 // Edit the entries from blocklist
53 foreach ($_POST['domain'] as $id => $domain) {
54 // Trimming whitespaces as well as any lingering slashes
55 $domain = Strings::escapeTags(trim($domain, "\x00..\x1F/"));
56 $reason = Strings::escapeTags(trim($_POST['reason'][$id]));
57 if (empty($_POST['delete'][$id])) {
64 DI::config()->set('system', 'blocklist', $blocklist);
67 DI::baseUrl()->redirect('admin/blocklist/server');
70 public static function content(array $parameters = [])
72 parent::content($parameters);
74 $blocklist = DI::config()->get('system', 'blocklist');
76 if (is_array($blocklist)) {
77 foreach ($blocklist as $id => $b) {
79 'domain' => ["domain[$id]", DI::l10n()->t('Blocked server domain pattern'), $b['domain'], '', 'required', '', ''],
80 'reason' => ["reason[$id]", DI::l10n()->t("Reason for the block"), $b['reason'], '', 'required', '', ''],
81 'delete' => ["delete[$id]", DI::l10n()->t("Delete server domain pattern") . ' (' . $b['domain'] . ')', false, DI::l10n()->t("Check to delete this entry from the blocklist")]
86 $t = Renderer::getMarkupTemplate('admin/blocklist/server.tpl');
87 return Renderer::replaceMacros($t, [
88 '$title' => DI::l10n()->t('Administration'),
89 '$page' => DI::l10n()->t('Server Domain Pattern Blocklist'),
90 '$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.'),
91 '$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.'),
92 '$syntax' => DI::l10n()->t('<p>The server domain pattern syntax is case-insensitive shell wildcard, comprising the following special characters:</p>
94 <li><code>*</code>: Any number of characters</li>
95 <li><code>?</code>: Any single character</li>
96 <li><code>[<char1><char2>...]</code>: char1 or char2</li>
98 '$addtitle' => DI::l10n()->t('Add new entry to block list'),
99 '$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.'), 'required', '', ''],
100 '$newreason' => ['newentry_reason', DI::l10n()->t('Block reason'), '', DI::l10n()->t('The reason why you blocked this server domain pattern.'), 'required', '', ''],
101 '$submit' => DI::l10n()->t('Add Entry'),
102 '$savechanges' => DI::l10n()->t('Save changes to the blocklist'),
103 '$currenttitle' => DI::l10n()->t('Current Entries in the Blocklist'),
104 '$thurl' => DI::l10n()->t('Blocked server domain pattern'),
105 '$threason' => DI::l10n()->t('Reason for the block'),
106 '$delentry' => DI::l10n()->t('Delete entry from blocklist'),
107 '$entries' => $blocklistform,
108 '$baseurl' => DI::baseUrl()->get(true),
109 '$confirm_delete' => DI::l10n()->t('Delete entry from blocklist?'),
110 '$form_security_token' => parent::getFormSecurityToken("admin_blocklist")