Subversion Repositories oidplus

Rev

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

Rev 1086 Rev 1116
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 OIDplusCaptchaPluginHCaptcha extends OIDplusCaptchaPlugin {
26
class OIDplusCaptchaPluginHCaptcha extends OIDplusCaptchaPlugin {
27
 
27
 
-
 
28
        /**
-
 
29
         * @return string
-
 
30
         */
28
        public static function id(): string {
31
        public static function id(): string {
29
                return 'hCaptcha';
32
                return 'hCaptcha';
30
        }
33
        }
31
 
34
 
-
 
35
        /**
-
 
36
         * @return bool
-
 
37
         */
32
        public function isVisible(): bool {
38
        public function isVisible(): bool {
33
                return true;
39
                return true;
34
        }
40
        }
35
 
41
 
-
 
42
        /**
-
 
43
         * @param string|null $header_text
-
 
44
         * @param string|null $footer_text
-
 
45
         * @return string
-
 
46
         * @throws OIDplusException
-
 
47
         */
36
        public function captchaGenerate($header_text=null, $footer_text=null) {
48
        public function captchaGenerate(string $header_text=null, string $footer_text=null): string {
37
                return ($header_text ? '<p>'.$header_text.'</p>' : '') .
49
                return ($header_text ? '<p>'.$header_text.'</p>' : '') .
38
                       '<noscript>'.
50
                       '<noscript>'.
39
                       '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>'.
51
                       '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>'.
40
                       '</noscript>'.
52
                       '</noscript>'.
41
                       '<div id="h-captcha"></div>'.
53
                       '<div id="h-captcha"></div>'.
Line 44... Line 56...
44
                       'OIDplusCaptchaPluginHCaptcha.captchaShow('.js_escape(OIDplus::baseConfig()->getValue('HCAPTCHA_SITEKEY', '')).')'.
56
                       'OIDplusCaptchaPluginHCaptcha.captchaShow('.js_escape(OIDplus::baseConfig()->getValue('HCAPTCHA_SITEKEY', '')).')'.
45
                       '</script>'.
57
                       '</script>'.
46
                       ($footer_text ? '<p>'.$footer_text.'</p>' : '');
58
                       ($footer_text ? '<p>'.$footer_text.'</p>' : '');
47
        }
59
        }
48
 
60
 
-
 
61
        /**
-
 
62
         * @param string[] $params
-
 
63
         * @param string|null $fieldname
-
 
64
         * @return void
-
 
65
         * @throws OIDplusException
-
 
66
         */
49
        public function captchaVerify($params, $fieldname=null) {
67
        public function captchaVerify(array $params, string $fieldname=null) {
50
                $sitekey=OIDplus::baseConfig()->getValue('HCAPTCHA_SITEKEY', '');
68
                $sitekey=OIDplus::baseConfig()->getValue('HCAPTCHA_SITEKEY', '');
51
                $secret=OIDplus::baseConfig()->getValue('HCAPTCHA_SECRET', '');
69
                $secret=OIDplus::baseConfig()->getValue('HCAPTCHA_SECRET', '');
52
 
70
 
53
                if (!function_exists('curl_init')) {
71
                if (!function_exists('curl_init')) {
54
                        throw new OIDplusException(_L('hCaptcha plugin needs the PHP extension php_curl'));
72
                        throw new OIDplusException(_L('hCaptcha plugin needs the PHP extension php_curl'));
Line 77... Line 95...
77
                if (!$captcha_success || ($captcha_success->success==false)) {
95
                if (!$captcha_success || ($captcha_success->success==false)) {
78
                        throw new OIDplusException(_L('CAPTCHA not successfully verified').' ('.implode(", ",$captcha_success->{'error-codes'}).')');
96
                        throw new OIDplusException(_L('CAPTCHA not successfully verified').' ('.implode(", ",$captcha_success->{'error-codes'}).')');
79
                }
97
                }
80
        }
98
        }
81
 
99
 
-
 
100
        /**
-
 
101
         * @return string
-
 
102
         */
82
        public static function setupHTML(): string {
103
        public static function setupHTML(): string {
83
                $curl_status = function_exists('curl_init') ? 1 : 0;
104
                $curl_status = function_exists('curl_init') ? 1 : 0;
84
                return '<div id="CAPTCHAPLUGIN_PARAMS_HCAPTCHA">'.
105
                return '<div id="CAPTCHAPLUGIN_PARAMS_HCAPTCHA">'.
85
                       '<p>(<a href="https://www.hcaptcha.com/" target="_blank">'._L('more information and obtain key').'</a>)</p>'.
106
                       '<p>(<a href="https://www.hcaptcha.com/" target="_blank">'._L('more information and obtain key').'</a>)</p>'.
86
                       '<p>'._L('hCaptcha Site key').'<br><input id="hcaptcha_sitekey" type="text" onkeypress="rebuild()" onkeyup="rebuild()"> <span id="hcaptcha_sitekey_warn"></span></p>'.
107
                       '<p>'._L('hCaptcha Site key').'<br><input id="hcaptcha_sitekey" type="text" onkeypress="rebuild()" onkeyup="rebuild()"> <span id="hcaptcha_sitekey_warn"></span></p>'.
Line 88... Line 109...
88
                       '<input id="hcaptcha_curl_status" value="'.$curl_status.'" type="hidden">'.
109
                       '<input id="hcaptcha_curl_status" value="'.$curl_status.'" type="hidden">'.
89
                       (!$curl_status ? '<p><font color="red">'._L('hCaptcha plugin needs the PHP extension php_curl').'</font></p>' : '').
110
                       (!$curl_status ? '<p><font color="red">'._L('hCaptcha plugin needs the PHP extension php_curl').'</font></p>' : '').
90
                       '</div>';
111
                       '</div>';
91
        }
112
        }
92
 
113
 
-
 
114
        /**
-
 
115
         * @param array $http_headers
-
 
116
         * @return void
-
 
117
         */
93
        function httpHeaderCheck(&$http_headers) {
118
        function httpHeaderCheck(array &$http_headers) {
94
 
119
 
95
                // If you use CSP headers, please add the following to your configuration:
120
                // If you use CSP headers, please add the following to your configuration:
96
                // script-src should include https://hcaptcha.com, https://*.hcaptcha.com
121
                // script-src should include https://hcaptcha.com, https://*.hcaptcha.com
97
                $http_headers["Content-Security-Policy"]["script-src"][] = "https://hcaptcha.com";
122
                $http_headers["Content-Security-Policy"]["script-src"][] = "https://hcaptcha.com";
98
                $http_headers["Content-Security-Policy"]["script-src"][] = "https://*.hcaptcha.com";
123
                $http_headers["Content-Security-Policy"]["script-src"][] = "https://*.hcaptcha.com";