Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 1236 → Rev 1237

/trunk/dev/generate_example_data_firebird
0,0 → 1,53
#!/bin/bash
 
# OIDplus 2.0
# Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
 
DIR=$( dirname "$0" )
cd "$DIR"
 
# Export tables "demo_*" into file setup/sql/example_firebird.sql
# We don't print to console because of encoding issues
#mysqldump --default-character-set=utf8 --no-create-info --extended-insert=FALSE oidplus demo_iri demo_asn1id demo_ra demo_objects -r ../setup/sql/example_firebird.sql
 
# Remove database prefix
#sed -i 's/`demo_/`/g' ../setup/sql/example_firebird.sql
 
# Since we have to do some manual work to the MySQL data, we do not create a new dump
# but instead use the MySQL example script (that has been carefully checked)
cat ../setup/sql/example_mysql.sql > ../setup/sql/example_firebird.sql
 
# Avoid that there is a conflict with well known IDs (e.g. 2.999)
#sed -i 's/INSERT INTO `iri`/INSERT IGNORE INTO `iri`/g' ../setup/sql/example_pgsql.sql
#sed -i 's/INSERT INTO `asn1id`/INSERT IGNORE INTO `asn1id`/g' ../setup/sql/example_pgsql.sql
 
# Change backticks to double quotes
# and write everything inside upper case! (very important)
sed -i 's/`/"/g' ../setup/sql/example_firebird.sql
sed -i 's/"asn1id"/"ASN1ID"/g' ../setup/sql/example_firebird.sql
sed -i 's/"objects"/"OBJECTS"/g' ../setup/sql/example_firebird.sql
sed -i 's/"iri"/"IRI"/g' ../setup/sql/example_firebird.sql
 
# Change \" to "
sed -i 's/\\"/"/g' ../setup/sql/example_firebird.sql
 
# Dates need "TIMESTAMP" prefix
for year in {2010..2099}
do
sed -i "s/'$year/TIMESTAMP '$year/g" ../setup/sql/example_firebird.sql
done
 
# Change "\n" to "' || ASCII_CHAR(10) || '"
sed -i "s/\\\n/' \|\| ASCII_CHAR\(10\) \|\| '/g" ../setup/sql/example_firebird.sql
/trunk/dev/generate_wellknown_country_firebird
0,0 → 1,63
#!/usr/bin/env php
<?php
 
/*
* OIDplus 2.0
* Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
// This script generates a part of ../setup/sql/wellknown_country_firebird.sql , based on Country OIDs at oid-info.com
// If new countries are added to the ISO / ITU arcs, please re-run this script and update ../setup/sql/wellknown_country_firebird.sql accordingly
 
use ViaThinkSoft\OIDplus\OIDplus;
 
require_once __DIR__ . '/../includes/oidplus.inc.php';
 
OIDplus::init(true);
 
// Generates countries for wellknown OIDs
 
$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'));
$context = stream_context_create($options);
$cont = file_get_contents('http://oid-info.com/get/1.2', false, $context).
file_get_contents('http://oid-info.com/get/2.16', false, $context).
file_get_contents('http://oid-info.com/get/2.49.0.0', false, $context);
 
preg_match_all('@<option value="/get/([^"]+)">(..)\(.+\)</option>@ismU', $cont, $m, PREG_SET_ORDER);
 
echo "-- Country OIDs\n";
echo "-- Use the tool dev/generate_wellknown_country_firebird to generate this file\n";
echo "\n";
 
$check_sum = '';
foreach ($m as $n) {
$check_sum .= $n[1].'='.$n[2].'/';
 
if (strpos($n[1], '2.49.0.0') === 0) {
// WMO Country OIDs (does not assign Unicode labels), 2.49.0.0
echo "INSERT INTO \"ASN1ID\" (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n";
 
// Country-Msg, 2.49.0.1
$n[1] = str_replace('2.49.0.0', '2.49.0.1', $n[1]);
echo "INSERT INTO \"ASN1ID\" (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n";
} else {
// ISO or Joint-ISO-ITU-T OID Countries (1.2 and 2.16)
echo "INSERT INTO \"ASN1ID\" (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n";
echo "INSERT INTO \"IRI\" (oid, name, longarc, well_known) VALUES ('oid:$n[1]', '".strtoupper($n[2])."', '0', '1');\n";
}
}
 
echo "\n";
echo '-- Generator "generate_wellknown_country_firebird" checksum '.dechex(crc32($check_sum))."\n";
/trunk/dev/generate_wellknown_other_firebird
0,0 → 1,238
#!/usr/bin/env php
-- This file (wellknown_other_firebird.sql) contains ASN.1 and IRI names of OIDs which are either
-- a) Root OIDs
-- b) Unicode labels which are long arcs
-- c) Standardized ASN.1 identifiers
-- d) OIDs where potential users of this software can register OIDs in these arcs (e.g. an "identified organization" arc)
-- Use the tool dev/generate_wellknown_other_firebird to generate this file
 
<?php
 
/*
* OIDplus 2.0
* Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
require_once __DIR__ . '/../includes/oidplus.inc.php';
 
OIDplus::init(false);
if (!OIDplus::baseConfig()->exists('OIDINFO_API_URL')) {
die("OIDINFO_API_URL not available (API is currently not public)\n");
}
 
$output = array();
 
function _is_standardized($oid, $asn1id) {
$std = asn1_get_standardized_array();
$x = oid_up($oid) == $oid ? '' : oid_up($oid).".";
return isset( $std[$x.$asn1id]) && ($std[$x.$asn1id] == $oid);
}
 
function _is_long($oid) {
$oid = '/'.str_replace('.', '/', $oid);
return in_array($oid, iri_get_long_arcs());
}
 
function _process_oid($oid) {
global $output;
 
if (!isset($output[$oid])) {
if ($oid == '0.0.23') {
// Rec. ITU-T X.660 | ISO/IEC 9834-3, clause A.3.3.1 allows "0.0.w", although it is illegal, since no W-series exist
$data = array();
$data['oid'] = array();
$data['oid']['identifier'] = array('w');
$data['oid']['unicode-label'] = array('W');
} else {
$data = ft_get_oid_data($oid);
}
 
$output[$oid] = array();
$output[$oid]['asn1id'] = array();
$output[$oid]['iri'] = array();
$output[$oid]['checksum'] = array();
 
if (isset($data['oid']['identifier'])) {
foreach ($data['oid']['identifier'] as $asn1id) {
$output[$oid]['checksum'][] = $oid.'|ASN1|'.$asn1id.'|'.(_is_standardized($oid, $asn1id) ? '1' : '0').'|1||';
$std = _is_standardized($oid, $asn1id) ? "'1'" : "'0'";
$output[$oid]['asn1id'][] = "INSERT INTO \"ASN1ID\" (oid, name, standardized, well_known) VALUES ('oid:$oid', '$asn1id', $std, '1');";
}
} else {
//echo "-- Warning: Has no ASN.1 identifier: $oid\n";
}
if (isset($data['oid']['unicode-label'])) {
foreach ($data['oid']['unicode-label'] as $iri) {
$output[$oid]['checksum'][] = $oid.'|IRI|'.$iri.'|'.(_is_long($oid) ? '1' : '0').'|1||';
 
$std = _is_long($oid) ? "'1'" : "'0'";
 
if (strpos($iri, '&#') !== false) {
$iri = "base64_decode('".base64_encode(html_entity_decode($iri, ENT_COMPAT | ENT_HTML401, "UTF-8"))."')";
} else {
$iri = "'$iri'";
}
 
$output[$oid]['iri'][] = "INSERT INTO \"IRI\" (oid, name, longarc, well_known) VALUES ('oid:$oid', $iri, $std, '1');";
}
}
}
 
return $output[$oid];
}
 
// ---
 
$interesting_oids = array();
 
foreach (asn1_get_standardized_array() as $tmp => $oid) {
$interesting_oids[] = $oid;
}
 
foreach (iri_get_long_arcs() as $tmp => $oid) {
$oid = substr(str_replace('/', '.', $oid),1);
$interesting_oids[] = $oid;
}
 
// ----------------------------------------------------------------
 
$interesting_oids[] = '0'; // itu-t
$interesting_oids[] = '0.2'; // telecom operators
$interesting_oids[] = '0.3'; // network-operator
$interesting_oids[] = '0.4'; // identified-organization
$interesting_oids[] = '0.4.0'; // etsi
$interesting_oids[] = '0.4.0.127'; // reserved
$interesting_oids[] = '0.4.0.127.0'; // etsi-identified-organization
$interesting_oids[] = '1'; // iso
$interesting_oids[] = '1.1'; // registration-authority
$interesting_oids[] = '1.1.19785'; // cbeff
$interesting_oids[] = '1.1.19785.0'; // organization
$interesting_oids[] = '1.2'; // member-body
// country_getter defines the country OIDs
//$interesting_oids[] = '1.2.158'; // tw
$interesting_oids[] = '1.2.158.1'; // organization
//$interesting_oids[] = '1.2.276'; // de
$interesting_oids[] = '1.2.276.0'; // din-certco
//$interesting_oids[] = '1.2.344'; // hk
$interesting_oids[] = '1.2.344.1'; // organization
//$interesting_oids[] = '1.2.616'; // pl
$interesting_oids[] = '1.2.616.1'; // organization
//$interesting_oids[] = '1.2.826'; // gb
$interesting_oids[] = '1.2.826.0'; // national
$interesting_oids[] = '1.2.826.0.1'; // eng-ltd
$interesting_oids[] = '1.2.826.0.1.3680043'; // Medical Connections ( https://www.medicalconnections.co.uk/FreeUID/ )
//$interesting_oids[] = '1.2.840'; // us
$interesting_oids[] = '1.2.840.1'; // organization
$interesting_oids[] = '1.2.840.113556'; // microsoft
$interesting_oids[] = '1.2.840.113556.1'; // Microsoft Active Directory
$interesting_oids[] = '1.2.840.113556.1.8000'; // companies
$interesting_oids[] = '1.2.840.113556.1.8000.2554'; // customer usage
$interesting_oids[] = '1.2.840.113556.2'; // DICOM
$interesting_oids[] = '1.3'; // identified-organization
$interesting_oids[] = '1.3.6'; // dod
$interesting_oids[] = '1.3.6.1'; // internet
$interesting_oids[] = '1.3.6.1.2'; // mgmt
$interesting_oids[] = '1.3.6.1.2.1'; // mib-2
$interesting_oids[] = '1.3.6.1.4'; // private
$interesting_oids[] = '1.3.6.1.4.1'; // enterprise
$interesting_oids[] = '1.3.6.1.4.1.19376'; // Integrating the Healthcare Enterprise International
$interesting_oids[] = '1.3.6.1.4.1.19376.3'; // Organizations (not in Repo!)
$interesting_oids[] = '1.3.6.1.4.1.19376.3.276'; // IHE Deutschland
$interesting_oids[] = '1.3.6.1.4.1.19376.3.276.1'; // OID für das OID Konzept Version 1
$interesting_oids[] = '1.3.6.1.4.1.19376.3.276.1.4'; // Identifikation des ID-Pools für Institutionen (Organisationen, Einheiten, etc.)
$interesting_oids[] = '1.3.6.1.4.1.19376.3.276.1.4.1'; // Krankenhäuser
$interesting_oids[] = '1.3.6.1.4.1.19376.3.276.1.4.2'; // Praxen niedergelassener Ärzte
$interesting_oids[] = '1.3.6.1.4.1.19376.3.276.1.4.3'; // Systeme
$interesting_oids[] = '1.3.6.1.4.1.12798'; // Members of Internet-Käyttäjät Ikuisesti (IKI)
$interesting_oids[] = '1.3.6.1.4.1.12798.1'; // member
$interesting_oids[] = '1.3.6.1.4.1.37476'; // ViaThinkSoft
$interesting_oids[] = '1.3.6.1.4.1.37476.9000'; // freeoid
$interesting_oids[] = '1.3.6.1.4.1.37553'; // frdlweb
$interesting_oids[] = '1.3.6.1.4.1.37553.8'; // WEID
$interesting_oids[] = '1.3.6.1.4.1.37553.8.8'; // private
$interesting_oids[] = '1.3.6.1.4.1.37553.8.9'; // ns
$interesting_oids[] = '1.3.6.1.4.1.37553.8.9.17704'; // dns
$interesting_oids[] = '1.3.6.1.4.1.37553.8.9.1439221'; // uuid
$interesting_oids[] = '2'; // joint-iso-itu-t
$interesting_oids[] = '2.16'; // country
// country_getter defines the country OIDs
//$interesting_oids[] = '2.16.158'; // tw
$interesting_oids[] = '2.16.158.1'; // organization
//$interesting_oids[] = '2.16.344'; // hk
$interesting_oids[] = '2.16.344.1'; // organization
//$interesting_oids[] = '2.16.616'; // pl
$interesting_oids[] = '2.16.616.1'; // organization
//$interesting_oids[] = '2.16.840'; // us
$interesting_oids[] = '2.16.840.1'; // organization
$interesting_oids[] = '2.16.840.1.113883'; // hl7
$interesting_oids[] = '2.16.840.1.113883.3'; // externalUseRoots
$interesting_oids[] = '2.16.840.1.113883.6'; // externalCodeSystems
$interesting_oids[] = '2.16.840.1.113883.13'; // externalValueSets
$interesting_oids[] = '2.23'; // international-organizations
$interesting_oids[] = '2.25'; // uuid
$interesting_oids[] = '2.40'; // upu
$interesting_oids[] = '2.40.2'; // member-body
$interesting_oids[] = '2.40.3'; // identified-organization
$interesting_oids[] = '2.49'; // alerting
$interesting_oids[] = '2.49.0'; // wmo
$interesting_oids[] = '2.49.0.0'; // authority (Countries)
// country_getter defines the country OIDs beneath 2.49.0.0
$interesting_oids[] = '2.49.0.1'; // country-msg
// country_getter defines the country OIDs beneath 2.49.0.1
$interesting_oids[] = '2.49.0.2'; // org
$interesting_oids[] = '2.49.0.3'; // org-msg
 
// ----------------------------------------------------------------
 
$interesting_oids = array_unique($interesting_oids);
natsort($interesting_oids);
 
$output = array();
foreach ($interesting_oids as $oid) {
_process_oid($oid);
}
 
$check_sum = '';
foreach ($output as $oid => $data) {
if (count($data['asn1id']) + count($data['iri']) == 0) continue;
 
echo "-- $oid\n";
foreach ($data['asn1id'] as $line_asn1) {
echo "$line_asn1\n";
}
foreach ($data['iri'] as $line_iri) {
echo "$line_iri\n";
}
foreach ($data['checksum'] as $chunk) {
$check_sum .= $chunk;
}
echo "\n";
}
echo '-- Generator "generate_wellknown_other_firebird" checksum '.dechex(crc32($check_sum))."\n";
 
# ---
 
function ft_get_oid_data($oid) {
$url = OIDplus::baseConfig()->getValue('OIDINFO_API_URL') . '&oid='.urlencode($oid);
$cont_json = @file_get_contents($url);
if (!$cont_json) {
sleep(5);
$cont_json = @file_get_contents($url);
if (!$cont_json) return false;
}
$data = json_decode($cont_json,true);
 
return $data;
}