@@ -32,30 +32,30 @@ |
||
32 | 32 | use OCP\Migration\SimpleMigrationStep; |
33 | 33 | |
34 | 34 | class Version20000Date20201111081915 extends SimpleMigrationStep { |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - |
|
45 | - $result = $this->ensureColumnIsNullable($schema, 'direct_edit', 'accessed'); |
|
46 | - |
|
47 | - return $result ? $schema : null; |
|
48 | - } |
|
49 | - |
|
50 | - protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
51 | - $table = $schema->getTable($tableName); |
|
52 | - $column = $table->getColumn($columnName); |
|
53 | - |
|
54 | - if ($column->getNotnull()) { |
|
55 | - $column->setNotnull(false); |
|
56 | - return true; |
|
57 | - } |
|
58 | - |
|
59 | - return false; |
|
60 | - } |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + |
|
45 | + $result = $this->ensureColumnIsNullable($schema, 'direct_edit', 'accessed'); |
|
46 | + |
|
47 | + return $result ? $schema : null; |
|
48 | + } |
|
49 | + |
|
50 | + protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
51 | + $table = $schema->getTable($tableName); |
|
52 | + $column = $table->getColumn($columnName); |
|
53 | + |
|
54 | + if ($column->getNotnull()) { |
|
55 | + $column->setNotnull(false); |
|
56 | + return true; |
|
57 | + } |
|
58 | + |
|
59 | + return false; |
|
60 | + } |
|
61 | 61 | } |
@@ -37,61 +37,61 @@ |
||
37 | 37 | */ |
38 | 38 | class Version0001Date20200602134824 extends SimpleMigrationStep { |
39 | 39 | |
40 | - /** |
|
41 | - * @param IOutput $output |
|
42 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
43 | - * @param array $options |
|
44 | - * @return null|ISchemaWrapper |
|
45 | - * @since 20.0.0 |
|
46 | - */ |
|
47 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
48 | - /** @var ISchemaWrapper $schema */ |
|
49 | - $schema = $schemaClosure(); |
|
40 | + /** |
|
41 | + * @param IOutput $output |
|
42 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
43 | + * @param array $options |
|
44 | + * @return null|ISchemaWrapper |
|
45 | + * @since 20.0.0 |
|
46 | + */ |
|
47 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
48 | + /** @var ISchemaWrapper $schema */ |
|
49 | + $schema = $schemaClosure(); |
|
50 | 50 | |
51 | - $statusTable = $schema->createTable('user_status'); |
|
52 | - $statusTable->addColumn('id', Types::BIGINT, [ |
|
53 | - 'autoincrement' => true, |
|
54 | - 'notnull' => true, |
|
55 | - 'length' => 20, |
|
56 | - 'unsigned' => true, |
|
57 | - ]); |
|
58 | - $statusTable->addColumn('user_id', Types::STRING, [ |
|
59 | - 'notnull' => true, |
|
60 | - 'length' => 255, |
|
61 | - ]); |
|
62 | - $statusTable->addColumn('status', Types::STRING, [ |
|
63 | - 'notnull' => true, |
|
64 | - 'length' => 255, |
|
65 | - ]); |
|
66 | - $statusTable->addColumn('status_timestamp', Types::INTEGER, [ |
|
67 | - 'notnull' => true, |
|
68 | - 'length' => 11, |
|
69 | - 'unsigned' => true, |
|
70 | - ]); |
|
71 | - $statusTable->addColumn('is_user_defined', Types::BOOLEAN, [ |
|
72 | - 'notnull' => false, |
|
73 | - ]); |
|
74 | - $statusTable->addColumn('message_id', Types::STRING, [ |
|
75 | - 'notnull' => false, |
|
76 | - 'length' => 255, |
|
77 | - ]); |
|
78 | - $statusTable->addColumn('custom_icon', Types::STRING, [ |
|
79 | - 'notnull' => false, |
|
80 | - 'length' => 255, |
|
81 | - ]); |
|
82 | - $statusTable->addColumn('custom_message', Types::TEXT, [ |
|
83 | - 'notnull' => false, |
|
84 | - ]); |
|
85 | - $statusTable->addColumn('clear_at', Types::INTEGER, [ |
|
86 | - 'notnull' => false, |
|
87 | - 'length' => 11, |
|
88 | - 'unsigned' => true, |
|
89 | - ]); |
|
51 | + $statusTable = $schema->createTable('user_status'); |
|
52 | + $statusTable->addColumn('id', Types::BIGINT, [ |
|
53 | + 'autoincrement' => true, |
|
54 | + 'notnull' => true, |
|
55 | + 'length' => 20, |
|
56 | + 'unsigned' => true, |
|
57 | + ]); |
|
58 | + $statusTable->addColumn('user_id', Types::STRING, [ |
|
59 | + 'notnull' => true, |
|
60 | + 'length' => 255, |
|
61 | + ]); |
|
62 | + $statusTable->addColumn('status', Types::STRING, [ |
|
63 | + 'notnull' => true, |
|
64 | + 'length' => 255, |
|
65 | + ]); |
|
66 | + $statusTable->addColumn('status_timestamp', Types::INTEGER, [ |
|
67 | + 'notnull' => true, |
|
68 | + 'length' => 11, |
|
69 | + 'unsigned' => true, |
|
70 | + ]); |
|
71 | + $statusTable->addColumn('is_user_defined', Types::BOOLEAN, [ |
|
72 | + 'notnull' => false, |
|
73 | + ]); |
|
74 | + $statusTable->addColumn('message_id', Types::STRING, [ |
|
75 | + 'notnull' => false, |
|
76 | + 'length' => 255, |
|
77 | + ]); |
|
78 | + $statusTable->addColumn('custom_icon', Types::STRING, [ |
|
79 | + 'notnull' => false, |
|
80 | + 'length' => 255, |
|
81 | + ]); |
|
82 | + $statusTable->addColumn('custom_message', Types::TEXT, [ |
|
83 | + 'notnull' => false, |
|
84 | + ]); |
|
85 | + $statusTable->addColumn('clear_at', Types::INTEGER, [ |
|
86 | + 'notnull' => false, |
|
87 | + 'length' => 11, |
|
88 | + 'unsigned' => true, |
|
89 | + ]); |
|
90 | 90 | |
91 | - $statusTable->setPrimaryKey(['id']); |
|
92 | - $statusTable->addUniqueIndex(['user_id'], 'user_status_uid_ix'); |
|
93 | - $statusTable->addIndex(['clear_at'], 'user_status_clr_ix'); |
|
91 | + $statusTable->setPrimaryKey(['id']); |
|
92 | + $statusTable->addUniqueIndex(['user_id'], 'user_status_uid_ix'); |
|
93 | + $statusTable->addIndex(['clear_at'], 'user_status_clr_ix'); |
|
94 | 94 | |
95 | - return $schema; |
|
96 | - } |
|
95 | + return $schema; |
|
96 | + } |
|
97 | 97 | } |
@@ -33,30 +33,30 @@ |
||
33 | 33 | |
34 | 34 | class Version1000Date20201111130204 extends SimpleMigrationStep { |
35 | 35 | |
36 | - /** |
|
37 | - * @param IOutput $output |
|
38 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
39 | - * @param array $options |
|
40 | - * @return null|ISchemaWrapper |
|
41 | - */ |
|
42 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
43 | - /** @var ISchemaWrapper $schema */ |
|
44 | - $schema = $schemaClosure(); |
|
45 | - |
|
46 | - $result = $this->ensureColumnIsNullable($schema, 'user_status', 'is_user_defined'); |
|
47 | - |
|
48 | - return $result ? $schema : null; |
|
49 | - } |
|
50 | - |
|
51 | - protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
52 | - $table = $schema->getTable($tableName); |
|
53 | - $column = $table->getColumn($columnName); |
|
54 | - |
|
55 | - if ($column->getNotnull()) { |
|
56 | - $column->setNotnull(false); |
|
57 | - return true; |
|
58 | - } |
|
59 | - |
|
60 | - return false; |
|
61 | - } |
|
36 | + /** |
|
37 | + * @param IOutput $output |
|
38 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
39 | + * @param array $options |
|
40 | + * @return null|ISchemaWrapper |
|
41 | + */ |
|
42 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
43 | + /** @var ISchemaWrapper $schema */ |
|
44 | + $schema = $schemaClosure(); |
|
45 | + |
|
46 | + $result = $this->ensureColumnIsNullable($schema, 'user_status', 'is_user_defined'); |
|
47 | + |
|
48 | + return $result ? $schema : null; |
|
49 | + } |
|
50 | + |
|
51 | + protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool { |
|
52 | + $table = $schema->getTable($tableName); |
|
53 | + $column = $table->getColumn($columnName); |
|
54 | + |
|
55 | + if ($column->getNotnull()) { |
|
56 | + $column->setNotnull(false); |
|
57 | + return true; |
|
58 | + } |
|
59 | + |
|
60 | + return false; |
|
61 | + } |
|
62 | 62 | } |
@@ -38,58 +38,58 @@ |
||
38 | 38 | */ |
39 | 39 | class Capabilities implements IPublicCapability { |
40 | 40 | |
41 | - /** @var ThemingDefaults */ |
|
42 | - protected $theming; |
|
41 | + /** @var ThemingDefaults */ |
|
42 | + protected $theming; |
|
43 | 43 | |
44 | - /** @var Util */ |
|
45 | - protected $util; |
|
44 | + /** @var Util */ |
|
45 | + protected $util; |
|
46 | 46 | |
47 | - /** @var IURLGenerator */ |
|
48 | - protected $url; |
|
47 | + /** @var IURLGenerator */ |
|
48 | + protected $url; |
|
49 | 49 | |
50 | - /** @var IConfig */ |
|
51 | - protected $config; |
|
50 | + /** @var IConfig */ |
|
51 | + protected $config; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param ThemingDefaults $theming |
|
55 | - * @param Util $util |
|
56 | - * @param IURLGenerator $url |
|
57 | - * @param IConfig $config |
|
58 | - */ |
|
59 | - public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator $url, IConfig $config) { |
|
60 | - $this->theming = $theming; |
|
61 | - $this->util = $util; |
|
62 | - $this->url = $url; |
|
63 | - $this->config = $config; |
|
64 | - } |
|
53 | + /** |
|
54 | + * @param ThemingDefaults $theming |
|
55 | + * @param Util $util |
|
56 | + * @param IURLGenerator $url |
|
57 | + * @param IConfig $config |
|
58 | + */ |
|
59 | + public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator $url, IConfig $config) { |
|
60 | + $this->theming = $theming; |
|
61 | + $this->util = $util; |
|
62 | + $this->url = $url; |
|
63 | + $this->config = $config; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Return this classes capabilities |
|
68 | - * |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function getCapabilities() { |
|
72 | - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', ''); |
|
73 | - $color = $this->theming->getColorPrimary(); |
|
74 | - return [ |
|
75 | - 'theming' => [ |
|
76 | - 'name' => $this->theming->getName(), |
|
77 | - 'url' => $this->theming->getBaseUrl(), |
|
78 | - 'slogan' => $this->theming->getSlogan(), |
|
79 | - 'color' => $color, |
|
80 | - 'color-text' => $this->theming->getTextColorPrimary(), |
|
81 | - 'color-element' => $this->util->elementColor($color), |
|
82 | - 'color-element-bright' => $this->util->elementColor($color), |
|
83 | - 'color-element-dark' => $this->util->elementColor($color, false), |
|
84 | - 'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()), |
|
85 | - 'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ? |
|
86 | - $this->theming->getColorPrimary() : |
|
87 | - $this->url->getAbsoluteURL($this->theming->getBackground()), |
|
88 | - 'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9'), |
|
89 | - 'background-default' => !$this->util->isBackgroundThemed(), |
|
90 | - 'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()), |
|
91 | - 'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()), |
|
92 | - ], |
|
93 | - ]; |
|
94 | - } |
|
66 | + /** |
|
67 | + * Return this classes capabilities |
|
68 | + * |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function getCapabilities() { |
|
72 | + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', ''); |
|
73 | + $color = $this->theming->getColorPrimary(); |
|
74 | + return [ |
|
75 | + 'theming' => [ |
|
76 | + 'name' => $this->theming->getName(), |
|
77 | + 'url' => $this->theming->getBaseUrl(), |
|
78 | + 'slogan' => $this->theming->getSlogan(), |
|
79 | + 'color' => $color, |
|
80 | + 'color-text' => $this->theming->getTextColorPrimary(), |
|
81 | + 'color-element' => $this->util->elementColor($color), |
|
82 | + 'color-element-bright' => $this->util->elementColor($color), |
|
83 | + 'color-element-dark' => $this->util->elementColor($color, false), |
|
84 | + 'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()), |
|
85 | + 'background' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9') ? |
|
86 | + $this->theming->getColorPrimary() : |
|
87 | + $this->url->getAbsoluteURL($this->theming->getBackground()), |
|
88 | + 'background-plain' => $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $this->theming->getColorPrimary() !== '#0082c9'), |
|
89 | + 'background-default' => !$this->util->isBackgroundThemed(), |
|
90 | + 'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()), |
|
91 | + 'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()), |
|
92 | + ], |
|
93 | + ]; |
|
94 | + } |
|
95 | 95 | } |
@@ -37,105 +37,105 @@ |
||
37 | 37 | |
38 | 38 | class ScanLegacyFormat extends Command { |
39 | 39 | |
40 | - /** @var Util */ |
|
41 | - protected $util; |
|
42 | - |
|
43 | - /** @var IConfig */ |
|
44 | - protected $config; |
|
45 | - |
|
46 | - /** @var QuestionHelper */ |
|
47 | - protected $questionHelper; |
|
48 | - |
|
49 | - /** @var IUserManager */ |
|
50 | - private $userManager; |
|
51 | - |
|
52 | - /** @var View */ |
|
53 | - private $rootView; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param Util $util |
|
57 | - * @param IConfig $config |
|
58 | - * @param QuestionHelper $questionHelper |
|
59 | - */ |
|
60 | - public function __construct(Util $util, |
|
61 | - IConfig $config, |
|
62 | - QuestionHelper $questionHelper, |
|
63 | - IUserManager $userManager) { |
|
64 | - parent::__construct(); |
|
65 | - |
|
66 | - $this->util = $util; |
|
67 | - $this->config = $config; |
|
68 | - $this->questionHelper = $questionHelper; |
|
69 | - $this->userManager = $userManager; |
|
70 | - $this->rootView = new View(); |
|
71 | - } |
|
72 | - |
|
73 | - protected function configure() { |
|
74 | - $this |
|
75 | - ->setName('encryption:scan:legacy-format') |
|
76 | - ->setDescription('Scan the files for the legacy format'); |
|
77 | - } |
|
78 | - |
|
79 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
80 | - $result = true; |
|
81 | - |
|
82 | - $output->writeln('Scanning all files for legacy encryption'); |
|
83 | - |
|
84 | - foreach ($this->userManager->getBackends() as $backend) { |
|
85 | - $limit = 500; |
|
86 | - $offset = 0; |
|
87 | - do { |
|
88 | - $users = $backend->getUsers('', $limit, $offset); |
|
89 | - foreach ($users as $user) { |
|
90 | - $output->writeln('Scanning all files for ' . $user); |
|
91 | - $this->setupUserFS($user); |
|
92 | - $result &= $this->scanFolder($output, '/' . $user); |
|
93 | - } |
|
94 | - $offset += $limit; |
|
95 | - } while (count($users) >= $limit); |
|
96 | - } |
|
97 | - |
|
98 | - if ($result) { |
|
99 | - $output->writeln('All scanned files are properly encrypted. You can disable the legacy compatibility mode.'); |
|
100 | - return 0; |
|
101 | - } |
|
102 | - |
|
103 | - return 1; |
|
104 | - } |
|
105 | - |
|
106 | - private function scanFolder(OutputInterface $output, string $folder): bool { |
|
107 | - $clean = true; |
|
108 | - |
|
109 | - foreach ($this->rootView->getDirectoryContent($folder) as $item) { |
|
110 | - $path = $folder . '/' . $item['name']; |
|
111 | - if ($this->rootView->is_dir($path)) { |
|
112 | - if ($this->scanFolder($output, $path) === false) { |
|
113 | - $clean = false; |
|
114 | - } |
|
115 | - } else { |
|
116 | - if (!$item->isEncrypted()) { |
|
117 | - // ignore |
|
118 | - continue; |
|
119 | - } |
|
120 | - |
|
121 | - $stats = $this->rootView->stat($path); |
|
122 | - if (!isset($stats['hasHeader']) || $stats['hasHeader'] === false) { |
|
123 | - $clean = false; |
|
124 | - $output->writeln($path . ' does not have a proper header'); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - return $clean; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * setup user file system |
|
134 | - * |
|
135 | - * @param string $uid |
|
136 | - */ |
|
137 | - protected function setupUserFS($uid) { |
|
138 | - \OC_Util::tearDownFS(); |
|
139 | - \OC_Util::setupFS($uid); |
|
140 | - } |
|
40 | + /** @var Util */ |
|
41 | + protected $util; |
|
42 | + |
|
43 | + /** @var IConfig */ |
|
44 | + protected $config; |
|
45 | + |
|
46 | + /** @var QuestionHelper */ |
|
47 | + protected $questionHelper; |
|
48 | + |
|
49 | + /** @var IUserManager */ |
|
50 | + private $userManager; |
|
51 | + |
|
52 | + /** @var View */ |
|
53 | + private $rootView; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param Util $util |
|
57 | + * @param IConfig $config |
|
58 | + * @param QuestionHelper $questionHelper |
|
59 | + */ |
|
60 | + public function __construct(Util $util, |
|
61 | + IConfig $config, |
|
62 | + QuestionHelper $questionHelper, |
|
63 | + IUserManager $userManager) { |
|
64 | + parent::__construct(); |
|
65 | + |
|
66 | + $this->util = $util; |
|
67 | + $this->config = $config; |
|
68 | + $this->questionHelper = $questionHelper; |
|
69 | + $this->userManager = $userManager; |
|
70 | + $this->rootView = new View(); |
|
71 | + } |
|
72 | + |
|
73 | + protected function configure() { |
|
74 | + $this |
|
75 | + ->setName('encryption:scan:legacy-format') |
|
76 | + ->setDescription('Scan the files for the legacy format'); |
|
77 | + } |
|
78 | + |
|
79 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
80 | + $result = true; |
|
81 | + |
|
82 | + $output->writeln('Scanning all files for legacy encryption'); |
|
83 | + |
|
84 | + foreach ($this->userManager->getBackends() as $backend) { |
|
85 | + $limit = 500; |
|
86 | + $offset = 0; |
|
87 | + do { |
|
88 | + $users = $backend->getUsers('', $limit, $offset); |
|
89 | + foreach ($users as $user) { |
|
90 | + $output->writeln('Scanning all files for ' . $user); |
|
91 | + $this->setupUserFS($user); |
|
92 | + $result &= $this->scanFolder($output, '/' . $user); |
|
93 | + } |
|
94 | + $offset += $limit; |
|
95 | + } while (count($users) >= $limit); |
|
96 | + } |
|
97 | + |
|
98 | + if ($result) { |
|
99 | + $output->writeln('All scanned files are properly encrypted. You can disable the legacy compatibility mode.'); |
|
100 | + return 0; |
|
101 | + } |
|
102 | + |
|
103 | + return 1; |
|
104 | + } |
|
105 | + |
|
106 | + private function scanFolder(OutputInterface $output, string $folder): bool { |
|
107 | + $clean = true; |
|
108 | + |
|
109 | + foreach ($this->rootView->getDirectoryContent($folder) as $item) { |
|
110 | + $path = $folder . '/' . $item['name']; |
|
111 | + if ($this->rootView->is_dir($path)) { |
|
112 | + if ($this->scanFolder($output, $path) === false) { |
|
113 | + $clean = false; |
|
114 | + } |
|
115 | + } else { |
|
116 | + if (!$item->isEncrypted()) { |
|
117 | + // ignore |
|
118 | + continue; |
|
119 | + } |
|
120 | + |
|
121 | + $stats = $this->rootView->stat($path); |
|
122 | + if (!isset($stats['hasHeader']) || $stats['hasHeader'] === false) { |
|
123 | + $clean = false; |
|
124 | + $output->writeln($path . ' does not have a proper header'); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + return $clean; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * setup user file system |
|
134 | + * |
|
135 | + * @param string $uid |
|
136 | + */ |
|
137 | + protected function setupUserFS($uid) { |
|
138 | + \OC_Util::tearDownFS(); |
|
139 | + \OC_Util::setupFS($uid); |
|
140 | + } |
|
141 | 141 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | /** @var Application $app */ |
34 | 34 | $app = \OC::$server->query(Application::class); |
35 | 35 | if ($encryptionSystemReady) { |
36 | - $app->registerEncryptionModule($encryptionManager); |
|
37 | - $app->registerHooks(\OC::$server->getConfig()); |
|
38 | - $app->setUp($encryptionManager); |
|
36 | + $app->registerEncryptionModule($encryptionManager); |
|
37 | + $app->registerHooks(\OC::$server->getConfig()); |
|
38 | + $app->setUp($encryptionManager); |
|
39 | 39 | } |
@@ -44,67 +44,67 @@ |
||
44 | 44 | use OCP\IConfig; |
45 | 45 | |
46 | 46 | class Application extends \OCP\AppFramework\App { |
47 | - /** |
|
48 | - * @param array $urlParams |
|
49 | - */ |
|
50 | - public function __construct($urlParams = []) { |
|
51 | - parent::__construct('encryption', $urlParams); |
|
52 | - } |
|
47 | + /** |
|
48 | + * @param array $urlParams |
|
49 | + */ |
|
50 | + public function __construct($urlParams = []) { |
|
51 | + parent::__construct('encryption', $urlParams); |
|
52 | + } |
|
53 | 53 | |
54 | - public function setUp(IManager $encryptionManager) { |
|
55 | - if ($encryptionManager->isEnabled()) { |
|
56 | - /** @var Setup $setup */ |
|
57 | - $setup = $this->getContainer()->query(Setup::class); |
|
58 | - $setup->setupSystem(); |
|
59 | - } |
|
60 | - } |
|
54 | + public function setUp(IManager $encryptionManager) { |
|
55 | + if ($encryptionManager->isEnabled()) { |
|
56 | + /** @var Setup $setup */ |
|
57 | + $setup = $this->getContainer()->query(Setup::class); |
|
58 | + $setup->setupSystem(); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * register hooks |
|
64 | - */ |
|
65 | - public function registerHooks(IConfig $config) { |
|
66 | - if (!$config->getSystemValueBool('maintenance')) { |
|
67 | - $container = $this->getContainer(); |
|
68 | - $server = $container->getServer(); |
|
69 | - // Register our hooks and fire them. |
|
70 | - $hookManager = new HookManager(); |
|
62 | + /** |
|
63 | + * register hooks |
|
64 | + */ |
|
65 | + public function registerHooks(IConfig $config) { |
|
66 | + if (!$config->getSystemValueBool('maintenance')) { |
|
67 | + $container = $this->getContainer(); |
|
68 | + $server = $container->getServer(); |
|
69 | + // Register our hooks and fire them. |
|
70 | + $hookManager = new HookManager(); |
|
71 | 71 | |
72 | - $hookManager->registerHook([ |
|
73 | - new UserHooks($container->query(KeyManager::class), |
|
74 | - $server->getUserManager(), |
|
75 | - $server->getLogger(), |
|
76 | - $container->query(Setup::class), |
|
77 | - $server->getUserSession(), |
|
78 | - $container->query(Util::class), |
|
79 | - $container->query(Session::class), |
|
80 | - $container->query(Crypt::class), |
|
81 | - $container->query(Recovery::class)) |
|
82 | - ]); |
|
72 | + $hookManager->registerHook([ |
|
73 | + new UserHooks($container->query(KeyManager::class), |
|
74 | + $server->getUserManager(), |
|
75 | + $server->getLogger(), |
|
76 | + $container->query(Setup::class), |
|
77 | + $server->getUserSession(), |
|
78 | + $container->query(Util::class), |
|
79 | + $container->query(Session::class), |
|
80 | + $container->query(Crypt::class), |
|
81 | + $container->query(Recovery::class)) |
|
82 | + ]); |
|
83 | 83 | |
84 | - $hookManager->fireHooks(); |
|
85 | - } else { |
|
86 | - // Logout user if we are in maintenance to force re-login |
|
87 | - $this->getContainer()->getServer()->getUserSession()->logout(); |
|
88 | - } |
|
89 | - } |
|
84 | + $hookManager->fireHooks(); |
|
85 | + } else { |
|
86 | + // Logout user if we are in maintenance to force re-login |
|
87 | + $this->getContainer()->getServer()->getUserSession()->logout(); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - public function registerEncryptionModule(IManager $encryptionManager) { |
|
92 | - $container = $this->getContainer(); |
|
91 | + public function registerEncryptionModule(IManager $encryptionManager) { |
|
92 | + $container = $this->getContainer(); |
|
93 | 93 | |
94 | - $encryptionManager->registerEncryptionModule( |
|
95 | - Encryption::ID, |
|
96 | - Encryption::DISPLAY_NAME, |
|
97 | - function () use ($container) { |
|
98 | - return new Encryption( |
|
99 | - $container->query(Crypt::class), |
|
100 | - $container->query(KeyManager::class), |
|
101 | - $container->query(Util::class), |
|
102 | - $container->query(Session::class), |
|
103 | - $container->query(EncryptAll::class), |
|
104 | - $container->query(DecryptAll::class), |
|
105 | - $container->getServer()->getLogger(), |
|
106 | - $container->getServer()->getL10N($container->getAppName()) |
|
107 | - ); |
|
108 | - }); |
|
109 | - } |
|
94 | + $encryptionManager->registerEncryptionModule( |
|
95 | + Encryption::ID, |
|
96 | + Encryption::DISPLAY_NAME, |
|
97 | + function () use ($container) { |
|
98 | + return new Encryption( |
|
99 | + $container->query(Crypt::class), |
|
100 | + $container->query(KeyManager::class), |
|
101 | + $container->query(Util::class), |
|
102 | + $container->query(Session::class), |
|
103 | + $container->query(EncryptAll::class), |
|
104 | + $container->query(DecryptAll::class), |
|
105 | + $container->getServer()->getLogger(), |
|
106 | + $container->getServer()->getL10N($container->getAppName()) |
|
107 | + ); |
|
108 | + }); |
|
109 | + } |
|
110 | 110 | } |
@@ -31,35 +31,35 @@ |
||
31 | 31 | use OCA\Encryption\KeyManager; |
32 | 32 | |
33 | 33 | class Setup { |
34 | - /** @var Crypt */ |
|
35 | - private $crypt; |
|
36 | - /** @var KeyManager */ |
|
37 | - private $keyManager; |
|
34 | + /** @var Crypt */ |
|
35 | + private $crypt; |
|
36 | + /** @var KeyManager */ |
|
37 | + private $keyManager; |
|
38 | 38 | |
39 | - public function __construct(Crypt $crypt, |
|
40 | - KeyManager $keyManager) { |
|
41 | - $this->crypt = $crypt; |
|
42 | - $this->keyManager = $keyManager; |
|
43 | - } |
|
39 | + public function __construct(Crypt $crypt, |
|
40 | + KeyManager $keyManager) { |
|
41 | + $this->crypt = $crypt; |
|
42 | + $this->keyManager = $keyManager; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $uid user id |
|
47 | - * @param string $password user password |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function setupUser($uid, $password) { |
|
51 | - if (!$this->keyManager->userHasKeys($uid)) { |
|
52 | - $keyPair = $this->crypt->createKeyPair(); |
|
53 | - return is_array($keyPair) ? $this->keyManager->storeKeyPair($uid, $password, $keyPair) : false; |
|
54 | - } |
|
55 | - return true; |
|
56 | - } |
|
45 | + /** |
|
46 | + * @param string $uid user id |
|
47 | + * @param string $password user password |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function setupUser($uid, $password) { |
|
51 | + if (!$this->keyManager->userHasKeys($uid)) { |
|
52 | + $keyPair = $this->crypt->createKeyPair(); |
|
53 | + return is_array($keyPair) ? $this->keyManager->storeKeyPair($uid, $password, $keyPair) : false; |
|
54 | + } |
|
55 | + return true; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * make sure that all system keys exists |
|
60 | - */ |
|
61 | - public function setupSystem() { |
|
62 | - $this->keyManager->validateShareKey(); |
|
63 | - $this->keyManager->validateMasterKey(); |
|
64 | - } |
|
58 | + /** |
|
59 | + * make sure that all system keys exists |
|
60 | + */ |
|
61 | + public function setupSystem() { |
|
62 | + $this->keyManager->validateShareKey(); |
|
63 | + $this->keyManager->validateMasterKey(); |
|
64 | + } |
|
65 | 65 | } |
@@ -30,62 +30,62 @@ |
||
30 | 30 | use OCP\Federation\ICloudId; |
31 | 31 | |
32 | 32 | class CloudId implements ICloudId { |
33 | - /** @var string */ |
|
34 | - private $id; |
|
35 | - /** @var string */ |
|
36 | - private $user; |
|
37 | - /** @var string */ |
|
38 | - private $remote; |
|
39 | - /** @var string|null */ |
|
40 | - private $displayName; |
|
33 | + /** @var string */ |
|
34 | + private $id; |
|
35 | + /** @var string */ |
|
36 | + private $user; |
|
37 | + /** @var string */ |
|
38 | + private $remote; |
|
39 | + /** @var string|null */ |
|
40 | + private $displayName; |
|
41 | 41 | |
42 | - /** |
|
43 | - * CloudId constructor. |
|
44 | - * |
|
45 | - * @param string $id |
|
46 | - * @param string $user |
|
47 | - * @param string $remote |
|
48 | - */ |
|
49 | - public function __construct(string $id, string $user, string $remote, ?string $displayName = null) { |
|
50 | - $this->id = $id; |
|
51 | - $this->user = $user; |
|
52 | - $this->remote = $remote; |
|
53 | - $this->displayName = $displayName; |
|
54 | - } |
|
42 | + /** |
|
43 | + * CloudId constructor. |
|
44 | + * |
|
45 | + * @param string $id |
|
46 | + * @param string $user |
|
47 | + * @param string $remote |
|
48 | + */ |
|
49 | + public function __construct(string $id, string $user, string $remote, ?string $displayName = null) { |
|
50 | + $this->id = $id; |
|
51 | + $this->user = $user; |
|
52 | + $this->remote = $remote; |
|
53 | + $this->displayName = $displayName; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * The full remote cloud id |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getId(): string { |
|
62 | - return $this->id; |
|
63 | - } |
|
56 | + /** |
|
57 | + * The full remote cloud id |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getId(): string { |
|
62 | + return $this->id; |
|
63 | + } |
|
64 | 64 | |
65 | - public function getDisplayId(): string { |
|
66 | - if ($this->displayName) { |
|
67 | - $atPos = strrpos($this->getId(), '@'); |
|
68 | - $atHost = substr($this->getId(), $atPos); |
|
69 | - return $this->displayName . $atHost; |
|
70 | - } |
|
71 | - return str_replace('https://', '', str_replace('http://', '', $this->getId())); |
|
72 | - } |
|
65 | + public function getDisplayId(): string { |
|
66 | + if ($this->displayName) { |
|
67 | + $atPos = strrpos($this->getId(), '@'); |
|
68 | + $atHost = substr($this->getId(), $atPos); |
|
69 | + return $this->displayName . $atHost; |
|
70 | + } |
|
71 | + return str_replace('https://', '', str_replace('http://', '', $this->getId())); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * The username on the remote server |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getUser(): string { |
|
80 | - return $this->user; |
|
81 | - } |
|
74 | + /** |
|
75 | + * The username on the remote server |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getUser(): string { |
|
80 | + return $this->user; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * The base address of the remote server |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function getRemote(): string { |
|
89 | - return $this->remote; |
|
90 | - } |
|
83 | + /** |
|
84 | + * The base address of the remote server |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function getRemote(): string { |
|
89 | + return $this->remote; |
|
90 | + } |
|
91 | 91 | } |