@@ -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 | } |