Issues (314)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

class/Import.php (1 issue)

Severity
1
<?php
2
3
namespace XoopsModules\Modulebuilder;
4
5
use Xmf\Request;
6
7
/**
8
 * class Import
9
 */
10
class Import
11
{
12
    public static function importModule()
13
    {
14
        $ret = [];
15
        $moduleName    = Request::getString('moduleName',  'newModule', 'POST');
16
        $moduleNewName = Request::getString('moduleNewName',  $moduleName, 'POST');
17
        $moduleDirname = \preg_replace('/[^a-zA-Z0-9]\s+/', '', \mb_strtolower($moduleNewName));
18
        if ('' === $moduleDirname) {
19
            $ret['result'] = false;
20
            $ret['error'] = \_AM_MODULEBUILDER_ERROR_MNAME;
21
            return $ret;
22
        }
23
24
        $helper         = Helper::getInstance();
25
        $modulesHandler = $helper->getHandler('Modules');
26
        $newModuleObj   = $modulesHandler->create();
27
28
        $newModuleObj->setVar('mod_name', $moduleNewName);
29
        $newModuleObj->setVar('mod_release', date('Y-m-d'));
30
        $newModuleObj->setVar('mod_dirname', $moduleDirname);
31
32
        $newModuleObj->setVar('mod_version', $helper->getConfig('version')); //$GLOBALS['xoopsModuleConfig']['version']);
33
34
        $newModuleObj->setVar('mod_since', $helper->getConfig('since'));
35
        $newModuleObj->setVar('mod_min_php', $helper->getConfig('min_php'));
36
        $newModuleObj->setVar('mod_min_xoops', $helper->getConfig('min_xoops'));
37
        $newModuleObj->setVar('mod_min_admin', $helper->getConfig('min_admin'));
38
        $newModuleObj->setVar('mod_min_mysql', $helper->getConfig('min_mysql'));
39
40
        $newModuleObj->setVar('mod_description', $helper->getConfig('description'));
41
        $newModuleObj->setVar('mod_author', $helper->getConfig('author'));
42
        $newModuleObj->setVar('mod_author_mail', $helper->getConfig('author_email'));
43
        $newModuleObj->setVar('mod_author_website_url', $helper->getConfig('author_website_url'));
44
        $newModuleObj->setVar('mod_author_website_name', $helper->getConfig('author_website_name'));
45
        $newModuleObj->setVar('mod_credits', $helper->getConfig('credits'));
46
        $newModuleObj->setVar('mod_license', $helper->getConfig('license'));
47
        $newModuleObj->setVar('mod_display_admin', $helper->getConfig('display_admin'));
48
        $newModuleObj->setVar('mod_display_user', $helper->getConfig('display_user'));
49
        $newModuleObj->setVar('mod_active_search', $helper->getConfig('active_search'));
50
        $newModuleObj->setVar('mod_active_comments', $helper->getConfig('active_comments'));
51
        $newModuleObj->setVar('mod_release_info', $helper->getConfig('release_info'));
52
        $newModuleObj->setVar('mod_release_file', $helper->getConfig('release_file'));
53
        $newModuleObj->setVar('mod_manual', $helper->getConfig('manual'));
54
        $newModuleObj->setVar('mod_manual_file', $helper->getConfig('manual_file'));
55
        $newModuleObj->setVar('mod_image', 'empty.png');
56
        $newModuleObj->setVar('mod_demo_site_url', $helper->getConfig('demo_site_url'));
57
        $newModuleObj->setVar('mod_demo_site_name', $helper->getConfig('demo_site_name'));
58
        $newModuleObj->setVar('mod_support_url', $helper->getConfig('support_url'));
59
        $newModuleObj->setVar('mod_support_name', $helper->getConfig('support_name'));
60
        $newModuleObj->setVar('mod_website_url', $helper->getConfig('website_url'));
61
        $newModuleObj->setVar('mod_website_name', $helper->getConfig('website_name'));
62
        $newModuleObj->setVar('mod_status', $helper->getConfig('status'));
63
64
        $newModuleObj->setVar('mod_admin', $helper->getConfig('display_admin'));
65
        $newModuleObj->setVar('mod_user', $helper->getConfig('display_user'));
66
        $newModuleObj->setVar('mod_search', $helper->getConfig('active_search'));
67
        $newModuleObj->setVar('mod_comments', $helper->getConfig('active_comments'));
68
        $newModuleObj->setVar('mod_notifications', $helper->getConfig('active_notifications'));
69
        $newModuleObj->setVar('mod_permissions', $helper->getConfig('active_permissions'));
70
        $newModuleObj->setVar('mod_donations', $helper->getConfig('donations'));
71
        $newModuleObj->setVar('mod_subversion', $helper->getConfig('subversion'));
72
73
        if ($modulesHandler->insert($newModuleObj)) {
74
            // get the ID of the new module
75
            $criteria     = new \Criteria('mod_name', $moduleNewName);
76
            $moduleObject = $modulesHandler->getObjects($criteria, false, true);
77
            $moduleId     = $moduleObject[0]->getVar('mod_id');
78
            $tables = self::importTables($moduleId, $moduleName);
79
            if (false === $tables ) {
0 ignored issues
show
The condition false === $tables is always true.
Loading history...
80
                $ret['result'] = false;
81
                $ret['error'] = \_AM_MODULEBUILDER_ERROR_IMPTABLES;
82
            } else {
83
                $ret['result'] = true;
84
                $ret['tables'] = $tables;
85
            }
86
        } else {
87
            $ret['result'] = false;
88
            $ret['error'] = \_AM_MODULEBUILDER_ERROR_MCREATE . $GLOBALS['xoopsDB']->error();
89
        }
90
        return $ret;
91
    }
92
93
    /**
94
     * @param $moduleId
95
     * @param $moduleName
96
     */
97
    public static function importTables($moduleId, $moduleName)
98
    {
99
        $helper        = Helper::getInstance();
100
        $tablesHandler = $helper->getHandler('Tables');
101
        $fieldsHandler = $helper->getHandler('Fields');
102
103
        /** @var \XoopsModuleHandler $moduleHandler */
104
        $moduleHandler = xoops_getHandler('module');
105
        $module        = $moduleHandler->getByDirname($moduleName);
106
        $moduleTables  = $module->getInfo('tables');
107
108
        $tables = [];
109
110
        if (false !== $moduleTables && is_array($moduleTables)) {
111
            $currentTableNumber = 0;
112
            foreach ($moduleTables as $table) {
113
                //create a new tablesholder
114
                $newTable = $tablesHandler->create();
115
                $newTable->setVar('table_mid', $moduleId);
116
117
                $newTable->setVar('table_name', $table);
118
                $newTable->setVar('table_image', 'alert.png');
119
120
                //get all the fields for this table
121
                $importedFields = self::importFields($table);
122
123
                //set the number of fields for this table
124
                $countFields = count($importedFields);
125
                $newTable->setVar('table_nbfields', $countFields);
126
                $newTable->setVar('table_order', $currentTableNumber);
127
                $tablesHandler->insert($newTable);
128
129
                $currentFieldNumber = 0;
130
                foreach ($importedFields as $t) {
131
                    $fieldsObj = $fieldsHandler->create();
132
                    $fieldsObj->setVar('field_mid', $moduleId);
133
                    $fieldsObj->setVar('field_tid', $newTable->getVar('table_id'));
134
                    $fieldsObj->setVar('field_order', $currentFieldNumber);
135
                    $fieldsObj->setVar('field_name', $t['Field']);
136
137
138
                    $type = '1';
139
                    if (isset($t['Type'])) {
140
                        $types = [
141
                            2  => 'INT',
142
                            3  => 'TINYINT',
143
                            4  => 'MEDIUMINT',
144
                            5  => 'SMALLINT',
145
                            6  => 'FLOAT',
146
                            7  => 'DOUBLE',
147
                            8  => 'DECIMAL',
148
                            9  => 'SET',
149
                            10 => 'ENUM',
150
                            11 => 'EMAIL',
151
                            12 => 'URL',
152
                            13 => 'CHAR',
153
                            14 => 'VARCHAR',
154
                            15 => 'TEXT',
155
                            16 => 'TINYTEXT',
156
                            17 => 'MEDIUMTEXT',
157
                            18 => 'LONGTEXT',
158
                            19 => 'DATE',
159
                            20 => 'DATETIME',
160
                            21 => 'TIMESTAMP',
161
                            22 => 'TIME',
162
                            23 => 'YEAR',
163
                        ];
164
                        $type = array_search(strtolower($t['Type']), array_map('strtolower', $types));
165
                    }
166
                    $fieldsObj->setVar('field_type', $type);
167
                    $fieldsObj->setVar('field_value', $t['Len']);
168
169
                    $attr = '1';
170
                    if (isset($t['Signed'])) {
171
                        $attribs = [
172
                            2 => 'BINARY',
173
                            3 => 'UNSIGNED',
174
                            4 => 'UNSIGNED_ZEROFILL',
175
                            5 => 'SMALLINT',
176
                            6 => 'CURRENT_TIMESTAMP',
177
                        ];
178
                        $attr    = array_search(strtolower($t['Signed']), array_map('strtolower', $attribs));
179
                    }
180
                    $fieldsObj->setVar('field_attribute', $attr);
181
182
                    //                    $fieldsObj->setVar('field_null', $t['Null'] ?? '');
183
                    $null = '1';
184
                    if ('NOT NULL' === $t['Null']) {
185
                        $null = '2';
186
                    } elseif ('NULL' === $t['Null']) {
187
                        $null = '3';
188
                    }
189
                    $fieldsObj->setVar('field_null', $null);
190
                    $fieldsObj->setVar('field_default', $t['Default']);
191
192
                    $key  = 1;
193
                    if (isset($t['Key'])) {
194
                        $keys = [
195
                            2 => 'PRI',
196
                            3 => 'UNI',
197
                            4 => 'KEY',
198
                            5 => 'IND',
199
                            6 => 'FUL',
200
                        ];
201
                        $key = array_search(strtolower($t['Key']), array_map('strtolower', $keys));
202
                    }
203
                    $fieldsObj->setVar('field_key', $key);
204
                    $fieldsObj->setVar('field_element', $t['Field']);
205
206
                    if ($currentFieldNumber < $countFields - 1) {
207
                        //
208
                    }
209
210
                    if (0 == $currentFieldNumber) {
211
                        if (in_array($t['Type'], ['blob', 'text', 'mediumblob', 'mediumtext', 'longblob', 'longtext', 'enum', 'set',])) {
212
                            // XoopsFormTextArea
213
                            $fieldsObj->setVar('field_element', '3');
214
                        } elseif (in_array($t['Type'], ['int', 'integer', 'tinyint', 'smallint', 'mediumint', 'bigint', 'float', 'double', 'real', 'char', 'varchar',])) {
215
                            //XoopsFormText
216
                            $fieldsObj->setVar('field_element', '2');
217
                        } elseif ('datetime' === $t['Type']) {
218
                            //XoopsFormDateTime //XoopsFormDatePicker
219
                            $fieldsObj->setVar('field_element', '21');
220
                        } elseif ('date' === $t['Type']) {
221
                            //XoopsFormTextDateSelect
222
                            $fieldsObj->setVar('field_element', '15');
223
                        }
224
                    } elseif ($currentFieldNumber > 0) {
225
                            if (in_array($t['Type'], ['blob', 'text', 'mediumblob', 'mediumtext', 'longblob', 'longtext', 'enum', 'set',])) {
226
                                //XoopsFormTextArea
227
                                $fieldsObj->setVar('field_element', '3');
228
                            } elseif (in_array($t['Type'], ['int', 'integer', 'tinyint', 'smallint', 'mediumint', 'bigint', 'float', 'double', 'real', 'char', 'varchar',])) {
229
                                //XoopsFormText
230
                                $fieldsObj->setVar('field_element', '2');
231
                            } elseif ('datetime' === $t['Type']) {
232
                                //XoopsFormDateTime //XoopsFormDatePicker
233
                                $fieldsObj->setVar('field_element', '21');
234
                            } elseif ('date' === $t['Type']) {
235
                                //XoopsFormTextDateSelect
236
                                $fieldsObj->setVar('field_element', '15');
237
                            }
238
                    }
239
240
                    ++$currentFieldNumber;
241
242
                    $fieldsHandler->insert($fieldsObj);
243
                }
244
245
                $tables[] = \_AM_MODULEBUILDER_SUCCESS_IMPTABLES . $table;
246
247
                ++$currentTableNumber;
248
            }
249
        } else {
250
            return false;
251
        }
252
        return $tables;
253
    }
254
255
    /**
256
     * @param $tableName
257
     *
258
     * @return array
259
     */
260
    public static function importFields($tableName)
261
    {
262
        $table  = $GLOBALS['xoopsDB']->prefix((string)$tableName);
263
        $sql    = 'SHOW COLUMNS FROM ' . $table;
264
        $result = $GLOBALS['xoopsDB']->query($sql);
265
266
        if (!$result instanceof \mysqli_result) {
267
            \trigger_error($GLOBALS['xoopsDB']->error());
268
        }
269
270
        $tFields = [];
271
        while ($data = $GLOBALS['xoopsDB']->fetchBoth($result)) {
272
            $t          = [];
273
            $t['Field'] = $data['Field'];
274
            $t['Type']  = $data['Type'];
275
276
            if ('YES' === $data['Null']) {
277
                $t['Null'] = 'NULL';
278
            } else {
279
                $t['Null'] = 'NOT NULL';
280
            }
281
            $t['Key']     = $data['Key'];
282
            $t['Default'] = $data['Default'];
283
            $t['Extra']   = $data['Extra'];
284
285
            $t['Label'] = $data['Label'] ?? '';
286
287
            $h = strpos($data['Type'], '(');
288
            $i = strpos($data['Type'], ')');
289
            if (false === $h) {
290
                $t['Len'] = 0;
291
            } else {
292
                $t['Type'] = substr($data['Type'], 0, $h);
293
                if ('double' === $t['Type'] || 'float' === $t['Type'] || 'real' === $t['Type']) {
294
                    $t['Len'] = substr($data['Type'], $h + 1, $i - 1 - $h);
295
                } else {
296
                    $t['Len'] = (int)substr($data['Type'], $h + 1, $i - 1 - $h);
297
                }
298
                if (strlen($data['Type']) > $i) {
299
                    $t['Signed'] = substr($data['Type'], $i + 2);
300
                }
301
            }
302
303
            $tFields[$t['Field']] = $t;
304
        }
305
        return $tFields;
306
    }
307
}
308