1
0
Fork 0
mirror of https://github.com/MetaProvide/talked-client.git synced 2025-04-07 14:15:41 +00:00

Add admin settings ()

This commit is contained in:
Magnus Walbeck 2021-08-12 16:34:59 +02:00 committed by GitHub
parent 5402304b64
commit 8140443561
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 331 additions and 9 deletions

View file

@ -19,4 +19,7 @@
<commands>
<command>OCA\Talked\Command\Record</command>
</commands>
<settings>
<admin>OCA\Talked\Settings\Admin</admin>
</settings>
</info>

31
appinfo/routes.php Normal file
View file

@ -0,0 +1,31 @@
<?php
/**
* Talked - Call recording for Nextcloud Talk
*
* @copyright Copyright (C) 2021 Magnus Walbeck <mw@mwalbeck.org>
*
* @author Magnus Walbeck <mw@mwalbeck.org>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
return [
'routes' => [
['name' => 'Settings#admin', 'url' => '/settings/admin', 'verb' => 'POST']
],
];

13
css/settings.css Normal file
View file

@ -0,0 +1,13 @@
.talked-admin.section {
border-top: 1px solid var(--color-border);
}
.talked-admin input {
margin-bottom: 1em;
}
.talked-admin input[type=text],
.talked-admin input[type=password] {
width: 480px;
display: block;
}

64
js/settings.js Normal file
View file

@ -0,0 +1,64 @@
/**
* Talked - Call recording for Nextcloud
*
* @copyright Copyright (C) 2021 Magnus Walbeck <mw@mwalbeck.org>
*
* @author Magnus Walbeck <mw@mwalbeck.org>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
function postSuccess(selector, id) {
$(selector).after(
" <span id='" + id + "' class='msg success'>" + t("talked", "Saved") + "</span>"
);
setTimeout(function () {
$("#" + id).remove();
}, 3000);
}
function postError(selector, id) {
$(selector).after(
" <span id='" + id + "' class='msg error'>" + t("talked", "Error") + "</span>"
);
setTimeout(function () {
$("#" + id).remove();
}, 3000);
}
window.addEventListener("DOMContentLoaded", function () {
$("#talked-save-settings").click(function () {
$.post(OC.generateUrl("apps/talked/settings/admin"), {
server_url: $("#talked-server-url").val(),
use_http_basic_auth: $("#talked-use-http-basic-auth").prop("checked") ? 1 : 0,
http_basic_auth_username: $("#talked-http-basic-auth-username").val(),
http_basic_auth_password: $("#talked-http-basic-auth-password").val(),
})
.done(function () {
postSuccess(
"#talked-save-settings",
"talked-save-settings-msg"
);
})
.fail(function () {
postError(
"#talked-save-settings",
"talked-save-settings-msg"
);
});
});
});

View file

@ -1,5 +1,4 @@
<?php
declare(strict_types=1);
/**
@ -69,16 +68,16 @@ class Record extends Command
{
$token = $input->getArgument('token');
$argument = $input->getArgument('argument');
$talkedServer = $this->config->getAppValue('talked', 'talked_server', '');
$serverUrl = $this->config->getAppValue('talked', 'server_url', '');
if ($talkedServer === '') {
if ($serverUrl === '') {
$output->writeln("A recording server hasn't been configured yet.");
return 0;
}
if ($argument === 'info') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $talkedServer);
curl_setopt($ch, CURLOPT_URL, $serverUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
@ -93,7 +92,7 @@ class Record extends Command
'token' => $token
];
$result = $this->sendPostRequest($talkedServer, 'status', $payload);
$result = $this->sendPostRequest($serverUrl, 'status', $payload);
$output->writeln($result);
@ -105,7 +104,7 @@ class Record extends Command
'token' => $token
];
$result = $this->sendPostRequest($talkedServer, 'start', $payload);
$result = $this->sendPostRequest($serverUrl, 'start', $payload);
$output->writeln($result);
@ -117,7 +116,7 @@ class Record extends Command
'token' => $token
];
$result = $this->sendPostRequest($talkedServer, 'stop', $payload);
$result = $this->sendPostRequest($serverUrl, 'stop', $payload);
$output->writeln($result);
@ -128,11 +127,11 @@ class Record extends Command
return 0;
}
protected function sendPostRequest($base_url, $endpoint, $payload, $headers = []) {
protected function sendPostRequest($serverUrl, $endpoint, $payload, $headers = []) {
$headers[] = 'Content-Type: application/json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url . '/' . $endpoint);
curl_setopt($ch, CURLOPT_URL, $serverUrl . '/' . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));

View file

@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
/**
* Talked - Call recording for Nextcloud Talk
*
* @copyright Copyright (C) 2021 Magnus Walbeck <mw@mwalbeck.org>
*
* @author Magnus Walbeck <mw@mwalbeck.org>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Talked\Controller;
use OCP\AppFramework\Controller;
use OCP\IConfig;
use OCP\IRequest;
class SettingsController extends Controller
{
/** @var string */
public const APP_NAME = 'talked';
/** @var IConfig */
private $config;
/**
* @param IConfig $config
* @param IRequest $request
*/
public function __construct(
IConfig $config,
IRequest $request
) {
parent::__construct(self::APP_NAME, $request);
$this->config = $config;
}
/**
* Set talked options
*/
public function admin(): void
{
if ($this->request->getParam("server_url")) {
$this->config->setAppValue(self::APP_NAME, "server_url", $this->request->getParam("server_url"));
} else {
$this->config->setAppValue(self::APP_NAME, "server_url", "");
}
if ($this->request->getParam("use_http_basic_auth")) {
$this->config->setAppValue(self::APP_NAME, "use_http_basic_auth", "1");
} else {
$this->config->setAppValue(self::APP_NAME, "use_http_basic_auth", "0");
}
if ($this->request->getParam("http_basic_auth_username")) {
$this->config->setAppValue(self::APP_NAME, "http_basic_auth_username", $this->request->getParam("http_basic_auth_username"));
} else {
$this->config->setAppValue(self::APP_NAME, "http_basic_auth_username", "");
}
if ($this->request->getParam("http_basic_auth_password")) {
$this->config->setAppValue(self::APP_NAME, "http_basic_auth_password", $this->request->getParam("http_basic_auth_password"));
} else {
$this->config->setAppValue(self::APP_NAME, "http_basic_auth_password", "");
}
}
}

83
lib/Settings/Admin.php Normal file
View file

@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/**
* Talked - Call recording for Nextcloud Talk
*
* @copyright Copyright (C) 2021 Magnus Walbeck <mw@mwalbeck.org>
*
* @author Magnus Walbeck <mw@mwalbeck.org>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Talked\Settings;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\Settings\ISettings;
class Admin implements ISettings
{
/** @var string */
public const APP_NAME = 'talked';
/** @var IConfig */
private $config;
/**
* @param IConfig $config
*/
public function __construct(IConfig $config)
{
$this->config = $config;
}
/**
* @return TemplateResponse
*/
public function getForm(): TemplateResponse
{
$serverUrl = $this->config->getAppValue(self::APP_NAME, 'server_url', "");
$useHttpBasicAuth = $this->config->getAppValue(self::APP_NAME, 'use_http_basic_auth', "0");
$HttpBasicAuthUsername = $this->config->getAppValue(self::APP_NAME, 'http_basic_auth_username', "");
$HttpBasicAuthPassword = $this->config->getAppValue(self::APP_NAME, 'http_basic_auth_password', "");
return new TemplateResponse('talked', 'admin', [
"serverUrl" => $serverUrl,
"useHttpBasicAuth" => $useHttpBasicAuth,
"HttpBasicAuthUsername" => $HttpBasicAuthUsername,
"HttpBasicAuthPassword" => $HttpBasicAuthPassword
]);
}
/**
* @return string
*/
public function getSection(): string
{
return 'talk';
}
/**
* @return int
*/
public function getPriority(): int
{
return 50;
}
}

45
templates/admin.php Normal file
View file

@ -0,0 +1,45 @@
<?php
/**
* Talked - Call recording for Nextcloud Talk
*
* @copyright Copyright (C) 2021 Magnus Walbeck <mw@mwalbeck.org>
*
* @author Magnus Walbeck <mw@mwalbeck.org>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
style('talked', 'settings');
script('talked', 'settings');
?>
<div id="talked" class="talked-admin section">
<h2><?php p($l->t("Talked")); ?></h2>
<h3><?php p($l->t("Talked server URL")); ?></h3>
<input type="text" class="" id="talked-server-url" value="<?php p($serverUrl); ?>">
<input type="checkbox" class="checkbox" id="talked-use-http-basic-auth" <?php p($useHttpBasicAuth ? "checked" : ""); ?>>
<label for="talked-use-http-basic-auth"><?php p($l->t("Use HTTP Basic auth for the Talked server")); ?></label>
<h3><?php p($l->t("HTTP Basic username")); ?></h3>
<input type="text" class="" id="talked-http-basic-auth-username" value="<?php p($HttpBasicAuthUsername); ?>">
<h3><?php p($l->t("HTTP Basic password")); ?></h3>
<input type="password" class="" id="talked-http-basic-auth-password" value="<?php p($HttpBasicAuthPassword); ?>">
<button id="talked-save-settings"><?php p($l->t("Save")); ?></button>
</div>