3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Console;
24 use Asika\SimpleConsole\CommandArgsException;
26 use Friendica\Database\DBA;
27 use Friendica\Model\APContact;
28 use Friendica\Model\Contact;
29 use Friendica\Protocol\ActivityPub\Transmitter;
32 * tool to access the system config from the CLI
34 * With this script you can access the system configuration of your node from
35 * the CLI. You can do both, reading current values stored in the database and
36 * set new values to config variables.
39 * If you specify no parameters at the CLI, the script will list all config
42 * If you specify one parameter, the script will list all config variables
43 * defined in this section of the configuration (e.g. "system").
45 * If you specify two parameters, the script will show you the current value
46 * of the named configuration setting. (e.g. "system loglevel")
48 * If you specify three parameters, the named configuration setting will be
49 * set to the value of the last parameter. (e.g. "system loglevel 0" will
52 class Relay extends \Asika\SimpleConsole\Console
54 protected $helpOptions = ['h', 'help', '?'];
61 protected function getHelp()
64 console relay - Manage ActivityPub relay configuration
66 bin/console relay [-h|--help|-?] [-v]
67 bin/console relay add <actor> [-h|--help|-?] [-v]
68 bin/console relay remove <actoor> [-h|--help|-?] [-v]
72 Lists all active relais
74 bin/console relay add <actor>
77 bin/console relay remove <actoor>
81 -h|--help|-? Show help information
82 -v Show more debug information.
87 public function __construct(App\Mode $appMode, array $argv = null)
89 parent::__construct($argv);
91 $this->appMode = $appMode;
94 protected function doExecute()
96 if ($this->getOption('v')) {
97 $this->out('Executable: ' . $this->executable);
98 $this->out('Class: ' . __CLASS__);
99 $this->out('Arguments: ' . var_export($this->args, true));
100 $this->out('Options: ' . var_export($this->options, true));
103 if (count($this->args) > 2) {
104 throw new CommandArgsException('Too many arguments');
107 if (count($this->args) == 1) {
108 throw new CommandArgsException('Too few arguments');
111 if (count($this->args) == 0) {
112 $contacts = DBA::select('apcontact', ['url'],
113 ["`type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))",
114 'Application', 0, Contact::FOLLOWER, Contact::FRIEND]);
115 while ($contact = DBA::fetch($contacts)) {
116 $this->out($contact['url']);
118 DBA::close($contacts);
121 if (count($this->args) == 2) {
122 $mode = $this->getArgument(0);
123 $actor = $this->getArgument(1);
125 $apcontact = APContact::getByURL($actor);
126 if (empty($apcontact) || ($apcontact['type'] != 'Application')) {
127 $this->out($actor . ' is no relay actor');
131 if ($mode == 'add') {
132 if (Transmitter::sendRelayFollow($actor)) {
133 $this->out('Successfully added ' . $actor);
135 $this->out($actor . " couldn't be added");
137 } elseif ($mode == 'remove') {
138 if (Transmitter::sendRelayUndoFollow($actor)) {
139 $this->out('Successfully removed ' . $actor);
141 $this->out($actor . " couldn't be removed");
144 throw new CommandArgsException($mode . ' is no valid command');