Rev 1162 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
557 | daniel-mar | 1 | #!/usr/bin/env php |
264 | daniel-mar | 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 | |||
1244 | daniel-mar | 21 | // This script generates plugins/viathinksoft/sqlSlang/sqlite/sql/wellknown_country.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 plugins/viathinksoft/sqlSlang/sqlite/sql/wellknown_country.sql accordingly |
||
264 | daniel-mar | 23 | |
1162 | daniel-mar | 24 | use ViaThinkSoft\OIDplus\OIDplus; |
25 | |||
264 | daniel-mar | 26 | require_once __DIR__ . '/../includes/oidplus.inc.php'; |
27 | |||
28 | OIDplus::init(true); |
||
29 | |||
30 | // Generates countries for wellknown OIDs |
||
31 | |||
32 | $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')); |
||
33 | $context = stream_context_create($options); |
||
34 | $cont = file_get_contents('http://oid-info.com/get/1.2', false, $context). |
||
35 | file_get_contents('http://oid-info.com/get/2.16', false, $context). |
||
36 | file_get_contents('http://oid-info.com/get/2.49.0.0', false, $context); |
||
37 | |||
640 | daniel-mar | 38 | preg_match_all('@<option value="/get/([^"]+)">(..)\(.+\)</option>@ismU', $cont, $m, PREG_SET_ORDER); |
264 | daniel-mar | 39 | |
40 | echo "-- Country OIDs\n"; |
||
41 | echo "-- Use the tool dev/generate_wellknown_country_sqlite to generate this file\n"; |
||
42 | echo "\n"; |
||
43 | |||
44 | $check_sum = ''; |
||
45 | foreach ($m as $n) { |
||
640 | daniel-mar | 46 | $check_sum .= $n[1].'='.$n[2].'/'; |
264 | daniel-mar | 47 | |
640 | daniel-mar | 48 | if (strpos($n[1], '2.49.0.0') === 0) { |
264 | daniel-mar | 49 | // WMO Country OIDs (does not assign Unicode labels), 2.49.0.0 |
640 | daniel-mar | 50 | echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n"; |
264 | daniel-mar | 51 | |
52 | // Country-Msg, 2.49.0.1 |
||
640 | daniel-mar | 53 | $n[1] = str_replace('2.49.0.0', '2.49.0.1', $n[1]); |
54 | echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n"; |
||
264 | daniel-mar | 55 | } else { |
56 | // ISO or Joint-ISO-ITU-T OID Countries (1.2 and 2.16) |
||
640 | daniel-mar | 57 | echo "INSERT INTO `asn1id` (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n"; |
58 | echo "INSERT INTO `iri` (oid, name, longarc, well_known) VALUES ('oid:$n[1]', '".strtoupper($n[2])."', '0', '1');\n"; |
||
264 | daniel-mar | 59 | } |
60 | } |
||
61 | |||
62 | echo "\n"; |
||
63 | echo '-- Generator "generate_wellknown_country_sqlite" checksum '.dechex(crc32($check_sum))."\n"; |