Commit c03c42c4 authored by Jean-Vincent Loddo's avatar Jean-Vincent Loddo
Browse files

Some minor changes about the geoiplookup wrapper. Now the IPv4 geographical...

Some minor changes about the geoiplookup wrapper. Now the IPv4 geographical localization may be interpreted with a political angle (Martinique is France, and so on)
parent 59b18115
AFGHANISTAN (AF)
LAND ISLANDS (AX)
ALBANIA (AL)
ALGERIA (DZ)
AMERICAN SAMOA (AS)
ANDORRA (AD)
ANGOLA (AO)
ANGUILLA (AI)
ANTIGUA AND BARBUDA (AG)
ARGENTINA (AR)
ARMENIA (AM)
ARUBA (AW)
AUSTRALIA (AU)
AUSTRIA (AT)
AZERBAIJAN (AZ)
BAHAMAS (BS)
BAHRAIN (BH)
BANGLADESH (BD)
BARBADOS (BB)
BELARUS (BY)
BELGIUM (BE)
BELIZE (BZ)
BENIN (BJ)
BERMUDA (BM)
BHUTAN (BT)
BOLIVIA (BO)
BOSNIA AND HERZEGOVINA (BA)
BOTSWANA (BW)
BRAZIL (BR)
BRITISH INDIAN OCEAN TERRITORY (IO)
BRUNEI DARUSSALAM (BN)
BULGARIA (BG)
BURKINA FASO (BF)
BURUNDI (BI)
CAMBODIA (KH)
CAMEROON (CM)
CANADA (CA)
CAPE VERDE (CV)
CAYMAN ISLANDS (KY)
CENTRAL AFRICAN REPUBLIC (CF)
CHAD (TD)
CHILE (CL)
CHINA (CN)
COLOMBIA (CO)
COMOROS (KM)
CONGO (CG)
CONGO, THE DEMOCRATIC REPUBLIC OF THE (CD)
COOK ISLANDS (CK)
COSTA RICA (CR)
COTE D'IVOIRE (CI)
CROATIA (HR)
CUBA (CU)
CYPRUS (CY)
CZECH REPUBLIC (CZ)
DENMARK (DK)
DJIBOUTI (DJ)
DOMINICA (DM)
DOMINICAN REPUBLIC (DO)
ECUADOR (EC)
EGYPT (EG)
EL SALVADOR (SV)
EQUATORIAL GUINEA (GQ)
ERITREA (ER)
ESTONIA (EE)
ETHIOPIA (ET)
FAROE ISLANDS (FO)
FIJI (FJ)
FINLAND (FI)
FRANCE (FR)
FRENCH GUIANA (GF)
FRENCH POLYNESIA (PF)
GABON (GA)
GAMBIA (GM)
GEORGIA (GE)
GERMANY (DE)
GHANA (GH)
GIBRALTAR (GI)
GREECE (GR)
GREENLAND (GL)
GRENADA (Gd)
GUADELOUPE (GP)
GUAM (GU)
GUATEMALA (GT)
GUINEA (GN)
GUINEA-BISSAU (GW)
GUYANA (GY)
HAITI (HT)
HOLY SEE (VATICAN CITY STATE) (VA)
HONDURAS (HN)
HONG KONG (HK)
HUNGARY (HU)
ICELAND (IS)
INDIA (IN)
INDONESIA (ID)
IRAN, ISLAMIC REPUBLIC OF (IR)
IRAQ (IQ)
IRELAND (IE)
ISLE OF MAN (IM)
ISRAEL (IL)
ITALY (IT)
JAMAICA (JM)
JAPAN (JP)
JERSEY (JE)
JORDAN (JO)
KAZAKHSTAN (KZ)
KENYA (KE)
KIRIBATI (KI)
KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF (KP)
KOREA, REPUBLIC OF (KR)
KUWAIT (KW)
KYRGYZSTAN (KG)
LAO PEOPLE'S DEMOCRATIC REPUBLIC (LA)
LATVIA (LV)
LEBANON (LB)
LESOTHO (LS)
LIBERIA (LR)
LIBYAN ARAB JAMAHIRIYA (LY)
LIECHTENSTEIN (LI)
LITHUANIA (LT)
LUXEMBOURG (LU)
MACAO (MO)
MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF (MK)
MADAGASCAR (MG)
MALAWI (MW)
MALAYSIA (MY)
MALDIVES (MV)
MALI (ML)
MALTA (MT)
MARSHALL ISLANDS (MH)
MARTINIQUE (MQ)
MAURITANIA (MR)
MAURITIUS (MU)
MAYOTTE (YT)
MEXICO (MX)
MICRONESIA, FEDERATED STATES OF (FM)
MOLDOVA, REPUBLIC OF (MD)
MONACO (MC)
MONGOLIA (MN)
MONTENEGRO (ME)
MONTSERRAT (MS)
MOROCCO (MA)
MOZAMBIQUE (MZ)
MYANMAR (MM)
NAMIBIA (NA)
NAURU (NR)
NEPAL (NP)
NETHERLANDS (NL)
NEW CALEDONIA (NC)
NEW ZEALAND (NZ)
NICARAGUA (NI)
NIGER (NE)
NIGERIA (NG)
NIUE (NU)
NORFOLK ISLAND (NF)
NORTHERN MARIANA ISLANDS (MP)
NORWAY (NO)
OMAN (OM)
PAKISTAN (PK)
PALAU (PW)
PALESTINIAN TERRITORY, OCCUPIED (PS)
PANAMA (PA)
PAPUA NEW GUINEA (PG)
PARAGUAY (PY)
PERU (PE)
PHILIPPINES (PH)
POLAND (PL)
PORTUGAL (PT)
PUERTO RICO (PR)
QATAR (QA)
REUNION (RE)
ROMANIA (RO)
RUSSIAN FEDERATION (RU)
RWANDA (RW)
SAINT KITTS AND NEVIS (KN)
SAINT LUCIA (LC)
SAINT PIERRE AND MIQUELON (PM)
SAINT VINCENT AND THE GRENADINES (VC)
SAMOA (WS)
SAN MARINO (SM)
SAO TOME AND PRINCIPE (ST)
SAUDI ARABIA (SA)
SENEGAL (SN)
SERBIA (RS)
SEYCHELLES (SC)
SIERRA LEONE (SL)
SINGAPORE (SG)
SLOVAKIA (SK)
SLOVENIA (SI)
SOLOMON ISLANDS (SB)
SOMALIA (SO)
SOUTH AFRICA (ZA)
SPAIN (ES)
SRI LANKA (LK)
SUDAN (SD)
SURINAME (SR)
SWAZILAND (SZ)
SWEDEN (SE)
SWITZERLAND (CH)
SYRIAN ARAB REPUBLIC (SY)
TAIWAN (TW)
TAJIKISTAN (TJ)
TANZANIA, UNITED REPUBLIC OF (TZ)
THAILAND (TH)
TIMOR-LESTE (TL)
TOGO (TG)
TOKELAU (TK)
TONGA (TO)
TRINIDAD AND TOBAGO (TT)
TUNISIA (TN)
TURKEY (TR)
TURKMENISTAN (TM)
TURKS AND CAICOS ISLANDS (TC)
TUVALU (TV)
UGANDA (UG)
UKRAINE (UA)
UNITED ARAB EMIRATES (AE)
UNITED KINGDOM (GB)
UNITED STATES (US)
UNITED STATES MINOR OUTLYING ISLANDS (UM)
URUGUAY (UY)
UZBEKISTAN (UZ)
VANUATU (VU)
VENEZUELA (VE)
VIET NAM (VN)
VIRGIN ISLANDS, BRITISH (VG)
VIRGIN ISLANDS, U.S. (VI)
WALLIS AND FUTUNA (WF)
YEMEN (YE)
ZAMBIA (ZM)
ZIMBABWE (ZW)
......@@ -256,14 +256,45 @@ function is_ipv4_private_address($x) {
// ---
}
// Example:
// ---
// Geographical vs political country classification:
$real_country = [
# France related bindings:
"Guadeloupe" => "France",
"Guiana" => "France",
"Guyana" => "France",
"Martinique" => "France",
"Mayotte" => "France",
"Reunion" => "France",
# Add here the other relevant bindings for your server:
# ...
];
// ---
function translate_country_or_leave_unchanged($x) {
global $real_country;
# ---
if (array_key_exists($x, $real_country)) { return $real_country[$x]; } else { return $x; }
# ---
}
// ---
function geoiplookup_wrapper($x) {
# ---
$country = trim(shell_exec("geoiplookup ".$x." | awk '{print \$NF}'"));
return ($country);
}
// ---
// Examples:
// var_dump(test_are_they_in_the_same_country("109.203.232.1","109.9.108.67"));
// if (test_are_they_in_the_same_country($_SERVER["SERVER_ADDR"], $_SERVER["REMOTE_ADDR"])) { ... }
function test_are_they_in_the_same_country($x, $y) {
# ---
$out_x = shell_exec("geoiplookup ".$x." | awk '{print \$NF}'");
$out_y = shell_exec("geoiplookup ".$y." | awk '{print \$NF}'");
$country_x = geoiplookup_wrapper($x);
$country_y = geoiplookup_wrapper($y);
# ---
$country_x = translate_country_or_leave_unchanged($country_x);
$country_y = translate_country_or_leave_unchanged($country_y);
# ---
return ($out_x == $out_y);
return ($country_x == $country_y);
}
// Example:
......
......@@ -61,7 +61,7 @@ else {
$PREVENT_DATABASE_CONNECTION = True; // (use config.php as library)
require_once "config.php";
// ---
$cache = $_SESSION["mariotel_sessions_cache"][$_GET["id"]];
$cache = $_SESSION["mariotel_sessions_cache"][$_GET["id"]]; // TODO: Notice: Undefined offset: 404142 in /var/www/html/details.php on line 64 (bad id)
// ---
?>
......
......@@ -142,7 +142,7 @@ if (($_SERVER["REQUEST_METHOD"] == "POST") && (is_student_name_acceptable($_POST
// ---
if (! $FOUND) {
// TODO: do something more explicit!
// TODO: do something more explicit! (something like: "Sorry, all workstation are booked, there are no available free places in the room")
header("location: error.php?noway=w3"); exit();
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment