<commit_before><?php
/**
 * @copyright Copyright (C) 2020, Friendica
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

namespace Friendica\Console;

use Asika\SimpleConsole\CommandArgsException;
use Asika\SimpleConsole\Console;
use Console_Table;
use Friendica\Core\Config\IConfig;

/**
 * Manage blocked servers
 *
 * With this tool, you can list the current blocked servers
 * or you can add / remove a blocked server from the list
 */
class ServerBlock extends Console
{
	const DEFAULT_REASON = 'blocked';

	protected $helpOptions = ['h', 'help', '?'];

	/**
	 * @var IConfig
	 */
	private $config;

	protected function getHelp()
	{
		$help = <<<HELP
console serverblock - Manage blocked server domain patterns
Usage
	bin/console serverblock [-h|--help|-?] [-v]
	bin/console serverblock add <pattern> <reason> [-h|--help|-?] [-v]
	bin/console serverblock remove <pattern> [-h|--help|-?] [-v]
	bin/console serverblock export <filename>
	bin/console serverblock import <filename>

Description
	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.
	Using the export and import options you can share your server blocklist
	with other node admins by CSV files.
	
	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
	-v		   Show more debug information.
HELP;
		return $help;
	}

	public function __construct(IConfig $config, $argv = null)
	{
		parent::__construct($argv);

		$this->config = $config;
	}

	protected function doExecute()
	{
		if (count($this->args) == 0) {
			$this->printBlockedServers($this->config);
			return 0;
		}

		switch ($this->getArgument(0)) {
			case 'add':
				return $this->addBlockedServer($this->config);
			case 'remove':
				return $this->removeBlockedServer($this->config);
			case 'export':
				return $this->exportBlockedServers($this->config);<commit_msg>spaces instead of tabs here<commit_after><?php
/**
 * @copyright Copyright (C) 2020, Friendica
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

namespace Friendica\Console;

use Asika\SimpleConsole\CommandArgsException;
use Asika\SimpleConsole\Console;
use Console_Table;
use Friendica\Core\Config\IConfig;

/**
 * Manage blocked servers
 *
 * With this tool, you can list the current blocked servers
 * or you can add / remove a blocked server from the list
 */
class ServerBlock extends Console
{
	const DEFAULT_REASON = 'blocked';

	protected $helpOptions = ['h', 'help', '?'];

	/**
	 * @var IConfig
	 */
	private $config;

	protected function getHelp()
	{
		$help = <<<HELP
console serverblock - Manage blocked server domain patterns
Usage
	bin/console serverblock [-h|--help|-?] [-v]
	bin/console serverblock add <pattern> <reason> [-h|--help|-?] [-v]
	bin/console serverblock remove <pattern> [-h|--help|-?] [-v]
	bin/console serverblock export <filename>
	bin/console serverblock import <filename>

Description
	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.
	Using the export and import options you can share your server blocklist
	with other node admins by CSV files.
	
	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
	-v           Show more debug information.
HELP;
		return $help;
	}

	public function __construct(IConfig $config, $argv = null)
	{
		parent::__construct($argv);

		$this->config = $config;
	}

	protected function doExecute()
	{
		if (count($this->args) == 0) {
			$this->printBlockedServers($this->config);
			return 0;
		}

		switch ($this->getArgument(0)) {
			case 'add':
				return $this->addBlockedServer($this->config);
			case 'remove':
				return $this->removeBlockedServer($this->config);
			case 'export':
				return $this->exportBlockedServers($this->config);
{'fraction_non_alphanumeric': 0.10632911392405063, 'fraction_numerical': 0.004701627486437613, 'mean_word_length': 3.8645558487247142, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5257771', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1565, 'n_words': 635}