Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / sso / hive / lib.php
blob758d603d844ce8380bc8c8c00b90cc9c087c3f24
1 <?php // $Id$
2 // Logs into Hive from HarvestRoad and stores session ID in Moodle session
3 // Martin Dougiamas, Moodle
4 //
5 // Example CFG variables to make this work:
7 // $CFG->sso = 'hive';
8 // $CFG->hiveprotocol = 'http';
9 // $CFG->hiveport = '80';
10 // $CFG->hivehost = 'turkey.harvestroad.com.au';
11 // $CFG->hivepath = '/cgi-bin/hive/hive.cgi';
12 // $CFG->hivecbid = '28';
14 function sso_user_login($username, $password) {
16 global $CFG, $SESSION;
18 include($CFG->libdir.'/snoopy/Snoopy.class.inc');
20 if (empty($CFG->hivehost)) {
21 return false; // Hive config variables not configured yet
24 /// Set up Snoopy
26 $snoopy = new Snoopy;
28 $submit_url = $CFG->hiveprotocol .'://'. $CFG->hivehost .':'. $CFG->hiveport .''. $CFG->hivepath ;
30 $submit_vars['HIVE_UNAME'] = $username;
31 $submit_vars['HIVE_UPASS'] = $password;
32 $submit_vars['HIVE_ENDUSER']= $username;
33 $submit_vars['HIVE_REQ'] = '2112';
34 $submit_vars['HIVE_REF'] = 'hin:hive@API Login 3';
35 $submit_vars['HIVE_RET'] = 'ORG';
36 $submit_vars['HIVE_REM'] = '';
37 $submit_vars['HIVE_PROD'] = '0';
38 $submit_vars['HIVE_USERIP'] = getremoteaddr();
41 /// We use POST to call Hive with a bit more security
42 $snoopy->submit($submit_url,$submit_vars);
44 /// Extract HIVE_SESSION from headers
46 foreach ($snoopy->headers as $header) {
47 if (strpos($header, 'HIVE_SESSION=') !== false) {
48 $header = explode('HIVE_SESSION=', $header);
49 if (count($header) > 1) {
50 $cookie = explode(';', $header[1]);
51 $cookie = $cookie[0];
52 $SESSION->HIVE_SESSION = $cookie;
53 return true;
58 /// Try again with the guest username and password
60 $submit_vars['HIVE_UNAME'] = $CFG->hiveusername;
61 $submit_vars['HIVE_UPASS'] = $CFG->hivepassword;
62 $submit_vars['HIVE_ENDUSER']= $CFG->hiveusername;
63 $snoopy->submit($submit_url,$submit_vars);
64 foreach ($snoopy->headers as $header) {
65 if (strpos($header, 'HIVE_SESSION=') !== false) {
66 $header = explode('HIVE_SESSION=', $header);
67 if (count($header) > 1) {
68 $cookie = explode(';', $header[1]);
69 $cookie = $cookie[0];
70 $SESSION->HIVE_SESSION = $cookie;
71 return true;
76 return false; // No cookie found