Subversion Repositories oidplus

Rev

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