fix mysql error in auth plugins and add mybb auth

This commit is contained in:
Sebijk 2022-02-19 12:20:41 +01:00
parent 698b979173
commit 0150916ed5
11 changed files with 736 additions and 11 deletions

View file

@ -47,6 +47,21 @@ class jfChatAuthPlugin extends BMPlugin
$this->admin_page_title = 'jfChat-Auth';
}
/**
* get list of domains
*
* @return array
*/
private function _getDomains()
{
global $bm_prefs;
if(function_exists('GetDomainList'))
return GetDomainList();
else
return explode(':', $bm_prefs['domains']);
}
/**
* installation routine
*
@ -270,7 +285,7 @@ class jfChatAuthPlugin extends BMPlugin
$res->Free();
// assign
$tpl->assign('domains', explode(':', $bm_prefs['domains']));
$tpl->assign('domains', $this->_getDomains());
$tpl->assign('jfchat_prefs', $jfchat_prefs);
$tpl->assign('pageURL', $this->_adminLink());
$tpl->assign('page', $this->_templatePath('jfchatauth.plugin.prefs.tpl'));

View file

@ -131,10 +131,10 @@ class JoomlaAuthPlugin extends BMPlugin
return(false);
// connect to joomla! DB
$mysql = @mysqli_connect($joomla_prefs['mysqlHost'], $joomla_prefs['mysqlUser'], $joomla_prefs['mysqlPass'], true);
$mysql = @mysqli_connect($joomla_prefs['mysqlHost'], $joomla_prefs['mysqlUser'], $joomla_prefs['mysqlPass'], $joomla_prefs['mysqlDB']);
if($mysql)
{
if(mysqli_select_db($joomla_prefs['mysqlDB'], $mysql))
if(mysqli_select_db($mysql, $joomla_prefs['mysqlDB']))
{
$joomlaDB = new DB($mysql);

View file

@ -45,6 +45,22 @@ class Koobi7AuthPlugin extends BMPlugin
// admin pages
$this->admin_pages = true;
$this->admin_page_title = 'Koobi7-Auth';
$this->admin_page_icon = "koobi32.png";
}
/**
* get list of domains
*
* @return array
*/
private function _getDomains()
{
global $bm_prefs;
if(function_exists('GetDomainList'))
return GetDomainList();
else
return explode(':', $bm_prefs['domains']);
}
/**
@ -302,7 +318,7 @@ class Koobi7AuthPlugin extends BMPlugin
$res->Free();
// assign
$tpl->assign('domains', explode(':', $bm_prefs['domains']));
$tpl->assign('domains', $this->_getDomains());
$tpl->assign('koobi7_prefs', $koobi7_prefs);
$tpl->assign('pageURL', $this->_adminLink());
$tpl->assign('page', $this->_templatePath('koobi7auth.plugin.prefs.tpl'));

299
src/plugins/mybb.auth.php Normal file
View file

@ -0,0 +1,299 @@
<?php
/*
* MyBB auth plugin
* (c) 2022 b1gMail.eu
*
* This program 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.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/**
* MyBB auth plugin
*
*/
class MyBBAuthPlugin extends BMPlugin
{
var $_uidFormat = 'MyBB:%d';
/**
* constructor
*
* @return MyBBAuthPlugin
*/
public function __construct()
{
// plugin info
$this->type = BMPLUGIN_DEFAULT;
$this->name = 'MyBB Authentication PlugIn';
$this->author = 'b1gMail Project';
$this->version = '1.0';
// admin pages
$this->admin_pages = true;
$this->admin_page_title = 'MyBB-Auth';
$this->admin_page_icon = "mybb32.png";
}
/**
* get list of domains
*
* @return array
*/
private function _getDomains()
{
global $bm_prefs;
if(function_exists('GetDomainList'))
return GetDomainList();
else
return explode(':', $bm_prefs['domains']);
}
/**
* installation routine
*
* @return bool
*/
public function Install()
{
global $db, $bm_prefs;
// create prefs table
$db->Query('CREATE TABLE {pre}mybb_plugin_prefs(enableAuth tinyint(4) NOT NULL DEFAULT 0, mysqlHost varchar(128) NOT NULL, mysqlUser varchar(128) NOT NULL, mysqlPass varchar(128) NOT NULL, mysqlDB varchar(128) NOT NULL, mysqlPrefix varchar(128) NOT NULL, userDomain varchar(128) NOT NULL)');
// insert initial row
list($domain) = explode(':', $bm_prefs['domains']);
$db->Query('REPLACE INTO {pre}mybb_plugin_prefs(enableAuth, mysqlHost, mysqlUser, mysqlPass, mysqlDB, mysqlPrefix, userDomain) VALUES'
. '(?,?,?,?,?,?,?)',
0,
'localhost',
'MyBB-user',
'password',
'MyBB',
'mybb_',
$domain);
return(true);
}
/**
* uninstallation routine
*
* @return bool
*/
public function Uninstall()
{
global $db;
// drop prefs table
$db->Query('DROP TABLE {pre}mybb_plugin_prefs');
return(true);
}
/**
* authentication handler
*
* @param string $userName
* @param string $userDomain
* @param string $passwordMD5
* @return array
*/
public function OnAuthenticate($userName, $userDomain, $passwordMD5, $passwordPlain = '')
{
global $db, $bm_prefs;
// get config
$res = $db->Query('SELECT * FROM {pre}mybb_plugin_prefs LIMIT 1');
$mybb_prefs = $res->FetchArray();
$res->Free();
// enabled?
if($mybb_prefs['enableAuth'] != 1)
return(false);
// our domain?
if(strtolower($userDomain) != strtolower($mybb_prefs['userDomain']))
return(false);
// connect to MyBB DB
$mysql = @mysqli_connect($mybb_prefs['mysqlHost'], $mybb_prefs['mysqlUser'], $mybb_prefs['mysqlPass'], $mybb_prefs['mysqlDB']);
if($mysql)
{
if(mysqli_select_db($mysql, $mybb_prefs['mysqlDB']))
{
$MyBBDB = new DB($mysql);
// search user
$res = $MyBBDB->Query('SELECT uid,salt,password,email FROM ' . $mybb_prefs['mysqlPrefix'] . 'users WHERE username=?',
$userName);
if($res->RowCount() == 0)
return(false);
$row = $res->FetchArray(MYSQLI_ASSOC);
$res->Free();
// check password
if($row['password'] === md5(md5($row['salt']).$passwordMD5))
{
$uid = 'MyBB:' . $row['uid'];
$myUserName = sprintf('%s@%s', $userName, $userDomain);
// create user in b1gMail?
if(BMUser::GetID($myUserName) == 0)
{
PutLog(sprintf('Creating b1gMail user for MyBB user <%s> (%d)',
$userName,
$row['uid']),
PRIO_PLUGIN,
__FILE__,
__LINE__);
$bmUID = BMUser::CreateAccount($myUserName,
'',
'',
'',
'',
'',
'',
$bm_prefs['std_land'],
'',
'',
$row['email'],
'',
$passwordMD5,
array(),
true,
$uid);
}
// return
$result = array(
'uid' => $uid,
'profile' => array(
'altmail' => $row['email']
)
);
return($result);
}
else
return(false);
}
else
PutLog('Failed to select MyBB db',
PRIO_PLUGIN,
__FILE__,
__LINE__);
unset($MyBBDB);
mysqli_close($mysql);
}
else
PutLog('MySQL connection to MyBB db failed',
PRIO_PLUGIN,
__FILE__,
__LINE__);
return(false);
}
/**
* user page handler
*
*/
public function FileHandler($file, $action)
{
global $userRow;
if(!isset($userRow) || !is_array($userRow))
return(false);
if(strpos($userRow['uid'], 'MyBB:') === false || $userRow['vorname'] != '' || $userRow['nachname'] != '')
return(false);
$file = strtolower($file);
$action = strtolower($action);
if($file != 'index.php' && ($file != 'prefs.php' || $action != 'contact')
&& ($file != 'start.php' || $action != 'logout'))
{
header('Location: prefs.php?action=contact&sid=' . session_id());
exit();
}
}
/**
* admin handler
*
*/
public function AdminHandler()
{
global $tpl, $plugins, $lang_admin;
if(!isset($_REQUEST['action']))
$_REQUEST['action'] = 'prefs';
$tabs = array(
0 => array(
'title' => $lang_admin['prefs'],
'link' => $this->_adminLink() . '&',
'active' => $_REQUEST['action'] == 'prefs'
)
);
$tpl->assign('tabs', $tabs);
if($_REQUEST['action'] == 'prefs')
$this->_prefsPage();
}
/**
* admin prefs page
*
*/
private function _prefsPage()
{
global $tpl, $db, $bm_prefs;
// save?
if(isset($_REQUEST['do']) && $_REQUEST['do'] == 'save')
{
$db->Query('UPDATE {pre}mybb_plugin_prefs SET enableAuth=?,mysqlHost=?,mysqlUser=?,mysqlPass=?,mysqlDB=?,mysqlPrefix=?,userDomain=?',
isset($_REQUEST['enableAuth']) ? 1 : 0,
$_REQUEST['mysqlHost'],
$_REQUEST['mysqlUser'],
$_REQUEST['mysqlPass'],
$_REQUEST['mysqlDB'],
$_REQUEST['mysqlPrefix'],
trim($_REQUEST['userDomain']));
}
// get config
$res = $db->Query('SELECT * FROM {pre}mybb_plugin_prefs LIMIT 1');
$mybb_prefs = $res->FetchArray();
$res->Free();
// assign
$tpl->assign('domains', $this->_getDomains());
$tpl->assign('mybb_prefs', $mybb_prefs);
$tpl->assign('pageURL', $this->_adminLink());
$tpl->assign('page', $this->_templatePath('mybbauth.plugin.prefs.tpl'));
}
}
/**
* register plugin
*/
$plugins->registerPlugin('MyBBAuthPlugin');
?>

View file

@ -45,6 +45,22 @@ class phpBB3AuthPlugin extends BMPlugin
// admin pages
$this->admin_pages = true;
$this->admin_page_title = 'phpBB3-Auth';
$this->admin_page_icon = "phpbb32.png";
}
/**
* get list of domains
*
* @return array
*/
private function _getDomains()
{
global $bm_prefs;
if(function_exists('GetDomainList'))
return GetDomainList();
else
return explode(':', $bm_prefs['domains']);
}
/**
@ -270,7 +286,7 @@ class phpBB3AuthPlugin extends BMPlugin
$res->Free();
// assign
$tpl->assign('domains', explode(':', $bm_prefs['domains']));
$tpl->assign('domains', $this->_getDomains());
$tpl->assign('phpbb3_prefs', $phpbb3_prefs);
$tpl->assign('pageURL', $this->_adminLink());
$tpl->assign('page', $this->_templatePath('phpbb3auth.plugin.prefs.tpl'));

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View file

@ -0,0 +1,46 @@
<fieldset>
<legend>{lng p="prefs"}</legend>
<form action="{$pageURL}&sid={$sid}&do=save" method="post" onsubmit="spin(this)">
<table>
<tr>
<td align="left" rowspan="7" valign="top" width="40"><img src="../plugins/templates/images/mybb32.png" border="0" alt="" width="32" height="32" /></td>
<td class="td1" width="160">{lng p="enable"}?</td>
<td class="td2"><input name="enableAuth"{if $mybb_prefs.enableAuth} checked="checked"{/if} type="checkbox" /></td>
</tr>
<tr>
<td class="td1">MySQL {lng p="host"}:</td>
<td class="td2"><input type="text" name="mysqlHost" value="{text value=$mybb_prefs.mysqlHost}" size="36" /></td>
</tr>
<tr>
<td class="td1">MySQL {lng p="user"}:</td>
<td class="td2"><input type="text" name="mysqlUser" value="{text value=$mybb_prefs.mysqlUser}" size="36" /></td>
</tr>
<tr>
<td class="td1">MySQL {lng p="password"}:</td>
<td class="td2"><input type="password" name="mysqlPass" value="{text value=$mybb_prefs.mysqlPass}" size="36" /></td>
</tr>
<tr>
<td class="td1">MySQL {lng p="db"}:</td>
<td class="td2"><input type="text" name="mysqlDB" value="{text value=$mybb_prefs.mysqlDB}" size="36" /></td>
</tr>
<tr>
<td class="td1">MySQL Prefix:</td>
<td class="td2"><input type="text" name="mysqlPrefix" value="{text value=$mybb_prefs.mysqlPrefix allowEmpty=true}" size="36" /></td>
</tr>
<tr>
<td class="td1">{lng p="user"}-{lng p="domain"}:</td>
<td class="td2"><select name="userDomain">
{foreach from=$domains item=domain}
<option value="{$domain}"{if $mybb_prefs.userDomain==$domain} selected="selected"{/if}>{$domain}</option>
{/foreach}
</select></td>
</tr>
</table>
<p>
<div style="float:right;">
<input class="button" type="submit" value=" {lng p="save"} " />
</div>
</p>
</form>
</fieldset>

View file

@ -42,7 +42,23 @@ class VBulletinAuthPlugin extends BMPlugin
// admin pages
$this->admin_pages = true;
$this->admin_page_title = 'VBulletin-Auth';
$this->admin_page_title = 'vBulletin-Auth';
$this->admin_page_icon = "vbulletin32.png";
}
/**
* get list of domains
*
* @return array
*/
private function _getDomains()
{
global $bm_prefs;
if(function_exists('GetDomainList'))
return GetDomainList();
else
return explode(':', $bm_prefs['domains']);
}
/**
@ -113,10 +129,10 @@ class VBulletinAuthPlugin extends BMPlugin
return(false);
// connect to vBulletin DB
$mysql = @mysqli_connect($vb_prefs['mysqlHost'], $vb_prefs['mysqlUser'], $vb_prefs['mysqlPass'], true);
$mysql = @mysqli_connect($vb_prefs['mysqlHost'], $vb_prefs['mysqlUser'], $vb_prefs['mysqlPass'], $vb_prefs['mysqlDB']);
if($mysql)
{
if(mysqli_select_db($vb_prefs['mysqlDB'], $mysql))
if(mysqli_select_db($mysql, $vb_prefs['mysqlDB']))
{
$vbDB = new DB($mysql);
@ -268,7 +284,7 @@ class VBulletinAuthPlugin extends BMPlugin
$res->Free();
// assign
$tpl->assign('domains', explode(':', $bm_prefs['domains']));
$tpl->assign('domains', $this->_getDomains());
$tpl->assign('vb_prefs', $vb_prefs);
$tpl->assign('pageURL', $this->_adminLink());
$tpl->assign('page', $this->_templatePath('vbauth.plugin.prefs.tpl'));

317
src/plugins/wbb2.auth.php Normal file
View file

@ -0,0 +1,317 @@
<?php
/*
* b1gMail wbb2 auth plugin
* (c) 2002-2008 B1G Software and (c) 2009 IND-InterNetDienst Schlei
*
* Redistribution of this code without explicit permission
* is forbidden!
*
*/
/**
* wbb2 auth plugin
*
*/
class wbb2AuthPlugin extends BMPlugin
{
var $_uidFormat = 'wbb2:%d';
/**
* constructor
*
* @return wbb2AuthPlugin
*/
function __construct()
{
// extract version
sscanf('$Revision: 1.0 $', chr(36) . 'Revision: %d.%d ' . chr(36),
$vMajor,
$vMinor);
// plugin info
$this->name = 'wbb2 Authentication Plugin';
$this->author = 'IND-InterNetDienst Schlei';
$this->web = 'http://www.ind.de/';
$this->mail = 'b1gmail.com@ind.de';
$this->version = sprintf('%d.%d', $vMajor, $vMinor);
$this->designedfor = '7.1.0';
$this->type = BMPLUGIN_DEFAULT;
$this->update_url = 'http://my.b1gmail.com/update_service/';
// admin pages
$this->admin_pages = true;
$this->admin_page_title = 'wbb2-Auth';
}
/**
* installation routine
*
* @return bool
*/
function Install()
{
global $db, $bm_prefs;
// create prefs table
$db->Query('CREATE TABLE IF NOT EXISTS {pre}wbb2_plugin_prefs(enableAuth tinyint(4) NOT NULL DEFAULT 0, mysqlHost varchar(128) NOT NULL, mysqlUser varchar(128) NOT NULL, mysqlPass varchar(128) NOT NULL, mysqlDB varchar(128) NOT NULL, mysqlPrefix varchar(128) NOT NULL, userDomain varchar(128) NOT NULL, enableReg tinyint(4) NOT NULL DEFAULT 0)');
// insert initial row
list($domain) = explode(':', $bm_prefs['domains']);
$db->Query('REPLACE INTO {pre}wbb2_plugin_prefs(enableAuth, mysqlHost, mysqlUser, mysqlPass, mysqlDB, mysqlPrefix, userDomain, enableReg) VALUES'
. '(?,?,?,?,?,?,?,?)',
0,
'localhost',
'wbb2-user',
'password',
'wcf',
'bb1_',
$domain,
1);
return(true);
}
/**
* uninstallation routine
*
* @return bool
*/
function Uninstall()
{
global $db;
// drop prefs table
$db->Query('DROP TABLE {pre}wbb2_plugin_prefs');
return(true);
}
function BeforeDisplayTemplate($template)
{
global $db, $bm_prefs, $tpl;
// get config
$res = $db->Query('SELECT * FROM {pre}wbb2_plugin_prefs LIMIT 1');
$wbb2_prefs = $res->FetchArray();
$res->Free();
// sind wir nicht in der SignUp Page oder NeuerAlias Page?
if($tpl->_tpl_vars['page'] != 'nli/signup.tpl' && $tpl->_tpl_vars['pageContent'] != 'li/prefs.aliases.add.tpl')
return(false);
// Domainliste ggf. neu erstellen, wenn Registrierung ueber UserDomain nicht mehr gewuenscht
if($wbb2_prefs['enableReg']==0)
{
$domains = explode(':', $bm_prefs['domains']);
foreach($domains as $domain) {
if($domain != $wbb2_prefs['userDomain'])
$newDomains[] = $domain;
}
$newDomainlist = implode(':', $newDomains);
$tpl->assign('domainList', explode(':', $newDomainlist));
}
}
/**
* authentication handler
*
* @param string $userName
* @param string $userDomain
* @param string $passwordMD5
* @return array
*/
function OnAuthenticate($userName, $userDomain, $passwordMD5, $passwordPlain)
{
global $db, $bm_prefs;
// get config
$res = $db->Query('SELECT * FROM {pre}wbb2_plugin_prefs LIMIT 1');
$wbb2_prefs = $res->FetchArray();
$res->Free();
// enabled?
if($wbb2_prefs['enableAuth'] != 1)
return(false);
// our domain?
if(strtolower($userDomain) != strtolower($wbb2_prefs['userDomain']))
return(false);
// connect to wbb2 DB
$mysql = @mysqli_connect($wbb2_prefs['mysqlHost'], $wbb2_prefs['mysqlUser'], $wbb2_prefs['mysqlPass'], $wbb2_prefs['mysqlDB']);
if($mysql)
{
if(mysqli_select_db($mysql, $wbb2_prefs['mysqlDB']))
{
$wbb2DB = new DB($mysql);
// search user
$res = $wbb2DB->Query('SELECT `userID`,`password`,`sha1_password`,`email` FROM ' . $wbb2_prefs['mysqlPrefix'] . 'users WHERE `username`=? AND `activation`=1 AND `blocked`=0',
$userName);
if($res->RowCount() == 0)
return(false);
$row = $res->FetchArray(MYSQLI_ASSOC);
$res->Free();
// check password
if($row['password'] == $passwordMD5)
{
$uid = sprintf($this->_uidFormat, $row['userID']);
// Wenn Benutzername mit Leerzeichen durch . ersetzen
$userName = str_replace(" ", ".", $userName);
$myUserName = sprintf('%s@%s', $userName, $userDomain);
// create user in b1gMail?
if(BMUser::GetID($myUserName) == 0)
{
PutLog(sprintf('Creating b1gMail user for wbb2 user <%s> (%d)',
$userName,
$row['userID']),
PRIO_PLUGIN,
__FILE__,
__LINE__);
$bmUID = BMUser::CreateAccount($myUserName,
'',
'',
'',
'',
'',
'',
$bm_prefs['std_land'],
'',
'',
$row['email'],
'',
$passwordMD5,
array(),
true,
$uid);
}
// return
$result = array(
'uid' => $uid,
'profile' => array(
'altmail' => $row['email']
)
);
return($result);
}
else
return(false);
}
else
PutLog('Failed to select wbb2 db',
PRIO_PLUGIN,
__FILE__,
__LINE__);
unset($wbb2DB);
mysqli_close($mysql);
}
else
PutLog('MySQL connection to wbb2 db failed',
PRIO_PLUGIN,
__FILE__,
__LINE__);
return(false);
}
/**
* user page handler
*
*/
function FileHandler($file, $action)
{
global $userRow;
if(!isset($userRow) || !is_array($userRow))
return(false);
if(strpos($userRow['uid'], substr($this->_uidFormat, 0, strpos($this->_uidFormat, ':')+1)) === false || $userRow['vorname'] != '' || $userRow['nachname'] != '')
return(false);
$file = strtolower($file);
$action = strtolower($action);
if($file != 'index.php' && ($file != 'prefs.php' || $action != 'contact')
&& ($file != 'start.php' || $action != 'logout'))
{
header('Location: prefs.php?action=contact&sid=' . session_id());
exit();
}
}
/**
* admin handler
*
*/
function AdminHandler()
{
global $tpl, $plugins, $lang_admin;
if(!isset($_REQUEST['action']))
$_REQUEST['action'] = 'prefs';
$tabs = array(
0 => array(
'title' => $lang_admin['prefs'],
'link' => $this->_adminLink() . '&',
'active' => $_REQUEST['action'] == 'prefs'
)
);
$tpl->assign('tabs', $tabs);
if($_REQUEST['action'] == 'prefs')
$this->_prefsPage();
}
/**
* admin prefs page
*
*/
function _prefsPage()
{
global $tpl, $db, $bm_prefs;
// save?
if(isset($_REQUEST['do']) && $_REQUEST['do'] == 'save')
{
$db->Query('UPDATE {pre}wbb2_plugin_prefs SET enableAuth=?,mysqlHost=?,mysqlUser=?,mysqlPass=?,mysqlDB=?,mysqlPrefix=?,userDomain=?,enableReg=?',
isset($_REQUEST['enableAuth']) ? 1 : 0,
$_REQUEST['mysqlHost'],
$_REQUEST['mysqlUser'],
$_REQUEST['mysqlPass'],
$_REQUEST['mysqlDB'],
$_REQUEST['mysqlPrefix'],
trim($_REQUEST['userDomain']),
isset($_REQUEST['enableReg']) ? 1 : 0);
}
// get config
$res = $db->Query('SELECT * FROM {pre}wbb2_plugin_prefs LIMIT 1');
$wbb2_prefs = $res->FetchArray();
$res->Free();
// assign
$tpl->assign('domains', explode(':', $bm_prefs['domains']));
$tpl->assign('wbb2_prefs', $wbb2_prefs);
$tpl->assign('pageURL', $this->_adminLink());
$tpl->assign('page', $this->_templatePath('wbb2auth.plugin.prefs.tpl'));
}
}
/**
* register plugin
*/
$plugins->registerPlugin('wbb2AuthPlugin');
?>

View file

@ -154,10 +154,10 @@ class WBB3AuthPlugin extends BMPlugin
return(false);
// connect to wbb3 DB
$mysql = @mysqli_connect($wbb3_prefs['mysqlHost'], $wbb3_prefs['mysqlUser'], $wbb3_prefs['mysqlPass'], true);
$mysql = @mysqli_connect($wbb3_prefs['mysqlHost'], $wbb3_prefs['mysqlUser'], $wbb3_prefs['mysqlPass'], $wbb3_prefs['mysqlDB']);
if($mysql)
{
if(mysqli_select_db($wbb3_prefs['mysqlDB'], $mysql))
if(mysqli_select_db($mysql, $wbb3_prefs['mysqlDB']))
{
$wbb3DB = new DB($mysql);