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/banners/admin.php (5 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
use CMSFactory\assetManager;
4
5
(defined('BASEPATH')) OR exit('No direct script access allowed');
6
7
/**
8
 * Admin Class for Banners module
9
 * @uses BaseAdminController
10
 * @author L.Andriy <[email protected]>
11
 * @copyright (c) 2013, ImageCMS
12
 * @package ImageCMSModule
13
 * @property banner_model $banner_model
14
 */
15
class Admin extends BaseAdminController
16
{
17
18
    public function __construct() {
19
        parent::__construct();
20
        $this->load->model('banner_model');
21
        $this->load->helper('banners');
22
23
        $locale = $this->db->where('default', 1)->get('languages')->result_array();
24
        $this->def_locale = $locale[0]['identif'];
25
26
        $lang = new MY_Lang();
27
        $lang->load('banners');
28
29
        if (!$this->db->table_exists('mod_banner_groups')) {
30
            $this->banner_model->createGroupsTable();
31
        }
32
33
        $this->is_shop = SHOP_INSTALLED;
34
    }
35
36
    public function createGroup() {
37
        $name = $this->input->post('name');
38
        if ($this->db->where($name)->get('mod_banner_groups')) {
39
            return FALSE;
40
        }
41
42 View Code Duplication
        if ($this->db->table_exists('mod_banner_groups')) {
43
            $this->db->set('name', $name)->insert('mod_banner_groups');
44
        } else {
45
            $this->banner_model->createGroupsTable();
46
47
            $this->db->set('name', $name)->insert('mod_banner_groups');
48
        }
49
        if (!$this->db->_error_message()) {
50
            echo $this->db->insert_id();
51
        } else {
52
            echo 0;
53
        }
54
    }
55
56
    public function delGroup() {
57
        $name = $this->input->post('name');
58 View Code Duplication
        if ($this->db->table_exists('mod_banner_groups')) {
59
            $this->db->where('name', $name[0])->delete('mod_banner_groups');
60
        } else {
61
            $this->banner_model->createGroupsTable();
62
63
            $this->db->where('name', $name[0])->delete('mod_banner_groups');
64
        }
65
        if (!$this->db->_error_message()) {
66
            echo 1;
67
        } else {
68
            echo 0;
69
        }
70
    }
71
72
    /**
73
     * @access public
74
     * @author L.Andriy <[email protected]>
75
     * @copyright (c) 2013, ImageCMS
76
     */
77
    public function index() {
78
        /** Get all Banners from DB */
79
        $locale = $this->def_locale;
80
        $banners = $this->banner_model->get_all_banner($locale, 0, FALSE);
81
82
        /** Show Banners list */
83
        assetManager::create()
84
                ->registerScript('main')
85
                ->setData(['banners' => $banners, 'locale' => $locale, 'show_tpl' => $this->banner_model->get_settings_tpl()])
86
                ->renderAdmin('list');
87
    }
88
89
    /**
90
     * @access public
91
     * @author L.Andriy <[email protected]>
92
     * @copyright (c) 2013, ImageCMS
93
     */
94
    public function settings() {
95
        $st = (int) $this->input->post('status');
96
97
        $arr = serialize(['show_tpl' => $st]);
98
        $sql = $this->db->query("update  components set settings = '$arr' where name = 'banners'");
0 ignored issues
show
$sql is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
99
    }
100
101
    /**
102
     * Switch Banners activity status
103
     * @access public
104
     * @author L.Andriy <[email protected]>
105
     * @copyright (c) 2013, ImageCMS
106
     */
107
    public function chose_active() {
108
        $status = ($this->input->post('status')) === 'false' ? 1 : 0;
109
        $this->banner_model->chose_active($this->input->post('id'), $status);
110
        $this->lib_admin->log(lang('Banner status was edited', 'banners') . '. Id: ' . $this->input->post('id'));
111
    }
112
113
    /**
114
     * Banners remove method
115
     * @access public
116
     * @param $_POST $id
0 ignored issues
show
The doc-type $_POST could not be parsed: Unknown type name "$_POST" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
There is no parameter named $id. 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...
117
     * @author L.Andriy <[email protected]>
118
     * @copyright (c) 2013, ImageCMS
119
     */
120
    public function delete() {
121
        /** Remove Banners by Ids */
122
        $ids = $this->input->post('id');
123
        foreach (json_decode($ids) as $key) {
124
            $this->banner_model->del_banner($key);
125
        }
126
        $this->lib_admin->log(lang('Banner was removed', 'banners') . '. Ids: ' . implode(', ', json_decode($ids)));
127
    }
128
129
    /**
130
     * Сreate new Banner
131
     * @access public
132
     * @param $_POST
133
     * @author L.Andriy <[email protected]>
134
     * @copyright (c) 2013, ImageCMS
135
     */
136
    public function create() {
137
        if ($this->input->post()) {
138
139
            $this->load->library('Form_validation');
140
            /** Set Validation reles */
141
            $this->form_validation->set_rules('name', lang('Banner name', 'banners'), 'required|xss_clean|max_length[45]');
142
            $this->form_validation->set_rules('photo', lang('Image', 'banners'), 'required|xss_clean');
143
            if ($this->form_validation->run($this) !== FALSE) {
144
                /** Set Instart data */
145
                $data = [
146
                         'name'        => $this->input->post('name'),
147
                         'active'      => (int) $this->input->post('active'),
148
                         'description' => $this->input->post('description'),
149
                         'active_to'   => $this->input->post('active_to_permanent') == 'on' ? -1 : (int) strtotime($this->input->post('active_to')),
150
                         'where_show'  => count($this->input->post('data')) ? serialize(array_unique($this->input->post('data'))) : serialize([]),
151
                         'photo'       => $this->input->post('photo'),
152
                         'url'         => $this->input->post('url'),
153
                         'locale'      => $this->def_locale,
154
                        ];
155
                /** Create new banner from data-array */
156
                try {
157
                    $lid = $this->banner_model->add_banner($data);
158
159
                    $last_banner_id = $this->db->order_by('id', 'desc')->get('mod_banner')->row()->id;
160
                    $this->lib_admin->log(lang('Banner created', 'banners') . '. Id: ' . $last_banner_id);
161
                    showMessage(lang('Banner created', 'banners'));
162
                    /** Show successful message and redirect */
163
                    if ($this->input->post('action') == 'tomain') {
164
                        pjax('/admin/components/init_window/banners');
165
                    } elseif ($this->input->post('action') == 'toedit') {
166
                        pjax('/admin/components/init_window/banners/edit/' . $lid);
167
                    }
168
                } catch (Exception $e) {
169
                    showMessage($e->getMessage(), '', 'r');
170
                }
171
            } else {
172
                /** Show validation error message */
173
                showMessage(validation_errors(), false, 'r');
174
            }
175
        } else {
176
177
            /** Show empty form for create */
178
            assetManager::create()
179
                    ->registerScript('main')
180
                    ->registerStyle('style')
181
                    ->setData(['is_shop' => $this->is_shop, 'locale' => $locale, 'languages' => $lan])
0 ignored issues
show
The variable $locale does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $lan does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
182
                    ->renderAdmin('create');
183
        }
184
    }
185
186
    /**
187
     * Edit Banner by Id Banner
188
     * @access public
189
     * @param integer $id
190
     * @param string $locale
191
     * @author L.Andriy <[email protected]>
192
     * @copyright (c) 2013, ImageCMS
193
     */
194
    public function edit($id, $locale = null) {
195
        /** Locale value is necessary */
196
        ($locale != null) OR $locale = $this->def_locale;
197
198
        if ($this->input->post('name')) {
199
200
            $this->load->library('Form_validation');
201
            $this->form_validation->set_rules('name', lang('Banner name', 'banners'), 'required|xss_clean|max_length[45]');
202
            $this->form_validation->set_rules('photo', lang('Photo', 'banners'), 'required|xss_clean');
203
204
            if ($this->form_validation->run($this) != FALSE) {
205
206
                /** Set Update data */
207
                $data = [
208
                         'name'        => $this->input->post('name'),
209
                         'active'      => (int) $this->input->post('active'),
210
                         'description' => $this->input->post('description'),
211
                         'active_to'   => $this->input->post('active_to_permanent') == 'on' ? -1 : (int) strtotime($this->input->post('active_to')),
212
                         'where_show'  => count($this->input->post('data')) ? serialize(array_unique($this->input->post('data'))) : serialize([]),
213
                         'photo'       => $this->input->post('photo'),
214
                         'url'         => $this->input->post('url'),
215
                         'locale'      => $locale,
216
                         'group'       => serialize($this->input->post('group')),
217
                         'id'          => (int) $id,
218
                        ];
219
                /** Update banner from data-array */
220
                $this->banner_model->edit_banner($data);
221
222
                /** Show successful message and redirect */
223
                $this->lib_admin->log(lang('Banner was edited', 'banners') . '. Id: ' . $id);
224
                showMessage(lang('Data is saved', 'banners'));
225
                if ($this->input->post('action') == 'tomain') {
226
                    pjax('/admin/components/init_window/banners');
227
                }
228
            } else {
229
                /** Show validation error message */
230
                showMessage(validation_errors(), false, 'r');
231
            }
232
        } else {
233
234
            $banner = $this->banner_model->get_one_banner($id, $locale);
235
            $groups = $this->banner_model->getGroups();
236
237
            if (!isset($banner['id']) OR empty($banner)) {
238
                $banner['id'] = $id;
239
            }
240
241
            /** Show Banner edit template */
242
            CMSFactory\assetManager::create()
243
                    ->registerScript('main')
244
                    ->registerStyle('style')
245
                    ->setData(
246
                        [
247
                         'is_shop'   => $this->is_shop,
248
                         'banner'    => $banner,
249
                         'locale'    => $locale,
250
                         'languages' => $this->db->get('languages')->result_array(),
251
                         'groups'    => $groups,
252
                        ]
253
                    )
254
                    ->renderAdmin('edit');
255
        }
256
    }
257
258
    /**
259
     * Data Autocomplete
260
     * @access public
261
     * @author L.Andriy <[email protected]>
262
     * @copyright (c) 2013, ImageCMS
263
     */
264
    public function autosearch() {
265
        switch ($this->input->post('queryString')) {
266 View Code Duplication
            case 'product':
267
                $entity = SProductsQuery::create()->setComment(__METHOD__)->joinWithI18n($this->def_locale)->filterByActive(true)->withColumn('SProductsI18n.Name', 'Name')->select(['Id', 'Name'])->find()->toArray();
268
                break;
269 View Code Duplication
            case 'shop_category':
270
                $entity = SCategoryQuery::create()->setComment(__METHOD__)->joinWithI18n($this->def_locale)->withColumn('SCategoryI18n.Name', 'Name')->select(['Id', 'Name'])->find()->toArray();
271
                break;
272 View Code Duplication
            case 'brand':
273
                $entity = SBrandsQuery::create()->setComment(__METHOD__)->joinWithI18n($this->def_locale)->withColumn('SBrandsI18n.Name', 'Name')->select(['Id', 'Name'])->find()->toArray();
274
                break;
275
            case 'category':
276
                $entity = $this->db->select('id as Id')->select('name as Name')->get('category')->result_array();
277
                break;
278
            case 'page':
279
                $entity = $this->db->select('id as Id')->select('title as Name')->get('content')->result_array();
280
                break;
281
            case 'main':
282
                $entity = [
283
                           [
284
                            'Id'   => 0,
285
                            'Name' => lang('Main', 'banners'),
286
                           ],
287
                          ];
288
                break;
289
            default:
290
                break;
291
        }
292
293
        /** Show template with data */
294
        assetManager::create()
295
                ->setData('entity', $entity)
296
                ->render($this->input->post('tpl'), TRUE);
297
    }
298
299
    /**
300
     * Save banners positions
301
     * @access public
302
     * @author koloda90 <[email protected]>
303
     */
304
    public function save_positions() {
305
        if (!is_array($this->input->post('positions'))) {
306
            return;
307
        }
308
309
        foreach ($this->input->post('positions') as $key => $value) {
310
            $this->db->where('id = ' . $value)
311
                ->update('mod_banner', ['position' => $key]);
312
        }
313
314
        showMessage(lang('Positions saved', 'banners'));
315
    }
316
317
}
318
319
/* End of file admin.php */