-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
root
committed
Jul 31, 2019
1 parent
a111937
commit 6fde80d
Showing
85 changed files
with
1,128 additions
and
177 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
from channels.auth import AuthMiddlewareStack | ||
from channels.routing import ProtocolTypeRouter, URLRouter | ||
from webssh import routing as websshrouting | ||
from websocket import routing as websocketrouting | ||
from webssh.websocket import WebSSH | ||
from webtelnet.websocket import WebTelnet | ||
from django.urls import path | ||
|
||
application = ProtocolTypeRouter({ | ||
'websocket': AuthMiddlewareStack( | ||
URLRouter( | ||
websshrouting.websocket_urlpatterns, | ||
|
||
application = ProtocolTypeRouter( | ||
{ | ||
'websocket': AuthMiddlewareStack( | ||
URLRouter( | ||
websocketrouting.websocket_urlpatterns | ||
) | ||
) | ||
), | ||
}) | ||
} | ||
) | ||
|
||
# or like this | ||
# application = ProtocolTypeRouter( | ||
# { | ||
# 'websocket': AuthMiddlewareStack( | ||
# URLRouter( | ||
# [ | ||
# path('webssh/', WebSSH), | ||
# path('webtelnet/', WebTelnet), | ||
# ] | ||
# ) | ||
# ) | ||
# } | ||
# ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
'server', | ||
'user', | ||
'webssh', | ||
'webtelnet', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 2.2.3 on 2019-07-30 15:44 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('server', '0003_auto_20190730_0956'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='host', | ||
name='protocol', | ||
field=models.SmallIntegerField(choices=[(0, '其他'), (1, 'ssh'), (2, 'telnet'), (3, 'rdp'), (4, 'vnc'), (5, 'sftp'), (6, 'ftp')], default=1, verbose_name='协议'), | ||
), | ||
migrations.AlterField( | ||
model_name='remoteuser', | ||
name='enabled', | ||
field=models.BooleanField(default=False, verbose_name='登陆后是否su跳转超级用户'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 2.2.3 on 2019-07-30 17:04 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('server', '0004_auto_20190730_1544'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name='host', | ||
unique_together={('ip', 'protocol', 'port')}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 2.2.3 on 2019-07-31 08:34 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('server', '0005_auto_20190730_1704'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='remoteuserbindhost', | ||
name='host', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='server.Host'), | ||
), | ||
migrations.AlterField( | ||
model_name='remoteuserbindhost', | ||
name='remote_user', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='server.RemoteUser'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 2.2.3 on 2019-07-31 09:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('server', '0006_auto_20190731_0834'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='host', | ||
name='type', | ||
field=models.SmallIntegerField(choices=[(0, '其他'), (1, '服务器'), (2, '防火墙'), (3, '路由器'), (4, '二层交换机'), (5, '三层交换机'), (6, '虚拟机'), (7, 'PC机')], default=1, verbose_name='类型'), | ||
), | ||
migrations.AlterField( | ||
model_name='host', | ||
name='release', | ||
field=models.CharField(default='CentOS', max_length=255, verbose_name='系统/型号'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.2.3 on 2019-07-31 15:38 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('server', '0007_auto_20190731_0925'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='host', | ||
name='env', | ||
field=models.SmallIntegerField(choices=[(0, '其他'), (1, '正式环境'), (2, '测试环境')], default=1, verbose_name='环境'), | ||
), | ||
] |
Binary file added
BIN
+852 Bytes
server/migrations/__pycache__/0004_auto_20190730_1544.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+528 Bytes
server/migrations/__pycache__/0005_auto_20190730_1704.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+778 Bytes
server/migrations/__pycache__/0006_auto_20190731_0834.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+918 Bytes
server/migrations/__pycache__/0007_auto_20190731_0925.cpython-37.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
function checkwindow() { | ||
event.returnValue=false; | ||
} | ||
|
||
function get_connect_info() { | ||
var hostid = $.trim($('#hostid').text()); | ||
var connect_info = 'hostid=' + hostid; | ||
return connect_info | ||
} | ||
|
||
|
||
function get_term_size() { | ||
var init_width = 9; | ||
var init_height = 17; | ||
|
||
var windows_width = $(window).width(); | ||
var windows_height = $(window).height(); | ||
|
||
return { | ||
cols: Math.floor(windows_width / init_width), | ||
rows: Math.floor(windows_height / init_height), | ||
} | ||
} | ||
|
||
|
||
function websocket() { | ||
var cols = get_term_size().cols; | ||
var rows = get_term_size().rows; | ||
var connect_info = get_connect_info(); | ||
|
||
var term = new Terminal( | ||
{ | ||
cols: cols, | ||
rows: rows, | ||
useStyle: true, | ||
cursorBlink: true | ||
} | ||
), | ||
protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://', | ||
socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/webtelnet/?' + connect_info; | ||
|
||
var sock; | ||
sock = new WebSocket(socketURL); | ||
|
||
// 打开 websocket 连接, 打开 web 终端 | ||
sock.addEventListener('open', function () { | ||
//$('#django-webtelnet-terminal').removeClass('hide'); | ||
term.open(document.getElementById('terminal')); | ||
term.focus(); | ||
term.write('Connecting...\n\r'); | ||
$("body").attr("onbeforeunload",'checkwindow()'); //增加刷新关闭提示属性 | ||
|
||
}); | ||
|
||
// 读取服务器端发送的数据并写入 web 终端 | ||
sock.addEventListener('message', function (recv) { | ||
var data = JSON.parse(recv.data); | ||
var message = data.message; | ||
var status = data.status; | ||
if (status === 0) { | ||
term.write(message) | ||
} else { | ||
//window.location.reload() 端口连接后刷新页面 | ||
//term.clear() | ||
term.write(message) | ||
$("body").removeAttr("onbeforeunload"); //删除刷新关闭提示属性 | ||
|
||
//$(document).keyup(function(event){ // 监听回车按键事件 | ||
// if(event.keyCode == 13){ | ||
//window.location.reload(); | ||
// } | ||
//}); | ||
//term.dispose() | ||
//$('#django-webssh-terminal').addClass('hide'); | ||
//$('#form').removeClass('hide'); | ||
} | ||
}); | ||
|
||
/* | ||
* status 为 0 时, 将用户输入的数据通过 websocket 传递给后台, data 为传递的数据, 忽略 cols 和 rows 参数 | ||
*/ | ||
var message = {'status': 0, 'data': null, 'cols': null, 'rows': null}; | ||
|
||
// 向服务器端发送数据 | ||
term.on('data', function (data) { | ||
message['status'] = 0; | ||
message['data'] = data; | ||
var send_data = JSON.stringify(message); | ||
sock.send(send_data) | ||
}); | ||
|
||
// 监听浏览器窗口, 根据浏览器窗口大小修改终端大小 | ||
$(window).resize(function () { | ||
var cols = get_term_size().cols; | ||
var rows = get_term_size().rows; | ||
term.resize(cols, rows) | ||
}) | ||
} |
Oops, something went wrong.