mambax7 /
avaman
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.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 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 | * Avaman module |
||
| 14 | * |
||
| 15 | * @copyright XOOPS Project (http://xoops.org) |
||
| 16 | * @license {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License} |
||
| 17 | * @package Avaman |
||
| 18 | * @since 2.5.0 |
||
| 19 | * @author GIJOE |
||
| 20 | */ |
||
| 21 | |||
| 22 | $avaman_allowed_exts = array( |
||
| 23 | 'gif' => 'image/gif', |
||
| 24 | 'jpg' => 'image/jpeg', |
||
| 25 | 'jpeg' => 'image/jpeg', |
||
| 26 | 'png' => 'image/png' |
||
| 27 | ); |
||
| 28 | $realmyname = 'avatars.php'; |
||
| 29 | |||
| 30 | include_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; |
||
| 31 | |||
| 32 | include_once dirname(__DIR__) . '/include/gtickets.php'; |
||
| 33 | include_once __DIR__ . '/admin_header.php'; |
||
| 34 | $indexAdmin = new ModuleAdmin(); |
||
| 35 | |||
| 36 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 37 | $myts = MyTextSanitizer::getInstance(); |
||
| 38 | |||
| 39 | // |
||
| 40 | // POST Stage |
||
| 41 | // |
||
| 42 | |||
| 43 | if (!empty($_POST['modify_avatars'])) { |
||
| 44 | |||
| 45 | // Ticket Check |
||
| 46 | if (!$xoopsGTicket->check()) { |
||
| 47 | redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors()); |
||
| 48 | } |
||
| 49 | |||
| 50 | // rename |
||
| 51 | $avatar_ids = array(); |
||
| 52 | View Code Duplication | if (is_array(@$_POST['avatar_names'])) { |
|
| 53 | foreach ($_POST['avatar_names'] as $avatar_id => $avatar_name) { |
||
| 54 | $avatar_id = (int)$avatar_id; |
||
| 55 | $db->query('UPDATE ' . $db->prefix('avatar') . " SET avatar_name='" . $myts->addSlashes($avatar_name) . "' WHERE avatar_id=" . (int)$avatar_id); |
||
| 56 | $avatar_ids[] = $avatar_id; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | // display |
||
| 61 | View Code Duplication | foreach ($avatar_ids as $avatar_id) { |
|
| 62 | if (empty($_POST['avatar_displays'][$avatar_id])) { |
||
| 63 | $db->query('UPDATE ' . $db->prefix('avatar') . " SET avatar_display=0 WHERE avatar_id=$avatar_id"); |
||
| 64 | } else { |
||
| 65 | $db->query('UPDATE ' . $db->prefix('avatar') . " SET avatar_display=1 WHERE avatar_id=$avatar_id"); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | // weight |
||
| 70 | foreach ($avatar_ids as $avatar_id) { |
||
| 71 | $db->query('UPDATE ' . $db->prefix('avatar') . " SET avatar_weight='" . (int)(@$_POST['avatar_weights'][$avatar_id]) . "' WHERE avatar_id=$avatar_id"); |
||
| 72 | } |
||
| 73 | |||
| 74 | // delete |
||
| 75 | foreach ($avatar_ids as $avatar_id) { |
||
| 76 | if (!empty($_POST['avatar_deletes'][$avatar_id])) { |
||
| 77 | $result = $db->query('SELECT a.avatar_file,COUNT(l.user_id) FROM ' . $db->prefix('avatar') . ' a NATURAL LEFT JOIN ' . $db->prefix('avatar_user_link') . " l WHERE a.avatar_id=$avatar_id GROUP BY a.avatar_id"); |
||
| 78 | View Code Duplication | if ($result) { |
|
| 79 | list($file, $users) = $db->fetchRow($result); |
||
| 80 | if ($users > 0) { |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | if (false !== strpos($file, '..')) { |
||
| 84 | die('.. found.'); |
||
| 85 | } |
||
| 86 | @unlink(XOOPS_UPLOAD_PATH . '/' . $file); |
||
|
0 ignored issues
–
show
|
|||
| 87 | $db->query('DELETE FROM ' . $db->prefix('avatar') . " WHERE avatar_id=$avatar_id"); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | redirect_header($realmyname, 2, _AM_AVAMAN_DBUPDATED); |
||
| 93 | exit; |
||
| 94 | } |
||
| 95 | |||
| 96 | // ARCHIVE UPLOAD |
||
| 97 | if (!empty($_FILES['upload_archive']['tmp_name']) && is_uploaded_file($_FILES['upload_archive']['tmp_name'])) { |
||
| 98 | |||
| 99 | // extract stage |
||
| 100 | $orig_filename4check = strtolower($_FILES['upload_archive']['name']); |
||
| 101 | $orig_ext4check = substr($orig_filename4check, strrpos($orig_filename4check, '.') + 1); |
||
| 102 | View Code Duplication | if ($orig_ext4check === 'zip') { |
|
| 103 | |||
| 104 | // zip |
||
| 105 | include_once dirname(__DIR__) . '/include/Archive_Zip.php'; |
||
| 106 | $reader = new Archive_Zip($_FILES['upload_archive']['tmp_name']); |
||
| 107 | $files = $reader->extract(array('extract_as_string' => true)); |
||
| 108 | if (!is_array(@$files)) { |
||
| 109 | die($reader->errorName()); |
||
| 110 | } |
||
| 111 | } elseif ($orig_ext4check === 'tar' || $orig_ext4check === 'tgz' || $orig_ext4check === 'gz') { |
||
| 112 | |||
| 113 | // tar or tgz or tar.gz |
||
| 114 | include_once XOOPS_ROOT_PATH . '/class/class.tar.php'; |
||
| 115 | $tar = new tar(); |
||
| 116 | $tar->openTAR($_FILES['upload_archive']['tmp_name']); |
||
| 117 | $files = array(); |
||
| 118 | foreach ($tar->files as $id => $info) { |
||
| 119 | $files[] = array( |
||
| 120 | 'filename' => $info['name'], |
||
| 121 | 'mtime' => $info['time'], |
||
| 122 | 'content' => $info['file'] |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | if (empty($files)) { |
||
| 126 | die(_AM_AVAMAN_ERR_INVALIDARCHIVE); |
||
| 127 | } |
||
| 128 | } elseif (!empty($avaman_allowed_exts[$orig_ext4check])) { |
||
| 129 | |||
| 130 | // a single image file |
||
| 131 | $files = array(); |
||
| 132 | $files[] = array( |
||
| 133 | 'filename' => $_FILES['upload_archive']['name'], |
||
| 134 | 'mtime' => time(), |
||
| 135 | 'content' => function_exists('file_get_contents') ? file_get_contents($_FILES['upload_archive']['tmp_name']) : implode(file($_FILES['upload_archive']['tmp_name'])) |
||
| 136 | ); |
||
| 137 | } else { |
||
| 138 | die(_AM_AVAMAN_INVALIDEXT); |
||
| 139 | } |
||
| 140 | |||
| 141 | // import stage |
||
| 142 | $imported = 0; |
||
| 143 | foreach ($files as $file) { |
||
| 144 | if (!empty($file['folder'])) { |
||
| 145 | continue; |
||
| 146 | } |
||
| 147 | $file_pos = strrpos($file['filename'], '/'); |
||
| 148 | $file_name = $file_pos === false ? $file['filename'] : substr($file['filename'], $file_pos + 1); |
||
| 149 | $ext_pos = strrpos($file_name, '.'); |
||
| 150 | if ($ext_pos === false) { |
||
| 151 | continue; |
||
| 152 | } |
||
| 153 | $ext = strtolower(substr($file_name, $ext_pos + 1)); |
||
| 154 | if (empty($avaman_allowed_exts[$ext])) { |
||
| 155 | continue; |
||
| 156 | } |
||
| 157 | $file_node = substr($file_name, 0, $ext_pos); |
||
| 158 | $save_file_name = uniqid('savt') . '.' . $ext; |
||
| 159 | $fw = fopen(XOOPS_UPLOAD_PATH . '/' . $save_file_name, 'w'); |
||
| 160 | if (!$fw) { |
||
| 161 | continue; |
||
| 162 | } |
||
| 163 | @fwrite($fw, $file['content']); |
||
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||
| 164 | @fclose($fw); |
||
|
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||
| 165 | $db->query('INSERT INTO ' . $db->prefix('avatar') . " SET avatar_file='" . addslashes($save_file_name) . "', avatar_name='" . addslashes($file_node) . "', avatar_mimetype='" . addslashes(@$avaman_allowed_exts[$ext]) |
||
| 166 | . "', avatar_created=UNIX_TIMESTAMP(), avatar_display=1, avatar_weight=0, avatar_type='S'"); |
||
| 167 | |||
| 168 | ++$imported; |
||
| 169 | } |
||
| 170 | |||
| 171 | redirect_header($realmyname, 3, sprintf(_AM_AVAMAN_FILEUPLOADED, $imported)); |
||
| 172 | exit; |
||
| 173 | } |
||
| 174 | |||
| 175 | // Form Stage |
||
| 176 | |||
| 177 | xoops_cp_header(); |
||
| 178 | echo $indexAdmin->addNavigation(basename(__FILE__)); |
||
| 179 | |||
| 180 | $sql = 'SELECT a.avatar_id , a.avatar_file , a.avatar_name , a.avatar_created , a.avatar_display , a.avatar_weight , COUNT(l.user_id) FROM ' . $db->prefix('avatar') . ' a NATURAL LEFT JOIN ' . $db->prefix('avatar_user_link') |
||
| 181 | . " l WHERE a.avatar_type='S' GROUP BY a.avatar_id ORDER BY a.avatar_weight,a.avatar_id"; |
||
| 182 | $result = $db->query($sql); |
||
| 183 | |||
| 184 | echo " |
||
| 185 | <form action='$realmyname' id='avaman_upload' method='post' enctype='multipart/form-data' class='odd'> |
||
| 186 | <label for='upload_archive'>" . _AM_AVAMAN_UPLOAD . "</label> |
||
| 187 | <br> |
||
| 188 | <input type='file' id='upload_archive' name='upload_archive' size='60' /> |
||
| 189 | <input type='submit' value='" . _SUBMIT . "' /> |
||
| 190 | </form> |
||
| 191 | <form action='$realmyname' name='avaman_list' id='avaman_list' method='post'> |
||
| 192 | <table class='outer' id='avaman_main'> |
||
| 193 | <tr> |
||
| 194 | <th>" . _AM_AVAMAN_TH_ID . '</th> |
||
| 195 | <th>' . _AM_AVAMAN_TH_FILE . '</th> |
||
| 196 | <th>' . _AM_AVAMAN_TH_AVATARNAME . '</th> |
||
| 197 | <th>' . _AM_AVAMAN_TH_CREATED . '</th> |
||
| 198 | <th>' . _AM_AVAMAN_TH_DISPLAY . '</th> |
||
| 199 | <th>' . _AM_AVAMAN_TH_WEIGHT . '</th> |
||
| 200 | <th>' . _AM_AVAMAN_TH_USERS . '</th> |
||
| 201 | <th>' . _AM_AVAMAN_TH_DELETE . "<input type='checkbox' name='selectall' onclick=\"with(document.avaman_list){for (i=0;i<length;i++) {if(elements[i].type=='checkbox'&&elements[i].disabled==false&&elements[i].name.indexOf('deletes')>=0) {elements[i].checked=this.checked;}}}\" title='" |
||
| 202 | . _AM_AVAMAN_CB_SELECTALL . "' /></th> |
||
| 203 | </tr>\n"; |
||
| 204 | |||
| 205 | while (list($avatar_id, $avatar_file, $avatar_name, $avatar_created, $avatar_display, $avatar_weight, $avatar_users) = $db->fetchRow($result)) { |
||
| 206 | $evenodd = @$evenodd === 'even' ? 'odd' : 'even'; |
||
| 207 | $delete_disabled = $avatar_users > 0 ? "disabled='disabled'" : ''; |
||
| 208 | |||
| 209 | echo " |
||
| 210 | <tr> |
||
| 211 | <td class='$evenodd' align='center'>$avatar_id</td> |
||
| 212 | <td class='$evenodd' align='center'><img src='" . XOOPS_UPLOAD_URL . '/' . urlencode($avatar_file) . "' alt='' /></td> |
||
| 213 | <td class='$evenodd' align='center'><input type='text' size='24' name='avatar_names[$avatar_id]' value='" . htmlspecialchars($avatar_name, ENT_QUOTES) . "' /></td> |
||
| 214 | <td class='$evenodd' align='center'> " . formatTimestamp($avatar_created) . "</td> |
||
| 215 | <td class='$evenodd' align='center'><input type='checkbox' name='avatar_displays[$avatar_id]' " . ($avatar_display ? "checked='checked'" : '') . " /></td> |
||
| 216 | <td class='$evenodd' align='center'><input type='text' size='4' name='avatar_weights[$avatar_id]' value='$avatar_weight' style='text-align:right;' /></td> |
||
| 217 | <td class='$evenodd' align='center'>" . (int)$avatar_users . "</td> |
||
| 218 | <td class='$evenodd' align='center'><input type='checkbox' name='avatar_deletes[$avatar_id]' $delete_disabled /></td> |
||
| 219 | </tr>\n"; |
||
| 220 | } |
||
| 221 | echo " |
||
| 222 | </table> |
||
| 223 | <input type='submit' name='modify_avatars' value='" . _SUBMIT . "' /> |
||
| 224 | " . $xoopsGTicket->getTicketHtml(__LINE__) . ' |
||
| 225 | </form> |
||
| 226 | '; |
||
| 227 | |||
| 228 | include_once __DIR__ . '/admin_footer.php'; |
||
| 229 |
If you suppress an error, we recommend checking for the error condition explicitly: