[imp] re: custom login
Derek Martin
derek at younet.okstate.edu
Tue Jan 28 10:18:58 PST 2003
*This message was transferred with a trial version of CommuniGate(tm) Pro*
Wow, well, if people are interested, here is the code that we currently use.
Now, it is kinda fickle and we are trying to optimize it to facilitate
logouts as well and it is randomly failing for no apparent reason. We have
the HORDE login screen customized as the "backup" system when it does fail,
but basically, the variables are passed from our login system on another
server to HORDE and the session that is returned is set in the user's
sessions. Unfortunately, where we are having problems is in that HORDE
sends the login system a session even if it fails...kinda fun! So, if
anyone has any suggestions or would like to contribute to the development of
this particular code, please let us know - we are already using this in a
production environment.
Here is the code for the login part - other stuff like handling the
variables and the form itself are in other pages which can be provided
reasonably easy...
function horde_auto_login($username, $password)
{
// Parameters on where to send the login information to through cURL.
These are here for
// easy changing.
$horde_session_name = "HORDE";
$horde_login_url = "http://pathtoyourredirect.phpfileinimp ";
$horde_referer_url = "http://servernamewherethisfilesits";
// Parameters for the HORDE/IMP Login. We will then build the POST string
// for processing by cURL.
$horde_actionID = 105;
$horde_mailbox = "INBOX";
$horde_imapuser = $username;
$horde_pass = $password;
$horde_namespace = "";
$horde_server = "emailserver";
$horde_port = 143;
$horde_protocol = "imap";
$horde_folder = "";
$horde_new_lang = "en";
$horde_maildomain = "maildomain.com";
$horde_realm = "mailrealm.com";
$post_string = 'actionID='. $horde_actionID .'&mailbox='. $horde_mailbox
.'&imapuser='. $horde_imapuser;
$post_string .= '&pass='. $horde_pass . '&namepsace='. $horde_namespace
.'&server='. $horde_server;
$post_string .= '&port='. $horde_port .'&protocol='. $horde_protocol
.'&folders='. $horde_folders;
$post_string .= '&new_lang='. $horde_new_lang . '&maildomain='.
$horde_maildomain .'&realm='. $horde_realm;
// Begin the cURL setup procedure
$ch = curl_init();
if (!curl_setopt($ch, CURLOPT_URL, $horde_login_url)) {
curl_close($ch);
return false;
}
if (!curl_setopt($ch, CURLOPT_VERBOSE, 1)) {
return false;
}
if (!curl_setopt($ch, CURLOPT_FAILONERROR, 0)) {
return false;
}
if (!curl_setopt($ch, CURLOPT_USERAGENT, "HORDE Auto-Login")) {
return false;
}
if (!curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0)) {
return false;
}
if (!curl_setopt($ch, CURLOPT_REFERER, $horde_referer_url)) {
return false;
}
if (!curl_setopt($ch, CURLOPT_POST, 1)) {
return false;
}
if (!curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string)) {
return false;
}
if (!curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)) {
//return false;
}
if (!curl_setopt($ch, CURLOPT_HEADER, 1)) {
return false;
}
//execute all the code...
$result = curl_exec($ch);
if (!$result) {
return false;
exit;
} else {
$header_data = explode("\n", $result);
foreach ($header_data as $header_line) {
if (ereg("Set-Cookie: ". $horde_session_name ."=(.*); path=(.*);
domain=(.*)", $header_line, $pieces)) {
$session_id = $pieces[1];
$cookie_path = $pieces[2];
$cookie_domain = $pieces[3];
break;
}
}
}
if ($session_id) {
setcookie($horde_session_name, '', -10000, '/',
'alternateserverdomainexpiratory');
setcookie($horde_session_name, $session_id, 0, '/', '
alternateserverdomainexpiratory ');
log_login('horde', $username, $session_id, 's');
return true;
} else {
log_login('horde', $username, -1, 'f');
return false;
}
}
-----Original Message-----
From: Mark Merchant [mailto:mmerchant at dispatch.com]
Sent: Tuesday, January 28, 2003 8:29 AM
To: Derek Martin
Subject: RE: [imp] re: custom login
*This message was transferred with a trial version of CommuniGate(tm) Pro*
At 03:25 PM 1/27/03 -0600, you wrote:
>Yes, works pretty good...we use CURL to pass the attributes.
>If anyone is interested in code example, let me know...
yes, thanks. that is precisely what we're trying to do.
More information about the imp
mailing list