Subversion Repositories oidplus

Rev

Rev 381 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

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