1<?php
2/*************************
3  Coppermine Photo Gallery
4  ************************
5  Copyright (c) 2003-2016 Coppermine Dev Team
6  v1.0 originally written by Gregory Demar
7
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3
10  as published by the Free Software Foundation.
11
12  ********************************************
13  Coppermine version: 1.6.03
14  $HeadURL$
15**********************************************/
16
17if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
18
19if (isset($bridge_lookup)) {
20    $default_bridge_data[$bridge_lookup] = array(
21        'full_name' => 'MyBB 1.4',
22        'short_name' => 'mybb',
23        'support_url' => 'http://www.mybboard.net/',
24        'full_forum_url_default' => 'http://www.yoursite.com/board',
25        'full_forum_url_used' => 'mandatory,not_empty,no_trailing_slash',
26        'relative_path_to_config_file_default' => '../board/inc/',
27        'relative_path_to_config_file_used' => 'lookfor,config.php',
28        'use_post_based_groups_default' => '0',
29        'use_post_based_groups_used' => 'radio,1,0',
30    );
31} else {
32
33    // Switch that allows overriding the bridge manager with hard-coded values
34    define('USE_BRIDGEMGR', 1);
35
36    require_once 'bridge/udb_base.inc.php';
37
38    class cpg_udb extends core_udb {
39
40        function __construct ()
41        {
42            global $BRIDGE;
43
44            if (!USE_BRIDGEMGR) { // the vars that are used when bridgemgr is disabled
45
46                // URL of your punbb
47                $this->boardurl = 'http://localhost/mybb';
48
49                // local path to your punbb config file
50                require_once('../mybb/inc/config.php');
51
52                $this->use_post_based_groups = 1;
53
54            } else { // the vars from the bridgemgr
55                $this->boardurl = $BRIDGE['full_forum_url'];
56                require_once($BRIDGE['relative_path_to_config_file'] . 'config.php');
57                $this->use_post_based_groups = $BRIDGE['use_post_based_groups'];
58            }
59
60            $this->multigroups = 1;
61            $this->group_overrride = 0;
62
63            // Database connection settings
64            $this->db = array(
65                'name'     => $config['database']['database'],
66                'host'     => $config['database']['hostname'],
67                'user'     => $config['database']['username'],
68                'password' => $config['database']['password'],
69                'prefix'   => $config['database']['table_prefix'],
70            );
71
72            // Board table names
73            $this->table = array(
74                'users'    => 'users',
75                'groups'   => 'usergroups',
76                'sessions' => 'sessions',
77            );
78
79            // Derived full table names
80            $this->usertable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['users'];
81            $this->groupstable =  '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['groups'];
82            $this->sessionstable =  '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['sessions'];
83
84            // Table field names
85            $this->field = array(
86                'username' => 'username', // name of 'username' field in users table
87                'user_id' => 'uid', // name of 'id' field in users table
88                'password' => 'loginkey', // name of 'password' field in users table
89                'email' => 'email', // name of 'email' field in users table
90                'regdate' => 'regdate', // name of 'registered' field in users table
91                'location' => "''", // name of 'location' field in users table
92                'website' => 'website', // name of 'website' field in users table
93                'usertbl_group_id' => 'usergroup', // name of 'group id' field in users table
94                'grouptbl_group_id' => 'gid', // name of 'group id' field in groups table
95                'grouptbl_group_name' => 'title' // name of 'group name' field in groups table
96            );
97
98            // Pages to redirect to
99            $this->page = array(
100                'register'        => '/member.php?action=register',
101                'editusers'       => '/memberlist.php',
102                'edituserprofile' => "/member.php?action=profile&uid="
103            );
104
105            // Group ids
106            $this->admingroups = array(4);
107            $this->guestgroup  = 1;
108
109            // Connect to db
110            $this->connect();
111        }
112
113        // definition of how to extract id, name, group from a session cookie
114        function session_extraction()
115        {
116            $superCage = Inspekt::makeSuperCage();
117
118            if (!$superCage->cookie->keyExists('sid')) {
119                return false;
120            }
121
122            $this->sid = $superCage->cookie->getEscaped('sid');
123
124            if (!$this->sid) {
125                return false;
126            }
127
128            $result = $this->query("SELECT u.{$this->field['user_id']}, u.{$this->field['password']}, additionalgroups
129                FROM {$this->sessionstable} AS s
130                INNER JOIN {$this->usertable} AS u ON u.uid = s.uid
131                WHERE sid = '" . $this->sid . "'");
132
133            if (!cpg_db_num_rows($result)) {
134                return false;
135            }
136
137            $row = cpg_db_fetch_row($result);
138            $result->free();
139
140            $this->additionalgroups = array_pop($row);
141            $this->logoutkey = md5($row[1]);
142
143            return $row;
144        }
145
146        // definition of how to extract an id and password hash from a cookie
147        function cookie_extraction()
148        {
149            $superCage = Inspekt::makeSuperCage();
150
151            if ($superCage->cookie->keyExists('mybbuser')) {
152                return array_map('addslashes', explode("_", $superCage->cookie->getRaw('mybbuser'), 2));
153            } else {
154                return false;
155            }
156        }
157
158    	// Get groups of which user is member
159    	function get_groups($row)
160    	{
161    		$data = array();
162
163    		if ($this->use_post_based_groups) {
164
165    		    $data[] = $row['group_id'] + 100;
166
167    		    $additionalgroups = explode(',', $this->additionalgroups);
168
169    		    foreach ($additionalgroups as $g) {
170    		        $data[] = $g + 100;
171    		    }
172
173    		} else {
174    			$data[0] = (in_array($row['group_id'], $this->admingroups)) ? 1 : 2;
175    		}
176
177    		return $data;
178    	}
179
180        // definition of actions required to convert a password from user database form to cookie form
181        function udb_hash_db($password)
182        {
183            return $password;
184        }
185
186        // Login
187        function login_page()
188        {
189            $this->redirect('/member.php?action=login');
190        }
191
192        // Logout
193        function logout_page()
194        {
195            $this->redirect('/member.php?action=logout&logoutkey=' . $this->logoutkey);
196        }
197
198        function view_users()
199        {
200            $this->redirect($this->page['editusers']);
201        }
202
203        function get_users($options = array())
204        {
205        }
206
207        function view_profile($uid)
208        {
209        }
210    }
211
212    // and go !
213    $cpg_udb = new cpg_udb;
214}
215//EOF