Issues (134)

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/MessageHandler.php (1 issue)

1
<?php
2
3
namespace XoopsModules\Xfguestbook;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @package
19
 * @since
20
 * @author       XOOPS Development Team
21
 */
22
23
/**
24
 * Class MessageHandler
25
 */
26
class MessageHandler extends \XoopsPersistableObjectHandler
27
{
28
    /** @var \XoopsMySQLDatabase $db */
29
    public $db;
30
31
    /**
32
     * MessageHandler constructor.
33
     * @param \XoopsDatabase|null $db
34
     */
35
    public function __construct(\XoopsDatabase $db = null)
36
    {
37
        $this->db = $db;
38
    }
39
40
    /**
41
     * @param bool $isNew
42
     * @return Message
43
     */
44
    public function create($isNew = true)
45
    {
46
        return new Message();
47
    }
48
49
    /**
50
     * @param int|null $id
51
     * @param null     $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
52
     * @return bool|string
53
     */
54
    public function get($id = null, $fields = null)
55
    {
56
        $id = (int)$id;
57
        if ($id > 0) {
58
            $sql = 'SELECT * FROM ' . $this->db->prefix('xfguestbook_msg') . ' WHERE msg_id=' . $id;
59
            if (!$result = $this->db->query($sql)) {
60
                return false;
61
            }
62
            $numrows = $this->db->getRowsNum($result);
63
            if (1 == $numrows) {
64
                $msg = new Message();
65
                $msg->assignVars($this->db->fetchArray($result));
66
67
                return $msg;
68
            }
69
        }
70
71
        return false;
72
    }
73
74
    /**
75
     * @param \XoopsObject $msg
76
     * @param bool         $force
77
     * @return bool
78
     */
79
    public function insert(\XoopsObject $msg, $force = true)
80
    {
81
        if (Message::class !== \get_class($msg)) {
82
            return false;
83
        }
84
        if (!$msg->cleanVars()) {
85
            return false;
86
        }
87
        foreach ($msg->cleanVars as $k => $v) {
88
            ${$k} = $v;
89
        }
90
        if (empty($msg_id)) {
91
            $msg_id = $this->db->genId('xfguestbook_msg_msg_id_seq');
92
            $sql    = 'INSERT INTO '
93
                      . $this->db->prefix('xfguestbook_msg')
94
                      . ' (msg_id, user_id, uname, title, message, note, post_time, email, url, poster_ip, moderate, gender, country, photo, flagdir, other) VALUES ('
95
                      . $msg_id
96
                      . ','
97
                      . $user_id
98
                      . ', '
99
                      . $this->db->quoteString($uname)
100
                      . ', '
101
                      . $this->db->quoteString($title)
102
                      . ', '
103
                      . $this->db->quoteString($message)
104
                      . ', '
105
                      . $this->db->quoteString($note)
106
                      . ', '
107
                      . $post_time
108
                      . ',  '
109
                      . $this->db->quoteString($email)
110
                      . ', '
111
                      . $this->db->quoteString($url)
112
                      . ', '
113
                      . $this->db->quoteString($poster_ip)
114
                      . ', '
115
                      . $moderate
116
                      . ', '
117
                      . $this->db->quoteString($gender)
118
                      . ', '
119
                      . $this->db->quoteString($country)
120
                      . ', '
121
                      . $this->db->quoteString($photo)
122
                      . ', '
123
                      . $this->db->quoteString($flagdir)
124
                      . ', '
125
                      . $this->db->quoteString($other)
126
                      . ')';
127
        } else {
128
            $sql = 'UPDATE '
129
                   . $this->db->prefix('xfguestbook_msg')
130
                   . ' SET user_id='
131
                   . $user_id
132
                   . ', uname='
133
                   . $this->db->quoteString($uname)
134
                   . ', title='
135
                   . $this->db->quoteString($title)
136
                   . ', message='
137
                   . $this->db->quoteString($message)
138
                   . ', note='
139
                   . $this->db->quoteString($note)
140
                   . ', email='
141
                   . $this->db->quoteString($email)
142
                   . ', url='
143
                   . $this->db->quoteString($url)
144
                   . ', moderate='
145
                   . $moderate
146
                   . ', gender='
147
                   . $this->db->quoteString($gender)
148
                   . ', country='
149
                   . $this->db->quoteString($country)
150
                   . ', photo='
151
                   . $this->db->quoteString($photo)
152
                   . ', flagdir='
153
                   . $this->db->quoteString($flagdir)
154
                   . ', other='
155
                   . $this->db->quoteString($other)
156
                   . ' WHERE msg_id='
157
                   . $msg_id;
158
        }
159
        if (!$result = $this->db->queryF($sql)) {
160
            return false;
161
        }
162
        if (empty($msg_id)) {
163
            $msg_id = $this->db->getInsertId();
164
        }
165
        $msg->assignVar('msg_id', $msg_id);
166
167
        return $msg_id;
168
    }
169
170
    /**
171
     * @param \XoopsObject $msg
172
     * @param bool         $force
173
     * @return bool
174
     */
175
    public function delete(\XoopsObject $msg, $force = false)
176
    {
177
        global $xoopsModule;
178
        if (Message::class !== \get_class($msg)) {
179
            return false;
180
        }
181
        $sql = \sprintf('DELETE FROM `%s` WHERE msg_id = %u', $this->db->prefix('xfguestbook_msg'), $msg->getVar('msg_id'));
182
        if (isset($this->commentstable) && '' !== $this->commentstable) {
183
            \xoops_comment_delete($xoopsModule->getVar('mid'), $msg_id);
184
        }
185
186
        if (!$result = $this->db->query($sql)) {
187
            return false;
188
        }
189
190
        return true;
191
    }
192
193
    /**
194
     * @param null|\CriteriaElement|\CriteriaCompo $criteria
195
     * @param bool                                 $id_as_key
196
     * @param bool                                 $as_object
197
     * @return array
198
     */
199
    public function &getObjects(\CriteriaElement $criteria = null, $id_as_key = false, $as_object = true)//getObjects(\CriteriaElement $criteria = null)
200
    {
201
        $ret   = [];
202
        $limit = $start = 0;
203
        $sql   = 'SELECT * FROM ' . $this->db->prefix('xfguestbook_msg');
204
        if (null !== $criteria && $criteria instanceof \CriteriaElement) {
205
            $sql   .= ' ' . $criteria->renderWhere();
206
            $sort  = ('' !== $criteria->getSort()) ? $criteria->getSort() : 'msg_id';
207
            $sql   .= ' ORDER BY ' . $sort . ' ' . $criteria->getOrder();
208
            $limit = $criteria->getLimit();
209
            $start = $criteria->getStart();
210
        }
211
        $result = $this->db->query($sql, $limit, $start);
212
        if (!$result) {
213
            return $ret;
214
        }
215
        while (false !== ($myrow = $this->db->fetchArray($result))) {
216
            $msg = new Message();
217
            $msg->assignVars($myrow);
218
            $ret[] = $msg;
219
            unset($msg);
220
        }
221
222
        return $ret;
223
    }
224
225
    /**
226
     * @param null|\CriteriaElement|\CriteriaCompo $criteria
227
     * @return int
228
     */
229
    public function countMsg(\CriteriaElement $criteria = null)
230
    {
231
        $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('xfguestbook_msg');
232
        if (null !== $criteria && $criteria instanceof \CriteriaElement) {
233
            $sql .= ' ' . $criteria->renderWhere();
234
        }
235
        if (!$result = $this->db->query($sql)) {
236
            return 0;
237
        }
238
        [$count] = $this->db->fetchRow($result);
239
240
        return $count;
241
    }
242
243
    /**
244
     * @param null|\CriteriaElement|\CriteriaCompo $criteria
245
     * @return array|bool
246
     */
247
    public function countMsgByCountry(\CriteriaElement $criteria = null)
248
    {
249
        $arr = [];
250
        $sql = 'SELECT country, flagdir FROM ' . $this->db->prefix('xfguestbook_msg');
251
        if (null !== $criteria && $criteria instanceof \CriteriaElement) {
252
            $sql .= ' ' . $criteria->renderWhere();
253
        }
254
        if (!$result = $this->db->query($sql)) {
255
            return false;
256
        }
257
        while (list($country, $flagdir) = $this->db->fetchRow($result)) {
258
            $arr[] = $flagdir . '/' . $country;
259
        }
260
        $ret = \array_count_values($arr);
261
        \arsort($ret);
262
263
        return $ret;
264
    }
265
266
    /**
267
     * @param \CriteriaElement|\CriteriaCompo|null $criteria
268
     * @return array|bool
269
     */
270
    public function countMsgByGender(\CriteriaElement $criteria = null)
271
    {
272
        $arr = [];
273
        $sql = 'SELECT gender FROM ' . $this->db->prefix('xfguestbook_msg');
274
        if (null !== $criteria && $criteria instanceof \CriteriaElement) {
275
            $sql .= ' ' . $criteria->renderWhere();
276
        }
277
        if (!$result = $this->db->query($sql)) {
278
            return false;
279
        }
280
        while (list($gender) = $this->db->fetchRow($result)) {
281
            $arr[] = $gender;
282
        }
283
        $ret = \array_count_values($arr);
284
285
        return $ret;
286
    }
287
288
    /**
289
     * @param null|\CriteriaElement|\CriteriaCompo $criteria
290
     * @return array|int
291
     */
292
    public function getMsgImg(\CriteriaElement $criteria = null)
293
    {
294
        $arr = [];
295
        $sql = 'SELECT photo FROM ' . $this->db->prefix('xfguestbook_msg') . " WHERE `photo` LIKE 'msg_%'";
296
        if (null !== $criteria && $criteria instanceof \CriteriaElement) {
297
            $sql .= ' ' . $criteria->renderWhere();
298
        }
299
        if (!$result = $this->db->query($sql)) {
300
            return 0;
301
        }
302
        while (list($photo) = $this->db->fetchRow($result)) {
303
            $arr[] = $photo;
304
        }
305
306
        return $arr;
307
    }
308
}
309