2025-06-02 10:01:12 +02:00
< ? php
/**
* Project : astat - simple site engine
* File : / modules / mybb_bridge / mybb_bridge . plugins . php
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library 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
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*
* @ link http :// www . astat . org SVN : $URL $
* @ copyright 2009 becast . at
* @ author Bernhard Jaud < bernhard at becast dot at >
* @ package astat core
* @ license http :// opensource . org / licenses / gpl - license . php GNU Public License
* @ version $Id $
*/
If ( ! defined ( " in_astat " )) {
die ( " Dieses Script kann nicht ausserhalb des Frameworks laufen! " );
}
class plugins_mybb {
private $mybb_conf = array ();
function __construct (){
$this -> mybb_conf = $this -> fetchboardconfig ();
}
function register_plugins ( & $plugin ){
$plugin -> use_hook ( 'admin_user_before_delete' , array ( $this , " delete " ));
$plugin -> use_hook ( 'login_end' , array ( $this , " login " ));
$plugin -> use_hook ( 'login_openid_end' , array ( $this , " login " ));
$plugin -> use_hook ( 'register_openid_login' , array ( $this , " login " ));
$plugin -> use_hook ( 'register_end' , array ( $this , " register " ));
$plugin -> use_hook ( 'register_openid_end' , array ( $this , " register " ));
$plugin -> use_hook ( 'logout_end' , array ( $this , " logout " ));
$plugin -> use_hook ( 'lostpass_mail_pw' , array ( $this , " lostpwd " ));
$plugin -> use_hook ( 'usercp_end' , array ( $this , " usercp " ));
$plugin -> use_hook ( 'admin_user_after_update' , array ( $this , " update " ));
$plugin -> use_hook ( 'admin_user_after_create' , array ( $this , " add " ));
}
function login ( $pdata ){
global $db , $config , $session ;
$resultf = $db -> query ( " SELECT fu.`loginkey`, fu.`uid` FROM ` " . $config [ " prefix " ] . " users` u LEFT JOIN ` " . $this -> mybb_conf [ " prefix " ] . " users` fu ON fu.`uid`=u.`fuid` WHERE u.`uid`=' " . $pdata [ " uid " ] . " ' LIMIT 1 " );
$fud = $db -> fetch_array ( $resultf ); //fear, uncertainty and doubt
if ( $pdata [ " remember " ] == " on " ){
$session -> setcookie ( $this -> mybb_conf [ " cookieprefix " ] . " mybbuser " , $fud [ 'uid' ] . " _ " . $fud [ 'loginkey' ], time () + 60 * 60 * 24 * 365 , $this -> mybb_conf [ " cookiepath " ], $this -> mybb_conf [ 'cookiedomain' ], true , true );
} else {
$session -> setcookie ( $this -> mybb_conf [ " cookieprefix " ] . " mybbuser " , $fud [ 'uid' ] . " _ " . $fud [ 'loginkey' ], 0 , $this -> mybb_conf [ " cookiepath " ], $this -> mybb_conf [ 'cookiedomain' ], true , true );
}
}
function logout ( $ldata ){
global $db , $config , $session ;
$session -> setcookie ( $this -> mybb_conf [ " cookieprefix " ] . " mybbuser " , " 0 " , time () - 3600 , $this -> mybb_conf [ " cookiepath " ], $this -> mybb_conf [ 'cookiedomain' ]);
}
function register ( $sdata ){
2025-06-05 23:04:32 +02:00
global $db , $config , $session , $functions ;
$salt = $session -> generate_Key ( 8 );
if ( $sdata [ " pwd_sha2' " ] != '' ){
$saltetpass = md5 ( md5 ( $salt ) . md5 ( $session -> generate_Key ( 15 )));
} else {
$saltetpass = md5 ( md5 ( $sdata [ " salt " ]) . $sdata [ " pwd_md5 " ]);
}
$db -> query ( " INSERT INTO ` " . $this -> mybb_conf [ " prefix " ] . " users` (`username`,`salt`,`password`,`loginkey`,`email`,`usergroup`,`birthday`,`regdate`,`regip`,`showsigs`,`showavatars`,`showquickreply`,`showredirect`,`style`,`receivepms`,`allownotices`,`pmnotice`,`pmnotify`,`birthdayprivacy`,`signature`,`buddylist`,`ignorelist`,`pmfolders`,`notepad`,`usernotes`) VALUES (' " . $sdata [ " username " ] . " ',' " . $salt . " ',' " . $saltetpass . " ',' " . $session -> generate_Key ( 50 ) . " ',' " . $sdata [ " email " ] . " ','2',' " . date ( 'j-n-Y' , $sdata [ 'birthday' ]) . " ',' " . time () . " ', " . $db -> escape_binary ( $functions -> my_inet_pton ( $session -> ip )) . " ,'1','1','1','1','3','1','1','1','1','none','','','','0** $ %% $ 1** $ %% $ 2** $ %% $ 3** $ %% $ 4**','','') " );
$lid = $db -> last_id ();
$db -> query ( " UPDATE ` " . $config [ " prefix " ] . " users` SET `fuid`=' " . $lid . " ' WHERE `uid`=' " . $sdata [ " uid " ] . " ' " );
$db -> query ( " INSERT INTO ` " . $this -> mybb_conf [ " prefix " ] . " userfields` (`ufid`, `fid1`,`fid2`, `fid3`) VALUES (' " . $lid . " ',' " . $sdata [ " from " ] . " ','', ' " . $sdata [ " gender " ] . " ') " );
2025-06-02 10:01:12 +02:00
}
function add ( $rdata ){
global $db , $config , $session , $functions ;
$salt = $session -> generate_Key ( 8 );
if ( $rdata [ " pwd_sha2' " ] != '' ){
$saltetpass = md5 ( md5 ( $salt ) . md5 ( $session -> generate_Key ( 15 )));
} else {
$saltetpass = md5 ( md5 ( $rdata [ " salt " ]) . $rdata [ " pwd_md5 " ]);
}
2025-06-05 23:04:32 +02:00
$db -> query ( " INSERT INTO ` " . $this -> mybb_conf [ " prefix " ] . " users` (`username`,`salt`,`password`,`loginkey`,`email`,`usergroup`,`regdate`,`regip`,`showsigs`,`showavatars`,`showquickreply`,`showredirect`,`style`,`receivepms`,`allownotices`,`pmnotice`,`pmnotify`,`birthdayprivacy`,`signature`,`buddylist`,`ignorelist`,`pmfolders`,`notepad`,`usernotes`) VALUES (' " . $rdata [ " name " ] . " ',' " . $salt . " ',' " . $saltetpass . " ',' " . $session -> generate_Key ( 50 ) . " ',' " . $rdata [ " email " ] . " ','2',' " . time () . " ', " . $db -> escape_binary ( $functions -> my_inet_pton ( $session -> ip )) . " ,'1','1','1','1','3','1','1','1','1','none','','','','0** $ %% $ 1** $ %% $ 2** $ %% $ 3** $ %% $ 4**','','') " );
2025-06-02 10:01:12 +02:00
$lid = $db -> last_id ();
$db -> query ( " UPDATE ` " . $config [ " prefix " ] . " users` SET `fuid`=' " . $lid . " ' WHERE `uid`=' " . $rdata [ " uid " ] . " ' " );
}
function lostpwd ( $sdata ){
global $db , $config , $session ;
$salt = $session -> generate_Key ( 8 );
$saltetpass = md5 ( md5 ( $salt ) . $sdata [ " pwd_md5 " ]);
$result = $db -> query ( " SELECT `fuid` FROM ` " . $config [ " prefix " ] . " users` WHERE `uid`=' " . $sdata [ " uid " ] . " ' LIMIT 1 " );
$u = $db -> fetch_array ( $result );
$db -> query ( " UPDATE ` " . $this -> mybb_conf [ " prefix " ] . " users` SET `salt`=' " . $salt . " ',`password`=' " . $saltetpass . " ',`loginkey`=' " . $session -> generate_Key ( 50 ) . " ' WHERE `uid`=' " . $u [ " fuid " ] . " ' " );
}
function usercp ( $rdata ){
global $db , $config , $session ;
$result = $db -> query ( " SELECT `fuid` FROM ` " . $config [ " prefix " ] . " users` WHERE `uid`=' " . $rdata [ " uid " ] . " ' LIMIT 1 " );
$u = $db -> fetch_array ( $result );
if ( $rdata [ 'pwd_sha2' ] != NULL ){
$salt = $session -> generate_Key ( 8 );
$saltetpass = md5 ( md5 ( $salt ) . $rdata [ " pwd_md5 " ]);
$pwd = " ,`password`=' " . $saltetpass . " ',`salt`=' " . $salt . " ',`loginkey`=' " . $session -> generate_Key ( 50 ) . " ' " ;
}
$db -> query ( " UPDATE ` " . $this -> mybb_conf [ " prefix " ] . " users` SET `email`=' " . $rdata [ " email " ] . " ' " . $pwd . " WHERE `uid`=' " . $u [ " fuid " ] . " ' " );
}
function update ( $rdata ){
global $db , $config , $session ;
$result = $db -> query ( " SELECT `fuid` FROM ` " . $config [ " prefix " ] . " users` WHERE `uid`=' " . $rdata [ " uid " ] . " ' LIMIT 1 " );
$u = $db -> fetch_array ( $result );
if ( $rdata [ 'password' ] != " " ){
$salt = $session -> generate_Key ( 8 );
$saltetpass = md5 ( md5 ( $salt ) . md5 ( $rdata [ " password " ]));
$pwd = " ,`password`=' " . $saltetpass . " ',`salt`=' " . $salt . " ',`loginkey`=' " . $session -> generate_Key ( 50 ) . " ' " ;
}
$db -> query ( " UPDATE ` " . $this -> mybb_conf [ " prefix " ] . " users` SET `username`=' " . $rdata [ " name " ] . " ',`email`=' " . $rdata [ " email " ] . " ' " . $pwd . " WHERE `uid`=' " . $u [ " fuid " ] . " ' " );
if ( $rdata [ 'active' ] == 2 ){
$db -> query ( " DELETE FROM ` " . $this -> mybb_conf [ " prefix " ] . " banned` WHERE `uid`=' " . $u [ " fuid " ] . " ' " );
$db -> query ( " UPDATE ` " . $this -> mybb_conf [ " prefix " ] . " users` SET `usergroup`='7' WHERE `uid`=' " . $u [ " fuid " ] . " ' " );
$db -> query ( " INSERT INTO ` " . $this -> mybb_conf [ " prefix " ] . " banned` (`uid`,`gid`,`oldgroup`,`oldadditionalgroups`,`olddisplaygroup`,`admin`,`dateline`,`bantime`,`lifted`,`reason`) VALUES (' " . $u [ " fuid " ] . " ','7','2','','0',' " . $rdata [ 'user_fid' ] . " ',' " . time () . " ','---','0','') " );
}
}
function delete ( $data ){
global $db , $config , $cache , $log ;
$fdata = $db -> query ( " SELECT * FROM ` " . $this -> mybb_conf [ " prefix " ] . " users` WHERE `uid`=' " . $data [ 'fuid' ] . " ' " );
$forumdata = $db -> fetch_array ( $fdata );
$this -> delete_query ( " userfields " , " ufid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " privatemessages " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " events " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " forumsubscriptions " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " threadsubscriptions " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " sessions " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " banned " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " threadratings " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " users " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " joinrequests " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " warnings " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " reputation " , " uid=' " . $data [ 'fuid' ] . " ' OR adduid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " awaitingactivation " , " uid=' " . $data [ 'fuid' ] . " ' " );
$this -> delete_query ( " posts " , " uid = ' " . $data [ 'fuid' ] . " ' AND visible = '-2' " );
$this -> delete_query ( " threads " , " uid = ' " . $data [ 'fuid' ] . " ' AND visible = '-2' " );
if ( $forumdata [ 'avatartype' ] == " upload " )
{
// Removes the ./ at the beginning the timestamp on the end...
@ unlink ( " /var/www/forum.archer.agency/web/htdocs/uploads/avatars/ " . substr ( $user [ 'avatar' ], 2 , - 20 ));
}
$db -> query ( " UPDATE ` " . $this -> mybb_conf [ " prefix " ] . " posts` SET `uid`=0 WHERE `uid`=' " . $data [ 'fuid' ] . " ' " );
$db -> query ( " UPDATE ` " . $this -> mybb_conf [ " prefix " ] . " forums` SET `lastposteruid`=0 WHERE `lastposteruid`=' " . $data [ 'fuid' ] . " ' " );
$db -> query ( " UPDATE ` " . $this -> mybb_conf [ " prefix " ] . " threads` SET `lastposteruid`=0 WHERE `lastposteruid`=' " . $data [ 'fuid' ] . " ' " );
}
function fetchboardconfig (){
global $db , $config , $cache , $log ;
$mybb = $cache -> read ( 'mybbconfig' );
try {
$result = $db -> query ( " SELECT `name`, `value` FROM " . $mybb [ 'prefix' ] . " settings " );
if ( ! $result ){
throw new Exception ( $db -> error ());
}
while ( $row = $db -> fetch_array ( $result )){
$boardconfig [ $row [ 'name' ]] = $row [ 'value' ];
}
$boardconfig [ 'prefix' ] = $mybb [ 'prefix' ];
return $boardconfig ;
} catch ( Exception $e ){
$log -> write ( $e , 2 , __LINE__ , __FILE__ );
return NULL ;
}
}
function delete_query ( $table , $where = " " , $limit = " " )
{
global $db , $config , $cache , $log ;
$query = " " ;
if ( ! empty ( $where ))
{
$query .= " WHERE $where " ;
}
if ( ! empty ( $limit ))
{
$query .= " LIMIT $limit " ;
}
$db -> query ( 'DELETE FROM `' . $this -> mybb_conf [ " prefix " ] . $table . '`' . $query ) or die ( $db -> error ());
}
}
?>