function CID_get_country($ip) { require_once dirname(__FILE__) . '/ip2c/ip2c.php'; if (isset($GLOBALS['ip2c'])) { global $ip2c; } else { $ip2c = new ip2country(dirname(__FILE__) . '/ip2c/ip-to-country.bin'); $GLOBALS['ip2c'] = $ip2c; } return $ip2c->get_country($ip); }
function getIpAddrCountry($ipAddress) { $ip2c = new ip2country("include/ip-to-country.bin"); $res = $ip2c->get_country($ipAddress); if ($res == false) { return "Unknown"; } else { $country = $res['name']; if ($country == "") { $country = "Unknown"; } return $country; } }
function mystique_get_flag($ip) { require_once 'ip2c/ip2c.php'; if (isset($GLOBALS['ip2c'])) { global $ip2c; } else { $ip2c = new ip2country(TEMPLATEPATH . '/extensions/ip2country/ip2c/ip-to-country.bin'); $GLOBALS['ip2c'] = $ip2c; } $country = $ip2c->get_country($ip); if ($country) { $code = strtolower($country['id2']); $name = ucwords(strtolower($country['name'])); return array('code' => $code, 'name' => $name); } else { return false; } }
function get_user_timezone() { if (!isset($_SESSION['timezone'])) { include_once "ip2c/ip2country.php"; if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') { $_SESSION['timezone'] = ini_get('date.timezone'); } else { $ip2country = new ip2country(); $timezone = $ip2country->get_country_timezonename(); if ($timezone) { $_SESSION['timezone'] = $timezone; } else { $_SESSION['timezone'] = ini_get('date.timezone'); } } } }
function read3cCode() { fread($this->m_file, 1); $d = fread($this->m_file, 3); return $d != ' ' ? $d : ''; } function readCountryKey() { return fread($this->m_file, 2); } function readInt() { $a = unpack('N', fread($this->m_file, 4)); return $a[1]; } function seek($offset) { fseek($this->m_file, $offset); } } $ip2c = new ip2country(); if (empty($_GET['ip'])) { $_GET['ip'] = $_SERVER["REMOTE_ADDR"]; } $res = $ip2c->get_country($_GET['ip']); if ($res == false) { $c = "unknown"; } else { $c = strtolower($res['id2']); } header("Location: flags/{$c}.png");
try { $q = "SELECT * FROM `access` ORDER BY `id` DESC"; $q_do = $db->prepare($q); $q_do->execute(); $number = $db->query("SELECT FOUND_ROWS()")->fetchColumn(); } catch (PDOException $e) { $log->logError($e . " - " . basename(__FILE__)); } echo "<div class=\"page-header\"><h1>" . _("Access Logs") . "</h1></div>"; echo "<h6>" . _("Options") . " : <a href=\"{$website}/" . ADMIN_DIRECTORY . "/settings#/misc\">" . _("Access Settings") . "</a></h6><br/>"; echo "<ul class=\"breadcrumb\">\n\t\t<li><a href=\"{$website}/" . ADMIN_DIRECTORY . "/settings\">" . _("Home") . "</a> <span class=\"divider\">/</span></li>\n\t\t<li class=\"active\">" . _("Access Logs") . "</li>\n\t\t</ul>"; if (!empty($number)) { /* initializing the ip2country class for converting ip address to country. */ $ip2country = new ip2country($db); $p = new pagination(); $p->items($number); $p->limit($max_show); $p->currentPage($page); $p->parameterName("p"); $p->urlFriendly(); $p->target("{$website}/" . ADMIN_DIRECTORY . "/access/%"); $from2 = $page * $max_show; if ($from2 > $number) { $diff = $number % $max_show; $from2 = $number; $from1 = $from2 - $diff; } else { $from1 = $from2 - $max_show; }
<?php require_once 'ip2c.php'; set_time_limit(0); $ip2c = new ip2country(); $ips = array(); $len = 100000; echo "Generating {$len} random IP addresses...."; flush(); for ($i = 0; $i < $len; $i++) { $ips[$i] = mt_rand(0, 255) . "." . mt_rand(0, 255) . "." . mt_rand(0, 255) . "." . mt_rand(0, 255); } echo "Done<br/>Resolving addresses:<br/>"; $now = microtime_float(); $progress = $len / 20; for ($i = 0; $i < $len; $i++) { if ($i % $progress == 0) { echo $i . " done<br/>"; flush(); } $ip2c->get_country($ips[$i]); } echo "now " . microtime_float() . "<br/>"; echo "before " . $now . "<br/>"; $t = microtime_float() - $now; echo "Took " . $t . " for {$len} searches (" . $len / $t . " searches/sec)"; function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; }
<?php error_reporting(E_ALL | (defined('E_STRICT') ? E_STRICT : 0)); require_once 'ip2c.php'; $ip = htmlentities(isset($_GET['ip']) ? $_GET['ip'] : $_SERVER['REMOTE_ADDR']); $ip2c = new ip2country("../ip-to-country.bin"); var_dump($ip2c->find_country_impl(16981, 0, $ip2c->m_numCountries)); return; $res = $ip2c->get_country($ip); if ($res == false) { echo "{$ip} => not found"; } else { $o2c = $res['id2']; $o3c = $res['id3']; $oname = $res['name']; echo "{$ip} => {$o2c} {$o3c} {$oname}"; }
private function ip_server($ip) { if ($this->ip_valid($ip)) { if (class_exists('ip2country')) { $ip2country = new ip2country(); $ip2country->ip_country($ip); $registry = $ip2country->registry; } else { //http://www.team-cymru.org/Services/ip-to-asn.html $results = dns_get_record($this->ip_reverse($ip) . '.origin.asn.cymru.com', DNS_TXT); $results_a = explode('|', $results[0]['txt']); $registry = trim($results_a[3]); } switch ($registry) { case "ripencc": return "whois.ripe.net"; case "apnic": return "whois.apnic.net"; case "arin": return "whois.arin.net"; case "lacnic": return "whois.lacnic.net"; case "afrinic": return "whois.afrinic.net"; default: return false; } } return false; //IP number not valid }
/** * helper */ function countryByIp($ip) { if ($ip == '127.0.0.1') { /* ignore localhost */ return; } $query3 = sprintf("select ip, country from #__joomlawatch where (ip = '%s' and country is not NULL) limit 1", JoomlaWatchHelper::sanitize($ip)); $this->database->setQuery($query3); $this->database->query(); $row3 = $this->database->loadResult(); if (@(!$row3->country)) { $iplook = new ip2country($ip); $iplook->UseDB = true; $iplook->db_tablename = "#__joomlawatch_ip2c"; if ($iplook->LookUp()) { $country = strtolower($iplook->Country); $query3 = sprintf("update #__joomlawatch set country = '%s' where ip = '%s'", JoomlaWatchHelper::sanitize($country), JoomlaWatchHelper::sanitize($ip)); $this->database->setQuery($query3); $this->database->query(); } } else { $country = $row3->country; } return @$country; }
function admin_edit_user($id) { global $db, $err, $log, $website; $current_url = current_url(); try { $sql = "SELECT * FROM `members` WHERE `id` = :id"; $sql_do = $db->prepare($sql); $sql_do->bindParam(':id', $id, PDO::PARAM_INT); $sql_do->execute(); $number = $db->query("SELECT FOUND_ROWS()")->fetchColumn(); } catch (PDOException $e) { $log->logError($e . " - " . basename(__FILE__)); } if (!empty($number)) { $f = $sql_do->fetch(PDO::FETCH_ASSOC); $verified = intval($f['verified']); $email_user = cleanInput($f['email']); $first_name = cleanInput($f['first_name']); $last_name = cleanInput($f['last_name']); $banned = intval($f['banned']); $joined_on = cleanInput($f['join']); $last_access = cleanInput($f['access']); $user_bio = cleanInput($f['bio']); /* displaying gravatar photo over here if email is associated with a gravatar account. */ $default = $website . "/images/anonuser_50px.gif"; $gravatar = new Gravatar($email_user, $default); $gravatar->size = 50; ?> <div class="page-header no-border"> <h1><img class="profilephoto thumbnail" src="<?php echo $gravatar->getSrc(); ?> " /> <?php echo $first_name . " " . $last_name; ?> </h1> </div> <?php echo "<ul class=\"breadcrumb\">\n<li><a href=\"{$website}/" . ADMIN_DIRECTORY . "/settings\">" . _("Home") . "</a> <span class=\"divider\">/</span></li>\n<li><a href=\"{$website}/" . ADMIN_DIRECTORY . "/users\">" . _("Users") . "</a> <span class=\"divider\">/</span></li>\n<li class=\"active\">{$first_name} {$last_name}</li>\n</ul>"; ?> <div class="tabs-left"> <ul class="nav nav-tabs" id="usermanage"> <li class="active"><a href="#general" data-toggle="tab"><i class="icon-cog"></i> <?php echo _("General"); ?> </a></li> <li><a href="#profile" data-toggle="tab"><i class="icon-user"></i> <?php echo _("Profile"); ?> </a></li> <li><a href="#logs" data-toggle="tab"><i class="icon-list-alt"></i> <?php echo _("Access Logs"); ?> </a></li> </ul> <form class="form-horizontal" method="POST" action="<?php echo $current_url; ?> "> <div class="tab-content"> <div class="tab-pane active" id="general"> <fieldset> <legend><?php echo _("General"); ?> </legend> <?php echo $err; ?> <div class="control-group"> <label class="control-label" for="first_name"><?php echo _("First Name"); ?> </label> <div class="controls"> <input type="text" class="input-xlarge" id="first_name" name="first_name" value="<?php echo $first_name; ?> "> </div> </div> <div class="control-group"> <label class="control-label" for="last_name"><?php echo _("Last Name"); ?> </label> <div class="controls"> <input type="text" class="input-xlarge" id="last_name" name="last_name" value="<?php echo $last_name; ?> "> </div> </div> <div class="control-group"> <label class="control-label" for="email"><?php echo _("Email"); ?> </label> <div class="controls"> <input type="text" class="input-xlarge disabled" id="email" name="email" value="<?php echo $email_user; ?> " disabled> </div> </div> <div class="control-group"> <label class="control-label" for="pass"><?php echo _("Password"); ?> </label> <div class="controls"> <input type="text" class="input-xlarge disabled" id="pass" name="pass" value="<?php echo $f['password']; ?> " disabled> </div> </div> <div class="control-group"> <label class="control-label" for="verified"><?php echo _("Verified"); ?> </label> <div class="controls"> <select name="verified" id="verified"> <option value="1"<?php if ($verified == 1) { echo " selected=\"selected\""; } ?> ><?php echo _("Yes"); ?> </option> <option value="0"<?php if ($verified == 0) { echo " selected=\"selected\""; } ?> ><?php echo _("No"); ?> </option> </select> </div> </div> <div class="control-group"> <label class="control-label" for="join"><?php echo _("Joined On"); ?> </label> <div class="controls"> <input type="text" class="input-xlarge disabled" id="join" name="join" value="<?php echo $joined_on; ?> " disabled> </div> </div> <div class="control-group"> <label class="control-label" for="access"><?php echo _("Last Access"); ?> </label> <div class="controls"> <input type="text" class="input-xlarge disabled" id="access" name="access" value="<?php echo $last_access; ?> " disabled> </div> </div> <div class="control-group"> <label class="control-label" for="ban"><?php echo _("Banned"); ?> </label> <div class="controls"> <select name="ban" id="ban"> <option value="1"<?php if ($banned == 1) { echo " selected=\"selected\""; } ?> ><?php echo _("Yes"); ?> </option> <option value="0"<?php if ($banned == 0) { echo " selected=\"selected\""; } ?> ><?php echo _("No"); ?> </option> </select> </div> </div> </fieldset> </div> <div class="tab-pane" id="profile"> <fieldset> <legend><?php echo _("Profile"); ?> </legend> <?php echo $err; ?> <div class="control-group"> <label class="control-label" for="bio"><?php echo _("Bio"); ?> </label> <div class="controls"> <textarea class="input-xxlarge" id="bio" name="bio" rows="8"><?php echo $user_bio; ?> </textarea> </div> </div> </fieldset> </div> <div class="tab-pane" id="logs"> <fieldset> <legend><?php echo _("Access Logs"); ?> </legend> <?php try { $q = "SELECT * FROM `access` WHERE `userid` = :userid ORDER BY `id` DESC"; $q_do = $db->prepare($q); $q_do->bindParam(':userid', $id, PDO::PARAM_INT); $q_do->execute(); $number = $db->query("SELECT FOUND_ROWS()")->fetchColumn(); } catch (PDOException $e) { $log->logError($e . " - " . basename(__FILE__)); } if (!empty($number)) { echo "<table class=\"table table-condensed\">\n\t\t\t<thead>\n\t\t\t<tr>\n\t\t\t<th>" . _("IP Address") . "</th>\n\t\t\t<th>" . _("Country") . "</th>\n\t\t\t<th>" . _("Access") . "</th>\n\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t<tbody>"; /* initializing the ip2country class for converting ip address to country. */ $ip2country = new ip2country($db); /* displaying the information in a while loop. */ while ($row = $q_do->fetch(PDO::FETCH_ASSOC)) { $ip = cleanInput($row['ip_address']); $date = cleanInput($row['datetime']); /* fetching country name for the specific ip address */ $country = $ip2country->get_country_name($ip); echo "<tr>"; echo "<td>{$ip}</td>"; echo "<td>{$country}</td>"; echo "<td><abbr class=\"micro\" title=\"{$date}\"></abbr></td>"; echo "</tr>"; } echo "</tbody>\n\t\t\t</table>"; } else { echo "<div class=\"alert\"><strong>" . _("No Access Records.") . "</strong><br/>" . _("There are no access records for this user in the database.") . "</div>"; } ?> </fieldset> </div> <div class="form-actions"> <input type="submit" class="btn btn-primary" name="edituser" value="<?php echo _("Update User"); ?> "> </div> </div> </form> </div> <?php } else { echo "<div class=\"alert alert-error\"><strong>" . _("Not Found.") . "</strong><br/>" . _("User does not exist in the database. There are no records matching the user ID specified.") . "</div>"; } }