From 7f837a92053bdcae88f75344c8deffeb3b1bdb58 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 24 Apr 2017 23:43:39 +0200 Subject: [PATCH 1/5] add the contents from the blocklist to the /friendica page --- mod/friendica.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mod/friendica.php b/mod/friendica.php index f613dfd39c..230ffd8bcc 100644 --- a/mod/friendica.php +++ b/mod/friendica.php @@ -104,6 +104,16 @@ function friendica_content(App $a) { else $o .= '

' . t('No installed plugins/addons/apps') . '

'; + $blocklist = Config::get('system', 'blocklist'); + if (count($blocklist)) { + $o .= '

'. t('On this server the following remote servers are blocked.') .'

'; + $o .= ''; + foreach ($blocklist as $b) { + $o .= ''; + } + $o .= '
'. t('Blocked URL') .''. t('Reason for the block') .'
'. $b['URL'] .''. $b['reason'] .'
'; + } + call_hooks('about_hook', $o); return $o; From 1a436281c5ecdf348cb3d965cfb28db04a3eedd2 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 24 Apr 2017 23:44:27 +0200 Subject: [PATCH 2/5] added template for the blocklist editor in the admin panel --- view/templates/admin_blocklist.tpl | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 view/templates/admin_blocklist.tpl diff --git a/view/templates/admin_blocklist.tpl b/view/templates/admin_blocklist.tpl new file mode 100644 index 0000000000..c7ee47c59b --- /dev/null +++ b/view/templates/admin_blocklist.tpl @@ -0,0 +1,33 @@ + +
+

{{$title}} - {{$page}}

+

{{$intro}}

+

{{$public}}

+ +

{{$addtitle}}

+
+ + {{include file="field_input.tpl" field=$newurl}} + {{include file="field_input.tpl" field=$newreason}} +
+
+ + {{if $entries}} +

{{$currenttitle}}

+

{{$currentintro}}

+
+ + {{foreach $entries as $e}} + {{include file="field_input.tpl" field=$e.url}} + {{include file="field_input.tpl" field=$e.reason}} + {{include file="field_checkbox.tpl" field=$e.delete}} + {{/foreach}} +
+ {{/if}} +
+ +
From f969f446034794e599de021cd6f7c53ba3c47e39 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 24 Apr 2017 23:45:05 +0200 Subject: [PATCH 3/5] added subpage for blocklist management to the admin panel --- mod/admin.php | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/mod/admin.php b/mod/admin.php index 6be08f45a7..3aeee6d8ec 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -109,6 +109,9 @@ function admin_post(App $a) { case 'dbsync': admin_page_dbsync_post($a); break; + case 'blocklist': + admin_page_blocklist_post($a); + break; } } @@ -166,6 +169,7 @@ function admin_content(App $a) { 'features' => array("admin/features/", t("Additional features") , "features"), 'dbsync' => array("admin/dbsync/", t('DB updates'), "dbsync"), 'queue' => array("admin/queue/", t('Inspect Queue'), "queue"), + 'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"), 'federation' => array("admin/federation/", t('Federation Statistics'), "federation"), ); @@ -236,6 +240,9 @@ function admin_content(App $a) { case 'federation': $o = admin_page_federation($a); break; + case 'blocklist': + $o = admin_page_blocklist($a); + break; default: notice(t("Item not found.")); } @@ -252,6 +259,92 @@ 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. + * + * @param App $a + * @return string + */ +function admin_page_blocklist(App $a) { + $blocklist = Config::get('system', 'blocklist'); + $blocklistform = array(); + if (is_array($blocklist)) { + foreach($blocklist as $id =>$b) { + $blocklistform[] = Array( + 'url' => Array("url[$id]", t('Blocked URL'), $b['URL'], '', t('The blocked URL'), 'required', '', ''), + 'reason' => Array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this URL.').'('.$b['URL'].')', 'required', '', ''), + 'delete' => Array("delete[$id]", t("Delete UFL").' ('.$b['URL'].')', False , "Check to delete this entry from the blocklist") + ); + } + } + $t = get_markup_template("admin_blocklist.tpl"); + return replace_macros($t, array( + '$title' => t('Administration'), + '$page' => t('Server Blocklist'), + '$intro' => 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 URLs you should also give a reason, why you have blocked the remote server.'), + '$public' => 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' => t('Add new entry to block list'), + '$newurl' => Array('newentry_url', t('Server URL'), '', t('The URL of the new server to add to the block list. Do not include the protocol to the URL.'), 'required', '', ''), + '$newreason' => Array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this URL.'), 'required', '', ''), + '$submit' => t('Add Entry'), + '$savechanges' => t('Save changes to the blocklist'), + '$currenttitle' => t('Current Entries in the Blocklist'), + '$thurl' => t('Blocked URL'), + '$threason' => t('Reason for the block'), + '$delentry' => t('Delete entry from blocklist'), + '$entries' => $blocklistform, + '$baseurl' => App::get_baseurl(true), + '$confirm_delete' => t('Delete entriy from blocklist?'), + '$form_security_token' => get_form_security_token("admin_blocklist") + )); +} + +/** + * @brief Process send data from Admin Blocklist Page + * + * @param App $a + */ +function admin_page_blocklist_post(App $a) { + if (!x($_POST,"page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) { + return; + } + + check_form_security_token_redirectOnErr('/admin/blocklist', 'admin_blocklist'); + + if (x($_POST['page_blocklist_save'])) { + // Add new item to blocklist + $blocklist = get_config('system', 'blocklist'); + $blocklist[] = Array( + 'URL' => notags(trim($_POST['newentry_url'])), + 'reason' => notags(trim($_POST['newentry_reason'])) + ); + Config::set('system', 'blocklist', $blocklist); + info(t('Server added to blocklist.').EOL); + } else { + // Edit the entries from blocklist + $blocklist = array(); + foreach ($_POST['url'] as $id => $URL) { + $URL = notags(trim($URL)); + $reason = notags(trim($_POST['reason'][$id])); + if (!x($_POST['delete'][$id])) { + $blocklist[] = Array( + 'URL' => $URL, + 'reason' => $reason + ); + } + } + Config::set('system', 'blocklist', $blocklist); + info(t('Site blocklist updated.').EOL); + } + goaway('admin/blocklist'); + + return; // NOTREACHED +} + /** * @brief Subpage with some stats about "the federation" network * From eeb72bd8798e14fdc81510a677cae569e2a68429 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 24 Apr 2017 23:47:05 +0200 Subject: [PATCH 4/5] docstrings for the admin panel functions --- mod/admin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mod/admin.php b/mod/admin.php index 3aeee6d8ec..7f96983dfd 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -264,7 +264,8 @@ function admin_content(App $a) { * * 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. + * remote servers from communication with this node. The page allows + * adding, removing and editing of entries from the blocklist. * * @param App $a * @return string From f146c85e75314462823076a9d89ac2e698e6de45 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Tue, 25 Apr 2017 18:57:50 +0200 Subject: [PATCH 5/5] standards --- mod/admin.php | 20 ++++++++++---------- view/templates/admin_blocklist.tpl | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 7f96983dfd..a783ded0a3 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -274,11 +274,11 @@ function admin_page_blocklist(App $a) { $blocklist = Config::get('system', 'blocklist'); $blocklistform = array(); if (is_array($blocklist)) { - foreach($blocklist as $id =>$b) { - $blocklistform[] = Array( - 'url' => Array("url[$id]", t('Blocked URL'), $b['URL'], '', t('The blocked URL'), 'required', '', ''), - 'reason' => Array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this URL.').'('.$b['URL'].')', 'required', '', ''), - 'delete' => Array("delete[$id]", t("Delete UFL").' ('.$b['URL'].')', False , "Check to delete this entry from the blocklist") + foreach($blocklist as $id => $b) { + $blocklistform[] = array( + 'url' => array("url[$id]", t('Blocked URL'), $b['URL'], '', t('The blocked URL'), 'required', '', ''), + 'reason' => array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this URL.').'('.$b['URL'].')', 'required', '', ''), + 'delete' => array("delete[$id]", t("Delete UFL").' ('.$b['URL'].')', False , "Check to delete this entry from the blocklist") ); } } @@ -289,8 +289,8 @@ function admin_page_blocklist(App $a) { '$intro' => 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 URLs you should also give a reason, why you have blocked the remote server.'), '$public' => 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' => t('Add new entry to block list'), - '$newurl' => Array('newentry_url', t('Server URL'), '', t('The URL of the new server to add to the block list. Do not include the protocol to the URL.'), 'required', '', ''), - '$newreason' => Array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this URL.'), 'required', '', ''), + '$newurl' => array('newentry_url', t('Server URL'), '', t('The URL of the new server to add to the block list. Do not include the protocol to the URL.'), 'required', '', ''), + '$newreason' => array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this URL.'), 'required', '', ''), '$submit' => t('Add Entry'), '$savechanges' => t('Save changes to the blocklist'), '$currenttitle' => t('Current Entries in the Blocklist'), @@ -299,7 +299,7 @@ function admin_page_blocklist(App $a) { '$delentry' => t('Delete entry from blocklist'), '$entries' => $blocklistform, '$baseurl' => App::get_baseurl(true), - '$confirm_delete' => t('Delete entriy from blocklist?'), + '$confirm_delete' => t('Delete entry from blocklist?'), '$form_security_token' => get_form_security_token("admin_blocklist") )); } @@ -319,7 +319,7 @@ function admin_page_blocklist_post(App $a) { if (x($_POST['page_blocklist_save'])) { // Add new item to blocklist $blocklist = get_config('system', 'blocklist'); - $blocklist[] = Array( + $blocklist[] = array( 'URL' => notags(trim($_POST['newentry_url'])), 'reason' => notags(trim($_POST['newentry_reason'])) ); @@ -332,7 +332,7 @@ function admin_page_blocklist_post(App $a) { $URL = notags(trim($URL)); $reason = notags(trim($_POST['reason'][$id])); if (!x($_POST['delete'][$id])) { - $blocklist[] = Array( + $blocklist[] = array( 'URL' => $URL, 'reason' => $reason ); diff --git a/view/templates/admin_blocklist.tpl b/view/templates/admin_blocklist.tpl index c7ee47c59b..e888dcd936 100644 --- a/view/templates/admin_blocklist.tpl +++ b/view/templates/admin_blocklist.tpl @@ -1,16 +1,16 @@
-

{{$title}} - {{$page}}

-

{{$intro}}

+

{{$title}} - {{$page}}

+

{{$intro}}

{{$public}}

{{$addtitle}}

- + {{include file="field_input.tpl" field=$newurl}} {{include file="field_input.tpl" field=$newreason}}
@@ -20,7 +20,7 @@

{{$currenttitle}}

{{$currentintro}}

- + {{foreach $entries as $e}} {{include file="field_input.tpl" field=$e.url}} {{include file="field_input.tpl" field=$e.reason}} @@ -29,5 +29,5 @@
{{/if}}
- +