Subversion Repositories oidplus

Rev

Rev 754 | Rev 756 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2022 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. header('Content-Type:text/html; charset=UTF-8');
  21.  
  22. require_once __DIR__ . '/../../../../includes/oidplus.inc.php';
  23.  
  24. set_exception_handler(array('OIDplusGui', 'html_exception_handler'));
  25.  
  26. OIDplus::init(true);
  27.  
  28. if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminOIDInfoExport', false)) {
  29.         throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
  30. }
  31.  
  32. if (!class_exists('ZipArchive')) {
  33.         throw new OIDplusException(_L('The PHP extension "ZipArchive" needs to be installed to create a ZIP archive with an included database. Otherwise, you can just download the plain program without data.'));
  34. }
  35.  
  36. $dos_ids = array();
  37. $parent_oids = array();
  38. $i = 0;
  39. $dos_ids[''] = '00000000';
  40. $parent_oids[''] = '';
  41.  
  42. $dos_ids[''] = str_pad($i++, 8, '0', STR_PAD_LEFT);
  43. $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id'));
  44. while ($row = $res->fetch_object()) {
  45.         $oid = substr($row->id, strlen('oid:'));
  46.         $parent_oid = substr($row->parent, strlen('oid:'));
  47.         $dos_ids[$oid] = str_pad($i++, 8, '0', STR_PAD_LEFT);
  48.         if ($parent_oid == '') {
  49.                 $parent_oids[$oid] = '';
  50.         } else {
  51.                 $parent_oids[$oid] = $parent_oid;
  52.         }
  53. }
  54.  
  55. $tmp_file = OIDplus::localpath().'userdata/dos_export.zip';
  56.  
  57. $zip = new ZipArchive();
  58. if ($zip->open($tmp_file, ZipArchive::CREATE)!== true) {
  59.         throw new OIDplusException("cannot open <$tmp_file>");
  60. }
  61.  
  62. foreach ($dos_ids as $oid => $dos_id) {
  63.         $cont = '';
  64.  
  65.         $cont .= "VERS2022\r\n";
  66.  
  67.         $cont .= "SELF$dos_id$oid\r\n";
  68.  
  69.         $parent_oid = $parent_oids[$oid];
  70.         $parent_id = $dos_ids[$parent_oid];
  71.         $cont .= "SUPR$parent_id$parent_oid\r\n";
  72.  
  73.         foreach ($parent_oids as $child_oid => $parent_oid) {
  74.                 if ($child_oid == '') continue;
  75.                 if ($parent_oid == $oid) {
  76.                         $child_id = $dos_ids[$child_oid];
  77.                         $cont .= "CHLD$child_id$child_oid\r\n";
  78.                 }
  79.         }
  80.  
  81.         $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'");
  82.         while ($row = $res->fetch_object()) {
  83.                 $asn1 = $row->name;
  84.                 $cont .= "ASN1$asn1\r\n";
  85.         }
  86.  
  87.         $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'");
  88.         while ($row = $res->fetch_object()) {
  89.                 $iri = $row->name;
  90.                 $cont .= "UNIL$iri\r\n";
  91.         }
  92.  
  93.         if ($oid == '') {
  94.                 // TODO: Split in single parent OIDs
  95.                 $cont .= "DESCHere, you can find the root OIDs.\r\n";
  96.         } else {
  97.                 $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';");
  98.                 $row = $res->fetch_object();
  99.                 $desc = trim(trim(strip_tags($row->description)));
  100.                 $desc = str_replace("\r", "", $desc);
  101.                 $desc = str_replace("\n", "  ", $desc);
  102.                 $desc_ary1 = explode("\r\n", wordwrap($desc, 80/*TREEVIEW_WIDTH*/, "\r\n", true));
  103.                 $desc_ary2 = explode("\r\n", wordwrap($row->title, 80/*TREEVIEW_WIDTH*/, "\r\n", true));
  104.                 if (implode('',$desc_ary1) == '') $desc_ary1 = array();
  105.                 if (implode('',$desc_ary2) == '') $desc_ary2 = array();
  106.                 $desc_ary = array_merge($desc_ary1, $desc_ary2);
  107.                 foreach ($desc_ary as $line_idx => $line) {
  108.                         if ($line_idx >= 10/*DESCEDIT_LINES*/) break;
  109.                         $cont .= "DESC$line\r\n";
  110.                 }
  111.         }
  112.  
  113.         //echo "****$dos_id.OID\r\n";
  114.         //echo "$cont\r\n";
  115.  
  116.         $zip->addFromString("$dos_id.OID", $cont);
  117. }
  118.  
  119. $exe_url = 'https://github.com/danielmarschall/oidplus_dos/raw/master/OIDPLUS.EXE';
  120. $exe = @file_get_contents($exe_url);
  121. if ($exe == '') {
  122.         throw new OIDplusException(_L("Cannot download the binary file from GitHub (%1)", $exe_url));
  123. }
  124. $zip->addFromString('OIDPLUS.EXE', $exe);
  125.  
  126. $zip->close();
  127.  
  128. if (!headers_sent()) {
  129.         header('Content-Type: application/zip');
  130.         header('Content-Disposition: attachment; filename=oidplus_dos.zip');
  131.         readfile($tmp_file);
  132. }
  133.  
  134. unlink($tmp_file);
  135.  
  136. OIDplus::invoke_shutdown();
  137.