Issues (199)

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.

code/controllers/DMSCheckoutController.php (7 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
class DMSCheckoutController extends DMSCartAbstractController
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
6
        'DMSDocumentRequestForm',
7
        'index',
8
        'complete',
9
        'send',
10
    );
11
12
    /**
13
     * An array containing the recipients basic information
14
     *
15
     * @config
16
     * @var array
17
     */
18
    private static $receiver_info = array(
0 ignored issues
show
The property $receiver_info is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'ReceiverName'            => '',
20
        'ReceiverPhone'           => '',
21
        'ReceiverEmail'           => '',
22
        'DeliveryAddressLine1'    => '',
23
        'DeliveryAddressLine2'    => '',
24
        'DeliveryAddressCountry'  => '',
25
        'DeliveryAddressPostCode' => '',
26
    );
27
28
    public function init()
29
    {
30
        parent::init();
31
32
        Requirements::css(DMS_CART_DIR . '/css/dms-cart.css');
33
    }
34
35
    public function index()
36
    {
37
        $this->getCart()->setBackUrl(Director::absoluteBaseURL().$this->Link());
38
        $form = $this->DMSDocumentRequestForm();
39
        return $this
40
            ->customise(array(
41
                'Form'  => $form,
42
                'Title' => _t(__CLASS__ . '.CHECKOUT_TITLE', 'Checkout')
43
            ))
44
            ->renderWith(array('Page', 'DMSDocumentRequestForm'));
45
    }
46
47
    /**
48
     * Gets and displays a list of items within the cart, as well as a contact form with entry
49
     * fields for the recipients information.
50
     *
51
     * To extend use the following from within an Extension subclass:
52
     *
53
     * <code>
54
     * public function updateDMSDocumentRequestForm($form)
55
     * {
56
     *     // Do something here
57
     * }
58
     * </code>
59
     *
60
     * @return Form
61
     */
62
    public function DMSDocumentRequestForm()
63
    {
64
        $fields = DMSDocumentCartSubmission::create()->scaffoldFormFields();
65
        $fields->replaceField('DeliveryAddressLine2', TextField::create('DeliveryAddressLine2', ''));
66
        $fields->replaceField('DeliveryAddressCountry', CountryDropdownField::create(
67
            'DeliveryAddressCountry',
68
            _t('DMSCheckoutController.RECEIVER_COUNTRY', 'Country')
69
        )->setValue('NZ'));
70
71
        $requiredFields = array(
72
            'ReceiverName',
73
            'ReceiverPhone',
74
            'ReceiverEmail',
75
            'DeliveryAddressLine1',
76
            'DeliveryAddressCountry',
77
            'DeliveryAddressPostCode',
78
        );
79
        foreach ($fields as $field) {
80
            if (in_array($field->name, $requiredFields)) {
81
                $field->addExtraClass('requiredField');
82
            }
83
        }
84
        $validator = RequiredFields::create($requiredFields);
85
        $actions = FieldList::create(
86
            FormAction::create(
87
                'doRequestSend',
88
                _t('DMSCheckoutController.SEND_ACTION', 'Send your request')
89
            )
90
        );
91
92
        $form = Form::create($this, 'DMSDocumentRequestForm', $fields, $actions, $validator);
93
94
        if ($receiverInfo = $this->getCart()->getReceiverInfo()) {
95
            $form->loadDataFrom($receiverInfo);
96
        }
97
98
        $form->setTemplate('DMSDocumentRequestForm');
99
        $this->extend('updateDMSDocumentRequestForm', $form);
100
101
        return $form;
102
    }
103
104
    /**
105
     * Sends an email to both the configured recipient as well as the requester. The
106
     * configured recipient is bcc'ed to the email in order to fulfill it.
107
     *
108
     * To extend use the following from within an Extension subclass:
109
     *
110
     * <code>
111
     * public function updateSend($email)
112
     * {
113
     *     // Do something here
114
     * }
115
     * </code>
116
     * @return mixed
117
     */
118
    public function send()
119
    {
120
        $cart = $this->getCart();
121
        $from = Config::inst()->get('Email', 'admin_email');
122
        $emailAddress = ($info = $cart->getReceiverInfo()) ? $info['ReceiverEmail'] : $from;
123
        $email = Email::create(
124
            $from,
125
            $emailAddress,
126
            _t('DMSCheckoutController.EMAIL_SUBJECT', 'Request for Printed Publications')
127
        );
128
129
        if ($bcc = $this->getConfirmationBcc()) {
130
            $email->setBcc($bcc);
131
        }
132
133
        $renderedCart = $cart->renderWith('DocumentCart_email');
134
        $body = sprintf(
135
            '<p>%s</p>',
136
            _t(
137
                'DMSCheckoutController.EMAIL_BODY',
138
                'A request for printed publications has been submitted with the following details:'
139
            )
140
        );
141
        $body .= $renderedCart->getValue();
142
        $email->setBody($body)->setReplyTo($emailAddress);
143
        $this->extend('updateSend', $email);
144
145
        return $email->send();
146
    }
147
148
    /**
149
     * Handles form submission.
150
     * Totals requested are updated, delivery details added, email sent for fulfillment
151
     * and print request totals updated.
152
     *
153
     * @param array $data
154
     * @param Form $form
155
     * @param SS_HTTPRequest $request
156
     *
157
     * @return SS_HTTPResponse
0 ignored issues
show
Should the return type not be SS_HTTPResponse|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
158
     */
159
    public function doRequestSend($data, Form $form, SS_HTTPRequest $request)
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
160
    {
161
        $this->updateCartReceiverInfo($data);
162
        $this->send();
163
        $this->getCart()->saveSubmission($form);
164
        $this->getCart()->emptyCart();
165
166
        return $this->redirect($this->Link('complete'));
167
    }
168
169
    /**
170
     * Displays the preconfigured thank you message to the user upon completion
171
     *
172
     * @return ViewableData
173
     */
174
    public function complete()
175
    {
176
        $data = array(
177
            'Title'   => _t(__CLASS__ . '.COMPLETE_THANKS', 'Thanks!'),
178
            'Content' => _t(
179
                __CLASS__ . '.COMPLETE_MESSAGE',
180
                'Thank you. You will receive a confirmation email shortly.'
181
            )
182
        );
183
184
        $this->extend('updateCompleteMessage', $data);
185
186
        return $this->customise($data)->renderWith('Page');
187
    }
188
189
    /**
190
     * Updates the cart receiver info just before the request is sent.
191
     *
192
     * @param array $data
193
     */
194
    public function updateCartReceiverInfo($data)
195
    {
196
        $info = array_merge(static::config()->get('receiver_info'), $data);
197
        $this->getCart()->setReceiverInfo($info);
198
    }
199
200
    /**
201
     * If BCC email addresses are configured, return the addresses to send to in comma delimited format
202
     *
203
     * @return string
0 ignored issues
show
Should the return type not be false|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
204
     */
205
    protected function getConfirmationBcc()
206
    {
207
        $emails = (array) static::config()->get('recipient_emails');
208
        if (empty($emails)) {
209
            return false;
210
        }
211
212
        return implode(',', $emails);
213
    }
214
}
215