Subversion Repositories oidplus

Rev

Rev 1267 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1267 Rev 1293
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * OIDplus 2.0
4
 * OIDplus 2.0
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
6
 *
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with 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
9
 * You may obtain a copy of the License at
10
 *
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
17
 * limitations under the License.
18
 */
18
 */
19
 
19
 
20
namespace ViaThinkSoft\OIDplus;
20
namespace ViaThinkSoft\OIDplus;
21
 
21
 
22
// phpcs:disable PSR1.Files.SideEffects
22
// phpcs:disable PSR1.Files.SideEffects
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 OIDplusPageAdminRegistration extends OIDplusPagePluginAdmin
26
class OIDplusPageAdminRegistration extends OIDplusPagePluginAdmin
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1, /* oobeRequested, oobeEntry */
27
        implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1, /* oobeRequested, oobeEntry */
28
                   INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8  /* getNotifications */
28
                   INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8  /* getNotifications */
29
{
29
{
30
 
30
 
31
        /**
31
        /**
32
         *
32
         *
33
         */
33
         */
34
        /*private*/ const QUERY_REGISTER_V1 =         '1.3.6.1.4.1.37476.2.5.2.1.1.1';
34
        /*private*/ const QUERY_REGISTER_V1 =         '1.3.6.1.4.1.37476.2.5.2.1.1.1';
35
 
35
 
36
        /**
36
        /**
37
         *
37
         *
38
         */
38
         */
39
        /*private*/ const QUERY_UNREGISTER_V1 =       '1.3.6.1.4.1.37476.2.5.2.1.2.1';
39
        /*private*/ const QUERY_UNREGISTER_V1 =       '1.3.6.1.4.1.37476.2.5.2.1.2.1';
40
 
40
 
41
        /**
41
        /**
42
         *
42
         *
43
         */
43
         */
44
        /*private*/ const QUERY_LISTALLSYSTEMIDS_V1 = '1.3.6.1.4.1.37476.2.5.2.1.3.1';
44
        /*private*/ const QUERY_LISTALLSYSTEMIDS_V1 = '1.3.6.1.4.1.37476.2.5.2.1.3.1';
45
 
45
 
46
        /**
46
        /**
47
         *
47
         *
48
         */
48
         */
49
        /*private*/ const QUERY_LIVESTATUS_V1 =       '1.3.6.1.4.1.37476.2.5.2.1.4.1';
49
        /*private*/ const QUERY_LIVESTATUS_V1 =       '1.3.6.1.4.1.37476.2.5.2.1.4.1';
50
 
50
 
51
        /**
51
        /**
52
         * @param string $actionID
52
         * @param string $actionID
53
         * @return bool
53
         * @return bool
54
         */
54
         */
55
        public function csrfUnlock(string $actionID): bool {
55
        public function csrfUnlock(string $actionID): bool {
56
                if ($actionID == 'verify_pubkey') return true;
56
                if ($actionID == 'verify_pubkey') return true;
57
                return parent::csrfUnlock($actionID);
57
                return parent::csrfUnlock($actionID);
58
        }
58
        }
59
 
59
 
60
        /**
60
        /**
61
         * @param string $actionID
61
         * This action is called by the ViaThinkSoft server in order to verify that the system is in the ownership of the correct private key
62
         * @param array $params
62
         * @param array $params
63
         * @return array
63
         * @return array
64
         * @throws OIDplusException
64
         * @throws OIDplusException
65
         */
65
         */
66
        public function action(string $actionID, array $params): array {
66
        private function action_VerifyPubKey(array $params): array {
67
                if ($actionID == 'verify_pubkey') {
-
 
68
                        // This action is called by the ViaThinkSoft server in order to verify that the system is in the ownership of the correct private key
-
 
69
 
-
 
70
                        _CheckParamExists($params, 'challenge');
67
                _CheckParamExists($params, 'challenge');
71
 
68
 
72
                        $payload = 'oidplus-verify-pubkey:'.sha3_512($params['challenge']);
69
                $payload = 'oidplus-verify-pubkey:'.sha3_512($params['challenge']);
73
 
70
 
74
                        $signature = '';
71
                $signature = '';
75
                        if (!OIDplus::getPkiStatus() || !@openssl_sign($payload, $signature, OIDplus::getSystemPrivateKey())) {
72
                if (!OIDplus::getPkiStatus() || !@openssl_sign($payload, $signature, OIDplus::getSystemPrivateKey())) {
76
                                throw new OIDplusException(_L('Signature failed'));
73
                        throw new OIDplusException(_L('Signature failed'));
77
                        }
74
                }
78
 
75
 
79
                        return array(
76
                return array(
80
                                "status" => 0,
77
                        "status" => 0,
81
                                "response" => base64_encode($signature)
78
                        "response" => base64_encode($signature)
82
                        );
79
                );
-
 
80
        }
-
 
81
 
-
 
82
        /**
-
 
83
         * @param string $actionID
-
 
84
         * @param array $params
-
 
85
         * @return array
-
 
86
         * @throws OIDplusException
-
 
87
         */
-
 
88
        public function action(string $actionID, array $params): array {
-
 
89
                if ($actionID == 'verify_pubkey') {
-
 
90
                        return $this->action_VerifyPubKey($params);
83
                } else {
91
                } else {
84
                        return parent::action($actionID, $params);
92
                        return parent::action($actionID, $params);
85
                }
93
                }
86
        }
94
        }
87
 
95
 
88
        /**
96
        /**
89
         * @param string $id
97
         * @param string $id
90
         * @param array $out
98
         * @param array $out
91
         * @param bool $handled
99
         * @param bool $handled
92
         * @return void
100
         * @return void
93
         * @throws OIDplusConfigInitializationException
101
         * @throws OIDplusConfigInitializationException
94
         * @throws OIDplusException
102
         * @throws OIDplusException
95
         */
103
         */
96
        public function gui(string $id, array &$out, bool &$handled) {
104
        public function gui(string $id, array &$out, bool &$handled) {
97
                if ($id === 'oidplus:srv_registration') {
105
                if ($id === 'oidplus:srv_registration') {
98
                        $handled = true;
106
                        $handled = true;
99
                        $out['title'] = _L('System registration settings');
107
                        $out['title'] = _L('System registration settings');
100
                        $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
108
                        $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
101
 
109
 
102
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
110
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
103
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
111
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
104
                        }
112
                        }
105
 
113
 
106
                        if (file_exists(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html')) {
114
                        if (file_exists(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html')) {
107
                                $info = file_get_contents(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html');
115
                                $info = file_get_contents(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html');
108
                        } else {
116
                        } else {
109
                                $info = file_get_contents(__DIR__ . '/info.html');
117
                                $info = file_get_contents(__DIR__ . '/info.html');
110
                        }
118
                        }
111
 
119
 
112
                        list($html, $js, $css) = extractHtmlContents($info);
120
                        list($html, $js, $css) = extractHtmlContents($info);
113
                        $info = '';
121
                        $info = '';
114
                        if (!empty($js))  $info .= "<script>\n$js\n</script>";
122
                        if (!empty($js))  $info .= "<script>\n$js\n</script>";
115
                        if (!empty($css)) $info .= "<style>\n$css\n</style>";
123
                        if (!empty($css)) $info .= "<style>\n$css\n</style>";
116
                        $info .= stripHtmlComments($html);
124
                        $info .= stripHtmlComments($html);
117
 
125
 
118
                        $out['text'] = $info;
126
                        $out['text'] = $info;
119
 
127
 
120
                        if (!OIDplus::getPkiStatus()) {
128
                        if (!OIDplus::getPkiStatus()) {
121
                                $out['text'] .= '<p><font color="red">'._L('Error: Your system could not generate a private/public key pair. (OpenSSL is probably missing on your system). Therefore, you cannot register/unregister your OIDplus instance.').'</font></p>';
129
                                $out['text'] .= '<p><font color="red">'._L('Error: Your system could not generate a private/public key pair. (OpenSSL is probably missing on your system). Therefore, you cannot register/unregister your OIDplus instance.').'</font></p>';
122
                        } else if (!url_post_contents_available(true, $reason)) {
130
                        } else if (!url_post_contents_available(true, $reason)) {
123
                                $out['text'] .= '<p><font color="red">';
131
                                $out['text'] .= '<p><font color="red">';
124
                                $out['text'] .= _L('OIDplus cannot connect to the Internet (%1). Therefore, you <b>cannot</b> register your OIDplus instance now.', $reason);
132
                                $out['text'] .= _L('OIDplus cannot connect to the Internet (%1). Therefore, you <b>cannot</b> register your OIDplus instance now.', $reason);
125
                                $out['text'] .= '</font></p>';
133
                                $out['text'] .= '</font></p>';
126
                        } else {
134
                        } else {
127
                                $out['text'] .= '<p><input type="button" onclick="openOidInPanel(\'oidplus:srvreg_status\');" value="'._L('Check status of the registration and collected data').'"></p>';
135
                                $out['text'] .= '<p><input type="button" onclick="openOidInPanel(\'oidplus:srvreg_status\');" value="'._L('Check status of the registration and collected data').'"></p>';
128
 
136
 
129
                                if (OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
137
                                if (OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
130
                                        $out['text'] .= '<p><font color="red"><b>'._L('Attention!').'</b> '._L('<code>REGISTRATION_HIDE_SYSTEM</code> is set in the local configuration file! Therefore, this system will not register itself, despite of the settings below.').'</font></p>';
138
                                        $out['text'] .= '<p><font color="red"><b>'._L('Attention!').'</b> '._L('<code>REGISTRATION_HIDE_SYSTEM</code> is set in the local configuration file! Therefore, this system will not register itself, despite of the settings below.').'</font></p>';
131
                                }
139
                                }
132
 
140
 
133
                                $out['text'] .= '<p>'._L('You can adjust your privacy level here').':</p><p><select name="reg_privacy" id="reg_privacy">';
141
                                $out['text'] .= '<p>'._L('You can adjust your privacy level here').':</p><p><select name="reg_privacy" id="reg_privacy">';
134
 
142
 
135
                                # ---
143
                                # ---
136
 
144
 
137
                                $out['text'] .= '<option value="0"';
145
                                $out['text'] .= '<option value="0"';
138
                                if (OIDplus::config()->getValue('reg_privacy') == 0) {
146
                                if (OIDplus::config()->getValue('reg_privacy') == 0) {
139
                                        $out['text'] .= ' selected';
147
                                        $out['text'] .= ' selected';
140
                                } else {
148
                                } else {
141
                                        $out['text'] .= '';
149
                                        $out['text'] .= '';
142
                                }
150
                                }
143
                                $out['text'] .= '>'._L('0 = Register to directory service and automatically publish RA/OID data at oid-info.com').'</option>';
151
                                $out['text'] .= '>'._L('0 = Register to directory service and automatically publish RA/OID data at oid-info.com').'</option>';
144
 
152
 
145
                                # ---
153
                                # ---
146
 
154
 
147
                                $out['text'] .= '<option value="1"';
155
                                $out['text'] .= '<option value="1"';
148
                                if (OIDplus::config()->getValue('reg_privacy') == 1) {
156
                                if (OIDplus::config()->getValue('reg_privacy') == 1) {
149
                                        $out['text'] .= ' selected';
157
                                        $out['text'] .= ' selected';
150
                                } else {
158
                                } else {
151
                                        $out['text'] .= '';
159
                                        $out['text'] .= '';
152
                                }
160
                                }
153
                                $out['text'] .= '>'._L('1 = Only register to directory service').'</option>';
161
                                $out['text'] .= '>'._L('1 = Only register to directory service').'</option>';
154
 
162
 
155
                                # ---
163
                                # ---
156
 
164
 
157
                                $out['text'] .= '<option value="2"';
165
                                $out['text'] .= '<option value="2"';
158
                                if (OIDplus::config()->getValue('reg_privacy') == 2) {
166
                                if (OIDplus::config()->getValue('reg_privacy') == 2) {
159
                                        $out['text'] .= ' selected';
167
                                        $out['text'] .= ' selected';
160
                                } else {
168
                                } else {
161
                                        $out['text'] .= '';
169
                                        $out['text'] .= '';
162
                                }
170
                                }
163
                                $out['text'] .= '>'._L('2 = Hide system').'</option>';
171
                                $out['text'] .= '>'._L('2 = Hide system').'</option>';
164
 
172
 
165
                                # ---
173
                                # ---
166
 
174
 
167
                                $out['text'] .= '</select> <input type="button" value="'._L('Change').'" onclick="OIDplusPageAdminRegistration.crudActionRegPrivacyUpdate()"></p>';
175
                                $out['text'] .= '</select> <input type="button" value="'._L('Change').'" onclick="OIDplusPageAdminRegistration.crudActionRegPrivacyUpdate()"></p>';
168
 
176
 
169
                                $out['text'] .= '<p>'._L('After clicking "change", your OIDplus system will contact the ViaThinkSoft server to adjust (add or remove information) your privacy setting. This may take a few minutes.').'</p>';
177
                                $out['text'] .= '<p>'._L('After clicking "change", your OIDplus system will contact the ViaThinkSoft server to adjust (add or remove information) your privacy setting. This may take a few minutes.').'</p>';
170
 
178
 
171
                                $out['text'] .= '<p>'._L('<i>Privacy information:</i> Please note that removing your system from the directory does not automatically delete information about OIDs which are already published at oid-info.com. To remove already submitted OIDs at oid-info.com, please contact the <a href="mailto:admin@oid-info.com">OID Repository Webmaster</a>.').'</p>';
179
                                $out['text'] .= '<p>'._L('<i>Privacy information:</i> Please note that removing your system from the directory does not automatically delete information about OIDs which are already published at oid-info.com. To remove already submitted OIDs at oid-info.com, please contact the <a href="mailto:admin@oid-info.com">OID Repository Webmaster</a>.').'</p>';
172
                        }
180
                        }
173
                }
181
                }
174
                if ($id === 'oidplus:srvreg_status') {
182
                if ($id === 'oidplus:srvreg_status') {
175
                        $handled = true;
183
                        $handled = true;
176
                        $out['title'] = _L('Registration live status');
184
                        $out['title'] = _L('Registration live status');
177
                        $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
185
                        $out['icon'] = file_exists(__DIR__.'/img/main_icon.png') ? OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png' : '';
178
 
186
 
179
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
187
                        if (!OIDplus::authUtils()->isAdminLoggedIn()) {
180
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
188
                                throw new OIDplusHtmlException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')), $out['title'], 401);
181
                        }
189
                        }
182
 
190
 
183
                        $query = self::QUERY_LIVESTATUS_V1;
191
                        $query = self::QUERY_LIVESTATUS_V1;
184
 
192
 
185
                        $payload = array(
193
                        $payload = array(
186
                                "query" => $query, // we must include $query to the playload, because we want to sign it
194
                                "query" => $query, // we must include $query to the playload, because we want to sign it
187
                                "lang" => OIDplus::getCurrentLang(),
195
                                "lang" => OIDplus::getCurrentLang(),
188
                                "system_id" => OIDplus::getSystemId(false)
196
                                "system_id" => OIDplus::getSystemId(false)
189
                        );
197
                        );
190
 
198
 
191
                        $signature = '';
199
                        $signature = '';
192
                        if (!OIDplus::getPkiStatus() || !@openssl_sign(json_encode($payload), $signature, OIDplus::getSystemPrivateKey())) {
200
                        if (!OIDplus::getPkiStatus() || !@openssl_sign(json_encode($payload), $signature, OIDplus::getSystemPrivateKey())) {
193
                                throw new OIDplusException(_L('Signature failed'));
201
                                throw new OIDplusException(_L('Signature failed'));
194
                        }
202
                        }
195
 
203
 
196
                        $data = array(
204
                        $data = array(
197
                                "payload" => $payload,
205
                                "payload" => $payload,
198
                                "signature" => base64_encode($signature)
206
                                "signature" => base64_encode($signature)
199
                        );
207
                        );
200
 
208
 
201
                        if (function_exists('gzdeflate')) {
209
                        if (function_exists('gzdeflate')) {
202
                                $compressed = "1";
210
                                $compressed = "1";
203
                                $data2 = gzdeflate(json_encode($data));
211
                                $data2 = gzdeflate(json_encode($data));
204
                        } else {
212
                        } else {
205
                                $compressed = "0";
213
                                $compressed = "0";
206
                                $data2 = json_encode($data);
214
                                $data2 = json_encode($data);
207
                        }
215
                        }
208
 
216
 
209
                        $res = url_post_contents(
217
                        $res = url_post_contents(
210
                                'https://oidplus.viathinksoft.com/reg2/query.php',
218
                                'https://oidplus.viathinksoft.com/reg2/query.php',
211
                                array(
219
                                array(
212
                                        "query"      => $query,
220
                                        "query"      => $query,
213
                                        "compressed" => $compressed,
221
                                        "compressed" => $compressed,
214
                                        "data"       => base64_encode($data2)
222
                                        "data"       => base64_encode($data2)
215
                                )
223
                                )
216
                        );
224
                        );
217
 
225
 
218
                        if ($res === false) {
226
                        if ($res === false) {
219
                                throw new OIDplusException(_L('Communication with %1 server failed', 'ViaThinkSoft'));
227
                                throw new OIDplusException(_L('Communication with %1 server failed', 'ViaThinkSoft'));
220
                        }
228
                        }
221
 
229
 
222
                        $json = @json_decode($res, true);
230
                        $json = @json_decode($res, true);
223
 
231
 
224
                        if (!$json) {
232
                        if (!$json) {
225
                                throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res), $out['title']);
233
                                throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res), $out['title']);
226
                        }
234
                        }
227
 
235
 
228
                        if (isset($json['error']) || ($json['status'] < 0)) {
236
                        if (isset($json['error']) || ($json['status'] < 0)) {
229
                                if (isset($json['error'])) {
237
                                if (isset($json['error'])) {
230
                                        throw new OIDplusException(_L('Received error status code: %1',$json['error']), $out['title']);
238
                                        throw new OIDplusException(_L('Received error status code: %1',$json['error']), $out['title']);
231
                                } else {
239
                                } else {
232
                                        throw new OIDplusException(_L('Received error status code: %1',$json['status']), $out['title']);
240
                                        throw new OIDplusException(_L('Received error status code: %1',$json['status']), $out['title']);
233
                                }
241
                                }
234
                        }
242
                        }
235
 
243
 
236
                        $out['text']  = '<p><a '.OIDplus::gui()->link('oidplus:srv_registration').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Go back to registration settings').'</a></p>' .
244
                        $out['text']  = '<p><a '.OIDplus::gui()->link('oidplus:srv_registration').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Go back to registration settings').'</a></p>' .
237
                                        $json['content'];
245
                                        $json['content'];
238
                }
246
                }
239
        }
247
        }
240
 
248
 
241
        /**
249
        /**
242
         * @return bool
250
         * @return bool
243
         * @throws OIDplusException
251
         * @throws OIDplusException
244
         */
252
         */
245
        protected function areWeRegistered(): bool {
253
        protected function areWeRegistered(): bool {
246
                // To check if we are registered. Check it "anonymously" (i.e. without revealing our system ID)
254
                // To check if we are registered. Check it "anonymously" (i.e. without revealing our system ID)
247
                $res = url_get_contents('https://oidplus.viathinksoft.com/reg2/query.php?query='.self::QUERY_LISTALLSYSTEMIDS_V1);
255
                $res = url_get_contents('https://oidplus.viathinksoft.com/reg2/query.php?query='.self::QUERY_LISTALLSYSTEMIDS_V1);
248
                if ($res === false) return false;
256
                if ($res === false) return false;
249
 
257
 
250
                $json = @json_decode($res, true);
258
                $json = @json_decode($res, true);
251
 
259
 
252
                if (!$json) {
260
                if (!$json) {
253
                        return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
261
                        return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
254
                }
262
                }
255
 
263
 
256
                if (isset($json['error']) || ($json['status'] < 0)) {
264
                if (isset($json['error']) || ($json['status'] < 0)) {
257
                        if (isset($json['error'])) {
265
                        if (isset($json['error'])) {
258
                                return false; // throw new OIDplusException(_L('Received error status code: %1',$json['error']));
266
                                return false; // throw new OIDplusException(_L('Received error status code: %1',$json['error']));
259
                        } else {
267
                        } else {
260
                                return false; // throw new OIDplusException(_L('Received error status code: %1',$json['status']));
268
                                return false; // throw new OIDplusException(_L('Received error status code: %1',$json['status']));
261
                        }
269
                        }
262
                }
270
                }
263
 
271
 
264
                $list = $json['list'];
272
                $list = $json['list'];
265
 
273
 
266
                return in_array(OIDplus::getSystemId(false), $list);
274
                return in_array(OIDplus::getSystemId(false), $list);
267
        }
275
        }
268
 
276
 
269
        /**
277
        /**
270
         * @param int|null $privacy_level
278
         * @param int|null $privacy_level
271
         * @return false|void
279
         * @return false|void
272
         * @throws OIDplusException|\OIDInfoException
280
         * @throws OIDplusException|\OIDInfoException
273
         */
281
         */
274
        public function sendRegistrationQuery(int $privacy_level=null) {
282
        public function sendRegistrationQuery(int $privacy_level=null) {
275
 
283
 
276
                if (is_null($privacy_level)) {
284
                if (is_null($privacy_level)) {
277
                        $privacy_level = OIDplus::config()->getValue('reg_privacy');
285
                        $privacy_level = OIDplus::config()->getValue('reg_privacy');
278
                }
286
                }
279
 
287
 
280
                $system_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL);
288
                $system_url = OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL);
281
 
289
 
282
                // It is very important that we set the ping time NOW, because ViaThinkSoft might contact us during the ping,
290
                // It is very important that we set the ping time NOW, because ViaThinkSoft might contact us during the ping,
283
                // and this would cause an endless loop!
291
                // and this would cause an endless loop!
284
                OIDplus::config()->setValue('reg_last_ping', time());
292
                OIDplus::config()->setValue('reg_last_ping', time());
285
 
293
 
286
                if (!OIDplus::getPkiStatus()) return false;
294
                if (!OIDplus::getPkiStatus()) return false;
287
 
295
 
288
                if (!url_post_contents_available(true)) return false;
296
                if (!url_post_contents_available(true)) return false;
289
 
297
 
290
                if ($privacy_level == 2) {
298
                if ($privacy_level == 2) {
291
                        // The user wants to unregister,  but we only unregister if we are registered
299
                        // The user wants to unregister,  but we only unregister if we are registered
292
                        if ($this->areWeRegistered()) {
300
                        if ($this->areWeRegistered()) {
293
                                $query = self::QUERY_UNREGISTER_V1;
301
                                $query = self::QUERY_UNREGISTER_V1;
294
 
302
 
295
                                $payload = array(
303
                                $payload = array(
296
                                        "query" => $query, // we must include $query to the payload, because we want to sign it
304
                                        "query" => $query, // we must include $query to the payload, because we want to sign it
297
                                        "system_id" => OIDplus::getSystemId(false)
305
                                        "system_id" => OIDplus::getSystemId(false)
298
                                );
306
                                );
299
 
307
 
300
                                $signature = '';
308
                                $signature = '';
301
                                if (!OIDplus::getPkiStatus() || !@openssl_sign(json_encode($payload), $signature, OIDplus::getSystemPrivateKey())) {
309
                                if (!OIDplus::getPkiStatus() || !@openssl_sign(json_encode($payload), $signature, OIDplus::getSystemPrivateKey())) {
302
                                        return false; // throw new OIDplusException(_L('Signature failed'));
310
                                        return false; // throw new OIDplusException(_L('Signature failed'));
303
                                }
311
                                }
304
 
312
 
305
                                $data = array(
313
                                $data = array(
306
                                        "payload" => $payload,
314
                                        "payload" => $payload,
307
                                        "signature" => base64_encode($signature)
315
                                        "signature" => base64_encode($signature)
308
                                );
316
                                );
309
 
317
 
310
                                if (function_exists('gzdeflate')) {
318
                                if (function_exists('gzdeflate')) {
311
                                        $compressed = "1";
319
                                        $compressed = "1";
312
                                        $data2 = gzdeflate(json_encode($data));
320
                                        $data2 = gzdeflate(json_encode($data));
313
                                } else {
321
                                } else {
314
                                        $compressed = "0";
322
                                        $compressed = "0";
315
                                        $data2 = json_encode($data);
323
                                        $data2 = json_encode($data);
316
                                }
324
                                }
317
 
325
 
318
                                $res = url_post_contents(
326
                                $res = url_post_contents(
319
                                        'https://oidplus.viathinksoft.com/reg2/query.php',
327
                                        'https://oidplus.viathinksoft.com/reg2/query.php',
320
                                        array(
328
                                        array(
321
                                                "query" => $query,
329
                                                "query" => $query,
322
                                                "compressed" => $compressed,
330
                                                "compressed" => $compressed,
323
                                                "data" => base64_encode($data2)
331
                                                "data" => base64_encode($data2)
324
                                        )
332
                                        )
325
                                );
333
                                );
326
 
334
 
327
                                if ($res === false) return false; // throw new OIDplusException(_L('Communication with %1 server failed', 'ViaThinkSoft'));
335
                                if ($res === false) return false; // throw new OIDplusException(_L('Communication with %1 server failed', 'ViaThinkSoft'));
328
 
336
 
329
                                $json = @json_decode($res, true);
337
                                $json = @json_decode($res, true);
330
 
338
 
331
                                if (!$json) {
339
                                if (!$json) {
332
                                        return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
340
                                        return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
333
                                }
341
                                }
334
 
342
 
335
                                if (isset($json['error']) || ($json['status'] < 0)) {
343
                                if (isset($json['error']) || ($json['status'] < 0)) {
336
                                        return false; // throw new OIDplusException(_L('Received error status code: %1',isset($json['error']) ? $json['error'] : $json['status']));
344
                                        return false; // throw new OIDplusException(_L('Received error status code: %1',isset($json['error']) ? $json['error'] : $json['status']));
337
                                }
345
                                }
338
                        }
346
                        }
339
                } else {
347
                } else {
340
                        if ($privacy_level == 0) {
348
                        if ($privacy_level == 0) {
341
                                $adminExportPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.400'); // OIDplusPageAdminOIDInfoExport
349
                                $adminExportPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.400'); // OIDplusPageAdminOIDInfoExport
342
                                if (!is_null($adminExportPlugin)) {
350
                                if (!is_null($adminExportPlugin)) {
343
                                        list($oidinfo_xml, $dummy_content_type) = OIDplusPageAdminOIDInfoExport::outputXML(false); // no online check, because the query should be short (since the query is done while a visitor waits for the response)
351
                                        list($oidinfo_xml, $dummy_content_type) = OIDplusPageAdminOIDInfoExport::outputXML(false); // no online check, because the query should be short (since the query is done while a visitor waits for the response)
344
                                } else {
352
                                } else {
345
                                        $oidinfo_xml = false;
353
                                        $oidinfo_xml = false;
346
                                }
354
                                }
347
                        } else {
355
                        } else {
348
                                $oidinfo_xml = false;
356
                                $oidinfo_xml = false;
349
                        }
357
                        }
350
 
358
 
351
                        $query = self::QUERY_REGISTER_V1;
359
                        $query = self::QUERY_REGISTER_V1;
352
 
360
 
353
                        $root_oids = array();
361
                        $root_oids = array();
354
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
362
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
355
                                if ($ot::ns() == 'oid') {
363
                                if ($ot::ns() == 'oid') {
356
                                        $res = OIDplus::db()->query("select id from ###objects where " .
364
                                        $res = OIDplus::db()->query("select id from ###objects where " .
357
                                                                    "(parent = 'oid:' or " .
365
                                                                    "(parent = 'oid:' or " .
358
                                                                    // The following two cases are special cases e.g. if there are multiple PEN or UUID-OIDs, and the system owner decides to use the IANA PEN as root OID, but actually, it is not "his" root then! The OIDs inside the IANA PEN root are his root then!
366
                                                                    // The following two cases are special cases e.g. if there are multiple PEN or UUID-OIDs, and the system owner decides to use the IANA PEN as root OID, but actually, it is not "his" root then! The OIDs inside the IANA PEN root are his root then!
359
                                                                    "parent in (select oid from ###asn1id where well_known = ?) or " .
367
                                                                    "parent in (select oid from ###asn1id where well_known = ?) or " .
360
                                                                    "parent in (select oid from ###iri where well_known = ?)) and " .
368
                                                                    "parent in (select oid from ###iri where well_known = ?)) and " .
361
                                                                    // We assume hereby that RAs of well-known OIDs (e.g. IANA) will not use OIDplus for allocating OIDs:
369
                                                                    // We assume hereby that RAs of well-known OIDs (e.g. IANA) will not use OIDplus for allocating OIDs:
362
                                                                    "id not in (select oid from ###asn1id where well_known = ?) and " .
370
                                                                    "id not in (select oid from ###asn1id where well_known = ?) and " .
363
                                                                    "id not in (select oid from ###iri where well_known = ?)", array(true, true, true, true));
371
                                                                    "id not in (select oid from ###iri where well_known = ?)", array(true, true, true, true));
364
                                        $res->naturalSortByField('id');
372
                                        $res->naturalSortByField('id');
365
                                        while ($row = $res->fetch_array()) {
373
                                        while ($row = $res->fetch_array()) {
366
                                                $root_oids[] = substr($row['id'],strlen('oid:'));
374
                                                $root_oids[] = substr($row['id'],strlen('oid:'));
367
                                        }
375
                                        }
368
                                }
376
                                }
369
                        }
377
                        }
370
                        $payload = array(
378
                        $payload = array(
371
                                "query" => $query, // we must include $query to the payload, because we want to sign it
379
                                "query" => $query, // we must include $query to the payload, because we want to sign it
372
                                "privacy_level" => $privacy_level,
380
                                "privacy_level" => $privacy_level,
373
                                "system_id" => OIDplus::getSystemId(false),
381
                                "system_id" => OIDplus::getSystemId(false),
374
                                "public_key" => OIDplus::getSystemPublicKey(),
382
                                "public_key" => OIDplus::getSystemPublicKey(),
375
                                "system_url" => $system_url,
383
                                "system_url" => $system_url,
376
                                "hide_system_url" => 0,
384
                                "hide_system_url" => 0,
377
                                "hide_public_key" => 0,
385
                                "hide_public_key" => 0,
378
                                "admin_email" => OIDplus::config()->getValue('admin_email'),
386
                                "admin_email" => OIDplus::config()->getValue('admin_email'),
379
                                "system_title" => OIDplus::config()->getValue('system_title'),
387
                                "system_title" => OIDplus::config()->getValue('system_title'),
380
                                "oidinfo_xml" => @base64_encode($oidinfo_xml),
388
                                "oidinfo_xml" => @base64_encode($oidinfo_xml),
381
                                "root_oids" => $root_oids,
389
                                "root_oids" => $root_oids,
382
                                "system_version" => OIDplus::getVersion(),
390
                                "system_version" => OIDplus::getVersion(),
383
                                "system_install_type" => OIDplus::getInstallType()
391
                                "system_install_type" => OIDplus::getInstallType()
384
                        );
392
                        );
385
 
393
 
386
                        $signature = '';
394
                        $signature = '';
387
                        if (!OIDplus::getPkiStatus() || !@openssl_sign(json_encode($payload), $signature, OIDplus::getSystemPrivateKey())) {
395
                        if (!OIDplus::getPkiStatus() || !@openssl_sign(json_encode($payload), $signature, OIDplus::getSystemPrivateKey())) {
388
                                return false; // throw new OIDplusException(_L('Signature failed'));
396
                                return false; // throw new OIDplusException(_L('Signature failed'));
389
                        }
397
                        }
390
 
398
 
391
                        $data = array(
399
                        $data = array(
392
                                "payload" => $payload,
400
                                "payload" => $payload,
393
                                "signature" => base64_encode($signature)
401
                                "signature" => base64_encode($signature)
394
                        );
402
                        );
395
 
403
 
396
                        if (function_exists('gzdeflate')) {
404
                        if (function_exists('gzdeflate')) {
397
                                $compressed = "1";
405
                                $compressed = "1";
398
                                $data2 = gzdeflate(json_encode($data));
406
                                $data2 = gzdeflate(json_encode($data));
399
                        } else {
407
                        } else {
400
                                $compressed = "0";
408
                                $compressed = "0";
401
                                $data2 = json_encode($data);
409
                                $data2 = json_encode($data);
402
                        }
410
                        }
403
 
411
 
404
                        $res = url_post_contents(
412
                        $res = url_post_contents(
405
                                'https://oidplus.viathinksoft.com/reg2/query.php',
413
                                'https://oidplus.viathinksoft.com/reg2/query.php',
406
                                array(
414
                                array(
407
                                        "query"      => $query,
415
                                        "query"      => $query,
408
                                        "compressed" => $compressed,
416
                                        "compressed" => $compressed,
409
                                        "data"       => base64_encode($data2)
417
                                        "data"       => base64_encode($data2)
410
                                )
418
                                )
411
                        );
419
                        );
412
 
420
 
413
                        if ($res === false) return false; // throw new OIDplusException(_L('Communication with %1 server failed', 'ViaThinkSoft'));
421
                        if ($res === false) return false; // throw new OIDplusException(_L('Communication with %1 server failed', 'ViaThinkSoft'));
414
 
422
 
415
                        $json = @json_decode($res, true);
423
                        $json = @json_decode($res, true);
416
 
424
 
417
                        if (!$json) {
425
                        if (!$json) {
418
                                return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
426
                                return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
419
                        }
427
                        }
420
 
428
 
421
                        if (isset($json['error']) || ($json['status'] < 0)) {
429
                        if (isset($json['error']) || ($json['status'] < 0)) {
422
                                if (isset($json['error'])) {
430
                                if (isset($json['error'])) {
423
                                        return false; // throw new OIDplusException(_L('Received error status code: %1',$json['error']));
431
                                        return false; // throw new OIDplusException(_L('Received error status code: %1',$json['error']));
424
                                } else {
432
                                } else {
425
                                        return false; // throw new OIDplusException(_L('Received error status code: %1',$json['status']));
433
                                        return false; // throw new OIDplusException(_L('Received error status code: %1',$json['status']));
426
                                }
434
                                }
427
                        } else if ($json['status'] == 99/*Hash conflict*/) {
435
                        } else if ($json['status'] == 99/*Hash conflict*/) {
428
                                OIDplus::logger()->log("V2:[WARN]A", "Removing SystemID and key pair because there is a hash conflict with another OIDplus system!");
436
                                OIDplus::logger()->log("V2:[WARN]A", "Removing SystemID and key pair because there is a hash conflict with another OIDplus system!");
429
 
437
 
430
                                // Delete the system ID since we have a conflict with the 31-bit hash!
438
                                // Delete the system ID since we have a conflict with the 31-bit hash!
431
                                OIDplus::config()->setValue('oidplus_private_key', '');
439
                                OIDplus::config()->setValue('oidplus_private_key', '');
432
                                OIDplus::config()->setValue('oidplus_public_key', '');
440
                                OIDplus::config()->setValue('oidplus_public_key', '');
433
 
441
 
434
                                // Try to generate a new system ID
442
                                // Try to generate a new system ID
435
                                OIDplus::getPkiStatus(true);
443
                                OIDplus::getPkiStatus(true);
436
 
444
 
437
                                // Enforce a new registration attempt at the next page visit
445
                                // Enforce a new registration attempt at the next page visit
438
                                // We will not try again here, because that might lead to an endless loop if the VTS server would always return 'HASH_CONFLCIT'
446
                                // We will not try again here, because that might lead to an endless loop if the VTS server would always return 'HASH_CONFLCIT'
439
                                OIDplus::config()->setValue('reg_last_ping', 0);
447
                                OIDplus::config()->setValue('reg_last_ping', 0);
440
                        } else if ($json['status'] == 0/*OK*/) {
448
                        } else if ($json['status'] == 0/*OK*/) {
441
                                // Note: whois.viathinksoft.de:43 uses VGWhoIs, which uses these patterns: https://github.com/danielmarschall/vgwhois/blob/master/main/pattern/oid
449
                                // Note: whois.viathinksoft.de:43 uses VGWhoIs, which uses these patterns: https://github.com/danielmarschall/vgwhois/blob/master/main/pattern/oid
442
                                // If your system gets acknowledged by ViaThinkSoft, then vts_whois will be filled with that server name whois.viathinksoft.de:43
450
                                // If your system gets acknowledged by ViaThinkSoft, then vts_whois will be filled with that server name whois.viathinksoft.de:43
443
                                if (isset($json['vts_whois'])) OIDplus::config()->setValue('vts_whois', $json['vts_whois']);
451
                                if (isset($json['vts_whois'])) OIDplus::config()->setValue('vts_whois', $json['vts_whois']);
444
 
452
 
445
                                // ViaThinkSoft certifies the system public key and other system attributes and root objects (requires human verification)
453
                                // ViaThinkSoft certifies the system public key and other system attributes and root objects (requires human verification)
446
                                if (isset($json['vts_cert'])) OIDplus::config()->setValue('vts_cert', $json['vts_cert']);
454
                                if (isset($json['vts_cert'])) OIDplus::config()->setValue('vts_cert', $json['vts_cert']);
447
                                if (isset($json['vts_ca'])) OIDplus::config()->setValue('vts_ca', $json['vts_ca']);
455
                                if (isset($json['vts_ca'])) OIDplus::config()->setValue('vts_ca', $json['vts_ca']);
448
                        }
456
                        }
449
                }
457
                }
450
        }
458
        }
451
 
459
 
452
        /**
460
        /**
453
         * @param bool $html
461
         * @param bool $html
454
         * @return void
462
         * @return void
455
         * @throws OIDplusException
463
         * @throws OIDplusException
456
         */
464
         */
457
        public function init(bool $html=true) {
465
        public function init(bool $html=true) {
458
                if (OIDplus::getEditionInfo()['vendor'] != 'ViaThinkSoft') {
466
                if (OIDplus::getEditionInfo()['vendor'] != 'ViaThinkSoft') {
459
                        throw new OIDplusException(_L('This plugin is only available in the ViaThinkSoft edition of OIDplus'));
467
                        throw new OIDplusException(_L('This plugin is only available in the ViaThinkSoft edition of OIDplus'));
460
                }
468
                }
461
 
469
 
462
                // Note: It is important that the default value is '2', otherwise, systems which don't have CURL will fail
470
                // Note: It is important that the default value is '2', otherwise, systems which don't have CURL will fail
463
                OIDplus::config()->prepareConfigKey('reg_privacy', '2=Hide your system, 1=Register your system to the ViaThinkSoft directory and oid-info.com, 0=Publish your system to ViaThinkSoft directory and all public contents (RA/OID) to oid-info.com', '2', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
471
                OIDplus::config()->prepareConfigKey('reg_privacy', '2=Hide your system, 1=Register your system to the ViaThinkSoft directory and oid-info.com, 0=Publish your system to ViaThinkSoft directory and all public contents (RA/OID) to oid-info.com', '2', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
464
                        if (($value != '0') && ($value != '1') && ($value != '2')) {
472
                        if (($value != '0') && ($value != '1') && ($value != '2')) {
465
                                throw new OIDplusException(_L('Please enter either 0, 1 or 2.'));
473
                                throw new OIDplusException(_L('Please enter either 0, 1 or 2.'));
466
                        }
474
                        }
467
                        // Now do a recheck and notify the ViaThinkSoft server
475
                        // Now do a recheck and notify the ViaThinkSoft server
468
                        if (($value == 2) || !OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
476
                        if (($value == 2) || !OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
469
                                OIDplus::config()->setValue('reg_last_ping', 0);
477
                                OIDplus::config()->setValue('reg_last_ping', 0);
470
                                if (!url_post_contents_available(true, $reason)) throw new OIDplusException(_L('The system cannot contact the ViaThinkSoft server to change the registration settings.').' '.$reason);
478
                                if (!url_post_contents_available(true, $reason)) throw new OIDplusException(_L('The system cannot contact the ViaThinkSoft server to change the registration settings.').' '.$reason);
471
                                $this->sendRegistrationQuery($value);
479
                                $this->sendRegistrationQuery($value);
472
                        }
480
                        }
473
                });
481
                });
474
                OIDplus::config()->prepareConfigKey('reg_ping_interval', 'Registration ping interval (in seconds)', '3600', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
482
                OIDplus::config()->prepareConfigKey('reg_ping_interval', 'Registration ping interval (in seconds)', '3600', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
475
 
483
 
476
                });
484
                });
477
                OIDplus::config()->prepareConfigKey('reg_last_ping', 'Last ping to ViaThinkSoft directory services', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
485
                OIDplus::config()->prepareConfigKey('reg_last_ping', 'Last ping to ViaThinkSoft directory services', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
478
 
486
 
479
                });
487
                });
480
                OIDplus::config()->prepareConfigKey('vts_whois', 'ViaThinkSoft Whois Server (if this system is recognized)', '', OIDplusConfig::PROTECTION_READONLY, function($value) {
488
                OIDplus::config()->prepareConfigKey('vts_whois', 'ViaThinkSoft Whois Server (if this system is recognized)', '', OIDplusConfig::PROTECTION_READONLY, function($value) {
481
 
489
 
482
                });
490
                });
483
                OIDplus::config()->prepareConfigKey('vts_cert', 'ViaThinkSoft certificate (requires registration)', '', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
491
                OIDplus::config()->prepareConfigKey('vts_cert', 'ViaThinkSoft certificate (requires registration)', '', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
484
 
492
 
485
                });
493
                });
486
                OIDplus::config()->prepareConfigKey('vts_ca', 'ViaThinkSoft certificate root (requires registration)', '', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
494
                OIDplus::config()->prepareConfigKey('vts_ca', 'ViaThinkSoft certificate root (requires registration)', '', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
487
 
495
 
488
                });
496
                });
489
                OIDplus::config()->prepareConfigKey('oobe_registration_done', '"Out Of Box Experience" wizard for OIDplusPageAdminRegistration done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
497
                OIDplus::config()->prepareConfigKey('oobe_registration_done', '"Out Of Box Experience" wizard for OIDplusPageAdminRegistration done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
490
 
498
 
491
                // Is it time to register / renew the directory entry?
499
                // Is it time to register / renew the directory entry?
492
                // Note: REGISTRATION_HIDE_SYSTEM is an undocumented constant that can be put in the userdata/baseconfig/config.inc.php files of a test system accessing the same database as the productive system that is registered.
500
                // Note: REGISTRATION_HIDE_SYSTEM is an undocumented constant that can be put in the userdata/baseconfig/config.inc.php files of a test system accessing the same database as the productive system that is registered.
493
                // This avoids that the URL of a productive system is overridden with the URL of a cloned test system (since they use the same database, they also have the same system ID)
501
                // This avoids that the URL of a productive system is overridden with the URL of a cloned test system (since they use the same database, they also have the same system ID)
494
 
502
 
495
                if (OIDplus::config()->getValue('oobe_registration_done') == '1') {
503
                if (OIDplus::config()->getValue('oobe_registration_done') == '1') {
496
                        if (!OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
504
                        if (!OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
497
                                $privacy_level = OIDplus::config()->getValue('reg_privacy');
505
                                $privacy_level = OIDplus::config()->getValue('reg_privacy');
498
 
506
 
499
                                if (PHP_SAPI !== 'cli') { // don't register when called from CLI, otherwise the oidinfo XML can't convert relative links into absolute links
507
                                if (PHP_SAPI !== 'cli') { // don't register when called from CLI, otherwise the oidinfo XML can't convert relative links into absolute links
500
                                        $last_ping = OIDplus::config()->getValue('reg_last_ping');
508
                                        $last_ping = OIDplus::config()->getValue('reg_last_ping');
501
                                        if (!is_numeric($last_ping)) $last_ping = 0;
509
                                        if (!is_numeric($last_ping)) $last_ping = 0;
502
                                        $last_ping_interval = OIDplus::config()->getValue('reg_ping_interval');
510
                                        $last_ping_interval = OIDplus::config()->getValue('reg_ping_interval');
503
                                        if (!is_numeric($last_ping_interval)) $last_ping_interval = 3600;
511
                                        if (!is_numeric($last_ping_interval)) $last_ping_interval = 3600;
504
 
512
 
505
                                        // Cronjobs get half ping interval, to make sure that a web visitor won't get any delay
513
                                        // Cronjobs get half ping interval, to make sure that a web visitor won't get any delay
506
                                        if (OIDplus::isCronjob()) $last_ping_interval /= 2;
514
                                        if (OIDplus::isCronjob()) $last_ping_interval /= 2;
507
 
515
 
508
                                        if ((time()-$last_ping >= $last_ping_interval)) {
516
                                        if ((time()-$last_ping >= $last_ping_interval)) {
509
                                                try {
517
                                                try {
510
                                                        $this->sendRegistrationQuery();
518
                                                        $this->sendRegistrationQuery();
511
                                                } catch (\Exception $e) {
519
                                                } catch (\Exception $e) {
512
                                                        // Don't do anything, because we don't want that a failed registration query blocks the system
520
                                                        // Don't do anything, because we don't want that a failed registration query blocks the system
513
                                                        OIDplus::logger()->log('V2:[WARN]A', 'System registration query crashed: %1', $e->getMessage());
521
                                                        OIDplus::logger()->log('V2:[WARN]A', 'System registration query crashed: %1', $e->getMessage());
514
                                                }
522
                                                }
515
                                        }
523
                                        }
516
                                }
524
                                }
517
                        }
525
                        }
518
                }
526
                }
519
        }
527
        }
520
 
528
 
521
        /**
529
        /**
522
         * @param array $json
530
         * @param array $json
523
         * @param string|null $ra_email
531
         * @param string|null $ra_email
524
         * @param bool $nonjs
532
         * @param bool $nonjs
525
         * @param string $req_goto
533
         * @param string $req_goto
526
         * @return bool
534
         * @return bool
527
         * @throws OIDplusException
535
         * @throws OIDplusException
528
         */
536
         */
529
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
537
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
530
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
538
                if (!OIDplus::authUtils()->isAdminLoggedIn()) return false;
531
 
539
 
532
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
540
                if (file_exists(__DIR__.'/img/main_icon16.png')) {
533
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
541
                        $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png';
534
                } else {
542
                } else {
535
                        $tree_icon = null; // default icon (folder)
543
                        $tree_icon = null; // default icon (folder)
536
                }
544
                }
537
 
545
 
538
                $json[] = array(
546
                $json[] = array(
539
                        'id' => 'oidplus:srv_registration',
547
                        'id' => 'oidplus:srv_registration',
540
                        'icon' => $tree_icon,
548
                        'icon' => $tree_icon,
541
                        'text' => _L('System registration')
549
                        'text' => _L('System registration')
542
                );
550
                );
543
 
551
 
544
                return true;
552
                return true;
545
        }
553
        }
546
 
554
 
547
        /**
555
        /**
548
         * @param string $request
556
         * @param string $request
549
         * @return array|false
557
         * @return array|false
550
         */
558
         */
551
        public function tree_search(string $request) {
559
        public function tree_search(string $request) {
552
                return false;
560
                return false;
553
        }
561
        }
554
 
562
 
555
        /**
563
        /**
556
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
564
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
557
         * @return bool
565
         * @return bool
558
         * @throws OIDplusException
566
         * @throws OIDplusException
559
         */
567
         */
560
        public function oobeRequested(): bool {
568
        public function oobeRequested(): bool {
561
                return OIDplus::config()->getValue('oobe_registration_done') == '0';
569
                return OIDplus::config()->getValue('oobe_registration_done') == '0';
562
        }
570
        }
563
 
571
 
564
        /**
572
        /**
565
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
573
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1
566
         * @param int $step
574
         * @param int $step
567
         * @param bool $do_edits
575
         * @param bool $do_edits
568
         * @param bool $errors_happened
576
         * @param bool $errors_happened
569
         * @return void
577
         * @return void
570
         * @throws OIDplusConfigInitializationException
578
         * @throws OIDplusConfigInitializationException
571
         * @throws OIDplusException
579
         * @throws OIDplusException
572
         */
580
         */
573
        public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ {
581
        public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ {
574
                echo '<h2>'._L('Step %1: System registration and automatic publishing (optional)',$step).'</h2>';
582
                echo '<h2>'._L('Step %1: System registration and automatic publishing (optional)',$step).'</h2>';
575
 
583
 
576
                if (file_exists(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html')) {
584
                if (file_exists(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html')) {
577
                        $info = file_get_contents(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html');
585
                        $info = file_get_contents(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html');
578
                } else {
586
                } else {
579
                        $info = file_get_contents(__DIR__ . '/info.html');
587
                        $info = file_get_contents(__DIR__ . '/info.html');
580
                }
588
                }
581
 
589
 
582
                // make sure the program works even if the user provided HTML is not UTF-8
590
                // make sure the program works even if the user provided HTML is not UTF-8
583
                $info = convert_to_utf8_no_bom($info);
591
                $info = convert_to_utf8_no_bom($info);
584
 
592
 
585
                echo $info;
593
                echo $info;
586
 
594
 
587
                if (!url_post_contents_available(true, $reason)) {
595
                if (!url_post_contents_available(true, $reason)) {
588
                        echo '<p><font color="red">';
596
                        echo '<p><font color="red">';
589
                        echo _L('OIDplus cannot connect to the Internet (%1). Therefore, you <b>cannot</b> register your OIDplus instance now.', $reason);
597
                        echo _L('OIDplus cannot connect to the Internet (%1). Therefore, you <b>cannot</b> register your OIDplus instance now.', $reason);
590
                        echo '</font></p>';
598
                        echo '</font></p>';
591
                        if ($do_edits) {
599
                        if ($do_edits) {
592
                                OIDplus::config()->setValue('oobe_registration_done', '1');
600
                                OIDplus::config()->setValue('oobe_registration_done', '1');
593
                        }
601
                        }
594
                        return;
602
                        return;
595
                }
603
                }
596
 
604
 
597
                $pki_status = OIDplus::getPkiStatus();
605
                $pki_status = OIDplus::getPkiStatus();
598
 
606
 
599
                if (!$pki_status) {
607
                if (!$pki_status) {
600
                        echo '<p><font color="red">';
608
                        echo '<p><font color="red">';
601
                        echo _L('Your system could not generate a private/public key pair. (OpenSSL is probably missing on your system).').' ';
609
                        echo _L('Your system could not generate a private/public key pair. (OpenSSL is probably missing on your system).').' ';
602
                        echo _L('Therefore, you <b>cannot</b> register your OIDplus instance now.');
610
                        echo _L('Therefore, you <b>cannot</b> register your OIDplus instance now.');
603
                        echo '</font></p>';
611
                        echo '</font></p>';
604
                        if ($do_edits) {
612
                        if ($do_edits) {
605
                                OIDplus::config()->setValue('oobe_registration_done', '1');
613
                                OIDplus::config()->setValue('oobe_registration_done', '1');
606
                        }
614
                        }
607
                        return;
615
                        return;
608
                }
616
                }
609
 
617
 
610
                echo '<p>'._L('Privacy level').':</p><select name="reg_privacy" id="reg_privacy">';
618
                echo '<p>'._L('Privacy level').':</p><select name="reg_privacy" id="reg_privacy">';
611
 
619
 
612
                # ---
620
                # ---
613
 
621
 
614
                echo '<option value="0"';
622
                echo '<option value="0"';
615
                if (isset($_POST['sent'])) {
623
                if (isset($_POST['sent'])) {
616
                        if (isset($_POST['reg_privacy']) && ($_POST['reg_privacy'] == 0)) echo ' selected';
624
                        if (isset($_POST['reg_privacy']) && ($_POST['reg_privacy'] == 0)) echo ' selected';
617
                } else {
625
                } else {
618
                        if ((OIDplus::config()->getValue('reg_privacy') == 0) || !OIDplus::config()->getValue('oobe_registration_done')) {
626
                        if ((OIDplus::config()->getValue('reg_privacy') == 0) || !OIDplus::config()->getValue('oobe_registration_done')) {
619
                                echo ' selected';
627
                                echo ' selected';
620
                        } else {
628
                        } else {
621
                                echo '';
629
                                echo '';
622
                        }
630
                        }
623
                }
631
                }
624
                echo '>'._L('0 = Register to directory service and automatically publish RA/OID data at oid-info.com').'</option>';
632
                echo '>'._L('0 = Register to directory service and automatically publish RA/OID data at oid-info.com').'</option>';
625
 
633
 
626
                # ---
634
                # ---
627
 
635
 
628
                echo '<option value="1"';
636
                echo '<option value="1"';
629
                if (isset($_POST['sent'])) {
637
                if (isset($_POST['sent'])) {
630
                        if (isset($_POST['reg_privacy']) && ($_POST['reg_privacy'] == 1)) echo ' selected';
638
                        if (isset($_POST['reg_privacy']) && ($_POST['reg_privacy'] == 1)) echo ' selected';
631
                } else {
639
                } else {
632
                        if ((OIDplus::config()->getValue('reg_privacy') == 1)) {
640
                        if ((OIDplus::config()->getValue('reg_privacy') == 1)) {
633
                                echo ' selected';
641
                                echo ' selected';
634
                        } else {
642
                        } else {
635
                                echo '';
643
                                echo '';
636
                        }
644
                        }
637
                }
645
                }
638
                echo '>'._L('1 = Only register to directory service').'</option>';
646
                echo '>'._L('1 = Only register to directory service').'</option>';
639
 
647
 
640
                # ---
648
                # ---
641
 
649
 
642
                echo '<option value="2"';
650
                echo '<option value="2"';
643
                if (isset($_POST['sent'])) {
651
                if (isset($_POST['sent'])) {
644
                        if (isset($_POST['reg_privacy']) && ($_POST['reg_privacy'] == 2)) echo ' selected';
652
                        if (isset($_POST['reg_privacy']) && ($_POST['reg_privacy'] == 2)) echo ' selected';
645
                } else {
653
                } else {
646
                        if ((OIDplus::config()->getValue('reg_privacy') == 2)) {
654
                        if ((OIDplus::config()->getValue('reg_privacy') == 2)) {
647
                                echo ' selected';
655
                                echo ' selected';
648
                        } else {
656
                        } else {
649
                                echo '';
657
                                echo '';
650
                        }
658
                        }
651
                }
659
                }
652
                echo '>'._L('2 = Hide system').'</option>';
660
                echo '>'._L('2 = Hide system').'</option>';
653
 
661
 
654
                # ---
662
                # ---
655
 
663
 
656
                echo '</select>';
664
                echo '</select>';
657
 
665
 
658
                $htmlmsg = '';
666
                $htmlmsg = '';
659
                if ($do_edits) {
667
                if ($do_edits) {
660
                        try {
668
                        try {
661
                                OIDplus::config()->setValue('reg_privacy', $_POST['reg_privacy'] ?? 1);
669
                                OIDplus::config()->setValue('reg_privacy', $_POST['reg_privacy'] ?? 1);
662
                                OIDplus::config()->setValue('oobe_registration_done', '1');
670
                                OIDplus::config()->setValue('oobe_registration_done', '1');
663
                        } catch (\Exception $e) {
671
                        } catch (\Exception $e) {
664
                                $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage());
672
                                $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage());
665
                                $errors_happened = true;
673
                                $errors_happened = true;
666
                        }
674
                        }
667
                }
675
                }
668
                if (!empty($htmlmsg)) echo ' <font color="red"><b>'.$htmlmsg.'</b></font>';
676
                if (!empty($htmlmsg)) echo ' <font color="red"><b>'.$htmlmsg.'</b></font>';
669
 
677
 
670
                echo '<p>'._L('<i>Privacy information:</i> This setting can always be changed in the administrator login / control panel.').'<br>';
678
                echo '<p>'._L('<i>Privacy information:</i> This setting can always be changed in the administrator login / control panel.').'<br>';
671
                echo _L('<a %1>Click here</a> for more information about privacy related topics.','href="../../../../res/OIDplus/privacy_documentation.html" target="_blank"');
679
                echo _L('<a %1>Click here</a> for more information about privacy related topics.','href="../../../../res/OIDplus/privacy_documentation.html" target="_blank"');
672
                echo '</p>';
680
                echo '</p>';
673
        }
681
        }
674
 
682
 
675
        /**
683
        /**
676
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
684
         * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8
677
         * @param string|null $user
685
         * @param string|null $user
678
         * @return array
686
         * @return array
679
         * @throws OIDplusException
687
         * @throws OIDplusException
680
         */
688
         */
681
        public function getNotifications(string $user=null): array {
689
        public function getNotifications(string $user=null): array {
682
                $notifications = array();
690
                $notifications = array();
683
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
691
                if ((!$user || ($user == 'admin')) && OIDplus::authUtils()->isAdminLoggedIn()) {
684
                        if (!url_post_contents_available(true, $reason)) {
692
                        if (!url_post_contents_available(true, $reason)) {
685
                                $title = _L('System registration');
693
                                $title = _L('System registration');
686
                                $notifications[] = new OIDplusNotification('ERR', _L('OIDplus plugin "%1" is enabled, but OIDplus cannot connect to the Internet.', '<a '.OIDplus::gui()->link('oidplus:srv_registration').'>'.htmlentities($title).'</a>').' '.$reason);
694
                                $notifications[] = new OIDplusNotification('ERR', _L('OIDplus plugin "%1" is enabled, but OIDplus cannot connect to the Internet.', '<a '.OIDplus::gui()->link('oidplus:srv_registration').'>'.htmlentities($title).'</a>').' '.$reason);
687
                        }
695
                        }
688
                }
696
                }
689
                return $notifications;
697
                return $notifications;
690
        }
698
        }
691
 
699
 
692
}
700
}
693
 
701