1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - files_antivirus |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Viktar Dubiniuk <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @copyright Viktar Dubiniuk 2014-2018 |
11
|
|
|
* @license AGPL-3.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OCA\Files_Antivirus; |
15
|
|
|
|
16
|
|
|
class Notification { |
17
|
|
|
public static function sendMail($path) { |
18
|
|
|
if (!\OCP\User::isLoggedIn()) { |
19
|
|
|
return; |
20
|
|
|
} |
21
|
|
|
$user = \OC::$server->getUserSession()->getUser(); |
22
|
|
|
$email = $user->getEMailAddress(); |
23
|
|
|
$displayName = $user->getDisplayName(); |
24
|
|
|
if (\strval($displayName) === '') { |
25
|
|
|
$displayName = $user->getUID(); |
26
|
|
|
} |
27
|
|
|
\OCP\Util::writeLog( |
28
|
|
|
'files_antivirus', |
29
|
|
|
'Email: ' . $email, |
30
|
|
|
\OCP\Util::DEBUG |
31
|
|
|
); |
32
|
|
|
if (!empty($email)) { |
33
|
|
|
try { |
34
|
|
|
$tmpl = new \OCP\Template('files_antivirus', 'notification'); |
35
|
|
|
$tmpl->assign('file', $path); |
36
|
|
|
$tmpl->assign('host', \OC::$server->getRequest()->getServerHost()); |
37
|
|
|
$tmpl->assign('user', $displayName); |
38
|
|
|
$msg = $tmpl->fetchPage(); |
39
|
|
|
$from = \OCP\Util::getDefaultEmailAddress('security-noreply'); |
40
|
|
|
$mailer = \OC::$server->getMailer(); |
41
|
|
|
$message = $mailer->createMessage(); |
42
|
|
|
$message->setSubject( |
43
|
|
|
\OCP\Util::getL10N('files_antivirus')->t('Malware detected') |
44
|
|
|
); |
45
|
|
|
$message->setFrom([$from => 'ownCloud Notifier']); |
46
|
|
|
$message->setTo([$email => $displayName]); |
47
|
|
|
$message->setPlainBody($msg); |
48
|
|
|
$message->setHtmlBody($msg); |
49
|
|
|
$mailer->send($message); |
50
|
|
|
} catch (\Exception $e) { |
51
|
|
|
\OC::$server->getLogger()->error( |
52
|
|
|
__METHOD__ . ', exception: ' . $e->getMessage(), |
53
|
|
|
['app' => 'files_antivirus'] |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|