Issues (1177)

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.

application/modules/cmsemail/admin.php (1 issue)

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
use cmsemail\email;
4
use CMSFactory\assetManager;
5
6
(defined('BASEPATH')) OR exit('No direct script access allowed');
7
8
/**
9
 * Image CMS
10
 * Email Module Admin
11
 * @property Cache $cache
12
 * @property Cms_base $cms_base
13
 */
14
class Admin extends BaseAdminController
15
{
16
17
    const MAX_DEFAULT_TEMPLATES_CORPORATE = 3;
18
    const MAX_DEFAULT_TEMPLATES_SHOP = 7;
19
20
    /**
21
     * Object of Email class
22
     * @var Email
23
     */
24
    public $email;
25
26
    public function __construct() {
27
        parent::__construct();
28
        $this->load->language('email');
29
        $this->email = email::getInstance();
30
        $lang = new MY_Lang();
31
        $lang->load('cmsemail');
32
    }
33
34
    public function index() {
35
        assetManager::create()
36
            ->setData(
37
                [
38
                 'models'                => $this->email->getAllTemplates(),
39
                 'defaultTemplatesCount' => $this->getMaxDefaultTemplatesCount(),
40
                ]
41
            )
42
            ->renderAdmin('list');
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    private function getMaxDefaultTemplatesCount() {
49
        if (MY_Controller::isCorporateCMS()) {
50
            return self::MAX_DEFAULT_TEMPLATES_CORPORATE;
51
        }
52
53
        return self::MAX_DEFAULT_TEMPLATES_SHOP;
54
    }
55
56
    /**
57
     * @param string $locale
58
     */
59
    public function settings($locale) {
60
61
        $locale = $locale ?: MY_Controller::defaultLocale();
62
        $encryption = [
63
                       'tls',
64
                       'ssl',
65
                      ];
66
        assetManager::create()
67
            ->registerScript('email')
68
            ->registerStyle('style')
69
            ->setData('settings', $this->email->getSettings($locale))
70
            ->setData('languages', $this->cms_base->get_langs())
71
            ->setData('locale', $locale)
72
            ->setData('encryption', $encryption)
73
            ->renderAdmin('settings');
74
    }
75
76
    public function create() {
77
78
        if ($this->input->post()) {
79
            $id = $this->email->create();
80
            if ($id) {
81
                $this->lib_admin->log(lang('E-mail template created', 'cmsemail') . ' - ' . $this->input->post('mail_name'));
82
                showMessage(lang('Template created', 'cmsemail'));
83
84 View Code Duplication
                if ($this->input->post('action') == 'tomain') {
85
                    pjax('/admin/components/cp/cmsemail/index');
86
                } else {
87
                    pjax('/admin/components/cp/cmsemail/edit/' . $id . '#settings');
88
                }
89
            } else {
90
                showMessage($this->email->errors, '', 'r');
91
            }
92
        } else {
93
            assetManager::create()
94
                ->registerScript('email')
95
                ->setData('settings', $this->email->getSettings())
96
                ->renderAdmin('create');
97
        }
98
    }
99
100
    public function mailTest() {
101
        lang('email_sent', 'admin');
102
        echo $this->email->mailTest();
103
    }
104
105
    public function delete() {
106
107
        $this->db->select('name');
108
        foreach ($this->input->post('ids') as $id) {
109
            $this->db->or_where('id', $id);
110
        }
111
        $names = $this->db->get('mod_email_paterns')->result_array();
112
        $this->email->delete($this->input->post('ids'));
113
        foreach ($names as $val) {
114
            $logNames[] = $val['name'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$logNames was never initialized. Although not strictly required by PHP, it is generally a good practice to add $logNames = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
115
        }
116
        $this->lib_admin->log(lang('Email template deleted', 'cmsemail') . ' - ' . implode(', ', $logNames));
117
        showMessage(lang('Email template deleted', 'cmsemail'), lang('Message', 'cmsemail'));
118
    }
119
120
    public function edit($id, $locale = null) {
121
122
        if (null === $locale) {
123
            $locale = chose_language();
124
        }
125
126
        $model = $this->email->getTemplateById($id, $locale);
127
128
        if (!$model) {
129
            $this->load->module('core');
130
            $this->core->error_404();
131
            exit;
132
        }
133
        $variables = unserialize($model['variables']);
134
135
        if ($this->input->post()) {
136
            if ($this->email->edit($id, [], $locale)) {
137
                $name = $this->db->select('name')->where('id', $id)->get('mod_email_paterns')->row()->name;
138
139
                $this->lib_admin->log(lang('Email template was edited', 'cmsemail') . ' - ' . $name);
140
                showMessage(lang('Template edited', 'cmsemail'));
141
142
                if ($this->input->post('action') == 'tomain') {
143
                    pjax('/admin/components/cp/cmsemail/index');
144
                }
145
            } else {
146
                showMessage($this->email->errors, '', 'r');
147
            }
148
        } else {
149
            assetManager::create()
150
                ->setData('locale', $locale)
151
                ->setData('languages', $this->db->get('languages')->result_array())
152
                ->setData('model', $model)
153
                ->setData('variables', $variables)
154
                ->registerScript('email')
155
                ->renderAdmin('edit');
156
        }
157
    }
158
159
    /**
160
     * update settings for email
161
     * @param string $locale
162
     */
163
    public function update_settings($locale) {
164
165
        $locale = $locale ?: MY_Controller::defaultLocale();
166
167
        if ($this->input->post()) {
168
            $this->form_validation->set_rules('settings[admin_email]', lang('Admin email', 'cmsemail'), 'required|xss_clean|callback_email_check|trim');
169
            $this->form_validation->set_rules('settings[from_email]', lang('Email sender', 'cmsemail'), 'required|xss_clean|valid_email');
170
            $this->form_validation->set_rules('settings[from]', lang('From', 'cmsemail'), 'required|xss_clean');
171
            $this->form_validation->set_rules('settings[theme]', lang('From email', 'cmsemail'), 'xss_clean|required');
172
173
            $post_settings = $this->input->post('settings');
174
            if ($post_settings['wraper_activ']) {
175
                $this->form_validation->set_rules('settings[wraper]', lang('Wraper', 'cmsemail'), 'required|xss_clean|callback_wraper_check');
176
            } else {
177
                $this->form_validation->set_rules('settings[wraper]', lang('Wraper', 'cmsemail'), 'xss_clean');
178
            }
179
180
            if ($this->form_validation->run($this) == FALSE) {
181
                showMessage(validation_errors(), lang('Message', 'cmsemail'), 'r');
182 View Code Duplication
            } else {
183
                $data = [
184
                         'locale'   => $locale,
185
                         'settings' => $this->input->post('settings'),
186
                        ];
187
188
                $this->email->setSettings($data);
189
                showMessage(lang('Settings saved', 'cmsemail'), lang('Message', 'cmsemail'));
190
                $this->lib_admin->log(lang('Template customization mails have been changed', 'cmsemail') . '. Id: '); // . $id);??
191
            }
192
193
            $this->cache->delete_all();
194
        }
195
    }
196
197
    /**
198
     * @param string $wrapper
199
     * @return bool
200
     */
201
    public function wraper_check($wrapper) {
202
203
        if (preg_match('/\$content/', htmlentities($wrapper))) {
204
            return TRUE;
205
        } else {
206
            $this->form_validation->set_message('wraper_check', lang('Field', 'cmsemail') . ' %s ' . lang('Must contain variable', 'cmsemail') . ' $content');
207
            return FALSE;
208
        }
209
    }
210
211
    /**
212
     * @param $emails
213
     *
214
     * @return bool
215
     */
216 View Code Duplication
    public function email_check($emails) {
217
218
        $emails = str_replace(' ', '', $emails);
219
220
        foreach (explode(',', $emails) as $e) {
221
            if (!filter_var($e, FILTER_VALIDATE_EMAIL)) {
222
                $this->form_validation->set_message('email_check', lang('Field', 'cmsemail') . ' %s ' . lang('Must contain valid email', 'cmsemail'));
223
224
                return false;
225
            }
226
        }
227
228
        return TRUE;
229
    }
230
231
    /**
232
     * @param null|string $locale
233
     * @return bool|object
234
     */
235
    public function deleteVariable($locale = null) {
236
237
        if (null === $locale) {
238
            $locale = chose_language();
239
        }
240
        $template_id = $this->input->post('template_id');
241
        $variable = $this->input->post('variable');
242
243
        return $this->email->deleteVariable($template_id, $variable, $locale);
244
    }
245
246
    /**
247
     * @param null|string $locale
248
     * @return bool|object
249
     */
250
    public function updateVariable($locale = null) {
251
252
        if (null === $locale) {
253
            $locale = chose_language();
254
        }
255
        $template_id = $this->input->post('template_id');
256
        $variable = $this->input->post('variable');
257
        $variableNewValue = $this->input->post('variableValue');
258
        $oldVariable = $this->input->post('oldVariable');
259
        return $this->email->updateVariable($template_id, $variable, $variableNewValue, $oldVariable, $locale);
260
    }
261
262
    /**
263
     * @param null|string $locale
264
     * @return bool
265
     */
266
    public function addVariable($locale = null) {
267
268
        if (null === $locale) {
269
            $locale = chose_language();
270
        }
271
        $template_id = $this->input->post('template_id');
272
        $variable = $this->input->post('variable');
273
        $variableValue = $this->input->post('variableValue');
274
275
        if ($this->email->addVariable($template_id, $variable, $variableValue, $locale)) {
276
            assetManager::create()
277
                ->setData('template_id', $template_id)
278
                ->setData('variable', $variable)
279
                ->setData('variable_value', $variableValue)
280
                ->setData('locale', $locale)
281
                ->render('newVariable', true);
282
        } else {
283
            return FALSE;
284
        }
285
    }
286
287
    /**
288
     * @param null|string $locale
289
     * @return bool
290
     */
291
    public function getTemplateVariables($locale = null) {
292
293
        if (null === $locale) {
294
            $locale = chose_language();
295
        }
296
        $template_id = $this->input->post('template_id');
297
        $variables = $this->email->getTemplateVariables($template_id, $locale);
298
        if ($variables) {
299
            assetManager::create()
300
                ->setData('variables', $variables)
301
                ->render('variablesSelectOptions', true);
302
        } else {
303
            return FALSE;
304
        }
305
    }
306
307
    /**
308
     * import templates from file
309
     */
310
    public function import_templates() {
311
312
        $this->db->where_in('id', [1, 2, 3, 4, 5, 6, 7, 8, 9])->delete('mod_email_paterns');
313
        $this->db->where_in('id', [1, 2, 3, 4, 5, 6, 7, 8, 9])->delete('mod_email_paterns_i18n');
314
315
        if (MY_Controller::isCorporateCMS()) {
316
            $file = $this->load->file(__DIR__ . '/models/paterns_corporate.sql', true);
317
            $file_i18n = $this->load->file(__DIR__ . '/models/patterns_i18n_corporate.sql', true);
318
        } else {
319
            $file = $this->load->file(__DIR__ . '/models/paterns.sql', true);
320
            $file_i18n = $this->load->file(__DIR__ . '/models/patterns_i18n.sql', true);
321
        }
322
        $this->db->query($file);
323
        $this->db->query($file_i18n);
324
325
        $this->lib_admin->log(lang('Email templates were successfully imported', 'cmsemail'));
326
327
        redirect('/admin/components/cp/cmsemail/');
328
    }
329
330
}