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/libraries/SiteInfo.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
/**
4
 * Class works with site info
5
 *
6
 * @author kolia
7
 */
8
class SiteInfo
9
{
10
11
    /**
12
     * If TRUE then setting will be saved and getted for each locale
13
     * @var boolean
14
     */
15
    public $useLocales = TRUE;
16
17
    /**
18
     * For items witch are same for all locales
19
     * (only if $useLocales is TRUE)
20
     * @var array
21
     */
22
    protected $nonLocaleKeys = [
23
                                'siteinfo_logo',
24
                                'siteinfo_favicon',
25
                               ];
26
27
    /**
28
     * Current locale
29
     * @var string
30
     */
31
    public $locale;
32
33
    /**
34
     *
35
     * @var array
36
     */
37
    public $locales = [];
38
39
    /**
40
     *
41
     * @var array
42
     */
43
    protected $siteinfo;
44
45
    /**
46
     * Path to folder where images will be uploaded
47
     * ATTENTION! serves as url too!!!
48
     * @var string
49
     */
50
    public $imagesPath = '/uploads/images/';
51
52
    /**
53
     *
54
     * @var array
55
     */
56
    public static $siteInfoObject;
57
58
    /**
59
     * Setting class variables
60
     * @param string $locale locale to intiate class with
61
     */
62
    public function __construct($locale = NULL) {
63
        if ($this->useLocales === TRUE) {
64
            $this->locale = $locale !== null ? $locale : MY_Controller::getCurrentLocale();
65
        }
66
67
        if (!self::$siteInfoObject) {
68
            $locales_ = CI::$APP->cms_base->get_langs();
69
70
            foreach ($locales_ as $row) {
71
                $this->locales[$row['id']] = $row['identif'];
72
            }
73
74
            // getting data from DB
75
            $result = CI::$APP->db->select('siteinfo')->get('settings')->row_array();
76
            self::$siteInfoObject = unserialize($result['siteinfo']);
77
            if (is_array(self::$siteInfoObject)) {
78
                $this->siteinfo = self::$siteInfoObject;
79
            }
80
        } else {
81
            $this->siteinfo = self::$siteInfoObject;
82
        }
83
    }
84
85
    /**
86
     * Sets all params in one array (mostly on saving)
87
     * @param array $siteInfo
88
     */
89
    public function setSiteInfoData(array $siteInfo) {
90
91
        $languages = CI::$APP->db->get('languages')->result_array();
92
93
        if ($this->useLocales === TRUE) {
94
            if (!array_key_exists($this->locale, $this->siteinfo)) {
95
                $this->siteinfo[$this->locale] = [];
96
            }
97
            foreach ($siteInfo as $key => $value) {
98
                if (in_array($key, $this->nonLocaleKeys)) {
99
                    $this->siteinfo[$key] = $value;
100
                } else {
101
                    foreach ($languages as $lang) {
102
                        if ($lang['identif'] === $this->locale) {
103
                            $this->siteinfo[$this->locale][$key] = $value;
104
                        } elseif ($key == 'contacts') {
105
                            $this->contactsKeys($key, $lang);
106
                        }
107
                    }
108
                }
109
            }
110
        } else {
111
            $this->siteinfo = $siteInfo;
112
        }
113
    }
114
115
    /**
116
     * @param string $key
117
     * @param string $lang
118
     */
119
    private function contactsKeys($key, $lang) {
120
        $siteinfoAll = $this->getSiteInfoData(FALSE);
121
        $locale = MY_Controller::getCurrentLocale();
122
        $keysMain = [];
123
124
        foreach ($siteinfoAll[$locale][$key] as $name => $contacts) {
125
            $contacts = $contacts;
126
            $keysMain[] = $name;
127
        }
128
129
        foreach ($keysMain as $contacts) {
130
            if (isset($siteinfoAll[$locale][$key][$contacts])) {
131
                $this->siteinfo[$lang['identif']][$key][$contacts] = $siteinfoAll[$lang['identif']][$key][$contacts];
132
            } else {
133
                $this->siteinfo[$lang['identif']][$key][$contacts] = '';
134
            }
135
        }
136
137
        foreach ($this->siteinfo as $language => $datas) {
138
            foreach ($datas['contacts'] as $k => $data) {
139
                $data = $data;
140
                if (!in_array($k, $keysMain)) {
141
                    unset($this->siteinfo[$language][$key][$k]);
142
                }
143
            }
144
        }
145
    }
146
147
    /**
148
     * Saving data in DB
149
     */
150
    public function save() {
151
        $this->normalizeData();
152
        $siteinfo = $this->getSiteInfoData(FALSE);
153
        $string = serialize($siteinfo);
154
        return CI::$APP->db->update('settings', ['siteinfo' => $string]);
155
    }
156
157
    /**
158
     * Setting one value of site informations
159
     * @param string $key
160
     * @param string $value
161
     * @param boolean $contacts (optional, default false) true if value need to be setted in contacts
162
     * @return bool
163
     */
164
    public function setSiteInfoValue($key, $value, $contacts = FALSE) {
165
        if (0 !== strpos($key, 'siteinfo_')) {
166
            $key = 'siteinfo_' . $key;
167
        }
168
169
        if ($this->useLocales != TRUE || in_array($key, $this->nonLocaleKeys)) {
170
            if ($contacts == TRUE) {
171
                $this->siteinfo['contacts'][$key] = $value;
172
                return TRUE;
173
            } else {
174
                if (array_key_exists($key, $this->siteinfo)) {
175
                    $this->siteinfo[$key] = $value;
176
                    return TRUE;
177
                }
178
            }
179
        } else {
180
            if ($contacts == TRUE) {
181
                $this->siteinfo[$this->locale]['contacts'][$key] = $value;
182
                return TRUE;
183
            } else {
184
                if (array_key_exists($key, $this->siteinfo[$this->locale])) {
185
                    $this->siteinfo[$this->locale][$key] = $value;
186
                    return TRUE;
187
                }
188
            }
189
        }
190
        return false;
191
    }
192
193
    /**
194
     * @param string $key
195
     * @param bool|FALSE $contacts
196
     */
197
    public function deleteSiteInfoValue($key, $contacts = FALSE) {
198
        if (0 !== strpos($key, 'siteinfo_')) {
199
            $key = 'siteinfo_' . $key;
200
        }
201
        if ($this->useLocales != TRUE || in_array($key, $this->nonLocaleKeys)) {
202
            if ($contacts == TRUE) {
203
                unset($this->siteinfo['contacts'][$key]);
204
            } else {
205
                unset($this->siteinfo[$key]);
206
            }
207
        } else {
208
            if ($contacts == TRUE) {
209
                unset($this->siteinfo[$this->locale]['contacts'][$key]);
210
            } else {
211
                unset($this->siteinfo[$this->locale][$key]);
212
            }
213
        }
214
    }
215
216
    /**
217
     * Returns all params in one array (for serialize)
218
     * @param boolean $byLocale if true then will be returned data by locale, else all dataS
219
     * @return array
220
     */
221
    public function getSiteInfoData($byLocale = FALSE) {
222
        if ($this->useLocales == TRUE & $byLocale !== FALSE) {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: ($this->useLocales == TRUE) & $byLocale !== FALSE, Probably Intended Meaning: $this->useLocales == (TRUE & $byLocale !== FALSE)

When comparing the result of a bit operation, we suggest to add explicit parenthesis and not to rely on PHP’s built-in operator precedence to ensure the code behaves as intended and to make it more readable.

Let’s take a look at these examples:

// Returns always int(0).
return 0 === $foo & 4;
return (0 === $foo) & 4;

// More likely intended return: true/false
return 0 === ($foo & 4);
Loading history...
223
            if (is_string($byLocale) & in_array($byLocale, $this->locales)) {
224
                $locale = $byLocale;
225
            } else {
226
                $locale = $this->locale;
227
            }
228
            if (array_key_exists($locale, $this->siteinfo)) {
229
                $returnArray = $this->siteinfo[$locale];
230
231
                $defaultContacts = $this->siteinfo[MY_Controller::defaultLocale()]['contacts'];
232
                foreach ($defaultContacts as $contactKey => $contactValue) {
233
                    if (!$returnArray['contacts'][$contactKey]) {
234
                        $returnArray['contacts'][$contactKey] = '';
235
                    }
236
                }
237
238
                foreach ($this->siteinfo as $key => $value) {
239
                    if (in_array($key, $this->nonLocaleKeys)) {
240
                        $returnArray[$key] = $value;
241
                    }
242
                }
243
                return $returnArray;
244
            }
245
        }
246
247
        return $this->siteinfo;
248
    }
249
250
    /**
251
     * Returns siteinfo item by param
252
     * @param string $name name of param
253
     * @return string
254
     */
255
    public function getSiteInfo($name = NULL) {
256
        // simple checks just in case
257
        if (!is_string($name)) {
258
            return '';
259
        }
260
        if (!(strlen($name) > 0)) {
261
            return '';
262
        }
263
        if (!is_array($this->siteinfo)) {
264
            return '';
265
        }
266
267
        if ($this->useLocales == TRUE) {
268
            // if it is non locale field
269
            if (array_key_exists($name, $this->siteinfo)) {
270
                return $this->siteinfo[$name];
271
            } elseif (isset($this->siteinfo['contacts'])) {
272
                $nameTemp = str_replace('siteinfo_', '', $name);
273
                if (array_key_exists($nameTemp, $this->siteinfo['contacts'])) {
274
                    return $this->siteinfo['contacts'][$nameTemp];
275
                }
276
            }
277
            if (array_key_exists($this->locale, $this->siteinfo)) {
278
                $siteinfo = $this->siteinfo[$this->locale];
279
            } else {
280
                return '';
281
            }
282
        } else {
283
            $siteinfo = $this->siteinfo;
284
        }
285
286
        // if key exists value will be returned
287
        if (array_key_exists($name, $siteinfo)) {
288
            return $siteinfo[$name];
289
        }
290
291
        $name = str_replace('siteinfo_', '', $name);
292
        if (array_key_exists($name, $siteinfo['contacts'])) {
293
            return $siteinfo['contacts'][$name];
294
        }
295
296
        return '';
297
    }
298
299
    /**
300
     * Changing array structure relatively to that locales are use or not
301
     */
302
    public function normalizeData() {
303
        if ($this->useLocales == TRUE) {
304
            // deleting non locale fields from data array (except those what are present $this->nonLocaleKeys)
305
            foreach ($this->siteinfo as $key => $value) {
306
                if (!in_array($key, $this->locales) & !in_array($key, $this->nonLocaleKeys)) {
307
                    unset($this->siteinfo[$key]);
308
                }
309
            }
310
            // deleting non-locale fields from each locale data
311
            foreach ($this->siteinfo as $locale => $localeData) {
312
                foreach ($localeData as $key => $value) {
313
                    if (in_array($key, $this->nonLocaleKeys)) {
314
                        unset($this->siteinfo[$locale][$key]);
315
                    }
316
                }
317
            }
318
        } else {
319
            // deleting locales data
320
            foreach ($this->siteinfo as $key => $value) {
321
                if (in_array($key, $this->locales)) {
322
                    unset($this->siteinfo[$key]);
323
                }
324
            }
325
        }
326
    }
327
328
}