ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilNICKeyRegisteredObjective.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
8{
9 const MAX_REDIRECTS = 5;
10 const SOCKET_TIMEOUT = 5;
11 const ILIAS_NIC_SERVER = "https://nic.ilias.de/index.php";
12
13 public function getHash() : string
14 {
15 return hash("sha256", self::class);
16 }
17
18 public function getLabel() : string
19 {
20 return "The NIC key is registered at the ILIAS Open Source society";
21 }
22
23 public function isNotable() : bool
24 {
25 return true;
26 }
27
28 public function getPreconditions(Setup\Environment $environment) : array
29 {
30 $http_config = $environment->getConfigFor("http");
31 return [
32 new \ilNICKeyStoredObjective($this->config),
33 new \ilSettingsFactoryExistsObjective(),
34 new \ilHttpConfigStoredObjective($http_config)
35 ];
36 }
37
38 public function achieve(Setup\Environment $environment) : Setup\Environment
39 {
40 $factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY);
41 $settings = $factory->settingsFor("common");
42 $systemfolder_config = $environment->getConfigFor("systemfolder");
43 $http_config = $environment->getConfigFor("http");
44
47 "CURL extension is required to register NIC."
48 );
49 }
50
51 //ATTENTION: This makes ilProxySettings work. It uses global ilSetting...
52 $old_settings = $GLOBALS["ilSetting"] ?? null;
53 $GLOBALS["ilSetting"] = $settings;
54
55 $url = $this->getURLStringForNIC($settings, $systemfolder_config, $http_config);
56 $req = $this->getCurlConnection($url);
57 $response = $req->exec();
58 $req->parseResponse($response);
59
60 if ($req->getInfo()["http_code"] != "200") {
61 $settings->set("nic_enabled", "-1");
63 "Could not connect to NIC server at \"" . self::ILIAS_NIC_SERVER . "\""
64 );
65 }
66
67 $status = explode("\n", $req->getResponseBody());
68 $settings->set("nic_enabled", "1");
69 $settings->set("inst_id", $status[2]);
70
71 $GLOBALS["ilSetting"] = $old_settings;
72
73 return $environment;
74 }
75
76 protected function getURLStringForNIC($settings, \ilSystemFolderSetupConfig $systemfolder_config, \ilHttpSetupConfig $http_config) : string
77 {
78 $inst_id = $settings->get("inst_id", 0);
79 $http_path = $http_config->getHttpPath();
80 $host_name = parse_url($http_path)["host"];
81
82 $url = self::ILIAS_NIC_SERVER .
83 "?cmd=getid" .
84 "&inst_id=" . rawurlencode($inst_id) .
85 "&hostname=" . rawurlencode($host_name) .
86 "&inst_name=" . rawurlencode($systemfolder_config->getClientName()) .
87 "&inst_info=" . rawurlencode($systemfolder_config->getClientDescription()) .
88 "&http_path=" . rawurlencode($http_path) .
89 "&contact_firstname=" . rawurlencode($systemfolder_config->getContactFirstname()) .
90 "&contact_lastname=" . rawurlencode($systemfolder_config->getContactLastname()) .
91 "&contact_email=" . rawurlencode($systemfolder_config->getContactEMail()) .
92 "&nic_key=" . rawurlencode($settings->get("nic_key"));
93
94 return $url;
95 }
96
97 protected function getCurlConnection(string $url)
98 {
99 $req = new \ilCurlConnection($url);
100 $req->init();
101
102 $req->setOpt(CURLOPT_HEADER, 1);
103 $req->setOpt(CURLOPT_RETURNTRANSFER, 1);
104 $req->setOpt(CURLOPT_CONNECTTIMEOUT, self::SOCKET_TIMEOUT);
105 $req->setOpt(CURLOPT_MAXREDIRS, self::MAX_REDIRECTS);
106
107 return $req;
108 }
109}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
Signals that some goal won't be achievable by actions of the system ever.
static _isCurlExtensionLoaded()
Check if curl extension is loaded.
getPreconditions(Setup\Environment $environment)
achieve(Setup\Environment $environment)
getURLStringForNIC($settings, \ilSystemFolderSetupConfig $systemfolder_config, \ilHttpSetupConfig $http_config)
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
$factory
Definition: metadata.php:58
$url
$response