1
طلبات تصميم "مودات/ إضافات" جديدة / رد: ربط Kleeja مع smf
« في: 16 , مارس, 2012 - 02:52:44 مسائاً »شفرة: [اختيار]
<?php
/**
*
* @package auth
* @version $Id: smf.php 1 2012-03-16 12:30:04 Z SAFAD $
* @copyright (c) 2012 smfarabic.com
* @license ./docs/license.txt
*
*/
//no for directly open
if (!defined('IN_COMMON'))
{
exit();
}
//
//Path of config file in SMF
//
if(!defined('SCRIPT_CONFIG_PATH'))
{
define('SCRIPT_CONFIG_PATH', '/Settings.php');
}
function kleeja_auth_login ($name, $pass, $hashed = false, $expire, $loginadm = false, $return_name = false)
{
global $lang, $config, $usrcp, $userinfo;
global $script_path, $script_encoding, $script_srv, $script_db, $script_user, $script_pass, $script_prefix;
//check for last slash /
if(isset($script_path))
{
if(isset($script_path[strlen($script_path)]) && $script_path[strlen($script_path)] == '/')
{
$script_path = substr($script_path, 0, strlen($script_path));
}
//get some useful data from phbb config file
if(file_exists(PATH . $script_path . SCRIPT_CONFIG_PATH))
{
include (PATH . $script_path . SCRIPT_CONFIG_PATH);
$forum_srv = $db_server;
$forum_db = $db_name;
$forum_user = $db_user;
$forum_pass = $db_passwd;
$forum_prefix = $db_prefix;
if(empty($dbhost))
{
$forum_srv = 'localhost';
}
if(!empty($dbport))
{
$forum_srv .= ':' . $dbport;
}
}
else
{
big_error('Forum path is not correct', sprintf($lang['SCRIPT_AUTH_PATH_WRONG'], 'SMF'));
}
}
else
{
$forum_srv = $script_srv;
$forum_db = $script_db;
$forum_user = $script_user;
$forum_pass = $script_pass;
$forum_prefix = $script_prefix;
}
//if no variables of db
if(empty($forum_srv) || empty($forum_user) || empty($forum_db))
{
return;
}
//conecting ...
$SQLBB = new SSQL($forum_srv, $forum_user, $forum_pass, $forum_db, true);
$SQLBB->set_names('utf8');
unset($forum_pass); // We do not need this any longer
$row_leve = 'user_type';
$admin_level = 1;
$query2 = array(
'SELECT' => '*',
'FROM' => "`{$forum_prefix}members`",
);
$query2['WHERE'] = $hashed ? "id_member=" . intval($name) . " AND passwd='" . sha1(strtolower($name) . $pass) . "' " : "member_name='" . $SQLBB->real_escape($name) . "'";
if($return_name)
{
$query2['SELECT'] = "member_name";
$query2['WHERE'] = "id_member=" . intval($name);
}
$query = '';
if(!$hashed)
{
$result2 = $SQLBB->build($query2);
while($row=$SQLBB->fetch_array($result2))
{
$SQLBB->freeresult($result2);
if($return_name)
{
return $row['member_name'];
}
else
{
if(sha1(strtolower($name) . $pass))
{
$query = $query2;
}
}
}
}
else
{
$query = $query2;
}
if(empty($query))
{
$SQLBB->close();
return false;
}
($hook = kleeja_run_hook('qr_select_usrdata_smf_usr_class')) ? eval($hook) : null; //run hook
$result = $SQLBB->build($query);
//check if not banned
if ($SQLBB->num_rows($result) != 0)
{
while($row=$SQLBB->fetch_array($result))
{
if($SQLBB->num_rows($SQLBB->query("SELECT * FROM `{$forum_prefix}ban_items` WHERE id_member=" . intval($row['id_member']))) == 0)
{
if(!$loginadm)
{
define('USER_ID', $row['id_member']);
define('USER_NAME', $row['member_name']);
define('USER_MAIL',$row['email_address']);
define('USER_ADMIN',($row['id_group'] == $admin_level) ? 1 : 0);
}
$userinfo = $row;
$user_y = kleeja_base64_encode(serialize(array('id'=>$row['id_member'], 'name'=>$row['member_name'], 'mail'=>$row['email_address'], 'last_visit'=>time())));
if(!$hashed && !$loginadm)
{
$usrcp->kleeja_set_cookie('ulogu', $usrcp->en_de_crypt($row['id_member'] . '|' . $row['passwd'] . '|' . $expire . '|' . sha1(md5($config['h_key'] . $row['passwd']) . $expire) . '|' . (defined('USER_ADMIN') ? '1': '0') . '|' . $user_y), $expire);
}
($hook = kleeja_run_hook('qr_while_usrdata_smf_usr_class')) ? eval($hook) : null; //run hook
}
else
{
//he is banned from phpBB
$SQLBB->freeresult($result);
unset($pass);
$SQLBB->close();
return false;
}
}
$SQLBB->freeresult($result);
unset($pass);
$SQLBB->close();
return true;
}
else
{
$SQLBB->freeresult($result);
$SQLBB->close();
return false;
}
//dont know why they come here !
return false;
}
function kleeja_auth_username ($user_id)
{
return kleeja_auth_login ($user_id, false, false, 0, false, true);
}
doesn't work properly but it is for a startthis auth integration system is the worst i've ever used in my entire life
EDIT :
here is another code but the results are the same :
شفرة: [اختيار]
<?php
/**
*
* @package auth
* @version $Id: smf.php 1 2012-03-16 12:30:04 Z SAFAD $
* @copyright (c) 2012 smfarabic.com
* @license ./docs/license.txt
*
*/
//no for directly open
if (!defined('IN_COMMON'))
{
exit();
}
//
//Path of config file in SMF
//
if(!defined('SCRIPT_CONFIG_PATH'))
{
define('SCRIPT_CONFIG_PATH', '/Settings.php');
}
function kleeja_auth_login ($name, $pass, $hashed = false, $expire, $loginadm = false, $return_name = false)
{
global $lang, $config, $usrcp, $userinfo;
global $script_path, $script_encoding, $script_srv, $script_db, $script_user, $script_pass, $script_prefix;
if(isset($script_path))
{
//check for last slash /
if(isset($script_path[strlen($script_path)]) && $script_path[strlen($script_path)] == '/')
{
$script_path = substr($script_path, 0, strlen($script_path));
}
//get database data from mysmartbb config file
if(file_exists(PATH . $script_path . SCRIPT_CONFIG_PATH))
{
require_once (PATH . $script_path . SCRIPT_CONFIG_PATH);
$forum_srv = $db_server;
$forum_db = $db_name;
$forum_user = $db_user;
$forum_pass = $db_passwd;
$forum_prefix = $db_prefix;
}
else
{
big_error('Forum path is not correct', sprintf($lang['SCRIPT_AUTH_PATH_WRONG'], 'SMF'));
}
}
else
{
$forum_srv = $script_srv;
$forum_db = $script_db;
$forum_user = $script_user;
$forum_pass = $script_pass;
$forum_prefix = $script_prefix;
}
if(empty($forum_srv) || empty($forum_user) || empty($forum_db))
{
return;
}
$SQLMS = new SSQL($forum_srv, $forum_user, $forum_pass, $forum_db, true);
$SQLMS->set_names('utf8');
$pass = $usrcp->kleeja_utf8($pass, false);
$name = $usrcp->kleeja_utf8($name, false);
$query = array(
'SELECT' => '*',
'FROM' => "`{$forum_prefix}members`",
);
$query['WHERE'] = $hashed ? "id_member=" . intval($name) . " AND passwd='" . sha1(strtolower($name) . $pass) . "'" : "member_name='" . $SQLMS->real_escape($name) . "' AND passwd='" . sha1(strtolower($name) . $pass) . "'";
//if return only name let's ignore the obove
if($return_name)
{
$query_salt['SELECT'] = "member_name";
$query_salt['WHERE'] = "id_member=" . intval($name);
}
($hook = kleeja_run_hook('qr_select_usrdata_smf_usr_class')) ? eval($hook) : null; //run hook
$result = $SQLMS->build($query);
if ($SQLMS->num_rows($result) != 0)
{
while($row=$SQLMS->fetch_array($result))
{
if($return_name)
{
return $row['member_name'];
}
if(!$loginadm)
{
define('USER_ID',$row['id_member']);
define('USER_NAME', $usrcp->kleeja_utf8($row['member_name']));
define('USER_MAIL',$row['email_address']);
define('USER_ADMIN',($row['id_group'] == 1) ? 1 : 0);
}
$userinfo = $row;
$user_y = kleeja_base64_encode(serialize(array('id'=>$row['id_member'], 'name'=>$usrcp->kleeja_utf8($row['membe_rname']), 'mail'=>$row['email_address'], 'last_visit'=>time())));
if(!$hashed)
{
$hash_key_expire = sha1(md5($config['h_key'] . $row['passwd']) . $expire);
if(!$loginadm)
{
$usrcp->kleeja_set_cookie('ulogu', $usrcp->en_de_crypt($row['id_member'] . '|' . $row['passwd'] . '|' . $expire . '|' . $hash_key_expire . '|' . $row['id_group'] . '|' . $user_y), $expire);
}
}
($hook = kleeja_run_hook('qr_while_usrdata_smfc_usr_class')) ? eval($hook) : null; //run hook
}
$SQLMS->freeresult($result);
unset($pass);
$SQLMS->close();
return true;
}
else
{
$SQLMS->close();
return false;
}
}
function kleeja_auth_username ($user_id)
{
return kleeja_auth_login ($user_id, false, false, 0, false, true);
}
kleeja authentication system is bugged, you should report itand to prove that it is bugged and not my lame coding, try linking it with mysmartbb
it will output a php error claiming that set_names function doesn't exist (class not initiated properly)
nothing for us to do here, you better check with saanina or tareq or someone in the kleeja dev team
take care