3 namespace Friendica\Module\Admin\Blocklist;
5 use Friendica\Core\Config;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Renderer;
8 use Friendica\Module\BaseAdminModule;
9 use Friendica\Util\Strings;
11 class Server extends BaseAdminModule
13 public static function post()
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 = 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(L10n::t('Server 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(L10n::t('Site blocklist updated.') . EOL);
50 self::getApp()->internalRedirect('admin/blocklist/server');
53 public static function content()
59 $blocklist = Config::get('system', 'blocklist');
61 if (is_array($blocklist)) {
62 foreach ($blocklist as $id => $b) {
64 'domain' => ["domain[$id]", L10n::t('Blocked domain'), $b['domain'], '', L10n::t('The blocked domain'), 'required', '', ''],
65 'reason' => ["reason[$id]", L10n::t("Reason for the block"), $b['reason'], L10n::t('The reason why you blocked this domain.') . '(' . $b['domain'] . ')', 'required', '', ''],
66 'delete' => ["delete[$id]", L10n::t("Delete domain") . ' (' . $b['domain'] . ')', false, L10n::t("Check to delete this entry from the blocklist")]
71 $t = Renderer::getMarkupTemplate('admin/blocklist/server.tpl');
72 return Renderer::replaceMacros($t, [
73 '$title' => L10n::t('Administration'),
74 '$page' => L10n::t('Server Blocklist'),
75 '$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.'),
76 '$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.'),
77 '$addtitle' => L10n::t('Add new entry to block list'),
78 '$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', '', ''],
79 '$newreason' => ['newentry_reason', L10n::t('Block reason'), '', L10n::t('The reason why you blocked this domain.'), 'required', '', ''],
80 '$submit' => L10n::t('Add Entry'),
81 '$savechanges' => L10n::t('Save changes to the blocklist'),
82 '$currenttitle' => L10n::t('Current Entries in the Blocklist'),
83 '$thurl' => L10n::t('Blocked domain'),
84 '$threason' => L10n::t('Reason for the block'),
85 '$delentry' => L10n::t('Delete entry from blocklist'),
86 '$entries' => $blocklistform,
87 '$baseurl' => $a->getBaseURL(true),
88 '$confirm_delete' => L10n::t('Delete entry from blocklist?'),
89 '$form_security_token' => parent::getFormSecurityToken("admin_blocklist")