Permalink
Browse files

Started working on a basic authentification system

  • Loading branch information...
1 parent 404acf5 commit 11af5a128a0e9620749323354e86b19d9f4d5624 @sebgiroux committed Jul 1, 2011
View
@@ -5,7 +5,9 @@
@author Sébastien Giroux
@copyright All rights reserved - 2011
*/
-
+ require_once('include/kernel.inc.php');
+ require_once('include/verify_login.inc.php');
+
$vw_vars['cluster_name'] = $sys_manager->describe_cluster_name();
$vw_vars['partitioner'] = $sys_manager->describe_partitioner();
$vw_vars['snitch'] = $sys_manager->describe_snitch();
View
@@ -7,6 +7,7 @@
*/
require('include/kernel.inc.php');
+ require('include/verify_login.inc.php');
$action = '';
if (isset($_GET['action'])) $action = $_GET['action'];
View
@@ -4,6 +4,26 @@ body {
background-color: #eee;
}
+.float_left {
+ float: left;
+}
+
+.float_right {
+ float: right;
+}
+
+.clear_left {
+ clear: left;
+}
+
+.clear_right {
+ clear: right;
+}
+
+.clear_both {
+ clear: both;
+}
+
form div {
margin-bottom: 5px;
}
@@ -13,7 +33,7 @@ form label {
float: left;
}
-input[type=text] {
+input[type=text], input[type=password] {
width: 300px;
}
@@ -7,6 +7,7 @@
*/
require('include/kernel.inc.php');
+ require('include/verify_login.inc.php');
echo getHTML('header.php');
View
@@ -7,6 +7,7 @@
*/
require('include/kernel.inc.php');
+ require('include/verify_login.inc.php');
echo getHTML('header.php');
View
@@ -9,7 +9,7 @@
$CASSANDRA_SERVERS = array('127.0.0.1:9160'); // Add as many Cassandra nodes as you want in this array
/*
- Enter your cassandra credentials here if needed
+ Enter your Cassandra credentials here if needed
*/
define('CASSANDRA_USERNAME','');
define('CASSANDRA_PASSWORD','');
@@ -18,4 +18,11 @@
if (CASSANDRA_USERNAME != '' && CASSANDRA_PASSWORD != '') {
$CREDENTIALS = array('username' => CASSANDRA_USERNAME, 'password' => CASSANDRA_PASSWORD);
}
+
+ /*
+ Enter your Cassandra Cluster Admin credentials here
+ */
+ define('CCA_LOGIN_REQUIRED',true);
+ define('CCA_USERNAME','root');
+ define('CCA_PASSWORD','');
?>
View
@@ -23,8 +23,9 @@ function getHTML($filename, $php_params = array()) {
if (!file_exists('views/'.$filename))
die ('The view ' . $filename . ' doesn\'t exist');
- //if we get some params to be treated in php
+ // If we got some params to be treated in php
extract($php_params);
+
ob_start();
include('views/'.$filename);
$content = ob_get_contents();
@@ -134,6 +135,12 @@ function displayErrorMessage($index,$params = array()) {
elseif ($index == 'columnfamily_name_must_be_specified') {
return '<div class="error_message">You must specify a column family name</div>';
}
+ elseif ($index == 'login_wrong_username_password') {
+ return '<div class="error_message">Wrong username and/or password!</div>';
+ }
+ elseif ($index == 'you_must_be_logged') {
+ return '<div class="error_message">You must be logged to access Cassandra Cluster Admin!</div>';
+ }
}
function displayCFRow($row,$scf_key = null) {
@@ -0,0 +1,12 @@
+<?php
+ /*
+ Cassandra Cluster Admin
+
+ @author Sébastien Giroux
+ @copyright All rights reserved - 2011
+ */
+
+ if (CCA_LOGIN_REQUIRED && (!isset($_SESSION['cca_login']) || $_SESSION['cca_login'] !== md5(CCA_USERNAME.CCA_PASSWORD))) {
+ redirect('login.php?you_must_be_logged=1');
+ }
+?>
View
@@ -7,7 +7,8 @@
*/
require('include/kernel.inc.php');
-
+ require('include/verify_login.inc.php');
+
/*
Display success message
*/
View
@@ -7,6 +7,7 @@
*/
require('include/kernel.inc.php');
+ require('include/verify_login.inc.php');
$action = '';
if (isset($_GET['action'])) $action = $_GET['action'];
View
@@ -0,0 +1,45 @@
+<?php
+ /*
+ Cassandra Cluster Admin
+
+ @author Sébastien Giroux
+ @copyright All rights reserved - 2011
+ */
+
+ require('include/kernel.inc.php');
+
+ /*
+ No login required mode, redirect to index
+ */
+ if (!CCA_LOGIN_REQUIRED) {
+ redirect('index.php');
+ }
+
+ $vw_vars['login_error'] = '';
+
+ /*
+ Submit login form
+ */
+ if (isset($_POST['btn_login'])) {
+ $username = $_POST['username'];
+ $password = $_POST['password'];
+
+ if ($username === CCA_USERNAME && $password === CCA_PASSWORD) {
+ $_SESSION['cca_login'] = md5($username.$password);
+ redirect('index.php');
+ }
+ else {
+ $vw_vars['login_error'] = displayErrorMessage('login_wrong_username_password');
+ }
+ }
+
+ $vw_vars['you_must_be_logged'] = '';
+ if (isset($_GET['you_must_be_logged'])) {
+ $vw_vars['you_must_be_logged'] = displayErrorMessage('you_must_be_logged');
+ }
+
+ echo getHTML('header.php');
+ echo getHTML('login.php',$vw_vars);
+ echo getHTML('footer.php');
+
+?>
View
@@ -0,0 +1,13 @@
+<?php
+ /*
+ Cassandra Cluster Admin
+
+ @author Sébastien Giroux
+ @copyright All rights reserved - 2011
+ */
+
+ require('include/kernel.inc.php');
+
+ unset($_SESSION['cca_login']);
+ redirect('login.php');
+?>
View
@@ -14,4 +14,6 @@
</head>
<body>
- <h1>Cassandra Cluster Admin</h1>
+ <h1 class="float_left">Cassandra Cluster Admin</h1>
+ <div class="float_right"><a href="logout.php">Logout</a></div>
+ <div class="clear_both"></div>
View
@@ -0,0 +1,18 @@
+<?php echo $login_error; ?>
+<?php echo $you_must_be_logged; ?>
+
+<form method="post" action="login.php">
+ <div>
+ <label for="username">Username:</label>
+ <input type="text" id="username" name="username" />
+ </div>
+
+ <div>
+ <label for="password">Password:</label>
+ <input type="password" id="password" name="password" />
+ </div>
+
+ <div>
+ <input type="submit" name="btn_login" value="Login" />
+ </div>
+</form>

0 comments on commit 11af5a1

Please sign in to comment.