]> git.mxchange.org Git - friendica.git/commitdiff
Move admin/blocklist/server to src/Module
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 22 Apr 2019 01:40:05 +0000 (21:40 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 13:52:47 +0000 (09:52 -0400)
- Add Module\Admin\Blocklist\Server class
- Add route for admin/blocklist/server
- Add server blocklist admin aside menu entry
- Move templates/admin/blocklist.tpl to templates/admin/blocklist/server.tpl
- Remove admin_page_blocklist and admin_page_blocklist_post from mod/admin.php

mod/admin.php
src/App/Router.php
src/Module/Admin/Blocklist/Server.php [new file with mode: 0644]
src/Module/BaseAdminModule.php
view/templates/admin/blocklist.tpl [deleted file]
view/templates/admin/blocklist/server.tpl [new file with mode: 0644]

index 3684e114483c70a27b7b0823f14f1e3707a84795..e77780c086ed45a1331b895497f16371d09e965e 100644 (file)
@@ -114,9 +114,6 @@ function admin_post(App $a)
                        case 'logs':
                                admin_page_logs_post($a);
                                break;
-                       case 'blocklist':
-                               admin_page_blocklist_post($a);
-                               break;
                        case 'deleteitem':
                                admin_page_deleteitem_post($a);
                                break;
@@ -237,9 +234,6 @@ function admin_content(App $a)
                        case 'workerqueue':
                                $o = admin_page_workerqueue($a, false);
                                break;
-                       case 'blocklist':
-                               $o = admin_page_blocklist($a);
-                               break;
                        case 'deleteitem':
                                $o = admin_page_deleteitem($a);
                                break;
@@ -256,98 +250,6 @@ function admin_content(App $a)
        }
 }
 
-/**
- * @brief Subpage to modify the server wide block list via the admin panel.
- *
- * This function generates the subpage of the admin panel to allow the
- * modification of the node wide block/black list to block entire
- * remote servers from communication with this node. The page allows
- * adding, removing and editing of entries from the blocklist.
- *
- * @param App $a
- * @return string
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_blocklist(App $a)
-{
-       $blocklist = Config::get('system', 'blocklist');
-       $blocklistform = [];
-       if (is_array($blocklist)) {
-               foreach ($blocklist as $id => $b) {
-                       $blocklistform[] = [
-                               'domain' => ["domain[$id]", L10n::t('Blocked domain'), $b['domain'], '', L10n::t('The blocked domain'), 'required', '', ''],
-                               'reason' => ["reason[$id]", L10n::t("Reason for the block"), $b['reason'], L10n::t('The reason why you blocked this domain.') . '(' . $b['domain'] . ')', 'required', '', ''],
-                               'delete' => ["delete[$id]", L10n::t("Delete domain") . ' (' . $b['domain'] . ')', false, L10n::t("Check to delete this entry from the blocklist")]
-                       ];
-               }
-       }
-       $t = Renderer::getMarkupTemplate('admin/blocklist.tpl');
-       return Renderer::replaceMacros($t, [
-               '$title' => L10n::t('Administration'),
-               '$page' => L10n::t('Server Blocklist'),
-               '$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.'),
-               '$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.'),
-               '$addtitle' => L10n::t('Add new entry to block list'),
-               '$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', '', ''],
-               '$newreason' => ['newentry_reason', L10n::t('Block reason'), '', L10n::t('The reason why you blocked this domain.'), 'required', '', ''],
-               '$submit' => L10n::t('Add Entry'),
-               '$savechanges' => L10n::t('Save changes to the blocklist'),
-               '$currenttitle' => L10n::t('Current Entries in the Blocklist'),
-               '$thurl' => L10n::t('Blocked domain'),
-               '$threason' => L10n::t('Reason for the block'),
-               '$delentry' => L10n::t('Delete entry from blocklist'),
-               '$entries' => $blocklistform,
-               '$baseurl' => System::baseUrl(true),
-               '$confirm_delete' => L10n::t('Delete entry from blocklist?'),
-               '$form_security_token' => BaseModule::getFormSecurityToken("admin_blocklist")
-       ]);
-}
-
-/**
- * @brief Process send data from Admin Blocklist Page
- *
- * @param App $a
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_blocklist_post(App $a)
-{
-       if (empty($_POST['page_blocklist_save']) && empty($_POST['page_blocklist_edit'])) {
-               return;
-       }
-
-       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/blocklist', 'admin_blocklist');
-
-       if (!empty($_POST['page_blocklist_save'])) {
-               //  Add new item to blocklist
-               $blocklist = Config::get('system', 'blocklist');
-               $blocklist[] = [
-                       'domain' => Strings::escapeTags(trim($_POST['newentry_domain'])),
-                       'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))
-               ];
-               Config::set('system', 'blocklist', $blocklist);
-               info(L10n::t('Server added to blocklist.') . EOL);
-       } else {
-               // Edit the entries from blocklist
-               $blocklist = [];
-               foreach ($_POST['domain'] as $id => $domain) {
-                       // Trimming whitespaces as well as any lingering slashes
-                       $domain = Strings::escapeTags(trim($domain, "\x00..\x1F/"));
-                       $reason = Strings::escapeTags(trim($_POST['reason'][$id]));
-                       if (empty($_POST['delete'][$id])) {
-                               $blocklist[] = [
-                                       'domain' => $domain,
-                                       'reason' => $reason
-                               ];
-                       }
-               }
-               Config::set('system', 'blocklist', $blocklist);
-               info(L10n::t('Site blocklist updated.') . EOL);
-       }
-       $a->internalRedirect('admin/blocklist');
-
-       return; // NOTREACHED
-}
-
 /**
  * @brief Subpage where the admin can delete an item from their node given the GUID
  *
index 71b8ebe7aa91a51c081373936e738b180f246e40..1cf19c53d6f707d307afadcc5c33a7aed055dff2 100644 (file)
@@ -125,6 +125,8 @@ class Router
                        $collector->addRoute(['GET', 'POST'], '/addons/{addon}'         , Module\Admin\Addons\Details::class);
 
                        $collector->addRoute(['GET', 'POST'], '/blocklist/contact'      , Module\Admin\Blocklist\Contact::class);
+                       $collector->addRoute(['GET', 'POST'], '/blocklist/server'       , Module\Admin\Blocklist\Server::class);
+
                        $collector->addRoute(['GET', 'POST'], '/features'               , Module\Admin\Features::class);
                        $collector->addRoute(['GET']        , '/federation'             , Module\Admin\Federation::class);
 
diff --git a/src/Module/Admin/Blocklist/Server.php b/src/Module/Admin/Blocklist/Server.php
new file mode 100644 (file)
index 0000000..1d0dc1f
--- /dev/null
@@ -0,0 +1,91 @@
+<?php\r
+\r
+namespace Friendica\Module\Admin\Blocklist;\r
+\r
+use Friendica\Core\Config;\r
+use Friendica\Core\L10n;\r
+use Friendica\Core\Renderer;\r
+use Friendica\Core\System;\r
+use Friendica\Module\BaseAdminModule;\r
+use Friendica\Util\Strings;\r
+\r
+class Server extends BaseAdminModule\r
+{\r
+       public static function post()\r
+       {\r
+               parent::post();\r
+\r
+               if (empty($_POST['page_blocklist_save']) && empty($_POST['page_blocklist_edit'])) {\r
+                       return;\r
+               }\r
+\r
+               parent::checkFormSecurityTokenRedirectOnError('/admin/blocklist/server', 'admin_blocklist');\r
+\r
+               if (!empty($_POST['page_blocklist_save'])) {\r
+                       //  Add new item to blocklist\r
+                       $blocklist = Config::get('system', 'blocklist');\r
+                       $blocklist[] = [\r
+                               'domain' => Strings::escapeTags(trim($_POST['newentry_domain'])),\r
+                               'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))\r
+                       ];\r
+                       Config::set('system', 'blocklist', $blocklist);\r
+                       info(L10n::t('Server added to blocklist.') . EOL);\r
+               } else {\r
+                       // Edit the entries from blocklist\r
+                       $blocklist = [];\r
+                       foreach ($_POST['domain'] as $id => $domain) {\r
+                               // Trimming whitespaces as well as any lingering slashes\r
+                               $domain = Strings::escapeTags(trim($domain, "\x00..\x1F/"));\r
+                               $reason = Strings::escapeTags(trim($_POST['reason'][$id]));\r
+                               if (empty($_POST['delete'][$id])) {\r
+                                       $blocklist[] = [\r
+                                               'domain' => $domain,\r
+                                               'reason' => $reason\r
+                                       ];\r
+                               }\r
+                       }\r
+                       Config::set('system', 'blocklist', $blocklist);\r
+                       info(L10n::t('Site blocklist updated.') . EOL);\r
+               }\r
+\r
+               self::getApp()->internalRedirect('admin/blocklist/server');\r
+       }\r
+\r
+       public static function content()\r
+       {\r
+               parent::content();\r
+\r
+               $blocklist = Config::get('system', 'blocklist');\r
+               $blocklistform = [];\r
+               if (is_array($blocklist)) {\r
+                       foreach ($blocklist as $id => $b) {\r
+                               $blocklistform[] = [\r
+                                       'domain' => ["domain[$id]", L10n::t('Blocked domain'), $b['domain'], '', L10n::t('The blocked domain'), 'required', '', ''],\r
+                                       'reason' => ["reason[$id]", L10n::t("Reason for the block"), $b['reason'], L10n::t('The reason why you blocked this domain.') . '(' . $b['domain'] . ')', 'required', '', ''],\r
+                                       'delete' => ["delete[$id]", L10n::t("Delete domain") . ' (' . $b['domain'] . ')', false, L10n::t("Check to delete this entry from the blocklist")]\r
+                               ];\r
+                       }\r
+               }\r
+\r
+               $t = Renderer::getMarkupTemplate('admin/blocklist/server.tpl');\r
+               return Renderer::replaceMacros($t, [\r
+                       '$title' => L10n::t('Administration'),\r
+                       '$page' => L10n::t('Server Blocklist'),\r
+                       '$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
+                       '$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
+                       '$addtitle' => L10n::t('Add new entry to block list'),\r
+                       '$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
+                       '$newreason' => ['newentry_reason', L10n::t('Block reason'), '', L10n::t('The reason why you blocked this domain.'), 'required', '', ''],\r
+                       '$submit' => L10n::t('Add Entry'),\r
+                       '$savechanges' => L10n::t('Save changes to the blocklist'),\r
+                       '$currenttitle' => L10n::t('Current Entries in the Blocklist'),\r
+                       '$thurl' => L10n::t('Blocked domain'),\r
+                       '$threason' => L10n::t('Reason for the block'),\r
+                       '$delentry' => L10n::t('Delete entry from blocklist'),\r
+                       '$entries' => $blocklistform,\r
+                       '$baseurl' => System::baseUrl(true),\r
+                       '$confirm_delete' => L10n::t('Delete entry from blocklist?'),\r
+                       '$form_security_token' => parent::getFormSecurityToken("admin_blocklist")\r
+               ]);\r
+       }\r
+}
\ No newline at end of file
index 31f279bca7731db22b34e5165e95e6a8eff3b770..bc84ad8873f279038af943fae654275167f9493d 100644 (file)
@@ -61,6 +61,7 @@ abstract class BaseAdminModule extends BaseModule
                        ]],\r
                        'tools' => [L10n::t('Tools'), [\r
                                'contactblock' => ['admin/blocklist/contact', L10n::t('Contact Blocklist')  , 'contactblock'],\r
+                               'blocklist'    => ['admin/blocklist/server' , L10n::t('Server Blocklist')   , 'blocklist'],\r
                        ]],\r
                ];\r
 \r
diff --git a/view/templates/admin/blocklist.tpl b/view/templates/admin/blocklist.tpl
deleted file mode 100644 (file)
index 1484c98..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<script>
-       function confirm_delete(uname){
-               return confirm("{{$confirm_delete}}".format(uname));
-       }
-</script>
-<div id="adminpage">
-       <h1>{{$title}} - {{$page}}</h1>
-       <p>{{$intro}}</p>
-       <p>{{$public}}</p>
-
-       <h2>{{$addtitle}}</h2>
-       <form action="{{$baseurl}}/admin/blocklist" method="post">
-               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
-               {{include file="field_input.tpl" field=$newdomain}}
-               {{include file="field_input.tpl" field=$newreason}}
-               <div class="submit"><input type="submit" name="page_blocklist_save" value="{{$submit}}" /></div>
-       </form>
-
-       {{if $entries}}
-       <h2>{{$currenttitle}}</h2>
-       <p>{{$currentintro}}</p>
-       <form action="{{$baseurl}}/admin/blocklist" method="post">
-               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
-               {{foreach $entries as $e}}
-                       {{include file="field_input.tpl" field=$e.domain}}
-                       {{include file="field_input.tpl" field=$e.reason}}
-                       {{include file="field_checkbox.tpl" field=$e.delete}}
-               {{/foreach}}
-               <div class="submit"><input type="submit" name="page_blocklist_edit" value="{{$savechanges}}" /></div>
-               {{/if}}
-       </form>
-
-</div>
diff --git a/view/templates/admin/blocklist/server.tpl b/view/templates/admin/blocklist/server.tpl
new file mode 100644 (file)
index 0000000..beea96f
--- /dev/null
@@ -0,0 +1,33 @@
+<script>
+       function confirm_delete(uname){
+               return confirm("{{$confirm_delete}}".format(uname));
+       }
+</script>
+<div id="adminpage">
+       <h1>{{$title}} - {{$page}}</h1>
+       <p>{{$intro}}</p>
+       <p>{{$public}}</p>
+
+       <h2>{{$addtitle}}</h2>
+       <form action="{{$baseurl}}/admin/blocklist/server" method="post">
+               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
+               {{include file="field_input.tpl" field=$newdomain}}
+               {{include file="field_input.tpl" field=$newreason}}
+               <div class="submit"><input type="submit" name="page_blocklist_save" value="{{$submit}}" /></div>
+       </form>
+
+       {{if $entries}}
+       <h2>{{$currenttitle}}</h2>
+       <p>{{$currentintro}}</p>
+       <form action="{{$baseurl}}/admin/blocklist/server" method="post">
+               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
+               {{foreach $entries as $e}}
+                       {{include file="field_input.tpl" field=$e.domain}}
+                       {{include file="field_input.tpl" field=$e.reason}}
+                       {{include file="field_checkbox.tpl" field=$e.delete}}
+               {{/foreach}}
+               <div class="submit"><input type="submit" name="page_blocklist_edit" value="{{$savechanges}}" /></div>
+               {{/if}}
+       </form>
+
+</div>