get basic login functionality going, some minor code cleanup, more to follow

git-svn-id: svn://10.0.0.236/trunk@186497 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
robert%accettura.com
2005-12-23 00:43:57 +00:00
parent 6cc597430a
commit dcac69edca
8 changed files with 199 additions and 187 deletions

View File

@@ -35,85 +35,44 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
require_once("../../config.inc.php");
require_once('DB.php');
require_once($config['app_path'].'/includes/iolib.inc.php');
require_once($config['app_path'].'/includes/security.inc.php');
// Start Session
require_once('../../config.inc.php');
require_once($config['base_path'].'/includes/iolib.inc.php');
require_once($config['base_path'].'/includes/db.inc.php');
require_once($config['base_path'].'/includes/contrib/smarty/libs/Smarty.class.php');
require_once($config['base_path'].'/includes/security.inc.php');
// start the session
session_name('reportSessID');
session_start();
header("Cache-control: private"); //IE 6 Fix
printheaders();
include($config['app_path'].'/includes/header.inc.php');
include($config['app_path'].'/includes/message.inc.php');
if (isset($_POST['redirect'])){
$redirect = $_POST['redirect'];
}
else if (isset($_GET['redirect'])){
$redirect = $_GET['redirect'];
}
else {
$redirect = $config['app_url'];
}
if ($_SESSION['login'] != true){
// submit form?
if (isset($_POST['submit_login'])){
if(isset($_POST['do_login'])){
$login = false;
// Open DB
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleErrors');
$db =& DB::connect($config['db_dsn']);
$db = NewDBConnection($config['db_dsn']);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$loginCheck = false;
$loginCheck = $userlib->login($_POST['username'], $_POST['password']);
$login = $securitylib->login($_POST['username'], $_POST['password']);
// disconnect database
$db->disconnect();
$db->Close();
if ($loginCheck[0] == true){
header("Location: ".$redirect);
exit;
} else {
$error = true;
?>Login Failed<?php
}
}
?>
<table>
<tr>
<td>
<fieldset>
<legend>Login</legend>
<form method="post" action ="<?php print $config['app_url']; ?>/login/" ID="login">
<table>
<tr>
<td><label for="username">Username: </label></td>
<td><input type="text" id="username" name="username" <?php if ($error == true){ print 'value="'.$_POST['username'].'" ';}?>/></td>
</tr>
<tr>
<td><label for="password">Password: </label></td>
<td><input type="password" id="password" name="password" /></td>
</tr>
</table>
<input type="hidden" id="redirect" name="redirect" value="<?php print $redirect; ?>" />
<input type="submit" id="submit_login" name="submit_login" value="Login" />
</form>
</fieldset>
</td>
<td valign="top">
<h5>Administrator Login</h5>
<p>Contact <a href="http://robert.accettura.com/contact/?subject=Reporter%20Access%20Request">Robert Accettura</a> if you need an admin account. This is for special circumstances only.</p>
</td>
</tr>
</table>
<?
if($login === true){
header('Location: '.$config['base_url']);
exit;
}
$content = initializeTemplate();
$content->assign('error', 'Incorrect Username or Password');
}
if(!isset($content)){
$content = initializeTemplate();
}
displayPage($content, 'login', 'login.tpl');
exit;
} else {
header("Location: ".$redirect);
header('Location: '.$config['base_url']);
}
include($config['app_path'].'/includes/footer.inc.php');
?>
?>

View File

@@ -37,7 +37,7 @@
* ***** END LICENSE BLOCK ***** */
require_once('../../config.inc.php');
require_once($config['app_path'].'/includes/iolib.inc.php');
require_once($config['base_path'].'/includes/iolib.inc.php');
// start the session
session_name('reportSessID');
@@ -48,16 +48,10 @@ printheaders();
$_SESSION = array();
session_destroy();
if (isset($_GET['redirect'])){
$redirect = $_GET['redirect'];
} else {
$redirect = $config['app_url'];
}
if($_SESSION['username']){
// not sure if this could ever happen, but just incase.
// not sure if this could ever happen, but just in case.
echo 'Failed to logout';
} else {
header("Location: ".$redirect);
header("Location: ".$config['base_url']);
}
?>

View File

@@ -1,140 +1,139 @@
body {
margin: 0 30px 2em 30px;
color: #333;
background: #fff url("img/body_back.gif") repeat-x;
font-size: 100%;
margin: 0 30px 2em 30px;
color: #333;
background: #fff url("img/body_back.gif") repeat-x;
font-size: 100%;
}
body, td, th, h3, input, pre { /* redundant rules for bad browsers */
font-family: verdana, sans-serif;
voice-family: "\"}\"";
voice-family: inherit;
font-family: verdana, sans-serif;
voice-family: "\"}\"";
voice-family: inherit;
}
#container {
width: 100%;
margin: 0 auto;
width: 100%;
margin: 0 auto;
}
#page {
padding: 15px 0 0 0;
padding: 15px 0 0 0;
}
#content {
background: url("img/page-background.gif") repeat-x top left;
font-size: 0.8em;
background: url("img/page-background.gif") repeat-x top left;
font-size: 0.8em;
}
#mozilla-org {
position: relative;
height: 25px;
position: relative;
height: 25px;
}
#mozilla-org a {
position: absolute;
right: 0;
top: 0;
display: block;
width: 110px;
height: 25px;
background: url("img/mozilla-org.gif") no-repeat;
text-decoration: none;
text-indent: -5000em;
position: absolute;
right: 0;
top: 0;
display: block;
width: 110px;
height: 25px;
background: url("img/mozilla-org.gif") no-repeat;
text-decoration: none;
text-indent: -5000em;
}
.skipLink {
display: none;
display: none;
}
#reporterSearch label {
font-weight: bold;
font-weight: bold;
}
#reporterSearch .label {
text-align: right;
text-align: right;
}
#reporterQuery {
font-size: 0.9em;
font-size: 0.9em;
}
#reporterQuery .header {
background-color: #ddd;
color: #666;
text-align: left;
background-color: #ddd;
color: #666;
text-align: left;
}
#reporterQuery .header a {
color: #666;
text-decoration: none;
color: #666;
text-decoration: none;
}
#reporterQuery td {
border-bottom: 1px solid #eee;
padding: 1px 0 1px 0;
font-size: 0.9em;
border-bottom: 1px solid #eee;
padding: 1px 0 1px 0;
font-size: 0.9em;
}
#reporterReport .header{
background-color: #eee;
width: 100%;
text-align: center;
font-weight: bold;
padding: 4px 0 4px 0;
background-color: #eee;
width: 100%;
text-align: center;
font-weight: bold;
padding: 4px 0 4px 0;
}
#reporterReport div {
margin-bottom: 3px;
margin-bottom: 3px;
}
#reporterReport .title {
float: left;
width: 9em;
padding: 0 .5em;
text-align: right;
font-weight: bold;
float: left;
width: 9em;
padding: 0 .5em;
text-align: right;
font-weight: bold;
}
#reporterReport .data {
overflow: auto;
overflow: auto;
}
#header{
margin: 20px 0 16px 0;
bottom: 1px solid #eee;
}
#header h1 {
display: inline;
font-size: 2.2em;
}
#header{
margin: 20px 0 16px 0;
bottom: 1px solid #eee;
}
#header h1 {
display: inline;
font-size: 2.2em;
}
#header #logo {
margin: 0;
float: left;
width: 500px;
}
#header #logo {
margin: 0;
float: left;
width: 500px;
}
#header #logo a {
text-decoration: none;
color: #000;
}
#header #logo a {
text-decoration: none;
color: #000;
}
#header a img {
border: 0;
}
#header #navbox {
float: right;
margin-top: 8px;
margin-right: 15px;
#header a img {
border: 0;
}
#header #navbox {
float: right;
margin-top: 8px;
margin-right: 15px;
background-color: #eee;
border: 1px solid #333;
font-size: 0.8em;
}
}
#navbox ul {
padding: 0 0 0 8px;
}
#navbox li {
#navbox ul {
padding: 0 0 0 8px;
}
#navbox li {
display: inline;
margin: 0;
padding: 0 8px 0 0;
@@ -143,24 +142,46 @@ body, td, th, h3, input, pre { /* redundant rules for bad browsers */
}
.navigation {
text-align: center;
margin: 12px auto 5px auto;
text-align: center;
margin: 12px auto 5px auto;
}
.navigation .currentPage {
font-weight: bold;
font-weight: bold;
}
.navigation a {
text-decoration: none;
color: #000;
text-decoration: none;
color: #000;
}
.navigation a:hover {
border-bottom: 2px solid #000;
border-bottom: 2px solid #000;
}
#login_form label{
float: left;
width: 9em;
padding: 0 .5em;
text-align: right;
font-weight: bold;
}
#login_leftcol{
float: left;
width: 45%;
padding: 2px 9px 5px 9px;
}
#login_rightcol {
float: right;
width: 45%;
padding: 2px 9px 5px 9px;
}
/*
#reporter_note {
border: 1px solid #ccc;
background: #eee;

View File

@@ -61,12 +61,12 @@ function initializeTemplate(){
function templateStandardVars($object){
global $config, $userlib;
global $config, $securitylib;
$object->assign('base_url', $config['base_url']);
$object->assign('app_url', $config['base_url'].'/app');
$object->assign('charset', 'utf-8');
$object->assign('is_admin', $userlib->isLoggedIn());
$object->assign('is_admin', $securitylib->isLoggedIn());
return $object;
}
@@ -117,7 +117,7 @@ function strMiddleReduceWordSensitive($string, $max = 50, $rep = '[...]') {
}
return $return;
return substr($string, 0, $start) . $rep . substr($string, - $end);
}
}
function resolveProblemTypes($q){
global $problemTypes;

View File

@@ -36,32 +36,38 @@
*
* ***** END LICENSE BLOCK ***** */
class userlib {
class securitylib {
function login($username, $password){
global $db;
function login($username, $password){
global $db;
$data =& $db->getRow("SELECT user.user_id, user.user_username, user.user_password, user.user_realname, user.user_status
FROM user
WHERE user.user_username = ".$db->quote($username)." AND user.user_password = md5(".$db->quote($password).")", DB_FETCHMODE_ASSOC);
if ($data['user_status'] == 1){
$_SESSION['user_id'] = $data['user_id'];
$_SESSION['user_realname'] = $data['user_realname'];
$_SESSION['user_username'] = $data['user_username'];
$_SESSION['login'] = true;
return array(true, '');
$data = $db->Execute("SELECT user.user_id, user.user_username, user.user_password, user.user_realname, user.user_status
FROM user
WHERE user.user_username = ".$db->quote($username)."
AND user.user_password = PASSWORD(".$db->quote($password).")
AND user.user_status = 1");
if(!$data || $data->EOF){
return false;
}
if ($data->fields['user_status'] == 1){
$_SESSION['user_id'] = $data->fields['user_id'];
$_SESSION['user_realname'] = $data->fields['user_realname'];
$_SESSION['user_username'] = $data->fields['user_username'];
$_SESSION['login'] = true;
session_regenerate_id();
return true;
}
return false;
}
return array(false, 'Bad Status');
}
function isLoggedIn(){
if ($_SESSION['user_username'] && $_SESSION['login'] == true){
return true;
function isLoggedIn(){
if ($_SESSION['user_username'] && $_SESSION['login'] == true){
return true;
}
return false;
}
return false;
}
// End Class
}
$userlib = new userlib;
?>
$securitylib = new securitylib;
?>

View File

@@ -23,7 +23,13 @@
</div>
<div id="navbox">
<ul>
<li id="login"><a href="{$base_url}/app/login" title="Admin Login">Login</a></li>
<li id="login">{strip}
{if $is_admin == true}
<a href="{$base_url}/app/logout" title="Admin Logout">Logout</a>
{else}
<a href="{$base_url}/app/login" title="Admin Login">Login</a>
{/if}
{/strip}</li>
<li id="stats"><a href="{$base_url}/app/stats/" title="View Statistics">Stats</a></li>
<li id="top_25"><a href="{$base_url}/app/query/?show=25&count=on&&submit_query=Search" title="Top 25 Hosts">Top 25</a></li>
<li id="query"><a href="{$base_url}/app" title="Create a new Query">Query</a></li>

View File

@@ -0,0 +1,26 @@
<div id="login_leftcol">
<form method="post" action="{$base_url}/app/login/" id="login_form">
<fieldset>
<legend>Login</legend>
{if $error != ''}
<p>{$error}</p>
{/if}
<div>
<label for="username">Username:</label>
<input type="text" name="username" id="username" />
</div>
<div>
<label for="password">Password:</label>
<input type="password" name="password" id="password" />
</div>
<div>
<input type="submit" name="do_login" id="do_login" value="Login" />
</div>
</fieldset>
</form>
</div>
<div id="login_rightcol">
<p>If you need access to this system, contact <a href="http://robert.accettura.com/contact">Robert Accettura</a>.</p>
<p>Login Access is only given in special circumstances.</p>
</div>
<br style="clear: both;" />

View File

@@ -53,11 +53,11 @@
{if $is_admin == true}
<div>
<div class="title">Email:</div>
<div class="data">{$report_email}</div>
<div class="data">{$report_email}&nbsp; {*this space at the end fixes some formatting issues with no text in this optional field *}</div>
</div>
<div>
<div class="title">IP Address:</div>
<div class="data"><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput={$report_ip}" rel="external" target="_blank" title="Lookup IP: {$report_ip}">{$report_ip}</a></div>
<div class="data"><a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput={$report_ip}" rel="external" target="_blank" title="Lookup IP: {$report_ip}">{$report_ip}</a>&nbsp; {*this space at the end fixes some formatting issues with no text in this optional field *}</div>
</div>
{/if}
<div>