Skip to content

Commit 854e783

Browse files
committed
bugfixes
1 parent b250bb6 commit 854e783

11 files changed

+244
-107
lines changed

lib/Command/PointList.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ protected function configure() {
130130
* @param OutputInterface $output
131131
*
132132
* @return int
133-
* @throws RemoteInstanceException
134-
* @throws RemoteInstanceNotFoundException
135-
* @throws RemoteResourceNotFoundException
136133
*/
137134
protected function execute(InputInterface $input, OutputInterface $output): int {
138135
$rp = $this->getRPFromInstances(
@@ -146,7 +143,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
146143
$output = $output->section();
147144

148145
$table = new Table($output);
149-
$table->setHeaders(['Restoring Point', 'Date', 'Status', 'Parent', 'Instance', 'Health']);
146+
$table->setHeaders(['Restoring Point', 'Date', 'Parent', 'Status', 'Instance', 'Health']);
150147
$table->render();
151148

152149
foreach ($rp as $pointId => $item) {
@@ -175,8 +172,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
175172
[
176173
($fresh) ? $displayPointId : '',
177174
($fresh) ? date('Y-m-d H:i:s', $point->getDate()) : '',
178-
($fresh) ? implode(',', $status) : '',
179175
($fresh) ? $point->getParent() : '',
176+
implode(',', $status),
180177
$instance,
181178
$this->displayStyleHealth($point),
182179
'<error>' . $issue . '</error>'
@@ -199,7 +196,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
199196
*
200197
* @return array
201198
*/
202-
private function getRPFromInstances(OutputInterface $output, bool $local, string $remote, string $external
199+
private function getRPFromInstances(
200+
OutputInterface $output,
201+
bool $local,
202+
string $remote,
203+
string $external
203204
): array {
204205
if ($local) {
205206
$instances = [RemoteInstance::LOCAL];

lib/Command/PointRestore.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
173173

174174
$point = $this->pointService->getLocalRestoringPoint($input->getArgument('pointId'));
175175

176+
if ($point->isStatus(RestoringPoint::STATUS_PACKED)) {
177+
throw new RestoringPointNotFoundException('the restoring point is packed, please unpack first');
178+
}
176179
$file = $input->getOption('file');
177180
$data = $input->getOption('data');
178181
$chunk = $input->getOption('chunk');

lib/Command/PointUpload.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCA\Backup\Exceptions\RemoteResourceNotFoundException;
4343
use OCA\Backup\Exceptions\RestoringChunkNotFoundException;
4444
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
45+
use OCA\Backup\Exceptions\RestoringPointPackException;
4546
use OCA\Backup\Model\ChunkPartHealth;
4647
use OCA\Backup\Model\RestoringHealth;
4748
use OCA\Backup\Model\RestoringPoint;
@@ -119,6 +120,7 @@ protected function configure() {
119120
* @throws RemoteInstanceNotFoundException
120121
* @throws RestoringPointNotFoundException
121122
* @throws ExternalFolderNotFoundException
123+
* @throws RestoringPointPackException
122124
*/
123125
protected function execute(InputInterface $input, OutputInterface $output) {
124126
$point = $this->pointService->getLocalRestoringPoint($input->getArgument('point'));

lib/Command/SetupImport.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
use Exception;
3838
use OC\Core\Command\Base;
3939
use OCA\Backup\Db\RemoteRequest;
40+
use OCA\Backup\Exceptions\EncryptException;
41+
use OCA\Backup\Exceptions\RemoteInstanceUidException;
4042
use OCA\Backup\Model\RemoteInstance;
4143
use OCA\Backup\Service\ConfigService;
4244
use OCA\Backup\Service\EncryptService;
45+
use SodiumException;
4346
use Symfony\Component\Console\Input\InputInterface;
4447
use Symfony\Component\Console\Input\InputOption;
4548
use Symfony\Component\Console\Output\OutputInterface;
@@ -102,7 +105,9 @@ protected function configure() {
102105
* @param OutputInterface $output
103106
*
104107
* @return int
105-
* @throws Exception
108+
* @throws RemoteInstanceUidException
109+
* @throws EncryptException
110+
* @throws SodiumException
106111
*/
107112
protected function execute(InputInterface $input, OutputInterface $output): int {
108113
$json = '';
@@ -112,8 +117,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
112117

113118
$key = $input->getOption('key');
114119
if ($key !== '') {
115-
$key = base64_decode($key);
116-
$json = $this->encryptService->decryptString($json, $key);
120+
try {
121+
$json = $this->encryptService->decryptString(base64_decode($json), $key);
122+
} catch (EncryptException $e) {
123+
throw new EncryptException('Invalid Key');
124+
}
117125
}
118126

119127
$setup = json_decode($json, true);
@@ -133,6 +141,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
133141
$this->remoteRequest->insertOrUpdate($remote, true);
134142
}
135143

144+
$output->writeln('Setup imported.');
145+
136146
return 0;
137147
}
138148

lib/Model/RestoringChunk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function addFile(ArchiveFile $file): self {
226226

227227

228228
/**
229-
* @return ArchiveFile[]
229+
* @return RestoringChunkPart[]
230230
*/
231231
public function getParts(): array {
232232
return $this->parts;

lib/Model/RestoringChunkPart.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ public function setEncryptedChecksum(string $encryptedChecksum): self {
157157
return $this;
158158
}
159159

160+
161+
162+
163+
160164
/**
161165
* @return string
162166
*/

lib/Model/RestoringPoint.php

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class RestoringPoint implements IDeserializable, INC23QueryRow, ISignedModel, Js
5959
use TNC23Logger;
6060

6161

62+
const STATUS_UNPACKED = 0;
6263
const STATUS_PACKED = 1;
6364
const STATUS_COMPRESSED = 2;
6465
const STATUS_ENCRYPTED = 4;
@@ -240,50 +241,22 @@ public function setNotes(SimpleDataStore $notes): self {
240241
return $this;
241242
}
242243

244+
/**
245+
* @return $this
246+
*/
247+
public function unsetNotes(): self {
248+
$this->notes = new SimpleDataStore();
249+
250+
return $this;
251+
}
252+
243253
/**
244254
* @return SimpleDataStore
245255
*/
246256
public function getNotes(): SimpleDataStore {
247257
return $this->notes;
248258
}
249259

250-
//
251-
// /**
252-
// * @param string $key
253-
// * @param string $note
254-
// *
255-
// * @return $this
256-
// */
257-
// public function setNote(string $key, string $note = ''): self {
258-
// if ($note === '') {
259-
// if (array_key_exists($key, $this->notes)) {
260-
// unset($this->notes[$key]);
261-
// }
262-
// } else {
263-
// $this->notes[$key] = $note;
264-
// }
265-
//
266-
// return $this;
267-
// }
268-
//
269-
// /**
270-
// * @param string $key
271-
// *
272-
// * @return string
273-
// */
274-
// public function getNote(string $key): string {
275-
// return $this->get($key, $this->notes);
276-
// }
277-
//
278-
// /**
279-
// * @param string $key
280-
// *
281-
// * @return int
282-
// */
283-
// public function getNoteInt(string $key): int {
284-
// return $this->getInt($key, $this->notes);
285-
// }
286-
287260

288261
/**
289262
* @param int $date

lib/Service/EncryptService.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public function encryptString(string $data, string $key): string {
9393
* @throws SodiumException
9494
*/
9595
public function decryptString(string $encrypted, string $key): string {
96-
$encrypted = base64_decode($encrypted);
96+
$key = base64_decode($key);
97+
9798
if ($encrypted === false) {
9899
throw new EncryptException('invalid data');
99100
}
@@ -115,6 +116,7 @@ public function decryptString(string $encrypted, string $key): string {
115116
if ($plain === false) {
116117
throw new EncryptException('invalid data');
117118
}
119+
118120
sodium_memzero($ciphertext);
119121
sodium_memzero($key);
120122

@@ -130,7 +132,7 @@ public function decryptString(string $encrypted, string $key): string {
130132
* @throws EncryptionKeyException
131133
*/
132134
public function encryptFile(string $input, string $output): void {
133-
$key = $this->getEncryptionKey();
135+
$key = base64_decode($this->getEncryptionKey());
134136
$read = fopen($input, 'rb');
135137
$write = fopen($output, 'wb');
136138
[$state, $header] = sodium_crypto_secretstream_xchacha20poly1305_init_push($key);
@@ -157,7 +159,7 @@ public function encryptFile(string $input, string $output): void {
157159
* @throws EncryptionKeyException
158160
*/
159161
public function decryptFile(string $input, string $output): void {
160-
$key = $this->getEncryptionKey();
162+
$key = base64_decode($this->getEncryptionKey());
161163
$read = fopen($input, 'rb');
162164
$write = fopen($output, 'wb');
163165

@@ -191,7 +193,7 @@ public function getEncryptionKey(): string {
191193
$this->configService->setAppValue(ConfigService::ENCRYPTION_KEY, $key);
192194
}
193195

194-
return base64_decode($key);
196+
return $key;
195197
}
196198

197199

lib/Service/OutputService.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,15 @@ public function displayHealth(RestoringPoint $point): string {
133133
}
134134
}
135135

136-
return '<comment>'
136+
$color = 'comment';
137+
if ($unknown + $missing + $faulty === 0) {
138+
$color = 'info';
139+
}
140+
141+
return '<' . $color . '>'
137142
. $good . ' correct, '
138143
. $missing . ' missing and '
139-
. $faulty . ' faulty files</comment>';
144+
. $faulty . ' faulty files</' . $color . '>';
140145
}
141146

142147
}

0 commit comments

Comments
 (0)