From: <ope...@li...> - 2002-06-25 03:18:56
|
Update of /cvsroot/openposs/Server In directory usw-pr-cvs1:/tmp/cvs-serv5997 Modified Files: config.php database.php index.php Log Message: Added basic user authentication. Index: config.php =================================================================== RCS file: /cvsroot/openposs/Server/config.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** config.php 12 Apr 2002 11:44:30 -0000 1.4 --- config.php 25 Jun 2002 03:18:53 -0000 1.5 *************** *** 18,22 **** $DBConfig['Server']="localhost"; $DBConfig['UserName']="root"; ! $DBConfig['Password']="openPOS"; $DBConfig['DBName']="openPOS"; $DBConfig['DBType']="mysql"; --- 18,22 ---- $DBConfig['Server']="localhost"; $DBConfig['UserName']="root"; ! $DBConfig['Password']=""; $DBConfig['DBName']="openPOS"; $DBConfig['DBType']="mysql"; Index: database.php =================================================================== RCS file: /cvsroot/openposs/Server/database.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** database.php 12 Apr 2002 11:44:30 -0000 1.2 --- database.php 25 Jun 2002 03:18:53 -0000 1.3 *************** *** 20,24 **** function DBInit() { ! global $DBConfig; // Assign the database connection information to variables. --- 20,24 ---- function DBInit() { ! global $DBConfig, $SystemConfig; // Assign the database connection information to variables. *************** *** 39,47 **** die("Failed to connect to $DBType://$DBUserName:$DBPassword@$DBServer/$DBName\n".$DBConn->ErrorMsg()); } - // We have a connection and handle on the database. global $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; - $sql = "SELECT Value FROM Configuration WHERE Parameter='DBVersion'"; $results = $DBConn->Execute($sql); --- 39,45 ---- *************** *** 54,58 **** } } ! return true; } --- 52,61 ---- } } ! // OK, Lets load the system config. ! $sql = "SELECT Parameter, Value FROM Configuration WHERE Parameter <> 'DBVersion'"; ! $results = $DBConn->Execute($sql); ! while(list($Param, $Value) = $results->FetchRow()) { ! $SystemConfig[$Param] = $Value; ! } return true; } *************** *** 63,66 **** --- 66,84 ---- return true; + } + + function Validate_Password($UserName, $Password) { + GLOBAL $DBConn; + $ret_val = 0; + $sql = "SELECT Password FROM SystemUsers WHERE UserName=\"$UserName\""; + $result = $DBConn->Execute($sql); + if ($result->NumRows() > 0) { + list($pw) = $result->fields; + $pword = md5($Password); + if (strcmp($pw, $pword) == 0) { + $ret_val = 1; + } + } + return $ret_val; } Index: index.php =================================================================== RCS file: /cvsroot/openposs/Server/index.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** index.php 17 Apr 2002 11:55:18 -0000 1.3 --- index.php 25 Jun 2002 03:18:53 -0000 1.4 *************** *** 24,27 **** --- 24,42 ---- include_once("database.php"); + /****************************************************************************** + * Function: ReadConfigFromDatabase() * + * -------------------------------------------------------------------------- * + * This function is used to read the configuration from the database table * + * openPOS.Configuration. * + * * + * Returned Values * + * None. * + * * + * Input Values * + * None. * + ******************************************************************************/ + function ReadConfigFromDatabase() { + + } /****************************************************************************** *************** *** 32,36 **** * * * Returned Values * ! * None. * * * * Input Values * --- 47,51 ---- * * * Returned Values * ! * HTML Page text to return to the client. * * * * Input Values * *************** *** 38,45 **** ******************************************************************************/ function DisplayMainMenu() { ! global $HTMLOutput; ! $HTMLOutput = "<HTML><HEAD><TITLE>"; ! $HTMLOutput .= _OPENPOSTITLE."</TITLE></HEAD><BODY><DIV ALIGN=\"center\"><H1>"._OPENPOSMAINTITLE."</H1></DIV>"; ! $HTMLOutput .= "</BODY></HTML>"; } --- 53,81 ---- ******************************************************************************/ function DisplayMainMenu() { ! GLOBAL $UserName; ! $Output = Theme_Open_Page(_OPENPOSMAINTITLE); ! $Output .= Theme_Open_Table("99%"); ! $Output .= Theme_Open_Row(); ! $Output .= Theme_Open_Data_Cell("Right", "15%"); ! if (isset($UserName)) { ! $Output .= $UserName." Logged In<br>"; ! } else { ! $Output .= "Not Logged In<br>"; ! } ! $Output .= "<br><br><B>" . _OPENPOSNAVTITLE . "</B><br>"; ! if ( strcmp($SystemConfig['modUserLogin'], "On")) { ! if (isset($UserName)) { ! $Output .= Theme_Add_Link("/Server/?action=logout", "Logout") . "<br>"; ! } else { ! $Output .= Theme_Add_Link("/Server/?action=login", "Login") . "<br>"; ! } ! } ! $Output .= Theme_Add_Link("/Server/?action=admin", _OPENPOSADMINTITLE ); ! $Output .= Theme_Close_Data_Cell().Theme_Open_Data_Cell(); ! $Output .= Theme_Close_Data_Cell(); ! $Output .= Theme_Close_Row(); ! $Output .= Theme_Close_Table(); ! $Output .= Theme_Close_Page(); ! return $Output; } *************** *** 51,55 **** * * * Returned Values * ! * None. * * * * Input Values * --- 87,91 ---- * * * Returned Values * ! * HTML Page text to return to the client. * * * * Input Values * *************** *** 57,66 **** ******************************************************************************/ function DisplayAdminMenu() { ! global $HTMLOutput; ! $HTMLOutput = "<HTML><HEAD><TITLE>"; ! $HTMLOutput .= _OPENPOSTITLE."</TITLE></HEAD><BODY><DIV ALIGN=\"center\"><H1>"._OPENPOSADMINTITLE."</H1></DIV>"; ! $HTMLOutput .= "</BODY></HTML>"; } /****************************************************************************** --- 93,167 ---- ******************************************************************************/ function DisplayAdminMenu() { ! $Output = Theme_Open_Page(_OPENPOSADMINTITLE); ! $Output .= Theme_Close_Page(); ! return $Output; ! } ! ! /****************************************************************************** ! * Function: DisplayError() * ! * -------------------------------------------------------------------------- * ! * This function will display the administration menu when the user is * ! * accessing the system via a web browser. * ! * * ! * Returned Values * ! * HTML Page text to return to the client. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function DisplayError() { ! $Output = Theme_Open_Page( _OPENPOSERRORTITLE ); ! $Output .= "<DIV ALIGN=\"CENTER\"><H3>ERROR: Incorrect Parameters sent to the server. Please contact your support section.</H3></DIV>"; ! $Output .= Theme_Close_Page(); ! return $Output; ! } ! ! /****************************************************************************** ! * Function: ProcessLoginRequest() * ! * -------------------------------------------------------------------------- * ! * This function will display the administration menu when the user is * ! * accessing the system via a web browser. * ! * * ! * Returned Values * ! * HTML Code to log the user in. This code is generated from the theme.php * ! * file. This way the login screen can be customised. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function ProcessLoginRequest() { ! GLOBAL $Action, $UserName, $Password; ! // Validate the password against the database, and if all is well ! // we will create a cookie, and return to the main menu. ! if (Validate_Password($UserName, $Password) == 1) { ! setcookie("openPOSAuthTok", $UserName, time()+3600); ! } ! header("HTTP/1.0 303 See Other"); ! header("Location: /Server/"); ! return; } + /****************************************************************************** + * Function: ProcessLogoutRequest() * + * -------------------------------------------------------------------------- * + * This function will display the administration menu when the user is * + * accessing the system via a web browser. * + * * + * Returned Values * + * None. * + * * + * Input Values * + * None. * + ******************************************************************************/ + function ProcessLogoutRequest() { + GLOBAL $Action, $UserName; + if (isset($UserName)) { + setcookie("openPOSAuthTok", $UserName, time()-3600); + header("HTTP/1.0 303 See Other"); + header("Location: /Server/"); + unset($UserName); + } + return; + } /****************************************************************************** *************** *** 76,80 **** * None. * ******************************************************************************/ ! global $HTMLOutput, $OutputLang, $Action; if (!DBInit()) { die("Unable to connect to the database."); --- 177,182 ---- * None. * ******************************************************************************/ ! global $HTMLOutput, $OutputLang, $Action, $OutputTheme, $SystemConfig; ! global $UserName, $Password; if (!DBInit()) { die("Unable to connect to the database."); *************** *** 82,85 **** --- 184,188 ---- $OutputLang=$HTTP_GET_VARS["lang"]; $Action=$HTTP_GET_VARS["action"]; + $OutputTheme=$HTTP_GET_VARS["theme"]; if (!isset($Action)) { $Action="none"; *************** *** 88,103 **** $OutputLang="eng"; } include_once ("language/$OutputLang/global.php"); switch ($Action) { ! case "none": ! DisplayMainMenu(); ! break; case "admin": ! DisplayAdminMenu(); ! break; } if (!DBClose()) { die("Unable to disconnect from the database."); } ! echo $HTMLOutput; ?> --- 191,229 ---- $OutputLang="eng"; } + if (!isset($OutputTheme)) { + $OutputTheme="Default"; + } + if (isset($openPOSAuthTok)) { + $UserName = $openPOSAuthTok; + } + include_once ("theme/$OutputTheme/theme.php"); include_once ("language/$OutputLang/global.php"); switch ($Action) { ! case "login": ! $HTMLOutput = Theme_Login_Screen(); ! break; ! case "submitlogin": ! $UserName=$HTTP_GET_VARS["username"]; ! $Password=$HTTP_GET_VARS["password"]; ! ProcessLoginRequest(); ! break; ! case "logout": ! ProcessLogoutRequest(); ! break; ! case "none": ! $HTMLOutput = DisplayMainMenu(); ! break; case "admin": ! $HTMLOutput = DisplayAdminMenu(); ! break; ! default: ! $HTMLOutput = DisplayError(); ! break; } if (!DBClose()) { die("Unable to disconnect from the database."); } ! if (isset($HTMLOutput)) { ! echo $HTMLOutput; ! } ?> |