forked from lushonline/moodle2-skillsoft-activity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
olsadiag.php
373 lines (339 loc) · 12.5 KB
/
olsadiag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?php
/*
* @package mod-skillsoft
* @author $Author$
* @version SVN: $Header$
* @copyright 2009-2014 Martin Holden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
require_once($CFG->dirroot.'/mod/skillsoft/locallib.php');
require_once($CFG->dirroot.'/mod/skillsoft/olsalib.php');
global $CFG;
$url = new moodle_url('/mod/skillsoft/olsadiag.php');
//$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_SYSTEM::instance();
require_login();
require_capability('moodle/site:config', $context);
//Display the page header
$pagetitle = 'OLSA Diagnostics';
$PAGE->set_context($context);
$PAGE->set_url($url);
$PAGE->set_title($pagetitle);
$PAGE->set_heading($pagetitle);
$PAGE->navbar->add($pagetitle);
echo $OUTPUT->header();
echo $OUTPUT->heading($pagetitle);
//Report all PHP errors
error_reporting(E_ALL);
$br = '<br/>';
$pass ='<font style="color: #008000; font-weight: bold;">Test PASSED<br />';
$fail ='<font style="color: #800000; font-weight: bold;">Test FAILED<br />';
$fontend ='</font>';
$continue = true;
$currenttest = 1;
function testheader($testnumber, $message) {
return sprintf('<h2>Test %s : %s</h2>',$testnumber,$message);
}
/* Returns the DateTime from the HTTP Header
*
*/
function getservertime() {
global $CFG;
$location = $CFG->skillsoft_olsaendpoint;
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
// curl_setopt($ch, CURLOPT_HTTPGET, true); //this is needed to fix the issue
//Force CURL to use TLSv1 or later as SSLv3 deprecated on Skillsoft servers
//Bug Fix - http://code.google.com/p/moodle2-skillsoft-activity/issues/detail?id=17
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
if (!empty($CFG->proxyhost)) {
// SOCKS supported in PHP5 only
if (!empty($CFG->proxytype) and ($CFG->proxytype == 'SOCKS5')) {
if (defined('CURLPROXY_SOCKS5')) {
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
} else {
curl_close($ch);
debugging("SOCKS5 proxy is not supported in PHP4.", DEBUG_ALL);
return false;
}
}
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
if (empty($CFG->proxyport)) {
curl_setopt($ch, CURLOPT_PROXY, $CFG->proxyhost);
} else {
curl_setopt($ch, CURLOPT_PROXY, $CFG->proxyhost.':'.$CFG->proxyport);
}
if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $CFG->proxyuser.':'.$CFG->proxypassword);
if (defined('CURLOPT_PROXYAUTH')) {
// any proxy authentication if PHP 5.1
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
}
}
}
$response = curl_exec($ch);
curl_close($ch);
/* get the status code from HTTP headers */
if(preg_match('/Date: (.*)\r/', $response, $matches)){
$result = new stdClass();
$result->serverdatetime = time();
$result->olsadatetime=strtotime( $matches[1] );
$result->diff = $result->olsadatetime - $result->serverdatetime;
//If diff > than limit then too slow
$result->limit = 60;
$result->isfast = $result->serverdatetime > $result->olsadatetime;
$result->isslow = $result->diff > $result->limit;
return $result;
} else {
return false;
}
}
echo $OUTPUT->box('This page will perform some basic tests to confirm Moodle Module is able to access SkillSoft OLSA Servers', 'generalbox boxaligncenter boxwidthwide', 'summary');
if (!empty($CFG->proxyhost)) {
$html = '';
$html .= 'Moodle is configured to connect to the internet using the following proxy server details.';
$html .= $br;
$html .='Proxy Host: '.$CFG->proxyhost;
$html .= $br;
$html .= 'Proxy Port: '.$CFG->proxyport;
$html .= $br;
if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
$html .= 'Proxy Authentication: true';
$html .= $br;
}
echo $OUTPUT->box('<h2>'.'Moodle Proxy Configuration Details'.'</h2>'.$html, 'generalbox boxaligncenter boxwidthwide', 'summary');
}
if ($continue) {
$html = '';
if (!extension_loaded('soap')) {
$continue = false;
$html .= $fail;
$html .= 'SOAP Extension is not enabled in PHP.INI. To enable please see <a target="_blank" href="http://www.php.net/manual/en/book.soap.php">http://www.php.net/manual/en/book.soap.php</a>';
$html .= $br;
$html .= 'DIAGNOSTICS HALTED';
$html .= $br;
$html .= $fontend;
} else {
$html .= $pass;
$html .= 'SOAP Extension is loaded.';
$html .= $br;
$html .= $fontend;
}
echo $OUTPUT->box(testheader($currenttest,'Checking SOAP Extension is loaded').$html, 'generalbox boxaligncenter boxwidthwide', 'summary');
}
$currenttest++;
if ($continue) {
$html = '';
if (!extension_loaded('curl')) {
$continue = false;
$html .= $fail;
$html .= 'cURL Extension is not enabled in PHP.INI. To enable please see <a target="_blank" href="http://www.php.net/manual/en/book.curl.php">http://www.php.net/manual/en/book.curl.php</a>';
$html .= $br;
$html .= 'DIAGNOSTICS HALTED';
$html .= $br;
$html .= $fontend;
} else {
$html .= $pass;
$html .= 'cURL Extension is loaded.';
$html .= $br;
$html .= $fontend;
}
echo $OUTPUT->box(testheader($currenttest,'Checking cURL Extension is loaded').$html, 'generalbox boxaligncenter boxwidthwide', 'summary');
}
$currenttest++;
if ($continue) {
$html = '';
if (!isolsaconfigurationset()) {
$continue = false;
$html .= $fail;
$html .= 'OLSA Settings are Not Configured. Please ensure you enter the OLSA settings in the module configuration settings';
$html .= $br;
$html .= 'DIAGNOSTICS HALTED';
$html .= $br;
$html .= $fontend;
} else {
$html .= $pass;
$html .= 'OLSA Settings Configured.';
$html .= $br;
$html .= $fontend;
//Set local OLSA Variables used for subsequent tests
$endpoint = $CFG->skillsoft_olsaendpoint;
$customerId = $CFG->skillsoft_olsacustomerid;
$sharedsecret = $CFG->skillsoft_olsasharedsecret;
}
echo $OUTPUT->box(testheader($currenttest,'Checking OLSA Settings are configured').$html, 'generalbox boxaligncenter boxwidthwide', 'summary');
}
$currenttest++;
if ($continue) {
$html = '';
if ($content = download_file_content($endpoint.'?WSDL',null,null,true,300,20,true)) {
//Check for HTTP 200 response
if ($content->status != 200) {
$continue = false;
$html .= $fail;
$html .= 'OLSA WSDL Can Not Be Accessed';
$html .= $br;
$html .= 'Current Value: <a target="_blank" href ="'.$endpoint.'?WSDL">'.$endpoint.'</a>';
$html .= $br;
if ($content->headers == false) {
if (!extension_loaded('openssl') && stripos($endpoint, 'https') === 0) {
$html .= 'OLSA EndPoint uses SSL';
$html .= $br;
$html .= 'OPENSSL Extension is not enabled in PHP.INI. To enable please see <a target="_blank" href="http://uk.php.net/manual/en/book.openssl.php">http://uk.php.net/manual/en/book.openssl.php</a>';
$html .= $br;
} else {
$html .= 'No Headers Returned, this typically indicates a networking or DNS resolution issue. Please confirm connectivity and the correct URL is specified.';
$html .= $br;
$html .= 'Error Message returned by request ='.$content->error;
$html .= $br;
}
} else {
$html .= 'Please ensure you entered the correct URL';
$html .= $br;
$html .= $br;
$html .= 'Headers Returned';
$html .= $br;
foreach ($http_headers as $header) {
$html .= ' '.$header;
$html .= $br;
}
}
$html .= 'DIAGNOSTICS HALTED';
$html .= $br;
$html .= $fontend;
$continue = false;
} else {
$html .= $pass;
$html .= 'OLSA WSDL Can Be Opened.';
$html .= $br;
$html .= $fontend;
}
}
echo $OUTPUT->box(testheader($currenttest,'Is OLSA EndPoint Accessible').$html, 'generalbox boxaligncenter boxwidthwide', 'summary');
}
$currenttest++;
if ($continue) {
$html = '';
if (!$result = getservertime()) {
$continue = false;
$html .= $fail;
$html .= 'Unable to retrieve OLSA server time.';
$html .= $br;
$html .= 'DIAGNOSTICS HALTED';
$html .= $br;
$html .= $fontend;
} else {
//Now compare with current time.
//Is it faster
if ($result->isfast && $result->diff > 1) {
$continue = false;
$html .= $fail;
$html .= 'Moodle Server Time is faster than OLSA Server. The OLSA Authentication Process will fail';
$html .= $br;
$html .= 'Ensure the Moodle Server Time is synchronised to a reliable time source such as an NTP server <a target="_blank" href ="http://en.wikipedia.org/wiki/Network_Time_Protocol">http://en.wikipedia.org/wiki/Network_Time_Protocol</a>';
$html .= $br;
$html .= 'Moodle Server Time : '.gmdate('Y-m-d\TH:i:s', $result->serverdatetime).'Z';
$html .= $br;
$html .= 'OLSA Server Time : '.gmdate('Y-m-d\TH:i:s', $result->olsadatetime).'Z';
$html .= $br;
$html .= 'Time difference (OLSA - Moodle): '.$result->diff.' seconds';
$html .= $br;
$html .= 'DIAGNOSTICS HALTED';
$html .= $br;
$html .= $fontend;
} else if ($result->isslow) {
$continue = false;
$html .= $fail;
$html .= 'Moodle Server Time is slower than OLSA Server. The OLSA Authentication Process will fail';
$html .= $br;
$html .= 'The Moodle Server Time can be no more than '.$result->limit.' seconds slower than OLSA server';
$html .= $br;
$html .= 'Ensure the Moodle Server Time is synchronised to a reliable time source such as an NTP server <a target="_blank" href ="http://en.wikipedia.org/wiki/Network_Time_Protocol">http://en.wikipedia.org/wiki/Network_Time_Protocol</a>';
$html .= $br;
$html .= 'Moodle Server Time : '.gmdate('Y-m-d\TH:i:s', $result->serverdatetime).'Z';
$html .= $br;
$html .= 'OLSA Server Time : '.gmdate('Y-m-d\TH:i:s', $result->olsadatetime).'Z';
$html .= $br;
$html .= 'Time difference (OLSA - Moodle): '.$result->diff.' seconds';
$html .= $br;
$html .= 'DIAGNOSTICS HALTED';
$html .= $br;
$html .= $fontend;
} else {
$html .= $pass;
$html .= 'Server Times are within limits';
$html .= $br;
$html .='Moodle Server Time : '.gmdate('Y-m-d\TH:i:s', $result->serverdatetime).'Z';
$html .= $br;
$html .='OLSA Server Time : '.gmdate('Y-m-d\TH:i:s', $result->olsadatetime).'Z';
$html .= $br;
$html .='Time difference (OLSA - Moodle): '.$result->diff.' seconds';
$html .= $br;
$html .= $fontend;
}
}
echo $OUTPUT->box(testheader($currenttest,'Check Time Synchronisation').$html, 'generalbox boxaligncenter boxwidthwide', 'summary');
}
$currenttest++;
if ($continue) {
$html = '';
//Specify the SOAP Client Options
$options = array(
"trace" => 1,
"exceptions" => true,
"soap_version" => SOAP_1_2,
"cache_wsdl" => WSDL_CACHE_BOTH,
"encoding"=> "UTF-8"
);
try {
//Create a new instance of the OLSA Soap Client
$client = new olsa_soapclient($endpoint.'?WSDL',$options);
//Create the USERNAMETOKEN
$client->__setUsernameToken($customerId,$sharedsecret);
$html .= $pass;
$html .= 'OLSA SOAP Client Created';
$html .= $br;
$html .= $fontend;
} catch (Exception $e) {
$continue = false;
$html .= $fail;
$html .= 'Exception while creating OLSA SOAP Client';
$html .= $br;
$html .= 'Exception Details';
$html .= $br;
$html .= $e->getMessage();
$html .= $br;
$html .= 'DIAGNOSTICS HALTED';
$html .= $fontend;
}
echo $OUTPUT->box(testheader($currenttest,'Create OLSA SOAP Client').$html, 'generalbox boxaligncenter boxwidthwide', 'summary');
}
$currenttest++;
if ($continue) {
$html = '';
$pollresponse = UTIL_PollForReport('0');
if ($pollresponse->errormessage == get_string('skillsoft_olsassoapauthentication','skillsoft')) {
$continue = false;
$html .= $fail;
$html .= 'OLSA Credentials are incorrect, or Moodle Server time is incorrect. Please ensure you entered the correct values.';
$html .= $br;
$html .= 'DIAGNOSTICS HALTED';
$html .= $br;
$html .= $fontend;
} else {
$html .= $pass;
$html .= 'OLSA Credentials are correct.';
$html .= $br;
$html .= $fontend;
//Set local OLSA Variables used for subsequent tests
$endpoint = $CFG->skillsoft_olsaendpoint;
$customerId = $CFG->skillsoft_olsacustomerid;
$sharedsecret = $CFG->skillsoft_olsasharedsecret;
}
echo $OUTPUT->box(testheader($currenttest,'Check OLSA Authentication').$html, 'generalbox boxaligncenter boxwidthwide', 'summary');
}
echo $OUTPUT->footer();