migrate admin additional settings implementation

This commit is contained in:
binsky 2021-03-13 20:05:16 +01:00
parent 3358d5de8b
commit 7065a60686
5 changed files with 120 additions and 46 deletions

View file

@ -56,4 +56,7 @@ For an demo of this app visit [https://demo.passman.cc](https://demo.passman.cc)
</post-migration>
</repair-steps>
<settings>
<admin>OCA\Passman\Settings\Admin</admin>
</settings>
</info>

View file

@ -115,14 +115,11 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
$l = \OC::$server->getL10N(self::APP_ID);
/** @var IManager $manager */
$manager = $context->getAppContainer()->get(IManager::class);
$manager->registerNotifierService(Notifier::class);
Util::addTranslations(self::APP_ID);
\OCP\App::registerAdmin(self::APP_ID, 'templates/admin.settings');
}
/**

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

@ -0,0 +1,113 @@
<?php
/**
* Nextcloud - passman
*
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @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\Passman\Settings;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use OCP\App;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Settings\ISettings;
class Admin implements ISettings {
protected IConfig $config;
private IL10N $l;
/**
* Admin constructor.
* @param IConfig $config
* @param IL10N $l
*/
public function __construct(IConfig $config, IL10N $l) {
$this->config = $config;
$this->l = $l;
}
/**
* @return TemplateResponse
*/
public function getForm(): TemplateResponse {
$checkVersion = $this->config->getAppValue('passman', 'check_version', '1') === '1';
$AppInstance = new App();
$localVersion = $AppInstance->getAppInfo("passman")["version"];
$githubVersion = $this->l->t('Unable to get version info');
if ($checkVersion) {
// get latest master version
$version = false;
$url = 'https://raw.githubusercontent.com/nextcloud/passman/master/appinfo/info.xml';
try {
$httpClient = new Client();
$response = $httpClient->request('get', $url);
$xml = $response->getBody()->getContents();
} catch (GuzzleException $e) {
$xml = false;
}
if ($xml) {
$data = @simplexml_load_string($xml);
// libxml_disable_entity_loader is deprecated with php8, the vulnerability is disabled by default by libxml with php8
if (\PHP_VERSION_ID < 80000) {
$loadEntities = libxml_disable_entity_loader(true);
$data = @simplexml_load_string($xml);
libxml_disable_entity_loader($loadEntities);
}
if ($data !== false) {
$version = (string)$data->version;
} else {
libxml_clear_errors();
}
}
if ($version !== false) {
$githubVersion = $version;
}
}
// $ciphers = openssl_get_cipher_methods();
return new TemplateResponse('passman', 'admin', [
'localVersion' => $localVersion,
'githubVersion' => $githubVersion,
'checkVersion' => $checkVersion,
], 'blank');
}
/**
* @return string
*/
public function getSection(): string {
return 'additional';
}
/**
* @return int
*/
public function getPriority(): int {
return 100;
}
}

View file

@ -1,58 +1,23 @@
<?php
/** @var \OCP\IL10N $l */
/** @var array $_ */
use \OCP\App;
script('passman', 'settings-admin');
style('passman', 'admin');
style('passman', 'vendor/font-awesome/font-awesome.min');
$checkVersion = OC::$server->getConfig()->getAppValue('passman', 'check_version', '1') === '1';
$AppInstance = new App();
$localVersion = $AppInstance->getAppInfo("passman")["version"];
$githubVersion = $l->t('Unable to get version info');
if ($checkVersion) {
// get latest master version
$version = false;
$url = 'https://raw.githubusercontent.com/nextcloud/passman/master/appinfo/info.xml';
try {
$client = OC::$server->getHTTPClientService()->newClient();
$response = $client->get($url);
$xml = $response->getBody();
} catch (\Exception $e) {
$xml = false;
}
if ($xml) {
$loadEntities = libxml_disable_entity_loader(true);
$data = @simplexml_load_string($xml);
libxml_disable_entity_loader($loadEntities);
if ($data !== false) {
$version = (string)$data->version;
} else {
libxml_clear_errors();
}
}
if ($version !== false) {
$githubVersion = $version;
}
}
$ciphers = openssl_get_cipher_methods();
?>
<div id="passwordSharingSettings" class="followup section">
<h2><?php p($l->t('Passman Settings')); ?></h2>
<?php
if ($checkVersion) {
p($l->t('GitHub version:') . ' ' . $githubVersion);
if ($_['checkVersion']) {
p($l->t('GitHub version:') . ' ' . $_['githubVersion']);
print '<br />';
} ?>
Local version: <?php p($localVersion); ?><br/>
Local version: <?php p($_['localVersion']); ?><br/>
<?php
if ($checkVersion && version_compare($githubVersion, $localVersion) === 1) {
if ($_['checkVersion'] && version_compare($_['githubVersion'], $_['localVersion']) === 1) {
p($l->t('A newer version of Passman is available'));
}
?>

View file

@ -1,4 +0,0 @@
<?php
namespace OCA\Passman;
$tmpl = new \OCP\Template('passman', 'part.admin');
return $tmpl->fetchPage();