Subversion Repositories oidplus

Rev

Rev 279 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. class OIDplusPageAdminOIDInfoExport extends OIDplusPagePluginAdmin {
  21.  
  22.         public function action(&$handled) {
  23.                 // Nothing
  24.         }
  25.  
  26.         public function init($html=true) {
  27.                 require_once __DIR__ . '/oidinfo_api.inc.php';
  28.         }
  29.  
  30.         public function gui($id, &$out, &$handled) {
  31.                 if ($id === 'oidplus:export') {
  32.                         $handled = true;
  33.                         $out['title'] = 'Data export';
  34.                         $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
  35.  
  36.                         if (!OIDplus::authUtils()::isAdminLoggedIn()) {
  37.                                 $out['icon'] = 'img/error_big.png';
  38.                                 $out['text'] = '<p>You need to <a '.OIDplus::gui()->link('oidplus:login').'>log in</a> as administrator.</p>';
  39.                                 return;
  40.                         }
  41.  
  42.                         $out['text'] = '<p>Here you can prepare the data export to <b>oid-info.com</b>.</p>'.
  43.                                        '<p><a href="'.OIDplus::webpath(__DIR__).'oidinfo_export.php">Generate XML (all)</a></p>'.
  44.                                        '<p><a href="'.OIDplus::webpath(__DIR__).'oidinfo_export.php?online=1">Generate XML (only non-existing)</a></p>'.
  45.                                        '<p><a href="http://www.oid-info.com/submit.htm">Upload to oid-info.com</a></p>';
  46.                 }
  47.         }
  48.  
  49.         public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
  50.                 if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
  51.                
  52.                 if (file_exists(__DIR__.'/treeicon.png')) {
  53.                         $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
  54.                 } else {
  55.                         $tree_icon = null; // default icon (folder)
  56.                 }
  57.  
  58.                 $json[] = array(
  59.                         'id' => 'oidplus:export',
  60.                         'icon' => $tree_icon,
  61.                         'text' => 'Data export'
  62.                 );
  63.  
  64.                 return true;
  65.         }
  66.  
  67.         public function tree_search($request) {
  68.                 return false;
  69.         }
  70.  
  71.         public static function outputXML($only_non_existing) {
  72.                 $oa = new OIDInfoAPI();
  73.                 $oa->addSimplePingProvider('viathinksoft.de:49500');
  74.  
  75.                 $email = OIDplus::config()->getValue('admin_email');
  76.                 if (empty($email)) $email = 'unknown@example.com';
  77.  
  78.                 echo $oa->xmlAddHeader(OIDplus::config()->getValue('system_title'), isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'Export interface', $email);
  79.  
  80.                 $params['allow_html'] = true;
  81.                 $params['allow_illegal_email'] = true; // It should be enabled, because the creator could have used some kind of human-readable anti-spam technique
  82.                 $params['soft_correct_behavior'] = OIDInfoAPI::SOFT_CORRECT_BEHAVIOR_NONE;
  83.                 $params['do_online_check'] = false; // Flag to disable this online check, because it generates a lot of traffic and runtime.
  84.                 $params['do_illegality_check'] = true;
  85.                 $params['do_simpleping_check'] = $only_non_existing;
  86.                 $params['auto_extract_name'] = '';
  87.                 $params['auto_extract_url'] = '';
  88.                 $params['always_output_comment'] = false;
  89.                 $params['creation_allowed_check'] = $only_non_existing;
  90.                 $params['tolerant_htmlentities'] = true;
  91.                 $params['ignore_xhtml_light'] = false;
  92.  
  93.                 $nonConfidential = OIDplusObject::getAllNonConfidential();
  94.                 natsort($nonConfidential);
  95.  
  96.                 foreach ($nonConfidential as $id) {
  97.                         $res = OIDplus::db()->query("select * from ###objects where id = ?", array($id));
  98.                         if ($row = $res->fetch_object()) {
  99.                                 $elements['identifier'] = array();
  100.                                 $res2 = OIDplus::db()->query("select * from ###asn1id where oid = ?", array($row->id));
  101.                                 while ($row2 = $res2->fetch_object()) {
  102.                                         $elements['identifier'][] = $row2->name; // 'unicode-label' is currently not in the standard format (oid.xsd)
  103.                                 }
  104.  
  105.                                 $elements['unicode-label'] = array();
  106.                                 $res2 = OIDplus::db()->query("select * from ###iri where oid = ?", array($row->id));
  107.                                 while ($row2 = $res2->fetch_object()) {
  108.                                         $elements['unicode-label'][] = $row2->name;
  109.                                 }
  110.  
  111.                                 if (!empty($row->title)) {
  112.                                         $elements['description'] = $row->title;
  113.                                         $elements['information'] = $row->description;
  114.                                         if (trim($row->title) == trim(strip_tags($row->description))) {
  115.                                                 $elements['information'] = '';
  116.                                         }
  117.                                 } else if (isset($elements['identifier'][0])) {
  118.                                         $elements['description'] = '"'.$elements['identifier'][0].'"';
  119.                                         $elements['information'] = $row->description;
  120.                                 } else if (isset($elements['unicode-label'][0])) {
  121.                                         $elements['description'] = '"'.$elements['unicode-label'][0].'"';
  122.                                         $elements['information'] = $row->description;
  123.                                 } else if (!empty($row->description)) {
  124.                                         $elements['description'] = $row->description;
  125.                                         $elements['information'] = '';
  126.                                 } else if (!empty($row->comment)) {
  127.                                         $elements['description'] = $row->comment;
  128.                                         $elements['information'] = '';
  129.                                 } else {
  130.                                         $elements['description'] = '<i>No description available</i>';
  131.                                         $elements['information'] = '';
  132.                                 }
  133.  
  134.                                 if ($elements['information'] != '') {
  135.                                         $elements['information'] .= '<br/><br/>';
  136.                                 }
  137.  
  138.                                 $elements['information'] .= 'See <a href="'.OIDplus::getSystemUrl(false).'?goto='.urlencode($id).'">more information</a>.'; // TODO: system_url() geht nicht bei CLI
  139.  
  140.                                 if (explode(':',$id,2)[0] != 'oid') {
  141.                                         $elements['information'] = "Object: $id\n\n" . $elements['information'];
  142.                                 }
  143.  
  144.                                 $elements['description'] = self::repair_relative_links($elements['description']);
  145.                                 $elements['information'] = self::repair_relative_links($elements['information']);
  146.  
  147.                                 $elements['first-registrant']['first-name'] = '';
  148.                                 $elements['first-registrant']['last-name'] = '';
  149.                                 $elements['first-registrant']['address'] = '';
  150.                                 $elements['first-registrant']['email'] = '';
  151.                                 $elements['first-registrant']['phone'] = '';
  152.                                 $elements['first-registrant']['fax'] = '';
  153.                                 $elements['first-registrant']['creation-date'] = self::_formatdate($row->created);
  154.  
  155.                                 $elements['current-registrant']['first-name'] = '';
  156.                                 $elements['current-registrant']['last-name'] = '';
  157.                                 $elements['current-registrant']['email'] = $row->ra_email;
  158.                                 $elements['current-registrant']['phone'] = '';
  159.                                 $elements['current-registrant']['fax'] = '';
  160.                                 $elements['current-registrant']['address'] = '';
  161.  
  162.                                 $res2 = OIDplus::db()->query("select * from ###ra where email = ?", array($row->ra_email));
  163.                                 if ($res2->num_rows() > 0) {
  164.                                         $row2 = $res2->fetch_object();
  165.  
  166.                                         $tmp = array();
  167.                                         if (!empty($row2->personal_name)) {
  168.                                                 $name_ary = split_firstname_lastname($row2->personal_name);
  169.                                                 $elements['current-registrant']['first-name'] = $name_ary[0];
  170.                                                 $elements['current-registrant']['last-name']  = $name_ary[1];
  171.                                                 if (!empty($row2->ra_name)       ) $tmp[] = $row2->ra_name;
  172.                                                 if (!empty($row2->office)        ) $tmp[] = $row2->office;
  173.                                                 if (!empty($row2->organization)  ) $tmp[] = $row2->organization;
  174.                                         } else {
  175.                                                 $elements['current-registrant']['first-name'] = $row2->ra_name;
  176.                                                 $elements['current-registrant']['last-name']  = '';
  177.                                                 if (!empty($row2->personal_name) ) $tmp[] = $row2->personal_name;
  178.                                                 if (!empty($row2->office)        ) $tmp[] = $row2->office;
  179.                                                 if (!empty($row2->organization)  ) $tmp[] = $row2->organization;
  180.                                         }
  181.  
  182.                                         if ((count($tmp) > 0) && ($tmp[0] == $row2->ra_name)) array_shift($tmp);
  183.                                         array_unique($tmp);
  184.  
  185.                                         if (!$row2->privacy) {
  186.                                                 if (!empty($row2->street))   $tmp[] = $row2->street;
  187.                                                 if (!empty($row2->zip_town)) $tmp[] = $row2->zip_town;
  188.                                                 if (!empty($row2->country))  $tmp[] = $row2->country;
  189.                                                 $elements['current-registrant']['phone'] = !empty($row2->phone) ? $row2->phone : $row2->mobile;
  190.                                                 $elements['current-registrant']['fax'] = $row2->fax;
  191.                                         }
  192.                                         if (empty($row2->zip_town) && empty($row2->country)) {
  193.                                                 // The address is useless if we do neither know city nor country
  194.                                                 // Ignore it
  195.                                                 $elements['current-registrant']['address'] = '';
  196.                                         } else {
  197.                                                 $elements['current-registrant']['address'] = implode("<br/>", $tmp);
  198.                                         }
  199.                                 }
  200.                                 $elements['current-registrant']['modification-date'] = self::_formatdate($row->updated);
  201.  
  202.                                 // Request from O.D. 20 May 2019: First registrant should not be empty (especially for cases where Creation and Modify Dates are the same)
  203.                                 // Actually, this is a problem because we don't know the first registrant.
  204.                                 // However, since oidinfo gets their XML very fast (if using registration), it is likely that the reported RA is still the same...
  205.                                 // ... and changes at the RA are not reported to oid-info.com anyways - the XML is only for creation
  206.  
  207.                                 $elements['first-registrant']['first-name'] = $elements['current-registrant']['first-name'];
  208.                                 $elements['first-registrant']['last-name']  = $elements['current-registrant']['last-name'];
  209.                                 $elements['first-registrant']['address']    = $elements['current-registrant']['address'];
  210.                                 $elements['first-registrant']['email']      = $elements['current-registrant']['email'];
  211.                                 $elements['first-registrant']['phone']      = $elements['current-registrant']['phone'];
  212.                                 $elements['first-registrant']['fax']        = $elements['current-registrant']['fax'];
  213.  
  214.                                 $elements['current-registrant']['first-name'] = '';
  215.                                 $elements['current-registrant']['last-name'] = '';
  216.                                 $elements['current-registrant']['address'] = '';
  217.                                 $elements['current-registrant']['email'] = '';
  218.                                 $elements['current-registrant']['phone'] = '';
  219.                                 $elements['current-registrant']['fax'] = '';
  220.                                 $elements['current-registrant']['modification-date'] = '';
  221.  
  222.                                 // End request O.D. 20 May 2019
  223.  
  224.                                 $obj = OIDplusObject::parse($row->id);
  225.  
  226.                                 list($ns,$id) = explode(':',$obj->nodeId());
  227.                                 if ($ns == 'oid') {
  228.                                         echo $oa->createXMLEntry($id, $elements, $params, $comment=$obj->nodeId());
  229.                                 }
  230.  
  231.                                 $alt_ids = $obj->getAltIds(); // TODO: slow!
  232.                                 foreach ($alt_ids as $alt_id) {
  233.                                         $ns = $alt_id->getNamespace();
  234.                                         $id = $alt_id->getId();
  235.                                         $desc = $alt_id->getDescription();
  236.                                         if ($ns == 'oid') {
  237.                                                 if (strpos($id, '2.25.') === 0) continue; // don't spam the uuid arc with GUID objects
  238.                                                 echo $oa->createXMLEntry($id, $elements, $params, $comment=$obj->nodeId());
  239.                                         }
  240.                                 }
  241.                         }
  242.                 }
  243.  
  244.                 echo $oa->xmlAddFooter();
  245.         }
  246.  
  247.         private static function _formatdate($str) {
  248.                 $str = explode(' ',$str)[0];
  249.                 if ($str == '0000-00-00') $str = '';
  250.                 return $str;
  251.         }
  252.  
  253.         private static function repair_relative_links($str) {
  254.                 $str = preg_replace_callback('@(href\s*=\s*([\'"]))(.+)(\\2)@ismU', function($treffer) {
  255.                         $url = $treffer[3];
  256.                         if ((stripos($url,'http:') !== 0) && (stripos($url,'https:') !== 0) && (stripos($url,'ftp:') !== 0)) {
  257.                                 if (stripos($url,'www.') === 0) {
  258.                                         $url .= 'http://' . $url;
  259.                                 } else {
  260.                                         $url = OIDplus::getSystemUrl() . $url;
  261.                                 }
  262.                         }
  263.                         return $treffer[1].$url.$treffer[4];
  264.                 }, $str);
  265.                 return $str;
  266.         }
  267. }
  268.