Author: Derick Rethans (derickr)
Date: 2024-11-27T10:21:41Z

Commit: 
https://github.com/php/web-master/commit/2ba3496d388369512cec1ad66caa326bdd57f177
Raw diff: 
https://github.com/php/web-master/commit/2ba3496d388369512cec1ad66caa326bdd57f177.diff

Remove the ip-to-country fetching.

This script tries to obtain a database from an URL that returns a 404. This
functionality was only really used for re-directing to a mirror, but we long
ago discontinued the mirror system.

Now all it does is set a COUNTRY cookie with "NA," + IP-address in several
headers, and we should remove that too.

Changed paths:
  D  scripts/ip-to-country
  M  scripts/update-backend


Diff:

diff --git a/scripts/ip-to-country b/scripts/ip-to-country
deleted file mode 100644
index 5388690..0000000
--- a/scripts/ip-to-country
+++ /dev/null
@@ -1,155 +0,0 @@
-<?php /* vim: set noet ts=4 sw=4 ft=php: : */
-
-// This script will only work if included from "update-backend"!
-
-// Fetch ip-to-country.com data and index database
-function fetch_ip_to_country($root)
-{
-    // Files used / affected
-    $ipdbt   = "ip-to-country.db~";
-    $ipdbc   = "ip-to-country.dbr~";
-    $ipdb    = "$root/backend/ip-to-country.db";
-    $ipidx   = "$root/backend/ip-to-country.idx";
-
-    // Create one index entry for at least
-    // every '$indexby'th record in the db
-    $indexby = 10000000;
-
-    // Get last modified date of ip-to-country data
-    if (file_exists($ipdb)) { $lastmod = filemtime($ipdb); }
-    else { $lastmod = 0; }
-
-    // Fetch data from server to local temporary file
-    $succ = fetch_into_file("http://www.directi.com/iptocountry/"; .
-                            "?site=php.net&dbformat=1&lastupdate=" .
-                            $lastmod, $ipdbt); 
-
-    // No success in getting the DB
-    if (!$succ) { return FALSE; }
-    
-    /*
-     The following code checks the structure of the file
-     received. If this is an updated data file, then it
-     should start with a given line and end with a given line,
-     and all lines inside should be 24 bytes long with a
-     specific format. If the data received is not in this
-     format, then we reject to replace the old file with this.
-    */
-                    
-    // Open temporary database for reading
-    $ipdbf = @fopen($ipdbt, "r");
-    if (!$ipdbf) { die("Unable to open '$ipdbt' for reading"); }
-    
-    // Open local rewritten database for writing
-    $ipdbcf = @fopen($ipdbc, "w");
-    if (!$ipdbcf) { die("Unable to open '$ipdbc' for writing"); }
-    
-    // Initial state is the first line and
-    // the file is expected to be ok
-    $state = 'firstline'; $fileok = TRUE;
-    
-    // While we can read a line from the file 
-    while (!feof($ipdbf) && ($line = fgets($ipdbf))) {
-        
-        // Check the input depending on the state
-        switch ($state) {
-            
-            // First line is defined, and after it we
-            // switch to the 'data' state
-            case 'firstline' : 
-                if (trim($line) != "#Directi IP-to-Country Db: Start") {
-                    $fileok = FALSE;
-                    break 2;
-                } else { $state = 'data'; }
-                break;
-            
-            // In the data state we either get the last line,
-            // or we get a data line containing 24 bytes, in
-            // which case we write it out to the local rewritten
-            // database
-            case 'data' :
-                if (trim($line) == "#Directi IP-to-Country Db: End") {
-                    $state = 'lastline';
-                } elseif (!preg_match("!\\d{20}\\w{3}\n!", $line)) {
-                    $fileok = FALSE;
-                    break 2;
-                } else {
-                    fwrite($ipdbcf, $line);
-                }
-                break;
-            
-            // We should not receive any data after the last
-            // line, only whitespace is allowed
-            case 'lastline' :
-                if (strlen(trim($line)) > 0) {
-                    $fileok = FALSE;
-                    break 2;
-                }
-                break;
-        }
-    }
-    fclose($ipdbf);
-    fclose($ipdbcf);
-    
-    // Remove the temp file. If the data is ok, move
-    // it to the destination, or else delete that too
-    unlink($ipdbt);
-    if (file_exists($ipdbc)) {
-        if (!$fileok) {
-            unlink($ipdbc);
-        } else {
-            rename($ipdbc, $ipdb);
-            create_ip_to_country_index($ipdb, $ipidx, $indexby);
-        }
-    }
-}
-
-// Create local index for ip-to-country.com data
-function create_ip_to_country_index($ipdb, $ipidx, $indexby)
-{
-    // Last indexed number and last record number
-    $lastidx = $recnum = 0;
-
-    // We store the index in a PHP array temporarily
-    $idx_list = [$indexby, "0,0"];
-
-    // Open database for reading
-    $ipdbf = fopen($ipdb, "r");
-
-    // Return with error in case of we cannot open the db
-    if (!$ipdbf) { die("Unable to open '$ipdb' for reading"); }
-
-    // While we can read the file
-    while (!feof($ipdbf)) {
-
-        // Get one record
-        $record = fread($ipdbf, 24);
-
-        // Unable to read a record and not at end => error
-        if (strlen($record) != 24 && !feof($ipdbf)) {
-            die("Incorrect ip-to-country database format");
-        }
-
-        // This is a new record
-        $recnum++;
-
-        // Get the start of the range for this record
-        $range_start = (float) substr($record, 0, 10);
-
-        // If this range starts a new step with our granularity,
-        // add a new element to the index array
-        if (intval($range_start / $indexby) > $lastidx) {
-            $lastidx = intval($range_start / $indexby);
-            $idx_list[] = "$lastidx,$recnum";
-        }
-    }
-
-    // Close the database file
-    fclose($ipdbf);
-
-    // Write out index to file
-    $ipidxf = fopen($ipidx, "w");
-    if (!$ipidxf) { die("Unable to open '$ipidx' for writing"); }
-    fwrite($ipidxf, join("\n", $idx_list));
-    fclose($ipidxf);
-}
diff --git a/scripts/update-backend b/scripts/update-backend
index e0de02c..5b87909 100755
--- a/scripts/update-backend
+++ b/scripts/update-backend
@@ -26,11 +26,6 @@ include "event_listing";
 $months = (date('j') < 10) ? 1:2;
 pregenerate_events("$root/backend/events.csv", 
"$root/include/pregen-events.inc", $months);
 
-
-// Run ip-to-country fetch code
-include "ip-to-country";
-fetch_ip_to_country($root);
-
 include "pregen_news";
 pregen_atom("$root/archive/archive.xml", "$root/feed.atom", 
"$root/include/pregen-news.inc");
 include "rss_parser";

Reply via email to