添加上传

pull/6/head
guanghongwei 2015-04-09 11:27:36 +08:00
parent 2b14fefb5c
commit ff77cc28fa
12 changed files with 195 additions and 24 deletions

View File

@ -7,7 +7,6 @@ import re
import ast
import select
import time
from datetime import datetime
import paramiko
import struct
import fcntl
@ -119,8 +118,9 @@ def log_record(username, host):
except IOError:
raise ServerError('Create logfile failed, Please modify %s permission.' % today_connect_log_dir)
log = Log(user=username, host=host, remote_ip=ip_list, dept_name=dept_name, log_path=log_file_path, start_time=datetime.now(), pid=pid)
log_file.write('Starttime is %s\n' % datetime.now())
log = Log(user=username, host=host, remote_ip=ip_list, dept_name=dept_name,
log_path=log_file_path, start_time=datetime.datetime.now(), pid=pid)
log_file.write('Starttime is %s\n' % datetime.datetime.now())
log.save()
return log_file, log
@ -162,11 +162,11 @@ def posix_shell(chan, username, host):
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty)
log_file.write('Endtime is %s' % datetime.now())
log_file.write('Endtime is %s' % datetime.datetime.now())
log_file.close()
log.is_finished = True
log.log_finished = False
log.end_time = datetime.now()
log.end_time = datetime.datetime.now()
log.save()
print_prompt()
@ -280,7 +280,7 @@ def print_user_hostgroup(username):
group_attr = get_user_hostgroup(username)
groups = group_attr.keys()
for g in groups:
print "[%3s]%s -- %s" % (group_attr[g][0], g, group_attr[g][1])
print "[%3s] %s -- %s" % (group_attr[g][0], g, group_attr[g][1])
def print_user_hostgroup_host(username, gid):

View File

@ -16,7 +16,7 @@ class Perm(models.Model):
class CmdGroup(models.Model):
name = models.CharField(max_length=50)
name = models.CharField(max_length=50, unique=True)
cmd = models.CharField(max_length=999)
dept = models.ForeignKey(DEPT)
comment = models.CharField(blank=True, null=True, max_length=50)

View File

@ -23,6 +23,7 @@ urlpatterns = patterns('jperm.views',
(r'^cmd_list/$', 'cmd_list'),
(r'^cmd_del/$', 'cmd_del'),
(r'^cmd_edit/$', 'cmd_edit'),
(r'^cmd_detail/$', 'cmd_detail'),
(r'^apply/$', 'perm_apply'),
(r'^apply_show/(\w+)/$', 'perm_apply_log'),
(r'^apply_exec/$', 'perm_apply_exec'),

View File

@ -3,19 +3,13 @@
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import datetime
from django.core.mail import send_mail
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
from juser.models import User, UserGroup, DEPT
from jasset.models import Asset, BisGroup
from jperm.models import Perm, SudoPerm, CmdGroup, Apply
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.db.models import Q
from jumpserver.views import LDAP_ENABLE, ldap_conn, CONF, page_list_return, pages
from jumpserver.api import *
@ -544,8 +538,6 @@ def cmd_add(request):
error = u"閮ㄩ棬涓嶈兘涓虹┖"
msg = u'鍛戒护缁勬坊鍔犳垚鍔'
return HttpResponseRedirect('/jperm/cmd_list/')
return render_to_response('jperm/sudo_cmd_add.html', locals(), context_instance=RequestContext(request))
@ -597,7 +589,7 @@ def cmd_edit(request):
def cmd_list(request):
header_title, path1, path2 = u'sudo鍛戒护鏌ョ湅', u'鏉冮檺绠$悊', u'Sudo鍛戒护娣诲姞'
if request.session.get('role_id', '0') == '2':
if is_super_user(request):
cmd_groups = contact_list = CmdGroup.objects.all()
else:
user, dept = get_session_user_dept(request)
@ -626,6 +618,16 @@ def cmd_del(request):
return HttpResponseRedirect('/jperm/cmd_list/')
@require_admin
def cmd_detail(request):
cmd_id = request.GET.get('id')
cmd_group = CmdGroup.objects.filter(id=cmd_id)
if cmd_group:
cmd_group = cmd_group[0]
return render_to_response('jperm/sudo_cmd_detail.html', locals(), context_instance=RequestContext(request))
@require_login
def perm_apply(request):
header_title, path1, path2 = u'涓绘満鏉冮檺鐢宠', u'鏉冮檺绠$悊', u'鐢宠涓绘満'

View File

@ -5,7 +5,7 @@ import ast
import time
from django import template
from juser.models import User, UserGroup, DEPT
from jperm.models import CmdGroup
from jumpserver.api import *
from jasset.models import AssetAlias
@ -264,3 +264,19 @@ def time_delta(time_before):
return '%s 鍒嗛挓鍓' % mins
else:
return '%s 绉掑墠' % delta.seconds
@register.filter(name='sudo_cmd_list')
def sudo_cmd_list(cmd_group_id):
cmd_group = CmdGroup.objects.filter(id=cmd_group_id)
if cmd_group:
cmd_group = cmd_group[0]
return cmd_group.cmd.split(',')
@register.filter(name='sudo_cmd_count')
def sudo_cmd_count(cmd_group_id):
cmd_group = CmdGroup.objects.filter(id=cmd_group_id)
if cmd_group:
cmd_group = cmd_group[0]
return len(cmd_group.cmd.split(','))

View File

@ -144,11 +144,14 @@ def index(request):
active_users = User.objects.filter(is_active=1)
active_hosts = Asset.objects.filter(is_active=1)
users_total = users.count() if users.count() else 1
hosts_total = hosts.count() if hosts.count() else 1
# percent of dashboard
percent_user = format(active_users.count() / users.count(), '.0%')
percent_host = format(active_hosts.count() / hosts.count(), '.0%')
percent_online_user = format(online_user.count() / users.count(), '.0%')
percent_online_host = format(online_host.count() / hosts.count(), '.0%')
percent_user = format(active_users.count() / users_total, '.0%')
percent_host = format(active_hosts.count() / hosts_total, '.0%')
percent_online_user = format(online_user.count() / users_total, '.0%')
percent_online_host = format(online_host.count() / hosts_total, '.0%')
li_date, li_str = getDaysByNum(7)
today = datetime.datetime.now().day
@ -290,4 +293,12 @@ def install(request):
def upload(request):
pass
if request.method == 'POST':
host = request.POST.get('host')
path = request.POST.get('path')
upload_file = request.FILES.getlist('file', None)
if upload_file:
return HttpResponse(upload_file)
return render_to_response('upload.html', locals(), context_instance=RequestContext(request))

View File

@ -24,6 +24,7 @@
<!-- highcharts -->
<script src="/static/js/highcharts/highcharts.js"></script>
<script src="/static/js/dropzone/dropzone.js"></script>
<!-- active menu -->
<script>
var str = document.location.pathname.split("/")[1];

View File

@ -8,3 +8,4 @@
<!-- validator js -->
<script src="/static/js/validator/jquery.validator.js"></script>
<script src="/static/js/validator/zh_CN.js"></script>

View File

@ -0,0 +1,44 @@
{% load mytags %}
<html>
<head>
{% include 'link_css.html' %}
<style type="text/css">
body
{
background: #FFFFFF;
}
</style>
</head>
<body>
<div class="row">
<div class="contact-box">
<h2 class="text-center">{{ cmd_group.name }} 鍛戒护璇︽儏</h2>
<div class="ibox-content">
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<td class="text-center" width="120">ID</td>
<td class="text-center">鍚嶇О</td>
<td class="text-center">閮ㄩ棬</td>
</tr>
</thead>
<tbody>
<tr class="gradeX">
<td class="text-center">{{ cmd_group.id }}</td>
<td class="text-center">{{ cmd_group.name }}</td>
<td class="text-center">{{ cmd_group.dept.name }}</td>
</tr>
<tr>
<td colspan="1" class="text-center">鍛戒护锛</td>
<td colspan="6" class="text-center">
<b>{{ cmd_group.cmd }}</b>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>

View File

@ -69,7 +69,7 @@
<td class="text-center"><a href="/juser/user_list/?gid={{ group.id }}">{{ group.id | member_count }} </a> </td>
<td class="text-center"><a href="/jasset/group_list/?sid={{ group.id }}">{{ group.id | ugrp_perm_agrp_count }} </a> </td>
<td class="text-center"><a href="/jasset/host_list/?sid={{ group.id }}"> {{ group.id | ugrp_perm_asset_count }} </a> </td>
<td class="text-center"> {{ group.id | ugrp_perm_asset_count }} </td>
<td class="text-center"><a value="/jperm/cmd_detail/?id={{ group.id }}" class="iframe">{{ group.id | sudo_cmd_count }}</a> </td>
<td class="text-center"> {{ group.comment }} </td>
<td class="text-center">
<a href="../sudo_edit/?id={{ group.id }}" class="btn btn-xs btn-danger">sudo鎺堟潈</a>
@ -104,7 +104,20 @@
<script>
$(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"70%", height:"70%"});
$(".iframe").on('click', function(){
var url= $(this).attr("value");
$.layer({
type: 2,
title: '鍛戒护璇︽儏',
maxmin: true,
shift: 'top',
border: [2, 0.3, '#1AB394'],
shade: [0.5, '#000000'],
shadeClose: true,
area : ['800px' , '600px'],
iframe: {src: url}
});
});
$("#refresh").click(function(){
$.get('/jperm/sudo_refresh/',
{'test':''},

View File

@ -7,3 +7,5 @@
<link href="/static/css/vaildator/jquery.validator.css" rel="stylesheet">
<link href="/static/css/magnific/magnific-popup.css" rel="stylesheet">
<link href="/static/css/plugins/fullcalendar/fullcalendar.css" rel="stylesheet">
<link href="/static/css/plugins/dropzone/basic.css" rel="stylesheet">
<link href="/static/css/plugins/dropzone/dropzone.css" rel="stylesheet">

80
templates/upload.html Normal file
View File

@ -0,0 +1,80 @@
{% extends 'base.html' %}
{% load mytags %}
{% load humanize %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content">
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Dropzone Area</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">Config option 1</a>
</li>
<li><a href="#">Config option 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<form id="my-awesome-dropzone" class="dropzone" action="#">
<div class="dropzone-previews"></div>
<button type="submit" class="btn btn-primary pull-right">Submit this form!</button>
</form>
<div>
<div class="m text-right"><small>DropzoneJS is an open source library that provides drag'n'drop file uploads with image previews: <a href="https://github.com/enyo/dropzone" target="_blank">https://github.com/enyo/dropzone</a></small> </div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
Dropzone.options.myAwesomeDropzone = {
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100,
url: '/upload/',
// Dropzone settings
init: function() {
var myDropzone = this;
this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
});
this.on("sendingmultiple", function() {
});
this.on("successmultiple", function(files, response) {
alert(files)
});
this.on("errormultiple", function(files, response) {
});
}
}
});
</script>
{% endblock %}