Skip to content

Commit

Permalink
Merge 3d89e23 into 268e17e
Browse files Browse the repository at this point in the history
  • Loading branch information
backportbot-libresign[bot] committed Apr 11, 2023
2 parents 268e17e + 3d89e23 commit af4e798
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 198 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"iio/libmergepdf": "dev-move-tcpdi-parser-to-package",
"jsignpdf/jsignpdf-php": "^1.2",
"pagerfanta/pagerfanta": "^3.6",
"smalot/pdfparser": "^2.4",
"symfony/console": "^5.4",
"tecnickcom/tcpdf": "^6.4"
},
Expand Down
51 changes: 51 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions lib/Command/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ protected function uninstallJSignPdf(): void {
$this->installService->uninstallJSignPdf();
}

protected function installCli(): void {
$this->installService->installCli();
}

protected function uninstallCli(): void {
$this->installService->uninstallCli();
}

protected function installCfssl(): void {
$this->installService->installCfssl();
}
Expand Down
9 changes: 0 additions & 9 deletions lib/Command/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ protected function configure(): void {
InputOption::VALUE_NONE,
'CFSSL'
)
->addOption('cli',
null,
InputOption::VALUE_NONE,
'LibreSign CLI'
)
->addOption('java',
null,
InputOption::VALUE_NONE,
Expand All @@ -70,10 +65,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->installService->installCfssl();
$ok = true;
}
if ($input->getOption('cli') || $all) {
$this->installService->installCli();
$ok = true;
}
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
throw $e;
Expand Down
9 changes: 0 additions & 9 deletions lib/Command/Uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ protected function configure(): void {
InputOption::VALUE_NONE,
'CFSSL'
)
->addOption('cli',
null,
InputOption::VALUE_NONE,
'LibreSign CLI'
)
->addOption('java',
null,
InputOption::VALUE_NONE,
Expand All @@ -69,10 +64,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->installService->uninstallCfssl();
$ok = true;
}
if ($input->getOption('cli') || $all) {
$this->installService->uninstallCli($output);
$ok = true;
}
} catch (\Exception $e) {
$this->logger->error($e->getMessage());
throw $e;
Expand Down
1 change: 0 additions & 1 deletion lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public function downloadBinaries(): Response {
$this->installService->installJava($async);
$this->installService->installJSignPdf($async);
$this->installService->installCfssl($async);
$this->installService->installCli($async);
$previous = [];
do {
$totalSize = $this->installService->getTotalSize();
Expand Down
63 changes: 63 additions & 0 deletions lib/Migration/Version8000Date20230410230327.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Vitor Mattos <vitor@php.rio>
*
* @author Vitor Mattos <vitor@php.rio>
*
* @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\Libresign\Migration;

use Closure;
use OC\Files\AppData\Factory;
use OCA\Libresign\AppInfo\Application;
use OCP\DB\ISchemaWrapper;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version8000Date20230410230327 extends SimpleMigrationStep {
protected IAppData $appData;

public function __construct(
protected IConfig $config,
protected Factory $appDataFactory
) {
$this->appData = $appDataFactory->get('libresign');
}

public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {
$libresignCliPath = $this->config->getAppValue(Application::APP_ID, 'libresign_cli_path');
if (!$libresignCliPath) {
return;
}
$appFolder = $this->appData->getFolder('/');
try {
$folder = $appFolder->getFolder('libresign-cli');
$folder->delete();
} catch (NotFoundException $e) {
}
$this->config->deleteAppValue(Application::APP_ID, 'libresign_cli_path');
return;
}
}
23 changes: 0 additions & 23 deletions lib/Service/ConfigureCheckService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function checkSign(): array {
$return = [];
$return = array_merge($return, $this->checkJava());
$return = array_merge($return, $this->checkJSignPdf());
$return = array_merge($return, $this->checkLibresignCli());
return $return;
}

Expand Down Expand Up @@ -227,28 +226,6 @@ function (ConfigureCheckHelper $config) {
return empty($error);
}

/**
* Check all requirements to use LibreSign CLI tool
*
* @return ConfigureCheckHelper[]
*/
private function checkLibresignCli(): array {
$path = $this->config->getAppValue(Application::APP_ID, 'libresign_cli_path');
if (!file_exists($path) || !is_executable($path)) {
return [
(new ConfigureCheckHelper())
->setErrorMessage('LibreSign cli tools not found or without execute permission.')
->setResource('libresign-cli')
->setTip('Run occ libresign:install --cli'),
];
}
return [
(new ConfigureCheckHelper())
->setSuccessMessage('LibreSign cli tools found in path: ' . $path)
->setResource('libresign-cli'),
];
}

/**
* Check all requirements to use CFSSL
*
Expand Down
59 changes: 1 addition & 58 deletions lib/Service/InstallService.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public function getTotalSize(): array {
$resources = [
'java',
'jsignpdf',
'cli',
'cfssl'
];
$return = [];
Expand Down Expand Up @@ -363,62 +362,6 @@ public function uninstallJSignPdf(): void {
$this->config->deleteAppValue(Application::APP_ID, 'jsignpdf_jar_path');
}

public function installCli(?bool $async = false): void {
if (PHP_OS_FAMILY === 'Windows') {
throw new \RuntimeException('LibreSign CLI do not work in Windows!');
}
$this->setResource('cli');
if ($async) {
$this->runAsync();
return;
}
$folder = $this->getFolder();
$version = '0.0.4';
$file = null;
if (PHP_OS_FAMILY === 'Darwin') {
$file = 'libresign_' . $version . '_Linux_arm64';
} elseif (PHP_OS_FAMILY === 'Linux') {
if (PHP_INT_SIZE === 4) {
$file = 'libresign_' . $version . '_Linux_i386';
} else {
$file = 'libresign_' . $version . '_Linux_x86_64';
}
}

$checksumUrl = 'https://github.com/LibreSign/libresign-cli/releases/download/v' . $version . '/checksums.txt';
$hash = $this->getHash($folder, 'libresign-cli', $file, $version, $checksumUrl);

$url = 'https://github.com/LibreSign/libresign-cli/releases/download/v' . $version . '/' . $file;
$file = $folder->newFile('libresign-cli');
$fullPath = $this->getDataDir() . DIRECTORY_SEPARATOR . $file->getInternalPath();

$this->download($url, 'libresign-cli', $fullPath, $hash, 'sha256');

if (PHP_OS_FAMILY !== 'Windows') {
chmod($fullPath, 0700);
}

$this->config->setAppValue(Application::APP_ID, 'libresign_cli_path', $fullPath);
$this->removeDownloadProgress();
}

public function uninstallCli(): void {
$libresignCliPath = $this->config->getAppValue(Application::APP_ID, 'libresign_cli_path');
if (!$libresignCliPath) {
return;
}
$appFolder = $this->getAppRootFolder();
$name = $appFolder->getName();
// Remove prefix
$path = explode($name, $libresignCliPath)[1];
try {
$folder = $appFolder->get($path);
$folder->delete();
} catch (NotFoundException $e) {
}
$this->config->deleteAppValue(Application::APP_ID, 'libresign_cli_path');
}

public function installCfssl(?bool $async = false): void {
$this->setResource('cfssl');
if ($async) {
Expand Down Expand Up @@ -453,7 +396,7 @@ private function installCfssl64(): void {
$baseUrl = 'https://github.com/cloudflare/cfssl/releases/download/v' . self::CFSSL_VERSION . '/';
$checksumUrl = 'https://github.com/cloudflare/cfssl/releases/download/v' . self::CFSSL_VERSION . '/cfssl_' . self::CFSSL_VERSION . '_checksums.txt';
foreach ($downloads as $download) {
$hash = $this->getHash($folder, 'libresign-cli', $download['file'], self::CFSSL_VERSION, $checksumUrl);
$hash = $this->getHash($folder, 'cfssl', $download['file'], self::CFSSL_VERSION, $checksumUrl);

$file = $folder->newFile($download['destination']);
$fullPath = $this->getDataDir() . DIRECTORY_SEPARATOR . $file->getInternalPath();
Expand Down
Loading

0 comments on commit af4e798

Please sign in to comment.