diff --git a/solid/appinfo/info.xml b/solid/appinfo/info.xml index 3c0abed4..83a87d13 100644 --- a/solid/appinfo/info.xml +++ b/solid/appinfo/info.xml @@ -21,7 +21,8 @@ When you do this, the Solid App can store data in your Nextcloud account through - \OCA\Solid\Settings + OCA\Solid\Settings\SolidAdmin + OCA\Solid\Sections\SolidAdmin diff --git a/solid/img/app-dark.svg b/solid/img/app-dark.svg new file mode 100644 index 00000000..dcb6b7ee --- /dev/null +++ b/solid/img/app-dark.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/solid/lib/BaseServerConfig.php b/solid/lib/BaseServerConfig.php new file mode 100644 index 00000000..a932b76f --- /dev/null +++ b/solid/lib/BaseServerConfig.php @@ -0,0 +1,69 @@ +config = $config; + } + + /** + * @return string + */ + public function getPrivateKey() { + $result = $this->config->getAppValue('solid','privateKey'); + if (!$result) { + // generate and save a new set if we don't have a private key; + $keys = $this->generateKeySet(); + $this->config->setAppValue('solid','privateKey',$keys['privateKey']); + $this->config->setAppValue('solid','encryptionKey',$keys['encryptionKey']); + } + return $this->config->getAppValue('solid','privateKey'); + } + + /** + * @param string $privateKey + */ + public function setPrivateKey($privateKey) { + $this->config->setAppValue('solid','privateKey',$privateKey); + } + + /** + * @return string + */ + public function getEncryptionKey() { + return $this->config->getAppValue('solid','encryptionKey'); + } + + /** + * @param string $publicKey + */ + public function setEncryptionKey($publicKey) { + $this->config->setAppValue('solid','encryptionKey',$publicKey); + } + + private function generateKeySet() { + $config = array( + "digest_alg" => "sha256", + "private_key_bits" => 2048, + "private_key_type" => OPENSSL_KEYTYPE_RSA, + ); + // Create the private and public key + $key = openssl_pkey_new($config); + + // Extract the private key from $key to $privateKey + openssl_pkey_export($key, $privateKey); + $encryptionKey = base64_encode(random_bytes(32)); + $result = array( + "privateKey" => $privateKey, + "encryptionKey" => $encryptionKey + ); + return $result; + } + } diff --git a/solid/lib/Sections/SolidAdmin.php b/solid/lib/Sections/SolidAdmin.php new file mode 100644 index 00000000..59a5c9b1 --- /dev/null +++ b/solid/lib/Sections/SolidAdmin.php @@ -0,0 +1,32 @@ +l = $l; + $this->urlGenerator = $urlGenerator; + } + + public function getIcon(): string { + return $this->urlGenerator->imagePath('solid', 'app-dark.svg'); + } + + public function getID(): string { + return 'solid'; + } + + public function getName(): string { + return $this->l->t('Solid'); + } + + public function getPriority(): int { + return 98; + } +} diff --git a/solid/lib/ServerConfig.php b/solid/lib/ServerConfig.php index 590a3719..7536f2cf 100644 --- a/solid/lib/ServerConfig.php +++ b/solid/lib/ServerConfig.php @@ -4,56 +4,26 @@ use OCP\IConfig; use OCP\IUserManager; use OCP\IUrlGenerator; - + use OCA\Solid\BaseServerConfig; + /** * @package OCA\Solid */ - class ServerConfig { - /** @var IConfig */ - private $config; + class ServerConfig extends BaseServerConfig { + private IConfig $config; + private IUrlGenerator $urlGenerator; + private IUserManager $userManager; /** * @param IConfig $config + * @param IUrlGenerator $urlGenerator + * @param IUserManager $userManager */ public function __construct(IConfig $config, IUrlGenerator $urlGenerator, IUserManager $userManager) { $this->config = $config; $this->userManager = $userManager; $this->urlGenerator = $urlGenerator; - } - - /** - * @return string - */ - public function getPrivateKey() { - $result = $this->config->getAppValue('solid','privateKey'); - if (!$result) { - // generate and save a new set if we don't have a private key; - $keys = $this->generateKeySet(); - $this->config->setAppValue('solid','privateKey',$keys['privateKey']); - $this->config->setAppValue('solid','encryptionKey',$keys['encryptionKey']); - } - return $this->config->getAppValue('solid','privateKey'); - } - - /** - * @param string $privateKey - */ - public function setPrivateKey($privateKey) { - $this->config->setAppValue('solid','privateKey',$privateKey); - } - - /** - * @return string - */ - public function getEncryptionKey() { - return $this->config->getAppValue('solid','encryptionKey'); - } - - /** - * @param string $publicKey - */ - public function setEncryptionKey($publicKey) { - $this->config->setAppValue('solid','encryptionKey',$publicKey); + parent::__construct($config); } /** @@ -194,22 +164,4 @@ public function setProfileData($userId, $profileData) { $user->setDisplayName($fields['name']); } } - private function generateKeySet() { - $config = array( - "digest_alg" => "sha256", - "private_key_bits" => 2048, - "private_key_type" => OPENSSL_KEYTYPE_RSA, - ); - // Create the private and public key - $key = openssl_pkey_new($config); - - // Extract the private key from $key to $privateKey - openssl_pkey_export($key, $privateKey); - $encryptionKey = base64_encode(random_bytes(32)); - $result = array( - "privateKey" => $privateKey, - "encryptionKey" => $encryptionKey - ); - return $result; - } } diff --git a/solid/lib/Settings.php b/solid/lib/Settings.php deleted file mode 100644 index 7ab6dfb0..00000000 --- a/solid/lib/Settings.php +++ /dev/null @@ -1,32 +0,0 @@ -config = $config; - } - - public function getForm() { - $response = new TemplateResponse('solid', 'admin'); - $response->setParams([ - 'privateKey' => $this->config->getPrivateKey(), - 'encryptionKey' => $this->config->getEncryptionKey() - ]); - return $response; - } - - public function getSection() { - return 'security'; - } - - public function getPriority() { - return 50; - } -} diff --git a/solid/lib/Settings/SolidAdmin.php b/solid/lib/Settings/SolidAdmin.php new file mode 100644 index 00000000..78701e95 --- /dev/null +++ b/solid/lib/Settings/SolidAdmin.php @@ -0,0 +1,47 @@ +config = $config; + $this->l = $l; + $this->serverConfig = new BaseServerConfig($config); + } + + /** + * @return TemplateResponse + */ + public function getForm() { + $parameters = [ + 'privateKey' => $this->serverConfig->getPrivateKey(), + 'encryptionKey' => $this->serverConfig->getEncryptionKey() + ]; + + return new TemplateResponse('solid', 'admin', $parameters, ''); + } + + public function getSection() { + return 'solid'; // Name of the previously created section. + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 70; + } +}