Subversion Repositories oidplus

Rev

Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. include_once __DIR__ . '/../../includes/config.inc.php';
  4.  
  5. if (!OIDINFO_EXPORT_ENABLED) {
  6.         die('Export disabled via switch OIDINFO_EXPORT_ENABLED.');
  7. }
  8.  
  9. header("Content-type: text/xml");
  10.  
  11. set_time_limit(0);
  12.  
  13. include_once __DIR__ . '/../../includes/oid_plus.inc.php';
  14. include_once __DIR__ . '/../../includes/oid_utils.inc.php';
  15. include_once __DIR__ . '/../../includes/gui.inc.php';
  16. include_once __DIR__ . '/../../includes/oidinfo_api.inc.php';
  17.  
  18. # TODO: mehr konfigurierbar...
  19. # TODO ra(1)-person etc.... ra(2)  --> regex ?
  20. # URL of OID+ system
  21. # Also add non-desription-fields, e.g. "whois" @freeoid
  22. # exclude GenRoot (aber was ist mit UUID definitions?)
  23. # Check if OID is available at oidinfo
  24. # nach dem rausfiltern soll make_tabs erneut aufgerufen werden...
  25.  
  26. # FreeOID: versuchen, vor und nachname aufzusplitten?
  27.  
  28. $db = new OIDPlus(__DIR__ . '/../../db/local.conf', true);
  29. $db->addDir(__DIR__ . '/../../db');
  30. $x = $db->listAllOIDs('.');
  31.  
  32. $oa = new OIDInfoAPI();
  33.  
  34. if (defined('OIDINFO_EXPORT_SIMPLEPINGPROVIDER')) {
  35.         $oa->addSimplePingProvider(OIDINFO_EXPORT_SIMPLEPINGPROVIDER);
  36. }
  37.  
  38.  
  39. echo $oa->xmlAddHeader(OIDINFO_EXPORT_SUBMITTER_FIRST_NAME,
  40.                        OIDINFO_EXPORT_SUBMITTER_LAST_NAME,
  41.                        OIDINFO_EXPORT_SUBMITTER_EMAIL);
  42.  
  43. $params['allow_html'] = true; // TODO: allow_whitespaces !
  44. $params['allow_illegal_email'] = true;
  45. $params['soft_correct_behavior'] = OIDInfoAPI::SOFT_CORRECT_BEHAVIOR_NONE;
  46. $params['do_online_check'] = false; // true;
  47. $params['do_illegality_check'] = true;
  48. $params['do_csv_check'] = true;
  49. $params['auto_extract_name'] = '';
  50. $params['auto_extract_url'] = '';
  51. $params['always_output_comment'] = false;
  52. $params['creation_allowed_check'] = defined('OIDINFO_EXPORT_SIMPLEPINGPROVIDER');
  53.  
  54. foreach ($x as $oid) {
  55.         $filtered = array();
  56.  
  57.         $std_oid = substr($oid, 1);
  58.  
  59.         if (!$db->oidDescribed($oid)) continue;
  60.  
  61.         $cont = $db->showSingleOID($oid, '', OIDPlus::SEG_OIDDATA, true /*false*/);
  62.         $cont = $db->filterRedactedEntries($cont);
  63.  
  64.         $ra_person_name = _filter($cont, 'ra(1)-person-name', false, false);
  65.         $ra_org_name = _filter($cont, 'ra(1)-name', false, false);
  66.         $pre_addr = '';
  67.         if ($ra_person_name != '') {
  68.                 $xry = explode(' ', $ra_person_name, 2);
  69.                 $prename = $xry[0];
  70.                 $famname = $xry[1];
  71.                 $pre_addr = $ra_org_name;
  72.         } else {
  73.                 $prename = $ra_org_name;
  74.                 $famname = '';
  75.                 $pre_addr  = '';
  76.         }
  77.  
  78. /*
  79.         $a_fto_curra_name = array();
  80.         _add($a_fto_curra_name, _filter($cont, 'ra(1)-name', false, false));
  81.         _add($a_fto_curra_name, _filter($cont, 'ra(1)-person-name', false, false));
  82.         $fto_curra_name = implode(' / ', $a_fto_curra_name);
  83. */
  84.  
  85.         # naja... mit dem neuen code sieht das aus, als ob die VTS RA in MEINER adresse wäre...
  86.  
  87.         $a_fto_curra_address_p = array();
  88.         _add($a_fto_curra_address_p, _filter($cont, 'ra(1)-person-org', false, false));
  89.         _add($a_fto_curra_address_p, _filter($cont, 'ra(1)-person-organisation', false, false));
  90.         _add($a_fto_curra_address_p, _filter($cont, 'ra(1)-person-address', false, false));
  91.         _add($a_fto_curra_address_p, _country(_filter($cont, 'ra(1)-person-country', false, false)));
  92.         $a_fto_curra_address_o = array();
  93.         _add($a_fto_curra_address_o, _filter($cont, 'ra(1)-org', false, false));
  94.         _add($a_fto_curra_address_o, _filter($cont, 'ra(1)-organisation', false, false));
  95.         _add($a_fto_curra_address_o, _filter($cont, 'ra(1)-address', false, false));
  96.         _add($a_fto_curra_address_o, _country(_filter($cont, 'ra(1)-country', false, false)));
  97.         if (implode("\n", $a_fto_curra_address_o) != '') {
  98.                 $fto_curra_address = implode("\n", $a_fto_curra_address_o);
  99.         } else {
  100.                 $fto_curra_address = implode("\n", $a_fto_curra_address_p);
  101.         }
  102.         if ($pre_addr != '') $fto_curra_address = $pre_addr."\n".$fto_curra_address;
  103.         $fto_curra_address = _formatHTML($fto_curra_address, false);
  104.  
  105.         $fto_curra_email_p = _filter($cont, 'ra(1)-person-email', false, false);
  106.         $fto_curra_email_o = _filter($cont, 'ra(1)-email', false, false);
  107.         if ($fto_curra_email_o != '') {
  108.                 $fto_curra_email = $fto_curra_email_o;
  109.         } else {
  110.                 $fto_curra_email = $fto_curra_email_p;
  111.         }
  112.  
  113.         $fto_curra_phone_p = _filter($cont, 'ra(1)-person-phone', false, false);
  114.         $fto_curra_phone_o = _filter($cont, 'ra(1)-phone', false, false);
  115.         if ($fto_curra_phone_o != '') {
  116.                 $fto_curra_phone = $fto_curra_phone_o;
  117.         } else {
  118.                 $fto_curra_phone = $fto_curra_phone_p;
  119.         }
  120.  
  121.         $fto_curra_fax_p = _filter($cont, 'ra(1)-person-fax', false, false);
  122.         $fto_curra_fax_o = _filter($cont, 'ra(1)-fax', false, false);
  123.         if ($fto_curra_fax_o != '') {
  124.                 $fto_curra_fax = $fto_curra_fax_o;
  125.         } else {
  126.                 $fto_curra_fax = $fto_curra_fax_p;
  127.         }
  128.  
  129.         $att_changed = _filter($cont, 'modified', false, false);
  130.         if ($att_changed == '') $att_changed = _filter($cont, 'changed', false, false);
  131.         $att_changed = _findDate($att_changed);
  132.         if ($att_changed == '0000-00-00') $att_changed = '';
  133.  
  134.         $att_created = _filter($cont, 'created', false, false);
  135.         if ($att_created == '') $att_created = _filter($cont, 'assigned', false, false);
  136.         if ($att_created == '') $att_created = _filter($cont, 'allocated', false, false);
  137.         $att_created = _findDate($att_created);
  138.         if ($att_created == '0000-00-00') $att_created = '';
  139.  
  140.         $att_asn1_id = explode("\n", trim(_filter($cont, 'identifier', false, false)));
  141.  
  142.         $att_description = _filter($cont, 'description', false, false);
  143.         $att_information = _filter($cont, 'information', false, false) . "\n\n" . _filter($cont, 'comment', false, false);
  144.         $att_name        = _filter($cont, 'name', false, false);
  145.         if (!empty($att_name)) {
  146.                 $fto_desc = $att_name;
  147.                 $fto_info = $att_description."\n\n".$att_information;
  148.         } else {
  149.                 $fto_desc = $att_description;
  150.                 $fto_info = $att_information;
  151.         }
  152.  
  153.         $xry = explode('. ', $fto_desc, 2);
  154.         if (count($xry) > 1) {
  155.                 $fto_desc = $xry[0];
  156.                 $fto_info = (($xry[1] == '') ? $xry[1]."\n\n" : '').$fto_info;
  157.         }
  158.  
  159.         if (($fto_desc == '') && isset($att_asn1_id[0])) {
  160.                 $fto_desc = $att_asn1_id[0];
  161.         }
  162.  
  163.  
  164.  
  165.         $rawdata = array();
  166.  
  167.         $ary = explode("\n", $cont);
  168.         foreach ($ary as $a) {
  169.                 $bry = explode(":", $a);
  170.                 $b = trim($bry[0]);
  171.  
  172.                 if (($b == 'attribute') && (isset($bry[1]))) {
  173.                         $val = strtoupper(trim($bry[1]));
  174.                         if ($val == 'DRAFT') continue 2; // do not export this OID at all
  175.                         if ($val == 'NOEXPORT') continue 2; // do not export this OID at all
  176.                 }
  177.  
  178.                 if (isset($filtered[$b])) continue;
  179.                 if (substr($b, 0, 3) == 'ra(') continue;
  180.  
  181.                 if ($b == 'index(uuid)') $a = 'UUID: '.trim($bry[1]);
  182.                 if ($b == 'index(doi)') $a = 'DOI: '.trim($bry[1]);
  183.                 if ($b == 'index(ipv4)') $a = 'IPv4: '.trim($bry[1]);
  184.                 if ($b == 'index(ipv6)') $a = 'IPv6: '.trim($bry[1]);
  185.                 if ($b == 'index(domain)') $a = 'Domain: '.trim($bry[1]);
  186.                 if ($b == 'unicodelabel') $a = 'Unicode label (IRI): '.trim($bry[1]);
  187.                 if ($b == 'attribute') $a = 'Attribute: '.ucfirst(trim($bry[1]));
  188.  
  189.                 $a = ucfirst($a);
  190.  
  191.                 $rawdata[] = $a;
  192.         }
  193.         $rawdata = implode("\n", $rawdata);
  194.  
  195.         $fto_info .= "\n\n$rawdata"; // TODO: test
  196.  
  197.  
  198.  
  199.         $fto_info = preg_replace('@^\n+@ism', '', $fto_info);
  200.         $fto_desc = preg_replace('@^\n+@ism', '', $fto_desc);
  201.  
  202.         $fto_info = preg_replace('@\n+$@ism', '', $fto_info);
  203.         $fto_desc = preg_replace('@\n+$@ism', '', $fto_desc);
  204.  
  205.         $fto_info = preg_replace('@\n{3,}$@ism', "\n\n", $fto_info);
  206.         $fto_desc = preg_replace('@\n{3,}$@ism', "\n\n", $fto_desc);
  207.  
  208.         $use_monospace_desc = OIDINFO_EXPORT_SUBMITTER_ONLY_MONOSPACE;
  209.         if (!$use_monospace_desc) {
  210.                 # Try to find evidence of ASCII art
  211.                 if (strpos($fto_desc, '----') !== false) {
  212.                         $use_monospace_desc = true;
  213.                 }
  214.         }
  215.  
  216.         $use_monospace_info = OIDINFO_EXPORT_SUBMITTER_ONLY_MONOSPACE;
  217.         if (!$use_monospace_info) {
  218.                 # Try to find evidence of ASCII art
  219.                 if (strpos($fto_info, '----') !== false) {
  220.                         $use_monospace_info = true;
  221.                 }
  222.         }
  223.  
  224.         $fto_desc = _formatHTML($fto_desc, $use_monospace_desc);
  225.         $fto_info = _formatHTML($fto_info, $use_monospace_info);
  226.  
  227.         # OID-Info does not accept <pre>.
  228.         $fto_desc = str_replace('<pre>', '<code>', $fto_desc);
  229.         $fto_info = str_replace('<pre>', '<code>', $fto_info);
  230.         $fto_desc = str_replace('</pre>', '</code>', $fto_desc);
  231.         $fto_info = str_replace('</pre>', '</code>', $fto_info);
  232.  
  233.         $elements = array();
  234.  
  235.         $elements['synonymous-identifier'] = $att_asn1_id;
  236.         $elements['description'] = $fto_desc;
  237.         $elements['information'] = $fto_info;
  238.  
  239.         $elements['first-registrant']['first-name'] = '';
  240.         $elements['first-registrant']['last-name'] = '';
  241.         $elements['first-registrant']['address'] = '';
  242.         $elements['first-registrant']['email'] = '';
  243.         $elements['first-registrant']['phone'] = '';
  244.         $elements['first-registrant']['fax'] = '';
  245.         $elements['first-registrant']['creation-date'] = '';
  246.         if ($att_created != '') {
  247.                 if ($att_changed == '') { // We only save the current RA, because if the OID was changed, we do not know the old RA
  248.                         $elements['first-registrant']['first-name'] = $prename;
  249.                         $elements['first-registrant']['last-name'] = $famname;
  250.                         $elements['first-registrant']['address'] = $fto_curra_address;
  251.                         $elements['first-registrant']['email'] = $fto_curra_email;
  252.                         $elements['first-registrant']['phone'] = $fto_curra_phone;
  253.                         $elements['first-registrant']['fax'] = $fto_curra_fax;
  254.                 }
  255.                 $elements['first-registrant']['creation-date'] = $att_created;
  256.         }
  257.  
  258. /*
  259.         $elements['current-registrant']['first-name'] = '';
  260.         $elements['current-registrant']['last-name'] = '';
  261.         $elements['current-registrant']['address'] = '';
  262.         $elements['current-registrant']['email'] = '';
  263.         $elements['current-registrant']['phone'] = '';
  264.         $elements['current-registrant']['fax'] = '';
  265.         $elements['current-registrant']['modification-date'] = '';
  266.         if ($att_changed != '') {
  267.                 $elements['current-registrant']['first-name'] = $prename;
  268.                 $elements['current-registrant']['last-name'] = $famname;
  269.                 $elements['current-registrant']['address'] = $fto_curra_address;
  270.                 $elements['current-registrant']['email'] = $fto_curra_email; // TODO: wieso gibt es da ein "<br />\n" , das dann zu "<br /><br />" wird ?
  271.                 $elements['current-registrant']['phone'] = $fto_curra_phone;
  272.                 $elements['current-registrant']['fax'] = $fto_curra_fax;
  273.                 $elements['current-registrant']['modification-date'] = $att_changed;
  274.         }
  275. */
  276.         $elements['current-registrant']['first-name'] = $prename;
  277.         $elements['current-registrant']['last-name'] = $famname;
  278.         $elements['current-registrant']['address'] = $fto_curra_address;
  279.         $elements['current-registrant']['email'] = $fto_curra_email; // TODO: wieso gibt es da ein "<br />\n" , das dann zu "<br /><br />" wird ?
  280.         $elements['current-registrant']['phone'] = $fto_curra_phone;
  281.         $elements['current-registrant']['fax'] = $fto_curra_fax;
  282.         if ($att_changed != '') {
  283.                 $elements['current-registrant']['modification-date'] = $att_changed;
  284.         }
  285.  
  286.         echo $oa->createXMLEntry($std_oid, $elements, $params);
  287. }
  288.  
  289. echo $oa->xmlAddFooter();
  290.  
  291. # ---
  292.  
  293. function _formatHTML($cont, $monospace) {
  294.         global $db;
  295.         return showHTML(trim($cont), $db, false, $monospace);
  296. }
  297.  
  298. function _filter($cont, $name, $preg=false, $including_name=true) {
  299.         global $filtered;
  300.         $filtered[$name] = true;
  301.  
  302.         global $db;
  303.         $res = $db->filterOutput($cont, $name, $preg, $including_name);
  304.         return trim($res);
  305. }
  306.  
  307. function _add(&$a, $c) {
  308.         if ($c != '') $a[] = $c;
  309. }
  310.  
  311. function _findDate($x) {
  312.         $ary = explode(' ', $x);
  313.         foreach ($ary as $v) {
  314.                 if (preg_match('@\\d{4}-\\d{2}-\\d{2}@', $v)) return $v;
  315.         }
  316.         return false;
  317. }
  318.  
  319. function _country($country) {
  320.         return Locale::getDisplayRegion('-'.$country, 'en');
  321. }
  322.  
  323.