Subversion Repositories oidplus

Rev

Rev 1125 | Rev 1131 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1125 Rev 1130
Line 23... Line 23...
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPageAdminOIDInfoExport extends OIDplusPagePluginAdmin {
26
class OIDplusPageAdminOIDInfoExport extends OIDplusPagePluginAdmin {
27
 
27
 
-
 
28
        /**
-
 
29
         *
-
 
30
         */
28
        /*private*/ const QUERY_LIST_OIDINFO_OIDS_V1 = '1.3.6.1.4.1.37476.2.5.2.1.5.1';
31
        /*private*/ const QUERY_LIST_OIDINFO_OIDS_V1 = '1.3.6.1.4.1.37476.2.5.2.1.5.1';
-
 
32
 
-
 
33
        /**
-
 
34
         *
-
 
35
         */
29
        /*private*/ const QUERY_GET_OIDINFO_DATA_V1  = '1.3.6.1.4.1.37476.2.5.2.1.6.1';
36
        /*private*/ const QUERY_GET_OIDINFO_DATA_V1  = '1.3.6.1.4.1.37476.2.5.2.1.6.1';
30
 
37
 
31
        /**
38
        /**
32
         * @param string $actionID
39
         * @param string $actionID
33
         * @param array $params
40
         * @param array $params
Line 140... Line 147...
140
                        }
147
                        }
141
 
148
 
142
                        if (isset($json['error']) || ($json['status'] < 0)) {
149
                        if (isset($json['error']) || ($json['status'] < 0)) {
143
                                return array(
150
                                return array(
144
                                        "status" => -1,
151
                                        "status" => -1,
145
                                        "error" => isset($json['error']) ? $json['error'] : _L('Received error status code: %1',$json['status'])
152
                                        "error" => $json['error'] ?? _L('Received error status code: %1', $json['status'])
146
                                );
153
                                );
147
                        }
154
                        }
148
 
155
 
149
                        $errors = array();
156
                        $errors = array();
150
                        list($count_imported_oids, $count_already_existing, $count_errors, $count_warnings) = $this->oidinfoImportXML('<oid-database>'.$json['xml'].'</oid-database>', $errors, $replaceExistingOIDs=false, $orphan_mode=self::ORPHAN_DISALLOW_ORPHANS);
157
                        list($count_imported_oids, $count_already_existing, $count_errors, $count_warnings) = $this->oidinfoImportXML('<oid-database>'.$json['xml'].'</oid-database>', $errors, $replaceExistingOIDs=false, $orphan_mode=self::ORPHAN_DISALLOW_ORPHANS);
Line 438... Line 445...
438
 
445
 
439
                                                                // End: Build oid-info.com create URL
446
                                                                // End: Build oid-info.com create URL
440
 
447
 
441
                                                                // Note: "Actions" is at the left, because it has a fixed width, so the user can continue clicking without the links moving if the OID length changes between lines
448
                                                                // Note: "Actions" is at the left, because it has a fixed width, so the user can continue clicking without the links moving if the OID length changes between lines
442
                                                                $out['text'] .= '<tr id="missing_oid_'.str_replace('.','_',$local_oid).'">'.
449
                                                                $out['text'] .= '<tr id="missing_oid_'.str_replace('.','_',$local_oid).'">'.
443
                                                                '<td><a '.OIDplus::gui()->link(isset($lookup_nonoid[$local_oid]) ? $lookup_nonoid[$local_oid] : 'oid:'.$local_oid, true).'>'._L('View local OID').'</a></td>'.
450
                                                                '<td><a '.OIDplus::gui()->link($lookup_nonoid[$local_oid] ?? 'oid:' . $local_oid, true).'>'._L('View local OID').'</a></td>'.
444
                                                                '<td><a href="javascript:OIDplusPageAdminOIDInfoExport.removeMissingOid(\''.$local_oid.'\');">'._L('Ignore for now').'</a></td>'.
451
                                                                '<td><a href="javascript:OIDplusPageAdminOIDInfoExport.removeMissingOid(\''.$local_oid.'\');">'._L('Ignore for now').'</a></td>'.
445
                                                                '<td><a target="_blank" href="'.$url.'">'._L('Add to oid-info.com manually').'</a></td>'.
452
                                                                '<td><a target="_blank" href="'.$url.'">'._L('Add to oid-info.com manually').'</a></td>'.
446
                                                                '<td>'.$local_oid.'</td>'.
453
                                                                '<td>'.$local_oid.'</td>'.
447
                                                                '</tr>';
454
                                                                '</tr>';
448
                                                        }
455
                                                        }
Line 690... Line 697...
690
        public function tree_search(string $request) {
697
        public function tree_search(string $request) {
691
                return false;
698
                return false;
692
        }
699
        }
693
 
700
 
694
        /**
701
        /**
695
         * @param $only_non_existing
702
         * @param bool $only_non_existing
696
         * @return string[]
703
         * @return string[]
697
         * @throws OIDplusException
704
         * @throws OIDplusException
698
         * @throws \OIDInfoException
705
         * @throws \OIDInfoException
699
         */
706
         */
700
        public static function outputXML($only_non_existing) {
707
        public static function outputXML(bool $only_non_existing): array {
701
                $out_type = null;
708
                $out_type = null;
702
                $out_content = '';
709
                $out_content = '';
703
 
710
 
704
                // This file contains class \OIDInfoAPI.
711
                // This file contains class \OIDInfoAPI.
705
                // We cannot include this in init(), because the init
712
                // We cannot include this in init(), because the init
Line 720... Line 727...
720
                $email = OIDplus::config()->getValue('admin_email');
727
                $email = OIDplus::config()->getValue('admin_email');
721
                if (empty($email)) $email = 'unknown@example.com';
728
                if (empty($email)) $email = 'unknown@example.com';
722
 
729
 
723
                $sys_title = OIDplus::config()->getValue('system_title');
730
                $sys_title = OIDplus::config()->getValue('system_title');
724
                $name1 = !empty($sys_title) ? $sys_title : 'OIDplus 2.0';
731
                $name1 = !empty($sys_title) ? $sys_title : 'OIDplus 2.0';
725
                $name2 = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'Export interface';
732
                $name2 = $_SERVER['SERVER_NAME'] ?? 'Export interface';
726
                $out_content .= $oa->xmlAddHeader($name1, $name2, $email); // do not translate
733
                $out_content .= $oa->xmlAddHeader($name1, $name2, $email); // do not translate
727
 
734
 
728
                $params['allow_html'] = true;
735
                $params['allow_html'] = true;
729
                $params['allow_illegal_email'] = true; // It should be enabled, because the creator could have used some kind of human-readable anti-spam technique
736
                $params['allow_illegal_email'] = true; // It should be enabled, because the creator could have used some kind of human-readable anti-spam technique
730
                $params['soft_correct_behavior'] = \OIDInfoAPI::SOFT_CORRECT_BEHAVIOR_NONE;
737
                $params['soft_correct_behavior'] = \OIDInfoAPI::SOFT_CORRECT_BEHAVIOR_NONE;
Line 906... Line 913...
906
                if ($str == '0000-00-00') $str = '';
913
                if ($str == '0000-00-00') $str = '';
907
                return $str;
914
                return $str;
908
        }
915
        }
909
 
916
 
910
        /**
917
        /**
911
         * @param $str
918
         * @param string $str
912
         * @return array|string|string[]|null
919
         * @return string
913
         * @throws OIDplusException
920
         * @throws OIDplusException
914
         */
921
         */
915
        private static function repair_relative_links($str) {
922
        private static function repair_relative_links(string $str): string {
916
                $str = preg_replace_callback('@(href\s*=\s*([\'"]))(.+)(\\2)@ismU', function($treffer) {
923
                return preg_replace_callback('@(href\s*=\s*([\'"]))(.+)(\\2)@ismU', function($treffer) {
917
                        $url = $treffer[3];
924
                        $url = $treffer[3];
918
                        if ((stripos($url,'http:') !== 0) && (stripos($url,'https:') !== 0) && (stripos($url,'ftp:') !== 0)) {
925
                        if ((stripos($url,'http:') !== 0) && (stripos($url,'https:') !== 0) && (stripos($url,'ftp:') !== 0)) {
919
                                if (stripos($url,'www.') === 0) {
926
                                if (stripos($url,'www.') === 0) {
920
                                        $url .= 'http://' . $url;
927
                                        $url .= 'http://' . $url;
921
                                } else {
928
                                } else {
922
                                        $url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL) . $url; // TODO: Canonical or not?
929
                                        $url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL) . $url; // TODO: Canonical or not?
923
                                }
930
                                }
924
                        }
931
                        }
925
                        return $treffer[1].$url.$treffer[4];
932
                        return $treffer[1].$url.$treffer[4];
926
                }, $str);
933
                }, $str);
927
                return $str;
-
 
928
        }
934
        }
929
 
935
 
930
        /**
936
        /**
931
         * @param string $address
937
         * @param string $address
932
         * @return string[]
938
         * @return string[]
Line 942... Line 948...
942
                        return array($rest."\n".$last_line, '');
948
                        return array($rest."\n".$last_line, '');
943
                }
949
                }
944
        }
950
        }
945
 
951
 
946
        /**
952
        /**
947
         * @param $name
953
         * @param string $name
948
         * @return array
954
         * @return array
949
         */
955
         */
950
        private static function split_name($name) {
956
        private static function split_name(string $name): array {
951
                // uses regex that accepts any word character or hyphen in last name
957
                // uses regex that accepts any word character or hyphen in last name
952
                // https://stackoverflow.com/questions/13637145/split-text-string-into-first-and-last-name-in-php
958
                // https://stackoverflow.com/questions/13637145/split-text-string-into-first-and-last-name-in-php
953
                $name = trim($name);
959
                $name = trim($name);
954
                $last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name);
960
                $last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name);
955
                $first_name = trim( preg_replace('#'.preg_quote($last_name,'#').'#', '', $name ) );
961
                $first_name = trim( preg_replace('#'.preg_quote($last_name,'#').'#', '', $name ) );
Line 959... Line 965...
959
        /*protected*/ const ORPHAN_IGNORE = 0;
965
        /*protected*/ const ORPHAN_IGNORE = 0;
960
        /*protected*/ const ORPHAN_AUTO_DEORPHAN = 1;
966
        /*protected*/ const ORPHAN_AUTO_DEORPHAN = 1;
961
        /*protected*/ const ORPHAN_DISALLOW_ORPHANS = 2;
967
        /*protected*/ const ORPHAN_DISALLOW_ORPHANS = 2;
962
 
968
 
963
        /**
969
        /**
964
         * @param $xml_contents
970
         * @param string $xml_contents
965
         * @param $errors
971
         * @param array $errors
966
         * @param $replaceExistingOIDs
972
         * @param bool $replaceExistingOIDs
967
         * @param $orphan_mode
973
         * @param int $orphan_mode
968
         * @return int[]
974
         * @return int[]
969
         * @throws OIDplusException
975
         * @throws OIDplusException
970
         */
976
         */
971
        protected function oidinfoImportXML($xml_contents, &$errors, $replaceExistingOIDs=false, $orphan_mode=self::ORPHAN_AUTO_DEORPHAN): array {
977
        protected function oidinfoImportXML(string $xml_contents, array &$errors, bool $replaceExistingOIDs=false, int $orphan_mode=self::ORPHAN_AUTO_DEORPHAN): array {
972
                // TODO: Implement RA import (let the user decide)
978
                // TODO: Implement RA import (let the user decide)
973
                // TODO: Let the user decide about $replaceExistingOIDs
979
                // TODO: Let the user decide about $replaceExistingOIDs
974
                // TODO: Let the user decide if "created=now" should be set (this is good when the XML files is created by the user itself to do bulk-inserts)
980
                // TODO: Let the user decide if "created=now" should be set (this is good when the XML files is created by the user itself to do bulk-inserts)
975
 
981
 
976
                $xml_contents = str_replace('<description>', '<description><![CDATA[', $xml_contents);
982
                $xml_contents = str_replace('<description>', '<description><![CDATA[', $xml_contents);
Line 1150... Line 1156...
1150
                return false;
1156
                return false;
1151
        }
1157
        }
1152
 
1158
 
1153
        /**
1159
        /**
1154
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.8
1160
         * Implements interface 1.3.6.1.4.1.37476.2.5.2.3.8
1155
         * @param $user
1161
         * @param string|null $user
1156
         * @return array
1162
         * @return array
1157
         * @throws OIDplusException
1163
         * @throws OIDplusException
1158
         */
1164
         */
1159
        public function getNotifications($user=null): array {
1165
        public function getNotifications(string $user=null): array {
1160
                $notifications = array();
1166
                $notifications = array();
1161
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
1167
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
1162
                        if (!function_exists('curl_init')) {
1168
                        if (!function_exists('curl_init')) {
1163
                                $title = _L('OID-Info.com import/export');
1169
                                $title = _L('OID-Info.com import/export');
1164
                                $notifications[] = array('ERR', _L('OIDplus plugin "%1" is enabled, but the required PHP extension "%2" is not installed.', '<a '.OIDplus::gui()->link('oidplus:datatransfer').'>'.htmlentities($title).'</a>', 'php_curl'));
1170
                                $notifications[] = array('ERR', _L('OIDplus plugin "%1" is enabled, but the required PHP extension "%2" is not installed.', '<a '.OIDplus::gui()->link('oidplus:datatransfer').'>'.htmlentities($title).'</a>', 'php_curl'));