<!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" dir="ltr">
<head>
	<title>Shell</title>
	<jsp:include page="head_include.jsp">
		<jsp:param name="page" value="shell" />
	</jsp:include>
</head>
<body>
<script type="text/javascript">
$(function() {
window.linkifyURLs=false, suppressAllAudio=true;
window.userCSSList = [
	[ 'White on Black', false, true, '/library/css/cli/' ],
	[ 'Black on White', false, false, '/library/css/cli/' ],
	[ 'Monochrome', true, false, '/library/css/cli/' ],
	[ 'Color Terminal', false, true, '/library/css/cli/' ]
];

function extend(subClass, baseClass) {
	function inheritance() {}
	inheritance.prototype          = baseClass.prototype;
	subClass.prototype             = new inheritance();
	subClass.prototype.constructor = subClass;
	subClass.prototype.superClass  = baseClass.prototype;
};
extend(CLI = function() {}, VT100);

CLI.prototype.initialize = function(url, container) {
	this.superClass.constructor.call(this, container);
	this.wsURL = url;
	this.ws = null;
	
	setTimeout(function(cli) {
		return function() {
			cli.run();
		};
	}(this), 1000);
	
	this.reconnectBtn.firstChild.className = 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only';
	this.reconnectBtn.firstChild.value = 'Reconnect';
};

var listening = 0;
var id = Math.random();
var mac=getURLParameter('mac') || '00:27:22:e5:07:42';	// fake
var name=getURLParameter('name') || mac || 'unknown';

document.title = 'Shell[' + name + ']';

function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}


CLI.prototype.keysPressed = function(ch) {
	var self = this;
	
	listening ++;
	$.post('/cli/console/' + mac + '/' + id, ch, function(response) {
		listening--;
		self.vt100(response);
		if (listening==0)
			self.run();
	});
};

CLI.prototype.run = function() {
	var self = this;
	listening ++;
	$.post('/cli/console/' + mac + '/' + id + "/read", {}, function(response) {
		listening --;
		//$.log(response);
		self.vt100(response);
		if (listening==0)
			self.run();
	});
};

CLI.prototype.showReconnect = function(state) {
	this.superClass.showReconnect.call(this, state);
	
	if (state) {
		document.body.className = 'disabled';
	} else {
		document.body.className = '';
	}
};

CLI.prototype.reconnect = function() {
	this.reset(false);
	this.showReconnect(false);
	this.run();
};

var cli = new CLI('/cli');
cli.initialize(document.body);
}); 
</script>
</body>
</html>
