Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
139 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
256 daniel-mar 20
class OIDplusPageAdminRegistration extends OIDplusPagePluginAdmin {
139 daniel-mar 21
 
269 daniel-mar 22
        /*private*/ const QUERY_REGISTER_V1 =         '1.3.6.1.4.1.37476.2.5.2.1.1.1';
23
        /*private*/ const QUERY_UNREGISTER_V1 =       '1.3.6.1.4.1.37476.2.5.2.1.2.1';
24
        /*private*/ const QUERY_LISTALLSYSTEMIDS_V1 = '1.3.6.1.4.1.37476.2.5.2.1.3.1';
25
        /*private*/ const QUERY_LIVESTATUS_V1 =       '1.3.6.1.4.1.37476.2.5.2.1.4.1';
256 daniel-mar 26
 
139 daniel-mar 27
        public function gui($id, &$out, &$handled) {
141 daniel-mar 28
                if ($id === 'oidplus:srv_registration') {
139 daniel-mar 29
                        $handled = true;
360 daniel-mar 30
                        $out['title'] = _L('System registration settings');
241 daniel-mar 31
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
139 daniel-mar 32
 
33
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
34
                                $out['icon'] = 'img/error_big.png';
360 daniel-mar 35
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login')).'</p>';
281 daniel-mar 36
                                return;
37
                        }
38
 
362 daniel-mar 39
                        if (file_exists(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html')) {
40
                                $info = file_get_contents(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html');
41
                        } else {
42
                                $info = file_get_contents(__DIR__ . '/info.html');
43
                        }
281 daniel-mar 44
 
362 daniel-mar 45
                        // make sure the program works even if the user provided HTML is not UTF-8
46
                        $info = iconv(mb_detect_encoding($info, mb_detect_order(), true), 'UTF-8//IGNORE', $info);
47
                        $bom = pack('H*','EFBBBF');
48
                        $info = preg_replace("/^$bom/", '', $info);
49
 
50
                        $out['text'] = $info;
51
 
281 daniel-mar 52
                        if (!OIDplus::getPkiStatus()) {
360 daniel-mar 53
                                $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>';
139 daniel-mar 54
                        } else {
360 daniel-mar 55
                                $out['text'] .= '<p><input type="button" onclick="openOidInPanel(\'oidplus:srvreg_status\');" value="'._L('Check status of the registration and collected data').'"></p>';
277 daniel-mar 56
 
281 daniel-mar 57
                                if (OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
360 daniel-mar 58
                                        $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>';
281 daniel-mar 59
                                }
139 daniel-mar 60
 
360 daniel-mar 61
                                $out['text'] .= '<p>'._L('You can adjust your privacy level here').':</p><p><select name="reg_privacy" id="reg_privacy">';
227 daniel-mar 62
 
281 daniel-mar 63
                                # ---
139 daniel-mar 64
 
281 daniel-mar 65
                                $out['text'] .= '<option value="0"';
66
                                if (OIDplus::config()->getValue('reg_privacy') == 0) {
67
                                        $out['text'] .= ' selected';
68
                                } else {
69
                                        $out['text'] .= '';
70
                                }
360 daniel-mar 71
                                $out['text'] .= '>'._L('0 = Register to directory service and automatically publish RA/OID data at oid-info.com').'</option>';
139 daniel-mar 72
 
281 daniel-mar 73
                                # ---
139 daniel-mar 74
 
281 daniel-mar 75
                                $out['text'] .= '<option value="1"';
76
                                if (OIDplus::config()->getValue('reg_privacy') == 1) {
77
                                        $out['text'] .= ' selected';
78
                                } else {
79
                                        $out['text'] .= '';
80
                                }
360 daniel-mar 81
                                $out['text'] .= '>'._L('1 = Only register to directory service').'</option>';
139 daniel-mar 82
 
281 daniel-mar 83
                                # ---
139 daniel-mar 84
 
281 daniel-mar 85
                                $out['text'] .= '<option value="2"';
86
                                if (OIDplus::config()->getValue('reg_privacy') == 2) {
87
                                        $out['text'] .= ' selected';
88
                                } else {
89
                                        $out['text'] .= '';
90
                                }
360 daniel-mar 91
                                $out['text'] .= '>'._L('2 = Hide system').'</option>';
139 daniel-mar 92
 
281 daniel-mar 93
                                # ---
139 daniel-mar 94
 
360 daniel-mar 95
                                $out['text'] .= '</select> <input type="button" value="'._L('Change').'" onclick="crudActionRegPrivacyUpdate()"></p>';
139 daniel-mar 96
 
360 daniel-mar 97
                                $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>';
139 daniel-mar 98
 
360 daniel-mar 99
                                $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>';
139 daniel-mar 100
                        }
101
                }
141 daniel-mar 102
                if ($id === 'oidplus:srvreg_status') {
103
                        $handled = true;
104
 
256 daniel-mar 105
                        $query = self::QUERY_LIVESTATUS_V1;
141 daniel-mar 106
 
107
                        $payload = array(
108
                                "query" => $query, // we must repeat the query because we want to sign it
227 daniel-mar 109
                                "system_id" => OIDplus::getSystemId(false)
141 daniel-mar 110
                        );
111
 
112
                        $signature = '';
239 daniel-mar 113
                        if (!@openssl_sign(json_encode($payload), $signature, OIDplus::config()->getValue('oidplus_private_key'))) {
360 daniel-mar 114
                                throw new OIDplusException(_L('Signature failed'));
239 daniel-mar 115
                        }
141 daniel-mar 116
 
117
                        $data = array(
118
                                "payload" => $payload,
119
                                "signature" => base64_encode($signature)
120
                        );
121
 
122
                        $ch = curl_init();
123
                        curl_setopt($ch, CURLOPT_URL, 'https://oidplus.viathinksoft.com/reg2/query.php');
124
                        curl_setopt($ch, CURLOPT_POST, 1);
125
                        curl_setopt($ch, CURLOPT_POSTFIELDS, "query=$query&data=".base64_encode(json_encode($data)));
126
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
127
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
128
                        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
239 daniel-mar 129
                        if (!($res = @curl_exec($ch))) {
360 daniel-mar 130
                                throw new OIDplusException(_L('Communication with ViaThinkSoft server failed: %1',curl_error($ch)));
239 daniel-mar 131
                        }
141 daniel-mar 132
                        curl_close($ch);
133
 
370 daniel-mar 134
                        $json = @json_decode($res, true);
135
 
136
                        if (!$json) {
137
                                $out['icon'] = 'img/error_big.png';
138
                                $out['text'] = _L('JSON reply from ViaThinkSoft decoding error: %1',$res);
139
                                return;
140
                        }
141
 
381 daniel-mar 142
                        if (isset($json['error']) || ($json['status'] < 0)) {
370 daniel-mar 143
                                $out['icon'] = 'img/error_big.png';
144
                                if (isset($json['error'])) {
145
                                        $out['text'] = _L('Received error status code: %1',$json['error']);
146
                                } else {
147
                                        $out['text'] = _L('Received error status code: %1',$json['status']);
148
                                }
149
                                return;
150
                        }
151
 
360 daniel-mar 152
                        $out['title'] = _L('Registration live status');
366 daniel-mar 153
                        $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>' .
372 daniel-mar 154
                                        $json['content'];
141 daniel-mar 155
                }
139 daniel-mar 156
        }
157
 
370 daniel-mar 158
        protected function areWeRegistered() {
159
                // To check if we are registered. Check it "anonymously" (i.e. without revealing our system ID)
160
                $res = file_get_contents('https://oidplus.viathinksoft.com/reg2/query.php?query='.self::QUERY_LISTALLSYSTEMIDS_V1);
161
 
162
                $json = @json_decode($res, true);
163
 
164
                if (!$json) {
165
                        return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
166
                }
167
 
381 daniel-mar 168
                if (isset($json['error']) || ($json['status'] < 0)) {
370 daniel-mar 169
                        if (isset($json['error'])) {
170
                                return false; // throw new OIDplusException(_L('Received error status code: %1',$json['error']));
171
                        } else {
172
                                return false; // throw new OIDplusException(_L('Received error status code: %1',$json['status']));
173
                        }
174
                }
175
 
176
                $list = $json['list'];
177
 
178
                return in_array(OIDplus::getSystemId(false), $list);
179
        }
180
 
140 daniel-mar 181
        public function sendRegistrationQuery($privacy_level=null) {
182
                if (is_null($privacy_level)) {
183
                        $privacy_level = OIDplus::config()->getValue('reg_privacy');
184
                }
139 daniel-mar 185
 
227 daniel-mar 186
                $system_url = OIDplus::getSystemUrl();
139 daniel-mar 187
 
175 daniel-mar 188
                // It is very important that we set the ping time NOW, because ViaThinkSoft might contact us during the ping,
189
                // and this would cause an endless loop!
190
                OIDplus::config()->setValue('reg_last_ping', time());
277 daniel-mar 191
 
239 daniel-mar 192
                if (!OIDplus::getPkiStatus()) return false;
175 daniel-mar 193
 
139 daniel-mar 194
                if ($privacy_level == 2) {
370 daniel-mar 195
                        // The user wants to unregister,  but we only unregister if we are registered
196
                        if ($this->areWeRegistered()) {
256 daniel-mar 197
                                $query = self::QUERY_UNREGISTER_V1;
139 daniel-mar 198
 
199
                                $payload = array(
200
                                        "query" => $query, // we must repeat the query because we want to sign it
227 daniel-mar 201
                                        "system_id" => OIDplus::getSystemId(false)
139 daniel-mar 202
                                );
203
 
204
                                $signature = '';
239 daniel-mar 205
                                if (!@openssl_sign(json_encode($payload), $signature, OIDplus::config()->getValue('oidplus_private_key'))) {
360 daniel-mar 206
                                        return false; // throw new OIDplusException(_L('Signature failed'));
239 daniel-mar 207
                                }
139 daniel-mar 208
 
209
                                $data = array(
210
                                        "payload" => $payload,
211
                                        "signature" => base64_encode($signature)
212
                                );
213
 
214
                                $ch = curl_init();
215
                                curl_setopt($ch, CURLOPT_URL, 'https://oidplus.viathinksoft.com/reg2/query.php');
216
                                curl_setopt($ch, CURLOPT_POST, 1);
217
                                curl_setopt($ch, CURLOPT_POSTFIELDS, "query=$query&data=".base64_encode(json_encode($data)));
218
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
219
                                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
220
                                curl_setopt($ch, CURLOPT_AUTOREFERER, true);
239 daniel-mar 221
                                if (!($res = @curl_exec($ch))) {
360 daniel-mar 222
                                        return false; // throw new OIDplusException(_L('Communication with ViaThinkSoft server failed: %1',curl_error($ch)));
239 daniel-mar 223
                                }
139 daniel-mar 224
                                curl_close($ch);
370 daniel-mar 225
 
226
                                $json = @json_decode($res, true);
227
 
228
                                if (!$json) {
229
                                        return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
230
                                }
231
 
381 daniel-mar 232
                                if (isset($json['error']) || ($json['status'] < 0)) {
370 daniel-mar 233
                                        if (isset($json['error'])) {
234
                                                return false; // throw new OIDplusException(_L('Received error status code: %1',$json['error']));
235
                                        } else {
236
                                                return false; // throw new OIDplusException(_L('Received error status code: %1',$json['status']));
237
                                        }
238
                                }
139 daniel-mar 239
                        }
240
                } else {
241
                        if ($privacy_level == 0) {
380 daniel-mar 242
                                $adminExportPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.400'); // OIDplusPageAdminOIDInfoExport
243
                                if (!is_null($adminExportPlugin)) {
139 daniel-mar 244
                                        ob_start();
245
                                        OIDplusPageAdminOIDInfoExport::outputXML(false); // no online check, because the query should be short (since the query is done while a visitor waits for the response)
246
                                        $oidinfo_xml = ob_get_contents();
247
                                        ob_end_clean();
248
                                } else {
249
                                        $oidinfo_xml = false;
250
                                }
251
                        } else {
252
                                $oidinfo_xml = false;
253
                        }
254
 
256 daniel-mar 255
                        $query = self::QUERY_REGISTER_V1;
139 daniel-mar 256
 
257
                        $root_oids = array();
227 daniel-mar 258
                        foreach (OIDplus::getEnabledObjectTypes() as $ot) {
139 daniel-mar 259
                                if ($ot::ns() == 'oid') {
261 daniel-mar 260
                                        $res = OIDplus::db()->query("select id from ###objects where " .
139 daniel-mar 261
                                                                    "parent = 'oid:' " .
262
                                                                    "order by ".OIDplus::db()->natOrder('id'));
236 daniel-mar 263
                                        while ($row = $res->fetch_array()) {
139 daniel-mar 264
                                                $root_oids[] = substr($row['id'],strlen('oid:'));
265
                                        }
266
                                }
267
                        }
268
                        $payload = array(
269
                                "query" => $query, // we must repeat the query because we want to sign it
270
                                "privacy_level" => $privacy_level,
227 daniel-mar 271
                                "system_id" => OIDplus::getSystemId(false),
139 daniel-mar 272
                                "public_key" => OIDplus::config()->getValue('oidplus_public_key'),
273
                                "system_url" => $system_url,
274
                                "hide_system_url" => 0,
275
                                "hide_public_key" => 0,
276
                                "admin_email" => OIDplus::config()->getValue('admin_email'),
257 daniel-mar 277
                                "system_title" => OIDplus::config()->getValue('system_title'),
139 daniel-mar 278
                                "oidinfo_xml" => @base64_encode($oidinfo_xml),
170 daniel-mar 279
                                "root_oids" => $root_oids,
280
                                "system_version" => OIDplus::getVersion(),
281
                                "system_install_type" => OIDplus::getInstallType()
139 daniel-mar 282
                        );
283
 
284
                        $signature = '';
239 daniel-mar 285
                        if (!@openssl_sign(json_encode($payload), $signature, OIDplus::config()->getValue('oidplus_private_key'))) {
360 daniel-mar 286
                                        return false; // throw new OIDplusException(_L('Signature failed'));
239 daniel-mar 287
                        }
139 daniel-mar 288
 
289
                        $data = array(
290
                                "payload" => $payload,
291
                                "signature" => base64_encode($signature)
292
                        );
293
 
294
                        $ch = curl_init();
295
                        curl_setopt($ch, CURLOPT_URL, 'https://oidplus.viathinksoft.com/reg2/query.php');
296
                        curl_setopt($ch, CURLOPT_POST, 1);
297
                        curl_setopt($ch, CURLOPT_POSTFIELDS, "query=$query&data=".base64_encode(json_encode($data)));
298
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
299
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
300
                        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
239 daniel-mar 301
                        if (!($res = @curl_exec($ch))) {
360 daniel-mar 302
                                return false; // throw new OIDplusException(_L('Communication with ViaThinkSoft server failed: %1',curl_error($ch)));
239 daniel-mar 303
                        }
139 daniel-mar 304
                        curl_close($ch);
206 daniel-mar 305
 
370 daniel-mar 306
                        $json = @json_decode($res, true);
307
 
308
                        if (!$json) {
309
                                return false; // throw new OIDplusException(_L('JSON reply from ViaThinkSoft decoding error: %1',$res));
310
                        }
311
 
381 daniel-mar 312
                        if (isset($json['error']) || ($json['status'] < 0)) {
313
                                if (isset($json['error'])) {
314
                                        return false; // throw new OIDplusException(_L('Received error status code: %1',$json['error']));
315
                                } else {
316
                                        return false; // throw new OIDplusException(_L('Received error status code: %1',$json['status']));
317
                                }
318
                        } else if ($json['status'] == 99/*Hash conflict*/) {
288 daniel-mar 319
                                OIDplus::logger()->log("[WARN]A!", "Removing SystemID and key pair because there is a hash conflict with another OIDplus system!");
206 daniel-mar 320
 
321
                                // Delete the system ID since we have a conflict with the 31-bit hash!
322
                                OIDplus::config()->setValue('oidplus_private_key', '');
323
                                OIDplus::config()->setValue('oidplus_public_key', '');
324
 
325
                                // Try to generate a new system ID
227 daniel-mar 326
                                OIDplus::getPkiStatus(true);
206 daniel-mar 327
 
370 daniel-mar 328
                                // Enforce a new registration attempt at the next page visit
206 daniel-mar 329
                                // We will not try again here, because that might lead to an endless loop if the VTS server would always return 'HASH_CONFLCIT'
330
                                OIDplus::config()->setValue('reg_last_ping', 0);
331
                        }
139 daniel-mar 332
                }
333
        }
334
 
335
        public function init($html=true) {
263 daniel-mar 336
                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', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
337
                        if (($value != '0') && ($value != '1') && ($value != '2')) {
360 daniel-mar 338
                                throw new OIDplusException(_L('Please enter either 0, 1 or 2.'));
263 daniel-mar 339
                        }
340
                        // Now do a recheck and notify the ViaThinkSoft server
316 daniel-mar 341
                        if (($value == 2) || !OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
342
                                OIDplus::config()->setValue('reg_last_ping', 0);
343
                                $this->sendRegistrationQuery($value);
344
                        }
263 daniel-mar 345
                });
346
                OIDplus::config()->prepareConfigKey('reg_ping_interval', 'Registration ping interval (in seconds)', '3600', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
277 daniel-mar 347
 
263 daniel-mar 348
                });
349
                OIDplus::config()->prepareConfigKey('reg_last_ping', 'Last ping to ViaThinkSoft directory services', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {
277 daniel-mar 350
 
263 daniel-mar 351
                });
362 daniel-mar 352
                OIDplus::config()->prepareConfigKey('oobe_registration_done', '"Out Of Box Experience" wizard for OIDplusPageAdminRegistration done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {});
277 daniel-mar 353
 
292 daniel-mar 354
                // Is it time to register / renew the directory entry?
294 daniel-mar 355
                // 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.
292 daniel-mar 356
                // 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)
277 daniel-mar 357
 
292 daniel-mar 358
                if (!OIDplus::baseConfig()->getValue('REGISTRATION_HIDE_SYSTEM', false)) {
359
                        $privacy_level = OIDplus::config()->getValue('reg_privacy');
139 daniel-mar 360
 
316 daniel-mar 361
                        if (php_sapi_name() !== 'cli') { // don't register when called from CLI, otherwise the oidinfo XML can't convert relative links into absolute links
292 daniel-mar 362
                                if ((time()-OIDplus::config()->getValue('reg_last_ping') >= OIDplus::config()->getValue('reg_ping_interval'))) {
363
                                        $this->sendRegistrationQuery();
139 daniel-mar 364
                                }
365
                        }
366
                }
367
        }
368
 
369
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
281 daniel-mar 370
                if (!OIDplus::authUtils()::isAdminLoggedIn()) return false;
292 daniel-mar 371
 
139 daniel-mar 372
                if (file_exists(__DIR__.'/treeicon.png')) {
241 daniel-mar 373
                        $tree_icon = OIDplus::webpath(__DIR__).'treeicon.png';
139 daniel-mar 374
                } else {
375
                        $tree_icon = null; // default icon (folder)
376
                }
377
 
378
                $json[] = array(
141 daniel-mar 379
                        'id' => 'oidplus:srv_registration',
139 daniel-mar 380
                        'icon' => $tree_icon,
360 daniel-mar 381
                        'text' => _L('System registration')
139 daniel-mar 382
                );
383
 
384
                return true;
385
        }
386
 
387
        public function tree_search($request) {
388
                return false;
389
        }
292 daniel-mar 390
 
391
        public function implementsFeature($id) {
370 daniel-mar 392
                if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested
292 daniel-mar 393
                return false;
394
        }
395
 
362 daniel-mar 396
        public function oobeRequested(): bool {
397
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
370 daniel-mar 398
 
362 daniel-mar 399
                return OIDplus::config()->getValue('oobe_registration_done') == '0';
400
        }
401
 
292 daniel-mar 402
        public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ {
403
                // Interface 1.3.6.1.4.1.37476.2.5.2.3.1
404
 
360 daniel-mar 405
                echo '<p><u>'._L('Step %1: System registration and automatic publishing (optional)',$step).'</u></p>';
370 daniel-mar 406
 
362 daniel-mar 407
                if (file_exists(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html')) {
408
                        $info = file_get_contents(__DIR__ . '/info$'.OIDplus::getCurrentLang().'.html');
409
                } else {
410
                        $info = file_get_contents(__DIR__ . '/info.html');
411
                }
292 daniel-mar 412
 
362 daniel-mar 413
                // make sure the program works even if the user provided HTML is not UTF-8
414
                $info = iconv(mb_detect_encoding($info, mb_detect_order(), true), 'UTF-8//IGNORE', $info);
415
                $bom = pack('H*','EFBBBF');
416
                $info = preg_replace("/^$bom/", '', $info);
292 daniel-mar 417
 
362 daniel-mar 418
                echo $info;
419
 
353 daniel-mar 420
                if (!function_exists('curl_exec')) {
360 daniel-mar 421
                        echo '<p><font color="red">';
362 daniel-mar 422
                        echo _L('Note: The "CURL" PHP extension is not installed at your system. Please enable the PHP extension <code>php_curl</code>.').' ';
360 daniel-mar 423
                        echo _L('Therefore, you <b>cannot</b> register your OIDplus instance now.');
424
                        echo '</font></p>';
362 daniel-mar 425
                        if ($do_edits) {
426
                                OIDplus::config()->setValue('oobe_registration_done', '1');
427
                        }
353 daniel-mar 428
                        return;
429
                }
430
 
431
                $testurl = 'https://www.google.com/';
432
                $ch = curl_init();
433
                curl_setopt($ch, CURLOPT_URL, $testurl);
434
                curl_setopt($ch, CURLOPT_HEADER, TRUE);
435
                curl_setopt($ch, CURLOPT_NOBODY, TRUE);
436
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
437
                curl_exec($ch);
438
                $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
439
                curl_close($ch);
440
                if (!$httpCode) {
360 daniel-mar 441
                        echo '<p><font color="red">';
362 daniel-mar 442
                        echo _L('Note: The "CURL" PHP extension cannot access HTTPS webpages. Therefore, you cannot use this feature. Please download <a href="https://curl.haxx.se/ca/cacert.pem">cacert.pem</a>, place it somewhere and then adjust the setting <code>curl.cainfo</code> in PHP.ini.').' ';
360 daniel-mar 443
                        echo _L('Therefore, you <b>cannot</b> register your OIDplus instance now.');
444
                        echo '</font></p>';
362 daniel-mar 445
                        if ($do_edits) {
446
                                OIDplus::config()->setValue('oobe_registration_done', '1');
447
                        }
353 daniel-mar 448
                        return;
449
                }
450
 
292 daniel-mar 451
                $pki_status = OIDplus::getPkiStatus();
452
 
453
                if (!$pki_status) {
360 daniel-mar 454
                        echo '<p><font color="red">';
362 daniel-mar 455
                        echo _L('Note: Your system could not generate a private/public key pair. (OpenSSL is probably missing on your system).').' ';
360 daniel-mar 456
                        echo _L('Therefore, you <b>cannot</b> register your OIDplus instance now.');
457
                        echo '</font></p>';
362 daniel-mar 458
                        if ($do_edits) {
459
                                OIDplus::config()->setValue('oobe_registration_done', '1');
460
                        }
353 daniel-mar 461
                        return;
462
                }
292 daniel-mar 463
 
360 daniel-mar 464
                echo '<p>'._L('Privacy level').':</p><select name="reg_privacy" id="reg_privacy">';
292 daniel-mar 465
 
353 daniel-mar 466
                # ---
292 daniel-mar 467
 
353 daniel-mar 468
                echo '<option value="0"';
469
                if (isset($_REQUEST['sent'])) {
470
                        if (isset($_REQUEST['reg_privacy']) && ($_REQUEST['reg_privacy'] == 0)) echo ' selected';
471
                } else {
362 daniel-mar 472
                        if ((OIDplus::config()->getValue('reg_privacy') == 0) || !OIDplus::config()->getValue('oobe_registration_done')) {
353 daniel-mar 473
                                echo ' selected';
292 daniel-mar 474
                        } else {
353 daniel-mar 475
                                echo '';
292 daniel-mar 476
                        }
353 daniel-mar 477
                }
360 daniel-mar 478
                echo '>'._L('0 = Register to directory service and automatically publish RA/OID data at oid-info.com').'</option>';
292 daniel-mar 479
 
353 daniel-mar 480
                # ---
292 daniel-mar 481
 
353 daniel-mar 482
                echo '<option value="1"';
483
                if (isset($_REQUEST['sent'])) {
484
                        if (isset($_REQUEST['reg_privacy']) && ($_REQUEST['reg_privacy'] == 1)) echo ' selected';
485
                } else {
486
                        if ((OIDplus::config()->getValue('reg_privacy') == 1)) {
487
                                echo ' selected';
292 daniel-mar 488
                        } else {
353 daniel-mar 489
                                echo '';
292 daniel-mar 490
                        }
353 daniel-mar 491
                }
360 daniel-mar 492
                echo '>'._L('1 = Only register to directory service').'</option>';
292 daniel-mar 493
 
353 daniel-mar 494
                # ---
292 daniel-mar 495
 
353 daniel-mar 496
                echo '<option value="2"';
497
                if (isset($_REQUEST['sent'])) {
498
                        if (isset($_REQUEST['reg_privacy']) && ($_REQUEST['reg_privacy'] == 2)) echo ' selected';
499
                } else {
500
                        if ((OIDplus::config()->getValue('reg_privacy') == 2)) {
501
                                echo ' selected';
292 daniel-mar 502
                        } else {
353 daniel-mar 503
                                echo '';
292 daniel-mar 504
                        }
353 daniel-mar 505
                }
360 daniel-mar 506
                echo '>'._L('2 = Hide system').'</option>';
292 daniel-mar 507
 
353 daniel-mar 508
                # ---
292 daniel-mar 509
 
353 daniel-mar 510
                echo '</select>';
292 daniel-mar 511
 
353 daniel-mar 512
                $msg = '';
513
                if ($do_edits) {
514
                        try {
515
                                OIDplus::config()->setValue('reg_privacy', $_REQUEST['reg_privacy']);
362 daniel-mar 516
                                OIDplus::config()->setValue('oobe_registration_done', '1');
353 daniel-mar 517
                        } catch (Exception $e) {
518
                                $msg = $e->getMessage();
519
                                $errors_happened = true;
292 daniel-mar 520
                        }
353 daniel-mar 521
                }
522
                echo ' <font color="red"><b>'.$msg.'</b></font>';
292 daniel-mar 523
 
360 daniel-mar 524
                echo '<p>'._L('<i>Privacy information:</i> This setting can always be changed in the administrator login / control panel.').'<br>';
525
                echo _L('<a %1>Click here</a> for more information about privacy related topics.','href="../../../res/OIDplus/privacy_documentation.html" target="_blank"');
526
                echo '</p>';
292 daniel-mar 527
        }
528
 
366 daniel-mar 529
}