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/cfcm/admin.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
if (!defined('BASEPATH')) {
4
    exit('No direct script access allowed');
5
}
6
7
/**
8
 * Image CMS
9
 *
10
 * CFCM Admin
11
 * @property Forms $forms
12
 * @property Cfcm $cfcm
13
 */
14
class Admin extends BaseAdminController
15
{
16
17
    public function __construct() {
18
        parent::__construct();
19
20
        $this->load->library('DX_Auth');
21
        //cp_check_perm('module_admin');
22
23
        parent::__construct();
24
25
        $this->load->module('forms');
26
        $this->load->module('cfcm');
27
28
        $this->load->library('form_validation');
29
        $this->cfcm->_set_forms_config();
30
31
        $obj = new MY_Lang();
32
        $obj->load('cfcm');
33
    }
34
35
    public function create_field() {
36
        $form = $this->get_form('create_field');
37
        $form->action = $this->get_url('create_field');
38
        $form->title = lang('Field creating', 'cfcm');
39
40
        if ($this->input->post()) {
41
42
            if (!$this->input->post('field_name')) {
43
                showMessage(lang('Specify the field name', 'cfcm'), false, 'r');
44
                exit;
45
            }
46 View Code Duplication
            if (!$this->input->post('label')) {
47
                showMessage(lang('Specify <b>Label</b> field', 'cfcm'), false, 'r');
48
                exit;
49
            }
50
            if (!preg_match('/^[0-9a-z_]+$/i', $this->input->post('field_name'))) {
51
                showMessage(lang('Field Name cant contain only Latin alphanumeric characters', 'cfcm'), false, 'r');
52
                exit;
53
            }
54
55
            if ($form->isValid()) {
56
57
                $data = $form->getData();
58
                $groups = $data['groups'];
59
60
                $data['data'] = serialize($data);
61
                unset($data['groups']);
62
                $data['field_name'] = 'field_' . $data['field_name'];
63
                if ($this->db->get_where('content_fields', ['field_name' => $data['field_name']])->num_rows() > 0) {
64
                    showMessage(lang('Select another  name', 'cfcm'), false, 'r');
65
                } else {
66
                    // Set field weight.
67
                    $this->db->select_max('weight');
68
                    $query = $this->db->get('content_fields')->row();
69
                    $data['weight'] = $query->weight + 1;
70
71
                    $this->db->insert('content_fields', $data);
72
73
                    //write relations
74
                    $toInsert = [];
75 View Code Duplication
                    if (count($groups)) {
76
                        foreach ($groups as $group) {
77
                            $toInsert[] = [
78
                                           'field_name' => $data['field_name'],
79
                                           'group_id'   => $group,
80
                                          ];
81
                        }
82
83
                        if (count($toInsert)) {
84
                            $this->db->insert_batch('content_fields_groups_relations', $toInsert);
85
                        }
86
                    }
87
88
                    $this->lib_admin->log(lang('Field created', 'cfcm') . ' - field_' . $this->input->post('field_name'));
89
                    showMessage(lang('Field created', 'cfcm'));
90
91 View Code Duplication
                    if ($this->input->post('action') === 'close') {
92
                        pjax($this->get_url());
93
                    } else {
94
                        pjax($this->get_url('edit_field/' . $data['field_name']));
95
                    }
96
                    exit;
97
                }
98
            } else {
99
                showMessage($form->_validation_errors(), false, 'r');
100
            }
101
        } else {
102
            $this->template->add_array(
103
                ['form' => $form]
104
            );
105
106
            $this->render('_form');
107
        }
108
    }
109
110
    /**
111
     * @param string $name
112
     * @return mixed
113
     */
114
    public function get_form($name) {
115
        return $this->load->module('cfcm/cfcm_forms')->$name();
116
    }
117
118
    /**
119
     * @param string $segments
120
     * @return string
121
     */
122
    public function get_url($segments) {
123
        return site_url('admin/components/cp/cfcm/' . $segments);
124
    }
125
126
    public function create_group() {
127
        $form = $this->get_form('create_group_form');
128
        $form->action = $this->get_url('create_group');
129
        $form->title = lang('Creating a group', 'cfcm');
130
        $form->type = 'group';
131
        if ($this->input->post()) {
132 View Code Duplication
            if (!$this->input->post('name')) {
133
                showMessage(lang('Specify the group name', 'cfcm'), false, 'r');
134
                exit;
135
            }
136
137
            if ($form->isValid()) {
138
                $this->db->insert('content_field_groups', $form->getData());
139
140
                $last_field_id = $this->db->order_by('id', 'desc')->get('content_field_groups')->row()->id;
141
                $this->lib_admin->log(lang('Group has been created', 'cfcm') . '. Id: ' . $last_field_id);
142
                showMessage(lang('Group has been created', 'cfcm'));
143
                if ($this->input->post('action') == 'edit') {
144
                    pjax('/admin/components/cp/cfcm/edit_group/' . $last_field_id);
145
                } else {
146
                    pjax('/admin/components/cp/cfcm#fields_groups');
147
                }
148
            } else {
149
                showMessage($form->_validation_errors(), false, 'r');
150
            }
151
            exit;
152
        }
153
154
        $this->template->add_array(
155
            ['form' => $form]
156
        );
157
158
        $this->render('_form');
159
    }
160
161
    /**
162
     * @param string $field_name
163
     */
164
    public function delete_field($field_name) {
165
        $field_name = urldecode($field_name);
166
167
        $this->db->where('field_name', $field_name)
168
            ->delete('content_fields');
169
170
        $this->db->where('field_name', $field_name)
171
            ->delete('content_fields_data');
172
173
        $this->db->where('field_name', $field_name)
174
            ->delete('content_fields_groups_relations');
175
176
        $this->lib_admin->log(lang('Field deleted successfuly', 'cfcm') . ' - ' . $field_name);
177
        showMessage(lang('Field deleted successfuly', 'cfcm'));
178
        pjax($this->get_url('index'));
179
    }
180
181
    /**
182
     * @param int $id
183
     */
184
    public function delete_group($id) {
185
        //todo: delete group
186
        $this->db->where('id', $id)
187
            ->delete('content_field_groups');
188
189
        $this->db->where('group_id', $id)
190
            ->update('content_fields_groups_relations', ['group_id' => '0']);
191
192
        $this->db->where('field_group', $id)
193
            ->update('category', ['field_group' => '-1']);
194
195
        $this->db->where('category_field_group', $id)
196
            ->update('category', ['category_field_group' => '-1']);
197
198
        $this->lib_admin->log(lang('Group deleted successfuly', 'cfcm') . '. Id: ' . $id);
199
        showMessage(lang('Group deleted successfuly', 'cfcm'));
200
        pjax('/admin/components/cp/cfcm#fields_groups');
201
    }
202
203
    /**
204
     * @param string $name
205
     */
206
    public function edit_field($name = '') {
207
        $name = urldecode($name);
208
        $this->db->limit(1);
209
        $field = $this->db->get_where('content_fields', ['field_name' => (string) $name]);
210
211
        if ($field->num_rows() == 1) {
212
            $field = $field->row();
213
            $field_data = unserialize($field->data);
214
215
            $form = $this->load->module('cfcm/cfcm_forms')->edit_field($this->input->post('type')?:$field->type);
216
217
            $form->title = lang('Field editing', 'cfcm') . ': ' . $field->label;
218
            $form->action = $this->get_url('edit_field/' . $name);
219
220
            $form->setAttributes($field_data);
221
222
            $form->validation->setInitial(str_replace('required|', '', $field_data['validation']));
223
224
            if ($this->input->post()) {
225
                $data = $form->getData();
226
227
                if (isset($data['required'])) {
228
                    $data['validation'] = 'required|' . $data['validation'];
229
                }
230
                unset($data['validation_required']);
231
232
                /** Проверка на наличие сетнутых пунктов изображений и файлов*/
233
                if ($data['type'] == 'textarea') {
234
235
                    if (($data['enable_image_browser'] || $data['enable_file_browser']) || ($data['enable_image_browser'] && $data['enable_file_browser'])) {
236
                        $data['type'] = 'text';
237
238
                    }
239
                }
240
241
                $this->db->where('field_name', $field->field_name);
242
                $this->db->update(
243
                    'content_fields',
244
                    [
245
                     'data'  => serialize($data),
246
                     'type'  => $data['type'],
247
                     'label' => $data['label'],
248
                    ]
249
                );
250
251
                $groups = $data['groups'];
252
                $data['field_name'] = end($this->uri->segment_array());
0 ignored issues
show
$this->uri->segment_array() cannot be passed to end() as the parameter $array expects a reference.
Loading history...
253
254
                $this->db->delete('content_fields_groups_relations', ['field_name' => $data['field_name']]);
255 View Code Duplication
                if (count($groups)) {
256
                    foreach ($groups as $group) {
257
                        $toInsert[] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$toInsert was never initialized. Although not strictly required by PHP, it is generally a good practice to add $toInsert = 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...
258
                                       'field_name' => $data['field_name'],
259
                                       'group_id'   => $group,
260
                                      ];
261
                    }
262
263
                    $this->db->insert_batch('content_fields_groups_relations', $toInsert);
264
                }
265
266
                $this->lib_admin->log(lang('Field has been updated', 'cfcm') . ' - ' . $name);
267
                showMessage(lang('Field has been updated', 'cfcm'));
268
269
                if ($this->input->post('action') == 'close') {
270
                    pjax('/admin/components/cp/cfcm/index#additional_fields');
271
                }
272
            } else {
273
                $modulePath = getModulePath('cfcm');
274
                $this->template->registerJsFile($modulePath . 'templates/scripts/admin.js', 'after');
275
                $this->template->add_array(
276
                    ['form' => $form]
277
                );
278
279
                $this->render('_form');
280
            }
281
        } else {
282
283
            echo lang('Field has not been found', 'cfcm');
284
        }
285
    }
286
287
    /**
288
     * @param string $field_name
289
     */
290
    public function edit_field_data_type($field_name) {
291
        $form = $this->get_form('create_field');
292
        $form->action = $this->get_url('edit_field_data_type/' . $field_name);
293
        $form->title = lang('Field editing', 'cfcm');
294
295
        $field = $this->db->get_where('content_fields', ['field_name' => $field_name])->row_array();
296
297
        if ($this->input->post()) {
298
            $_POST['field_name'] = $field['field_name'];
299
300
            if ($form->isValid()) {
301
                $data = $form->getData();
302
                unset($data['field_name']);
303
304
                if (!$data['in_search']) {
305
                    $data['in_search'] = 0;
306
                }
307
308
                $this->db->limit(1);
309
                $this->db->where('field_name', $field_name);
310
                $this->db->update('content_fields', $data);
311
312
                showMessage(lang('Field has been updated', 'cfcm'));
313
                pjax($this->get_url('index'));
314
                exit;
315
            } else {
316
                showMessage($form->_validation_errors(), false, 'r');
317
                exit;
318
            }
319
            exit;
0 ignored issues
show
die; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
320
        }
321
322
        $form->setAttributes($field);
323
        $form->field_name->field->attributes = 'disabled="disabled"';
324
325
        $this->template->add_array(
326
            ['form' => $form]
327
        );
328
329
        $this->render('_form');
330
    }
331
332
    /**
333
     * @param int $id
334
     */
335
    public function edit_group($id) {
336
        $id = (int) $id;
337
338
        $group = $this->db->get_where('content_field_groups', ['id' => $id]);
339
340
        if ($group->num_rows() == 1) {
341
            $group = $group->row_array();
342
        } else {
343
            showMessage(lang('Group has not been found', 'cfcm'), false, 'r');
344
            exit;
345
        }
346
347
        $form = $this->get_form('create_group_form');
348
        $form->action = $this->get_url('edit_group/' . $id);
349
        $form->title = lang('ID group editing', 'cfcm') . $group['id'];
350
        $form->type = 'group';
351
        if ($this->input->post()) {
352
            if ($form->isValid()) {
353
                $data = $form->getData();
354
355
                $this->db->limit(1);
356
                $this->db->where('id', $id);
357
                $this->db->update('content_field_groups', $data);
358
359
                $this->lib_admin->log(lang('Group has been updated', 'cfcm') . '. Id: ' . $id);
360
361
                showMessage(lang('Group has been updated', 'cfcm'));
362 View Code Duplication
                if ('close' === $this->input->post('action')) {
363
                    pjax($this->get_url('index#fields_groups'));
364
                } else {
365
                    pjax($this->get_url('edit_group/' . $id));
366
                }
367
                exit;
368
            } else {
369
                showMessage($form->_validation_errors(), false, 'r');
370
                exit;
371
            }
372
        }
373
374
        $form->setAttributes($group);
375
376
        $this->template->add_array(
377
            ['form' => $form]
378
        );
379
380
        $this->render('_form');
381
    }
382
383
    /**
384
     * Create form from category field group
385
     * on add/edit page tpl.
386
     * @param bool|false|int $category_id
387
     * @param bool|false|int $item_id
388
     * @param bool|false|int $item_type
389
     */
390
    public function form_from_category_group($category_id = FALSE, $item_id = FALSE, $item_type = FALSE) {
391
        $this->cfcm->get_form($category_id, $item_id, $item_type);
392
    }
393
394
    /**
395
     * @param null|string $type
396
     */
397
    public function getFormFields($type = NULL) {
398
        if ($type) {
399
400
            $form = $this->load->module('cfcm/cfcm_forms')->edit_field($type);
401
402
            $findType = FALSE;
403
            $fieldsData = [];
404
            foreach ($form->fields as $key => $field) {
405
406
                if ($findType && $key != 'validation') {
407
                    $fieldsData[$key] = $field;
408
                }
409
410
                if ($key == 'type') {
411
                    $findType = TRUE;
412
                }
413
414
                if ($key == 'validation') {
415
                    break;
416
                }
417
            }
418
419
            return $this->render('one_type_field', ['fields' => $fieldsData], TRUE);
420
        }
421
    }
422
423
    /**
424
     * @param array $fields
425
     * @param integer $item_id
426
     * @param string|boolean $item_type
427
     * @return array|bool
428
     */
429
    public function get_form_attributes(array $fields, $item_id, $item_type) {
430
        return $this->cfcm->get_form_attributes($fields, $item_id, $item_type);
431
    }
432
433
    public function index() {
434
        $this->template->add_array(
435
            [
436
             'fields'    => $this->db->order_by('weight', 'ASC')->get('content_fields')->result_array(),
437
             'groups'    => $this->load->module('cfcm/cfcm_forms')->prepare_groups_select(),
438
             'groupRels' => $this->db
439
                 ->select('*')
440
                 ->join('content_field_groups', 'content_field_groups.id = content_fields_groups_relations.group_id OR content_fields_groups_relations.group_id = -1')
441
                 ->order_by('content_field_groups.id')
442
                 ->get('content_fields_groups_relations')
443
                 ->result_array(),
444
            ]
445
        );
446
447
        $groups = $this->db->get('content_field_groups');
448
449
        if ($groups->num_rows() > 0) {
450
            $this->template->assign('groups', $groups->result_array());
451
        } else {
452
            $this->template->assign('groups', false);
453
        }
454
        $this->render('index');
455
    }
456
457
    /**
458
     * render template
459
     * @param string $viewName
460
     * @param array $data
461
     */
462
    public function render($viewName, array $data = []) {
463
        if (!empty($data)) {
464
            $this->template->add_array($data);
465
        }
466
467
        if ($this->ajaxRequest) {
468
            echo $this->template->fetch('file:' . realpath(__DIR__) . '/templates/admin/' . $viewName);
469
        } else {
470
            $this->template->show('file:' . realpath(__DIR__) . '/templates/admin/' . $viewName);
471
        }
472
        exit;
473
    }
474
475
    public function save_weight() {
476
        if (count($this->input->post('fields_names')) > 0) {
477
            foreach ($this->input->post('fields_names') as $k => $v) {
478
                $name = (string) substr($v, 5);
479
                $weight = (int) $this->input->post('fields_pos')[$k];
480
481
                $this->db->where('field_name', $name);
482
                $this->db->update('content_fields', ['weight' => $weight]);
483
            }
484
        }
485
    }
486
487
}