]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Blocklist/Server.php
Merge pull request #7044 from MrPetovan/task/router
[friendica.git] / src / Module / Admin / Blocklist / Server.php
1 <?php
2
3 namespace Friendica\Module\Admin\Blocklist;
4
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;
10
11 class Server extends BaseAdminModule
12 {
13         public static function post()
14         {
15                 parent::post();
16
17                 if (empty($_POST['page_blocklist_save']) && empty($_POST['page_blocklist_edit'])) {
18                         return;
19                 }
20
21                 parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');
22
23                 if (!empty($_POST['page_blocklist_save'])) {
24                         //  Add new item to blocklist
25                         $blocklist = Config::get('system', 'blocklist');
26                         $blocklist[] = [
27                                 'domain' => Strings::escapeTags(trim($_POST['newentry_domain'])),
28                                 'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))
29                         ];
30                         Config::set('system', 'blocklist', $blocklist);
31                         info(L10n::t('Server added to blocklist.') . EOL);
32                 } else {
33                         // Edit the entries from blocklist
34                         $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])) {
40                                         $blocklist[] = [
41                                                 'domain' => $domain,
42                                                 'reason' => $reason
43                                         ];
44                                 }
45                         }
46                         Config::set('system', 'blocklist', $blocklist);
47                         info(L10n::t('Site blocklist updated.') . EOL);
48                 }
49
50                 self::getApp()->internalRedirect('admin/blocklist/server');
51         }
52
53         public static function content()
54         {
55                 parent::content();
56
57                 $a = self::getApp();
58
59                 $blocklist = Config::get('system', 'blocklist');
60                 $blocklistform = [];
61                 if (is_array($blocklist)) {
62                         foreach ($blocklist as $id => $b) {
63                                 $blocklistform[] = [
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")]
67                                 ];
68                         }
69                 }
70
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")
90                 ]);
91         }
92 }