XoopsModules25x /
backpack
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 |
||
| 2 | /* |
||
| 3 | ******************************************************* |
||
| 4 | *** *** |
||
| 5 | *** backpack *** |
||
| 6 | *** Cedric MONTUY pour CHG-WEB *** |
||
| 7 | *** Original author : Yoshi Sakai *** |
||
| 8 | *** *** |
||
| 9 | ******************************************************* |
||
| 10 | */ |
||
| 11 | |||
| 12 | use Xmf\Module\Admin; |
||
| 13 | use Xmf\Request; |
||
| 14 | |||
| 15 | /** @var Admin $adminObject */ |
||
| 16 | |||
| 17 | require_once __DIR__ . '/admin_header.php'; |
||
| 18 | xoops_cp_header(); |
||
| 19 | $adminObject = Admin::getInstance(); |
||
| 20 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 21 | |||
| 22 | $bp = new backpack(); |
||
| 23 | if ($bp->err_msg) { |
||
| 24 | sprintf('<span style="color: red; ">%s</span>', $bp->err_msg); |
||
| 25 | } |
||
| 26 | function mysqli_tablename($result, $i) |
||
| 27 | { |
||
| 28 | mysqli_data_seek($result, $i); |
||
| 29 | $f = mysqli_fetch_array($result); |
||
| 30 | $fetch = null !== $f ? $f[0] : null; |
||
| 31 | return $fetch; |
||
| 32 | } |
||
| 33 | |||
| 34 | $time_start = time(); |
||
| 35 | //$dump_buffer = null; |
||
| 36 | $dump_line = 0; |
||
| 37 | $dump_size = 0; |
||
| 38 | $download_count = 0; |
||
| 39 | $download_fname = []; |
||
| 40 | $mime_type = ''; |
||
| 41 | $query_res = []; // for query result |
||
| 42 | |||
| 43 | if (isset($_POST['purgeallfiles'])) { |
||
| 44 | $bp->purge_allfiles(); |
||
| 45 | redirect_header('./index.php', 1, _AM_PURGED_ALLFILES); |
||
| 46 | } |
||
| 47 | // Make sure we pick up variables passed via URL |
||
| 48 | $mode = Request::getString('mode', '', 'GET'); |
||
| 49 | $action = Request::getString('action', '', 'GET'); |
||
| 50 | $num_tables = Request::getString('num_tables', '', 'GET'); |
||
| 51 | $checkall = Request::getString('checkall', '', 'GET'); |
||
| 52 | |||
| 53 | $tr_comp = '<tr><td class="odd"><strong>' |
||
| 54 | . _AM_COMPRESSION |
||
| 55 | . '</strong></td>' |
||
| 56 | . '<td><input type="radio" id="gzip" name="file_compression" value="gzip" checked>' |
||
| 57 | . '<label for="gz">gzip</label> ' |
||
| 58 | . '<input type="radio" id="zip" name="file_compression" value="zip">' |
||
| 59 | . '<label for="sql">zip</label>  ' |
||
| 60 | . '<input type="radio" id="plain" name="file_compression" value="none">' |
||
| 61 | . '<label for="sql">text</label>  </td></tr>'; |
||
| 62 | $tr_strd = '<tr><td class="odd" style="width:30%;"><strong>' . _AM_DETAILSTOBACKUP . '</strong></td>' . '<td><input type="checkbox" name="structure" checked> ' . _AM_TABLESTRUCTURE . ' ' . '<input type="checkbox" name="data" checked> ' . _AM_TABLEDATA . ' </td></tr>'; |
||
| 63 | |||
| 64 | // Handle URL actions |
||
| 65 | switch ($mode) { |
||
| 66 | case POST_SELECT_MODULE_FORM: |
||
| 67 | { |
||
| 68 | $select_dirname = isset($_GET['dirname']) ? filter_input(INPUT_GET, 'dirname', FILTER_SANITIZE_STRING) : 0; |
||
| 69 | $mod_selections = $bp->make_module_selection($select_dirname); |
||
| 70 | echo '<form method="post" action="index2.php?mode=' . POST_SELECT_TABLES_FORM . '&alltables=on">'; |
||
| 71 | echo '<table class="outer" style="width:100%;"><tr><td class="head" colspan=2>' . _AM_MODULEBACKUP . '</td></tr>'; |
||
| 72 | echo '<tr><td class="odd"><strong>' . _AM_SELECTMODULE . '</strong></td><td>' . $mod_selections . '</td></tr>'; |
||
| 73 | echo $tr_strd; |
||
| 74 | echo $tr_comp; |
||
| 75 | echo '<tr><td colspan=2 style="text-align: center;"><input type="submit" value="' . _AM_BACKUP . '"></td></tr></table>'; |
||
| 76 | echo '</form>'; |
||
| 77 | //echo '</p>'; |
||
| 78 | echo '<br>'; |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | case POST_DB_SELECT_FORM: |
||
| 82 | { |
||
| 83 | $select_dirname = isset($_GET['dirname']) ? filter_input(INPUT_GET, 'dirname', FILTER_SANITIZE_STRING) : 0; |
||
| 84 | $mod_selections = $bp->make_module_selection($select_dirname, 1); |
||
| 85 | // Get list of tables in the database and output form |
||
| 86 | if ('module' == $action && $dirname) { |
||
| 87 | $result = get_module_tables($dirname); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 88 | $num_tables = count($result); |
||
| 89 | $checkall = true; |
||
| 90 | } else { |
||
| 91 | $result = $xoopsDB->queryF('SHOW TABLES FROM ' . $db_selected); |
||
| 92 | $num_tables = $xoopsDB->getRowsNum($result); |
||
| 93 | } |
||
| 94 | echo '<table class="outer" style="width:100%">'; |
||
| 95 | echo '<form method="post" action="index2.php?mode=' . POST_SELECT_TABLES_FORM . '&num_tables=' . $num_tables . '">'; |
||
| 96 | echo '<tr><td class="head" colspan="2"><strong>' . _AM_SELECTTABLES . '</strong></td></tr>'; |
||
| 97 | echo '<tr><td class="main_left" colspan="2"><p>' . _AM_BACKUPNOTICE . '</p>'; |
||
| 98 | echo '<p><strong>' . _AM_SELECTTABLE . '</strong></p>'; |
||
| 99 | $checked = (!empty($checkall) ? ' checked' : ''); |
||
| 100 | for ($i = 0; $i < $num_tables; ++$i) { |
||
| 101 | if ('module' == $action && $dirname) { |
||
| 102 | $tablename = $xoopsDB->prefix($result[$i]); |
||
| 103 | } else { |
||
| 104 | $tablename = mysqli_tablename($result, $i); |
||
| 105 | } |
||
| 106 | $checkbox_string = sprintf( |
||
| 107 | '<input type="checkbox" name="check_id%d" $checked> |
||
| 108 | <input type="hidden" name="tablename%d" value="%s"> %s<br>' . "\n", |
||
| 109 | $i, |
||
| 110 | $i, |
||
| 111 | $tablename, |
||
| 112 | $tablename |
||
| 113 | ); |
||
| 114 | echo '<tr><td class="main_left" colspan="2">' . $checkbox_string . '</td></tr>'; |
||
| 115 | } |
||
| 116 | if ('module' == $action && $dirname) { |
||
| 117 | echo '<input type="hidden" name="dirname" value="' . $dirname . '>'; |
||
| 118 | } |
||
| 119 | echo '<tr><td colspan="2">'; |
||
| 120 | echo '<a href="' . XOOPS_URL . '/modules/backpack/admin/index.php?mode=' . POST_DB_SELECT_FORM . '&action=backup&checkall=1">' . _AM_CHECKALL . '</a></td></tr>'; |
||
| 121 | echo $tr_strd; |
||
| 122 | echo $tr_comp; |
||
| 123 | echo '<tr><td colspan="2">'; |
||
| 124 | echo '<p><input type="submit" value="' . _AM_BACKUP . '">'; |
||
| 125 | echo '<input type="reset" value="' . _AM_RESET . '">'; |
||
| 126 | echo '</p></td></tr></form></table>'; |
||
| 127 | break; |
||
| 128 | } |
||
| 129 | case POST_SELECT_TABLES_FORM: |
||
| 130 | { |
||
| 131 | $bp->purge_allfiles(); |
||
| 132 | |||
| 133 | $sql_string = ''; |
||
| 134 | $alltables = $backup_structure = $backup_data = 0; |
||
| 135 | if (isset($_GET['alltables'])) { |
||
| 136 | $alltables = ('on' == filter_input(INPUT_GET, 'alltables', FILTER_SANITIZE_STRING)) ? 1 : 0; |
||
| 137 | } |
||
| 138 | if (isset($_POST['alltables'])) { |
||
| 139 | $alltables = ('on' == filter_input(INPUT_POST, 'alltables', FILTER_SANITIZE_STRING)) ? 1 : 0; |
||
| 140 | } |
||
| 141 | if (isset($_POST['structure'])) { |
||
| 142 | $backup_structure = ('on' == filter_input(INPUT_POST, 'structure', FILTER_SANITIZE_STRING)) ? 1 : 0; |
||
| 143 | } |
||
| 144 | if (isset($_POST['data'])) { |
||
| 145 | $backup_data = ('on' == filter_input(INPUT_POST, 'data', FILTER_SANITIZE_STRING)) ? 1 : 0; |
||
| 146 | } |
||
| 147 | $dirname = isset($_POST['dirname']) ? filter_input(INPUT_POST, 'dirname', FILTER_SANITIZE_STRING) : 0; |
||
| 148 | if ($dirname) { |
||
| 149 | if (0 == strcmp($dirname, 'system')) { |
||
| 150 | $result = $sys_tables; |
||
| 151 | } else { |
||
| 152 | $result = $bp->get_module_tables($dirname); |
||
| 153 | } |
||
| 154 | $num_tables = count($result); |
||
| 155 | } else { |
||
| 156 | $result = $xoopsDB->queryF('SHOW TABLES FROM ' . $db_selected); |
||
| 157 | $num_tables = $xoopsDB->getRowsNum($result); |
||
| 158 | } |
||
| 159 | $j = 0; |
||
| 160 | $tablename_array = []; |
||
| 161 | if (!$alltables) { |
||
| 162 | for ($i = 0; $i < $num_tables; ++$i) { |
||
| 163 | $check_id = sprintf('check_id%d', $i); |
||
| 164 | $tablename = sprintf('tablename%d', $i); |
||
| 165 | |||
| 166 | if (isset($_POST[$check_id])) { |
||
| 167 | if (isset($_POST[$tablename])) { |
||
| 168 | $tablename_array[$j] = filter_input(INPUT_POST, $tablename, FILTER_SANITIZE_STRING); |
||
| 169 | ++$j; |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | } else { |
||
| 174 | for ($i = 0; $i < $num_tables; ++$i) { |
||
| 175 | if ($dirname) { |
||
| 176 | $tablename_array[$i] = $xoopsDB->prefix($result[$i]); |
||
| 177 | } else { |
||
| 178 | $tablename_array[$i] = mysqli_tablename($result, $i); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | if ($dirname) { |
||
| 183 | $filename = $dirname . date('YmdHis', time()); |
||
| 184 | } elseif ($alltables) { |
||
| 185 | $filename = 'xdb' . date('YmdHis', time()); |
||
| 186 | } else { |
||
| 187 | $filename = 'xtbl' . date('YmdHis', time()); |
||
| 188 | } |
||
| 189 | $cfgZipType = filter_input(INPUT_POST, 'file_compression', FILTER_SANITIZE_STRING); //$_POST['file_compression'] ; |
||
| 190 | $bp->backup_data($tablename_array, $backup_structure, $backup_data, $filename, $cfgZipType); |
||
| 191 | $download_fname = $bp->download_fname(); |
||
| 192 | if (1 == $bp->download_count) { |
||
| 193 | //redirect_header("./download.php?url=".$download_fname[0]['filename'], 1, _AM_READY_TO_DOWNLOAD); |
||
| 194 | $url = './download.php?url=' . $download_fname[0]['filename']; |
||
| 195 | $time = 1; |
||
| 196 | $message = _AM_READY_TO_DOWNLOAD; |
||
| 197 | $url = preg_replace('/&/i', '&', htmlspecialchars($url, ENT_QUOTES)); |
||
| 198 | echo ' |
||
| 199 | <html> |
||
| 200 | <head> |
||
| 201 | <title>' . htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES | ENT_HTML5) . '</title> |
||
| 202 | <meta http-equiv="Content-Type" content="text/html; charset=' . _CHARSET . '"> |
||
| 203 | <meta http-equiv="Refresh" content="' . $time . '; url=' . $url . '"> |
||
| 204 | <style type="text/css"> |
||
| 205 | body {background-color : #fcfcfc; font-size: 12px; font-family: Trebuchet MS,Verdana, Arial, Helvetica, sans-serif; margin: 0px;} |
||
| 206 | .redirect {width: 70%; margin: 110px; text-align: center; padding: 15px; border: #e0e0e0 1px solid; color: #666666; background-color: #f6f6f6;} |
||
| 207 | .redirect a:link {color: #666666; text-decoration: none; font-weight: bold;} |
||
| 208 | .redirect a:visited {color: #666666; text-decoration: none; font-weight: bold;} |
||
| 209 | .redirect a:hover {color: #999999; text-decoration: underline; font-weight: bold;} |
||
| 210 | </style> |
||
| 211 | </head> |
||
| 212 | <body> |
||
| 213 | <div align="center"> |
||
| 214 | <div class="redirect"> |
||
| 215 | <span style="font-size: 16px; font-weight: bold;">' . $message . '</span> |
||
| 216 | <hr style="height: 3px; border: 3px #E18A00 solid; width: 95%;"> |
||
| 217 | <p>' . sprintf(_AM_IFNOTRELOAD, $url) . '</p> |
||
| 218 | </div> |
||
| 219 | </div> |
||
| 220 | </body> |
||
| 221 | </html>'; |
||
| 222 | } else { |
||
| 223 | $form = new XoopsThemeForm(_AM_DOWNLOAD_LIST, 'download', $_SERVER['PHP_SELF']); |
||
| 224 | $iMax = count($download_fname); |
||
| 225 | for ($i = 0; $i < $iMax; ++$i) { |
||
| 226 | $url = '<a href="download.php?url=' . $download_fname[$i]['filename'] . '" target="_blank">' . $download_fname[$i]['filename'] . '</a>'; |
||
| 227 | $url .= $download_fname[$i]['line'] . 'lines ' . $download_fname[$i]['size'] . 'bytes<br>'; |
||
| 228 | $form->addElement(new XoopsFormLabel($i, $url)); |
||
| 229 | } |
||
| 230 | $form->addElement(new XoopsFormButton('', 'purgeallfiles', _AM_PURGE_FILES, 'submit')); |
||
| 231 | $form->display(); |
||
| 232 | } |
||
| 233 | break; |
||
| 234 | } |
||
| 235 | |||
| 236 | case DB_SELECT_FORM: |
||
| 237 | { |
||
| 238 | echo '<table cellspacing="0" cellpadding="3">'; |
||
| 239 | if ('backup' == $action) { |
||
| 240 | echo '<tr><td class="title">' . _AM_TITLE_BCK . '</td></tr>'; |
||
| 241 | echo '<tr><td class="main_left"><p><b>' . _AM_SELECT_DATABASE . '</b>'; |
||
| 242 | } |
||
| 243 | if ('backup' == $action) { |
||
| 244 | echo '<form method="post" action="index2.php?mode=' . POST_DB_SELECT_FORM . '">'; |
||
| 245 | } |
||
| 246 | echo '<input type="submit" value="Restore">'; |
||
| 247 | echo '</form></p></td></tr></table>'; |
||
| 248 | break; |
||
| 249 | } |
||
| 250 | default: |
||
| 251 | { |
||
| 252 | $result = $xoopsDB->queryF('SHOW TABLES FROM ' . $db_selected); |
||
| 253 | $num_tables = $xoopsDB->getRowsNum($result); |
||
| 254 | echo '<form method="post" action="index2.php?mode=' . POST_SELECT_TABLES_FORM . '&num_tables=' . $num_tables . '&alltables=on">'; |
||
| 255 | echo '<table class="outer" style="width:100%;"><tr><td class="head" colspan="2">' . _AM_BACKUPTITLE . '</td></tr>'; |
||
| 256 | echo $tr_strd; |
||
| 257 | echo $tr_comp; |
||
| 258 | echo '<tr><td colspan="2" style="text-align: center;"><input type="submit" value="' . _AM_BACKUP . '"></td></tr></table></form>'; |
||
| 259 | echo '<br>'; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | require __DIR__ . '/admin_footer.php'; |
||
| 263 |