|
9 | 9 | use Coduo\PHPHumanizer\NumberHumanizer; |
10 | 10 | use Exception; |
11 | 11 | use OCA\GDataVaas\AppInfo\Application; |
12 | | -use OCP\Files\File; |
13 | | -use OCP\Files\InvalidPathException; |
14 | | -use OCP\Files\NotFoundException; |
15 | 12 | use OCP\IAppConfig; |
16 | 13 | use OCP\Mail\IMailer; |
17 | 14 | use Psr\Log\LoggerInterface; |
@@ -76,100 +73,4 @@ private function getNotifyMails(): array { |
76 | 73 | } |
77 | 74 | return explode(',', $notifyMails); |
78 | 75 | } |
79 | | - |
80 | | - /** |
81 | | - * @param array $maliciousFiles |
82 | | - * @return void |
83 | | - * @throws Exception |
84 | | - */ |
85 | | - public function notifyWeeklySummary(array $maliciousFiles): void { |
86 | | - $msg = $this->mailer->createMessage(); |
87 | | - $msg->setSubject('Summary: Malicious files in your Nextcloud instance'); |
88 | | - $msg->setHtmlBody($this->createSummaryHtml($maliciousFiles)); |
89 | | - $msg->setPlainBody($this->createSummaryPlain($maliciousFiles)); |
90 | | - $receiver = $this->getNotifyMails(); |
91 | | - $msg->setTo($receiver); |
92 | | - |
93 | | - $this->mailer->send($msg); |
94 | | - $this->logger->debug('Mail sent to ' . implode(', ', $receiver)); |
95 | | - } |
96 | | - |
97 | | - /** |
98 | | - * @param array $maliciousFiles |
99 | | - * @return string |
100 | | - */ |
101 | | - private function createSummaryHtml(array $maliciousFiles): string { |
102 | | - $htmlMessage = '<p>This is your weekly summary of the malicious files found in your Nextcloud instance:</p>'; |
103 | | - $htmlMessage .= '<p>Found ' . count($maliciousFiles) . ' malicious files:</p>'; |
104 | | - $htmlMessage .= '<table>'; |
105 | | - $htmlMessage .= '<tr>'; |
106 | | - $htmlMessage .= '<td> <strong>Name</strong> </td>'; |
107 | | - $htmlMessage .= '<td> <strong>Path</strong> </td>'; |
108 | | - $htmlMessage .= '<td> <strong>Owner</strong> </td>'; |
109 | | - $htmlMessage .= '<td> <strong>Upload time</strong> </td>'; |
110 | | - $htmlMessage .= '<td> <strong>Mimetype</strong> </td>'; |
111 | | - $htmlMessage .= '<td> <strong>Size</strong> </td>'; |
112 | | - $htmlMessage .= '</tr>'; |
113 | | - foreach ($maliciousFiles as $file) { |
114 | | - if ($file instanceof File) { |
115 | | - try { |
116 | | - $size = $file->getSize(); |
117 | | - } catch (InvalidPathException|NotFoundException) { |
118 | | - $size = 0; |
119 | | - } |
120 | | - $uploadTime = $file->getCreationTime() ?: $file->getUploadTime(); |
121 | | - if ($uploadTime === 0) { |
122 | | - $uploadTime = 'Unknown'; |
123 | | - } |
124 | | - $htmlMessage .= '<tr>'; |
125 | | - $htmlMessage .= '<td>' . $file->getName() . '</td>'; |
126 | | - $htmlMessage .= '<td>' . $file->getInternalPath() . '</td>'; |
127 | | - $htmlMessage .= '<td>' . $file->getOwner()->getDisplayName() . '</td>'; |
128 | | - $htmlMessage .= '<td>' . $uploadTime . '</td>'; |
129 | | - $htmlMessage .= '<td>' . $file->getMimeType() . '</td>'; |
130 | | - if ($size !== 0) { |
131 | | - $htmlMessage .= '<td>' . NumberHumanizer::binarySuffix($size, 'de') . '</td>'; |
132 | | - } else { |
133 | | - $htmlMessage .= '<td>Unknown</td>'; |
134 | | - } |
135 | | - $htmlMessage .= '</tr>'; |
136 | | - } |
137 | | - } |
138 | | - $htmlMessage .= '</table>'; |
139 | | - return $htmlMessage; |
140 | | - } |
141 | | - |
142 | | - /** |
143 | | - * @param array $maliciousFiles |
144 | | - * @return string |
145 | | - */ |
146 | | - private function createSummaryPlain(array $maliciousFiles): string { |
147 | | - $plainMessage = "This is your weekly summary of the malicious files found in your Nextcloud instance:\n"; |
148 | | - $plainMessage .= 'Found ' . count($maliciousFiles) . " malicious files:\n"; |
149 | | - foreach ($maliciousFiles as $file) { |
150 | | - if ($file instanceof File) { |
151 | | - $plainMessage .= "\n"; |
152 | | - try { |
153 | | - $size = $file->getSize(); |
154 | | - } catch (InvalidPathException|NotFoundException) { |
155 | | - $size = 0; |
156 | | - } |
157 | | - $uploadTime = $file->getCreationTime() ?: $file->getUploadTime(); |
158 | | - if ($uploadTime === 0) { |
159 | | - $uploadTime = 'Unknown'; |
160 | | - } |
161 | | - $plainMessage .= 'Name: ' . $file->getName() . "\n"; |
162 | | - $plainMessage .= 'Path: ' . $file->getPath() . "\n"; |
163 | | - $plainMessage .= 'Owner: ' . $file->getOwner()->getDisplayName() . "\n"; |
164 | | - $plainMessage .= 'Time: ' . $uploadTime . "\n"; |
165 | | - $plainMessage .= 'Mimetype: ' . $file->getMimeType() . "\n"; |
166 | | - if ($size !== 0) { |
167 | | - $plainMessage .= 'Size: ' . NumberHumanizer::binarySuffix($size, 'de') . "\n"; |
168 | | - } else { |
169 | | - $plainMessage .= "Size: Unknown\n"; |
170 | | - } |
171 | | - } |
172 | | - } |
173 | | - return $plainMessage; |
174 | | - } |
175 | 76 | } |
0 commit comments