XoopsModules25x /
xfguestbook
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 | namespace XoopsModules\Xfguestbook; |
||
| 4 | |||
| 5 | use XoopsModules\Xfguestbook; |
||
| 6 | use XoopsModules\Xfguestbook\Common; |
||
| 7 | use XoopsModules\Xfguestbook\Constants; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Class Utility |
||
| 11 | */ |
||
| 12 | class Utility extends Common\SysUtility |
||
| 13 | { |
||
| 14 | //--------------- Custom module methods ----------------------------- |
||
| 15 | |||
| 16 | public static function upload() |
||
| 17 | { |
||
| 18 | global $xoopsModule, $preview_name, $msgstop; |
||
| 19 | /** @var Helper $helper */ |
||
| 20 | $helper = Helper::getInstance(); |
||
| 21 | |||
| 22 | $created = \time(); |
||
| 23 | $ext = \preg_replace("/^.+\.([^.]+)$/sU", '\\1', $_FILES['photo']['name']); |
||
| 24 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
| 25 | $field = $_POST['xoops_upload_file'][0]; |
||
| 26 | if (!empty($field) || '' !== $field) { |
||
| 27 | // Check if file uploaded |
||
| 28 | if ('' === $_FILES[$field]['tmp_name'] || !\is_readable($_FILES[$field]['tmp_name'])) { |
||
| 29 | $msgstop .= \sprintf(MD_XFGUESTBOOK_FILEERROR, $helper->getConfig('photo_maxsize')); |
||
| 30 | } else { |
||
| 31 | $photos_dir = XOOPS_UPLOAD_PATH . '/' . $xoopsModule->getVar('dirname'); |
||
| 32 | $array_allowed_mimetypes = ['image/gif', 'image/pjpeg', 'image/jpeg', 'image/x-png']; |
||
| 33 | $uploader = new \XoopsMediaUploader($photos_dir, $array_allowed_mimetypes, $helper->getConfig('photo_maxsize'), $helper->getConfig('photo_maxwidth'), $helper->getConfig('photo_maxheight')); |
||
| 34 | if ($uploader->fetchMedia($field) && $uploader->upload()) { |
||
| 35 | if (null !== $preview_name) { |
||
| 36 | @\unlink("$photos_dir/" . $preview_name); |
||
|
0 ignored issues
–
show
|
|||
| 37 | } |
||
| 38 | $tmp_name = $uploader->getSavedFileName(); |
||
| 39 | $ext = \preg_replace("/^.+\.([^.]+)$/sU", '\\1', $tmp_name); |
||
| 40 | $preview_name = 'tmp_' . $created . '.' . $ext; |
||
| 41 | \rename("$photos_dir/$tmp_name", "$photos_dir/$preview_name"); |
||
| 42 | } else { |
||
| 43 | $msgstop .= $uploader->getErrors(); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param null $criteria |
||
| 51 | * @param int $limit |
||
| 52 | * @param int $start |
||
| 53 | * @return array |
||
| 54 | */ |
||
| 55 | public static function getCountry($criteria = null, $limit = 0, $start = 0) |
||
| 56 | { |
||
| 57 | global $xoopsDB, $action; |
||
| 58 | $ret = []; |
||
| 59 | $sql = 'SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_country'); |
||
| 60 | if (null !== $criteria && '' !== $criteria) { |
||
| 61 | $sql .= ' WHERE ' . $criteria; |
||
| 62 | } |
||
| 63 | $sql .= ' ORDER BY country_code ASC'; |
||
| 64 | $result = $xoopsDB->query($sql, $limit, $start); |
||
| 65 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 66 | $ret[] = $myrow; |
||
| 67 | } |
||
| 68 | |||
| 69 | return $ret; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param null $criteria |
||
| 74 | * @param int $limit |
||
| 75 | * @param int $start |
||
| 76 | * @return array |
||
| 77 | */ |
||
| 78 | public static function getAllCountry($criteria = null, $limit = 0, $start = 0) |
||
| 79 | { |
||
| 80 | global $xoopsDB, $action; |
||
| 81 | /** @var Helper $helper */ |
||
| 82 | $helper = Helper::getInstance(); |
||
| 83 | |||
| 84 | $ret = []; |
||
| 85 | $sql = 'SELECT country_code, country_name FROM ' . $xoopsDB->prefix('xfguestbook_country'); |
||
| 86 | if (null !== $criteria && '' !== $criteria) { |
||
| 87 | $sql .= ' WHERE ' . $criteria; |
||
| 88 | } |
||
| 89 | $sql .= ' ORDER BY country_code ASC'; |
||
| 90 | $result = $xoopsDB->query($sql, $limit, $start); |
||
| 91 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 92 | // $ret[$myrow['country_code']] = $myrow['country_name']; |
||
| 93 | $ret[$helper->getConfig('flagdir') . '/' . $myrow['country_code']] = $myrow['country_name']; |
||
| 94 | } |
||
| 95 | |||
| 96 | return $ret; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @param $user_id |
||
| 101 | * @return bool |
||
| 102 | */ |
||
| 103 | public static function get_user_data($user_id) |
||
| 104 | { |
||
| 105 | global $xoopsUser; |
||
| 106 | /** @var Helper $helper */ |
||
| 107 | $helper = Helper::getInstance(); |
||
| 108 | |||
| 109 | if (!(int)$user_id) { |
||
| 110 | return false; |
||
| 111 | } |
||
| 112 | |||
| 113 | $poster = new \XoopsUser($user_id); |
||
| 114 | if ($poster->isActive()) { |
||
| 115 | $xoopsUser ? $a_poster['poster'] = "<a href='../../userinfo.php?uid=$user_id'>" . $poster->uname() . '</a>' : $a_poster['poster'] = $poster->uname(); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 116 | if ($helper->getConfig('display_avatar')) { |
||
| 117 | $rank = $poster->rank(); |
||
| 118 | $rank['title'] ? $a_poster['rank'] = $rank['title'] : $a_poster['rank'] = ''; |
||
| 119 | $rank['image'] ? $a_poster['rank_img'] = "<img src='" . XOOPS_URL . '/uploads/' . $rank['image'] . '\' alt=\'\'>' : $a_poster['rank_img'] = ''; |
||
| 120 | $poster->user_avatar() ? $a_poster['avatar'] = "<img src='" . XOOPS_URL . '/uploads/' . $poster->user_avatar() . '\' alt=\'\'>' : $a_poster['avatar'] = ''; |
||
| 121 | } else { |
||
| 122 | $a_poster['rank'] = ''; |
||
| 123 | $a_poster['avatar'] = ''; |
||
| 124 | $a_poster['rank_img'] = ''; |
||
| 125 | } |
||
| 126 | |||
| 127 | return $a_poster; |
||
| 128 | } |
||
| 129 | |||
| 130 | return false; |
||
| 131 | } |
||
| 132 | |||
| 133 | // Effacement fichiers temporaires |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param $dir_path |
||
| 137 | * @param string $prefix |
||
| 138 | * @return int |
||
| 139 | */ |
||
| 140 | public static function clear_tmp_files($dir_path, $prefix = 'tmp_') |
||
| 141 | { |
||
| 142 | if (!($dir = @\opendir($dir_path))) { |
||
| 143 | return 0; |
||
| 144 | } |
||
| 145 | $ret = 0; |
||
| 146 | $prefix_len = mb_strlen($prefix); |
||
| 147 | while (false !== ($file = \readdir($dir))) { |
||
| 148 | // if (strncmp($file, $prefix, $prefix_len) === 0) { |
||
| 149 | if (0 === mb_strpos($file, $prefix)) { |
||
| 150 | if (@\unlink("$dir_path/$file")) { |
||
| 151 | $ret++; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | } |
||
| 155 | \closedir($dir); |
||
| 156 | |||
| 157 | return $ret; |
||
| 158 | } |
||
| 159 | |||
| 160 | // IP bannies (modérés automatiquement) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @param null $all |
||
| 164 | * @return array |
||
| 165 | */ |
||
| 166 | public static function get_badips($all = null) |
||
| 167 | { |
||
| 168 | global $xoopsDB; |
||
| 169 | $ret = []; |
||
| 170 | $sql = 'SELECT * FROM ' . $xoopsDB->prefix('xfguestbook_badips'); |
||
| 171 | $result = $xoopsDB->query($sql); |
||
| 172 | if ($all) { |
||
| 173 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 174 | $ret[] = $myrow; |
||
| 175 | } |
||
| 176 | } else { |
||
| 177 | while (list($ip_id, $ip_value) = $xoopsDB->fetchRow($result)) { |
||
| 178 | $ret[] = $ip_value; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | return $ret; |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @param $email |
||
| 187 | * @return bool |
||
| 188 | */ |
||
| 189 | public static function email_exist($email) |
||
| 190 | { |
||
| 191 | if (!\filter_var($email, \FILTER_VALIDATE_EMAIL)) { |
||
| 192 | return false; |
||
| 193 | } |
||
| 194 | |||
| 195 | if (!\checkdnsrr(\array_pop(\explode('@', $email)), 'MX')) { |
||
| 196 | return false; |
||
| 197 | } |
||
| 198 | |||
| 199 | return true; |
||
| 200 | } |
||
| 201 | } |
||
| 202 |
If you suppress an error, we recommend checking for the error condition explicitly: