Admin wrapper script | > Script written by Matt Mecham | > Date started: 1st March 2002 | +-------------------------------------------------------------------------- */ //----------------------------------------------- // USER CONFIGURABLE ELEMENTS //----------------------------------------------- // Are we running this on a lycos / tripod server? // If so, change the following to a 1. $is_on_tripod = 0; // Root path define( 'ROOT_PATH', './' ); define( 'KERNEL_PATH', ROOT_PATH.'ips_kernel/' ); // Check IP address to see if they match? // this may cause problems for users on proxies // where the IP address changes during a session $check_ip = 1; // Use GZIP content encoding for fast page generation // in the admin center? $use_gzip = 1; // Enable module usage? // (Vital for some mods and IPB enhancements) define ( 'USE_MODULES', 1 ); // Enable custom error handling? // Useful to trap skin errors, etc define( 'CUSTOM_ERROR', 1 ); // You really don't want to turn this on define( 'TRIAL_VERSION', 0 ); //----------------------------------------------- // NO USER EDITABLE SECTIONS BELOW //----------------------------------------------- define ( 'IN_ACP', 1 ); define ( 'IN_IPB', 1 ); define ( 'IN_DEV', 0 ); error_reporting (E_ERROR | E_WARNING | E_PARSE); set_magic_quotes_runtime(0); if ( CUSTOM_ERROR ) { set_error_handler("my_error_handler"); } if ( $is_on_tripod != 1 ) { if (function_exists('ini_get')) { $safe_switch = @ini_get("safe_mode") ? 1 : 0; } else { $safe_switch = 1; } } else { $safe_switch = 1; } define( 'SAFE_MODE_ON', $safe_switch ); if (function_exists("set_time_limit") == 1 and SAFE_MODE_ON == 0) { @set_time_limit(0); } class Debug { function startTimer() { global $starttime; $mtime = microtime (); $mtime = explode (' ', $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; } function endTimer() { global $starttime; $mtime = microtime (); $mtime = explode (' ', $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = round (($endtime - $starttime), 5); return $totaltime; } } class info { var $vars = ""; var $version = 'v2.0.4'; var $acpversion = '20014'; var $base_url = ''; var $main_error = ""; var $main_msg = ""; var $skin = array(); var $member = array(); var $loaded_templates = array(); function info($INFO) { $this->vars = $INFO; if ( defined($ibforums->vars['safe_mode_skins']) ) { define( 'SAFE_MODE_SKINS', $ibforums->vars['safe_mode_skins'] ); } else { define( 'SAFE_MODE_SKINS', SAFE_MODE_ON ); } $this->vars['AVATARS_URL'] = 'style_avatars'; $this->vars['EMOTICONS_URL'] = 'style_emoticons/<#EMO_DIR#>'; $this->vars['mime_img'] = 'style_images/<#IMG_DIR#>/folder_mime_types'; } } //-------------------------------- // Import $INFO, now! //-------------------------------- require ROOT_PATH."conf_global.php"; $ibforums = new info($INFO); //-------------------------------- // The clocks a' tickin' //-------------------------------- $Debug = new Debug; $Debug->startTimer(); //-------------------------------- // Load up our database library //-------------------------------- $INFO['sql_driver'] = ! $INFO['sql_driver'] ? 'mysql' : strtolower($INFO['sql_driver']); require ( KERNEL_PATH.'class_db_'.$INFO['sql_driver'].".php" ); $DB = new db_driver; $DB->obj['sql_database'] = $INFO['sql_database']; $DB->obj['sql_user'] = $INFO['sql_user']; $DB->obj['sql_pass'] = $INFO['sql_pass']; $DB->obj['sql_host'] = $INFO['sql_host']; $DB->obj['sql_tbl_prefix'] = $INFO['sql_tbl_prefix']; $DB->obj['query_cache_file'] = ROOT_PATH.'sources/sql/'.$INFO['sql_driver'].'_admin_queries.php'; $DB->obj['use_shutdown'] = 0; //----------------------------------- // Required vars? //----------------------------------- if ( is_array( $DB->connect_vars ) and count( $DB->connect_vars ) ) { foreach( $DB->connect_vars as $k => $v ) { $DB->connect_vars[ $k ] = $INFO[ $k ]; } } //-------------------------------- // Get a DB connection //-------------------------------- $DB->connect(); //-------------------------------- // Make CONSTANT //-------------------------------- define( 'SQL_PREFIX', $DB->obj['sql_tbl_prefix'] ); define( 'SQL_DRIVER', $INFO['sql_driver'] ); //=========================================================================== // Get cache... //=========================================================================== $DB->simple_construct( array( 'select' => '*', 'from' => 'cache_store', 'where' => "cs_key IN ( 'settings', 'group_cache', 'systemvars', 'skin_id_cache', 'forum_cache', 'moderators', 'stats' )" ) ); $DB->simple_exec(); while ( $r = $DB->fetch_row() ) { if ( $r['cs_key'] == 'settings' and $r['cs_value'] ) { $tmp = unserialize(stripslashes($r['cs_value'])); if ( is_array( $tmp ) and count( $tmp ) ) { foreach( $tmp as $k => $v ) { $ibforums->vars[ $k ] = $v; } } unset( $tmp ); } else { if ( $r['cs_array'] ) { $ibforums->cache[ $r['cs_key'] ] = unserialize(stripslashes($r['cs_value'])); } else { $ibforums->cache[ $r['cs_key'] ] = $r['cs_value']; } } } //-------------------------------- // Load up our classes (compiled into one package) //-------------------------------- require ROOT_PATH."sources/functions.php"; require ROOT_PATH."sources/classes/class_session.php"; require ROOT_PATH."sources/classes/class_forums.php"; require KERNEL_PATH."class_converge.php"; $std = new FUNC; $forums = new forum_functions(); $sess = new session(); //-------------------------------- // Set up our vars $HTTP_POST_VARS['adsess'] //-------------------------------- $ibforums->input = $std->parse_incoming(); //-------------------------------- // Initialize the FUNC //-------------------------------- $std->FUNC_init(); //-------------------------------- // Set converge //-------------------------------- $ibforums->converge = new class_converge( $DB ); //-------------------------------- // Message in a bottle? //-------------------------------- if ( $ibforums->input['messageinabottleacp'] ) { $ibforums->input['messageinabottleacp'] = $std->clean_evil_tags( $std->txt_UNhtmlspecialchars( urldecode($ibforums->input['messageinabottleacp']) ) ); $ibforums->main_msg = $ibforums->input['messageinabottleacp']; } //-------------------------------- // Fix up base URLs //-------------------------------- $ibforums->base_url = $ibforums->vars['board_url']."/admin.".$ibforums->vars['php_ext'].'?adsess='.$ibforums->input['adsess']; $ibforums->skin_url = $ibforums->vars['board_url']."/skin_acp/IPB2_Standard"; //-------------------------------- // Set up cache path //-------------------------------- if ( $ibforums->vars['ipb_cache_path'] ) { define( 'CACHE_PATH', $ibforums->vars['ipb_cache_path'] ); } else { define( 'CACHE_PATH', ROOT_PATH ); } //-------------------------------- // Upload dir? //-------------------------------- $ibforums->vars['upload_dir'] = $ibforums->vars['upload_dir'] ? $ibforums->vars['upload_dir'] : ROOT_PATH.'uploads'; //-------------------------------- // Import $PAGES and $CATS //-------------------------------- require ROOT_PATH."sources/admin/admin_pages.php"; //-------------------------------- // Import Admin Functions //-------------------------------- require ROOT_PATH."sources/admin/admin_functions.php"; $ibforums->admin = new admin_functions(); //------------------------------------------------ // Sort out settings cookie //------------------------------------------------ $ibforums->vars['menu'] = 0; $ibforums->vars['tx'] = 80; $ibforums->vars['ty'] = 40; $ibforums->vars['preview'] = ""; //------------------------------------------------ // Load skin //------------------------------------------------ $std->load_skin(); $std->load_template( 'skin_global' ); //-------------------------------- // Import Skinable elements //-------------------------------- require ROOT_PATH."sources/admin/admin_skin.php"; $ibforums->adskin = new admin_skin(); //------------------------------------------------ // Admin.php Rules: // // No adsess number? // ----------------- // // Then we log into the admin CP // // Got adsess number? // ------------------ // // Then we check the cookie "ad_login" for a session key. // // If this session key matches the one stored in the admin_sessions // table, then we check the data against the data stored in the // profiles table. // // The session key and ad_sess keys are generated each time we log in. // // If we don't have a valid adsess in the URL, then we ask for a log in. // //------------------------------------------------ $session_validated = 0; $this_session = array(); $validate_login = 0; if ($ibforums->input['login'] != 'yes') { if ( ! $ibforums->input['adsess'] ) { //---------------------------------- // No URL adsess found, lets log in. //---------------------------------- do_login("No administration session found"); } else { //---------------------------------- // We have a URL adsess, lets verify... //---------------------------------- $DB->query("SELECT * FROM ibf_admin_sessions WHERE session_id='".$ibforums->input['adsess']."'"); $row = $DB->fetch_row(); if ($row['session_id'] == "") { //---------------------------------- // Fail-safe, no DB record found, lets log in.. //---------------------------------- do_login("Could not retrieve session record"); } else if ($row['session_member_id'] == "") { //---------------------------------- // No member ID is stored, log in! //---------------------------------- do_login("Could not retrieve a valid member id"); } else { //---------------------------------- // Key is good, check the member details //---------------------------------- $DB->query("SELECT m.*, g.* FROM ibf_members m, ibf_groups g WHERE id=".intval($row['session_member_id'])." and m.mgroup=g.g_id"); $ibforums->member = $DB->fetch_row(); //---------------------------------- // Get perms //---------------------------------- $sess->member = $ibforums->member; $sess->build_group_permissions(); $ibforums->member = $sess->member; if ($ibforums->member['id'] == "") { //---------------------------------- // Ut-oh, no such member, log in! //---------------------------------- do_login("Member ID invalid"); } else { //---------------------------------- // Member found, check passy //---------------------------------- if ($row['session_member_login_key'] != $ibforums->member['member_login_key']) { //---------------------------------- // Passys don't match.. //---------------------------------- do_login("Session member password mismatch"); } else { //---------------------------------- // Do we have admin access? //---------------------------------- if ($ibforums->member['g_access_cp'] != 1) { do_login("You do not have access to the administrative CP"); } else { $session_validated = 1; $this_session = $row; } } } } } } else { //---------------------------------- // We must have submitted the form // time to check some details. //---------------------------------- $ibforums->input['username'] = str_replace( '|', '|', $ibforums->input['username'] ); if ( empty($ibforums->input['username']) ) { do_login("You must enter a username before proceeding"); } if ( empty($ibforums->input['password']) ) { do_login("You must enter a password before proceeding"); } //---------------------------------- // Attempt to get the details from the // DB //---------------------------------- $DB->cache_add_query( 'login_getmember', array( 'username' => strtolower($ibforums->input['username']) ) ); $DB->cache_exec_query(); $mem = $DB->fetch_row(); //---------------------------------- // Get perms //---------------------------------- $sess->member = $mem; $sess->build_group_permissions(); $mem = $sess->member; if ( empty($mem['id']) ) { do_login("Could not find a record matching that username, please check the spelling"); } //---------------------------------- // Load converge member //---------------------------------- $ibforums->converge->converge_load_member($mem['email']); if ( ! $ibforums->converge->member['converge_id'] ) { do_login("Could not find a record matching that username, please check the spelling"); } //---------------------------------- // Check converge pass //---------------------------------- $pass = md5( $ibforums->input['password'] ); //------------------------------ // Check password... //------------------------------ if ( $ibforums->converge->converge_authenticate_member( $pass ) != TRUE ) { do_login("The password you entered is not correct"); } else { if ($mem['g_access_cp'] != 1) { do_login("You do not have access to the administrative CP"); } else { //---------------------------------- // Fix up query string... //---------------------------------- $extra_query = ""; if ( $_POST['qstring'] ) { $extra_query = $_POST['qstring']; $extra_query = str_replace( "{$ibforums->vars['board_url']}" , "" , $extra_query ); $extra_query = preg_replace( "!/?admin\.{$ibforums->vars['php_ext']}!i", "" , $extra_query ); $extra_query = preg_replace( "!^\?!" , "" , $extra_query ); $extra_query = preg_replace( "!adsess=(\w){32}!" , "" , $extra_query ); $extra_query = preg_replace( "!s=(\w){32}!" , "" , $extra_query ); } //---------------------------------- // All is good, rejoice as we set a // session for this user //---------------------------------- $sess_id = md5( uniqid( microtime() ) ); $db_string = $DB->compile_db_insert_string( array ( 'session_id' => $sess_id, 'session_ip_address' => $ibforums->input['IP_ADDRESS'], 'session_member_name' => $mem['name'], 'session_member_id' => $mem['id'], 'session_member_login_key' => $mem['member_login_key'], 'session_location' => 'index', 'session_log_in_time' => time(), 'session_running_time' => time(), ) ); $DB->query("INSERT INTO ibf_admin_sessions (".$db_string['FIELD_NAMES'].") VALUES (".$db_string['FIELD_VALUES'].")"); $ibforums->input['AD_SESS'] = $sess_id; // Print the "well done page" $ibforums->admin->page_title = "Log in successful"; $ibforums->admin->page_detail = "Taking you to the administrative control panel"; $ibforums->html .= $ibforums->adskin->start_table("Proceed"); $ibforums->html .= "