Topic: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Hey All,

I've been shopping around for a chat client and saw a really nice opensource one here:
http://x7chat.com

I was amazed that it currently supports the following PHP apps:

Invision Board 1.X
Invision Board 2.X
Mambo 4.5.X
MercuryBoard 1.1.X
PhpBB 2.0.X
PhpNuke 7.X
PostNuke 0.075
XMB 1.9
SMF 1.X
Xoops
YabbSE 1.5.X

BUT WAIT... no PunBB support?!?!   yikes

Is it possible for some mod master to create the process for integrating this cool chat client with PunBB so we can get added to that list?

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Tell me how this works wink
lib/auth/punbb.php

<?PHP
/////////////////////////////////////////////////////////////// 
//
//        X7 Chat Version 2.0.4
//        Released June 16, 2006
//        Copyright (c) 2004-2006 By the X7 Group
//        Website: http://www.x7chat.com
//
//        This program is free software.  You may
//        modify and/or redistribute it under the
//        terms of the included license as written  
//        and published by the X7 Group.
//  
//        By using this software you agree to the         
//        terms and conditions set forth in the
//        enclosed file "license.txt".  If you did
//        not recieve the file "license.txt" please
//        visit our website and obtain an official
//        copy of X7 Chat.
//
//        Removing this copyright and/or any other
//        X7 Group or X7 Chat copyright from any
//        of the files included in this distribution
//        is forbidden and doing so will terminate
//        your right to use this software.
//    
////////////////////////////////////////////////////////////////EOH

// PunBB 1.2

// This file holds data on authentication
$auth_ucookie = "X7C2U";
$auth_pcookie = "X7C2P";
$auth_register_link = "../register.php";
$auth_disable_guest = true;

// Get the PunBB Configuration File
require ("../config.php");

// Make a database connection to the PunBB database
$pun_db = new x7chat_db($db_host,$db_username,$db_password,$db_name);

// Authenticate the user against the PunBB database
if (isset($_COOKIE[$cookie_name]))
    list($cookie['user_id'], $cookie['password_hash']) = @unserialize($_COOKIE[$cookie_name]);

if ($cookie['user_id'] > 1)
{
    // Check if there's a user with the user ID and password hash from the cookie
    $result = $pun_db->DoQuery('SELECT u.id, u.username, u.password FROM '.$db_prefix.'users AS u WHERE u.id='.intval($cookie['user_id']));
    $pun_user = $pun_db->Do_Fetch_Row($result);

    if (isset($pun_user[0]) && md5($cookie_seed.$pun_user[2]) === $cookie['password_hash'])
    {
        @setcookie($auth_ucookie, $pun_user[1], time()+$x7c->settings['cookie_time'], $X7CHAT_CONFIG['COOKIE_PATH']);
        @setcookie($auth_pcookie, $cookie['password_hash'], time()+$x7c->settings['cookie_time'], $X7CHAT_CONFIG['COOKIE_PATH']);
        $_COOKIE[$auth_ucookie] = $pun_user[1];
        $_COOKIE[$auth_pcookie] = $cookie['password_hash'];
    }
}

function auth_encrypt($data)
{
    if (function_exists('sha1'))    // Only in PHP 4.3.0+
        return sha1($data);
    else if (function_exists('mhash'))    // Only if Mhash library is loaded
        return bin2hex(mhash(MHASH_SHA1, $data));
    else
        return md5($data);
}

function auth_getpass($auth_ucookie)
{
    global $pun_db, $db_prefix, $prefix, $txt, $g_default_settings, $x7c, $db;
    
    $query = $pun_db->DoQuery("SELECT password FROM {$db_prefix}users WHERE username='$_COOKIE[$auth_ucookie]'");
    $password = $pun_db->Do_Fetch_Row($query);
    // Check if they have an X7 Chat account
    if($password[0] != ""){    
        $query = $db->DoQuery("SELECT * FROM {$prefix}users WHERE username='$_COOKIE[$auth_ucookie]'");
        $row = $db->Do_Fetch_Row($query);
        if($row[0] == ""){
            // Create an X7 Chat account for them.
            $time = time();
            $ip = $_SERVER['REMOTE_ADDR'];
            $db->DoQuery("INSERT INTO {$prefix}users (id,username,password,status,user_group,time,settings,hideemail,ip) VALUES('0','$_COOKIE[$auth_ucookie]','$password[0]','$txt[150]','{$x7c->settings['usergroup_default']}','$time','{$g_default_settings}','0','$ip')");
        }
    }
    return $password[0];
}

function change_pass($user,$newpass)
{
    global $db_prefix, $pun_db;
    $newpass = auth_encrypt($newpass);
    $query = $pun_db->DoQuery("UPDATE {$db_prefix}users SET password='$newpass' WHERE username='$user'");
}

And in install.php
FIND

                    }elseif(eregi("http://phpnuke.org",$data)){
                        include("../config.php");
                        $def['db_name'] = $dbname;
                        $def['db_user'] = $dbuname;
                        $def['db_pass'] = $dbpass;
                        $def['db_host'] = $dbhost;
                        $def['type'] = "phpnuke";
                        $integrated = true;
                    }

AFTER, ADD

elseif(eregi("define('PUN', 1);",$data)){
                        include("../config.php");
                        $def['db_name'] = $db_name;
                        $def['db_user'] = $db_username;
                        $def['db_pass'] = $db_password;
                        $def['db_host'] = $db_host;
                        $def['type'] = "punbb";
                        $integrated = true;
                    }

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Oh, and moved to Integration

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Wow, thanks much Smartys, I'll give it a try.

So.... either:

1)  This mod / integration already existed and my searches didn't pick it up, or
2)  You're a freakin' fast coder!

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

I coded it tongue
It really wasn't hard, I used the existing stuff as a basis
It's completely untested though and I didn't look through any code other than the auth I based mine off of, so it may not work smile

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Ok, here's my update on installing X7Chat with PunBB:

The whole install went PERFECTLY... not a single hangup using smartys notes above.  Once I deleted the install files I visited the /chat/ directory:

1)  I noticed I was still asked to login:  is this correct? I thought I'd already be logged into chat if I was logged into my forum?  Maybe they are just suppose to pull from the same user DB but chat requires a second login?
2)  I tried the login info for my admin user in PunBB and received:

Fatal error: Call to a member function on a non-object in /home/mother/public_html/forum/chat/lib/auth/punbb.php on line 80
line 80 =   $query = $db->DoQuery("SELECT * FROM {$prefix}users WHERE username='$_COOKIE[$auth_ucookie]'");

3)  I used the "send password" tool on the chat login screen and it sent me a random password for my admin user (also reset the password for the same PunBB user... so that's a good sign that most things are working properly.

4)  Tried the same user and new password, but received the same error message above.

Any thoughts?   Thanks!

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Try changing

global $pun_db, $db_prefix, $prefix, $txt, $g_default_settings, $x7c;

to

global $pun_db, $db_prefix, $prefix, $txt, $g_default_settings, $x7c, $db;

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

E-Oreo wrote:

Try changing

global $pun_db, $db_prefix, $prefix, $txt, $g_default_settings, $x7c;

to

global $pun_db, $db_prefix, $prefix, $txt, $g_default_settings, $x7c, $db;

Exactly right, thanks E-Oreo.
I updated the code above to reflect the change smile

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Don't forget to post this on PunRes smile

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Err, this isn't really something for PunRes, unless I were releasing a copy of X7 Chat with my plugin for PunBB bundled with it (which I'm not tongue). This isn't a modification to PunBB, this is a modification to another program so it works with PunBB wink
And hopefully it would get included with X7 Chat at some point, making posting it anywhere else pointless wink

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Worked like a charm! 

Thanks guys!

Hey E-Oreo, I see you got my email regarding your excellent chat script and getting it to work with PunBB!   You really should add it to your list of supported apps!

BTW, Any ideas about passing along login credetials so users don't have to login twice (once to forum and once to chat)?

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

12 (edited by Smartys 2006-12-10 22:11)

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Sec, my script is supposed to be doing that but I see the bug tongue

Edit: Fixed wink

13 (edited by reviewum.com 2006-12-10 23:01)

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Smartys, am I understanding your post above correctly that you fixed somthing which will automatically login users to chat?

Let me know what to change / do and I'll change and test!

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Just replace your old lib/auth/punbb.php file with what I have in my post now: I changed one of the setcookie calls so it sets the right value wink

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Smartys, thanks for the info, but unfortunately... no dice.   I used the new code for the lib/auth/punbb.php file and it didn't work.   I then tried from another PC (wondering if it was cookie related) and it didn't work.   I then went through the install process over again (for X7) and I'm still required to login.

Any thoughts?

Thanks much!

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Only problem I can think of is if X7 Chat relies on auth_encrypt when checking the username/password cookies (which I assume is the case). In that case, I'm not sure exactly how to do it, since PunBB uses a different encryption in the database versus for the cookie. You'd be better off asking E-Oreo or someone to take a look over at X7 chat to try and figure out what's wrong with it wink

17

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

This should work fully except for one part,

<?PHP
/////////////////////////////////////////////////////////////// 
//
//        X7 Chat Version 2.0.4
//        Released June 16, 2006
//        Copyright (c) 2004-2006 By the X7 Group
//        Website: http://www.x7chat.com
//
//        This program is free software.  You may
//        modify and/or redistribute it under the
//        terms of the included license as written  
//        and published by the X7 Group.
//  
//        By using this software you agree to the         
//        terms and conditions set forth in the
//        enclosed file "license.txt".  If you did
//        not recieve the file "license.txt" please
//        visit our website and obtain an official
//        copy of X7 Chat.
//
//        Removing this copyright and/or any other
//        X7 Group or X7 Chat copyright from any
//        of the files included in this distribution
//        is forbidden and doing so will terminate
//        your right to use this software.
//    
////////////////////////////////////////////////////////////////EOH

// PunBB 1.2
// Written by Smartys, PunBB Developer
// Modified by Tim C.

// This file holds data on authentication
$auth_ucookie = "X7C2U";
$auth_pcookie = "X7C2P";
$auth_register_link = "../register.php";
$auth_disable_guest = true;

// Get the PunBB Configuration File
require ("../config.php");

// Make a database connection to the PunBB database
$pun_db = new x7chat_db($db_host,$db_username,$db_password,$db_name);

// Authenticate the user against the PunBB database
if (isset($_COOKIE[$cookie_name])){
    $_COOKIE[$cookie_name] = stripslashes(str_replace('"','"',$_COOKIE[$cookie_name]));
    list($cookie['user_id'], $cookie['password_hash']) = unserialize($_COOKIE[$cookie_name]);

if ($cookie['user_id'] > 1)
{
    // Check if there's a user with the user ID and password hash from the cookie
    $result = $pun_db->DoQuery('SELECT u.id, u.username, u.password FROM '.$db_prefix.'users AS u WHERE u.id='.intval($cookie['user_id']));
    $pun_user = $pun_db->Do_Fetch_Row($result);

    if (isset($pun_user[0])) // && md5($cookie_seed.$pun_user[2]) === $cookie['password_hash'])
    {
        @setcookie($auth_ucookie, $pun_user[1], time()+$x7c->settings['cookie_time'], $X7CHAT_CONFIG['COOKIE_PATH']);
        @setcookie($auth_pcookie, $cookie['password_hash'], time()+$x7c->settings['cookie_time'], $X7CHAT_CONFIG['COOKIE_PATH']);
        $_COOKIE[$auth_ucookie] = $pun_user[1];
        $_COOKIE[$auth_pcookie] = $cookie['password_hash'];
    }
}

}

function auth_encrypt($data)
{
    global $cookie_seed;
    if (function_exists('sha1'))    // Only in PHP 4.3.0+
        $data = sha1($data);
    else if (function_exists('mhash'))    // Only if Mhash library is loaded
        $data = bin2hex(mhash(MHASH_SHA1, $data));
    else
        $data = md5($data);
        
    if(isset($_POST['dologin']))
        return md5($cookie_seed.$data);
    else
        return $data;
    
}

function auth_getpass($auth_ucookie)
{
    global $pun_db, $db_prefix, $prefix, $txt, $g_default_settings, $x7c, $db, $cookie_seed;
    
    $query = $pun_db->DoQuery("SELECT password FROM {$db_prefix}users WHERE username='$_COOKIE[$auth_ucookie]'");
    $password = $pun_db->Do_Fetch_Row($query);
    // Check if they have an X7 Chat account
    if($password[0] != ""){    
        $query = $db->DoQuery("SELECT * FROM {$prefix}users WHERE username='$_COOKIE[$auth_ucookie]'");
        $row = $db->Do_Fetch_Row($query);
        if($row[0] == ""){
            // Create an X7 Chat account for them.
            $time = time();
            $ip = $_SERVER['REMOTE_ADDR'];
            $db->DoQuery("INSERT INTO {$prefix}users (id,username,password,status,user_group,time,settings,hideemail,ip) VALUES('0','$_COOKIE[$auth_ucookie]','$password[0]','$txt[150]','{$x7c->settings['usergroup_default']}','$time','{$g_default_settings}','0','$ip')");
        }
    }
    return md5($cookie_seed.$password[0]);
}

function change_pass($user,$newpass)
{
    global $db_prefix, $pun_db;
    unset($_POST['dologin']);
    $newpass = auth_encrypt($newpass);
    $query = $pun_db->DoQuery("UPDATE {$db_prefix}users SET password='$newpass' WHERE username='$user'");
}
?>

If you change your password using the X7 Chat user control panel your session will be reset and you will need to relogin to punbb before being able to login to X7 Chat again.

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Thanks E-Oreo smile

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Very close...

I'm using the new punbb.php file and here's what happens:  I create a new punbb user via the registration system.  Login as that new user, and browse to my chat folder.  It pulls up the login

BUT... once I'm logged in, it keeps me logged in as that user since I'm still logged in as that user via the forum cookie.

Anybody else want to test this to see if it is just my installation vs. an issue with how we're going about this process.

Thanks!

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

I'm confused, what is the behavior supposed to be?

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Sorry for the confusion... I'm trying to sort this all out myself.

Desired Behavior:
Login to forums and click on chat and automatically be logged into chat.

Current Behavior:
Login to forums and click on chat... required to then login to chat.  Fortunately once you are logged into chat  (and have told punbb to keep you logged in) it seems that your login is remembered from then on in chat.

It is the initial double login that I'd love to get resolved.

Thanks Smartys!

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Could you link me to where you have this set up currently?

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

email sent with info!

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Works perfectly for me in FF 1.5 and IE7
Try clearing your cache?

Re: X7 Chat - Already integrates with SMF, PhpBB, XMB, MercuryBoard, etc.

Well.... I'll be darned!    I guess it may have been a session issue?    I closed all my browser windows and went to my forum, logged out the current user.  Registered / logged in a new user.  Went to chat and POW.... everything worked perfectly!

Thanks Smartys!    Now I just need to find ways to display either the number of users in chat, or maybe even the userID's in chat!

Rob Ludlow 
www.Nifty-Stuff.com - Repository of all Stuff Nifty!
www.reviewum.com - Professor Ratings + Teacher Reviews