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 | /** @var Admin $adminObject */ |
||||
| 14 | |||||
| 15 | require_once __DIR__ . '/admin_header.php'; |
||||
| 16 | xoops_cp_header(); |
||||
| 17 | $adminObject = Admin::getInstance(); |
||||
| 18 | $adminObject->displayNavigation(basename(__FILE__)); |
||||
| 19 | |||||
| 20 | $mode = ''; |
||||
| 21 | $action = ''; |
||||
| 22 | $filename = ''; |
||||
| 23 | $restore_structure = ''; |
||||
| 24 | $restore_data = ''; |
||||
| 25 | $replace_url = ''; |
||||
| 26 | // Make sure we pick up variables passed via URL |
||||
| 27 | if (isset($_GET['mode'])) { |
||||
| 28 | $mode = filter_input(INPUT_GET, 'mode', FILTER_SANITIZE_SPECIAL_CHARS); |
||||
| 29 | } |
||||
| 30 | if (isset($_GET['action'])) { |
||||
| 31 | $action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_SPECIAL_CHARS); |
||||
| 32 | } |
||||
| 33 | if (isset($_GET['filename'])) { |
||||
| 34 | $filename = filter_input(INPUT_GET, 'filename', FILTER_SANITIZE_SPECIAL_CHARS); |
||||
| 35 | } |
||||
| 36 | if (isset($_GET['restore_structure'])) { |
||||
| 37 | $restore_structure = filter_input(INPUT_GET, 'restore_structure', FILTER_SANITIZE_SPECIAL_CHARS); |
||||
| 38 | } |
||||
| 39 | if (isset($_GET['restore_data'])) { |
||||
| 40 | $restore_data = filter_input(INPUT_GET, 'restore_data', FILTER_SANITIZE_SPECIAL_CHARS); |
||||
| 41 | } |
||||
| 42 | if (isset($_POST['replace_url'])) { |
||||
| 43 | $replace_url = filter_input(INPUT_POST, 'replace_url', FILTER_SANITIZE_SPECIAL_CHARS); |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | $bp = new backpack(); |
||||
| 47 | if ($bp->err_msg) { |
||||
| 48 | echo '<span style="color: red; ">' . $bp->err_msg . '</span>'; |
||||
| 49 | } |
||||
| 50 | |||||
| 51 | // Handle URL actions |
||||
| 52 | switch ($mode) { |
||||
| 53 | case RESTORE_DATA: |
||||
| 54 | { |
||||
| 55 | echo '<p><strong>' . _AM_RESTORE_OK . '</strong><br>' . _AM_RESTORE_MESS1 . '</p>'; |
||||
| 56 | $fnamedotpos = strrpos($filename, '.'); |
||||
| 57 | $fext = substr($filename, $fnamedotpos + 1); |
||||
| 58 | $sql_str = ''; |
||||
| 59 | switch ($fext) { |
||||
| 60 | case 'gz': |
||||
| 61 | $mime_type = 'application/x-gzip'; |
||||
| 62 | $sql_str = PMA_readFile($bp->backup_dir . $filename, $mime_type); |
||||
| 63 | break; |
||||
| 64 | case 'bz': |
||||
| 65 | $mime_type = 'application/x-bzip'; |
||||
| 66 | $sql_str = PMA_readFile($bp->backup_dir . $filename, $mime_type); |
||||
| 67 | break; |
||||
| 68 | case 'sql': |
||||
| 69 | $mime_type = 'text/plain'; |
||||
| 70 | break; |
||||
| 71 | default: |
||||
| 72 | $mime_type = ''; |
||||
| 73 | break; |
||||
| 74 | } |
||||
| 75 | if (!file_exists($bp->backup_dir . $filename)) { |
||||
| 76 | echo _AM_NO_FILE . $bp->backup_dir . $filename; |
||||
| 77 | break; |
||||
| 78 | } |
||||
| 79 | if ($sql_str) { |
||||
| 80 | unlink($bp->backup_dir . $filename); |
||||
| 81 | //$filename = eregi_replace( ".gz|.bz" , "" , $filename); |
||||
| 82 | $filename = preg_replace('/.gz|.bz/i', '', $filename); |
||||
| 83 | $fp = fopen($bp->backup_dir . $filename, 'wb'); |
||||
| 84 | fwrite($fp, $sql_str); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 85 | fclose($fp); |
||||
|
0 ignored issues
–
show
It seems like
$fp can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 86 | } |
||||
| 87 | if (0 == strcmp(_CHARSET, 'EUC-JP')) { |
||||
| 88 | //$result = $GLOBALS['xoopsDB']->queryF( "SET NAMES 'ujis'" ); |
||||
| 89 | $result = $xoopsDB->queryF('SET NAMES \'ujis\''); |
||||
| 90 | } |
||||
| 91 | $bp->restore_data($bp->backup_dir . $filename, $restore_structure, $restore_data, $db_selected, $replace_url); |
||||
| 92 | unlink($bp->backup_dir . $filename); |
||||
| 93 | break; |
||||
| 94 | } |
||||
| 95 | case DB_SELECT_FORM: |
||||
| 96 | { |
||||
| 97 | echo '<table cellspacing="0" cellpadding="3">'; |
||||
| 98 | if ('backup' == $action) { |
||||
| 99 | echo '<tr><td class="title">' . _AM_TITLE_BCK . '</td></tr>'; |
||||
| 100 | echo '<tr><td class="main_left"><p><b>' . _AM_SELECT_DATABASE . '</b>'; |
||||
| 101 | } |
||||
| 102 | if ('restore' == $action) { |
||||
| 103 | $upload = $_FILES['filename']; |
||||
| 104 | $upload_tmp = $_FILES['filename']['tmp_name']; // Temp File name |
||||
| 105 | $upload_name = $_FILES['filename']['name']; // Local File Name |
||||
| 106 | $upload_size = $_FILES['filename']['size']; // Size |
||||
| 107 | $upload_type = $_FILES['filename']['type']; // Type |
||||
| 108 | $upfile_error = $_FILES['filename']['error']; //upload file error no |
||||
| 109 | if ($upfile_error > 0) { |
||||
| 110 | switch ($upfile_error) { |
||||
| 111 | case UPLOAD_ERR_INI_SIZE: |
||||
| 112 | echo _AM_MESS_ERROR_1; |
||||
| 113 | break; |
||||
| 114 | case UPLOAD_ERR_FORM_SIZE: |
||||
| 115 | echo _AM_MESS_ERROR_2; |
||||
| 116 | break; |
||||
| 117 | case UPLOAD_ERR_PARTIAL: |
||||
| 118 | echo _AM_MESS_ERROR_3; |
||||
| 119 | break; |
||||
| 120 | case UPLOAD_ERR_NO_FILE: |
||||
| 121 | echo _AM_MESS_ERROR_4; |
||||
| 122 | break; |
||||
| 123 | default: |
||||
| 124 | echo sprintf(_AM_MESS_ERROR_5, $upfile_error); |
||||
| 125 | break; |
||||
| 126 | } |
||||
| 127 | } |
||||
| 128 | echo '<tr><td class="title">' . _AM_TITLE_RESTORE . '</td></tr>'; |
||||
| 129 | if (!$upload_name && isset($_POST['uploadedfilename'])) { |
||||
| 130 | $upload_name = filter_input(INPUT_POST, 'uploadedfilename', FILTER_SANITIZE_STRING); //$_POST['uploadedfilename']; |
||||
| 131 | } else { |
||||
| 132 | // Upload file |
||||
| 133 | $ret_val = move_uploaded_file($upload_tmp, $bp->backup_dir . $upload_name); |
||||
| 134 | if (!$ret_val) { |
||||
| 135 | echo '<br><br>' . _AM_MESS_ERROR_6 . '<br>' . _AM_MESS_ERROR_7 . '</p></td></tr></table>'; |
||||
| 136 | break; |
||||
| 137 | } |
||||
| 138 | } |
||||
| 139 | echo '<tr><td class="main_left"><p><b>restore from ' . $upload_name . '</b>'; |
||||
| 140 | echo '<tr><td class="main_left"><p><b>replace URL from http://' . $replace_url . '</b>'; |
||||
| 141 | //$restore_structure = ($_POST['structure'] == "on") ? 1 : 0; |
||||
| 142 | $restore_structure = ('on' == filter_input(INPUT_POST, 'structure', FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE)) ? 1 : 0; |
||||
| 143 | //$restore_data = ($_POST['data'] == "on") ? 1 : 0; |
||||
| 144 | $restore_data = ('on' == filter_input(INPUT_POST, 'data', FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE)) ? 1 : 0; |
||||
| 145 | echo '<form method="post" action="restore.php?mode=' . RESTORE_DATA . '&filename=$upload_name&restore_structure=$restore_structure&restore_data=$restore_data\">\n'; |
||||
| 146 | sprintf('<form method="post" action="restore.php?mode=%s&filename=%s&restore_structure=%s&restore_data=%s">', RESTORE_DATA, $upload_name, $restore_structure, $restore_data); |
||||
| 147 | } |
||||
| 148 | echo '<input type="submit" value="' . _AM_RESTORE . '"></form>'; |
||||
| 149 | echo '</p></td></tr></table>'; |
||||
| 150 | break; |
||||
| 151 | } |
||||
| 152 | default: |
||||
| 153 | { |
||||
| 154 | if (!$filesize = ini_get('upload_max_filesize')) { |
||||
| 155 | $filesize = '5M'; |
||||
| 156 | } |
||||
| 157 | $max_upload_size = $bp->get_real_size($filesize); |
||||
|
0 ignored issues
–
show
$filesize of type string is incompatible with the type integer expected by parameter $size of backpack::get_real_size().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 158 | if ($postsize = ini_get('post_max_size')) { |
||||
| 159 | $postsize = $bp->get_real_size($postsize); |
||||
| 160 | if ($postsize < $max_upload_size) { |
||||
| 161 | $max_upload_size = $postsize; |
||||
| 162 | } |
||||
| 163 | } |
||||
| 164 | unset($filesize); |
||||
| 165 | unset($postsize); |
||||
| 166 | echo '<h2>' . _AM_RESTORETITLE . '</h2>'; |
||||
| 167 | /* |
||||
| 168 | ** for file upload |
||||
| 169 | */ |
||||
| 170 | //echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"" |
||||
| 171 | // .XOOPS_URL."/modules/backpack/admin/restore.php?mode=".DB_SELECT_FORM."&action=restore\">"; |
||||
| 172 | sprintf('<form method="post" enctype="multipart/form-data" action="%s/modules/backpack/admin/restore.php?mode=%s&action=restore">', XOOPS_URL, DB_SELECT_FORM); |
||||
| 173 | echo '<table class="outer" style="width: 100%"><tr><td class=head colspan="2">' . _AM_RESTORETITLE1 . '</td></tr>'; |
||||
| 174 | echo '<tr><td class="odd" style="width: 30%"><b>' . _AM_SELECTAFILE . '</b> (gz, bz, sql)</td>'; |
||||
| 175 | echo '<td><input type="hidden" name="MAX_FILE_SIZE" value="' . $maxbyte . '">'; |
||||
| 176 | echo '<input type="file" name="filename">' . $bp->PMA_displayMaximumUploadSize($max_upload_size) . '</td></tr>'; |
||||
| 177 | echo '<tr><td class="odd"><b>' . _AM_DETAILSTORESTORE . '</b></td>'; |
||||
| 178 | echo '<td><input type="checkbox" name="structure" checked> ' . _AM_TABLESTRUCTURE . ' <input type="checkbox" name="data" checked> ' . _AM_TABLEDATA . '</td></tr>'; |
||||
| 179 | // preg_replace URL |
||||
| 180 | echo '<tr><td class="odd" style="width: 30%"><b>' . _AM_REPLACEURL . '</b> </td>'; |
||||
| 181 | echo '<td><input type="text" name="replace_url"> ' . _AM_REPLACEURL_DESC . '</td></tr>'; |
||||
| 182 | // submit |
||||
| 183 | echo '<tr><td colspan="2" style="text-align: center;"><input type="submit" value="' . _AM_RESTORE . '"></td></tr></table></form>'; |
||||
| 184 | echo '</p>'; |
||||
| 185 | /* |
||||
| 186 | ** for import only |
||||
| 187 | */ |
||||
| 188 | //echo "<form method=\"post\" action=\"" |
||||
| 189 | // .XOOPS_URL."/modules/backpack/admin/restore.php?mode=".DB_SELECT_FORM."&action=restore\">"; |
||||
| 190 | sprintf('<form method="post" action="%s/modules/backpack/admin/restore.php?mode=%s&action=restore">', XOOPS_URL, DB_SELECT_FORM); |
||||
| 191 | echo '<table class="outer" style="width: 100%"><tr><td class="head" colspan="2">' . sprintf(_AM_RESTORETITLE2, $bp->backup_dir) . '</td></tr>'; |
||||
| 192 | echo '<tr><td class="odd" style="width: 30%"><b>' . _AM_UPLOADEDFILENAME . '</b> (gz, bz, sql)</td>'; |
||||
| 193 | echo '<td><input type="text" name="uploadedfilename">' . _AM_UPLOADEDFILENAME_DESC . '</td></tr>'; |
||||
| 194 | echo '<tr><td class="odd"><b>' . _AM_DETAILSTORESTORE . '</b></td>'; |
||||
| 195 | echo '<td><input type="checkbox" name="structure" checked> ' . _AM_TABLESTRUCTURE . ' <input type="checkbox" name="data" checked> ' . _AM_TABLEDATA . '</td></tr>'; |
||||
| 196 | // preg_replace URL |
||||
| 197 | echo '<tr><td class="odd" style="width: 30%"><b>' . _AM_REPLACEURL . '</b></td>'; |
||||
| 198 | echo '<td><input type="text" name="replace_url"> ' . _AM_REPLACEURL_DESC . '</td></tr>'; |
||||
| 199 | // submit |
||||
| 200 | echo '<tr><td colspan="2" style="text-align: center;"><input type="submit" value="' . _AM_RESTORE . '"></td></tr></table></form>'; |
||||
| 201 | echo '</p>'; |
||||
| 202 | } |
||||
| 203 | } |
||||
| 204 | require __DIR__ . '/admin_footer.php'; |
||||
| 205 |