Rev 1116 | Rev 1131 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1116 | 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 OIDplusOIDIP { |
26 | class OIDplusOIDIP { |
27 | 27 | ||
- | 28 | /** |
|
- | 29 | * @var string |
|
- | 30 | */ |
|
28 | protected $XML_SCHEMA_URN; |
31 | protected $XML_SCHEMA_URN; |
- | 32 | ||
- | 33 | /** |
|
- | 34 | * @var string |
|
- | 35 | */ |
|
29 | protected $XML_SCHEMA_URL; |
36 | protected $XML_SCHEMA_URL; |
- | 37 | ||
- | 38 | /** |
|
- | 39 | * @var string |
|
- | 40 | */ |
|
30 | protected $JSON_SCHEMA_URN; |
41 | protected $JSON_SCHEMA_URN; |
- | 42 | ||
- | 43 | /** |
|
- | 44 | * @var string |
|
- | 45 | */ |
|
31 | protected $JSON_SCHEMA_URL; |
46 | protected $JSON_SCHEMA_URL; |
32 | 47 | ||
33 | /** |
48 | /** |
34 | * @throws OIDplusException |
49 | * @throws OIDplusException |
35 | */ |
50 | */ |
Line 42... | Line 57... | ||
42 | $this->JSON_SCHEMA_URN = 'urn:ietf:id:draft-viathinksoft-oidip-05'; |
57 | $this->JSON_SCHEMA_URN = 'urn:ietf:id:draft-viathinksoft-oidip-05'; |
43 | $this->JSON_SCHEMA_URL = OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE).'whois/draft-viathinksoft-oidip-05.json'; |
58 | $this->JSON_SCHEMA_URL = OIDplus::webpath(__DIR__,OIDplus::PATH_ABSOLUTE).'whois/draft-viathinksoft-oidip-05.json'; |
44 | } |
59 | } |
45 | 60 | ||
46 | /** |
61 | /** |
47 | * @param $query |
62 | * @param string $query |
48 | * @return array|void |
63 | * @return array |
49 | * @throws OIDplusException |
64 | * @throws OIDplusException |
50 | */ |
65 | */ |
51 | public function oidipQuery($query) { |
66 | public function oidipQuery(string $query): array { |
52 | 67 | ||
53 | $out_type = null; |
68 | $out_type = null; |
54 | $out_content = ''; |
69 | $out_content = ''; |
55 | 70 | ||
56 | // Split input into query and arguments |
71 | // Split input into query and arguments |
Line 70... | Line 85... | ||
70 | $arguments[$tmp[0]] = $tmp[1]; |
85 | $arguments[$tmp[0]] = $tmp[1]; |
71 | } |
86 | } |
72 | 87 | ||
73 | $query = str_replace('oid:.', 'oid:', $query); // allow leading dot |
88 | $query = str_replace('oid:.', 'oid:', $query); // allow leading dot |
74 | 89 | ||
75 | if (isset($arguments['format'])) { |
- | |
76 | $format = $arguments['format']; |
90 | $format = $arguments['format'] ?? 'text'; |
77 | } else { |
- | |
78 | $format = 'text'; // default |
- | |
79 | } |
- | |
80 | 91 | ||
81 | if (isset($arguments['auth'])) { |
92 | if (isset($arguments['auth'])) { |
82 | $authTokens = explode(',', $arguments['auth']); |
93 | $authTokens = explode(',', $arguments['auth']); |
83 | } else { |
94 | } else { |
84 | $authTokens = array(); |
95 | $authTokens = array(); |
Line 636... | Line 647... | ||
636 | 647 | ||
637 | return array($out_content, $out_type); |
648 | return array($out_content, $out_type); |
638 | } |
649 | } |
639 | 650 | ||
640 | /** |
651 | /** |
641 | * @param $id |
652 | * @param string $id |
642 | * @return string |
653 | * @return string |
643 | * @throws OIDplusException |
654 | * @throws OIDplusException |
644 | */ |
655 | */ |
645 | protected function show_asn1_appendix($id) { |
656 | protected function show_asn1_appendix(string $id): string { |
646 | if (substr($id,0,4) === 'oid:') { |
657 | if (substr($id,0,4) === 'oid:') { |
647 | $appendix_asn1ids = array(); |
658 | $appendix_asn1ids = array(); |
648 | $res_asn = OIDplus::db()->query("select * from ###asn1id where oid = ?", array($id)); |
659 | $res_asn = OIDplus::db()->query("select * from ###asn1id where oid = ?", array($id)); |
649 | while ($row_asn = $res_asn->fetch_object()) { |
660 | while ($row_asn = $res_asn->fetch_object()) { |
650 | $appendix_asn1ids[] = $row_asn->name; |
661 | $appendix_asn1ids[] = $row_asn->name; |
Line 657... | Line 668... | ||
657 | } |
668 | } |
658 | return $appendix; |
669 | return $appendix; |
659 | } |
670 | } |
660 | 671 | ||
661 | /** |
672 | /** |
662 | * @param $id |
673 | * @param string $id |
663 | * @return bool |
674 | * @return bool |
664 | */ |
675 | */ |
665 | protected function is_root($id) { |
676 | protected function is_root(string $id): bool { |
666 | return empty(explode(':',$id,2)[1]); |
677 | return empty(explode(':',$id,2)[1]); |
667 | } |
678 | } |
668 | 679 | ||
669 | /** |
680 | /** |
670 | * @param $content |
681 | * @param string $id |
671 | * @param $authTokens |
682 | * @param array $authTokens |
672 | * @return bool |
683 | * @return bool |
- | 684 | * @throws OIDplusException |
|
673 | */ |
685 | */ |
674 | protected function authTokenAccepted($content, $authTokens) { |
686 | protected function authTokenAccepted(string $id, array $authTokens): bool { |
675 | foreach ($authTokens as $token) { |
- | |
676 | if (OIDplusPagePublicWhois::genWhoisAuthToken($content) == $token) return true; |
687 | return in_array(OIDplusPagePublicWhois::genWhoisAuthToken($id), $authTokens); |
677 | } |
- | |
678 | return false; |
- | |
679 | } |
688 | } |
680 | 689 | ||
681 | /** |
690 | /** |
682 | * @param $obj |
691 | * @param OIDplusObject $obj |
683 | * @param $authTokens |
692 | * @param array $authTokens |
684 | * @return bool |
693 | * @return bool |
685 | * @throws OIDplusException |
694 | * @throws OIDplusException |
686 | */ |
695 | */ |
687 | protected function allowObjectView($obj, $authTokens) { |
696 | protected function allowObjectView(OIDplusObject $obj, array $authTokens): bool { |
688 | // Master auth token (TODO: Have an object-master-token and a ra-master-token?) |
697 | // Master auth token (TODO: Have an object-master-token and a ra-master-token?) |
689 | $authToken = trim(OIDplus::config()->getValue('whois_auth_token')); |
698 | $authToken = trim(OIDplus::config()->getValue('whois_auth_token')); |
690 | if (empty($authToken)) $authToken = false; |
699 | if (empty($authToken)) $authToken = false; |
691 | if ($authToken && in_array($authToken, $authTokens)) return true; |
700 | if ($authToken && in_array($authToken, $authTokens)) return true; |
692 | 701 | ||
Line 708... | Line 717... | ||
708 | // Allow |
717 | // Allow |
709 | return true; |
718 | return true; |
710 | } |
719 | } |
711 | 720 | ||
712 | /** |
721 | /** |
713 | * @param $row_ra |
722 | * @param \stdClass $row_ra |
714 | * @param $authTokens |
723 | * @param array $authTokens |
715 | * @return bool |
724 | * @return bool |
716 | * @throws OIDplusException |
725 | * @throws OIDplusException |
717 | */ |
726 | */ |
718 | protected function allowRAView($row_ra, $authTokens) { |
727 | protected function allowRAView(\stdClass $row_ra, array $authTokens): bool { |
719 | // Master auth token (TODO: Have an object-master-token and a ra-master-token?) |
728 | // Master auth token (TODO: Have an object-master-token and a ra-master-token?) |
720 | $authToken = trim(OIDplus::config()->getValue('whois_auth_token')); |
729 | $authToken = trim(OIDplus::config()->getValue('whois_auth_token')); |
721 | if (empty($authToken)) $authToken = false; |
730 | if (empty($authToken)) $authToken = false; |
722 | if ($authToken && in_array($authToken, $authTokens)) return true; |
731 | if ($authToken && in_array($authToken, $authTokens)) return true; |
723 | 732 | ||
Line 727... | Line 736... | ||
727 | // Allow |
736 | // Allow |
728 | return true; |
737 | return true; |
729 | } |
738 | } |
730 | 739 | ||
731 | /** |
740 | /** |
732 | * @param $name |
741 | * @param string $name |
733 | * @param $value |
742 | * @param mixed $value |
734 | * @return array |
743 | * @return array |
735 | */ |
744 | */ |
736 | protected function _oidip_attr($name, $value) { |
745 | protected function _oidip_attr(string $name, $value): array { |
737 | return array( |
746 | return array( |
738 | 'xmlns' => '', |
747 | 'xmlns' => '', |
739 | 'xmlschema' => '', |
748 | 'xmlschema' => '', |
740 | 'xmlschemauri' => '', |
749 | 'xmlschemauri' => '', |
741 | 'name' => $name, |
750 | 'name' => $name, |
742 | 'value' => $value |
751 | 'value' => $value |
743 | ); |
752 | ); |
744 | } |
753 | } |
745 | 754 | ||
746 | /** |
755 | /** |
747 | * @param $out |
756 | * @param array $out |
748 | * @return void |
757 | * @return void |
749 | */ |
758 | */ |
750 | protected function _oidip_newout_format(&$out) { |
759 | protected function _oidip_newout_format(array &$out) { |
751 | foreach ($out as &$line) { |
760 | foreach ($out as &$line) { |
752 | if (is_string($line)) { |
761 | if (is_string($line)) { |
753 | $ary = explode(':', $line, 2); |
762 | $ary = explode(':', $line, 2); |
754 | $key = trim($ary[0]); |
763 | $key = trim($ary[0]); |
755 | $value = isset($ary[1]) ? trim($ary[1]) : ''; |
764 | $value = isset($ary[1]) ? trim($ary[1]) : ''; |