News:

Join the Facebook Fan Page.

Main Menu

Coppermine Integration

Started by lc62003, December 18, 2014, 09:41:44 PM

Previous topic - Next topic

lc62003

Perhaps this question would be better asked at Coppermine.  Or would it?  Since 2.1 has changed it's login hash methodology Coppermine bridging does not work naturally.  What changes would need to be made to accomplish a port?  Thanks!



Arantor

That would really depend on how the bridge works; there are methods involving the integration hooks that would work just as well regardless of version.

lc62003

Using a hook - there's an interesting thought.  I'm not sure I'm versed enough to make that happen.   :-X


Here is the bridge config file for 2.0:


<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2014 Coppermine Dev Team
  v1.0 originally written by Gregory Demar

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 3
  as published by the Free Software Foundation.

  ********************************************
  Coppermine version: 1.5.32
  $HeadURL: https://svn.code.sf.net/p/coppermine/code/trunk/cpg1.5.x/bridge/smf20.inc.php $
  $Revision: 8745 $
**********************************************/

if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');

if (isset(
$bridge_lookup)) {
    
$default_bridge_data[$bridge_lookup] = array(
        
'full_name' => 'Simple Machines (SMF) 2.x',
        
'short_name' => 'smf20',
        
'support_url' => 'http://www.simplemachines.org/',
        
'relative_path_to_config_file_default' => '../board/',
        
'relative_path_to_config_file_used' => 'lookfor,Settings.php',
        
'use_post_based_groups_default' => '0',
        
'use_post_based_groups_used' => 'radio,1,0',
    );
} else {

    
// Switch that allows overriding the bridge manager with hard-coded values
    
define('USE_BRIDGEMGR'1);

    require_once 
'bridge/udb_base.inc.php';

    class 
cpg_udb extends core_udb {

        function 
cpg_udb()
        {
            global 
$BRIDGE;

            if (!
USE_BRIDGEMGR) {
                require_once(
'../smf/Settings.php');
                
$boardurl 'http://www.mysite.com/board';
            } else {
                require_once(
$BRIDGE['relative_path_to_config_file'] . 'Settings.php');
            }

            
$this->use_post_based_groups $BRIDGE['use_post_based_groups'];
            
$this->boardurl $boardurl;
            
$this->multigroups 1;
            
$this->group_overrride 1;
            
$this->cookie_name $cookiename;

            
// Board table names
            
$this->table = array(
                
'users'    => 'members',
                
'groups'   => 'membergroups',
                
'sessions' => 'sessions'
            
);

            
// Database connection settings
            
$this->db = array(
                
'name'     => $db_name,
                
'host'     => $db_server $db_server 'localhost',
                
'user'     => $db_user,
                
'prefix'   => $db_prefix,
                
'password' => $db_passwd,
            );

            
// Derived full table names
            
if (strpos($db_prefix'.') === false) {
                
$this->usertable =     '`' $this->db['name'] . '`.' $this->db['prefix'] . $this->table['users'];
                
$this->groupstable =   '`' $this->db['name'] . '`.' $this->db['prefix'] . $this->table['groups'];
                
$this->sessionstable '`' $this->db['name'] . '`.' $this->db['prefix'] . $this->table['sessions'];
            } else {
                
$this->usertable =     $this->db['prefix'] . $this->table['users'];
                
$this->groupstable =   $this->db['prefix'] . $this->table['groups'];
                
$this->sessionstable $this->db['prefix'] . $this->table['sessions'];
            }

            
// Table field names
            
$this->field = array(
                
'username' => 'real_name'// name of 'username' field in users table
                
'user_id' => 'id_member'// name of 'id' field in users table
                
'password' => 'SHA1(CONCAT(passwd, password_salt))'// name of the password field in the users table
                
'email' => 'email_address'// name of 'email' field in users table
                
'regdate' => 'date_registered'// name of 'registered' field in users table
                
'lastvisit' => 'last_login'// last time user logged in
                
'active' => 'is_activated'// is user account active?
                
'location' => 'location'// name of 'location' field in users table
                
'website' => 'website_url'// name of 'website' field in users table
                
'usertbl_group_id' => 'id_post_group'// name of 'group id' field in users table
                
'grouptbl_group_id' => 'id_group'// name of 'group id' field in groups table
                
'grouptbl_group_name' => 'group_name'// name of 'group name' field in groups table
                
'postgroup' => 'id_post_group'// post group field
                
'additionals' => 'additional_groups'// additional groups, comma seperated
            
);

            
// Pages to redirect to
            
$this->page = array(
                
'register' => '/index.php?action=register',
                
'editusers' => '/index.php?action=mlist',
                
'edituserprofile' => '/index.php?action=profile;u='
            
);

            
// Group ids - admin and guest only.
            
$this->admingroups = array(1);
            
$this->guestgroup 0;

            
// Connect to db - or supply a connection id to be used instead of making own connection.
            
$this->connect();
        }

        
// definition of how to extract id, name, group from a session cookie
        
function session_extraction()
        {
            
$superCage Inspekt::makeSuperCage();

            if (
$superCage->cookie->keyExists($this->cookie_name)) {

                
$data unserialize($superCage->cookie->getRaw($this->cookie_name));

                if (
is_numeric($data[0]) && preg_match('/^[A-F0-9]{40}$/i'$data[1])) {
                    return 
$data;
                } else {
                    return 
false;
                }
            }
        }

        
// definition of how to extract an id and password hash from a cookie
        
function cookie_extraction()
        {
            return 
false;
        }

        
// definition of actions required to convert a password from user database form to cookie form
        
function udb_hash_db($password)
        {
            return 
$password// unused
        
}

        
// Get groups of which user is member
        
function get_groups($row)
        {
            
$data = array();

            
$sql "SELECT id_group, {$this->field['additionals']} AS additionals FROM {$this->usertable} WHERE {$this->field['user_id']} = {$row['id']}";
            
$result cpg_db_query($sql$this->link_id);

            
$groupdata mysql_fetch_assoc($result);

            if (
$this->use_post_based_groups) {

                
// the group is used as master group
                
if ($groupdata['id_group']) {
                    
$data[] = $groupdata['id_group'] + 100;
                }

                
// add in post based group as first additional group
                
if ($row['group_id']) {
                    
$data[] = $row['group_id'] + 100;
                }

                
//  add in any additional groups
                
if ($groupdata['additionals']) {

                    
$additionals explode(','$groupdata['additionals']);

                    foreach (
$additionals as $group) {
                        
$data[] = $group 100;
                    }
                }

            } else {
                
$data[0] = in_array($groupdata['id_group'] , $this->admingroups) ? 2;
            }

            return 
$data;
        }

        function 
collect_groups()
        {
            
// Use this version to exclude true post based groups
            //$sql ="SELECT * FROM {$this->groupstable} WHERE minposts=-1";

            // Use this version to include all SMF groups
            
$sql ="SELECT * FROM {$this->groupstable}";

            
$result cpg_db_query($sql$this->link_id);

            
$udb_groups = array(100 => 'Guests');

            while (
$row mysql_fetch_assoc($result)) {
                
$udb_groups[$row[$this->field['grouptbl_group_id']]+100] = utf_ucfirst(utf_strtolower($row[$this->field['grouptbl_group_name']]));
            }

            return 
$udb_groups;
        }

        function 
login_page()
        {
            global 
$CONFIG;

            if (
$session $this->_session_load()) {
                
$session['old_url'] = $CONFIG['site_url'] . '?board=redirect';
                
$this->_session_save($session);
            }

            
$this->redirect('/index.php?action=login');
        }

        function 
_session_load()
        {
            
$superCage Inspekt::makeSuperCage();

            if (
$superCage->cookie->keyExists('PHPSESSID')) {

                
$session_id $superCage->cookie->getEscaped('PHPSESSID');

                
$sql "SELECT data FROM {$this->sessionstable} WHERE session_id = '$session_id'";

                
$result cpg_db_query($sql$this->link_id);

                if (
mysql_num_rows($result)) {

                    list(
$data) = mysql_fetch_row($result);

                    
session_name('CPG');
                    
session_start();

                    
session_decode($data);

                    
$session $_SESSION;

                    return 
$session;
                }
            }

            return 
false;
        }

        function 
_session_save($session)
        {
            
$superCage Inspekt::makeSuperCage();

            if (
$superCage->cookie->keyExists('PHPSESSID')) {

                
$session_id $superCage->cookie->getEscaped('PHPSESSID');

                
$_SESSION $session;

                
$data addslashes(session_encode());

                
$sql "UPDATE {$this->sessionstable} SET data = '$data' WHERE session_id = '$session_id'";

                
cpg_db_query($sql$this->link_id);
            }
        }

        function 
logout_page()
        {
            global 
$CONFIG;

            if (
$session $this->_session_load()) {
                
$session['logout_url'] = $CONFIG['site_url'];
                
$this->_session_save($session);
                
$this->redirect('/index.php?action=logout;' $session['session_var'] . '=' $session['session_value']);
            } else {
                
$this->redirect('/index.php?action=logout');
            }
        }

        function 
view_users()
        {
        }

        function 
view_profile()
        {
        }
    }

    
// and go !
    
$cpg_udb = new cpg_udb;
}
?>






You're good enough with code to pick that apart right away.  I think the solution lies with  'password' in the field array, or with sessions.  But I could be way off.   O:)

Arantor

Ugh. This is really not how to do a bridge :(

Yeah, the way the password works is quite different. I forget exactly how it's done but it's using the bcrypt library now.

lc62003

Quote from: Arantor on December 18, 2014, 10:17:51 PM
Ugh. This is really not how to do a bridge :(

Yeah, the way the password works is quite different. I forget exactly how it's done but it's using the bcrypt library now.

Not surprising you'd say that.   :D   ;D

What do you recommend as a start?  I do ok with modifying existing code and don't mind digging around to learn.   8)

Arantor

Subs-Auth.php has a function called hash_password() that deals with the hashing; you pass in the username and password and it does the rest.

lc62003

Quote from: Arantor on December 18, 2014, 10:24:46 PM
Subs-Auth.php has a function called hash_password() that deals with the hashing; you pass in the username and password and it does the rest.

Cool!  Thanks!  I'll chew on that a few days.  If it's a success I'll update here so it can help someone else.   :)

lc62003

Quote from: Arantor on December 18, 2014, 10:24:46 PM
Subs-Auth.php has a function called hash_password() that deals with the hashing; you pass in the username and password and it does the rest.


Wouldn't that log into SMF from Coppermine?  The site needs users to be logged into Coppermine from SMF.  Shouldn't Coppermine be grabbing info from the SMF cookie, or am I thinking backward on this? 

Arantor

I've seen a bridge - and it does appear to rely on needing the hash algorithm.

lc62003

Quote from: Arantor on December 31, 2014, 02:09:21 PM
I've seen a bridge - and it does appear to rely on needing the hash algorithm.

Without question - that's why I have to make sure I'm understanding correctly.   :laugh:  Thanks.  I'll keep working on this.  It will be a strong learning curve. 

lc62003

After looking at this a while I just don't have the know-how to get it done.  Can anyone get me started?   O:)

Arantor

I'm really not sure it's actually so doable given the way the bridge I've seen appears to work, in all honesty... and if I'm *truly* honest... I have a different motivation now for studying Coppermine... to write an importer, not a bridge.

lc62003

Quote from: Arantor on January 10, 2015, 10:08:41 PM
I'm really not sure it's actually so doable given the way the bridge I've seen appears to work, in all honesty... and if I'm *truly* honest... I have a different motivation now for studying Coppermine... to write an importer, not a bridge.

That would be killer!!!   8)

Advertisement: