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 relay servers
74 bin/console relay add <actor>
77 bin/console relay remove <actor>
81 -h|--help|-? Show help information
82 -v Show more debug information.
87 /** @var $dba Friendica\Database\Database */
90 public function __construct(Friendica\Database\Database $dba, array $argv = null)
92 parent::__construct($argv);
97 protected function doExecute()
99 if ($this->getOption('v')) {
100 $this->out('Executable: ' . $this->executable);
101 $this->out('Class: ' . __CLASS__);
102 $this->out('Arguments: ' . var_export($this->args, true));
103 $this->out('Options: ' . var_export($this->options, true));
106 if (count($this->args) > 2) {
107 throw new CommandArgsException('Too many arguments');
110 if (count($this->args) == 1) {
111 throw new CommandArgsException('Too few arguments');
114 if (count($this->args) == 0) {
115 $contacts = $this->dba->select('apcontact', ['url'],
116 ["`type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))",
117 'Application', 0, Contact::FOLLOWER, Contact::FRIEND]);
118 while ($contact = $this->dba->fetch($contacts)) {
119 $this->out($contact['url']);
121 $this->dba->close($contacts);
124 if (count($this->args) == 2) {
125 $mode = $this->getArgument(0);
126 $actor = $this->getArgument(1);
128 $apcontact = APContact::getByURL($actor);
129 if (empty($apcontact) || ($apcontact['type'] != 'Application')) {
130 $this->out($actor . ' is no relay actor');
134 if ($mode == 'add') {
135 if (Transmitter::sendRelayFollow($actor)) {
136 $this->out('Successfully added ' . $actor);
138 $this->out($actor . " couldn't be added");
140 } elseif ($mode == 'remove') {
141 if (Transmitter::sendRelayUndoFollow($actor)) {
142 $this->out('Successfully removed ' . $actor);
144 $this->out($actor . " couldn't be removed");
147 throw new CommandArgsException($mode . ' is no valid command');