[GRASS-SVN] r29892 - grass-web/trunk
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 29 16:05:29 EST 2008
Author: neteler
Date: 2008-01-29 16:05:29 -0500 (Tue, 29 Jan 2008)
New Revision: 29892
Modified:
grass-web/trunk/index.php
Log:
replaced insecure fopen with cURL; fancy mirror detection
Modified: grass-web/trunk/index.php
===================================================================
--- grass-web/trunk/index.php 2008-01-29 10:50:56 UTC (rev 29891)
+++ grass-web/trunk/index.php 2008-01-29 21:05:29 UTC (rev 29892)
@@ -34,18 +34,30 @@
<center><br>
<h1>Welcome to GRASS GIS</h1>
<?php
+$ch = curl_init();
$MYIP = $_SERVER['SERVER_ADDR'];
-$file = fopen ("http://api.hostip.info/get_html.php?ip=$MYIP", "r");
-if (!$file) {
+$timeout = 5; // set to zero for no timeout
+curl_setopt ($ch, CURLOPT_URL, "http://api.hostip.info/get_html.php?ip=$MYIP");
+curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
+curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
+$file_contents = curl_exec($ch);
+curl_close($ch);
+
+if (!$file_contents) {
echo "[unknown mirror country]\n";
exit;
}
-$line = fgets ($file, 34);
-$MYSTATETMP = explode(":", $line);
-$MYSTATE = $MYSTATETMP[1];
-echo "<font size=\"-1\"><i>You are at the official GRASS site in $MYSTATE (or
- a <a href=\"mirrors.php\">mirror site</a>)<br>";
-fclose($file);
+// e.g.: "Country: UNITED STATES (US) City: San Diego, CA"
+$MYSTATETMP = explode(":", $file_contents);
+$MYSTATETMP2 = explode(")", $MYSTATETMP[1]);
+$MYSTATE = $MYSTATETMP2[0] . ")";
+if ($MYIP == "198.202.74.219")
+ echo "<font size=\"-1\"><i>You are at the official GRASS site in $MYSTATE
+ (<a href=\"mirrors.php\">mirror sites</a>)<br>";
+else
+ echo "<font size=\"-1\"><i>You are at a GRASS mirror site in $MYSTATE (other
+ <a href=\"mirrors.php\">mirror sites</a>)<br>";
+
?>
This site is updated daily: LASTUPDATED</i> <!-- processed by cron/sed -->
</font>
More information about the grass-commit
mailing list