Subversion Repositories oidplus

Rev

Rev 511 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
264 daniel-mar 1
#!/usr/bin/php
2
<?php
3
 
4
// This script generates a part of ../setup/sql/wellknown_country_sqlite.sql , based on Country OIDs at oid-info.com
5
// If new countries are added to the ISO / ITU arcs, please re-run this script and update ../setup/sql/wellknown_country_sqlite.sql accordingly
6
 
7
require_once __DIR__ . '/../includes/oidplus.inc.php';
8
 
9
OIDplus::init(true);
10
 
11
// Generates countries for wellknown OIDs
12
 
13
$options = array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36'));
14
$context = stream_context_create($options);
15
$cont = file_get_contents('http://oid-info.com/get/1.2', false, $context).
16
     file_get_contents('http://oid-info.com/get/2.16', false, $context).
17
     file_get_contents('http://oid-info.com/get/2.49.0.0', false, $context);
18
 
19
preg_match_all('@<option value="https{0,1}://(www.){0,1}oid-info.com/get/([^"]+)">(..)\(.+\)</option>@ismU', $cont, $m, PREG_SET_ORDER);
20
 
21
echo "-- Country OIDs\n";
22
echo "-- Use the tool dev/generate_wellknown_country_sqlite to generate this file\n";
23
echo "\n";
24
 
25
$check_sum = '';
26
foreach ($m as $n) {
27
	$check_sum .= $n[2].'='.$n[3].'/';
28
 
29
	if (strpos($n[2], '2.49.0.0') === 0) {
30
		// WMO Country OIDs (does not assign Unicode labels), 2.49.0.0
31
		echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[2]', '$n[3]', '0', '1');\n";
32
 
33
		// Country-Msg, 2.49.0.1
34
		$n[2] = str_replace('2.49.0.0', '2.49.0.1', $n[2]);
35
		echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[2]', '$n[3]', '0', '1');\n";
36
	} else {
37
		// ISO or Joint-ISO-ITU-T OID Countries (1.2 and 2.16)
38
		echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[2]', '$n[3]', '0', '1');\n";
39
		echo "INSERT INTO `iri` (oid, name, longarc, well_known) VALUES ('oid:$n[2]', '".strtoupper($n[3])."', '0', '1');\n";
40
	}
41
}
42
 
43
echo "\n";
44
echo '-- Generator "generate_wellknown_country_sqlite" checksum '.dechex(crc32($check_sum))."\n";