-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
100 lines (72 loc) · 2.48 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
throw new Exception("Windows is not supported by the programm.");
}
spl_autoload_register(function ($class_name) {
require 'classes/' . $class_name . '.php';
});
$user = Util::getUser($argv);
if (empty($user)) {
throw new Exception("No argument for user found.");
}
define("_USER_", $user);
$config = new Config();
define("DEBUG", $config->getValue("debug"));
define("TEST", $config->getValue("test"));
$baseDir = $config->getValue("data_dir") . _USER_ . "/";
if (!is_dir($baseDir)) {
throw new Exception("There is no directory for the user provided");
}
$privateKeyCatFile = file_get_contents($baseDir . "files_encryption/OC_DEFAULT_MODULE/" . _USER_ . ".privateKey");
$password = Util::promptPassword();
$colors = new Colors();
$logger = new ILogger($colors);
$logCli = new CliLogger($colors);
$crypt = new Crypt(
$logger,
_USER_,
$config->getValue("instance_id"),
$config->getValue("instance_secret")
);
$dbConnDataCur = $config->getDatabaseConfig((DEBUG) ? "test" : "current");
$database = new Database(
$dbConnDataCur["host"],
$dbConnDataCur["username"],
$dbConnDataCur["password"],
$dbConnDataCur["db"],
$dbConnDataCur["port"]
);
$storageID = $database->getStorageId(_USER_);
$privateKey = $crypt->decryptPrivateKey($privateKeyCatFile, $password, _USER_);
if (!$privateKey) {
$logger->error("Wrong password or corrupted private key");
die(1);
}
$encryption = new Encryption(
$logger,
$crypt
);
if ($customFile = Util::getFile($argv, $logCli)) {
$files = array($customFile);
} else {
$files = Util::grepFiles($baseDir, $logCli);
}
foreach ($files as $file) {
$ocPath = str_replace($baseDir, "", $file);
$keyFileDir = $baseDir . "files_encryption/keys/" . $ocPath . "/OC_DEFAULT_MODULE/";
$shareKeyCatFile = file_get_contents($keyFileDir . _USER_ . ".shareKey");
$fileKeyCatFile = file_get_contents($keyFileDir . "fileKey");
$fileKey = $crypt->multiKeyDecrypt($fileKeyCatFile, $shareKeyCatFile, $privateKey);
$newData = $encryption->fixUnencryptedSize($file, filesize($file), $fileKey);
if ($newData === false) {
$logger->error("No solutions found for this file");
} else {
$logger->success("Fixed: '$ocPath' - New size: $newData[0], new encryption: $newData[1]");
if (!DEBUG) {
$database->updateFileByPath($ocPath, $storageID, $newData[0], $newData[1]);
}
}
if (TEST) {
break;
}
}