Rev 77 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
61 | daniel-mar | 1 | #!/usr/bin/php |
2 | <?php |
||
3 | |||
4 | require_once __DIR__ . '/../oidplus/includes/oidplus.inc.php'; |
||
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 | |||
32 | $res = mysql_query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where id = 'oid:$oid'"); |
||
33 | $ok = mysql_num_rows($res) > 0; |
||
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 | |||
58 | $sql = "insert into ".OIDPLUS_TABLENAME_PREFIX."objects (id, parent, title, description, ra_email) values ('oid:".mysql_real_escape_string($oid)."', 'oid:".mysql_real_escape_string($parent)."', '".mysql_real_escape_string($title)."', '".mysql_real_escape_string($description)."', '".mysql_real_escape_string($ra_email)."');"; |
||
59 | sql_execute($sql); |
||
60 | |||
61 | return; |
||
62 | } |
||
63 | |||
64 | if (!isset($data['oid']['identifier'])) $data['oid']['identifier'] = array(); |
||
65 | foreach ($data['oid']['identifier'] as $identifier) { |
||
66 | $sql = "insert into ".OIDPLUS_TABLENAME_PREFIX."asn1id (oid, name) values ('oid:".mysql_real_escape_string($oid)."', '".mysql_real_escape_string($identifier)."');"; |
||
67 | sql_execute($sql); |
||
68 | } |
||
69 | |||
70 | if (!isset($data['oid']['unicode-label'])) $data['oid']['unicode-label'] = array(); |
||
71 | foreach ($data['oid']['unicode-label'] as $identifier) { |
||
72 | $sql = "insert into ".OIDPLUS_TABLENAME_PREFIX."iri (oid, name) values ('oid:".mysql_real_escape_string($oid)."', '".mysql_real_escape_string($identifier)."');"; |
||
73 | sql_execute($sql); |
||
74 | } |
||
75 | |||
76 | $parent = ($oid == $root) ? '' : oid_up($oid); |
||
77 | |||
78 | $title = strip_tags(@$data['oid']['description']); |
||
79 | $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); |
||
80 | |||
81 | $description = '<strong>' . trim(@$data['oid']['description']) . '</strong><br><br>' . nl2br(trim(@$data['oid']['information'])); |
||
82 | $description = str_replace(array("\r", "\n"), '', $description); |
||
83 | $description = str_ireplace('<br />', '<br>', $description); |
||
84 | $description = str_ireplace('<br/>', '<br>', $description); |
||
85 | $description = '<p>' . str_ireplace('<br><br>', '</p><p>', $description) . '</p>'; |
||
86 | |||
87 | $ra_email = @$data['oid']['current_registrant']['email']; |
||
88 | if ($ra_email == '') $ra_email = @$data['oid']['first_registrant']['email']; |
||
89 | |||
90 | $resx = mysql_query("select ra_email from ".OIDPLUS_TABLENAME_PREFIX."objects where id = 'oid:".mysql_real_escape_string($parent)."'"); |
||
91 | if ($rowx = mysql_fetch_array($resx)) $ra_email = $rowx['ra_email']; |
||
92 | |||
93 | $created = @$data['oid']['first_registrant']['creation-date']; |
||
94 | $updated = @$data['oid']['last-modification']; |
||
95 | |||
96 | $sql = "insert into ".OIDPLUS_TABLENAME_PREFIX."objects (id, parent, title, description, ra_email, created, updated) values ('oid:".mysql_real_escape_string($oid)."', 'oid:".mysql_real_escape_string($parent)."', '".mysql_real_escape_string($title)."', '".mysql_real_escape_string($description)."', '".mysql_real_escape_string($ra_email)."', '".mysql_real_escape_string($created)."', '".mysql_real_escape_string($updated)."');"; |
||
97 | sql_execute($sql); |
||
98 | } |
||
99 | |||
100 | function ft_get_oid_data($oid) { |
||
101 | $url = OIDINFO_API_URL . '&oid='.urlencode($oid); |
||
102 | $cont_json = @file_get_contents($url); |
||
103 | if (!$cont_json) { |
||
104 | sleep(5); |
||
105 | $cont_json = @file_get_contents($url); |
||
106 | if (!$cont_json) return false; |
||
107 | } |
||
108 | $data = json_decode($cont_json,true); |
||
109 | |||
110 | return $data; |
||
111 | } |
||
112 | |||
113 | function sql_execute($sql) { |
||
114 | # echo "$sql\n"; |
||
115 | mysql_query($sql); |
||
116 | $err = mysql_error(); |
||
117 | if ($err) echo "Warning: $err at $sql\n"; |
||
118 | } |