5 // check for bad agents immidietly
7 if($blockbadagents == 1) {
8 // those metaquery assholes at t-dialin and others can't
9 // get another dumber using the default user-agent, can they?
11 $agent = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
14 strstr("libwww-perl", $agent) ||
15 strstr("lwp-trivial", $agent) ||
16 strstr("LWP::Simple", $agent) ||
17 strstr("PHP/", $agent)) {
26 function s10_rfc_1918_ip($in) {
28 if (ereg('^(127\.)', $in, $part)) {
32 if (ereg('^(10\.)', $in, $part)) {
36 if (ereg('^(192\.168\.)', $in, $part)) {
40 if (ereg('^(172\.)' . '([0-9]{1,3})', $in, $part)) {
41 if(($part[2] > 15) and ($part[2] < 32)) {
50 function stuffanalyze($stuff) {
52 $stuff2[0] = array_values(preg_grep ("/CITY:/", $stuff)) or die("Sorry, but the lookup for this IP address failed! (CITY)");
53 $stuff2[1] = array_values(preg_grep ("/STATE:/", $stuff)) or die("Sorry, but the lookup for this IP address failed! (STATE)");
54 $stuff2[2] = array_values(preg_grep ("/COUNTRY:/", $stuff)) or die("Sorry, but the lookup for this IP address failed! (COUNTRY)");
55 $stuff2[3] = array_values(preg_grep ("/LAT:/", $stuff)) or die("Sorry, but the lookup for this IP address failed! (LAT)");
56 $stuff2[4] = array_values(preg_grep ("/LONG:/", $stuff)) or die("Sorry, but the lookup for this IP address failed! (LONG)");
58 // all the stuff2 values are actually arrays, making the following code look like crap
60 // the power of $count
62 if(isset($stuff2[0][0])) {
64 for ($count = 0; $count < count($stuff2); $count++) {
65 $stuff2[$count] = $stuff2[$count][0];
66 $stuff2[$count] = ucwords(strtolower(trim(substr(substr($stuff2[$count], 15), 0, -5))));
71 // if no data was found
72 $stuff2 = array("bad", "bad", "bad", "bad", "bad");
82 function getlatdata($ip) {
84 global $firewall_host;
85 global $firewall_port;
93 $fp = fsockopen ($firewall_host, $firewall_port, $errno, $errstr, 30) or die("Could not open socket to proxy");
95 echo "$errstr ($errno)<br/>\n";
97 fputs ($fp, "GET http://netgeo.caida.org/perl/netgeo.cgi?target=$ip HTTP/1.0\r\nHost: netgeo.caida.org\r\n\r\n") or die("Could not write to socket");
99 $packet = fgets ($fp,128) or die("Could not read from socket");
100 array_push($data, $packet) or die("Could not push data into array");
107 $fp = fsockopen ("netgeo.caida.org", 80, $errno, $errstr, 30) or die("Could not open socket to caida.org");
109 echo "$errstr ($errno)<br/>\n";
111 fputs ($fp, "GET /perl/netgeo.cgi?target=$ip HTTP/1.0\r\nHost: netgeo.caida.org\r\n\r\n") or die("Could not write to socket");
113 $packet = fgets ($fp,128) or die("Could not read from socket");
114 array_push($data, $packet) or die("Could not push socket data into array");
127 function finddot($name, $cssdots, $defaultdot) {
128 foreach($cssdots as $x) {
129 list($filename, , $width, $height) = split(":", $x);
130 if($filename == $name) { $found = 1; $return = array($name, $width, $height); }
135 $dott = $cssdots[$defaultdot];
136 list($dott, , $width, $height) = split(":", $dott);
137 return array($dott, $width, $height);
141 function getlocationcoords($lat, $lon, $width, $height) {
142 // some cartographers weren't mathematicians, up is apparently negative to them
147 $x = ($lon * ($width / 360));
148 $y = ($lat * ($height / 180));
152 return array($x, $y);
155 function getimagecoords($earthimages, $image) {
156 foreach($earthimages as $x) {
157 list($file, , $width, $height) = split(":", $x);
158 if($file == $image) {
159 $coords = array("$width", "$height");
165 function validcookie($cookie) {
166 if(preg_match("/.*.:.*.:.*.:.*.:.*./", $cookie)) {
173 function isvalidimage($cookie, $earthimages, $defaultimage) {
174 # list(, , , $setearthimage) = split(":", $cookie);
175 $setearthimage = $cookie;
176 if(isset($setearthimage)) {
177 // check if the image is one actually defined, not a cookie edit
178 foreach($earthimages as $image) {
179 list($testearthimage, , , ) = split(":", $image);
180 if($testearthimage == $setearthimage) {
185 return $setearthimage;
187 return $earthimages[$defaultimage];
190 return $earthimages[$defaultimage];
196 function istheregd() {
199 if (@ImageTypes() & IMG_PNG) {
209 function checkbrowser($agent) {
210 if (strstr($agent, "Mozilla/4.7") || strstr($agent, "Opera 6") || strstr($agent, "Opera/6")) {
217 function shouldrun($agent) {
219 // could cause probs... dunno
220 global $HTTP_COOKIE_VARS;
222 // check for new format of cookie with 6 parameters
223 if(@preg_match("/.*.:.*.:.*.:.*.:.*.:.*./", $HTTP_COOKIE_VARS["atlasprefs"])) {
224 list( , , , , , $drawmode) = split(":", $HTTP_COOKIE_VARS["atlasprefs"]);
229 // don't try to understand below, it figures out whether
230 // to run it in css or gd based of prefs, server ability, and user agent.
232 if(istheregd() && ($drawmode == "1")) {
234 } elseif($drawmode == "0") {
236 } elseif(checkbrowser($agent) && istheregd()) {
238 } elseif(!checkbrowser($agent)) {
240 } elseif (!istheregd()) {
247 function s10_validate_ip($in) {
248 if (is_string($in) && ereg('^([0-9]{1,3})\.([0-9]{1,3})\.' .
249 '([0-9]{1,3})\.([0-9]{1,3})$' ,
251 if ($part[1] <= 255 && $part[2] <= 255 &&
252 $part[3] <= 255 && $part[4] <= 255)
258 function getstuff($address, $local) {
260 $address = trim($address);
262 # some people still think that urls are hostnames
263 $address = str_replace("http://", "", $address);
264 $address = preg_replace("/\/.*$/", "", $address);
267 $address = escapeshellcmd($address);
271 $values["address"] = $address;
273 if(eregi("[a-z]", $address)){
274 $ipaddress = gethostbyname($address);
276 if($ipaddress == $address) {
278 $values["validity"] = "no";
282 $values["hostname"] = $address;
284 $values["ishost"] = "yes";
288 if(s10_validate_ip($address)) {
290 $ipaddress = $address;
291 $values["hostname"] = "";
293 $values["validity"] = "no";
298 if(!isset($values["validity"])) {
299 if(s10_rfc_1918_ip($ipaddress)) {
308 if(!isset($ipaddress)) { $ipaddress = ""; }
310 $values["ipaddress"] = $ipaddress;
312 if(!isset($values["validity"]) && ($private == "no")) {
314 $stuff = getlatdata($ipaddress);
324 ) = stuffanalyze($stuff);
328 // check if it is the user's ip address
329 if($local == 1) { $desc .= t("You at"); }
331 // add the ip address and hostname
332 $desc .= "<b>$values[hostname]</b> (<b>$values[ipaddress]</b>) ";
334 // use "are" if it is the user's ip address
335 if($local == 1) { $desc .= t("are"); } else { $desc .= t("is"); }
337 $desc .= " ".t("located in")." ";
339 // add the city if it's there
340 if($values["city"]) {
341 $desc .= "$values[city], ";
344 // add the state if its there
345 if($values["state"]) {
346 $desc .= "$values[state], ";
349 if($values["country"]) {
350 // make the country code capital so its ready for lookup
351 $values["country"] = strtoupper($values["country"]);
352 // convert the country code to a country name
353 $countries = file("countries.txt") or die("Could not open countries file");
354 $precountry = array_values(preg_grep("/$values[country] /", $countries));
355 $values["country"] = trim(substr($precountry[0], 4));
356 $desc .= "$values[country].";
359 $desc .= " <font color=\"#aaaaaa\">($values[lat], $values[lon])</font>";
361 $state = $values["state"];
362 $city = $values["city"];
364 // decide if address can't resolve, be located, or if it's fine
365 if($values["lat"] == "0.00" && $values["lon"] == "0.00" && (@($state != "bad" && $city != "bad"))) {
366 $values["desc"] = "<b>$values[address]</b> ".t("cannot be located.");
369 } elseif($values["lat"] == "" && $values["lon"] == "") {
370 $values["desc"] = "<b>$values[address]</b> ".t("cannot be located.");
372 $values["desc"] = $desc;
377 // check if it was a host before and decide on an error message
379 if($private == "yes") {
380 $values["desc"] = "<b>$address</b> ".t("is a host in the private IP address range.");
381 } elseif(@($values["state"] == "bad" && $values["city"] == "bad")) {
382 $values["desc"] = t("Temporary lookup failure.");
383 } elseif(isset($values["ishost"])) {
384 $values["desc"] = "<b>$address</b> ".t("does not resolve.");
386 $values["desc"] = "<b>$address</b> ".t("is not a valid IP address.");
389 // some blank lat/lon for the image script or it will plot us in the center