Commit 41708354 authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Moved files around for security and organization

- Add in javascript to templates
- Switch to a "sticky header/footer" design
- Some layout changes on the login screen
- Code cleanup
- New page for reports
parent 52df9500
PHP > 5.3.7 (5.3.3 on RHEL)
bower install jquery
bower install jqueryui
bower install bootstrap
composer install
<?php
/* Skynet - Automated "Cloud" Security Scanner *#
#* Copyright (C) 2014-present Jason Frisvold <friz@godshell.com> *#
#* *#
#* This program is free software; you can redistribute it and/or modify *#
#* it under the terms of the GNU General Public License as published by *#
#* the Free Software Foundation; either version 2 of the License, or *#
#* (at your option) any later version. *#
#* *#
#* This program is distributed in the hope that it will be useful, *#
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *#
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *#
#* GNU General Public License for more details. *#
#* *#
#* You should have received a copy of the GNU General Public License *#
#* along with this program; if not, write to the Free Software *#
#* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
// Define skynet (to allow access to files)
define('skynet', 1);
// Define usesmarty (to indicate that config needs to load smarty)
define('usesmarty', 1);
// Load the configuration file
require_once("config.php");
// Connect to the database server
$sqlhdlr = new mysqli($skynet_dbHost, $skynet_dbUser, $skynet_dbPass,
$skynet_dbName);
// Make sure we have a connection
if (mysqli_connect_errno()) {
die( '<p>Unable to connect to the database server at this time: ' .
mysqli_connect_error() . ' </p>' );
}
// If the user is not authenticated, jump them to the home page
if (! $user_obj = authenticate()) {
$smarty->assign('username', 'guest');
}
// Close the SQL Handler
$sqlhdlr->close();
$smarty->display('about.tpl');
?>
......@@ -24,15 +24,10 @@ session_start();
function login($username, $password) {
// Globalize the phptodo variables needed
//global $skynet_dbHost, $skynet_dbUser, $skynet_dbPass, $skynet_dbName,
// $skynet_sessTime, $sqlhdlr;
global $skynet_sessTime, $sqlhdlr;
// Create user class
//$user_obj = new skynetUser($skynet_dbHost, $skynet_dbUser,
// $skynet_dbPass, $skynet_dbName,
// -1, $username, $password, true);
$user_obj = new skynetUser(-1, $username, $password, true);
$user_obj = new skynetUser($sqlhdlr, -1, $username, $password, true);
if ($user_obj->logged_in()) {
// Regenerate the session ID (security enhancement)
......@@ -47,23 +42,12 @@ function login($username, $password) {
'last' => time()
));
//$query = sprintf('INSERT INTO sessions (phpsessid, user_id, last) ' .
// 'VALUES ("%s", "%s", %d)', session_id(),
// $user_obj->user_id(), time());
//
//$sqlhdlr->query($query) or die( 'Error: ' . $sqlhdlr->error );
// Clean up any old sessions that have timed out
$sqlhdlr->table('sessions')
->where('last', '<', time() - $skynet_sessTime)
->delete();
//$query = sprintf('DELETE FROM sessions WHERE last < %d', time() -
// $skynet_sessTime);
//
//$sqlhdlr->query($query) or die( 'Error: ' . $sqlhdlr->error );
// Return 1 indicating a successful login
return 1;
} else {
......@@ -78,13 +62,9 @@ function login($username, $password) {
function authenticate() {
// Globalize the phptodo variables needed
//global $skynet_dbHost, $skynet_dbUser, $skynet_dbPass, $skynet_dbName,
// $skynet_sessTime, $sqlhdlr;
global $skynet_sessTime, $smarty_data, $sqlhdlr;
// Globalize the user variables
//global $smarty;
// Try and get the id, last time, and user if from the sessions database
$results = $sqlhdlr->table('sessions')
->select('id', 'last', 'user_id')
->where('phpsessid', session_id())
......@@ -93,17 +73,6 @@ function authenticate() {
$id = $results['id'];
$last = $results['last'];
$user_id = $results['user_id'];
// Try and get the id, last time, and user if from the sessions database
//$query = sprintf('SELECT id, last, user_id FROM sessions WHERE ' .
// 'phpsessid = "%s"', session_id());
//
//if ($result = $sqlhdlr->query($query)) {
// list($id, $last, $user_id) = $result->fetch_array();
// $result->close();
//} else {
// die( 'Error: ' . $sqlhdlr->error );
//}
// Check to see if an id was set, and if the time is good
if ((isset($id)) && (($last + $skynet_sessTime) >= time())) {
......@@ -114,35 +83,18 @@ function authenticate() {
'last', time()
));
//$query = sprintf("UPDATE sessions SET last = %d WHERE id = %d", time(),
// $id);
//
//$sqlhdlr->query($query) or die( 'Error: ' . $sqlhdlr->error );
// Create the user object
//$user_obj = new skynetUser($skynet_dbHost, $skynet_dbUser,
// $skynet_dbPass, $skynet_dbName, $user_id);
$user_obj = new skynetUser($user_id);
$user_obj = new skynetUser($sqlhdlr, $user_id);
// Assign the username to the smarty template
array_push($smarty_data, array('username' => $user_obj->username()));
array_push($smarty_data, array('adminflag', $user_obj->adminflag()));
//$smarty->assign('username', $user_obj->username());
//$smarty->assign('adminflag', $user_obj->adminflag());
$smarty_data['username'] = $user_obj->username();
$smarty_data['adminflag'] = $user_obj->adminflag();
if (get_magic_quotes_gpc()) {
array_push($smarty_data,
array('fullname',
stripslashes(htmlentities($user_obj->fullname(),
ENT_QUOTES))));
//$smarty->assign('fullname',
// stripslashes(htmlentities($user_obj->fullname(),
// ENT_QUOTES)));
$smarty_data['fullname'] =
stripslashes(htmlentities($user_obj->fullname(), ENT_QUOTES));
} else {
array_push($smarty_data, array('fullname',
htmlentities($user_obj->fullname(),
ENT_QUOTES)));
//$smarty->assign('fullname', htmlentities($user_obj->fullname(),
// ENT_QUOTES));
$smarty_data['fullname'] = htmlentities($user_obj->fullname(),
ENT_QUOTES);
}
return($user_obj);
......@@ -166,9 +118,7 @@ function feed_authenticate($user_id, $feed_id, $secret) {
if ($feed->secret() == $secret) {
// Create the user object
$user_obj = new skynetUser($user_id);
//$user_obj = new skynetUser($skynet_dbHost, $skynet_dbUser,
// $skynet_dbPass, $skynet_dbName, $user_id);
$user_obj = new skynetUser($sqlhdlr, $user_id);
return Array($feed, $user_obj);
} else {
......@@ -188,11 +138,6 @@ function logout() {
->where('phpsessid', session_id())
->delete();
//$query = sprintf("DELETE FROM sessions WHERE phpsessid = '%s'",
// session_id());
//
//$sqlhdlr->query($query) or die( 'Error: ' . $sqlhdlr->error );
return(1);
}
......
......@@ -41,7 +41,7 @@ class skynetUser {
private $adminflag; // Boolean (TinyInt)
private $logged_in; // Boolean
//private $sqlhdlr; // Object
private $sqlhdlr; // Object
private $dirty_flag; // Boolean
private $pwd_dirty_flag; // Boolean
......@@ -60,20 +60,12 @@ class skynetUser {
* @param boolean $login Boolean value indicating whether this is a login
* attempt
*/
//public function __construct($dbHost, $dbUser, $dbPass, $dbName, $uid = -1,
// $username = '', $password = '', $login = false) {
public function __construct($uid = -1,
$username = '', $password = '', $login = false) {
global $sqlhdlr;
// Connect to the database server
//$this->sqlhdlr = new mysqli($dbHost, $dbUser, $dbPass, $dbName);
// Make sure we have a connection
//if (mysqli_connect_errno()) {
// die( '<p>Unable to connect to the database server at this time: ' .
// mysqli_connect_error() . ' </p>' );
//}
public function __construct($sqlhdlr, $uid = -1, $username = '',
$password = '', $login = false) {
// Store the database handler
$this->sqlhdlr = $sqlhdlr;
// Everyone starts with a clean slate
$this->dirty_flag = false;
$this->pwd_dirty_flag = false;
......@@ -101,11 +93,7 @@ global $sqlhdlr;
}
//// Check the database for the user and get their password
//$query = sprintf('SELECT id FROM users WHERE username = "%s" ' .
// 'AND password = SHA1("%s")', $clean_username,
// $this->sqlhdlr->real_escape_string($clean_password));
$results = $sqlhdlr->table('users')
$results = $this->sqlhdlr->table('users')
->select('id', 'password')
->where('username', $clean_username)
->first();
......@@ -122,22 +110,7 @@ global $sqlhdlr;
}
$this->logged_in = true;
}
// if ($result = $this->sqlhdlr->query($query)) {
// // If a single row was returned then we have a match
// if ($result->num_rows == 1) {
// // Get the user_id from the sql query result
// list($this->user_id) = $result->fetch_array();
//
// $result->close();
//
// // Mark the user as logged in
// $this->logged_in = true;
// }
// } else {
// die( 'Error: ' . $this->sqlhdlr->error );
// }
}
}
// If we have a UID, or we are logged in
if ((is_numeric($uid) && ($uid != -1)) || $this->logged_in) {
......@@ -146,7 +119,7 @@ global $sqlhdlr;
$this->user_id = $uid;
}
$results = $sqlhdlr->table('users')
$results = $this->sqlhdlr->table('users')
->select('username', 'full_name', 'email', 'admin')
->where('id', $this->user_id)
->first();
......@@ -156,25 +129,6 @@ global $sqlhdlr;
$this->email = $results['email'];
$this->adminflag = $results['admin'];
//// Create the necessary sql statement
//$query = sprintf('SELECT u.username, u.full_name, u.email, ' .
// 'u.admin FROM users AS u WHERE u.id = %d',
// $this->user_id);
//
//if ($result = $this->sqlhdlr->query($query)) {
//
// $line = $result->fetch_array(MYSQLI_NUM);
//
// $this->username = $line[0];
// $this->fullname = $line[1];
// $this->email = $line[2];
// $this->adminflag = $line[3];
//
// $result->close();
//} else {
// die( 'Error: ' . $this->sqlhdlr->error );
//}
// New user, use defaults
} else {
$this->user_id = -1;
......@@ -236,37 +190,6 @@ global $sqlhdlr;
return false;
}
///**
// * Checks whether the supplied password is correct or not
// *
// * @param string $password String representing the user's password
// *
// * @return boolean True if the password is correct, false if not
// */
//public function check_pwd($password = '') {
// $skynet_pwdRegex = '/^[a-zA-Z0-9@#$%\^&\*\/]{4,15}\z/';
// if (! empty($password) && preg_match($skynet_pwdRegex, $password)) {
// // Check the password against whats stored in the database
// $query = sprintf('SELECT count(*) FROM users WHERE id = %d ' .
// 'AND password = SHA1("%s")', $this->user_id,
// $this->sqlhdlr->real_escape_string($password));
//
// if ($result = $this->sqlhdlr->query($query)) {
// list($count) = $result->fetch_array();
//
// // If a single row was returned then we have a match
// if ($count == 1) {
// return true;
// }
// } else {
// die( 'Error: ' . $this->sqlhdlr->error );
// }
// }
//
// // If we get here, return a failure
// return false;
//}
/**
* Set / Return the username
*
......@@ -378,7 +301,7 @@ global $sqlhdlr;
* Updates the user password hash in the database
*/
private function _update_password() {
$sqlhdlr->table('users')
$this->sqlhdlr->table('users')
->where('id', $this->user_id)
->update(array('password' => $this->passwordHash));
}
......@@ -391,13 +314,9 @@ global $sqlhdlr;
if ($this->deleteme) {
// Delete the entries, being careful to ensure it's
// from the right user
$sqlhdlr->table('users')
$this->sqlhdlr->table('users')
->where('id', $this->id)
->delete();
//$query = sprintf('DELETE FROM users WHERE id = %d',
// $this->user_id);
//$this->sqlhdlr->query($query) or die( 'Error: ' . $this->sqlhdlr->error );
}
}
......@@ -408,26 +327,19 @@ global $sqlhdlr;
// username, fullname, password, admin flag
// User ID of -1 indicates a new user
if ($this->user_id == -1) {
$sqlhdlr->table('users')->insert(array(
'username' => $this->username,
'full_name' => $this->fullname,
'email' => $this->email,
'password' => $this->passwordHash,
'admin' => $this->adminflag
));
//$query = sprintf('INSERT INTO users (username, full_name, email, ' .
// 'password, admin) VALUES ("%s", "%s", "%s", ' .
// 'SHA1("%s"), %d)', $this->username, $this->fullname,
// $this->sqlhdlr->real_escape_string($this->email),
// $this->password, $this->adminflag);
//
//$this->sqlhdlr->query($query) or die( 'Error: ' . $this->sqlhdlr->error );
$this->sqlhdlr->table('users')
->insert(array(
'username' => $this->username,
'full_name' => $this->fullname,
'email' => $this->email,
'password' => $this->passwordHash,
'admin' => $this->adminflag
));
// Get the user_id
$this->user_id = $this->sqlhdlr->insert_id;
} else {
$sqlhdlr->table('users')
$this->sqlhdlr->table('users')
->where('id', $this->user_id)
->update(array(
'username' => $this->username,
......@@ -435,13 +347,6 @@ global $sqlhdlr;
'email' => $this->email,
'admin' => $this->adminflag
));
//$query = sprintf('UPDATE users SET username = "%s", full_name = ' .
// '"%s", email = "%s", admin = %d WHERE id = %d',
// $this->username, $this->fullname,
// $this->sqlhdlr->real_escape_string($this->email),
// $this->adminflag, $this->user_id);
//
//$this->sqlhdlr->query($query) or die( 'Error: ' . $this->sqlhdlr->error );
if ($this->pwd_dirty_flag) {
$this->_update_password();
......@@ -461,8 +366,6 @@ global $sqlhdlr;
if ($this->dirty_flag || $this->pwd_dirty_flag) {
$this->_serialize();
}
//$this->sqlhdlr->close();
}
}
......
......@@ -15,10 +15,12 @@
{--* along with this program; if not, write to the Free Software *}
{--* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv='content-type' content='text/html; charset=ISO-8859-1' />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='shortcut icon' type='image/x-icon' href='{$skynet_favicon}'>
{include file='head-css.tpl'}
<title>Skynet Automated Security Scanner</title>
......@@ -26,7 +28,7 @@
<body>
{assign var=page value='about'}
{include file='header.tpl'}
<div class='gpl'>
<div class='container'>
<h3>GNU GENERAL PUBLIC LICENSE</h3>
......
......@@ -16,18 +16,13 @@
{--* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*}
<div class='footer'>
<hr class='onethird' />
<p class='copyright'>
<a href='{$skynet_homepage}'>Skynet {$skynet_version}</a>
&nbsp;-&nbsp;
<a href='about.php'>Copyright &copy; 2014-present</a>
&nbsp;Jason Frisvold
</p>
<a href='http://validator.w3.org/check?uri=referer'>
<img src='http://www.w3.org/Icons/valid-xhtml10' alt='Valid XHTML 1.0 Strict' class='w3c' />
</a>
&nbsp;
<a class='right' href='http://jigsaw.w3.org/css-validator'>
<img src='http://jigsaw.w3.org/css-validator/images/vcss' alt='Valid CSS!' class='w3c' />
</a>
<div class='container'>
<p class='text-muted'>
<a href='{$skynet_homepage}'>Skynet {$skynet_version}</a>
&nbsp;-&nbsp;
<a href='about.php'>Copyright &copy; 2014-present</a>
&nbsp;Jason Frisvold
</p>
</div>
</div>
{include file='head-javascript.tpl'}
\ No newline at end of file
......@@ -16,7 +16,9 @@
{--* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*}
{if isset($skynet_useCDN) && ($skynet_useCDN == true)}
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
{else}
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
{/if}
\ No newline at end of file
{--* Skynet - Automated "Cloud" Security Scanner *}
{--* Copyright (C) 2014-present Jason Frisvold <friz@godshell.com> *}
{--* *}
{--* This program is free software; you can redistribute it and/or modify *}
{--* it under the terms of the GNU General Public License as published by *}
{--* the Free Software Foundation; either version 2 of the License, or *}
{--* (at your option) any later version. *}
{--* *}
{--* This program is distributed in the hope that it will be useful, *}
{--* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
{--* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
{--* GNU General Public License for more details. *}
{--* *}
{--* You should have received a copy of the GNU General Public License *}
{--* along with this program; if not, write to the Free Software *}
{--* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*}
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Skynet</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
{if $page == 'main'}
<li class="active"><a href="/">Home</a></li>
{else}
<li><a href="/">Home</a></li>
{/if}
{if $username != 'guest'}
{if $page == 'reports'}
<li class="active"><a href="/reports">Reports</a></li>
{else}
<li><a href="/reports">Reports</a></li>
{/if}
{/if}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{$username} <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
{if $username != 'guest'}
<li><a href="/logout">Logout</a></li>
{else}
<li><a href="/login">Login</a></li>
{/if}
<li class="divider"></li>
<li><a href="/about">About</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
\ No newline at end of file
......@@ -15,35 +15,41 @@
{--* along with this program; if not, write to the Free Software *}
{--* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name='robots' content='noindex, nofollow' />
<meta http-equiv='content-type' content='text/html; charset=ISO-8859-1' />
<link rel='shortcut icon' type='image/x-icon' href='{$skynet_favicon}'>
{include file='head-css.tpl'}
<title>Skynet Automated Security Scanner</title>
</head>
<body>
<h1>Welcome to Skynet</h1>
<h3>Please login :</h3>
<form action="login" method="post">
<div class="col-sm-8 col-sm-offset-2 col-md-10 col-md-offset-1">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" class="form-control" placeholder="username" id="username" name="username" tabindex="1" accesskey="" path="username" autocomplete="false" htmlEscape="true" autofocus />
</div>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
<input id="password" name="password" tabindex="2" placeholder="password" class="form-control" type="password" value="" autocomplete="off"/>
</div>
<input type="submit" class="btn btn-primary btn-lg btn-block" value="Log In" />
</div>
</form>
<div class="col-md-6 col-md-offset-3">
<div class='jumbotron'>
<h3>Please login :</h3>
<form class='form-horizontal' role='form' action="login" method="post">
<div class="form-group">
<label class="col-sm-1 col-sm-offset-3 control-label"><span class="glyphicon glyphicon-user"></span></label>
<div class='col-md-4'>
<input type="text" class="form-control" placeholder="username" id="username" name="username" tabindex="1" accesskey="" path="username" autocomplete="false" htmlEscape="true" autofocus />
</div>
</div>
<div class="form-group">
<label class="col-sm-1 col-sm-offset-3 control-label"><span class="glyphicon glyphicon-lock"></span></label>
<div class='col-md-4'>
<input id="password" name="password" tabindex="2" placeholder="password" class="form-control" type="password" value="" autocomplete="off" />
</div>
</div>
<input type="submit" class="col-sm-1 col-sm-offset-4 btn btn-default" value="Login"/>
</form>
</div>
</div>
<div class="col-sm-8 col-sm-offset-2 col-md-10 col-md-offset-1">
<div class="col-md-6 col-md-offset-3">
{if isset($smarty.session['slim.flash'].error)}
<div class='alert alert-danger'>{$smarty.session['slim.flash'].error}</div>
{/if}
......
......@@ -15,10 +15,12 @@
{--* along with this program; if not, write to the Free Software *}
{--* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv='content-type' content='text/html; charset=ISO-8859-1' />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='shortcut icon' type='image/x-icon' href='{$skynet_favicon}'>
{include file='head-css.tpl'}