Subversion Repositories oidplus

Rev

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

Rev 1086 Rev 1116
Line 35... Line 35...
35
        protected $rdapBaseUri;
35
        protected $rdapBaseUri;
36
        protected $useCache;
36
        protected $useCache;
37
        protected $rdapCacheDir;
37
        protected $rdapCacheDir;
38
        protected $rdapCacheExpires;
38
        protected $rdapCacheExpires;
39
 
39
 
-
 
40
        /**
-
 
41
         * @throws \ViaThinkSoft\OIDplus\OIDplusException
-
 
42
         */
40
        public function __construct() {
43
        public function __construct() {
41
                $this->rdapBaseUri = OIDplus::baseConfig()->getValue('RDAP_BASE_URI', OIDplus::webpath() );
44
                $this->rdapBaseUri = OIDplus::baseConfig()->getValue('RDAP_BASE_URI', OIDplus::webpath() );
42
                $this->useCache = OIDplus::baseConfig()->getValue('RDAP_CACHE_ENABLED', false );
45
                $this->useCache = OIDplus::baseConfig()->getValue('RDAP_CACHE_ENABLED', false );
43
                $this->rdapCacheDir = OIDplus::baseConfig()->getValue('RDAP_CACHE_DIRECTORY', OIDplus::localpath().'userdata/cache/' );
46
                $this->rdapCacheDir = OIDplus::baseConfig()->getValue('RDAP_CACHE_DIRECTORY', OIDplus::localpath().'userdata/cache/' );
44
                $this->rdapCacheExpires = OIDplus::baseConfig()->getValue('RDAP_CACHE_EXPIRES', 60 * 3 );
47
                $this->rdapCacheExpires = OIDplus::baseConfig()->getValue('RDAP_CACHE_EXPIRES', 60 * 3 );
45
        }
48
        }
46
 
49
 
-
 
50
        /**
-
 
51
         * @param $query
-
 
52
         * @return array
-
 
53
         * @throws \ViaThinkSoft\OIDplus\OIDplusException
-
 
54
         */
47
        public function rdapQuery($query) {
55
        public function rdapQuery($query) {
48
                $query = str_replace('oid:.', 'oid:', $query);
56
                $query = str_replace('oid:.', 'oid:', $query);
49
                $n = explode(':', $query);
57
                $n = explode(':', $query);
50
                if(2>count($n)){
58
                if(2>count($n)){
51
                 array_unshift($n, 'oid');
59
                 array_unshift($n, 'oid');
Line 112... Line 120...
112
 
120
 
113
                $out['name'] = $obj->nodeId(true);
121
                $out['name'] = $obj->nodeId(true);
114
                $out['objectClassName'] = $ns;
122
                $out['objectClassName'] = $ns;
115
                $out['handle'] = $ns.':'.$n[1];
123
                $out['handle'] = $ns.':'.$n[1];
116
                $out['parentHandle'] =   (null !== $parentHandle && is_callable([$parentHandle, 'nodeId']) )
124
                $out['parentHandle'] =   (null !== $parentHandle && is_callable([$parentHandle, 'nodeId']) )
117
                                         ? $obj->one_up()->nodeId(true)
125
                                         ? $parentHandle->nodeId(true)
118
                                         : null;
126
                                         : null;
119
 
127
 
120
                $out['rdapConformance'] = [
128
                $out['rdapConformance'] = [
121
                        "rdap_level_0", //https://datatracker.ietf.org/doc/html/rfc9083
129
                        "rdap_level_0", //https://datatracker.ietf.org/doc/html/rfc9083
122
                ];
130
                ];
Line 233... Line 241...
233
                        $this->rdap_write_cache($out, $cacheFile);
241
                        $this->rdap_write_cache($out, $cacheFile);
234
                }
242
                }
235
                return $this->rdap_out($out);
243
                return $this->rdap_out($out);
236
        }
244
        }
237
 
245
 
-
 
246
        /**
-
 
247
         * @param $out
-
 
248
         * @param $cacheFile
-
 
249
         * @return void
-
 
250
         */
238
        protected function rdap_write_cache($out, $cacheFile){
251
        protected function rdap_write_cache($out, $cacheFile){
239
                if (!is_string($cacheFile)) return;
252
                if (!is_string($cacheFile)) return;
240
                @file_put_contents($cacheFile, serialize($out));
253
                @file_put_contents($cacheFile, serialize($out));
241
        }
254
        }
242
 
255
 
-
 
256
        /**
-
 
257
         * @param $cacheFile
-
 
258
         * @param $rdapCacheExpires
-
 
259
         * @return array|null
-
 
260
         */
243
        protected function rdap_read_cache($cacheFile, $rdapCacheExpires){
261
        protected function rdap_read_cache($cacheFile, $rdapCacheExpires){
244
                if (is_string($cacheFile) && file_exists($cacheFile) && filemtime($cacheFile) >= time() - $rdapCacheExpires) {
262
                if (is_string($cacheFile) && file_exists($cacheFile) && filemtime($cacheFile) >= time() - $rdapCacheExpires) {
245
                        $out = unserialize(file_get_contents($cacheFile));
263
                        $out = unserialize(file_get_contents($cacheFile));
246
                        if(is_array($out) || is_object($out)){
264
                        if(is_array($out) || is_object($out)){
247
                                return $this->rdap_out($out);
265
                                return $this->rdap_out($out);
248
                        }
266
                        }
249
                }
267
                }
250
                return null;
268
                return null;
251
        }
269
        }
252
 
270
 
-
 
271
        /**
-
 
272
         * @param $out
-
 
273
         * @return array
-
 
274
         */
253
        protected function rdap_out($out){
275
        protected function rdap_out($out){
254
                $out_content = json_encode($out);
276
                $out_content = json_encode($out);
255
                $out_type = 'application/rdap+json';
277
                $out_type = 'application/rdap+json';
256
                return array($out_content, $out_type);
278
                return array($out_content, $out_type);
257
        }
279
        }