mambax7 /
smartfaq
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php declare(strict_types=1); |
||
| 2 | /* |
||
| 3 | * You may not change or alter any portion of this comment or credits |
||
| 4 | * of supporting developers from this source code or any supporting source code |
||
| 5 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 6 | * |
||
| 7 | * This program is distributed in the hope that it will be useful, |
||
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @copyright XOOPS Project (https://xoops.org) |
||
| 14 | * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 15 | * @author XOOPS Development Team, Kazumi Ono (AKA onokazu) |
||
| 16 | */ |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Module: SmartFAQ |
||
| 20 | * Author: The SmartFactory <www.smartfactory.ca> |
||
| 21 | * Licence: GNU |
||
| 22 | */ |
||
| 23 | |||
| 24 | use Xmf\Request; |
||
| 25 | |||
| 26 | if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) { |
||
| 27 | exit('Access Denied'); |
||
| 28 | } |
||
| 29 | require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
| 30 | require_once XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/blocksadmin.php'; |
||
| 31 | |||
| 32 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
| 33 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
| 34 | |||
| 35 | $op = 'list'; |
||
| 36 | if (isset($_POST)) { |
||
| 37 | foreach ($_POST as $k => $v) { |
||
| 38 | ${$k} = $v; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | if (Request::hasVar('op', 'GET')) { |
||
| 43 | if ('edit' === $_GET['op'] || 'delete' === $_GET['op'] || 'delete_ok' === $_GET['op'] |
||
| 44 | || 'clone' === $_GET['op'] |
||
| 45 | || 'previewpopup' === $_GET['op']) { |
||
| 46 | $op = $_GET['op']; |
||
| 47 | $bid = Request::getInt('bid', 0, 'GET'); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | if (isset($previewblock)) { |
||
| 52 | xoops_cp_header(); |
||
| 53 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 54 | $xoopsTpl = new \XoopsTpl(); |
||
| 55 | $xoopsTpl->caching = 0; |
||
| 56 | if (isset($bid)) { |
||
| 57 | $block['bid'] = $bid; |
||
| 58 | $block['form_title'] = _AM_EDITBLOCK; |
||
| 59 | $myblock = new \XoopsBlock($bid); |
||
| 60 | $block['name'] = $myblock->getVar('name'); |
||
| 61 | } else { |
||
| 62 | if ('save' === $op) { |
||
| 63 | $block['form_title'] = _AM_ADDBLOCK; |
||
| 64 | } else { |
||
| 65 | $block['form_title'] = _AM_CLONEBLOCK; |
||
| 66 | } |
||
| 67 | $myblock = new \XoopsBlock(); |
||
| 68 | $myblock->setVar('block_type', 'C'); |
||
| 69 | } |
||
| 70 | $myts = \MyTextSanitizer::getInstance(); |
||
| 71 | $myblock->setVar('title', ($btitle)); |
||
| 72 | $myblock->setVar('content', ($bcontent)); |
||
| 73 | $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '"><meta http-equiv="content-language" content="' . _LANGCODE . '"><title>' . $xoopsConfig['sitename'] . '</title><link rel="stylesheet" type="text/css" media="all" href="' . getcss( |
||
| 74 | $xoopsConfig['theme_set'] |
||
| 75 | ) . '"></head><body><table><tr><th>' . $myblock->getVar('title') . '</th></tr><tr><td>' . $myblock->getContent('S', $bctype) . '</td></tr></table></body></html>'; |
||
| 76 | |||
| 77 | $dummyfile = '_dummyfile_' . time() . '.html'; |
||
| 78 | $fp = fopen(XOOPS_CACHE_PATH . '/' . $dummyfile, 'wb'); |
||
| 79 | fwrite($fp, $dummyhtml); |
||
| 80 | fclose($fp); |
||
| 81 | $block['edit_form'] = false; |
||
| 82 | $block['template'] = ''; |
||
| 83 | $block['op'] = $op; |
||
| 84 | $block['side'] = $bside; |
||
| 85 | $block['weight'] = $bweight; |
||
| 86 | $block['visible'] = $bvisible; |
||
| 87 | $block['title'] = $myblock->getVar('title', 'E'); |
||
| 88 | $block['content'] = $myblock->getVar('content', 'E'); |
||
| 89 | $block['modules'] = &$bmodule; |
||
| 90 | $block['ctype'] = $bctype ?? $myblock->getVar('c_type'); |
||
| 91 | $block['is_custom'] = true; |
||
| 92 | $block['cachetime'] = (int)$bcachetime; |
||
| 93 | echo '<a href="admin.php?fct=blocksadmin">' . constant('CO_' . $moduleDirNameUpper . '_' . 'BADMIN') . '</a> <span style="font-weight:bold;">»»</span> ' . $block['form_title'] . '<br><br>'; |
||
| 94 | require_once XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/blockform.php'; |
||
| 95 | $form->display(); |
||
| 96 | xoops_cp_footer(); |
||
| 97 | echo '<script type="text/javascript"> |
||
| 98 | <!--// |
||
| 99 | preview_window = openWithSelfMain("' . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&op=previewpopup&file=' . $dummyfile . '", "popup", 250, 200); |
||
| 100 | //--> |
||
| 101 | </script>'; |
||
| 102 | exit(); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ('previewpopup' === $op) { |
||
| 106 | $file = str_replace('..', '', XOOPS_CACHE_PATH . '/' . trim($_GET['file'])); |
||
| 107 | if (file_exists($file)) { |
||
| 108 | require_once $file; |
||
| 109 | @unlink($file); |
||
|
0 ignored issues
–
show
|
|||
| 110 | } |
||
| 111 | exit(); |
||
| 112 | } |
||
| 113 | |||
| 114 | if ('list' === $op) { |
||
| 115 | xoops_cp_header(); |
||
| 116 | list_blocks(); |
||
| 117 | xoops_cp_footer(); |
||
| 118 | exit(); |
||
| 119 | } |
||
| 120 | |||
| 121 | if ('order' === $op) { |
||
| 122 | foreach (array_keys($bid) as $i) { |
||
| 123 | if ($side[$i] < 0) { |
||
| 124 | $visible[$i] = 0; |
||
| 125 | $side[$i] = -1; |
||
| 126 | } else { |
||
| 127 | $visible[$i] = 1; |
||
| 128 | } |
||
| 129 | |||
| 130 | $bmodule[$i] = (isset($bmodule[$i]) && is_array($bmodule[$i])) ? $bmodule[$i] : [-1]; |
||
| 131 | |||
| 132 | myblocksadmin_update_block($i, $side[$i], $weight[$i], $visible[$i], $title[$i], '', '', $bcachetime[$i], $bmodule[$i], []); |
||
| 133 | } |
||
| 134 | |||
| 135 | redirect_header('myblocksadmin.php', 1, _AM_DBUPDATED); |
||
| 136 | } |
||
| 137 | |||
| 138 | if ('save' === $op) { |
||
| 139 | save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime); |
||
| 140 | exit(); |
||
| 141 | } |
||
| 142 | |||
| 143 | if ('update' === $op) { |
||
| 144 | $bcachetime = isset($bcachetime) ? (int)$bcachetime : 0; |
||
| 145 | $options = $options ?? []; |
||
| 146 | $bcontent = $bcontent ?? ''; |
||
| 147 | $bctype = $bctype ?? ''; |
||
| 148 | $bmodule = (isset($bmodule) && is_array($bmodule)) ? $bmodule : [-1]; // GIJ + |
||
| 149 | $msg = myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options); // GIJ c |
||
| 150 | redirect_header('myblocksadmin.php', 1, $msg); // GIJ + |
||
| 151 | } |
||
| 152 | |||
| 153 | if ('delete_ok' === $op) { |
||
| 154 | delete_block_ok($bid); |
||
| 155 | exit(); |
||
| 156 | } |
||
| 157 | |||
| 158 | if ('delete' === $op) { |
||
| 159 | xoops_cp_header(); |
||
| 160 | delete_block($bid); |
||
| 161 | xoops_cp_footer(); |
||
| 162 | exit(); |
||
| 163 | } |
||
| 164 | |||
| 165 | if ('edit' === $op) { |
||
| 166 | xoops_cp_header(); |
||
| 167 | edit_block($bid); |
||
| 168 | xoops_cp_footer(); |
||
| 169 | exit(); |
||
| 170 | } |
||
| 171 | |||
| 172 | // import from modules/system/admin/blocksadmin/blocksadmin.php |
||
| 173 | /** |
||
| 174 | * @param $bid |
||
| 175 | * @param $bside |
||
| 176 | * @param $bweight |
||
| 177 | * @param $bvisible |
||
| 178 | * @param $btitle |
||
| 179 | * @param $bcontent |
||
| 180 | * @param $bctype |
||
| 181 | * @param $bcachetime |
||
| 182 | * @param $bmodule |
||
| 183 | * @param array $options |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | function myblocksadmin_update_block( |
||
| 187 | $bid, |
||
| 188 | $bside, |
||
| 189 | $bweight, |
||
| 190 | $bvisible, |
||
| 191 | $btitle, |
||
| 192 | $bcontent, |
||
| 193 | $bctype, |
||
| 194 | $bcachetime, |
||
| 195 | $bmodule, |
||
| 196 | $options = [] |
||
| 197 | ) { |
||
| 198 | global $xoopsConfig; |
||
| 199 | if (empty($bmodule)) { |
||
| 200 | xoops_cp_header(); |
||
| 201 | xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
||
| 202 | xoops_cp_footer(); |
||
| 203 | exit(); |
||
| 204 | } |
||
| 205 | $myblock = new \XoopsBlock($bid); |
||
| 206 | // $myblock->setVar('side', $bside); GIJ - |
||
| 207 | if ($bside >= 0) { |
||
| 208 | $myblock->setVar('side', $bside); |
||
| 209 | } // GIJ + |
||
| 210 | $myblock->setVar('weight', $bweight); |
||
| 211 | $myblock->setVar('visible', $bvisible); |
||
| 212 | $myblock->setVar('title', $btitle); |
||
| 213 | $myblock->setVar('content', $bcontent); |
||
| 214 | $myblock->setVar('bcachetime', $bcachetime); |
||
| 215 | if (isset($options) && (count($options) > 0)) { |
||
| 216 | $options = implode('|', $options); |
||
| 217 | $myblock->setVar('options', $options); |
||
| 218 | } |
||
| 219 | if ('C' === $myblock->getVar('block_type')) { |
||
| 220 | switch ($bctype) { |
||
| 221 | case 'H': |
||
| 222 | $name = _AM_CUSTOMHTML; |
||
| 223 | break; |
||
| 224 | case 'P': |
||
| 225 | $name = _AM_CUSTOMPHP; |
||
| 226 | break; |
||
| 227 | case 'S': |
||
| 228 | $name = _AM_CUSTOMSMILE; |
||
| 229 | break; |
||
| 230 | default: |
||
| 231 | $name = _AM_CUSTOMNOSMILE; |
||
| 232 | break; |
||
| 233 | } |
||
| 234 | $myblock->setVar('name', $name); |
||
| 235 | $myblock->setVar('c_type', $bctype); |
||
| 236 | } else { |
||
| 237 | $myblock->setVar('c_type', 'H'); |
||
| 238 | } |
||
| 239 | $msg = _AM_DBUPDATED; |
||
| 240 | if (false !== $myblock->store()) { |
||
| 241 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 242 | $sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $db->prefix('block_module_link'), $bid); |
||
| 243 | $db->query($sql); |
||
| 244 | foreach ($bmodule as $bmid) { |
||
| 245 | $sql = sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $db->prefix('block_module_link'), $bid, (int)$bmid); |
||
| 246 | $db->query($sql); |
||
| 247 | } |
||
| 248 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 249 | $xoopsTpl = new \XoopsTpl(); |
||
| 250 | $xoopsTpl->caching = 2; |
||
| 251 | if ('' != $myblock->getVar('template')) { |
||
| 252 | if ($xoopsTpl->is_cached('db:' . $myblock->getVar('template'))) { |
||
| 253 | if (!$xoopsTpl->clear_cache('db:' . $myblock->getVar('template'))) { |
||
| 254 | $msg = 'Unable to clear cache for block ID' . $bid; |
||
| 255 | } |
||
| 256 | } |
||
| 257 | } elseif ($xoopsTpl->is_cached('db:system_dummy.tpl', 'block' . $bid)) { |
||
| 258 | if (!$xoopsTpl->clear_cache('db:system_dummy.tpl', 'block' . $bid)) { |
||
| 259 | $msg = 'Unable to clear cache for block ID' . $bid; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | } else { |
||
| 263 | $msg = 'Failed update of block. ID:' . $bid; |
||
| 264 | } |
||
| 265 | |||
| 266 | return $msg; // GIJ + |
||
| 267 | } |
||
| 268 |
If you suppress an error, we recommend checking for the error condition explicitly: