Skip to content

Instantly share code, notes, and snippets.

@chipviled
Created December 4, 2016 21:04
Show Gist options
  • Save chipviled/ab657272e93c08293d35c6821a506544 to your computer and use it in GitHub Desktop.
Save chipviled/ab657272e93c08293d35c6821a506544 to your computer and use it in GitHub Desktop.
Bridge e107 (v 1.x and 2.x) and cpg (v1.5.x only)
<?php
/********************************************************************
Coppermine Photo Gallery
e107 bridge
************************
v1.01
Coppermine version: 1.4.9
$Source$
$Author: v3 <[email protected]>$
$Revision: 1.02 $
$Date: 2006-09-28 04:48:42 +0400 $
Origin brige: http://forum.coppermine-gallery.net/index.php?topic=36151.0
************************
Adapted for e107 (v 1.x and 2.x) and cpg (v1.5.x only) by Chip Viled
************************
--- ATTENTION !!! ---
In file cpg1.5.x/include/init.inc.php value `$strict` MUST BE `false` !!!
*********************************************************************/
if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
if (isset($bridge_lookup)) {
$default_bridge_data[$bridge_lookup] = array(
'full_name' => 'e107',
'short_name' => 'e107',
'support_url' => 'e107',
'full_forum_url_default' => 'http://localhost/marvin_test/',
'full_forum_url_used' => 'mandatory,not_empty',//,no_trailing_slash',
'relative_path_to_config_file_default' => '../',
'relative_path_to_config_file_used' => 'lookfor,e107_config.php',
'use_post_based_groups_default' => '0',
'use_post_based_groups_used' => 'radio,1,0',
//'cookie_prefix_default' => '',
//'cookie_prefix_used' => 'cookie',
);
} else {
// Switch that allows overriding the bridge manager with hard-coded values
define('USE_BRIDGEMGR', 1);
$E107_COPPERMINE_ADMIN_GROUP = "COPPERMINE_ADMIN";
require_once 'bridge/udb_base.inc.php';
class cpg_udb extends core_udb {
function cpg_udb()
{
global $BRIDGE;
if (!USE_BRIDGEMGR) { // the vars that are used when bridgemgr is disabled
// URL of your punbb
$this->boardurl = 'http://localhost/';
// local path to your punbb config file
require_once('../e107_config.php');
} else { // the vars from the bridgemgr
$this->boardurl = $BRIDGE['full_forum_url'];
require_once($BRIDGE['relative_path_to_config_file'] . 'e107_config.php');
$this->use_post_based_groups = $BRIDGE['use_post_based_groups'];
}
// class2.php MUST be included from CPG's config.inc.php (otherwise, globals will not work)
// it can't be realised with plugins for now. So, it's the only way.
if (!defined('CPG_E107_CLASS_INCLUDED')) {
//trying to find e107_config.php
//$BRIDGE['relative_path_to_config_file'] = "";
for ($tmp = 0; $tmp < 2; $tmp++)
if (!is_readable (@$BRIDGE['relative_path_to_config_file'] . 'class2.php'))
@$BRIDGE['relative_path_to_config_file'] = "../".@$BRIDGE['relative_path_to_config_file'];
if (@$_POST['e107path'] && $_POST['e107path'][ strlen($_POST['e107path']) - 1 ] != '/') {
$_POST['e107path'] .= "/";
}
if (@$_POST['e107path'] && !is_readable (@$BRIDGE['relative_path_to_config_file'] . 'class2.php'))
$BRIDGE['relative_path_to_config_file'] = @$_POST['e107path'];
if (is_readable ($BRIDGE['relative_path_to_config_file'] . 'class2.php') && !@$_POST['e107path']) {
$text =
'<h1>Please, enter relative path to e107</h1>
Please, check out if this is relative path to e107 (from Coppermine folder).<br />
Installing Coppermine not into e107 subfolder is <b>not recommend</b>, so don\'t complain if it will not work :)
<form action="" method="post">
<input type="text" name="e107path" value="'.$BRIDGE['relative_path_to_config_file'].'" />
<input type="submit" name="submit" value="Here\'s it" />
</form>';
//echo $text;
//die;
}
if (!is_readable ($BRIDGE['relative_path_to_config_file'] . 'class2.php')) {
$tmppath = @$_POST['e107path'] ? $_POST['e107path'] : "../e107/";
$text =
'<h1>Can\'t find e107_config.php :/</h1>
Please, enter <b>relative</b> path to e107 (from Coppermine folder).<br />
Installing Coppermine not into e107 subfolder is <b>not recommend</b>, so don\'t complain if it will not work :)
<form action="" method="post">
<input type="text" name="e107path" value="'.addslashes($tmppath).'" />
<input type="submit" name="submit" value="Here\'s it" />
</form>';
echo $text;
die;
}
$class2 = $BRIDGE['relative_path_to_config_file'] . 'class2.php';
$data =
'
<?php //e107
// this block was added by e107 CPG bridge
define("CPG_E107_CLASS_INCLUDED", 1);
$register_globals = true;
if(function_exists("ini_get")) {
$register_globals = ini_get("register_globals");
}
if ($register_globals) //evil e107... kills all globals :(
$HTTP___cpg = array ("cpg_time_start" => $cpg_time_start,
"queries" => $queries,
"query_stats" => $query_stats,
"CONFIG" => $CONFIG,
"CURRENT_PIC_DATA" => $CURRENT_PIC_DATA,
"ORIGINAL_PHP_SELF" => $ORIGINAL_PHP_SELF,
"PHP_SELF" => $PHP_SELF,
"REFERER" => $REFERER,
"ALBUM_SET" => $ALBUM_SET,
"META_ALBUM_SET" => $META_ALBUM_SET,
"FORBIDDEN_SET" => $FORBIDDEN_SET,
"FORBIDDEN_SET_DATA" => $FORBIDDEN_SET_DATA,
"CURRENT_CAT_NAME" => $CURRENT_CAT_NAME,
"CAT_LIST" => $CAT_LIST,
"raw_ip" => $raw_ip,
"hdr_ip" => $hdr_ip,
"cpgdebugger" => $cpgdebugger,
"file" => $file);
//$HTTP___e107_coppermine_self = $_SERVER["PHP_SELF"];
//$PHP_SELF = $_SERVER["PHP_SELF"] = $_SERVER["SCRIPT_NAME"] = $ORIGINAL_PHP_SELF;
@include_once "'.$class2.'";
//$PHP_SELF = $_SERVER["PHP_SELF"] = $_SERVER["SCRIPT_NAME"] = $HTTP___e107_coppermine_self;
//unset($HTTP___e107_coppermine_self);
if (@isset($HTTP___cpg)) {
extract($HTTP___cpg);
unset($HTTP___cpg);
}
?>
';
$config = "include/config.inc.php";
if (!is_writable($config)) die ("Can't write into '$config' file. Please, turn on write permissions on it.");
//upgrading from 1.3.5? Better to fix config file...
$old_config = file_get_contents($config);
if (strstr($old_config, "e107 master from wherever")) {
include $BRIDGE['relative_path_to_config_file'] . "e107_config.php";
preg_match('#^.*\$CONFIG\[\'TABLE_PREFIX\'\].*$#m', $old_config, $matches);
$prefix = str_replace('$mySQLprefix', "'".$mySQLprefix."'", $matches[0]);
$output = '<?php
// Coppermine configuration file
// Generated by e107 bridge
// MySQL configuration
$CONFIG[\'dbserver\'] = \''.$mySQLserver.'\'; // Your database server
$CONFIG[\'dbuser\'] = \''.$mySQLuser.'\'; // Your mysql username
$CONFIG[\'dbpass\'] = \''.$mySQLpassword.'\'; // Your mysql password
$CONFIG[\'dbname\'] = \''.$mySQLdefaultdb.'\'; // Your mysql database name
// MySQL TABLE NAMES PREFIX
'.$prefix.'
?>';
$f = fopen($config, "w");
fwrite($f, $output);
fclose($f);
}
$f = fopen($config, "a");
fwrite($f, $data);
fclose($f);
$text = '
<h1>e107 Coppermine Bridge was installed!</h1>
Note that "include/config.inc.php" was modified! It\'s required operation if you want this bridge to work propertly. :)<br />
Following block was added:<div style="margin: 5px; border: 1px solid #666; background-color: #eee">
<small><pre>'.htmlspecialchars($data).'</pre></small></div>
If you want to disable this bridge, you should remove added block by yourself!<br /><br />
';
if(@ini_get("register_globals")) $text = '
<h1>Warning: you have register_globals turned on!</h1>
There can be problems on configurations with register_globals turned on. So, if everything\'s messed up, please consider of
<a target="blank" href="http://www.google.ru/search?q=turn+off+register_globals">turning it off</a> (actually, it\'s a good idea anyway).'
.$text;
echo $text;
global $CONFIG;
$qr = "UPDATE `{$CONFIG['TABLE_BRIDGE']}`
SET `value` = '".mysql_escape_string($BRIDGE['relative_path_to_config_file'] )."'
WHERE name = 'relative_path_to_config_file'";
cpg_db_query($qr);
die;
}
if (!is_readable ($BRIDGE['relative_path_to_config_file'] . 'e107_config.php'))
die ("E107 BRIDGE ERROR: can't find 'e107_config.php'");
include($BRIDGE['relative_path_to_config_file'] . 'e107_config.php');
global $e107;
if (!is_object(@$e107)) {
die ('E107 BRIDGE ERROR: class2.php is not included! Try to check out "coppermine/include/config.inc.php"');
}
if (!$BRIDGE['full_forum_url']) {
global $CONFIG;
$BRIDGE['full_forum_url'] = $e107->base_path;
$qr = "UPDATE `{$CONFIG['TABLE_BRIDGE']}`
SET `value` = '".mysql_escape_string($BRIDGE['full_forum_url'] )."'
WHERE name = 'full_forum_url'";
cpg_db_query($qr);
}
$this->boardurl = $BRIDGE['full_forum_url'];
$this->use_post_based_groups = 1;
$this->e107_version = "0.7";
$this->multigroups = 1;
$this->group_overrride = 1;
// Database connection settings
$this->db = array(
'name' => $mySQLdefaultdb,
'host' => $mySQLserver,
'user' => $mySQLuser,
'password' => $mySQLpassword,
'prefix' => $mySQLprefix
);
// Board table names
$this->table = array(
'users' => 'user',
'groups' => 'userclass_classes',
'sessions' => 'session',
'config' => 'core'
);
// Derived full table names
$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'];
$this->configtable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['config'];
$this->usergroupstable = $this->usertable;
// Table field names
$this->field = array(
'username' => 'user_name', // name of 'username' field in users table
'user_id' => 'user_id', // name of 'id' field in users table
'is_admin' => 'user_admin', // whether user is admin
'admin_perms' => 'user_perms', // admin permissions
'password' => 'user_password', // name of 'password' field in users table
'email' => 'user_email', // name of 'email' field in users table
'regdate' => 'user_join', // name of 'registered' field in users table
'lastvisit' => 'user_lastvisit', // last time user logged in
'active' => 'user_ban', // is user account active?
'location' => "''", // name of 'location' field in users table
'website' => "''", // name of 'website' field in users table
'usertbl_group_id' => 'user_class', // name of 'group id' field in users table
'grouptbl_group_id' => 'userclass_id', // name of 'group id' field in groups table
'grouptbl_group_name' => 'userclass_name', // name of 'group name' field in groups table
'e107_configcol' => 'e107_name' // main column of e107_core
);
// Pages to redirect to
$this->page = array(
'register' => $BRIDGE['full_forum_url']."/signup.php",
'editusers' => $BRIDGE['full_forum_url'].'/administrator/index.php',
'edituserprofile' => $BRIDGE['full_forum_url']."/$ADMIN_DIRECTORY/user.php"
);
// Group ids - admin and guest only.
// get COPPERMINE_ADMIN Group
/*global $sql;*/
$this->connect();
global $E107_COPPERMINE_ADMIN_GROUP;
$query = "SELECT * FROM {$this->groupstable} WHERE `userclass_name` = '$E107_COPPERMINE_ADMIN_GROUP'";
$result = cpg_db_query($query, $this->link_id);
$row = mysql_fetch_assoc($result);
$this->admingroups = array();
if ($row['userclass_id']) $this->admingroups = array($row['userclass_id']);
$this->guestgroup = 3;
$this->guestgroup = -97; // (100 - 97) = 3
}
function collect_groups() {
$query ="SELECT * FROM {$this->groupstable}";
$result = cpg_db_query($query, $this->link_id);
$udb_groups = array(1 =>'Administrators', 2=> 'Registered', 3=>'Guests', 4=> 'Banned');
while ($row = mysql_fetch_assoc($result))
{
// don't include COPPERMINE_ADMIN Group
if (!in_array($row[$this->field['grouptbl_group_id']], $this->admingroups))
$udb_groups[$row[$this->field['grouptbl_group_id']]+100] = utf_ucfirst(utf_strtolower($row[$this->field['grouptbl_group_name']]));
}
return $udb_groups;
}
// definition of how to extract an id and password hash from a cookie
function cookie_extraction()
{
/* not used anymore
global $CONFIG;
// Default anonymous values
$id = 0;
$pass = '';
$f = $this->field;
$query = "SELECT `e107_value` ".
"FROM {$this->configtable} ".
"WHERE `e107_name` = 'SitePrefs'";
$result = cpg_db_query($query, $this->link_id);
$row = mysql_fetch_assoc($result);
preg_match("/cookie_name\' => \'(.*?)\'/", $row['e107_value'], $m);
$sessioncookie = @$_COOKIE[$m[1]];
if ($sessioncookie) {
$tmp = explode(".", $sessioncookie);
$id = $tmp[0];
$pass = $tmp[1];
}
return ($id) ? array($id, $pass) : false; // */
}
function get_groups($row) {
global $USER_DATA;
if (!$row['group_id']) return;
$g = explode(",", $row['group_id']);
foreach ($g as $i => $z) {
$g[$i]+=100;
}
return $g;
}
/* autentificate кто все эти люди? */
function authenticate()
{
global $USER_DATA, $currentUser;
//var_dump($currentUser);
if (!(USER && USERID)) {
$this->load_guest_data();
} else {
// class2.php included
list ($id, $cookie_pass) = array (USERID, $currentUser['user_password']);
$f = $this->field;
/* $query = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, u.{$f['usertbl_group_id']} AS group_id, ".
"u.{$f['is_admin']} as is_admin, u.{$f['admin_perms']} as admin_perms ".
"FROM {$this->usertable} AS u ".
"WHERE u.{$f['user_id']}='$id'"; // not used anymore */
$row = array (
'id' => $id,
'username' => $currentUser['user_name'],
'password' => $cookie_pass,
'is_admin' => $currentUser['user_admin'],
'admin_perms' => $currentUser['user_perms']
);
if ($currentUser['user_class']) $row['group_id'] = $currentUser['user_class'];
$this->load_user_data($row);
$USER_DATA['groups'][count($USER_DATA['groups'])] = 2; // user is registered
}
$user_group_set = '(' . implode(',', $USER_DATA['groups']) . ')';
if (in_array($this->admingroups[0]+100, $USER_DATA['groups']) ||
($row['is_admin'] && $row['admin_perms'] == 0)
) {
$USER_DATA['has_admin_access'] = true;
$USER_DATA['groups'][count($USER_DATA['groups'])] = 1;
}
$USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];
$USER_DATA = array_merge($USER_DATA, $this->get_user_data($USER_DATA['groups'][0], $USER_DATA['groups'], $this->guestgroup));
// avoids a template error
if (!$USER_DATA['user_id']) {
$USER_DATA['can_create_albums'] = 0;
}
// For error checking
$CONFIG['TABLE_USERS'] = '**ERROR**';
define('USER_ID', $USER_DATA['user_id']);
define('USER_NAME', addslashes($USER_DATA['user_name']));
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', $user_group_set);
define('USER_IS_ADMIN', $USER_DATA['has_admin_access']);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
//define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
//define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
//define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
//define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
//define('USER_CAN_CREATE_ALBUMS', ((int)$USER_DATA['can_create_albums'] || (int)$USER_DATA['can_create_public_albums']));
define('USER_CAN_CREATE_PRIVATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_CAN_CREATE_PUBLIC_ALBUMS', (int)$USER_DATA['can_create_public_albums']);
define('USER_ACCESS_LEVEL', (int)$USER_DATA['access_level']);
$this->session_update();
}
function udb_hash_db($password)
{
/* unused too
return md5($password); // e107 1.0 is using double hashing
*/
}
function login_page()
{
$this->redirect($BRIDGE['full_forum_url']);
}
function logout_page()
{
global $CONFIG;
$this->redirect($BRIDGE['full_forum_url']."?logout");
}
function edit_profile() {
$this->redirect($BRIDGE['full_forum_url']."usersettings.php");
}
function view_users() {}
function view_profile() {}
function session_extraction($cookie_id) {}
}
// and go !
$cpg_udb = new cpg_udb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment