[phpMP-CVS] CVS: phpMP/includes template.php,1.18,1.19 auth.php,1.21,1.22 constants.php,1.6,1.7 core
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2002-11-05 22:11:09
|
Update of /cvsroot/phpmp/phpMP/includes In directory usw-pr-cvs1:/tmp/cvs-serv19025/includes Modified Files: auth.php constants.php core.php dba.php functions.php parser.php sessions.php Added Files: template.php Log Message: Complete rewrite has begun! Index: auth.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/auth.php,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -r1.21 -r1.22 *** auth.php 14 Aug 2002 22:38:03 -0000 1.21 --- auth.php 5 Nov 2002 22:11:06 -0000 1.22 *************** *** 1,184 **** <? - /****************************************************************************** - ******************************************************************************* ! phpMP - The World's Greatest Modular Portal ! *********************************************** ! Are you MPowered? ! ! Copyright (C) 2002 phpMP Development Group ! All rights reserved. ! ! Lead Programmer: Brian Rose ! Lead Designer: Trevor Joynson ! ! Filename: /includes/auth.php ! Usage & Function: Contains Auth Class ! Create Date: March 29, 2002 ! ! $Id$ ! ! ******************************************************************************* ! ******************************************************************************* ! ! This software is provided under the GPL software license. A copy of the ! license should have been included with this software, located in the Docs ! folder. Feel free to redistribute and/or modify it according to the ! regulations stated in the license. ! ! ******************************************************************************* ! ******************************************************************************* ! ! Notes on this document: ! Database abstraction classes have been partially taken from jimmacr's phpusion ! project. Some source code has been modified, but most functions do exactly ! the same thing he intended them for. Most likely, this code will be mostly ! rewritten by project release. ! ! ******************************************************************************* ! ******************************************************************************/ ! ! class Auth { ! ! var $mpcookie; ! var $first_login; ! var $first_anon; ! ! function session_cleanup() { ! ! global $MPCONF, $DBA; ! ! $rand_val = rand(0, 10); ! if($rand_val >= 1) { ! ! $result = $DBA->query("DELETE FROM " . $MPCONF['DB']['table_prefix'] . "sessions WHERE expiretime < " . time()); ! ! return $DBA->affected_rows(); ! ! } ! ! } ! ! function AuthUser() { ! ! global $MPCONF, $Functions, $DBA; ! ! $this->session_cleanup(); ! ! if(empty($_POST['username'])) { ! session_start(); ! } ! ! if (empty($_REQUEST['PHPSESSID'])) { ! SetCookie("PHPSESSID", session_id(), (time() + $MPCONF['SES']['session_length']), "", "", 0); ! } ! ! if(($_POST['username'] != "") && ($_POST['password'] != "")) { ! ! $new_key = $Functions->createHash(); ! session_id($new_key); ! session_start(); ! ! $enc_password = md5($_POST['password']); ! ! $result = $DBA->query('SELECT * FROM ' . $MPCONF['DB']['table_prefix'] . "users WHERE username='{$_POST['username']}' AND password='$enc_password'"); ! $num_rows = $DBA->num_rows($result); ! if($num_rows > 0) { ! $user_array = $DBA->fetch_array($result); ! $MPCONF['USR'] = $user_array; ! ! if($MPCONF['USR']['active'] == 1) { ! ! $this->first_login = 1; ! $DBA->query("DELETE FROM " . $MPCONF['DB']['table_prefix'] . "sessions WHERE user_id = " . $user_array['user_id']); ! $DBA->query("DELETE FROM " . $MPCONF['DB']['table_prefix'] . "sessions WHERE user_ip = " . $MPCONF['SES']['user_ip']); ! ! unset($_SESSION['user_array']); ! $_SESSION['user_array'] = $user_array; ! ! $this->AuthAdmin(); ! ! } else { ! ! header("Location: " . $MPCONF['GEN']['uri'] . "/error.php?ecode=auth"); ! ! } ! ! } else { ! header("Location: " . $MPCONF['GEN']['uri'] . "/error.php?ecode=auth"); ! } ! } elseif(!empty($_SESSION['user_array'])) { ! ! $MPCONF['USR'] = $_SESSION['user_array']; ! ! $this->AuthAdmin(); ! ! //} elseif($_COOKIE[$MPCONF['SES']['extcookie']]) { ! ! //$this->mpcookie = $_COOKIE[$MPCONF['SES']['extcookie']]; ! //$authstring = $this->mpcookie; ! ! //$result = $DBA->query('SELECT username FROM ' . $MPCONF['DB']['table_prefix'] . 'users WHERE authstring="' . $authstring . '"'); ! ! //$num_rows = $DBA->num_rows($result); ! //if($num_rows > 0) { ! //$sess_user = $username; ! //$sesskey = $this->getSessKey(); ! //$userdata = $this->FetchUserVars($sess_user); ! ! //$DBA->query("INSERT INTO " . $MPCONF['DB']['table_prefix'] . "sessions (sesskey, expiretime, user_id) VALUES('$sesskey', '" . $this->cookietime . "', " . $userdata['user_id'] . ", )"); ! ! //setcookie($cookiename, $sess_user, $this->cookietime, $MPCONF['GEN']['uri']); ! //return $userdata; ! ! //} else { ! //header("Location: " . $MPCONF['GEN']['abs_path'] . "/error.php?ecode=auth"); ! //} ! } else { ! $sess_user = "Anonymous"; ! $result = $DBA->query('SELECT * FROM ' . $MPCONF['DB']['table_prefix'] . "users WHERE username='Anonymous'"); ! ! $DBA->query("DELETE FROM " . $MPCONF['DB']['table_prefix'] . "sessions WHERE user_ip = " . $MPCONF['SES']['user_ip']); ! ! $this->first_anon = 1; ! ! $user_array = $DBA->fetch_array($result); ! $MPCONF['USR'] = $user_array; ! ! $_SESSION['user_array'] = $user_array; ! } ! ! } ! ! function AuthAdmin() { ! if ($MPCONF['USR']['isadmin'] == 1) { ! ! $MPCONF['USR']['isadmin'] = 1; ! ! if ($MPCONF['USR']['isgod'] == 1) { ! ! $MPCONF['USR']['isadmin'] = 1; ! ! } ! ! return true; ! ! } ! ! } ! ! function Logout() { ! ! global $MPCONF, $DBA; ! ! unset($_SESSION['user_array']); ! $DBA->query('DELETE FROM ' . $MPCONF['DB']['table_prefix'] . 'sessions WHERE sesskey = "' . $_GET['sess_id'] . '"'); ! ! unset($MPCONF['USR']); ! $this->AuthUser(); ! ! } ! ! } ?> --- 1,6 ---- <? ! // Auth and User class/functions. ! // To be developed by Eric. ?> Index: constants.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/constants.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** constants.php 25 Jul 2002 20:50:07 -0000 1.6 --- constants.php 5 Nov 2002 22:11:06 -0000 1.7 *************** *** 1,3 **** --- 1,9 ---- <? + define("CONFIG_TABLE", TABLE_PREFIX . 'config'); + define("USERS_TABLE", TABLE_PREFIX . 'users'); + define("SESSION_TABLE", TABLE_PREFIX . 'sessions'); + define("MODULES_TABLE", TABLE_PREFIX . 'modules'); + define("BLOCK_TABLE", TABLE_PREFIX . 'blocks'); + ?> Index: core.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/core.php,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -r1.20 -r1.21 *** core.php 12 Aug 2002 01:08:29 -0000 1.20 --- core.php 5 Nov 2002 22:11:06 -0000 1.21 *************** *** 1,136 **** <? ! /****************************************************************************** ! ******************************************************************************* ! phpMP - The World's Greatest Modular Portal ! *********************************************** ! Are you MPowered? ! ! Copyright (C) 2002 phpMP Development Group ! All rights reserved. ! ! Lead Programmer: Brian Rose ! Lead Designer: Trevor Joynson ! ! Filename: /includes/core.php ! Usage & Function: Contains PHPMP Class ! Create Date: March 29, 2002 ! ! $Id$ ! ! ******************************************************************************* ! ******************************************************************************* ! ! This software is provided under the GPL software license. A copy of the ! license should have been included with this software, located in the Docs ! folder. Feel free to redistribute and/or modify it according to the ! regulations stated in the license. ! ! ******************************************************************************* ! ******************************************************************************* ! ! Notes on this document: ! Database abstraction classes have been partially taken from jimmacr's phpusion ! project. Some source code has been modified, but most functions do exactly ! the same thing he intended them for. Most likely, this code will be mostly ! rewritten by project release. ! ! ******************************************************************************* ! ******************************************************************************/ ! ! if( !defined('IN_PHPMP') ) { ! ! die("Hacking attempt."); ! ! } ! ! class Debug { //Taken from InvisionBoard and modified lightly. Will replace eventually. ! ! var $starttime; ! var $totaltime; ! ! function startTimer() { ! $mtime = microtime (); ! $mtime = explode (' ', $mtime); ! $mtime = $mtime[1] + $mtime[0]; ! $this->starttime = $mtime; ! } ! function endTimer() { ! $mtime = microtime (); ! $mtime = explode (' ', $mtime); ! $mtime = $mtime[1] + $mtime[0]; ! $endtime = $mtime; ! $totaltime = round (($endtime - $this->starttime), 5); ! $this->totaltime = $totaltime; ! } ! } ! ! $Debug = new Debug(); ! $Debug->startTimer(); ! ! // Main phpMP Class which loads all other files, config options, and modules. ! class PHPMP{ ! ! // Loads all core classes, config files, and variables. ! // Returns: none. ! function Init($core_files="",$var_files="") { ! ! global $MPCONF, $HTTP_GET_VARS; ! ! if($core_files != "") { ! $core_array = explode(',', "$core_files"); // Splits core_files. } ! $core_array[] = 'dba'; ! $core_array[] = 'functions'; ! $core_array[] = 'auth'; ! $core_array[] = 'Smarty.class'; ! $core_array[] = 'template_ext'; ! ! for($i=0; $i < count($core_array); $i++) { ! include($MPCONF['GEN']['abs_path'] . '/includes/' . $core_array[$i] . '.php'); ! } ! ! global $DBA, $Auth, $Functions, $Template, $Language; ! ! $DBA = new DBA(); ! ! $Functions = new Functions(); ! $Functions->GetConfig(); ! ! include_once($MPCONF['GEN']['abs_path'] . '/includes/sessions.php'); ! ! $Auth = new Auth(); ! $Auth->AuthUser(); ! if($HTTP_GET_VARS['logout'] == 'true') { ! $Auth->Logout(); ! } - if($MPCONF['USR']['language'] != '') { - $use_lang = $MPCONF['USR']['language']; - } else { - $use_lang = $MPCONF['TPL']['default_lang']; } ! require($MPCONF['GEN']['abs_path'] . '/languages/' . $use_lang . '/lang_main.php'); ! $Language = new Language(); ! ! $Template = new Template(); ! ! if($var_files != "") { ! $var_array = explode(',', "$var_files"); // Splits var_files. ! } ! $var_array[] = 'constants'; ! ! for($i=0; $i < count($var_array); $i++) { ! include($MPCONF['GEN']['abs_path'] . '/includes/' . $var_array[$i] . '.php'); ! } } } ?> --- 1,77 ---- <? ! class Core ! { ! // Initiates configuration from database. ! // Author: Brian 'Heimidal' Rose ! // Accepts: none. ! // Returns: Boolean - true ! function _initConfig () ! { ! ! global $DB; ! $sql = "SELECT * FROM " . CONFIG_TABLE; ! $result = $DBA->query( $sql ); ! ! while( $row = $DB->fetch_array( $result ) ) ! { ! define( $row['key'], $row['value'] ); } ! return true; ! ! } ! ! // Initiates all core components. ! // Author: Brian 'Heimidal' Rose ! // Accepts: $required_files (string of needed files separated by commas). ! // Returns: Boolean - true ! function init ( $required_files ) ! { ! ! $required_array = explode( $required_files, '' ); ! ! $required_array[] = 'debug'; ! $required_array[] = 'constants'; ! $required_array[] = 'dba'; ! $required_array[] = 'functions'; ! $required_array[] = 'auth'; ! $required_array[] = 'parser'; ! $required_array[] = 'Smarty.class'; ! $required_array[] = 'template'; ! ! $i = 0; ! while( $my_file = $required_array[$i] ) ! { ! include_once('./includes/' . $my_file . '.php'); ! $i++; } ! global $Debug, $DB, $Auth, $Parser, $Template, $Language; ! $Debug = new Debug(); ! $DB = new DBA(); ! $DBA->connect; + $this->_initConfig(); + } + } + // Main Class + // -- Init Function + // -- -- Debug + // -- -- Globals + // -- -- Require Files + // -- -- Load Constants + // -- -- Initiate DBA + // -- -- Load DB-based Config + // -- -- Load Language Files + // -- -- Authenticate User + // -- -- Initiate Template Engine ?> Index: dba.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/dba.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** dba.php 23 Apr 2002 08:14:55 -0000 1.6 --- dba.php 5 Nov 2002 22:11:06 -0000 1.7 *************** *** 1,43 **** <? ! /****************************************************************************** ! ******************************************************************************* ! ! phpMP - The World's Greatest Modular Portal ! *********************************************** ! Are you MPowered? ! ! Copyright (C) 2002 phpMP Development Group ! All rights reserved. ! ! Lead Programmer: Brian Rose ! Lead Designer: Trevor Joynson ! ! Filename: /includes/dba.php ! Usage & Function: DBA Initialisation Module ! Create Date: March 29, 2002 ! ! $Id$ ! ! ******************************************************************************* ! ******************************************************************************* ! ! This software is provided under the GPL software license. A copy of the ! license should have been included with this software, located in the Docs ! folder. Feel free to redistribute and/or modify it according to the ! regulations stated in the license. ! ! ******************************************************************************* ! ******************************************************************************/ ! ! switch( $MPCONF['DB']['host_type'] ) { ! case 'mysql': ! include($MPCONF['GEN']['abs_path'] . '/dba/' . $MPCONF['DB']['host_type'] . '.dba'); ! break; ! case '': ! die('Please open the config.php file and edit the values to reflect your server setup in order to use phpMP.'); ! default: ! die('We apologize, but the DB you are attempting to use is not supported by phpMP. Please review your config.php settings to ensure they are correct.'); ! } ?> --- 1,6 ---- <? ! // Handles Database Abstraction. ! // Essentially, this file decides what layer to load. ?> Index: functions.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/functions.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -r1.12 -r1.13 *** functions.php 14 Aug 2002 19:45:46 -0000 1.12 --- functions.php 5 Nov 2002 22:11:06 -0000 1.13 *************** *** 1,115 **** <? ! /****************************************************************************** ! ******************************************************************************* ! ! phpMP - The World's Greatest Modular Portal ! *********************************************** ! Are you MPowered? ! ! Copyright (C) 2002 phpMP Development Group ! All rights reserved. ! ! Lead Programmer: Brian Rose ! Lead Designer: Trevor Joynson ! ! Filename: /includes/functions.php ! Usage & Function: Contains Functions Class ! Create Date: March 29, 2002 ! ! $Id$ ! ! ******************************************************************************* ! ******************************************************************************* ! ! This software is provided under the GPL software license. A copy of the ! license should have been included with this software, located in the Docs ! folder. Feel free to redistribute and/or modify it according to the ! regulations stated in the license. ! ! ******************************************************************************* ! ******************************************************************************/ ! ! // A Class that contains all functions that belong no where else. ! class Functions { ! ! ! function encode_ip($dotquad_ip) { ! $ip_sep = explode('.', $dotquad_ip); ! return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]); ! } ! ! function decode_ip($int_ip) { ! $hexipbang = explode('.', chunk_split($int_ip, 2, '.')); ! return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]); ! } ! ! // Gathers configuration info stored in database. ! // Returns: none. ! function GetConfig() { ! global $MPCONF, $DBA; ! $sql = "SELECT * FROM " . $MPCONF['DB']['table_prefix'] . "config"; ! $db = $DBA->query($sql); ! while($row = $DBA->fetch_array($db)) { ! $MPCONF[$row['type']][$row['name']] = $row["value"]; ! } ! ! global $REMOTE_ADDR; ! if( getenv('HTTP_X_FORWARDED_FOR') != '' ) { ! $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR ); ! ! if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", getenv('HTTP_X_FORWARDED_FOR'), $ip_list) ) { ! $private_ip = array('/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.16\..*/', '/^10..*/', '/^224..*/', '/^240..*/'); ! $client_ip = preg_replace($private_ip, $client_ip, $ip_list[1]); ! } ! } else { ! $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR ); ! } ! ! $MPCONF['SES']['user_ip'] = $this->encode_ip($client_ip); ! ! } ! ! function createHash($length=32, $pool="") { ! if($pool == ""){ ! $pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ! $pool .= "abcdefghijklmnopqrstuvwxyz"; ! $pool .= "0123456789"; ! } ! mt_srand ((double) microtime() * 1000000); ! $unique_id = ""; ! for ($index = 0; $index < $length; $index++) { ! $unique_id .= substr($pool, (mt_rand()%(strlen($pool))), 1); ! } ! return $unique_id; ! } ! ! } ! ! class ModFunctions { ! ! // Changes the data string in the database for the module specified. ! // Returns: 1 on success, 0 on failure. ! function ChangeDataString($mod, $string) { ! global $DBA; ! $sql = "UPDATE " . $MPCONF['DB']['table_prefix'] . "modules SET data='" . $string . "'WHERE unixname='" . $mod . "'"; ! if($DBA->query($sql)) { ! return 1; ! } else { ! return 0; ! } ! } ! ! // Fetches the data stored by a module. ! // Returns: data string. ! function FetchDataString($mod, $string) { ! global $DBA; ! $sql = "SELECT data FROM " . $MPCONF['DB']['table_prefix'] . "modules WHERE unixname='" . $mod; ! $db = $DBA->query($sql); ! $result = $DBA->fetch_array($db); ! return $result[0]; ! } ! ! } ?> --- 1,5 ---- <? ! // File for functions that go nowhere in particular. ?> Index: parser.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/parser.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** parser.php 23 Apr 2002 08:14:55 -0000 1.5 --- parser.php 5 Nov 2002 22:11:06 -0000 1.6 *************** *** 1,1372 **** <? ! /****************************************************************************** ! ******************************************************************************* - phpMP - The World's Greatest Modular Portal - *********************************************** - Are you MPowered? - - Copyright (C) 2002 phpMP Development Group [...1349 lines suppressed...] - if (!function_exists("array_values")) - { - $t = array(); - while (list($k, $v) = each ($arr)) - $t[] = $v; - return $t; - } - else - return array_values($arr); - } - - } ?> --- 1,6 ---- <? ! // Content parsing functions to be developed here. ! // These work similarly to BBCode and the like. ?> Index: sessions.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/sessions.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** sessions.php 14 Aug 2002 19:45:46 -0000 1.5 --- sessions.php 5 Nov 2002 22:11:06 -0000 1.6 *************** *** 1,101 **** <? - /****************************************************************************** - ******************************************************************************* ! phpMP - The World's Greatest Modular Portal ! *********************************************** ! Are you MPowered? ! ! Copyright (C) 2002 phpMP Development Group ! All rights reserved. ! ! Lead Programmer: Brian Rose ! Lead Designer: Trevor Joynson ! ! Filename: /includes/sessions.php ! Usage & Function: Contains Session Handlers ! Create Date: July 26, 2002 ! ! $Id$ ! ! ******************************************************************************* ! ******************************************************************************* ! ! This software is provided under the GPL software license. A copy of the ! license should have been included with this software, located in the Docs ! folder. Feel free to redistribute and/or modify it according to the ! regulations stated in the license. ! ! ******************************************************************************* ! ******************************************************************************* ! ! Notes on this document: ! Database abstraction classes have been partially taken from jimmacr's phpusion ! project. Some source code has been modified, but most functions do exactly ! the same thing he intended them for. Most likely, this code will be mostly ! rewritten by project release. ! ! ******************************************************************************* ! ******************************************************************************/ ! ! ini_set ( "session.save_handler", "user"); ! ! function sess_open ($save_path, $session_name) { ! return true; ! } ! ! function sess_close() { ! return true; ! } ! ! function sess_read ($sesskey) { ! global $MPCONF, $DBA; ! ! $session_data = $DBA->query("SELECT data FROM " . $MPCONF['DB']['table_prefix'] . "sessions WHERE sesskey = '$sesskey' AND expiretime > " . time()) or die(db_error_message()); ! if (list($value) = $DBA->fetch_row($session_data)) { ! return $value; ! } else { ! return ''; ! } ! } ! ! function sess_write ($sesskey, $val) { ! global $MPCONF, $DBA; ! ! $expiry = time() + $MPCONF['SES']['session_length']; ! $value = addslashes($val); ! ! $retval = $DBA->query("UPDATE " . $MPCONF['DB']['table_prefix'] . "sessions SET data = '$value', user_id = '" . $MPCONF['USR']['user_id'] . "', time_started = '" . time() . "' expiretime = '" . $expiry . "' WHERE sesskey = '$sesskey'"); ! ! if(!($retval)) { ! $retval = $DBA->query("INSERT INTO " . $MPCONF['DB']['table_prefix'] . "sessions (sesskey, user_id, user_ip, time_started, expiretime, data) VALUES ('$sesskey', '" . $MPCONF['USR']['user_id'] . "', '" . $MPCONF['SES']['user_ip'] . "', '" . time() . "', '" . $expiry . "', '$value')"); ! } ! ! return $retval; ! } ! ! function sess_destroy ($sesskey) { ! global $MPCONF, $DBA; ! ! $retval = $DBA->query("DELETE FROM " . $MPCONF['DB']['table_prefix'] . "sessions WHERE sesskey = '$sesskey'"); ! return $retval; ! } ! ! function sess_gc ($maxlifetime) { ! global $MPCONF, $DBA; ! ! $retval = $DBA->query("DELETE FROM " . $MPCONF['DB']['table_prefix'] . "sessions WHERE expiretime < " . time()); ! ! return $DBA->affected_rows(); ! } ! ! session_set_save_handler ( ! 'sess_open', ! 'sess_close', ! 'sess_read', ! 'sess_write', ! 'sess_destroy', ! 'sess_gc' ! ); ?> --- 1,6 ---- <? ! // Session Management. ! // To be developed by Eric. ?> |