3 namespace Friendica\Module\Admin\Blocklist;
5 use Friendica\Core\Config;
6 use Friendica\Core\Renderer;
8 use Friendica\Module\BaseAdminModule;
9 use Friendica\Util\Strings;
11 class Server extends BaseAdminModule
13 public static function post(array $parameters = [])
15 parent::post($parameters);
17 if (empty($_POST['page_blocklist_save']) && empty($_POST['page_blocklist_edit'])) {
21 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');
23 if (!empty($_POST['page_blocklist_save'])) {
24 // Add new item to blocklist
25 $blocklist = DI::config()->get('system', 'blocklist');
27 'domain' => Strings::escapeTags(trim($_POST['newentry_domain'])),
28 'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))
30 Config::set('system', 'blocklist', $blocklist);
31 info(DI::l10n()->t('Server domain pattern added to blocklist.') . EOL);
33 // Edit the entries from blocklist
35 foreach ($_POST['domain'] as $id => $domain) {
36 // Trimming whitespaces as well as any lingering slashes
37 $domain = Strings::escapeTags(trim($domain, "\x00..\x1F/"));
38 $reason = Strings::escapeTags(trim($_POST['reason'][$id]));
39 if (empty($_POST['delete'][$id])) {
46 Config::set('system', 'blocklist', $blocklist);
47 info(DI::l10n()->t('Site blocklist updated.') . EOL);
50 DI::baseUrl()->redirect('admin/blocklist/server');
53 public static function content(array $parameters = [])
55 parent::content($parameters);
57 $blocklist = DI::config()->get('system', 'blocklist');
59 if (is_array($blocklist)) {
60 foreach ($blocklist as $id => $b) {
62 'domain' => ["domain[$id]", DI::l10n()->t('Blocked server domain pattern'), $b['domain'], '', 'required', '', ''],
63 'reason' => ["reason[$id]", DI::l10n()->t("Reason for the block"), $b['reason'], '', 'required', '', ''],
64 'delete' => ["delete[$id]", DI::l10n()->t("Delete server domain pattern") . ' (' . $b['domain'] . ')', false, DI::l10n()->t("Check to delete this entry from the blocklist")]
69 $t = Renderer::getMarkupTemplate('admin/blocklist/server.tpl');
70 return Renderer::replaceMacros($t, [
71 '$title' => DI::l10n()->t('Administration'),
72 '$page' => DI::l10n()->t('Server Domain Pattern Blocklist'),
73 '$intro' => DI::l10n()->t('This page can be used to define a blacklist 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.'),
74 '$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.'),
75 '$syntax' => DI::l10n()->t('<p>The server domain pattern syntax is case-insensitive shell wildcard, comprising the following special characters:</p>
77 <li><code>*</code>: Any number of characters</li>
78 <li><code>?</code>: Any single character</li>
79 <li><code>[<char1><char2>...]</code>: char1 or char2</li>
81 '$addtitle' => DI::l10n()->t('Add new entry to block list'),
82 '$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', '', ''],
83 '$newreason' => ['newentry_reason', DI::l10n()->t('Block reason'), '', DI::l10n()->t('The reason why you blocked this server domain pattern.'), 'required', '', ''],
84 '$submit' => DI::l10n()->t('Add Entry'),
85 '$savechanges' => DI::l10n()->t('Save changes to the blocklist'),
86 '$currenttitle' => DI::l10n()->t('Current Entries in the Blocklist'),
87 '$thurl' => DI::l10n()->t('Blocked server domain pattern'),
88 '$threason' => DI::l10n()->t('Reason for the block'),
89 '$delentry' => DI::l10n()->t('Delete entry from blocklist'),
90 '$entries' => $blocklistform,
91 '$baseurl' => DI::baseUrl()->get(true),
92 '$confirm_delete' => DI::l10n()->t('Delete entry from blocklist?'),
93 '$form_security_token' => parent::getFormSecurityToken("admin_blocklist")