forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
executable file
·69 lines (52 loc) · 2.03 KB
/
lib.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
<?php // $Id$
// Logs into Hive from HarvestRoad and stores session ID in Moodle session
// Martin Dougiamas, Moodle
//
// Example CFG variables to make this work:
// $CFG->sso = 'hive';
// $CFG->hiveprot = 'http';
// $CFG->hiveport = '80';
// $CFG->hivehost = 'turkey.harvestroad.com.au';
// $CFG->hivepath = '/cgi-bin/hive/hivedb.cgi';
// $CFG->hivecbid = '28';
function sso_user_login($username, $password) {
global $CFG, $SESSION;
include($CFG->libdir.'/snoopy/Snoopy.class.inc');
if (empty($CFG->hivehost)) {
return false; // Hive config variables not configured yet
}
/// Set up Snoopy
$snoopy = new Snoopy;
$submit_url = $CFG->hiveprot .'://'. $CFG->hivehost .':'. $CFG->hiveport .''. $CFG->hivepath ;
$submit_vars['HIVE_UNAME'] = $username;
$submit_vars['HIVE_UPASS'] = $password;
$submit_vars['HIVE_ENDUSER']= $username;
$submit_vars['HIVE_REQ'] = '2112';
$submit_vars['HIVE_REF'] = 'hin:hive@Moodle Login';
$submit_vars['HIVE_RET'] = 'ORG';
$submit_vars['HIVE_REM'] = '';
$submit_vars['HIVE_PROD'] = '0';
$submit_vars['HIVE_USERIP'] = getremoteaddr();
/// Ideally we use POST to call Hive with a bit more security
$snoopy->submit($submit_url,$submit_vars);
/// If there's a bug, we may need to use GET instead
/// foreach ($submit_vars as $name => $value) {
/// $params[] = "$name=".urlencode($value);
/// }
/// $submit_url .= '?'.implode('&', $params);
/// $snoopy->fetch($submit_url);
/// Extract HIVE_SESSION from headers
foreach ($snoopy->headers as $header) {
if (strpos($header, 'HIVE_SESSION=') !== false) {
$header = explode('HIVE_SESSION=', $header);
if (count($header) > 1) {
$cookie = explode(';', $header[1]);
$cookie = $cookie[0];
$SESSION->HIVE_SESSION = $cookie;
return true;
}
}
}
return false; // No cookie found
}
?>