|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Cron for scheduled import. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Cron |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright YetiForce S.A. |
|
8
|
|
|
* @license YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com) |
|
9
|
|
|
* @author Tomasz Kur <[email protected]> |
|
10
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* OSSMailScanner_Verification_Cron class. |
|
15
|
|
|
*/ |
|
16
|
|
|
class OSSMailScanner_Verification_Cron extends \App\CronHandler |
|
17
|
|
|
{ |
|
18
|
|
|
/** {@inheritdoc} */ |
|
19
|
|
|
public function process() |
|
20
|
|
|
{ |
|
21
|
|
|
$config = OSSMailScanner_Record_Model::getConfig('cron'); |
|
22
|
|
|
$duration = $config['time'] ?? 0; |
|
23
|
|
|
$email = $config['email'] ?? ''; |
|
24
|
|
|
$dbCommand = App\Db::getInstance()->createCommand(); |
|
25
|
|
|
$dataReader = (new App\Db\Query())->from('vtiger_ossmails_logs')->where(['status' => 1])->createCommand()->query(); |
|
26
|
|
|
while ($row = $dataReader->read()) { |
|
27
|
|
|
$startTime = strtotime($row['start_time']); |
|
28
|
|
|
if ($duration && $email |
|
29
|
|
|
&& strtotime('now') > $startTime + ($duration * 60) |
|
30
|
|
|
&& !(new \App\Db\Query())->from('vtiger_ossmailscanner_log_cron')->where(['laststart' => $startTime])->exists()) { |
|
31
|
|
|
$dbCommand->insert('vtiger_ossmailscanner_log_cron', ['laststart' => $startTime, 'status' => 0, 'created_time' => date('Y-m-d H:i:s')])->execute(); |
|
32
|
|
|
$url = \App\Config::main('site_URL'); |
|
33
|
|
|
$mailStatus = \App\Mailer::addMail([ |
|
34
|
|
|
'to' => $email, |
|
35
|
|
|
'subject' => App\Language::translate('Email_FromName', 'OSSMailScanner'), |
|
36
|
|
|
'content' => App\Language::translate('Email_Body', 'OSSMailScanner') . "\r\n<br><a href='{$url}'>{$url}</a>", |
|
37
|
|
|
]); |
|
38
|
|
|
$dbCommand->update('vtiger_ossmailscanner_log_cron', ['status' => (int) $mailStatus], ['laststart' => $startTime])->execute(); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
$dataReader->close(); |
|
42
|
|
|
|
|
43
|
|
|
$hours = OSSMailScanner_Record_Model::getConfig('cron')['blockCheckHours'] ?? ''; |
|
44
|
|
|
$hours = $hours ? explode(',', $hours) : []; |
|
45
|
|
|
$query = (new \App\Db\Query())->from('roundcube_users')->where(['crm_status' => \OSSMail_Record_Model::MAIL_BOX_STATUS_BLOCKED_TEMP]); |
|
46
|
|
|
$dataReader = $query->createCommand()->query(); |
|
47
|
|
|
while ($account = $dataReader->read()) { |
|
48
|
|
|
if (empty($account['actions'])) { |
|
49
|
|
|
continue; |
|
50
|
|
|
} |
|
51
|
|
|
$check = true; |
|
52
|
|
|
if (!empty($account['failed_login'])) { |
|
53
|
|
|
$check = date('Y-m-d G', strtotime($account['failed_login'])) !== date('Y-m-d G'); |
|
54
|
|
|
if ($hours && $check) { |
|
55
|
|
|
$check = \in_array(date('G'), $hours); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
if ($check) { |
|
59
|
|
|
\OSSMail_Record_Model::imapConnect($account['username'], \App\Encryption::getInstance()->decrypt($account['password']), $account['mail_host'], '', false, [], $account); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
$dataReader->close(); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|