-Unify the login and noderange experiment into a single index.html

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2269 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2008-09-30 20:57:53 +00:00
parent b5b49db02f
commit 365a26448c
2 changed files with 222 additions and 0 deletions

178
xCAT-web-exp/index.html Normal file
View File

@ -0,0 +1,178 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>xCAT WebUI</title>
<link rel="stylesheet" type="text/css" href="colorscheme.css" />
<style type="text/css">
span.logstatus {
margin-left: 5.5em;
}
label {
text-align: right;
width: 5em;
float: left;
margin-right: 0.5em;
display: block;
}
*#nrtree {
width:20%;
}
*#logout {
position:absolute;
top:0;
right:0;
margin-left:1em;
text-align: center;
vertical-align: middle;
}
.xcatbutton button {
margin: .5em .5em .5em 8px;
color: #555555;
background: #e6e6e6 url(images/e6e6e6_40x100_textures_02_glass_75.png) 0 50% repeat-x;
font-size: 0.7em;
border: 1px solid #d3d3d3;
cursor: pointer;
padding: .2em .6em .3em .6em;
line-height: 1.4em;
}
.xcatbutton button:hover {
color: #212121;
background: #dadada url(images/dadada_40x100_textures_02_glass_75.png) 0 50% repeat-x;
border: 1px solid #999999;
}
.xcatbutton button:active {
color: #222222;
background: #ffffff url(images/ffffff_40x100_textures_02_glass_65.png) 0 50% repeat-x;
border: 1px solid #dddddd;
}
</style>
<link rel="stylesheet" type="text/css" href="tree_component.css" />
<script type="text/javascript" src="css.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.listen.js"></script>
<script type="text/javascript" src="tree_component.js"></script>
<script type="text/javascript" src="jquery.ui.js"></script>
<script type="text/javascript">
var logdialog;
var nrtree;
function openlogdialog (data, textstatus) { //open the log in dialog if not logged in
if (data.authenticated == "no") {
logdialog.dialog("open");
}
}
function logincallback (data, textstatus) {
$("#password").val(""); //clear the password field regardless of what happens
if (data.authenticated == "yes") {
$("#logstatus").text("Logged in successfully");
nrtree.refresh(); // Fix tree potentiall broken through attempts to operate without auth
logdialog.dialog("close");
} else {
$("#logstatus").text("Authentication failure");
$("#logstatus").css("color","#ff0000");
}
}
function logout () {
$.post("log.php",{logout:1})
$("#logstatus").html("");
logdialog.dialog("open");
}
function login() {
$("#logstatus").css("color","#000000");
$("#logstatus").html('Authenticating...<img src="images/throbber.gif"/>');
var passwd=$("#password").val();
$.post("log.php",{
username: $("#username").val(),
password: passwd
},logincallback,"json");
}
function updatenoderange() {
}
$(document).ready(function() {
nrtree = new tree_component(); // -Tree begin
nrtree.init($("#nrtree"),{
rules: {
multiple: "Ctrl"
},
ui: {
animation: 250
},
callback : {
onchange : updatenoderange
},
data : {
type : "json",
async : "true",
url: "noderangesource.php"
}
}); //Tree finish
logdialog=$("#logdialog").dialog({
modal: true,
closeOnEscape: false,
overlay: {
backgroundColor: "#000",
opacity: 0.75
},
height: 200,
width: 350,
autoOpen: false,
buttons: {
"Log In": login
},
open: function(type, dialog) {
if (document.location.protocol == "http:") {
$("#logstatus").html("Unencrypted Session!");
$("#logstatus").css("color","#ff0000");
}
if ($("#username").val() == "") {
$("#username").focus();
} else {
$("#password").focus();
}
},
close: function(type, dialog) {
return false;
}
});
$("#username").keydown(function(event) {
if (event.keyCode==13) {
$("#password").focus();
}
});
$("#password").keydown(function(event) {
if (event.keyCode==13) {
login();
}
});
$("#login").click(function(event) {
login();
});
$("#logout").click(function(event) {
logout();
});
$.post("log.php",{},openlogdialog,"json");
});
</script>
</head>
<body>
<div id="nrdisplay">Noderange:</div>
<div id="nrtree"></div>
<!-- The omnipresent login dialog, waiting to be called forth by javascript -->
<div id="logdialog">
<form id="loginform" method="post" action="login.php">
<label for="username">Username:</label><input id="username" type="text" name="username"><br/>
<label for="password">Password:</label><input id="password" type="password" name="password"></form>
<span class="logstatus" id="logstatus"><br/></span>
</div>
<!-- Log out control -->
<div id="logout" class="xcatbutton"><button>Log Out</button></div>
</body>
</html>

44
xCAT-web-exp/log.php Normal file
View File

@ -0,0 +1,44 @@
<?php
session_start();
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
include "functions.php";
$successfullogin=0;
if (isset($_GET["logout"]) or isset($_POST["logout"])) {
logout();
}
if (isset($_POST["password"])) {
$_SESSION=array(); #Clear data from session. prevent session data from migrating in a hijacking?
session_regenerate_id(true);#Zap existing session entirely..
setpassword($_POST["password"]);
$_SESSION["xcatpassvalid"]=-1; #unproven password
}
if (isset($_POST["username"])) {
$_SESSION["username"]=$_POST["username"];
$_SESSION["xcatpassvalid"]=-1; #unproven password
}
if (is_logged()) {
if ($_SESSION["xcatpassvalid"] != 1) {
$testcred=docmd("authcheck","","");
if (isset($testcred->{'xcatresponse'}->{'data'})) {
$result="".$testcred->{'xcatresponse'}->{'data'};
if (is_numeric(strpos("Authenticated",$result))) {
$_SESSION["xcatpassvalid"]=1; #proven good
} else {
$_SESSION["xcatpassvalid"]=0; #proven bad
}
}
}
}
$jdata=array();
if (isset($_SESSION["xcatpassvalid"]) and $_SESSION["xcatpassvalid"]==1) {
$jdata["authenticated"]="yes";
} else {
$jdata["authenticated"]="no";
}
echo json_encode($jdata);
?>