Skip to content

Commit

Permalink
ver1.7.6 修正 webssh 与 webtelnet 可能会遇到的中文字符被截断以及遇到乱码字符错误退出的 BUG;优化 UI 界…
Browse files Browse the repository at this point in the history
…面,加入动态效果;
  • Loading branch information
root committed Sep 18, 2019
1 parent 636438c commit 1b6abde
Show file tree
Hide file tree
Showing 300 changed files with 871 additions and 1,250 deletions.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

564 changes: 46 additions & 518 deletions .idea/workspace.xml

Large diffs are not rendered by default.

114 changes: 46 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# devops
基于 python 3.7 + django 2.2.3 + AdminLTE-3.0.0-beta.1 实现的运维devops管理系统。具体见 `screenshots` 文件夹中的效果预览图。功能持续完善中。
基于 python 3.7 + django 2.2.3 + channels 2.2.0 + celery 4.3.0 + AdminLTE-3.0.0-beta.1 实现的运维 devops 管理系统。具体见 `screenshots` 文件夹中的效果预览图。功能持续完善中。


# 安装
首先其他依赖服务(docker方式)
首先其他依赖服务(docker 方式)

**redis**
```
Expand All @@ -28,54 +28,70 @@ python3 manage.py proxy_sshd
celery -A devops worker -l info -c 3 --max-tasks-per-child 40
```

**docker方式(Centos 7)**
**docker 方式(Centos 7**
```
sh start_docker.sh
```

- 其他依赖服务相关配置见项目配置文件:devops/settings.py
- windows 对 celery 兼容很差,无法正常使用,所以请使用 linux 部署,推荐 Centos 7 系列
- 调用scrt或者xshell客户端使用的是 URL PROTOCOL,需要本机安装 apploader,具体登陆后见:个人信息 - 配置
- 调用 securecrt、xshell、putty 以及 winscp 客户端使用的是 URL PROTOCOL,具体使用方法见:个人信息 - 配置

访问首页:http://127.0.0.1:8000

账号: admin 密码:123456


# 升级日志

### ver1.7.6
修正 webssh 与 webtelnet 可能会遇到的中文字符被截断以及遇到乱码字符错误退出的 BUG;

优化 UI 界面,加入动态效果;

### ver1.7.5
修正强制断开clissh后保存2次终端日志的BUG;
新增会话在一定时间内无操作自动断开功能(默认30分钟,settings.py中可配置);
个人信息中新增调用本地SSH客户端与本地SFTP客户端相关配置;
webssh终端页面新增文件上传与下载功能(支持5GB以下文件);
修正clissh连接后无法使用sz下载文件和rz上传文件的bug;
修正强制断开 clissh 后保存 2 次终端日志的BUG;

新增会话在一定时间内无操作自动断开功能(默认 30 分钟,settings.py 中可配置);

个人信息中新增调用本地 SSH 客户端与本地 SFTP 客户端相关配置;

webssh 终端页面新增文件上传与下载功能(支持 5GB 以下文件,分段上传,不占用服务器内存);

修正 clissh 连接后无法使用 sz 下载文件和 rz 上传文件的 BUG(Zmodem 只适合上传下载小文件);

### ver1.7.4
新增webguacamole、webssh、webtelnet会话锁定与解锁功能;微调web终端ui;
新增 webguacamole、webssh、webtelnet 会话锁定与解锁功能;

微调 web 终端 UI;

### ver1.7.3
新增webguacamole,支持RDP、VNC协议连接主机,并支持录像回放;
新增 webguacamole,支持 RDP、VNC 协议连接主机,并支持录像回放;

### ver1.7.2
新增客户端连接sftp;
linux平台下使用celery任务保存终端会话日志与录像(windows不支持celery);
新增客户端连接 sftp;

linux 平台下使用 celery 任务保存终端会话日志与录像(windows 不支持 celery);

### ver1.7.1
优化界面;
修复客户端SSH连接部分BUG;

修复客户端 SSH 连接部分 BUG;

### ver1.7.0
新增浏览器调用securecrt,xshell,putty等客户端终端;
新增浏览器调用 securecrt,xshell,putty 等客户端终端;

新增会话录像审计;

### ver1.6.0
新增实时查看在线终端会话;

### ver1.5.0
新增全站表单验证(原生javascript正则表达式验证)
新增全站表单验证(javascript 正则表达式验证)

### ver1.4.0
新增在线终端会话列表查看;

新增强制停止在线终端会话功能;

### ver1.3.0
Expand All @@ -84,18 +100,23 @@ linux平台下使用celery任务保存终端会话日志与录像(windows不支

### ver1.2.0
完善功能;

新增 docker 方式部署;
尝试加入 celery 4.3.0 实现异步任务;

尝试加入 celery 实现异步任务;

### ver1.1.0
新增ssh和telnet协议连接远程主机
新增 ssh 和 telnet 协议连接远程主机

### ver1.0.0
初始版本


# 效果
![效果](https://github.com/leffss/devops/blob/master/screenshots/1.PNG?raw=true)
# 功能
有点多,我很懒,不想描述了。


# 预览
![效果](https://github.com/leffss/devops/blob/master/screenshots/2.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/3.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/4.PNG?raw=true)
Expand All @@ -105,61 +126,18 @@ linux平台下使用celery任务保存终端会话日志与录像(windows不支
![效果](https://github.com/leffss/devops/blob/master/screenshots/8.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/9.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/10.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/11.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/12.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/13.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/14.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/15.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/16.PNG?raw=true)
![效果](https://github.com/leffss/devops/blob/master/screenshots/17.PNG?raw=true)


# TODO LISTS
- [x] 用户登陆
- [x] 查看用户信息
- [x] 修改用户信息
- [x] 修改用户密码
- [ ] 重置用户密码
- [x] 查看用户
- [x] 查看用户组
- [x] 添加用户
- [x] 添加用户组
- [x] 修改用户
- [x] 修改用户组
- [x] 删除用户
- [x] 删除用户组
- [ ] 权限管理(已实现部分)
- [ ] 仪表盘
- [x] 查看主机
- [x] 查看主机用户
- [x] 添加主机
- [x] 添加主机用户
- [x] 修改主机
- [x] 修改主机用户
- [x] 删除主机
- [x] 删除主机用户
- [ ] 主机信息自动获取
- [ ] 主机监控信息查看(zabbix调用)
- [ ] 批量命令
- [ ] 批量脚本
- [x] webssh终端
- [x] webtelnet终端
- [x] webguacamole支持RDP、VNC
- [x] 网页调用securecrt,xshell,putty,winscp等终端(目前只支持windows)
- [ ] websftp终端
- [x] 查看在线会话列表
- [x] 实时查看在线会话
- [ ] 锁定实时在线会话
- [x] 强制关闭在线会话
- [ ] 文件上传
- [ ] 文件下载
- [x] 用户日志审计
- [x] 操作日志审计
- [x] web终端日志审计
- [x] web终端操作录像
- [x] 所有界面表单数据验证(原生javascript正则表单式验证)
- [ ] 搜索
- [ ] 后台耗时任务使用 celery
- [ ] 批量处理(比如,删除操作)
- [ ] 批量执行命令
- [ ] 批量上传文件
- [ ] 集成 ansible,执行 module 与 playbook


更多新功能不断探索发现中.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added apps/server/__pycache__/urls.cpython-37.pyc
Binary file not shown.
File renamed without changes.
Binary file added apps/server/__pycache__/views.cpython-37.pyc
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
37 changes: 37 additions & 0 deletions apps/server/templatetags/server_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django import template
from ..models import RemoteUserBindHost
from django.db.models import Sum, Count
import random

register = template.Library()


def get_field_display(klass, field, value):
f = klass._meta.get_field(field)
return dict(f.flatchoices).get(value, value)


@register.simple_tag
def get_recent_hosts(num=5):
hosts = RemoteUserBindHost.objects.all()[:num]
return hosts


@register.simple_tag
def get_host_types():
result = RemoteUserBindHost.objects.values("type").annotate(total=Count("type")).order_by()
# result = RemoteUserBindHost.objects.all().annotate(total_id=Count("type")).order_by('type')
res = dict()
types = []
for i in result:
i['type'] = get_field_display(RemoteUserBindHost, 'type', i['type'])
types.append(i)
result = RemoteUserBindHost.objects.values("env").annotate(total=Count("env")).order_by()
envs = []
for i in result:
i['env'] = get_field_display(RemoteUserBindHost, 'env', i['env'])
envs.append(i)
res['types'] = types
res['envs'] = envs
return res

File renamed without changes.
1 change: 1 addition & 0 deletions server/urls.py → apps/server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
app_name="server"
urlpatterns = [
path('', views.index, name='index'),
path('redirect/', views.my_redirect, name='my_redirect'),
path('hosts/', views.hosts, name='hosts'),
path('host/<int:host_id>/', views.host, name='host'),
path('host/<int:host_id>/edit/', views.host_edit, name='host_edit'),
Expand Down
File renamed without changes.
12 changes: 11 additions & 1 deletion server/views.py → apps/server/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.shortcuts import render, get_object_or_404
from django.shortcuts import render, get_object_or_404, redirect
from django.urls import reverse
from util.tool import login_required, admin_required
from .models import RemoteUserBindHost, RemoteUser
from user.models import User, Group
Expand All @@ -8,6 +9,15 @@


@login_required
def my_redirect(request):
next = request.GET.get('next', None)
if next:
return redirect(next)
return redirect(reverse('server:index'))


@login_required
@admin_required
def index(request):
host_count = RemoteUserBindHost.objects.all().count()
user_count = User.objects.all().count()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def websocket_to_django(self):
for line in tmp:
f.write('{}'.format(line))
except Exception:
print(traceback.format_exc())
if self.websocker.send_flag == 0:
self.websocker.send('0.;')
elif self.websocker.send_flag == 1:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added apps/webssh/__pycache__/sftp.cpython-37.pyc
Binary file not shown.
Binary file added apps/webssh/__pycache__/ssh.cpython-37.pyc
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 11 additions & 6 deletions webssh/sftp.py → apps/webssh/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def __init__(self, host, port, username, password=None, key_file=None):
self.transport.connect(username=self.username, password=password)

self.sftp = paramiko.SFTPClient.from_transport(self.transport)
self.ssh = paramiko.SSHClient()
self.ssh._transport = self.transport

def put_file(self, local_file, user_home):
"""
Expand All @@ -37,15 +39,15 @@ def put_file(self, local_file, user_home):
file_stat = self.sftp.stat(user_home)
self.sftp.chown(remote_file, file_stat.st_uid, file_stat.st_gid)
except Exception:
logger.error(traceback.format_exc())
print(traceback.format_exc())
finally:
self.transport.close()

def get_file(self, remote_file, local_file):
try:
self.sftp.get(remote_file, local_file)
except Exception:
logger.error(traceback.format_exc())
print(traceback.format_exc())
finally:
self.transport.close()

Expand All @@ -54,16 +56,19 @@ def download_file(self, download_file, local_file):
self.get_file(download_file, local_file)
return True
except Exception:
print(traceback.format_exc())
return False

def upload_file(self, file_name, upload_file_path):
try:
stdin, stdout, stderr = self.ssh.exec_command('echo $HOME')
remote_path = '/tmp'
home_path = stdout.read().decode().strip()
if home_path:
remote_path = home_path
local_file = '{}/{}'.format(upload_file_path, file_name)
if self.username == 'root':
remote_path = '/root/'
else:
remote_path = '/home/{}/'.format(self.username)
self.put_file(local_file, remote_path)
return True, remote_path
except Exception:
print(traceback.format_exc())
return False, None
Loading

0 comments on commit 1b6abde

Please sign in to comment.