Issues (207)

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.

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
 * edit.php - edit a wiki page
4
 *
5
 * @copyright  Copyright © 2013 geekwright, LLC. All rights reserved.
6
 * @license    gwiki/docs/license.txt  GNU General Public License (GPL)
7
 * @since      1.0
8
 * @author     Richard Griffith <[email protected]>
9
 * @package    gwiki
10
 */
11
include __DIR__ . '/header.php';
12
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
13
14
global $xoTheme, $xoopsTpl;
15
16
if (isset($_SESSION['gwikiwizard'])) {
17
    $wizard_parms            = unserialize($_SESSION['gwikiwizard']);
18
    $_SESSION['gwikiwizard'] = null;
19
    unset($_SESSION['gwikiwizard']);
20
    $valid_keys = array(
21
        'page',
22
        'op',
23
        'title',
24
        'body',
25
        'display_keyword',
26
        'parent_page',
27
        'page_set_home',
28
        'page_set_order',
29
        'meta_description',
30
        'meta_keywords',
31
        'show_in_index',
32
        'leave_inactive'
33
    );
34
    foreach ($wizard_parms as $key => $value) {
35
        if (in_array($key, $valid_keys)) {
36
            $_POST[$key] = $value;
37
        }
38
    }
39
}
40
41
// $_GET and $_POST variables we use
42
if (isset($_GET['page'])) {
43
    $page = cleaner($_GET['page']);
44
}
45
if (isset($_POST['page'])) {
46
    $page = cleaner($_POST['page']);
47
}
48
49
if (isset($_GET['op'])) {
50
    $op = strtolower(cleaner($_GET['op']));
51
}
52
if (isset($_POST['op'])) {
53
    $op = strtolower(cleaner($_POST['op']));
54
}
55
if (empty($op) || ($op !== 'preview' && $op !== 'edit' && $op !== 'insert')) {
56
    $op = 'edit';
57
} // get a valid op
58
59
// namespace id (prefix_id) is set by newpage block, turn it into a full page name
60
if (isset($_GET['nsid'])) {
61
    $page = $wikiPage->makeKeywordFromPrefix((int)$_GET['nsid'], $page);
62
}
63
if (empty($page)) {
64
    $page = $wikiPage->wikiHomePage;
65
}
66
67
$normpage = $wikiPage->normalizeKeyword($page);
68
if ($normpage === _MI_GWIKI_WIKI404 && strcasecmp($page, _MI_GWIKI_WIKI404) !== 0) {
69
    redirect_header("index.php?page=$page", 2, _MI_GWIKI_WIKI404);
70
} else {
71
    $page = $normpage;
72
}
73
74
$id               = 0;
75
$uid              = 0;
76
$title            = '';
77
$body             = '';
78
$display_keyword  = '';
79
$parent_page      = '';
80
$page_set_home    = '';
81
$page_set_order   = 0;
82
$meta_description = '';
83
$meta_keywords    = '';
84
$show_in_index    = 1;
85
$leave_inactive   = 0;
86
87
if (isset($_GET['id'])) {
88
    $id = (int)$_GET['id'];
89
} // post value will override
90
// $_POST variables we use
91
if (isset($_POST['id'])) {
92
    $id = (int)$_POST['id'];
93
}
94
if (isset($_POST['uid'])) {
95
    $uid = (int)$_POST['uid'];
96
}
97
if (isset($_POST['title'])) {
98
    $title = cleaner($_POST['title']);
99
}
100
if (isset($_POST['body'])) {
101
    $body = cleaner($_POST['body'], false);
102
}
103
if (isset($_POST['display_keyword'])) {
104
    $display_keyword = cleaner($_POST['display_keyword']);
105
}
106
if (isset($_POST['parent_page'])) {
107
    $parent_page = cleaner($_POST['parent_page']);
108
}
109
if (isset($_POST['page_set_home'])) {
110
    $page_set_home = cleaner($_POST['page_set_home']);
111
}
112
if (isset($_POST['page_set_order'])) {
113
    $page_set_order = (int)$_POST['page_set_order'];
114
}
115
if (isset($_POST['meta_description'])) {
116
    $meta_description = cleaner($_POST['meta_description']);
117
}
118
if (isset($_POST['meta_keywords'])) {
119
    $meta_keywords = cleaner($_POST['meta_keywords']);
120
}
121
if (isset($_POST['show_in_index'])) {
122
    $show_in_index = (int)$_POST['show_in_index'];
123
}
124
if (isset($_POST['leave_inactive'])) {
125
    $leave_inactive = (int)$_POST['leave_inactive'];
126
}
127
128
global $wikiPage;
129
$pageX   = $wikiPage->getPage($page, ($id === 0 ? null : $id));
130
$mayEdit = $wikiPage->checkEdit();
131
132
if ($pageX) {
133
    $pageX['author']       = $wikiPage->getUserName($wikiPage->uid);
134
    $pageX['revisiontime'] = date($wikiPage->dateFormat, $pageX['lastmodified']);
135
    $pageX['mayEdit']      = $mayEdit;
136
    $pageX['pageFound']    = true;
137
    if (!empty($highlight)) {
138
        $pageX['body'] = $wikiPage->highlightWords($highlight);
139
    }
140 View Code Duplication
} else {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    $pageX                 = array();
142
    $uid                   = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
143
    $pageX['uid']          = $uid;
144
    $pageX['author']       = $wikiPage->getUserName($uid);
145
    $pageX['revisiontime'] = date($wikiPage->dateFormat);
146
    $pageX['mayEdit']      = $mayEdit;
147
    $pageX['keyword']      = $page;
148
    $pageX['pageFound']    = false;
149
}
150
$dir               = basename(__DIR__);
151
$pageX['moddir']   = $dir;
152
$pageX['modpath']  = XOOPS_ROOT_PATH . '/modules/' . $dir;
153
$pageX['modurl']   = XOOPS_URL . '/modules/' . $dir;
154
$pageX['ineditor'] = true;
155
$pageX['imglib']   = $wikiPage->getImageLib($page);
156
$pageX['maxsize']  = $wikiPage->getMaxUploadSize();
157
158
if (!$mayEdit) {
159
    $err_message = _MD_GWIKI_NO_PAGE_PERMISSION;
160
    redirect_header("index.php?page=$page", 2, $err_message);
161
}
162
163
if ($wikiPage->admin_lock) {
164
    redirect_header("index.php?page=$page", 2, _MD_GWIKI_PAGE_IS_LOCKED);
165
}
166
167
if ($op === 'insert') {
168
    // check if this page was updated elsewhere while we were editing
169
    // if so, we save it, but don't make it the active revision
170
    if ((int)$id === $wikiPage->getCurrentId($page)) {
171
        $forced_inactive = false;
172
    } else {
173
        $leave_inactive  = true;
174
        $forced_inactive = true;
175
    }
176
    $wikiPage->keyword         = $page;
177
    $wikiPage->title           = $title;
178
    $wikiPage->display_keyword = $display_keyword;
179
    $wikiPage->body            = $body;
180
    $wikiPage->uid             = $uid;
181
182
    $wikiPage->parent_page      = $parent_page;
183
    $wikiPage->page_set_home    = $page_set_home;
184
    $wikiPage->page_set_order   = $page_set_order;
185
    $wikiPage->meta_description = $meta_description;
186
    $wikiPage->meta_keywords    = $meta_keywords;
187
    $wikiPage->show_in_index    = $show_in_index;
188
189
    $success = $wikiPage->addRevision($leave_inactive);
190
191
    if ($success) {
192
        if ($forced_inactive) {
193
            $err_message = _MD_GWIKI_EDITCONFLICT;
194
            $op          = 'edit';
195
            $id          = $success;
196
        } else {
197
            $message = _MD_GWIKI_DBUPDATED;
198
            if ($leave_inactive) {
199
                $message = _MD_GWIKI_SAVED_INACTIVE;
200
            }
201
            $op = '';
202
            redirect_header("index.php?page=$page", 2, $message);
203
        }
204
    } else {
205
        $err_message = _MD_GWIKI_ERRORINSERT;
206
        $op          = 'edit';
207
    }
208
}
209
210
$pagestatmessage = '';
211
$pagechanged     = '';
212
$result          = false;
213
if (($op === 'preview') && isset($id)) {
214
    $result          = (int)$id;
215
    $pagestatmessage = _MD_GWIKI_PAGENOTSAVED;
216
    $pagechanged     = 'yes';
217
} else {
218
    //print_r($pageX);
219
    if ($pageX['pageFound']) {
220
        $result = true;
221
    } else {
222
        $result           = false;
223
        $pagestatmessage  = _MD_GWIKI_PAGENOTFOUND;
224
        $op               = 'edit';
225
        $pageX['keyword'] = $page;
226
        //      $pageX['pageFound'] = true; // not really, but used in template only from here on
227
    }
228
229
    $gwiki_id         = $wikiPage->gwiki_id;
230
    $keyword          = $wikiPage->keyword;
231
    $display_keyword  = $wikiPage->display_keyword;
232
    $title            = $wikiPage->title;
233
    $body             = $wikiPage->body;
234
    $parent_page      = $wikiPage->parent_page;
235
    $page_set_home    = $wikiPage->page_set_home;
236
    $page_set_order   = $wikiPage->page_set_order;
237
    $meta_description = $wikiPage->meta_description;
238
    $meta_keywords    = $wikiPage->meta_keywords;
239
    $show_in_index    = $wikiPage->show_in_index;
240
    $lastmodified     = $wikiPage->lastmodified;
241
    $uid              = $wikiPage->uid;
242
    $admin_lock       = $wikiPage->admin_lock;
243
    $active           = $wikiPage->active;
244
}
245
246
switch ($op) {
247
    case 'edit':
248
    case 'preview':
249
        //case "images":
250
        $GLOBALS['xoopsOption']['template_main'] = 'gwiki_edit.tpl';
251
        include XOOPS_ROOT_PATH . '/header.php';
252
253
        $title = prepOut($title); // we need title ready to display in several places
254
        if ($op === 'preview') {
255
            $pageX['keyword'] = $page;
256
            $pageX['title']   = $title;
257
            $pageX['body']    = $wikiPage->renderPage($body);
258
            $pageX['preview'] = true;
259
        } else {
260
            unset($pageX['title'], $pageX['body']);
261
            $pageX['preview'] = false;
262
        }
263
264
        $uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
265
266
        $form = new XoopsThemeForm(_MD_GWIKI_EDITPAGE . ": $page", 'gwikiform', "edit.php?page=$page");
267
268
        if (empty($display_keyword)) {
269
            $display_keyword = $page;
270
        }
271
272
        $form->addElement(new XoopsFormHidden('op', 'insert'));
273
        $form->addElement(new XoopsFormHidden('page', $page));
274
        $form->addElement(new XoopsFormHidden('id', $wikiPage->getCurrentId($page)));
275
        $form->addElement(new XoopsFormHidden('uid', $uid));
276
        $form->addElement(new XoopsFormHidden('pagechanged', $pagechanged));
277
278
        $form->addElement(new XoopsFormText(_MD_GWIKI_TITLE, 'title', 40, 250, $title));
279
        $form->addElement(new XoopsFormLabel('', '', 'gwikieditbuttons')); // edit buttons added in template
280
281
        $form_edit_body = new XoopsFormTextArea(_MD_GWIKI_BODY, 'body', htmlspecialchars($body), 20, 80);
282
        $form_edit_body->setExtra("onclick='setWikiChanged();'");
283
        $form->addElement($form_edit_body);
284
285
        $btn_tray   = new XoopsFormElementTray('', ' ', 'gwikiformpage1');
286
        $submit_btn = new XoopsFormButton('', 'submit', _MD_GWIKI_SUBMIT, 'submit');
287
        $submit_btn->setExtra("onclick='prepForSubmit();'");
288
        $btn_tray->addElement($submit_btn);
289
290
        $metadata_btn = new XoopsFormButton('', 'metaedit', _MD_GWIKI_EDIT_SHOW_META, 'button');
291
        $metadata_btn->setExtra('onclick=' . "'var ele = document.getElementById(\"gwikiformmetaedit\"); ele.style.display = \"inherit\";"
292
                                . " var ele2 = document.getElementById(\"gwikiformbodyedit\"); ele2.style.display = \"none\";'");
293
        $btn_tray->addElement($metadata_btn);
294
295
        $preview_btn = new XoopsFormButton('', 'preview', _PREVIEW, 'button');
296
        $preview_btn->setExtra("onclick='prepForPreview();'");
297
        $btn_tray->addElement($preview_btn);
298
299
        $cancel_btn = new XoopsFormButton('', 'cancel', _CANCEL, 'button');
300
        $cancel_btn->setExtra("onclick='" . (($op === 'edit') ? 'history.back();' : "document.location.href=\"index.php" . ($result ? "?page=$page" : '') . "\";") . "'");
301
        $btn_tray->addElement($cancel_btn);
302
303
        $btn_tray->addElement(new XoopsFormLabel('', " - <strong>{$pagestatmessage}</strong>"));
304
305
        $form->addElement($btn_tray);
306
307
        $form->addElement(new XoopsFormText(_MD_GWIKI_DISPLAY_KEYWORD, 'display_keyword', 40, 250, htmlspecialchars($display_keyword)));
308
        $form->addElement(new XoopsFormText(_MD_GWIKI_PARENT_PAGE, 'parent_page', 40, 250, htmlspecialchars($parent_page)));
309
        $form->addElement(new XoopsFormText(_MD_GWIKI_PAGE_SET_HOME, 'page_set_home', 40, 250, htmlspecialchars($page_set_home)));
310
        $form->addElement(new XoopsFormText(_MD_GWIKI_PAGE_SET_ORDER, 'page_set_order', 4, 10, htmlspecialchars($page_set_order)));
311
        $form->addElement(new XoopsFormText(_MD_GWIKI_META_KEYWORDS, 'meta_keywords', 80, 500, htmlspecialchars($meta_keywords)));
312
        $form->addElement(new XoopsFormTextArea(_MD_GWIKI_META_DESCRIPTION, 'meta_description', htmlspecialchars($meta_description), 6, 80));
313
        $form->addElement(new XoopsFormRadioYN(_MD_GWIKI_SHOW_IN_INDEX, 'show_in_index', (int)$show_in_index));
314
        $form->addElement(new XoopsFormRadioYN(_MD_GWIKI_LEAVE_INACTIVE, 'leave_inactive', (int)$leave_inactive));
315
        $btn_tray2 = new XoopsFormElementTray('', ' ', 'gwikiformpage2');
316
317
        $submit_btn2 = new XoopsFormButton('', 'submit2', _MD_GWIKI_SUBMIT, 'submit');
318
        $submit_btn2->setExtra("onclick='prepForSubmit();'");
319
        $btn_tray2->addElement($submit_btn2);
320
321
        $bodydata_btn = new XoopsFormButton('', 'bodyedit', _MD_GWIKI_EDIT_SHOW_BODY, 'button');
322
        $bodydata_btn->setExtra('onclick=' . "'var ele = document.getElementById(\"gwikiformmetaedit\"); ele.style.display = \"none\"; "
323
                                . " var ele2 = document.getElementById(\"gwikiformbodyedit\"); ele2.style.display = \"inherit\";'");
324
        $btn_tray2->addElement($bodydata_btn);
325
326
        $preview_btn2 = new XoopsFormButton('', 'preview2', _PREVIEW, 'button');
327
        $preview_btn2->setExtra("onclick='prepForPreview();'");
328
        $btn_tray2->addElement($preview_btn2);
329
330
        $cancel_btn2 = new XoopsFormButton('', 'cancel2', _CANCEL, 'button');
331
        $cancel_btn2->setExtra("onclick='" . (($op === 'edit') ? 'history.back();' : "document.location.href=\"index.php" . ($result ? "?page=$page" : '') . "\";") . "'");
332
        $btn_tray2->addElement($cancel_btn2);
333
334
        $btn_tray2->addElement(new XoopsFormLabel('', " - <strong>{$pagestatmessage}</strong>"));
335
336
        $form->addElement($btn_tray2);
337
338
        $form->assign($xoopsTpl);
339
        $xoopsTpl->assign('gwiki', $pageX);
340
        $xoopsTpl->assign('showwizard', empty($body));
341
        break;
342
343
}
344
345
$xoTheme->addStylesheet(XOOPS_URL . '/modules/gwiki/assets/css/module.css');
346
if (empty($title)) {
347
    $title = $xoopsModule->name();
348
}
349
$xoopsTpl->assign('xoops_pagetitle', $title);
350
if (!empty($message)) {
351
    $xoopsTpl->assign('message', htmlspecialchars($message));
352
}
353
if (!empty($err_message)) {
354
    $xoopsTpl->assign('err_message', htmlspecialchars($err_message));
355
}
356
357
include XOOPS_ROOT_PATH . '/footer.php';
358