Completed
Push — master ( 2a5b9e...5fec60 )
by rugk
02:33
created

pruneOldActionLogEntries()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * CleanUp tasks executed via cron.
4
 *
5
 * @package ThreemaGateway
6
 * @author rugk
7
 * @copyright Copyright (c) 2015-2016 rugk
8
 * @license MIT
9
 */
10
11
class ThreemaGateway_CronEntry_CleanUp
12
{
13
    /**
14
     * This task removes all deleted messages, which are so old that they are
15
     * no risk for a reply attack anymore.
16
     *
17
     * This ensures that unnecessary meta data is deleted as afterwards also
18
     * the message ID is deleted so no one knows that the message has been
19
     * received.
20
     */
21
    public static function pruneOldDeletedMessages()
22
    {
23
        /** @var $messageModel ThreemaGateway_Model_Messages */
24
        $messageModel = XenForo_Model::create('ThreemaGateway_Model_Messages');
25
        $messageModel->setTimeLimit(null, ThreemaGateway_Helper_Message::getOldestPossibleReplayAttackDate(), 'date_received');
26
27
        /* @var XenForo_Options $options */
28
        $xenOptions = XenForo_Application::getOptions();
29
        // only need to test whether one attribute is invalid, all others are
30
        // automatically invalid too unless something is really went wrong
31
        /* @var array $condition */
32
        $conditions = ['date_send IS NULL'];
33
34
        // when the hardened mode is activated, only set receive date to "null"
35
        if ($xenOptions->threema_gateway_harden_reply_attack_protection) {
36
            // update all receive_dates with "null" to remove as much meta data
37
            // as possible
38
            $messageModel->removeMetaData($conditions, ['date_received']);
39
        } else {
40
            // remove whole data set
41
            $messageModel->removeMetaData($conditions);
42
        }
43
    }
44
45
    /**
46
     * This task removes all expired pending requests for the 2FA modes.
47
     *
48
     * This task should stay enabled.
49
     */
50
    public static function pruneExpiredTfaPendingRequests()
51
    {
52
        /** @var $messageModel ThreemaGateway_Model_Messages */
53
        $messageModel = XenForo_Model::create('ThreemaGateway_Model_TfaPendingMessagesConfirmation');
54
        $messageModel->deleteExpired();
55
    }
56
57
    /**
58
     * This task removes all old action log entries, which are not anymore used
59
     * for rate-limiting/throtteling any actions.
60
     *
61
     * This task should stay enabled.
62
     */
63
    public static function pruneOldActionLogEntries()
64
    {
65
        /** @var $throttleModel ThreemaGateway_Model_ActionThrottle */
66
        $throttleModel = XenForo_Model::create('ThreemaGateway_Model_ActionThrottle');
67
        $throttleModel->pruneActionLog();
68
    }
69
}
70