3 namespace Friendica\Module\Admin\Blocklist;
\r
5 use Friendica\Core\Config;
\r
6 use Friendica\Core\L10n;
\r
7 use Friendica\Core\Renderer;
\r
8 use Friendica\Module\BaseAdminModule;
\r
9 use Friendica\Util\Strings;
\r
11 class Server extends BaseAdminModule
\r
13 public static function post()
\r
17 if (empty($_POST['page_blocklist_save']) && empty($_POST['page_blocklist_edit'])) {
\r
21 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');
\r
23 if (!empty($_POST['page_blocklist_save'])) {
\r
24 // Add new item to blocklist
\r
25 $blocklist = Config::get('system', 'blocklist');
\r
27 'domain' => Strings::escapeTags(trim($_POST['newentry_domain'])),
\r
28 'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))
\r
30 Config::set('system', 'blocklist', $blocklist);
\r
31 info(L10n::t('Server added to blocklist.') . EOL);
\r
33 // Edit the entries from blocklist
\r
35 foreach ($_POST['domain'] as $id => $domain) {
\r
36 // Trimming whitespaces as well as any lingering slashes
\r
37 $domain = Strings::escapeTags(trim($domain, "\x00..\x1F/"));
\r
38 $reason = Strings::escapeTags(trim($_POST['reason'][$id]));
\r
39 if (empty($_POST['delete'][$id])) {
\r
41 'domain' => $domain,
\r
46 Config::set('system', 'blocklist', $blocklist);
\r
47 info(L10n::t('Site blocklist updated.') . EOL);
\r
50 self::getApp()->internalRedirect('admin/blocklist/server');
\r
53 public static function content()
\r
57 $a = self::getApp();
\r
59 $blocklist = Config::get('system', 'blocklist');
\r
60 $blocklistform = [];
\r
61 if (is_array($blocklist)) {
\r
62 foreach ($blocklist as $id => $b) {
\r
63 $blocklistform[] = [
\r
64 'domain' => ["domain[$id]", L10n::t('Blocked domain'), $b['domain'], '', L10n::t('The blocked domain'), 'required', '', ''],
\r
65 'reason' => ["reason[$id]", L10n::t("Reason for the block"), $b['reason'], L10n::t('The reason why you blocked this domain.') . '(' . $b['domain'] . ')', 'required', '', ''],
\r
66 'delete' => ["delete[$id]", L10n::t("Delete domain") . ' (' . $b['domain'] . ')', false, L10n::t("Check to delete this entry from the blocklist")]
\r
71 $t = Renderer::getMarkupTemplate('admin/blocklist/server.tpl');
\r
72 return Renderer::replaceMacros($t, [
\r
73 '$title' => L10n::t('Administration'),
\r
74 '$page' => L10n::t('Server Blocklist'),
\r
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.'),
\r
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.'),
\r
77 '$addtitle' => L10n::t('Add new entry to block list'),
\r
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', '', ''],
\r
79 '$newreason' => ['newentry_reason', L10n::t('Block reason'), '', L10n::t('The reason why you blocked this domain.'), 'required', '', ''],
\r
80 '$submit' => L10n::t('Add Entry'),
\r
81 '$savechanges' => L10n::t('Save changes to the blocklist'),
\r
82 '$currenttitle' => L10n::t('Current Entries in the Blocklist'),
\r
83 '$thurl' => L10n::t('Blocked domain'),
\r
84 '$threason' => L10n::t('Reason for the block'),
\r
85 '$delentry' => L10n::t('Delete entry from blocklist'),
\r
86 '$entries' => $blocklistform,
\r
87 '$baseurl' => $a->getBaseURL(true),
\r
88 '$confirm_delete' => L10n::t('Delete entry from blocklist?'),
\r
89 '$form_security_token' => parent::getFormSecurityToken("admin_blocklist")
\r