Issues (108)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Services/NotificationsService.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2014 Sourcefabric z.ú.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
namespace Newscoop\PaywallBundle\Services;
9
10
use Newscoop\Services\EmailService;
11
use Newscoop\NewscoopBundle\Services\SystemPreferencesService;
12
use Newscoop\Services\PlaceholdersService;
13
use Newscoop\Services\TemplatesService;
14
use Newscoop\PaywallBundle\Notifications\Emails;
15
use Newscoop\PaywallBundle\Meta\MetaSubscription;
16
use Doctrine\ORM\EntityManager;
17
use Newscoop\PaywallBundle\Events\PaywallEvents;
18
use Newscoop\EventDispatcher\Events\GenericEvent;
19
use Newscoop\PaywallBundle\Entity\UserSubscription;
20
use Newscoop\PaywallBundle\Entity\Order;
21
22
/**
23
 * Notifications service.
24
 */
25
class NotificationsService
26
{
27
    /**
28
     * @var EmailService
29
     */
30
    protected $emailService;
31
32
    /**
33
     * @var SystemPreferencesService
34
     */
35
    protected $systemPreferences;
36
37
    /**
38
     * @var TemplatesService
39
     */
40
    protected $templatesService;
41
42
    /**
43
     * @var PlaceholdersService
44
     */
45
    protected $placeholdersService;
46
47
    /**
48
     * @var EntityManager
49
     */
50
    protected $em;
51
52
    protected $dispatcher;
53
54
    /**
55
     * @param EmailService                  $emailService
56
     * @param SystemPreferencesService      $systemPreferences
57
     * @param TemplatesService              $templatesService
58
     * @param PlaceholdersService           $placeholdersService
59
     * @param EntityManager                 $em
60
     * @param ContainerAwareEventDispatcher $dispatcher
61
     */
62
    public function __construct(
63
        EmailService $emailService,
64
        SystemPreferencesService $systemPreferences,
65
        TemplatesService $templatesService,
66
        PlaceholdersService $placeholdersService,
67
        EntityManager $em,
68
        $dispatcher
69
    ) {
70
        $this->emailService = $emailService;
71
        $this->systemPreferences = $systemPreferences;
72
        $this->templatesService = $templatesService;
73
        $this->placeholdersService = $placeholdersService;
74
        $this->em = $em;
75
        $this->dispatcher = $dispatcher;
76
    }
77
78
    /**
79
     * Sends email notifications.
80
     *
81
     * @param string                                $code             Email message type
82
     * @param Newscoop\Entity\User                  $user             User object
0 ignored issues
show
There is no parameter named $user. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
83
     * @param PaywallBundle\Entity\UserSubscription $userSubscription User's subscription
0 ignored issues
show
There is no parameter named $userSubscription. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
84
     */
85
    public function sendNotification($code, array $recipients = array(), array $data = array())
86
    {
87
        if ($this->systemPreferences->PaywallEmailNotifyEnabled != '1') {
88
            return;
89
        }
90
91
        $smarty = $this->templatesService->getSmarty();
92
        $smarty->assign('user', new \MetaUser($data['user']));
93
        $subscriptions = array();
94
        $order = new Order();
95
        if (!$data['subscriptions'] instanceof UserSubscription) {
96
            $subscription = $data['subscriptions'][0];
97
            $order = $subscription->getOrder();
98
            foreach ($data['subscriptions'] as $key => $value) {
99
                $subscriptions[] = new MetaSubscription($value);
100
            }
101
102
            $smarty->assign('userSubscriptions', $subscriptions);
103
        } else {
104
            $subscription = $data['subscriptions'];
105
            $order = $subscription->getOrder();
106
            $smarty->assign('userSubscription', new MetaSubscription($subscription));
107
        }
108
109
        $smarty->assign('order', $order);
110
111
        try {
112
            $message = $this->loadProperMessageTemplateBy($code);
113
        } catch (\Exception $e) {
114
            throw new \Exception($e->getMessage());
115
        }
116
117
        $recipients = !empty($recipients) ? $recipients : $this->systemPreferences->PaywallMembershipNotifyEmail;
118
        $this->emailService->send(
119
            $this->placeholdersService->get('subject'),
120
            $message,
121
            $recipients,
122
            $this->systemPreferences->PaywallMembershipNotifyFromEmail
123
        );
124
    }
125
126
    private function loadProperMessageTemplateBy($code)
127
    {
128
        switch ($code) {
129
            case Emails::USER_CONFIRMATION:
130
                $message = $this->templatesService->fetchTemplate(
131
                    '_paywall/email_notify_user.tpl'
132
                );
133
                break;
134
            case Emails::SUBSCRIPTION_CONFIRMATION:
135
                $message = $this->templatesService->fetchTemplate(
136
                    '_paywall/email_notify_admin.tpl'
137
                );
138
                break;
139
            case Emails::SUBSCRIPTION_STATUS:
140
                $message = $this->templatesService->fetchTemplate(
141
                    '_paywall/email_subscription_status.tpl'
142
                );
143
                break;
144
            case Emails::SUBSCRIPTION_EXPIRATION:
145
                $message = $this->templatesService->fetchTemplate(
146
                    '_paywall/email_subscription_expiration.tpl'
147
                );
148
                break;
149
            case Emails::ADMIN_CREATED_CONFIRMATION:
150
                $message = $this->templatesService->fetchTemplate(
151
                    '_paywall/email_subscription_admin_created.tpl'
152
                );
153
                break;
154
            default:
155
                break;
156
        }
157
158
        return $message;
159
    }
160
161
    /**
162
     * Sets notify sent flag for given user subscription.
163
     * Level one of the notifications, for instance,
164
     * sends notifications 7 days before expiration.
165
     *
166
     * @param UserSubscription $subscription User subscription
167
     * @param \DateTime        $datetime     Date time when notify has been sent
168
     */
169
    public function setSentDateTimeOnLevelOne(UserSubscription $subscription, $datetime = null)
170
    {
171
        $subscription->setNotifySentLevelOne($datetime ?: new \DateTime('now'));
172
        $this->em->flush();
173
    }
174
175
    /**
176
     * Sets notify sent flag for given user subscription.
177
     * Level two of the notifications, for instance,
178
     * sends notifications 3 days before expiration.
179
     *
180
     * @param UserSubscription $subscription User subscription
181
     * @param \DateTime        $datetime     Date time when notify has been sent
182
     */
183
    public function setSentDateTimeOnLevelTwo(UserSubscription $subscription, $datetime = null)
184
    {
185
        $subscription->setNotifySentLevelTwo($datetime ?: new \DateTime('now'));
186
        $this->em->flush();
187
    }
188
189
    /**
190
     * Processes expiring subscriptions and sends email
191
     * notifications to users.
192
     *
193
     * @param \DateTime $now                Current date time
194
     * @param int       $subscriptionsCount Subscriptions count
0 ignored issues
show
There is no parameter named $subscriptionsCount. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
195
     */
196
    public function processExpiringSubscriptions($now, $notify, $count = 0, $days = 7)
197
    {
198
        if ($count === 0) {
199
            $count = $this->getExpiringSubscriptionsCount($now);
200
        }
201
202
        $batch = 100;
203
        $steps = ($count > $batch) ? ceil($count / $batch) : 1;
204
        for ($i = 0; $i < $steps; ++$i) {
205
            $offset = $i * $batch;
206
207
            $query = $this->em->getRepository('Newscoop\PaywallBundle\Entity\UserSubscription')
208
                ->getExpiringSubscriptions($offset, $batch, $now, $notify, $days);
209
210
            $expiringSubscriptions = $query->getResult();
211
            $this->dispatchNotificationSend($expiringSubscriptions);
212
        }
213
    }
214
215
    /**
216
     * Gets expiring subscriptions count.
217
     *
218
     * @param \DateTime $now Current date time
219
     *
220
     * @return int
221
     */
222
    public function getExpiringSubscriptionsCount($now, $notify, $days = 7)
223
    {
224
        $query = $this->em->getRepository('Newscoop\PaywallBundle\Entity\UserSubscription')
225
            ->getExpiringSubscriptionsCount($now, $notify, $days);
226
227
        return (int) $query->getSingleScalarResult();
228
    }
229
230
    private function dispatchNotificationSend($expiringSubscriptions)
231
    {
232
        foreach ($expiringSubscriptions as $key => $subscription) {
233
            $this->dispatcher->dispatch(
234
                PaywallEvents::SUBSCRIPTION_EXPIRATION,
235
                new GenericEvent($subscription)
236
            );
237
        }
238
    }
239
}
240