Rev 88 | Rev 150 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
61 | daniel-mar | 1 | #!/usr/bin/php |
2 | <?php |
||
3 | |||
97 | daniel-mar | 4 | require_once __DIR__ . '/../includes/oidplus.inc.php'; |
61 | daniel-mar | 5 | |
6 | OIDplus::init(false); |
||
7 | if (!defined('OIDINFO_API_URL')) { |
||
8 | die("OIDINFO_API_URL not available (API is currently not public)\n"); |
||
9 | } |
||
10 | |||
11 | OIDplus::db()->set_charset("UTF8"); |
||
12 | OIDplus::db()->query("SET NAMES 'utf8'"); |
||
13 | |||
14 | define('VERBOSE', false); |
||
15 | define('DEFAULT_EMAIL', 'oidra@viathinksoft.de'); |
||
16 | define('ALL_OID_LIST', '/home/oidplus/all_oids.txt'); // contains all OIDs (non-public file) |
||
17 | define('DESIRED_ROOT', '1.3.6.1.4.1.37476'); |
||
18 | |||
19 | # --- |
||
20 | |||
21 | exec("cat ".escapeshellarg(ALL_OID_LIST)." | sort | grep '^".DESIRED_ROOT."'", $out, $ec); |
||
22 | |||
23 | foreach ($out as $oid) { |
||
24 | $oid = trim($oid); |
||
25 | if ($oid == '') continue; |
||
26 | |||
27 | check_oid($oid); |
||
28 | } |
||
29 | |||
30 | function check_oid($oid) { |
||
31 | |||
88 | daniel-mar | 32 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where id = '".OIDplus::db()->real_escape_string("oid:$oid")."';"); |
77 | daniel-mar | 33 | $ok = OIDplus::db()->num_rows($res) > 0; |
61 | daniel-mar | 34 | |
35 | if (!$ok) { |
||
36 | echo "Not existing: $oid : Adding!\n"; |
||
37 | add_oid($oid); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | echo "OK\n"; |
||
42 | |||
43 | # --- |
||
44 | |||
45 | function add_oid($oid, $root=DESIRED_ROOT) { |
||
46 | if (VERBOSE) echo "Adding $oid ...\n"; |
||
47 | $data = ft_get_oid_data($oid); |
||
48 | |||
49 | if (!isset($data['oid'])) { |
||
50 | echo "Warning: Cannot gain information about OID $oid\n"; |
||
51 | |||
52 | $parent = ($oid == $root) ? '' : oid_up($oid); |
||
53 | $title = '(tbd)'; |
||
54 | $description = '(tbd)'; |
||
55 | $ra_email = ''; |
||
56 | if ((DEFAULT_EMAIL != '') && ($ra_email == '')) $ra_email = DEFAULT_EMAIL; |
||
57 | |||
88 | daniel-mar | 58 | sql_execute("insert into ".OIDPLUS_TABLENAME_PREFIX."objects (id, parent, title, description, ra_email) values ('".OIDplus::db()->real_escape_string("oid:$oid")."', '".OIDplus::db()->real_escape_string("oid:$parent")."', '".OIDplus::db()->real_escape_string($title)."', '".OIDplus::db()->real_escape_string($description)."', '".OIDplus::db()->real_escape_string($ra_email)."');"); |
61 | daniel-mar | 59 | |
60 | return; |
||
61 | } |
||
62 | |||
63 | if (!isset($data['oid']['identifier'])) $data['oid']['identifier'] = array(); |
||
64 | foreach ($data['oid']['identifier'] as $identifier) { |
||
88 | daniel-mar | 65 | sql_execute("insert into ".OIDPLUS_TABLENAME_PREFIX."asn1id (oid, name) values ('".OIDplus::db()->real_escape_string("oid:$oid")."', '".OIDplus::db()->real_escape_string($identifier)."');"); |
61 | daniel-mar | 66 | } |
67 | |||
68 | if (!isset($data['oid']['unicode-label'])) $data['oid']['unicode-label'] = array(); |
||
69 | foreach ($data['oid']['unicode-label'] as $identifier) { |
||
88 | daniel-mar | 70 | sql_execute("insert into ".OIDPLUS_TABLENAME_PREFIX."iri (oid, name) values ('".OIDplus::db()->real_escape_string("oid:$oid")."', '".OIDplus::db()->real_escape_string($identifier)."');"); |
61 | daniel-mar | 71 | } |
72 | |||
73 | $parent = ($oid == $root) ? '' : oid_up($oid); |
||
74 | |||
75 | $title = strip_tags(@$data['oid']['description']); |
||
76 | $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); |
||
77 | |||
78 | $description = '<strong>' . trim(@$data['oid']['description']) . '</strong><br><br>' . nl2br(trim(@$data['oid']['information'])); |
||
79 | $description = str_replace(array("\r", "\n"), '', $description); |
||
80 | $description = str_ireplace('<br />', '<br>', $description); |
||
81 | $description = str_ireplace('<br/>', '<br>', $description); |
||
82 | $description = '<p>' . str_ireplace('<br><br>', '</p><p>', $description) . '</p>'; |
||
83 | |||
84 | $ra_email = @$data['oid']['current_registrant']['email']; |
||
85 | if ($ra_email == '') $ra_email = @$data['oid']['first_registrant']['email']; |
||
86 | |||
88 | daniel-mar | 87 | $resx = OIDplus::db()->query("select ra_email from ".OIDPLUS_TABLENAME_PREFIX."objects where id = '".OIDplus::db()->real_escape_string("oid:$parent")."'"); |
77 | daniel-mar | 88 | if ($rowx = OIDplus::db()->fetch_array($resx)) $ra_email = $rowx['ra_email']; |
61 | daniel-mar | 89 | |
90 | $created = @$data['oid']['first_registrant']['creation-date']; |
||
91 | $updated = @$data['oid']['last-modification']; |
||
92 | |||
88 | daniel-mar | 93 | $sql = "insert into ".OIDPLUS_TABLENAME_PREFIX."objects (id, parent, title, description, ra_email, created, updated) values ('".OIDplus::db()->real_escape_string("oid:$oid")."', '".OIDplus::db()->real_escape_string("oid:$parent")."', '".OIDplus::db()->real_escape_string($title)."', '".OIDplus::db()->real_escape_string($description)."', '".OIDplus::db()->real_escape_string($ra_email)."', '".OIDplus::db()->real_escape_string($created)."', '".OIDplus::db()->real_escape_string($updated)."');"; |
61 | daniel-mar | 94 | sql_execute($sql); |
95 | } |
||
96 | |||
97 | function ft_get_oid_data($oid) { |
||
98 | $url = OIDINFO_API_URL . '&oid='.urlencode($oid); |
||
99 | $cont_json = @file_get_contents($url); |
||
100 | if (!$cont_json) { |
||
101 | sleep(5); |
||
102 | $cont_json = @file_get_contents($url); |
||
103 | if (!$cont_json) return false; |
||
104 | } |
||
105 | $data = json_decode($cont_json,true); |
||
106 | |||
107 | return $data; |
||
108 | } |
||
109 | |||
110 | function sql_execute($sql) { |
||
111 | # echo "$sql\n"; |
||
77 | daniel-mar | 112 | OIDplus::db()->query($sql); |
113 | $err = OIDplus::db()->error(); |
||
61 | daniel-mar | 114 | if ($err) echo "Warning: $err at $sql\n"; |
115 | } |