Subversion Repositories ALCASAR

Compare Revisions

No changes between revisions

Ignore whitespace Rev 483 → Rev 484

/web/intercept.php
28,11 → 28,12
$uamsecret = "Mkb0pAEE";
 
# URL loaded after success authenticates (let blank for browser defaults)
$adminurl = "";
$adminurl = "http://www.sfr.fr";
 
# Our own path
$loginpath = $_SERVER['PHP_SELF'];
$loginpath = $_SERVER['PHP_SELF'];
$statuspath = "http://alcasar/status.php";
$debug = true;
 
# Choice of language
$Language = 'en';
326,7 → 327,7
 
# Otherwise it was not a form request
# Send out an error message
if ($result == 0) {
if ($result == 0) { //erreur
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
353,115 → 354,59
<title>$R_loggingin</title>
<meta http-equiv=\"Cache-control\" content=\"no-cache\">
<meta http-equiv=\"Pragma\" content=\"no-cache\">
<SCRIPT LANGUAGE=\"JavaScript\">
var blur = 0;
var starttime = new Date();
var startclock = starttime.getTime();
var mytimeleft = 0;
 
function doTime() {
window.setTimeout( \"doTime()\", 1000 );
t = new Date();
time = Math.round((t.getTime() - starttime.getTime())/1000);
if (mytimeleft) {
time = mytimeleft - time;
if (time <= 0) {
window.location = \"$statuspath?res=popup3&uamip=$uamip&uamport=$uamport\";
}
}
if (time < 0) time = 0;
hours = (time - (time % 3600)) / 3600;
time = time - (hours * 3600);
mins = (time - (time % 60)) / 60;
secs = time - (mins * 60);
if (hours < 10) hours = \"0\" + hours;
if (mins < 10) mins = \"0\" + mins;
if (secs < 10) secs = \"0\" + secs;
title = \"$R_online_time : \" + hours + \":\" + mins + \":\" + secs;
if (mytimeleft) {
title = \"$R_remaining_time : \" + hours + \":\" + mins + \":\" + secs;
}
if(document.all || document.getElementById){
document.title = title;
}
else {
self.status = title;
}
}
 
<script type=\"text/javascript\" language=\"JavaScript\">
var blur = 0; // not un use
var mytimeleft = 0; // not un use
alcasar_popup = null;
function popUp(URL) {
if (self.name != \"chillispot_popup\") {
chillispot_popup = window.open(URL, 'chillispot_popup', 'width=500,height=250,resizable,scrollbars=yes,location=yes,toolbar=no,statusbar=no,menubar=no');
if (self.name != \"alcasar_popup\") {
alcasar_popup = window.open(URL, 'alcasar_popup', 'width=500,height=250,directories=no,resizable=no,scrollbars=yes,location=no,toolbar=no,statusbar=no,menubar=no');
}
}
 
function doOnLoad(result, URL, userurl, redirurl, timeleft) {
URL = \"$statuspath\";
if (timeleft) {
function doOnLoad(result, userurl, redirurl, timeleft) {
if (timeleft) { // not in use
mytimeleft = timeleft;
}
if ((result == 1) && (self.name == \"chillispot_popup\")) {
doTime();
window.onbeforeunload = DecO($result);
}
if ((result == 1) && (self.name != \"chillispot_popup\")) {
// popUp(URL);
window.location = userurl;
}
if ((result == 2) || result == 5) {
document.form1.UserName.focus()
}
if ((result == 2) && (self.name != \"chillispot_popup\")) {
popUp();
chillispot_popup.close();
}
if ((result == 12) && (self.name == \"chillispot_popup\")) {
doTime();
";
if ($adminurl) { echo "opener.location = \"$adminurl\";";}
else if ($redirurl) { echo "opener.location = \"$redirurl\";";}
else if ($userurl) { echo "opener.location = \"$userurl\";";}
else echo "opener.home();";
if (result == 1) { //success
//window.location = userurl;
if (alcasar_popup != null) alcasar_popup.focus();
";
if ($adminurl) { echo "window.location = \"$adminurl\";";}
else if ($redirurl) { echo "window.location = \"$redirurl\";";}
else if ($userurl) { echo "window.location = \"$userurl\";";}
else echo "window.home();";
echo "
self.focus();
blur = 0;
}
if ((result == 13) && (self.name == \"chillispot_popup\")) {
self.focus();
blur = 1;
if ((result == 2) || (result == 3) || result == 5) { //failed or logoff or notyet
if (alcasar_popup != null) alcasar_popup.close();
document.form1.UserName.focus();
}
}
 
function DecO(result) {
if ((result == 12) && (self.name == \"chillispot_popup\")) {
window.location = \"http://$uamip:$uamport/logoff \";
self.focus();
blur = 1;
//alert ('$R_loggedout');
}
}
</script>
<link rel=\"stylesheet\" href=\"/css/style_intercept.css\" type=\"text/css\">
</head>
<body onLoad=\"javascript:doOnLoad($result,'$loginpath?res=popup2&uamip=$uamip&uamport=$uamport&userurl=$userurl&redirurl=$redirurl&timeleft=$timeleft','$userurl','$redirurl','$timeleft')\" OnbeforeUnload=\"javascript:DecO($result)\">
<body onLoad=\"javascript:doOnLoad($result,'$userurl','$redirurl','$timeleft')\">
<center>";
#Modifications par stephane ERARD le 30 11 2010
#Modifications par steweb57 le 06 02 2011
if ($debug){
# begin debugging
# print "<center>THE INPUT by GET method (for debugging):<br>";
# foreach ($_GET as $key => $value) {
# print $key . "=" . $value . "<br>";
# }
# print "<br>";
# print "<center>THE INPUT by POST method (for debugging):<br>";
# foreach ($_POST as $key => $value) {
# print $key . "=" . $value . "<br>";
# }
# print "<br></center>";
print "<center>THE INPUT by GET method (for debugging):<br>";
foreach ($_GET as $key => $value) {
print $key . "=" . $value . "<br>";
}
print "<br>";
print "<center>THE INPUT by POST method (for debugging):<br>";
foreach ($_POST as $key => $value) {
print $key . "=" . $value . "<br>";
}
print "<br></center>";
# end debugging
}
 
if ($result == 2) {
if ($result == 2) { //failed
echo "
<DIV id=\"logon\">
<h2>$R_loginfailed</h2>";
471,14 → 416,14
}
}
 
if ($result == 5) {
if ($result == 3 || $result == 5) { //logoff or notyet
echo "
<DIV id=\"logon\">
<h1>$organisme</h1>
<h2>$R_loggedcont</h2>";
}
 
if ($result == 2 || $result == 5) {
if ($result == 2 || $result == 3 || $result == 5) { //failed or logoff or notyet
echo "
<IMG id=\"logo-alcasar\" src=\"/images/logo-alcasar.png\">
<form name=\"form1\" method=\"post\" action=\"$loginpath\">
497,18 → 442,18
<TD align=\"left\"><INPUT maxLength=\"32\" type=\"password\" name=\"Password\"></TD>
</TR>
<TR>
<TD height=\"23\" colSpan=\"2\" align=\"middle\"><INPUT value=\"$R_boutonO\" type=\"submit\" name=\"button\" onclick=\"javascript:popUp('$statuspath')\"></TD>
<TD height=\"23\" colSpan=\"2\" align=\"center\"><INPUT value=\"$R_boutonO\" type=\"submit\" name=\"button\" onclick=\"javascript:popUp('$statuspath')\"></TD>
</TR>
<TR>
<TD colSpan=2 align=middle><H6><A href=\"https://$uamip/pass/\">$R_passwordchg</A></H6></TD>
<TD colSpan=2 align=center><H6><A href=\"https://$uamip/pass/\">$R_passwordchg</A></H6></TD>
</TR>
</TABLE>
<TABLE id=\"boite-info\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\">
<TR>
<TD align=\"middle\"><FONT color=\"red\"><B>$R_loggedin_stringl0</B></FONT></TD>
<TD align=\"center\"><FONT color=\"red\"><B>$R_loggedin_stringl0</B></FONT></TD>
</TR>
<TR>
<TD align=\"middle\"><FONT color=\"black\"><B>$R_loggedin_stringl1</B></FONT></TD>
<TD align=\"center\"><FONT color=\"black\"><B>$R_loggedin_stringl1</B></FONT></TD>
</TR>
<TR>
<TD align=\"left\">
524,14 → 469,15
</TD>
</TR>
</TABLE>
</DIV>
</center>
</form>
</DIV>
</body>
</html>";
}
#Fin des modifications
if ($result == 1) {
if ($result == 1) { //sucess
echo "
<table id=\"auth_reussi\">
<tr>
541,39 → 487,23
<td>
<p class=\"text_auth\">$R_login</p>
</td>
</tr>";
</tr>
<tr>
<td></td>
<td>";
if ($reply) {
## traitement reply
echo "<center> $reply </br></br></center>";
echo "$reply</br></br>";
}
echo "
<center>
<a href=\"http://$uamip:$uamport/logoff\">$R_logout</a>
</center>
</body>
</html>";
}
 
if (($result == 4) || ($result == 12)) {
echo "
<table id=\"auth_reussi\">
<tr>
<td>
<img height=\"150\" src=\"/images/logo-alcasar.png\">
<a href=\"http://$uamip:$uamport/logoff\">$R_logout</a>
</td>
<td>
<p class=\"text_auth\">$R_login</p>
</td>
</tr>
<tr><td colspan=2><center>
<p class=\"lien_deco\"><a href=\"http://$uamip:$uamport/logoff\">$R_logout</a></p>
</center></td></tr>
</table>
</body>
</html>";
</body>
</html>";
}
 
if ($result == 11) {
if ($result == 11) { //popup 1 (login)
echo "
<h2 style=\"text-align: center;\">$R_loggingin</h2>
<center>$R_wait</center>
580,17 → 510,5
</body>
</html>";
}
 
if (($result == 3) || ($result == 13)) {
echo "
<center>
<p class=\"log_out\">$R_loggedout</p>
<FORM>
<INPUT TYPE=\"button\" VALUE=\"$R_boutonF\" onClick=\"window.close()\">
</FORM></CENTER>
</body>
</html>";
}
 
exit(0);
?>
/web/images/wait.gif
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/web/status.php
27,6 → 27,9
$R_downloaded_label = "Downloaded";
$R_uploaded_label = "Uploaded";
$R_original_url_label = "Original URL";
$R_not_available = "Not available";
$R_na = "N/A";
$R_error = "error";
}
else if($Language == 'de'){
$R_login1 = "Erfolgreiche Authentifizierung.";
44,6 → 47,9
$R_downloaded_label = "Downloaded";
$R_uploaded_label = "Uploaded";
$R_original_url_label = "Original URL";
$R_not_available = "Not available";
$R_na = "N/A";
$R_error = "error";
}
else if($Language == 'nl'){
$R_login1 = "Succesvolle authenticatie.";
61,6 → 67,9
$R_downloaded_label = "Downloaded";
$R_uploaded_label = "Uploaded";
$R_original_url_label = "Original URL";
$R_not_available = "Not available";
$R_na = "N/A";
$R_error = "error";
}
else if($Language == 'fr'){
$R_login1 = "Authentification r&eacute;ussie.";
78,6 → 87,9
$R_downloaded_label = "Donn&eacute;es t&eacute;l&eacute;charg&eacute;es";
$R_uploaded_label = "Donn&eacute;es envoy&eacute;es";
$R_original_url_label = "URL demand&eacute;";
$R_not_available = "Not available";
$R_na = "N/A";
$R_error = "erreur";
}
else {
$R_login1 = "Successful authentication.";
95,14 → 107,10
$R_downloaded_label = "Downloaded";
$R_uploaded_label = "Uploaded";
$R_original_url_label = "Original URL";
$R_not_available = "Not available";
$R_na = "N/A";
$R_error = "error";
}
/*
Connected
logout
Connected
Not available
N/A
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html lang="fr">
109,18 → 117,77
<!-- written by steweb57 -->
<head>
<title>Alcasar - <?php echo $organisme; ?></title>
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="./js/ChilliLibrary.js">
<script type="text/javascript" src="./js/ChilliLibrary.js"></script>
<script type="text/javascript" src="./js/statusControler.js"></script>
<link type="text/css" href="./css/status.css" rel="stylesheet">
<script language="JavaScript">
var blur = 0;
var starttime = new Date();
var startclock = starttime.getTime();
var mytimeleft = 0;
function closePopup(){
this.focus();
self.opener=this;
self.close();
}
function alcasarLogoff(){
chilliClock.stop();
chilliController.logoff();
//showWaitPage(5000);
}
function logout() {
alcasarLogoff();
window.setTimeout("closePopup()",1000);
}
function logoutWithConfirmation(msg) {//"Are you sure you want to disconnect now?"
if (confirm(msg)) {
logout();
}
return false;
}
function logoutWithAlert(msg) {//"Are you sure you want to disconnect now?"
alert(msg);
logout();
}
function doTime() {
window.setTimeout( "doTime()", 1000 );
t = new Date();
time = Math.round((t.getTime() - starttime.getTime())/1000);
if (mytimeleft) {
time = mytimeleft - time;
if (time <= 0) {
alert("Votre session est terminée");
}
}
if (time < 0) time = 0;
hours = (time - (time % 3600)) / 3600;
time = time - (hours * 3600);
mins = (time - (time % 60)) / 60;
secs = time - (mins * 60);
if (hours < 10) hours = "0" + hours;
if (mins < 10) mins = "0" + mins;
if (secs < 10) secs = "0" + secs;
title = "$R_online_time : " + hours + ":" + mins + ":" + secs;
if (mytimeleft) {
title = "$R_remaining_time : " + hours + ":" + mins + ":" + secs;
}
if(document.all || document.getElementById){
document.title = title;
}
else {
self.status = title;
}
}
</script>
<script type="text/javascript" src="./js/statusControler.js">
</script>
<link type="text/css" href="./css/status.css" rel="stylesheet">
</head>
<body>
<body OnbeforeUnload="javascript:alcasarLogoff();">
<div id="Chilli">
<div id="locationName"></div>
<div id="chilliPage">
<div id="logonPage" class="c1">
<div id="loggedOutPage" class="c1">
<table id="disconnectTable">
<tr>
<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
142,7 → 209,7
</tr>
<tr>
<td align="center"><br>
<a href="#" onclick="return disconnect();" class="lien_deco"><?php echo $R_logout; ?></a><br>
<a href="#" onclick="return logoutWithConfirmation('Are you sure you want to disconnect now?');" class="lien_deco"><?php echo $R_logout; ?></a><br>
<br></td>
</tr>
<!--tr id="connectRow">
151,39 → 218,39
</tr-->
<!--tr id="sessionIdRow">
<td id="sessionIdLabel" class="chilliLabel"><strong><?php echo $R_session_id_label; ?></strong></td>
<td id="sessionId" class="chilliValue">Not available</td>
<td id="sessionId" class="chilliValue"><?php echo $R_not_available; ?></td>
</tr-->
<tr id="sessionTimeoutRow">
<td id="sessionTimeoutLabel" class="chilliLabel"><strong><?php echo $R_max_session_time_label; ?></strong></td>
<td id="sessionTimeout" class="chilliValue">Not available</td>
<td id="sessionTimeout" class="chilliValue"><?php echo $R_not_available; ?></td>
</tr>
<tr id="idleTimeoutRow">
<td id="idleTimeoutLabel" class="chilliLabel"><strong><?php echo $R_max_idle_time_label; ?></strong></td>
<td id="idleTimeout" class="chilliValue">Not available</td>
<td id="idleTimeout" class="chilliValue"><?php echo $R_not_available; ?></td>
</tr>
<tr id="startTimeRow">
<td id="startTimeLabel" class="chilliLabel"><strong><?php echo $R_start_time_label; ?></strong></td>
<td id="startTime" class="chilliValue">Not available</td>
<td id="startTime" class="chilliValue"><?php echo $R_not_available; ?></td>
</tr>
<tr id="sessionTimeRow">
<td id="sessionTimeLabel" class="chilliLabel"><strong><?php echo $R_session_time_label; ?></strong></td>
<td id="sessionTime" class="chilliValue">Not available</td>
<td id="sessionTime" class="chilliValue"><?php echo $R_not_available; ?></td>
</tr>
<tr id="idleTimeRow">
<td id="idleTimeLabel" class="chilliLabel"><strong><?php echo $R_idle_time_label; ?></strong></td>
<td id="idleTime" class="chilliValue">Not available</td>
<td id="idleTime" class="chilliValue"><?php echo $R_not_available; ?></td>
</tr>
<tr id="inputOctetsRow">
<td id="inputOctetsLabel" class="chilliLabel"><strong><?php echo $R_downloaded_label; ?></strong></td>
<td id="inputOctets" class="chilliValue">N/A</td>
<td id="inputOctets" class="chilliValue"><?php echo $R_na; ?></td>
</tr>
<tr id="outputOctetsRow">
<td id="outputOctetsLabel" class="chilliLabel"><strong><?php echo $R_uploaded_label; ?></strong></td>
<td id="outputOctets" class="chilliValue">N/A</td>
<td id="outputOctets" class="chilliValue"><?php echo $R_na; ?></td>
</tr>
<tr id="originalURLRow">
<td id="originalURLLabel" class="chilliLabel"><strong><?php echo $R_original_url_label; ?></strong></td>
<td id="originalURL" class="chilliValue">N/A</td>
<td id="originalURL" class="chilliValue"><?php echo $R_na; ?></td>
</tr>
</table>
</div>
201,7 → 268,7
<table id="errorTable">
<tr>
<td><img height="150" src="./images/logo-alcasar.png" alt="logo"></td>
<td><span id="errorMessage">Error</span></td>
<td><span id="errorMessage"><?php echo $R_error; ?></span></td>
</tr>
</table>
</div>
/web/js/ChilliLibrary.js
0,0 → 1,844
/**
* ChilliLibrary.js
* V2.0
*
* This Javascript library can be used to create HTML/JS browser
* based smart clients (BBSM) for the CoovaChilli access controller
* Coova Chilli rev 81 or higher is required
*
* This library creates four global objects :
*
* - chilliController Expose session/client state and
* connect()/disconnect() methods the to BBSM.
*
* - chilliJSON INTERNAL (should not be called from the BBSM).
* Issues a command to the chilli daemon by adding a new <SCRIPT>
* tag to the HTML DOM (this hack enables cross server requests).
*
* - chilliClock Can be used by BBSMs to display a count down.
* Will sync with chilliController for smooth UI display (not yet implemented)
*
* - chilliLibrary Expose API and library versions
*
* For more information http://www.coova.org/CoovaChilli/JSON
*
* TODO :
* - Fine tune level of debug messages
* - Define error code when invoking onError
* - Retry mechanism after a JSON request fails
* - Delay clock tick when there is already an ongoing request
* - Use a true JSON parser to validate what we received
* - Use idleTime and idleTimeout to re-schedule autofresh after
* a likely idle termination by chilli
* - check that the library can be compiled as a Flash swf library
* and used from Flash BBSMs with the same API.
*
* Copyright (C) Y.Deltroo 2007
* Distributed under the BSD License
*
* This file also contains third party code :
* - MD5, distributed under the BSD license
* http://pajhome.org.uk/crypt/md5
*
*/
 
var chilliLibrary = { revision:'85' , apiVersion:'2.0' } ;
 
 
/**
* Global chilliController object
*
* CONFIGUARION PROPERTIES
* -----------------------
* ident (String)
* Hex encoded string (used for client side CHAP-Password calculations)
*
* interval (Number)
* Poll the gateway every interval, in seconds
*
* host (String)
* IP address of the controller (String)
*
* port (Number)
* UAM port to direct request to on the gateway
*
* ssl (Boolean)
* Shall we use HTTP or HTTPS to communicate with the chilli controller
*
* uamService : String
* !!! EXPERIMENTAL FEATURE !!!
* URL to external uamService script (used for external MD5 calculation when portal/chilli trust is required)
* This remote script runs on a SSL enable web server, and knows UAM SECRET.
* The chilliController javascript object will send the password over SSL (and challenge for CHAP)
* UAM SERVICE should reply with a JSON response containing
* - CHAP logon : CHAP-Password X0Red with UAM SECRET
* - PAP logon : Password XORed with UAM SECRET
*
* For more information http://www.coova.org/CoovaChilli/JSON
*
*/
 
if (!chilliController || !chilliController.host)
var chilliController = { interval:30 , host:"1.0.0.1" , port:false , ident:'00' , ssl:false , uamService: false };
 
/* Define clientState numerical code constants */
chilliController.stateCodes = { UNKNOWN:-1 , NOT_AUTH:0 , AUTH:1 , AUTH_PENDING:2 , AUTH_SPLASH:3 } ;
 
/* Initializing session and accounting members, objet properties */
chilliController.session = {} ;
chilliController.accounting = {} ;
chilliController.redir = {} ;
 
chilliController.location = { name: '' } ;
chilliController.challenge = '' ;
chilliController.message = '' ;
chilliController.clientState = chilliController.stateCodes.UNKNOWN ;
chilliController.command = '' ;
chilliController.autorefreshTimer = 0 ;
 
/* This method returns the root URL for commands */
chilliController.urlRoot = function () {
var protocol = ( chilliController.ssl ) ? "https" : "http" ;
var urlRoot = protocol + "://" + chilliController.host + (chilliController.port ? ":" + chilliController.port.toString() : "") + "/json/" ;
return urlRoot;
};
 
/* Default event handlers */
chilliController.onUpdate = function ( cmd ) {
log('>> Default onUpdate handler. <<\n>> You should write your own. <<\n>> cmd = ' + cmd + ' <<' );
};
 
chilliController.onError = function ( str ) {
log ( '>> Default Error Handler<<\n>> You should write your own <<\n>> ' + str + ' <<' );
};
 
 
chilliController.formatTime = function ( t , zeroReturn ) {
 
if ( typeof(t) == 'undefined' ) {
return "Not available";
}
 
t = parseInt ( t , 10 ) ;
if ( (typeof (zeroReturn) !='undefined') && ( t === 0 ) ) {
return zeroReturn;
}
 
var h = Math.floor( t/3600 ) ;
var m = Math.floor( (t - 3600*h)/60 ) ;
var s = t % 60 ;
 
var s_str = s.toString();
if (s < 10 ) { s_str = '0' + s_str; }
 
var m_str = m.toString();
if (m < 10 ) { m_str= '0' + m_str; }
 
var h_str = h.toString();
if (h < 10 ) { h_str= '0' + h_str; }
 
 
if ( t < 60 ) { return s_str + 's' ; }
else if ( t < 3600 ) { return m_str + 'm' + s_str + 's' ; }
else { return h_str + 'h' + m_str + 'm' + s_str + 's'; }
 
};
 
chilliController.formatBytes = function ( b , zeroReturn ) {
 
if ( typeof(b) == 'undefined' ) {
b = 0;
} else {
b = parseInt ( b , 10 ) ;
}
 
if ( (typeof (zeroReturn) !='undefined') && ( b === 0 ) ) {
return zeroReturn;
}
 
var kb = Math.round(b / 10) / 100;
if (kb < 1) return b + ' Bytes';
 
var mb = Math.round(kb / 10) / 100;
if (mb < 1) return kb + ' Kilobytes';
 
var gb = Math.round(mb / 10) / 100;
if (gb < 1) return mb + ' Megabytes';
 
return gb + ' Gigabytes';
};
 
 
/**
* Global chilliController object
*
* PUBLIC METHODS
* --------------
* logon ( username, password ) :
* Attempt a CHAP logon with username/password
* issues a /logon command to chilli daemon
*
* logon2 ( username, response ) :
* Attempt a CHAP logon with username/response
* issues a /logon command to chilli daemon
*
* logoff () :
* Disconnect the current user by issuing a
* /logoff command to the chilli daemon
*
* refresh () :
* Issues a /status command to chilli daemon to refresh
* the local chilliController object state/session data
*
*/
chilliController.logon = function ( username , password ) {
 
if ( typeof(username) !== 'string') {
chilliController.onError( 1 , "username missing (or incorrect type)" ) ;
}
if ( typeof(password) !== 'string') {
chilliController.onError( 2 , "password missing (or incorrect type)" ) ;
}
 
log ( 'chilliController.logon( "' + username + '" , "' + password + ' " )' );
 
chilliController.temp = { 'username': username , 'password': password };
chilliController.command = 'logon';
 
log ('chilliController.logon: asking for a new challenge ' );
chilliJSON.onError = chilliController.onError ;
chilliJSON.onJSONReady = chilliController.logonStep2 ;
chilliController.clientState = chilliController.AUTH_PENDING ;
chilliJSON.get( chilliController.urlRoot() + 'status' ) ;
};
 
chilliController.logon2 = function ( username , response ) {
 
if ( typeof(username) !== 'string') {
chilliController.onError( 1 , "username missing (or incorrect type)" ) ;
}
if ( typeof(response) !== 'string') {
chilliController.onError( 2 , "response missing (or incorrect type)" ) ;
}
 
log ( 'chilliController.logon2( "' + username + '" , "' + response + ' " )' );
 
chilliController.temp = { 'username': username , 'response': response };
chilliController.command = 'logon2';
 
log ('chilliController.logon2: asking for a new challenge ' );
chilliJSON.onError = chilliController.onError ;
chilliJSON.onJSONReady = chilliController.logonStep2 ;
chilliController.clientState = chilliController.AUTH_PENDING ;
chilliJSON.get( chilliController.urlRoot() + 'status' ) ;
};
 
 
/**
* Second part of the logon process invoked after
* the just requested challenge has been received
*/
chilliController.logonStep2 = function ( resp ) {
 
log('Entering logonStep 2');
 
if ( typeof (resp.challenge) != 'string' ) {
log('logonStep2: cannot find a challenge. Aborting.');
return chilliController.onError('Cannot get challenge');
}
 
if ( resp.clientSate === chilliController.stateCodes.AUTH ) {
log('logonStep2: Already connected. Aborting.');
return chilliController.onError('Already connected.');
}
 
var challenge = resp.challenge;
 
var username = chilliController.temp.username ;
var password = chilliController.temp.password ;
var response = chilliController.temp.response ;
 
log ('chilliController.logonStep2: Got challenge = ' + challenge );
 
if ( chilliController.uamService ) { /* MD5 CHAP will be calculated by uamService */
 
log ('chilliController.logonStep2: Logon using uamService (external MD5 CHAP)');
 
var c ;
if ( chilliController.uamService.indexOf('?') === -1 ) {
c = '?' ;
}
else {
c = '&' ;
}
 
// Build command URL
var url = chilliController.uamService + c + 'username=' + escape(username) +'&password=' + escape(password) +'&challenge=' + challenge ;
 
if (chilliController.queryObj && chilliController.queryObj['userurl'] ) {
url += '&userurl='+chilliController.queryObj['userurl'] ;
}
 
// Make uamService request
chilliJSON.onError = chilliController.onError ;
chilliJSON.onJSONReady = chilliController.logonStep3 ;
 
chilliController.clientState = chilliController.AUTH_PENDING ;
chilliJSON.get( url ) ;
}
else {
/* TODO: Should check if challenge has expired and possibly get a new one */
/* OR always call status first to get a fresh challenge */
 
if (!response || response == '') {
/* Calculate MD5 CHAP at the client side */
var myMD5 = new ChilliMD5();
response = myMD5.chap ( chilliController.ident , password , challenge );
log ( 'chilliController.logonStep2: Calculating CHAP-Password = ' + response );
}
 
/* Prepare chilliJSON for logon request */
chilliJSON.onError = chilliController.onError ;
chilliJSON.onJSONReady = chilliController.processReply ;
chilliController.clientState = chilliController.stateCodes.AUTH_PENDING ;
/* Build /logon command URL */
var logonUrl = chilliController.urlRoot() + 'logon?username=' + escape(username) + '&response=' + response;
if (chilliController.queryObj && chilliController.queryObj['userurl'] ) {
logonUrl += '&userurl='+chilliController.queryObj['userurl'] ;
}
chilliJSON.get ( logonUrl ) ;
}
 
};
 
/**
* Third part of the logon process invoked after
* getting a uamService response
*/
chilliController.logonStep3 = function ( resp ) {
log('Entering logonStep 3');
 
var username = chilliController.temp.username ;
 
if ( typeof (resp.response) == 'string' ) {
chilliJSON.onError = chilliController.onError ;
chilliJSON.onJSONReady = chilliController.processReply ;
chilliController.clientState = chilliController.stateCodes.AUTH_PENDING ;
/* Build /logon command URL */
var logonUrl = chilliController.urlRoot() + 'logon?username=' + escape(username) + '&response=' + resp.response;
if (chilliController.queryObj && chilliController.queryObj['userurl'] ) {
logonUrl += '&userurl='+chilliController.queryObj['userurl'] ;
}
chilliJSON.get ( logonUrl ) ;
}
}
 
chilliController.refresh = function ( ) {
 
if ( chilliController.autorefreshTimer ) {
chilliController.command = 'autorefresh' ;
}
else {
chilliController.command = 'refresh' ;
}
 
chilliJSON.onError = chilliController.onError ;
chilliJSON.onJSONReady = chilliController.processReply ;
chilliJSON.get( chilliController.urlRoot() + 'status' ) ;
};
 
chilliController.logoff = function () {
 
chilliController.command = 'logoff' ;
chilliJSON.onError = chilliController.onError ;
chilliJSON.onJSONReady = chilliController.processReply ;
chilliJSON.get( chilliController.urlRoot() + 'logoff' );
};
 
/* *
*
* This functions does some check/type processing on the JSON resp
* and updates the corresponding chilliController members
*
*/
chilliController.processReply = function ( resp ) {
 
if ( typeof (resp.message) == 'string' ) {
 
/* The following trick will replace HTML entities with the corresponding
* character. This will not work in Flash (no innerHTML)
*/
 
var fakediv = document.createElement('div');
fakediv.innerHTML = resp.message ;
chilliController.message = fakediv.innerHTML ;
}
 
if ( typeof (resp.challenge) == 'string' ) {
chilliController.challenge = resp.challenge ;
}
 
if ( typeof ( resp.location ) == 'object' ) {
chilliController.location = resp.location ;
}
 
if ( typeof ( resp.accounting ) == 'object' ) {
chilliController.accounting = resp.accounting ;
}
 
if ( (typeof ( resp.redir ) == 'object') ) {
chilliController.redir = resp.redir ;
}
/* Update the session member only the first time after AUTH */
if ( (typeof ( resp.session ) == 'object') &&
( chilliController.session==null || (
( chilliController.clientState !== chilliController.stateCodes.AUTH ) &&
( resp.clientState === chilliController.stateCodes.AUTH )))) {
 
chilliController.session = resp.session ;
 
if ( resp.session.startTime ) {
chilliController.session.startTime = new Date();
chilliController.session.startTime.setTime(resp.session.startTime);
}
}
 
/* Update clientState */
if ( ( resp.clientState === chilliController.stateCodes.NOT_AUTH ) ||
( resp.clientState === chilliController.stateCodes.AUTH ) ||
( resp.clientState === chilliController.stateCodes.AUTH_SPLASH ) ||
( resp.clientState === chilliController.stateCodes.AUTH_PENDING ) ) {
 
chilliController.clientState = resp.clientState ;
}
else {
chilliController.onError("Unknown clientState found in JSON reply");
}
 
 
/* Launch or stop the autorefresh timer if required */
if ( chilliController.clientState === chilliController.stateCodes.AUTH ) {
 
if ( !chilliController.autorefreshTimer ) {
chilliController.autorefreshTimer = setInterval ('chilliController.refresh()' , 1000*chilliController.interval);
}
}
else if ( chilliController.clientState === chilliController.stateCodes.NOT_AUTH ) {
clearInterval ( chilliController.autorefreshTimer ) ;
chilliController.autorefreshTimer = 0 ;
}
 
/* Lastly... call the event handler */
log ('chilliController.processReply: Calling onUpdate. clienState = ' + chilliController.clientState);
chilliController.onUpdate( chilliController.command );
};
 
 
 
/**
* chilliJSON object
*
* This private objet implements the cross domain hack
* If no answer is received before timeout, then an error is raised.
*
*/
 
var chilliJSON = { timeout:25000 , timer:0 , node:0 , timestamp:0 };
 
chilliJSON.expired = function () {
 
if ( chilliJSON.node.text ) {
log ('chilliJSON: reply content \n' + chilliJSON.node.text );
}
else {
log ('chilliJSON: request timed out (or reply is not valid JS)');
}
 
clearInterval ( chilliJSON.timer ) ;
chilliJSON.timer = 0 ;
 
/* remove the <SCRIPT> tag node that we have created */
if ( typeof (chilliJSON.node) !== 'number' ) {
document.getElementsByTagName('head')[0].removeChild ( chilliJSON.node );
}
chilliJSON.node = 0;
 
/* TODO: Implement some kind of retry mechanism here ... */
 
chilliJSON.onError('JSON request timed out (or reply is not valid)');
};
 
chilliJSON.reply = function ( raw ) {
 
clearInterval ( chilliJSON.timer ) ;
chilliJSON.timer = 0 ;
 
var now = new Date() ;
var end = now.getTime() ;
if ( chilliJSON.timestamp ) {
log ( 'chilliJSON: JSON reply received in ' + ( end - chilliJSON.timestamp ) + ' ms\n' + dumpObject(raw) );
}
 
if ( typeof (chilliJSON.node) !== 'number' ) {
document.getElementsByTagName('head')[0].removeChild ( chilliJSON.node );
}
chilliJSON.node = 0;
 
/* TODO: We should parse raw JSON as an extra security measure */
chilliJSON.onJSONReady( raw ) ;
} ;
 
chilliJSON.get = function ( gUrl ) {
 
if ( typeof(gUrl) == "string" ) {
chilliJSON.url = gUrl ;
}
else {
log ( "chilliJSON:error:Incorrect url passed to chilliJSON.get():" + gUrl );
chilliJSON.onError ( "Incorrect url passed to chilliJSON.get() " );
return ;
}
 
if ( chilliJSON.timer ) {
log('logon: There is already a request running. Return without launching a new request.');
return ;
}
 
var scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
 
var c ;
if ( this.url.indexOf('?') === -1 ) {
c = '?' ;
}
else {
c = '&' ;
}
 
scriptElement.src = chilliJSON.url + c + 'callback=chilliJSON.reply' ;
scriptElement.src += '&'+Math.random(); // prevent caching in Safari
/* Adding the node that will trigger the HTTP request to the DOM tree */
chilliJSON.node = document.getElementsByTagName('head')[0].appendChild(scriptElement);
 
/* Using interval instead of timeout to support Flash 5,6,7 */
chilliJSON.timer = setInterval ( 'chilliJSON.expired()' , chilliJSON.timeout ) ;
var now = new Date();
chilliJSON.timestamp = now.getTime() ;
 
log ('chilliJSON: getting ' + chilliJSON.url + ' . Waiting for reply ...');
 
}; // end chilliJSON.get = function ( url )
 
 
/**
* chilliClock object
*
* Can be used by BBSMs to display a count down.
*
* Will sync with chilliController and modulate the delay to call onTick
* This will avoid ugly sequence of short updates in the IO
* (not yet implemented)
*
*/
 
var chilliClock = { isStarted : 0 };
 
chilliClock.onTick = function () {
log ("You should define your own onTick() handler on this clock object. Clock value = " + this.value );
};
chilliClock.increment = function () {
 
chilliClock.value = chilliClock.value + 1 ;
chilliClock.onTick( chilliClock.value ) ;
};
 
chilliClock.resync = function ( newval ) {
clearInterval ( chilliClock.isStarted ) ;
chilliClock.value = parseInt( newval , 10 ) ;
chilliClock.isStarted = setInterval ( 'chilliClock.increment()' , 1000 );
};
 
chilliClock.start = function ( newval ) {
 
if ( typeof (newval) !== 'Number' ) {
chilliClock.resync ( 0 ) ;
}
else {
chilliClock.resync ( newval ) ;
}
};
 
chilliClock.stop = function () {
clearInterval ( chilliClock.isStarted ) ;
chilliClock.isStarted = 0 ;
};
 
 
function getel(e) {
if (document.getElementById) {
return document.getElementById(e);
} else if (document.all){
return document.all[e];
}
}
 
function log( msg , messageLevel ) {
if (!chilliController.debug) return;
if ( typeof(trace)=="function") {
// ActionScript trace
trace ( msg );
}
else if ( typeof(console)=="object") {
// FireBug console
console.debug ( msg );
}
 
if ( getel('debugarea') ) {
var e = getel('debugarea') ;
e.value = e.value + '\n' + msg;
e.scrollTop = e.scrollHeight - e.clientHeight;
}
}
 
/* Transform an object to a text representation */
function dumpObject ( obj ) {
 
var str = '' ;
 
for (var key in obj ) {
str = str + " " + key + " = " + obj[key] + "\n" ;
if ( typeof ( obj[key] ) == "object" ) {
for ( var key2 in obj[key] ) {
str = str + " " + key2 + " = " + obj[key][key2] + "\n" ;
}
}
}
 
return str;
}
 
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*
* added by Y.DELTROO
* - new functions: chap(), hex2binl() and str2hex()
* - modifications to comply with the jslint test, http://www.jslint.com/
*
* Copyright (c) 2007
* Distributed under the BSD License
*
*/
 
 
function ChilliMD5() {
 
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
 
this.hex_md5 = function (s){
return binl2hex(core_md5(str2binl(s), s.length * chrsz));
};
 
this.chap = function ( hex_ident , str_password , hex_chal ) {
 
// Convert everything to hex encoded strings
var hex_password = str2hex ( str_password );
 
// concatenate hex encoded strings
var hex = hex_ident + hex_password + hex_chal;
 
// Convert concatenated hex encoded string to its binary representation
var bin = hex2binl ( hex ) ;
 
// Calculate MD5 on binary representation
var md5 = core_md5( bin , hex.length * 4 ) ;
 
return binl2hex( md5 );
};
 
function core_md5(x, len) {
x[len >> 5] |= 0x80 << ((len) % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
 
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
 
for(var i = 0; i < x.length; i += 16) {
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
 
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
 
a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
 
a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
 
a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
 
a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
}
return [ a, b, c, d ];
 
}
 
function md5_cmn(q, a, b, x, s, t) {
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
 
function md5_ff(a, b, c, d, x, s, t) {
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
 
function md5_gg(a, b, c, d, x, s, t) {
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
 
function md5_hh(a, b, c, d, x, s, t) {
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
 
function md5_ii(a, b, c, d, x, s, t) {
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}
 
function safe_add(x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
function bit_rol(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt));
}
 
function str2binl(str) {
var bin = [] ;
var mask = (1 << chrsz) - 1;
for (var i = 0; i < str.length * chrsz; i += chrsz) {
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
}
return bin;
}
 
function binl2hex(binarray) {
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for (var i = 0; i < binarray.length * 4; i++) {
str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
}
return str;
}
 
function str2hex ( str ) {
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var hex = '';
var val ;
for ( var i=0 ; i<str.length ; i++) {
/* TODO: adapt this if chrz=16 */
val = str.charCodeAt(i);
hex = hex + hex_tab.charAt( val/16 );
hex = hex + hex_tab.charAt( val%16 );
}
return hex;
}
 
function hex2binl ( hex ) {
/* Clean-up hex encoded input string */
hex = hex.toLowerCase() ;
hex = hex.replace( / /g , "");
 
var bin =[] ;
 
/* Transfrom to array of integers (binary representation) */
for ( i=0 ; i < hex.length*4 ; i=i+8 ) {
octet = parseInt( hex.substr( i/4 , 2) , 16) ;
bin[i>>5] |= ( octet & 255 ) << (i%32);
}
return bin;
}
} // end of ChilliMD5 constructor
/web/js/statusControler.js
0,0 → 1,231
chilliController.interval = 10;
chilliController.host = "192.168.182.1";
chilliController.port = 3990;
chilliController.onUpdate = updateUI ;
chilliController.onError = handleError ;
chilliClock.onTick = function () { }
 
if (!window.queryObj) {
window.queryObj = new Object();
window.location.search.replace(new RegExp("([^?=&]+)(=([^&]*))?","g"), function($0,$1,$2,$3) { queryObj[$1] = $3; });
}
 
chilliController.queryObj = window.queryObj;
 
function ie_getElementsByTagName(str) {
if (str=="*") return document.all;
else return document.all.tags(str);
}
 
if (document.all)
document.getElementsByTagName = ie_getElementsByTagName;
 
function hidePage(page) {
var e = document.getElementById(page);
if (e != null) e.style.display='none';
}
 
function showPage(page) {
var e = document.getElementById(page);
if (e != null) e.style.display='inline';
}
 
function setElementValue(elem, val, forceHTML) {
var e = document.getElementById(elem);
if (e != null) {
var node = e;
if (!forceHTML && node.firstChild) {
node = node.firstChild;
node.nodeValue = val;
} else {
node.innerHTML = val;
}
}
}
 
chilliClock.onChange = function ( newval ) {
setElementValue("sessionTime", chilliController.formatTime(newval));
}
function updateUI (cmd ) {
log ( "Update UI is called. chilliController.clientState = " + chilliController.clientState ) ;
clearTimeout ( delayTimer );
 
if ( chilliController.redir ) {
if (chilliController.redir.originalURL != null &&
chilliController.redir.originalURL != '') {
setElementValue('originalURL', '<a target="_blank" href="'+chilliController.redir.originalURL+
'">'+chilliController.redir.originalURL+'</a>', true);
}
if (chilliController.redir.redirectionURL != null &&
chilliController.redir.redirectionURL != '') {
setElementValue('redirectionURL', chilliController.redir.redirectionURL);
}
}
 
if ( chilliController.message ) {
setElementValue('logonMessage', chilliController.message);
chilliController.message = null;
chilliController.refresh();
}
 
if ( chilliController.location ) {
setElementValue('locationName', chilliController.location.name);
chilliController.location = null;
}
 
if ( chilliController.clientState == 0 ) {
showLoggedOutPage();
setTimeout('chilliController.refresh()', 1000*chilliController.interval);//WBR for status page only
}
 
if ( chilliController.clientState == 1 ) {
if ( chilliController.statusURL ) {
chilliController.statusWindow = window.open(chilliController.statusURL, "");
} else {
showStatusPage();
}
}
 
if (chilliController.redir.redirectionURL) {
//chilliController.nextWindow = window.open(chilliController.redir.redirectionURL,'nextURL');
window.location.href = chilliController.redir.redirectionURL;
chilliController.redir.redirectionURL = null;
}
if ( chilliController.clientState == 2 ) showWaitPage();
}
 
function handleError( code ) {
clearTimeout(delayTimer);
//showErrorPage(code);
}
 
/* Action triggered when buttons are pressed */
function connect() {
var username = document.getElementById('username').value ;
var password = document.getElementById('password').value ;
 
if (username == null || username == '')
return setElementValue('logonMessage', 'Username is required');
showWaitPage(1000);
chilliController.logon( username , password ) ;
}
 
function disconnect() {
if (confirm("Are you sure you want to disconnect now?")) {
chilliClock.stop();
showWaitPage(1000);
chilliController.logoff();
}
return false;
}
 
/* User interface pages update */
function showLoggedOutPage() {
showPage("loggedOutPage");
hidePage("statusPage");
hidePage("waitPage");
hidePage("errorPage");
window.setTimeout("closePopup()",1000);
}
 
function showStatusPage() {
hidePage("loggedOutPage");
showPage("statusPage");
hidePage("waitPage");
hidePage("errorPage");
// Update message
if ( chilliController.message ) {
setElementValue("statusMessage", chilliController.message);
}
// Update session
setElementValue("sessionId",
chilliController.session.sessionId ?
chilliController.session.sessionId :
"Not available");
setElementValue("userName",
chilliController.session.userName ?
chilliController.session.userName :
"Not available");
setElementValue("startTime",
chilliController.session.startTime ?
chilliController.session.startTime.toLocaleString() :
"Not available");
setElementValue("sessionTimeout",
chilliController.formatTime(chilliController.session.sessionTimeout, 'unlimited'));
 
setElementValue("idleTimeout",
chilliController.formatTime(chilliController.session.idleTimeout, 'unlimited'));
 
setElementValue("maxInputOctets",
chilliController.formatBytes(chilliController.session.maxInputOctets));
setElementValue("maxOutputOctets",
chilliController.formatBytes(chilliController.session.maxOutputOctets));
setElementValue("maxTotalOctets",
chilliController.formatBytes(chilliController.session.maxTotalOctets));
 
// Update accounting
setElementValue("sessionTime",
chilliController.formatTime(chilliController.accounting.sessionTime));
setElementValue("idleTime",
chilliController.formatTime(chilliController.accounting.idleTime));
setElementValue("inputOctets" , chilliController.formatBytes(chilliController.accounting.inputOctets));
setElementValue("outputOctets", chilliController.formatBytes(chilliController.accounting.outputOctets));
chilliClock.resync (chilliController.accounting.sessionTime);
}
 
function showWaitPage(delay) {
/* Wait for delay */
clearTimeout(delayTimer);
if (typeof(delay) == 'number' && (delay > 10)) {
delayTimer= setTimeout('showWaitPage(0)' , delay);
return;
}
/* show the waitPage */
hidePage("loggedOutPage");
hidePage("statusPage");
showPage("waitPage");
hidePage("errorPage");
}
 
function showErrorPage( str ) {
setTimeout('chilliController.refresh()', 15000);
hidePage("loggedOutPage");
hidePage("statusPage");
hidePage("waitPage");
showPage("errorPage");
setElementValue("errorMessage", str);
}
 
var chillijsWindowOnLoad = window.onload;
var delayTimer; // global reference to delayTimer
 
window.onload = function() {
if (chillijsWindowOnLoad)
chillijsWindowOnLoad();
 
//var logonForm = document.getElementById('logonForm');
var logonForm = document.getElementById('loggedOutPage');
 
var head = document.getElementsByTagName("head")[0];
if (head == null) head = document.body;
 
if (logonForm == null) {
logonForm = document.getElementById('loginForm');
}
showWaitPage();
setTimeout('chilliController.refresh()', 500);
}