I still cannot believe no one else has created this already, and if they have and I didn't find it sorry for the dupe... Anyway I needed to get our customers authenticated to kayako and our most common denominator is email.. they all have an email account. and there were no built in Imap loginshare modules. well I'm posting the file hack I made to the default loginshare module with pieces of code from other examples in this forum.. Hope it's helpful for Others.
Create the below file as imap.login.php into the includes/loginShare directory of your installation
Be sure to edit the includes/loginShare/loginshare.config.php file and put
Code:
define("LOGINAPI_IMAP", 240);
and
Code:
$_LOGINAPI[LOGINAPI_IMAP] = array("title" => $_SWIFT["language"]["loginapi_imap"], "include" => "imap.login.php");
in respective sections
also modify the locale/en-us/templates.php file and add
Code:
'imapserver' => 'IMAP Server Name',
'imapport' => 'Port (Default: 143)',
'imapprefix' => 'Prefix (Default: INBOX)',
somewhere in the __Lang array probably near the //loginshare comment tag but as long as it makes it into the array.
Use like any other loginshare add your imap server name and port etc in the templates section of the admin. if the imap login fails or if the user happens to not have an email account and registers to kayako it will attempt to auth via the defaut kayako DB..
Code:
<?php
/**
* Imap Login Module for Kayako 3.11.01
* By Marty Buchaus mbuchaus@asimail.com
* ASI Technologies 2008
*
**/
if (!defined("INSWIFT")) {
trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}
/**
* Initialization function. You can connect to your database etc over here.
*/
function loginShareInit(){
global $loginshare;
$loginshare->moduleloaded = true;
}
/**
* Authorize a user based on email and password
*/
function loginShareAuthorize($username, $password){
global $dbCore, $_SWIFT, $loginshare, $settings, $cookie;
$_loginshare = $settings->getSection("loginshare");
$serverinfo = sprintf("{%s:%s/service=imap/notls/novalidate-cert}%s", $_loginshare['imapserver'], $_loginshare['imapport'], $_loginshare['imapprefix']);
$conn = @imap_open($serverinfo, $username, $password, OP_HALFOPEN);
if (is_resource($conn)){
$userid = getLoginShareUser(LOGINAPI_IMAP, $username);
$regpassword = substr(buildHash(),0,8);
if (!$userid){
// Not registered, Register him
$userid = insertUser(true, $username, $regpassword, $_SWIFT["tgroup"]["regusergroupid"], LOGINAPI_IMAP, $username, '', $_SWIFT["tgroup"]["languageid"], 0, false, 1, true);
}
if (!$userid){
return false;
}
$_swiftuser = $loginshare->loadSWIFTUser($userid);
if (!$_swiftuser){
return false;
}
$_SWIFT["user"] = $_swiftuser;
return $_swiftuser["userid"];
} else {
//print_r($e->getmessage());
// Get the user id associated with this email
$_email = $dbCore->queryFetch("SELECT `userid` FROM `". TABLE_PREFIX ."useremails` WHERE `email` = '". $dbCore->escape($username) ."';");
if (empty($_email["userid"])){
return false;
}
$_user = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."users` WHERE `userid` = '". intval($_email["userid"]) ."';");
$loginmod = false;
$_cookieset = $cookie->getSCookie("loginemail");
if(!empty($_cookieset)){
$password_chk = $password ;
}else{
$password_chk = md5($password);
}
if ($_user["userpassword"] == $password_chk && $_user["enabled"] == 1 ){
// Authenticated
$_SWIFT["user"] = $_user;
return $_user["userid"];
} else {
unset($_SWIFT["user"]);
return false;
}
}
return false;
}
/**
* Return the Unique User ID of the current user
*/
function loginShareUserID()
{
global $_SWIFT;
if (empty($_SWIFT["user"]["userid"]))
{
return false;
} else {
return $_SWIFT["user"]["userid"];
}
}
/**
* Logout the current user
*/
function loginShareLogout()
{
global $session, $_SWIFT;
$session->updateSession($_SWIFT["session"]["sessionid"], 0);
return true;
}
/**
* Load the user credentials into current workspace. The following variables should be declared for proper working:
* userid - User id that is set in the "users" table
* fullname
* email - Array
* password (MD5 Hashed)
* usergroupid - If this is not set, then it will use the default registered user group for this template group
*/
function loginShareLoadUser()
{
global $dbCore, $_SWIFT, $loginshare;
if (empty($_SWIFT["session"]["typeid"]))
{
$_SWIFT["user"]["loggedin"] = false;
return false;
}
$_user = $loginshare->loadSWIFTUser($_SWIFT["session"]["typeid"]);
if (!$_user)
{
$_SWIFT["user"]["loggedin"] = false;
return false;
}
$_SWIFT["user"] = $_user;
return true;
}
/**
* Renders the Login Share Form
*/
function renderLoginShareForm()
{
global $_SWIFT;
$forms = array();
$forms[0]["title"] = $_SWIFT["language"]["imapserver"];
$forms[0]["name"] = "imapserver";
$forms[1]["title"] = $_SWIFT["language"]["imapport"];
$forms[1]["name"] = "imapport";
$forms[2]["title"] = $_SWIFT["language"]["imapprefix"];
$forms[2]["name"] = "imapprefix";
return $forms;
}
?>