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:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
|
<?php
/***************************************************************
* Copyright notice
*
* (c) 2004 Valery Romanchev (it@webmed.ru)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Service 'vBulletin Authentification Service' for the 'vbulletin_auth' extension.
*
* @author Valery Romanchev <it@webmed.ru>
*/
// Prefix and names for the database tables
define('VB_TABLE_PREFIX', 'vbb_');
define('VB_USER_TABLE', 'user'); // The members table
define('TYPO3_FEUSER_PID', 3);
require_once(PATH_t3lib.'class.t3lib_svbase.php');
class tx_vbulletinauth_sv1 extends tx_sv_authbase {
var $prefixId = 'tx_vbulletinauth_sv1'; // Same as class name
var $scriptRelPath = 'sv1/class.tx_vbulletinauth_sv1.php'; // Path to this script relative to the extension dir.
var $extKey = 'vbulletin_auth'; // The extension key.
function getUser() {
$vbgrops_to_typo3groups=array(
// vBulletin usergroupid => TYPO3 FE usergroup uid
// Default vBulletin Usergroups
1 => '', // Unregistered / Not Logged In
2 => '1', // Users Awaiting Email Confirmation
3 => '1', // Registered Users
4 => '', // (COPPA) Users Awaiting Moderation
5 => '1,2', // Super Moderators
6 => '1,2', // Administrators
7 => '1,2', // Moderators
// Custom vBulletin groups
8 => 'banned', // Banned Users
9 => '1,2', // Registered Power Users
10 => '1,2' // Registered Users (test)
);
// only do this if there is no valid user session
if(!$this->info['userSession']['uid']) {
$user = false;
if ($this->login['uident'] AND $this->login['uname']) {
// Look up the new user by the username:
$dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
VB_TABLE_PREFIX.VB_USER_TABLE,
'username="'.$GLOBALS['TYPO3_DB']->quoteStr($this->login['uname'], VB_TABLE_PREFIX.VB_USER_TABLE).'"'
);
if ($dbres) {
$vb_user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
$GLOBALS['TYPO3_DB']->sql_free_result($dbres);
}
if(!is_array($vb_user)) {
// Failed login attempt (no username found)
if ($this->pObj->writeAttemptLog) {
$this->writelog(255,3,3,2,
"Login-attempt from %s (%s), username '%s' not found!!",
Array($this->info['REMOTE_ADDR'], $this->info['REMOTE_HOST'], $this->login['uname'])); // Logout written to log
}
} else {
if ($this->writeDevLog) t3lib_div::devLog('User found: '.$vb_user['userid'], 'vb_auth');
$groupsForTypo3='';
$vb_usergrops=array();
if ($vb_user['membergroupids'] !=''){
$vb_usergrops=explode(",", $vb_user['membergroupids']);
}
$vb_usergrops[]=$vb_user['usergroupid'];
foreach ($vb_usergrops as $vbgroup_id) {
if ($vbgrops_to_typo3groups[$vbgroup_id]=='banned'){
$groupsForTypo3='';
break;
}
elseif (isset($vbgrops_to_typo3groups[$vbgroup_id]) && $vbgrops_to_typo3groups[$vbgroup_id]!=''){
$groupsForTypo3.=$vbgrops_to_typo3groups[$vbgroup_id].',';
}
}
$groupsForTypo3arr=explode(",", $groupsForTypo3);
$groupsForTypo3arr = array_unique($groupsForTypo3arr);
$groupsForTypo3str=implode(',',$groupsForTypo3arr);
//find user in TYPO3 fe_users
$dbres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
$this->db_user['table'],
$this->db_user['userid_column'].'='.$vb_user['userid']
);
if ($dbres) {
$user = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbres);
$GLOBALS['TYPO3_DB']->sql_free_result($dbres);
}
$Fields = array(
$this->db_user['username_column'] => $vb_user['username'],
//$this->db_user['userident_column'] => $vb_user['password'],
'pid' => TYPO3_FEUSER_PID,
'usergroup' => $groupsForTypo3str
);
if(!is_array($user)) {
// no fe_user, we must add it
$Fields[$this->db_user['userid_column']] = $vb_user['userid'];
$GLOBALS['TYPO3_DB']->exec_INSERTquery($this->db_user['table'], $Fields);
}
else{
$GLOBALS['TYPO3_DB']->exec_UPDATEquery(
$this->db_user['table'],
$this->db_user['userid_column'].'='.$vb_user['userid'],
$Fields);
}
$user[$this->db_user['userid_column']]=$vb_user['userid'];
$user=array_merge($user,$vb_user);
}
}
}
return $user;
}
/**
* Authenticate a user
*
* @param array Data of user.
* @param array Information array. Holds submitted form data etc.
* @param string subtype of the service which is used to call this service.
* @return int
*/
function authUser($user) {
t3lib_div::devLog('user uid authuser!!! '.$user['uid'].' '.$user['username'].' '.$user['usergroupid'], 'authUser', 1);
$OK = 100;
if ($this->login['uident'] && $this->login['uname']) {
$OK = false;
t3lib_div::devLog('before sql'.$this->login['uident'].' '.$this->login['uname'], 'authUser', 1 );
if(is_array($user)){
if ($user['password'] == md5(md5($this->login['uident']).$user['salt'])) {
$OK=200;
}
}
if($OK!=200) {
// Failed login attempt (wrong password) - write that to the log!
if ($this->writeAttemptLog) {
$this->writelog(255,3,3,1,
"Login-attempt from %s (%s), username '%s', password not accepted!",
Array($this->info['REMOTE_ADDR'], $this->info['REMOTE_HOST'], $this->login['uname']));
}
if ($this->writeDevLog) t3lib_div::devLog('Password not accepted: '.$this->login['uident'], 'vb_auth', 2);
}
}
t3lib_div::devLog('after sql, OK= '.$OK.' ', 'authUser', 1 );
return $OK;
}
}
if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/vbulletin_auth/sv1/class.tx_vbulletinauth_sv1.php"]) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/vbulletin_auth/sv1/class.tx_vbulletinauth_sv1.php"]);
}
?> |