Issues (277)

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.

admin/account.php (8 issues)

1
<?php declare(strict_types=1);
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
*/
12
13
/**
14
 * wgEvents module for xoops
15
 *
16
 * @copyright    2021 XOOPS Project (https://xoops.org)
17
 * @license      GPL 2.0 or later
18
 * @package      wgevents
19
 * @author       Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Wgevents;
24
use XoopsModules\Wgevents\Constants;
25
use XoopsModules\Wgevents\Common;
26
27
require __DIR__ . '/header.php';
28
// Get all request values
29
$op    = Request::getCmd('op', 'list');
30
$accId = Request::getInt('id');
31
$save_and_check = Request::getString('save_and_check', 'none');
32
$start = Request::getInt('start');
33
$limit = Request::getInt('limit', $helper->getConfig('adminpager'));
34
$GLOBALS['xoopsTpl']->assign('start', $start);
35
$GLOBALS['xoopsTpl']->assign('limit', $limit);
36
37
$moduleDirName = \basename(\dirname(__DIR__));
38
39
$GLOBALS['xoopsTpl']->assign('mod_url', XOOPS_URL . '/modules/' . $moduleDirName);
40
41
switch ($op) {
42
    case 'check_account':
43
        $imgFailed = WGEVENTS_ICONS_URL_16 . '/0.png';
44
        $imgOK = WGEVENTS_ICONS_URL_16 . '/1.png';
45
        $GLOBALS['xoTheme']->addStylesheet($style, null);
46
        $templateMain = 'wgevents_admin_account.tpl';
47
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('account.php'));
48
        $adminObject->addItemButton(\_AM_WGEVENTS_LIST_ACCOUNTS, 'account.php?op=list');
49
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
50
51
        $GLOBALS['xoopsTpl']->assign('account_check', true);
52
53
        if (0 === $accId) {
54
            redirect_header('account.php', 3, _MA_WGEVENTS_INVALID_PARAM);
55
        } else {
56
            $accountObj = $helper->getHandler('Account')->get($accId);
57
            if (!\is_object($accountObj)) {
58
                redirect_header('account.php', 3, _MA_WGEVENTS_INVALID_PARAM);
59
            }
60
        }
61
62
        $account_server_in = $accountObj->getVar('server_in');
63
        $account_port_in   = $accountObj->getVar('port_in');
64
        $account_type      = $accountObj->getVar('type');
65
        $logDetails = 'account_type:' . $account_type;
66
        switch ($account_type) {
67
            case Constants::ACCOUNT_TYPE_VAL_POP3:
68
                $service = 'pop3';
69
                break;
70
            case Constants::ACCOUNT_TYPE_VAL_SMTP:
71
            case Constants::ACCOUNT_TYPE_VAL_GMAIL:
72
                $service = 'imap';
73
                break;
74
            case 'default':
75
            default:
76
                $service = '';
77
                break;
78
        }
79
        $account_securetype_in = $accountObj->getVar('securetype_in');
80
        $account_password      = $accountObj->getVar('password');
81
        $account_username      = $accountObj->getVar('username');
82
83
        $command = $account_server_in . ':' . $account_port_in;
84
        if ('' !== $service) {
85
            $command .= '/' . $service;
86
        }
87
        if ('' !== $account_securetype_in) {
88
            $command .= '/' . $account_securetype_in;
89
        }
90
        $logDetails .= '<br>command:' . $command;
91
92
        $checks = [];
93
94
        $mbox = @imap_open('{' . $command . '}', $account_username, $account_password);
95
        $checks['openmailbox']['check'] = \_AM_WGEVENTS_ACCOUNT_CHECK_OPEN_MAILBOX;
96
        if (false === $mbox) {
97
            $checks['openmailbox']['result'] = \_AM_WGEVENTS_ACCOUNT_CHECK_FAILED;
98
            $checks['openmailbox']['result_img'] = $imgFailed;
99
            $checks['openmailbox']['info'] = \imap_last_error();
100
        } else {
101
            $checks['openmailbox']['result'] = \_AM_WGEVENTS_ACCOUNT_CHECK_OK;
102
            $checks['openmailbox']['result_img'] = $imgOK;
103
104
            $folders = \imap_list($mbox, '{' . $command . '}', '*');
105
            $checks['listfolder']['check'] = \_AM_WGEVENTS_ACCOUNT_CHECK_LIST_FOLDERS;
106
            if (false === $folders) {
107
                $checks['listfolder']['result'] = \_AM_WGEVENTS_ACCOUNT_CHECK_FAILED;
108
                $checks['listfolder']['result_img'] = $imgFailed;
109
                $checks['listfolder']['info'] = \imap_last_error();
110
            } else {
111
                $checks['listfolder']['result'] = \_AM_WGEVENTS_ACCOUNT_CHECK_OK;
112
                $checks['listfolder']['result_img'] = $imgOK;
113
                $checks['listfolder']['info'] = \implode('<br>', $folders);
114
115
                // send test mail
116
                // read data of account
117
                $account_yourname       = $accountObj->getVar('yourname');
118
                $account_yourmail       = $accountObj->getVar('yourmail');
119
                $account_server_out     = $accountObj->getVar('server_out');
120
                $account_port_out       = $accountObj->getVar('port_out');
121
                $account_securetype_out = $accountObj->getVar('securetype_out');
122
123
                try {
124
                    if ($account_type == Constants::ACCOUNT_TYPE_VAL_PHP_SENDMAIL) {
125
                        $pop = new POP3();
126
                        $pop->authorise($account_server_out, $account_port_out, 30, $account_username, $account_password, 1);
127
                    }
128
                    $xoopsMailer = xoops_getMailer();
129
                    $logDetails .= '<br>xoopsMailer is_object:' . \is_object($xoopsMailer);
130
131
                    //$xoopsMailer->useMail();
132
133
                    $xoopsMailer->CharSet = _CHARSET; //use xoops default character set
0 ignored issues
show
Bug Best Practice introduced by
The property CharSet does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
134
135
                    //if (Constants::ACCOUNT_TYPE_VAL_PHP_SENDMAIL == $account_type) {
136
                        //$xoopsMailer->IsSendmail();  Fix Error
137
                    //}
138
139
                    $xoopsMailer->Username = $account_username; // SMTP account username
0 ignored issues
show
The property Username does not seem to exist on XoopsMailerLocal.
Loading history...
The property Username does not seem to exist on XoopsMailer.
Loading history...
140
                    $logDetails .= '<br>account_username:' . $account_username;
141
                    $xoopsMailer->Password = $account_password; // SMTP account password
0 ignored issues
show
The property Password does not seem to exist on XoopsMailerLocal.
Loading history...
The property Password does not seem to exist on XoopsMailer.
Loading history...
142
                    $logDetails .= '<br>account_password:' . $account_password;
143
144
                    if (Constants::ACCOUNT_TYPE_VAL_POP3 == $account_type) {
145
                        //xoopsMailer->isSMTP();
146
                        //$xoopsMailer->SMTPDebug = 2;
147
                        $xoopsMailer->Host = $account_server_out;
0 ignored issues
show
The property Host does not seem to exist on XoopsMailerLocal.
Loading history...
The property Host does not seem to exist on XoopsMailer.
Loading history...
148
                    }
149
150
                    if (Constants::ACCOUNT_TYPE_VAL_SMTP == $account_type
151
                        || Constants::ACCOUNT_TYPE_VAL_GMAIL == $account_type) {
152
153
                        $xoopsMailer->multimailer->isSMTP();
154
                        $xoopsMailer->multimailer->Port       = $account_port_out; // set the SMTP port
155
                        $xoopsMailer->multimailer->Host       = $account_server_out; //sometimes necessary to repeat
156
                        $xoopsMailer->multimailer->SMTPAuth   = true;
157
                        $xoopsMailer->multimailer->SMTPSecure = $account_securetype_out;
158
                        $xoopsMailer->multimailer->Username   = $account_username; // SMTP account username
159
                        $xoopsMailer->multimailer->Password   = $account_password; // SMTP account password
160
                        $xoopsMailer->multimailer->SMTPDebug  = 4;
161
                        /*
162
                        $xoopsMailer->Port = $account_port_out; // set the SMTP port
163
                        $logDetails .= '<br>account_port_out:' . $account_port_out;
164
                        $xoopsMailer->Host = $account_server_out; //sometimes necessary to repeat
165
                        $logDetails .= '<br>account_server_out:' . $account_server_out;*/
166
                    }
167
                    /* old version:
168
                    if ('' != $account_securetype_out) {
169
                        $xoopsMailer->SMTPAuth   = true;
170
                        $xoopsMailer->SMTPSecure = $account_securetype_out; // sets the prefix to the server
171
                        $logDetails .= '<br>account_securetype_out:' . $account_securetype_out;
172
                    }
173
                    */
174
                    $xoopsMailer->setFromEmail($account_yourmail);
175
                    $xoopsMailer->setFromName($account_yourname);
176
                    $logDetails .= '<br>from:' . $account_yourmail . ' ' . $account_yourname;
177
                    $xoopsMailer->setSubject('Test account');
178
                    $xoopsMailer->setBody('This is a mail for testing account on: ' . \XOOPS_URL);
179
                    $usermail = $GLOBALS['xoopsUser']->email();
180
                    $xoopsMailer->setToEmails($usermail);
181
                    $logDetails .= '<br>setToEmails:' . $usermail;
182
                    $logHandler->createLog($logDetails);
183
184
                    //execute sending
185
                    $export = \var_export($xoopsMailer, TRUE);
186
                    $export = \preg_replace("/\n/", '<br>', $export);
187
                    if ($xoopsMailer->send()) {
188
                        $logHandler->createLog('Result Test send mail to ' . $usermail .': success' . '<br>' . $export);
189
                        $result = \_AM_WGEVENTS_ACCOUNT_CHECK_OK . '<br>' . $xoopsMailer->getErrors();
190
                        $resultImg = $imgOK;
191
                    } else {
192
                        $logHandler->createLog('Result Test send mail to ' . $usermail .': failed - ' . $xoopsMailer->getErrors() . '<br>' . $export);
193
                        $result = \_AM_WGEVENTS_ACCOUNT_CHECK_FAILED . '<br>' . $xoopsMailer->getErrors();
194
                        $resultImg = $imgFailed;
195
                    }
196
                    unset($mail);
197
                }
198
                catch (phpmailerException $e) {
199
                    // IN PROGRESS
200
                    $logHandler->createLog(\_AM_WGEVENTS_ACCOUNT_CHECK_FAILED. 'Result Test account: phpmailerException -' . $e->errorMessage());
201
                    $result = \_AM_WGEVENTS_ACCOUNT_CHECK_FAILED . '<br>' . imap_last_error() . $e->errorMessage();
202
                    $resultImg = $imgFailed;
203
                }
204
                catch (\Exception $e) {
205
                    // IN PROGRESS
206
                    $logHandler->createLog(\_AM_WGEVENTS_ACCOUNT_CHECK_FAILED. 'Result Test account: Exception -' . $e->getMessage());
207
                    $result = \_AM_WGEVENTS_ACCOUNT_CHECK_FAILED . '<br>' . imap_last_error() . $e->getMessage();
208
                    $resultImg = $imgFailed;
209
                }
210
211
                $checks['sendtest']['check'] = _AM_WGEVENTS_ACCOUNT_CHECK_SENDTEST;
212
                $checks['sendtest']['result'] = $result;
213
                $checks['sendtest']['result_img'] = $resultImg;
214
                $checks['sendtest']['info'] = $result;
215
            }
216
            @imap_close($mbox);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for imap_close(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

216
            /** @scrutinizer ignore-unhandled */ @imap_close($mbox);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
217
        }
218
        $GLOBALS['xoopsTpl']->assign('checks', $checks);
219
        break;
220
    case 'list':
221
    default:
222
        $crAccount = new \CriteriaCompo();
223
        $crAccount->add(new \Criteria('primary', 1));
224
        $accountsCount = $accountHandler->getCount($crAccount);
225
        if (0 === $accountsCount) {
226
            $GLOBALS['xoopsTpl']->assign('info', \_AM_WGEVENTS_THEREARENT_ACCOUNTS_DESC);
227
        }
228
        // Define Stylesheet
229
        $GLOBALS['xoTheme']->addStylesheet($style, null);
230
        $templateMain = 'wgevents_admin_account.tpl';
231
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('account.php'));
232
        $adminObject->addItemButton(\_AM_WGEVENTS_ADD_ACCOUNT, 'account.php?op=new');
233
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
234
        $accountCount = $accountHandler->getCountAccounts();
235
        $GLOBALS['xoopsTpl']->assign('accountCount', $accountCount);
236
        $GLOBALS['xoopsTpl']->assign('wgevents_url', \WGEVENTS_URL);
237
        $GLOBALS['xoopsTpl']->assign('wgevents_icons_url_16', \WGEVENTS_ICONS_URL_16);
238
        $GLOBALS['xoopsTpl']->assign('wgevents_upload_url', \WGEVENTS_UPLOAD_URL);
239
        // Table view accounts
240
        if ($accountCount > 0) {
241
            $accountAll = $accountHandler->getAllAccounts();
242
            foreach (\array_keys($accountAll) as $i) {
243
                $account = $accountAll[$i]->getValuesAccount();
244
                if (Constants::ACCOUNT_TYPE_VAL_PHP_MAIL != $account['type']
245
                    && Constants::ACCOUNT_TYPE_VAL_PHP_SENDMAIL != $account['type']) {
246
                    $account['show_check'] = true;
247
                }
248
                $GLOBALS['xoopsTpl']->append('accounts_list', $account);
249
                unset($account);
250
            }
251
        }
252
        break;
253
    case 'new':
254
        $templateMain = 'wgevents_admin_account.tpl';
255
        $GLOBALS['xoTheme']->addScript(\WGEVENTS_URL . '/assets/js/forms_admin.js');
256
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('account.php'));
257
        $adminObject->addItemButton(\_AM_WGEVENTS_LIST_ACCOUNTS, 'account.php', 'list');
258
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
259
        // Form Create
260
        $accountObj = $accountHandler->create();
261
        $form = $accountObj->getForm();
262
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
263
        break;
264
    case 'save':
265
        // Security Check
266
        if (!$GLOBALS['xoopsSecurity']->check()) {
267
            \redirect_header('account.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
268
        }
269
        if ($accId > 0) {
270
            $accountObj = $accountHandler->get($accId);
271
        } else {
272
            $accountObj = $accountHandler->create();
273
        }
274
        $crAccount = new \CriteriaCompo();
275
        $crAccount->add(new \Criteria('primary', 1));
276
        if ($accId > 0) {
277
            $crAccount->add(new \Criteria('id', $accId, '<>'));
278
        }
279
        $accPrimaryCount = $accountHandler->getCount($crAccount);
280
        unset($crAccount);
281
        // Set Vars
282
        $accountObj->setVar('type', Request::getInt('type'));
283
        $accountObj->setVar('name', Request::getString('name'));
284
        $accountObj->setVar('yourname', Request::getString('yourname'));
285
        $accountObj->setVar('yourmail', Request::getString('yourmail'));
286
        $accountObj->setVar('username', Request::getString('username'));
287
        $accountObj->setVar('password', Request::getString('password'));
288
        $accountObj->setVar('server_in', Request::getString('server_in'));
289
        $accountObj->setVar('port_in', Request::getInt('port_in'));
290
        $accountObj->setVar('securetype_in', Request::getString('securetype_in'));
291
        $accountObj->setVar('server_out', Request::getString('server_out'));
292
        $accountObj->setVar('port_out', Request::getInt('port_out'));
293
        $accountObj->setVar('securetype_out', Request::getString('securetype_out'));
294
        $accPrimary = Request::getInt('primary');
295
        if ($accPrimary > 0 && $accPrimaryCount > 0) {
296
            $crAccount = new \CriteriaCompo();
297
            $crAccount->add(new \Criteria('primary', 1));
298
            $accountHandler->updateAll('primary', 0, $crAccount,true);
299
        }
300
        $accountObj->setVar('primary', Request::getInt('primary'));
301
        $accountObj->setVar('limit_hour', Request::getInt('limit_hour'));
302
        $accountObj->setVar('datecreated', Request::getInt('datecreated'));
303
        $accountObj->setVar('submitter', Request::getInt('submitter'));
304
        // Insert Data
305
        if ($accountHandler->insert($accountObj)) {
306
            $newAccId = $accId > 0 ? $accId : $accountObj->getNewInsertedId();
307
            if ('none' === $save_and_check) {
308
                redirect_header('?op=list&amp;start=' . $start . '&amp;limit=' . $limit, 3, _MA_WGEVENTS_FORM_OK);
309
            } else {
310
                redirect_header('account.php?op=check_account&id=' . $newAccId . '&amp;start=' . $start . '&amp;limit=' . $limit, 3, _MA_WGEVENTS_FORM_OK);
311
            }
312
        }
313
        // Get Form
314
        $GLOBALS['xoopsTpl']->assign('error', $accountObj->getHtmlErrors());
315
        $form = $accountObj->getForm();
316
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
317
        break;
318
    case 'edit':
319
        $templateMain = 'wgevents_admin_account.tpl';
320
        $GLOBALS['xoTheme']->addScript(\WGEVENTS_URL . '/assets/js/forms_admin.js');
321
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('account.php'));
322
        $adminObject->addItemButton(\_AM_WGEVENTS_ADD_ACCOUNT, 'account.php?op=new');
323
        $adminObject->addItemButton(\_AM_WGEVENTS_LIST_ACCOUNTS, 'account.php', 'list');
324
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
325
        // Get Form
326
        $accountObj = $accountHandler->get($accId);
327
        $accountObj->start = $start;
328
        $accountObj->limit = $limit;
329
        $form = $accountObj->getForm();
330
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
331
        break;
332
    case 'delete':
333
        $templateMain = 'wgevents_admin_account.tpl';
334
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('account.php'));
335
        $accountObj = $accountHandler->get($accId);
336
        $accType = $accountObj->getVar('type');
337
        if (isset($_REQUEST['ok']) && 1 === (int)$_REQUEST['ok']) {
338
            if (!$GLOBALS['xoopsSecurity']->check()) {
339
                \redirect_header('account.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
340
            }
341
            if ($accountHandler->delete($accountObj)) {
342
                \redirect_header('account.php', 3, \_MA_WGEVENTS_FORM_DELETE_OK);
343
            } else {
344
                $GLOBALS['xoopsTpl']->assign('error', $accountObj->getHtmlErrors());
345
            }
346
        } else {
347
            $customConfirm = new Common\Confirm(
348
                ['ok' => 1, 'id' => $accId, 'start' => $start, 'limit' => $limit, 'op' => 'delete'],
349
                $_SERVER['REQUEST_URI'],
350
                \sprintf(\_MA_WGEVENTS_FORM_SURE_DELETE, $accountObj->getVar('name')));
351
            $form = $customConfirm->getFormConfirm();
352
            $GLOBALS['xoopsTpl']->assign('form', $form->render());
353
        }
354
        break;
355
    case 'change_yn':
356
        if ($accId > 0) {
357
            if (Request::getInt('value') > 0) {
358
                // reset all to false
359
                $crAccount = new \CriteriaCompo();
360
                $crAccount->add(new \Criteria('primary', 1));
361
                $accountHandler->updateAll('primary', 0, $crAccount,true);
362
            }
363
            $accountObj = $accountHandler->get($accId);
364
            $accountObj->setVar(Request::getString('field'), Request::getInt('value'));
365
            // Insert Data
366
            if ($accountHandler->insert($accountObj, true)) {
367
                \redirect_header('account.php?op=list&amp;start=' . $start . '&amp;limit=' . $limit, 2, \_MA_WGEVENTS_FORM_OK);
368
            }
369
        }
370
        break;
371
}
372
require __DIR__ . '/footer.php';
373