Rev 264 | Rev 557 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
264 | daniel-mar | 1 | #!/usr/bin/php |
2 | <?php |
||
3 | |||
511 | daniel-mar | 4 | /* |
5 | * OIDplus 2.0 |
||
6 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
||
7 | * |
||
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
9 | * you may not use this file except in compliance with the License. |
||
10 | * You may obtain a copy of the License at |
||
11 | * |
||
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
13 | * |
||
14 | * Unless required by applicable law or agreed to in writing, software |
||
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
17 | * See the License for the specific language governing permissions and |
||
18 | * limitations under the License. |
||
19 | */ |
||
20 | |||
264 | daniel-mar | 21 | // This script generates a part of ../setup/sql/wellknown_country_sqlite.sql , based on Country OIDs at oid-info.com |
22 | // If new countries are added to the ISO / ITU arcs, please re-run this script and update ../setup/sql/wellknown_country_sqlite.sql accordingly |
||
23 | |||
24 | require_once __DIR__ . '/../includes/oidplus.inc.php'; |
||
25 | |||
26 | OIDplus::init(true); |
||
27 | |||
28 | // Generates countries for wellknown OIDs |
||
29 | |||
30 | $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')); |
||
31 | $context = stream_context_create($options); |
||
32 | $cont = file_get_contents('http://oid-info.com/get/1.2', false, $context). |
||
33 | file_get_contents('http://oid-info.com/get/2.16', false, $context). |
||
34 | file_get_contents('http://oid-info.com/get/2.49.0.0', false, $context); |
||
35 | |||
36 | preg_match_all('@<option value="https{0,1}://(www.){0,1}oid-info.com/get/([^"]+)">(..)\(.+\)</option>@ismU', $cont, $m, PREG_SET_ORDER); |
||
37 | |||
38 | echo "-- Country OIDs\n"; |
||
39 | echo "-- Use the tool dev/generate_wellknown_country_sqlite to generate this file\n"; |
||
40 | echo "\n"; |
||
41 | |||
42 | $check_sum = ''; |
||
43 | foreach ($m as $n) { |
||
44 | $check_sum .= $n[2].'='.$n[3].'/'; |
||
45 | |||
46 | if (strpos($n[2], '2.49.0.0') === 0) { |
||
47 | // WMO Country OIDs (does not assign Unicode labels), 2.49.0.0 |
||
48 | echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[2]', '$n[3]', '0', '1');\n"; |
||
49 | |||
50 | // Country-Msg, 2.49.0.1 |
||
51 | $n[2] = str_replace('2.49.0.0', '2.49.0.1', $n[2]); |
||
52 | echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[2]', '$n[3]', '0', '1');\n"; |
||
53 | } else { |
||
54 | // ISO or Joint-ISO-ITU-T OID Countries (1.2 and 2.16) |
||
55 | echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[2]', '$n[3]', '0', '1');\n"; |
||
56 | echo "INSERT INTO `iri` (oid, name, longarc, well_known) VALUES ('oid:$n[2]', '".strtoupper($n[3])."', '0', '1');\n"; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | echo "\n"; |
||
61 | echo '-- Generator "generate_wellknown_country_sqlite" checksum '.dechex(crc32($check_sum))."\n"; |