Skip to content

Commit

Permalink
Fixes #83: Wrong string handling for IPv6 adresses and IPv4 addresses…
Browse files Browse the repository at this point in the history
… with ::ffff: prefix
  • Loading branch information
Jefferson49 committed Feb 3, 2024
1 parent 0108f8d commit deda6fa
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions com_sexypolling/modules/module/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ public static function voteAjax(): void
$datenow_sql = HTMLHelper::date($current_date, "Y-m-d", $data_time_zone);

//get ip address
$REMOTE_ADDR = null;
if($server->get('HTTP_X_FORWARDED_FOR') !== null) { list($REMOTE_ADDR) = explode(',', $server->get('HTTP_X_FORWARDED_FOR')); }
elseif($server->get('HTTP_X_REAL_IP') !== null) { $REMOTE_ADDR = $server->get('HTTP_X_REAL_IP'); }
elseif($server->get('REMOTE_ADDR') !== null) { $REMOTE_ADDR = $server->get('REMOTE_ADDR'); }
$REMOTE_ADDR = 'Unknown';
if($server->get('HTTP_X_FORWARDED_FOR') !== null) { list($REMOTE_ADDR) = explode(',', $server->getString('HTTP_X_FORWARDED_FOR', 'Unknown')); }
elseif($server->get('HTTP_X_REAL_IP') !== null) { $REMOTE_ADDR = $server->getString('HTTP_X_REAL_IP', 'Unknown'); }
elseif($server->get('REMOTE_ADDR') !== null) { $REMOTE_ADDR = $server->getString('REMOTE_ADDR', 'Unknown'); }
else { $REMOTE_ADDR = 'Unknown'; }
$ip = $REMOTE_ADDR;

$countryname = $post->get('country_name', 'Unknown');
$countryname = $countryname === "" ? 'Unknown' : $countryname;
$cityname = $post->get('city_name', 'Unknown');
$cityname = $cityname === "" ? 'Unknown' : $cityname;
$regionname = $post->get('region_name', 'Unknown');
$regionname = $regionname === "" ? 'Unknown' : $regionname;
$countrycode = $post->get('country_code', 'Unknown');
$countrycode = $countrycode === "" ? 'Unknown' : $countrycode;
$countryname = $post->getString('country_name', 'Unknown');
$countryname = in_array($countryname, ["", "-"]) ? 'Unknown' : $countryname;
$cityname = $post->getString('city_name', 'Unknown');
$cityname = in_array($cityname, ["", "-"]) ? 'Unknown' : $cityname;
$regionname = $post->getString('region_name', 'Unknown');
$regionname = in_array($regionname, ["", "-"]) ? 'Unknown' : $regionname;
$countrycode = $post->getString('country_code', 'Unknown');
$countrycode = in_array($countrycode, ["", "-"]) ? 'Unknown' : $countrycode;

$ip = $db->escape($ip);
$countryname = $db->escape($countryname);
Expand Down Expand Up @@ -435,10 +435,10 @@ public static function addanswerAjax(): void
$datenow_sql = HTMLHelper::date($current_date, "Y-m-d", $data_time_zone);

//get ip address
$REMOTE_ADDR = null;
if($server->get('HTTP_X_FORWARDED_FOR') !== null) { list($REMOTE_ADDR) = explode(',', $server->get('HTTP_X_FORWARDED_FOR')); }
elseif($server->get('HTTP_X_REAL_IP') !== null) { $REMOTE_ADDR = $server->get('HTTP_X_REAL_IP'); }
elseif($server->get('REMOTE_ADDR') !== null) { $REMOTE_ADDR = $server->get('REMOTE_ADDR'); }
$REMOTE_ADDR = 'Unknown';
if($server->get('HTTP_X_FORWARDED_FOR') !== null) { list($REMOTE_ADDR) = explode(',', $server->getString('HTTP_X_FORWARDED_FOR', 'Unknown')); }
elseif($server->get('HTTP_X_REAL_IP') !== null) { $REMOTE_ADDR = $server->getString('HTTP_X_REAL_IP', 'Unknown'); }
elseif($server->get('REMOTE_ADDR') !== null) { $REMOTE_ADDR = $server->getString('REMOTE_ADDR', 'Unknown'); }
else { $REMOTE_ADDR = 'Unknown'; }
$ip = $REMOTE_ADDR;

Expand All @@ -462,14 +462,14 @@ public static function addanswerAjax(): void
exit();
}

$countryname = $post->get('country_name', 'Unknown');
$countryname = $countryname === "" ? 'Unknown' : $countryname;
$cityname = $post->get('city_name', 'Unknown');
$cityname = $cityname === "" ? 'Unknown' : $cityname;
$regionname = $post->get('region_name', 'Unknown');
$regionname = $regionname === "" ? 'Unknown' : $regionname;
$countrycode = $post->get('country_code', 'Unknown');
$countrycode = $countrycode === "" ? 'Unknown' : $countrycode;
$countryname = $post->getString('country_name', 'Unknown');
$countryname = in_array($countryname, ["", "-"]) ? 'Unknown' : $countryname;
$cityname = $post->getString('city_name', 'Unknown');
$cityname = in_array($cityname, ["", "-"]) ? 'Unknown' : $cityname;
$regionname = $post->getString('region_name', 'Unknown');
$regionname = in_array($regionname, ["", "-"]) ? 'Unknown' : $regionname;
$countrycode = $post->getString('country_code', 'Unknown');
$countrycode = in_array($countrycode, ["", "-"]) ? 'Unknown' : $countrycode;

$ip = $db->escape($ip);
$countryname = $db->escape($countryname);
Expand Down Expand Up @@ -585,9 +585,16 @@ public static function addanswerAjax(): void
*/
public static function geoipAjax(): void
{
$app = Factory::getApplication();
$ip = $app->input->server->get('REMOTE_ADDR');
$server = Factory::getApplication()->input->server;

//get ip address
$REMOTE_ADDR = 'Unknown';
if($server->get('HTTP_X_FORWARDED_FOR') !== null) { list($REMOTE_ADDR) = explode(',', $server->getString('HTTP_X_FORWARDED_FOR', 'Unknown')); }
elseif($server->get('HTTP_X_REAL_IP') !== null) { $REMOTE_ADDR = $server->getString('HTTP_X_REAL_IP', 'Unknown'); }
elseif($server->get('REMOTE_ADDR') !== null) { $REMOTE_ADDR = $server->getString('REMOTE_ADDR', 'Unknown'); }
else { $REMOTE_ADDR = 'Unknown'; }
$ip = $REMOTE_ADDR;

$url = 'http://api.ipinfodb.com/v3/ip-city/?key=4f01028c9fcae27423d5d0cc4489b5679f26febf98d28b90a29c2f3f7531aafd&format=json&ip=' . $ip;
$ch = curl_init ($url) ;
curl_setopt($ch, CURLOPT_URL, $url);
Expand Down

0 comments on commit deda6fa

Please sign in to comment.