Merge pull request #7431 from MrPetovan/task/server-blocklist-wildcard

Add shell wildcard patterns feature to server blocklist
This commit is contained in:
Philipp 2019-07-27 19:03:15 +02:00 committed by GitHub
commit a2d9a2865a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1511 additions and 1376 deletions

View File

@ -23,15 +23,20 @@ class ServerBlock extends Console
protected function getHelp()
{
$help = <<<HELP
console serverblock - Manage blocked servers
console serverblock - Manage blocked server domain patterns
Usage
bin/console serverblock [-h|--help|-?] [-v]
bin/console serverblock add <server> <reason> [-h|--help|-?] [-v]
bin/console serverblock remove <server> [-h|--help|-?] [-v]
bin/console serverblock add <pattern> <reason> [-h|--help|-?] [-v]
bin/console serverblock remove <pattern> [-h|--help|-?] [-v]
Description
With this tool, you can list the current blocked servers
or you can add / remove a blocked server from the list
With this tool, you can list the current blocked server domain patterns
or you can add / remove a blocked server domain pattern from the list.
Patterns are case-insensitive shell wildcard comprising the following special characters:
- * : Any number of characters
- ? : Any single character
- [<char1><char2>...] : char1 or char2 or...
Options
-h|--help|-? Show help information

View File

@ -28,7 +28,7 @@ class Server extends BaseAdminModule
'reason' => Strings::escapeTags(trim($_POST['newentry_reason']))
];
Config::set('system', 'blocklist', $blocklist);
info(L10n::t('Server added to blocklist.') . EOL);
info(L10n::t('Server domain pattern added to blocklist.') . EOL);
} else {
// Edit the entries from blocklist
$blocklist = [];
@ -61,9 +61,9 @@ class Server extends BaseAdminModule
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")]
'domain' => ["domain[$id]", L10n::t('Blocked server domain pattern'), $b['domain'], '', 'required', '', ''],
'reason' => ["reason[$id]", L10n::t("Reason for the block"), $b['reason'], '', 'required', '', ''],
'delete' => ["delete[$id]", L10n::t("Delete server domain pattern") . ' (' . $b['domain'] . ')', false, L10n::t("Check to delete this entry from the blocklist")]
];
}
}
@ -71,16 +71,22 @@ class Server extends BaseAdminModule
$t = Renderer::getMarkupTemplate('admin/blocklist/server.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.'),
'$page' => L10n::t('Server Domain Pattern Blocklist'),
'$intro' => L10n::t('This page can be used to define a blacklist of server domain patterns from the federated network that are not allowed to interact with your node. For each domain pattern you should also provide the reason why you block it.'),
'$public' => L10n::t('The list of blocked server domain patterns will be made publically available on the <a href="/friendica">/friendica</a> page so that your users and people investigating communication problems can find the reason easily.'),
'$syntax' => L10n::t('<p>The server domain pattern syntax is case-insensitive shell wildcard, comprising the following special characters:</p>
<ul>
<li><code>*</code>: Any number of characters</li>
<li><code>?</code>: Any single character</li>
<li><code>[&lt;char1&gt;&lt;char2&gt;...]</code>: char1 or char2</li>
</ul>'),
'$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', '', ''],
'$newdomain' => ['newentry_domain', L10n::t('Server Domain Pattern'), '', L10n::t('The domain pattern 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 server domain pattern.'), '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'),
'$thurl' => L10n::t('Blocked server domain pattern'),
'$threason' => L10n::t('Reason for the block'),
'$delentry' => L10n::t('Delete entry from blocklist'),
'$entries' => $blocklistform,

View File

@ -472,7 +472,7 @@ class Network
}
foreach ($domain_blocklist as $domain_block) {
if (strcasecmp($domain_block['domain'], $host) === 0) {
if (fnmatch(strtolower($domain_block['domain']), strtolower($host))) {
return true;
}
}

View File

@ -316,15 +316,20 @@ CONS;
$txt = $this->dumpExecute($console);
$help = <<<HELP
console serverblock - Manage blocked servers
console serverblock - Manage blocked server domain patterns
Usage
bin/console serverblock [-h|--help|-?] [-v]
bin/console serverblock add <server> <reason> [-h|--help|-?] [-v]
bin/console serverblock remove <server> [-h|--help|-?] [-v]
bin/console serverblock add <pattern> <reason> [-h|--help|-?] [-v]
bin/console serverblock remove <pattern> [-h|--help|-?] [-v]
Description
With this tool, you can list the current blocked servers
or you can add / remove a blocked server from the list
With this tool, you can list the current blocked server domain patterns
or you can add / remove a blocked server domain pattern from the list.
Patterns are case-insensitive shell wildcard comprising the following special characters:
- * : Any number of characters
- ? : Any single character
- [<char1><char2>...] : char1 or char2 or...
Options
-h|--help|-? Show help information

File diff suppressed because it is too large Load Diff

View File

@ -6,14 +6,17 @@
<div id="adminpage">
<h1>{{$title}} - {{$page}}</h1>
<p>{{$intro}}</p>
<p>{{$public}}</p>
<p>{{$public nofilter}}</p>
{{$syntax nofilter}}
<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>
<div class="submit">
<button type="submit" class="btn btn-primary" name="page_blocklist_save" value="{{$submit}}">{{$submit}}</button>
</div>
</form>
{{if $entries}}
@ -26,8 +29,9 @@
{{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>
<div class="submit">
<button type="submit" class="btn btn-primary" name="page_blocklist_edit" value="{{$savechanges}}">{{$savechanges}}</button>
</div>
{{/if}}
</form>
</div>