修正导入select错误

This commit is contained in:
ibuler
2015-11-05 20:07:21 +08:00
parent 1bc15e57a6
commit 9a897e0cf4
8 changed files with 57 additions and 475 deletions

View File

@@ -108,7 +108,7 @@
function init(obj){
var file_path = obj.attr('file_path');
var wsUri = '{{ web_socket_uri }}';
var wsUri = '{{ web_monitor_uri }}';
var socket = new WebSocket(wsUri + '?file_path=' + file_path);
socket.onopen = function(evt){
socket.send(file_path)

View File

@@ -2,12 +2,10 @@
<html>
<head>
<meta charset="utf-8">
<title>wssh</title>
<title>Jumpserver web terminal</title>
<link href="/static/css/plugins/bootstrap.min.css" rel="stylesheet" />
<style>
body {
padding-top: 60px;
padding-bottom: 40px;
}
@@ -29,139 +27,56 @@
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">wssh</a>
</div>
</div>
</div>
<div class="container">
<!-- Connection form -->
<form id="connect" class="form-horizontal">
<fieldset>
<legend>Connect to a remote SSH server</legend>
<div class="control-group">
<label class="control-label">
Destination
</label>
<div class="controls">
<input type="text" id="username"
class="input-small"
placeholder="root" />
<div class="input-prepend">
<span class="add-on">@</span><input
type="text"
id="hostname"
class="input-large"
placeholder="localhost" />
<span class="add-on">port</span><input
type="text"
id="portnumber"
class="input-small"
value=22 />
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">
Authentication method
</label>
<div class="controls">
<label class="radio">
<input type="radio" name="authentication_method"
value="password" checked />
Password
</label>
<label class="radio">
<input type="radio" name="authentication_method"
value="private_key" />
Private Key
</label>
</div>
</div>
<div class="control-group" id="password_authentication">
<label class="control-label">
Password
</label>
<div class="controls">
<input type="password" id="password"
class="input-large" />
</div>
</div>
<div id="private_key_authentication">
<div class="control-group">
<label class="control-label">
Private Key
</label>
<div class="controls">
<textarea id="private_key" rows="6"
class="input-xxlarge"></textarea>
<p class="help-block">
Copy &amp; Paste your SSH private from
<code>~/.ssh/id_rsa</code> or
<code>~/.ssh/id_dsa</code>
</p>
</div>
</div>
<div class="control-group">
<label class="control-label">
Key Passphrase
</label>
<div class="controls">
<input type="password" id="key_passphrase"
class="input-large" />
<p class="help-block">
Enter your private key passphrase if it
is encrypted. Leave empty otherwise.
</p>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label">
Command
</label>
<div class="controls">
<input type="text" id="command" class="input-large" />
<p class="help-block">
Enter command to be executed or
empty for interactive.
</p>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">
Connect
</button>
</div>
</fieldset>
</form>
<div id="term">
</div>
</div>
<script type="application/javascript" src="/static/js/jquery-2.1.1.js">
</script>
<script type="application/javascript" src="/static/js/term.js">
</script>
<script type="application/javascript" src="/static/js/wssh.js">
</script>
<script type="application/javascript">
function WSSHClient() {
}
WSSHClient.prototype.connect = function(options) {
var endpoint = '{{ web_terminal_uri }}';
if (window.WebSocket) {
this._connection = new WebSocket(endpoint);
}
else if (window.MozWebSocket) {
this._connection = MozWebSocket(endpoint);
}
else {
options.onError('WebSocket Not Supported');
return ;
}
this._connection.onopen = function() {
options.onConnect();
};
this._connection.onmessage = function (evt) {
var data = JSON.parse(evt.data.toString());
if (data.error !== undefined) {
options.onError(data.error);
}
else {
options.onData(data.data);
}
};
this._connection.onclose = function(evt) {
options.onClose();
};
};
WSSHClient.prototype.send = function(data) {
this._connection.send(JSON.stringify({'data': data}));
};
function openTerminal(options) {
var client = new WSSHClient();
var term = new Terminal(80, 24, function(key) {
@@ -191,84 +106,11 @@
<script type='application/javascript'>
$(document).ready(function() {
$('#ssh').hide();
$('#private_key_authentication', '#connect').hide();
var options = {
};
$('input:radio[value=private_key]', '#connect').click(
function() {
$('#password_authentication').hide();
$('#private_key_authentication').show();
}
);
$('input:radio[value=password]', '#connect').click(
function() {
$('#password_authentication').show();
$('#private_key_authentication').hide();
}
);
$('#connect').submit(function(ev) {
ev.preventDefault();
function validate(fields) {
var success = true;
fields.forEach(function(field) {
if (!field.val()) {
field.closest('.control-group')
.addClass('error');
success = false;
}
});
return success;
}
// Clear errors
$('.error').removeClass('error');
var username = $('input:text#username');
var hostname = $('input:text#hostname');
var portnumber = $('input:text#portnumber');
var command = $('input:text#command');
var authentication = $(
'input[name=authentication_method]:checked',
'#connect').val();
var options = {
username: username.val(),
hostname: hostname.val(),
command: command.val(),
authentication_method: authentication
};
var port = parseInt(portnumber.val())
if (port > 0 && port < 65535) {
$.extend(options, {port: port});
} else {
$.extend(options, {port: 22});
}
if (authentication == 'password') {
var password = $('input:password#password');
if (!validate([username, hostname, password]))
return false;
$.extend(options, {password: password.val()});
} else if (authentication == 'private_key') {
var private_key = $('textarea#private_key');
if (!validate([username, hostname, private_key]))
return false;
$.extend(options, {private_key: private_key.val()});
var key_passphrase = $('input:password#key_passphrase');
if (key_passphrase.val()) {
$.extend(options,
{key_passphrase: key_passphrase.val()});
}
}
$('#connect').hide();
$('#ssh').show();
openTerminal(options);
});
$('#ssh').show();
openTerminal(options);
});
</script>
</body>