ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilNICKeyRegisteredObjective Class Reference
+ Inheritance diagram for ilNICKeyRegisteredObjective:
+ Collaboration diagram for ilNICKeyRegisteredObjective:

Public Member Functions

 getHash ()
 
 getLabel ()
 
 isNotable ()
 
 getPreconditions (Setup\Environment $environment)
 
 achieve (Setup\Environment $environment)
 
 isApplicable (Setup\Environment $environment)
 
- Public Member Functions inherited from ilSetupObjective
 __construct (\ilSetupConfig $config)
 

Data Fields

const MAX_REDIRECTS = 5
 
const SOCKET_TIMEOUT = 5
 
const ILIAS_NIC_SERVER = "https://nic.ilias.de/index.php"
 

Protected Member Functions

 getRegistrationProblem (array $nic_response_parts)
 
 getURLStringForNIC ($settings, \ilSystemFolderSetupConfig $systemfolder_config, \ilHttpSetupConfig $http_config)
 
 getCurlConnection (string $url)
 

Additional Inherited Members

- Protected Attributes inherited from ilSetupObjective
 $config
 

Detailed Description

Definition at line 7 of file class.ilNICKeyRegisteredObjective.php.

Member Function Documentation

◆ achieve()

ilNICKeyRegisteredObjective::achieve ( Setup\Environment  $environment)

Definition at line 38 of file class.ilNICKeyRegisteredObjective.php.

References $factory, $GLOBALS, XapiProxy\$req, $response, $url, ilCurlConnection\_isCurlExtensionLoaded(), getCurlConnection(), getRegistrationProblem(), and getURLStringForNIC().

38  : 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 
46  throw new Setup\UnachievableException(
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");
62  throw new Setup\UnachievableException(
63  "Could not connect to NIC server at \"" . self::ILIAS_NIC_SERVER . "\""
64  );
65  }
66 
67  $status = explode("\n", $req->getResponseBody());
68 
69  $nic_id = (string) ($status[2] ?? '');
70  if ($nic_id === '') {
71  $settings->set("nic_enabled", "-1");
72  throw new Setup\UnachievableException(
73  "Did not receive valid installation id from " .
74  "NIC server (\"" . self::ILIAS_NIC_SERVER . "\") for URL: $url" .
75  $this->getRegistrationProblem($status)
76  );
77  }
78 
79  $settings->set("nic_enabled", "1");
80  $settings->set("inst_id", $status[2]);
81 
82  $GLOBALS["ilSetting"] = $old_settings;
83 
84  return $environment;
85  }
getRegistrationProblem(array $nic_response_parts)
static _isCurlExtensionLoaded()
Check if curl extension is loaded.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$url
$response
$factory
Definition: metadata.php:58
getURLStringForNIC($settings, \ilSystemFolderSetupConfig $systemfolder_config, \ilHttpSetupConfig $http_config)
+ Here is the call graph for this function:

◆ getCurlConnection()

ilNICKeyRegisteredObjective::getCurlConnection ( string  $url)
protected

Definition at line 154 of file class.ilNICKeyRegisteredObjective.php.

References XapiProxy\$req.

Referenced by achieve().

155  {
156  $req = new \ilCurlConnection($url);
157  $req->init();
158 
159  $req->setOpt(CURLOPT_HEADER, 1);
160  $req->setOpt(CURLOPT_RETURNTRANSFER, 1);
161  $req->setOpt(CURLOPT_CONNECTTIMEOUT, self::SOCKET_TIMEOUT);
162  $req->setOpt(CURLOPT_MAXREDIRS, self::MAX_REDIRECTS);
163 
164  return $req;
165  }
$url
+ Here is the caller graph for this function:

◆ getHash()

ilNICKeyRegisteredObjective::getHash ( )

Definition at line 13 of file class.ilNICKeyRegisteredObjective.php.

13  : string
14  {
15  return hash("sha256", self::class);
16  }

◆ getLabel()

ilNICKeyRegisteredObjective::getLabel ( )

Definition at line 18 of file class.ilNICKeyRegisteredObjective.php.

18  : string
19  {
20  return "The NIC key is registered at the ILIAS Open Source society";
21  }

◆ getPreconditions()

ilNICKeyRegisteredObjective::getPreconditions ( Setup\Environment  $environment)

Definition at line 28 of file class.ilNICKeyRegisteredObjective.php.

28  : 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  }

◆ getRegistrationProblem()

ilNICKeyRegisteredObjective::getRegistrationProblem ( array  $nic_response_parts)
protected

Definition at line 95 of file class.ilNICKeyRegisteredObjective.php.

References $message.

Referenced by achieve().

95  : string
96  {
97  $error_code = trim((string) ($nic_response_parts[1] ?? ''));
98  $message = 'Unknown reason';
99 
100  switch ($error_code) {
101  case 'INIC-F-01':
102  $message = "NIC server could not connect to database";
103  break;
104 
105  case 'INIC-F-04':
106  $message = "NIC server could not execute query";
107  break;
108 
109  case 'INIC-E-04':
110  $message = "The installation name was missing in request, please check your " .
111  "configuration (systemfolder.client.name)";
112  break;
113 
114  case 'INIC-E-08':
115  $message = "The http path or contact's lastname was missing in request, please check " .
116  "your configuration (http.path or systemfolder.contact.lastname)";
117  break;
118 
119  case 'INIC-E-09':
120  $message = "The contact's firstname was missing in request, please check your " .
121  "configuration (systemfolder.contact.firstname)";
122  break;
123 
124  case 'INIC-E-15':
125  $message = "The contact's email address was missing in request, please check your " .
126  "configuration (systemfolder.contact.email)";
127  break;
128  }
129 
130  return 'Reason: ' . $message;
131  }
$message
Definition: xapiexit.php:14
+ Here is the caller graph for this function:

◆ getURLStringForNIC()

ilNICKeyRegisteredObjective::getURLStringForNIC (   $settings,
\ilSystemFolderSetupConfig  $systemfolder_config,
\ilHttpSetupConfig  $http_config 
)
protected

Definition at line 133 of file class.ilNICKeyRegisteredObjective.php.

References $url, ilSystemFolderSetupConfig\getClientDescription(), ilSystemFolderSetupConfig\getClientName(), ilSystemFolderSetupConfig\getContactEMail(), ilSystemFolderSetupConfig\getContactFirstname(), ilSystemFolderSetupConfig\getContactLastname(), and ilHttpSetupConfig\getHttpPath().

Referenced by achieve().

133  : string
134  {
135  $inst_id = (string) $settings->get('inst_id', '0');
136  $http_path = $http_config->getHttpPath();
137  $host_name = parse_url($http_path)["host"];
138 
139  $url = self::ILIAS_NIC_SERVER .
140  "?cmd=getid" .
141  "&inst_id=" . rawurlencode($inst_id) .
142  "&hostname=" . rawurlencode($host_name) .
143  "&inst_name=" . rawurlencode($systemfolder_config->getClientName() ?? '') .
144  "&inst_info=" . rawurlencode($systemfolder_config->getClientDescription() ?? '') .
145  "&http_path=" . rawurlencode($http_path) .
146  "&contact_firstname=" . rawurlencode($systemfolder_config->getContactFirstname()) .
147  "&contact_lastname=" . rawurlencode($systemfolder_config->getContactLastname()) .
148  "&contact_email=" . rawurlencode($systemfolder_config->getContactEMail()) .
149  "&nic_key=" . rawurlencode($settings->get("nic_key"));
150 
151  return $url;
152  }
$url
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isApplicable()

ilNICKeyRegisteredObjective::isApplicable ( Setup\Environment  $environment)

Definition at line 90 of file class.ilNICKeyRegisteredObjective.php.

90  : bool
91  {
92  return true;
93  }

◆ isNotable()

ilNICKeyRegisteredObjective::isNotable ( )

Definition at line 23 of file class.ilNICKeyRegisteredObjective.php.

23  : bool
24  {
25  return true;
26  }

Field Documentation

◆ ILIAS_NIC_SERVER

const ilNICKeyRegisteredObjective::ILIAS_NIC_SERVER = "https://nic.ilias.de/index.php"

Definition at line 11 of file class.ilNICKeyRegisteredObjective.php.

◆ MAX_REDIRECTS

const ilNICKeyRegisteredObjective::MAX_REDIRECTS = 5

Definition at line 9 of file class.ilNICKeyRegisteredObjective.php.

◆ SOCKET_TIMEOUT

const ilNICKeyRegisteredObjective::SOCKET_TIMEOUT = 5

Definition at line 10 of file class.ilNICKeyRegisteredObjective.php.


The documentation for this class was generated from the following file: