Subversion Repositories oidplus

Rev

Rev 1131 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
939 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
1086 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
939 daniel-mar 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
 
1050 daniel-mar 20
namespace Frdlweb\OIDplus;
939 daniel-mar 21
 
1131 daniel-mar 22
use ViaThinkSoft\OIDplus\INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2;
1050 daniel-mar 23
use ViaThinkSoft\OIDplus\OIDplus;
1130 daniel-mar 24
use ViaThinkSoft\OIDplus\OIDplusException;
1050 daniel-mar 25
use ViaThinkSoft\OIDplus\OIDplusPagePluginPublic;
26
 
1086 daniel-mar 27
// phpcs:disable PSR1.Files.SideEffects
28
\defined('INSIDE_OIDPLUS') or die;
29
// phpcs:enable PSR1.Files.SideEffects
30
 
1131 daniel-mar 31
class OIDplusPagePublicRdap extends OIDplusPagePluginPublic
32
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2 /* modifyContent */
33
{
1050 daniel-mar 34
 
1116 daniel-mar 35
        /**
1131 daniel-mar 36
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2
1116 daniel-mar 37
         * @param string $id
38
         * @param string $title
39
         * @param string $icon
40
         * @param string $text
41
         * @return void
42
         * @throws \ViaThinkSoft\OIDplus\OIDplusException
43
         */
44
        public function modifyContent(string $id, string &$title, string &$icon, string &$text) {
1279 daniel-mar 45
            $payload = '<br /> <a href="'.OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE)
1050 daniel-mar 46
                        .'rdap/rdap.php?query='.urlencode($id).'" class="gray_footer_font" target="_blank">'._L('RDAP').'</a>';
1279 daniel-mar 47
 
48
                $text = str_replace('<!-- MARKER 6 -->', '<!-- MARKER 6 -->'.$payload, $text);
939 daniel-mar 49
        }
950 daniel-mar 50
 
1116 daniel-mar 51
        /**
52
         * @param string $request
53
         * @return bool
1130 daniel-mar 54
         * @throws OIDplusException
1116 daniel-mar 55
         */
56
        public function handle404(string $request): bool {
950 daniel-mar 57
                $namespaces = array();
58
                foreach (OIDplus::getEnabledObjectTypes() as $ot) {
59
                        $namespaces[] = $ot::ns();
60
                }
61
                foreach ($namespaces as $ns) {
62
                        // Note: This only works if OIDplus is located at the domain root (because $request is relative to the domain)
63
                        if (!preg_match('@^/'.preg_quote($ns,'@').'/(.+)$@', $request, $m)) return false;
64
                        $oid = $m[1];
65
                        $query = "$ns:$oid";
66
                        $x = new OIDplusRDAP();
67
                        list($out_content, $out_type) = $x->rdapQuery($query);
68
                        if ($out_type) header('Content-Type:'.$out_type);
69
                        echo $out_content;
1116 daniel-mar 70
                        die();
71
                        // return true;
950 daniel-mar 72
                }
1116 daniel-mar 73
                return false;
950 daniel-mar 74
        }
75
 
939 daniel-mar 76
}