Beispiel #1
0
def server_type_add(request):
    """
    添加项目方法,用于主机业目分配
    """
    status = check_auth(request, "add_project")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    if request.method == 'POST':  # 验证post方法
        uf = business_form(request.POST)  # 绑定POST动作
        init = request.GET.get("init", False)
        if uf.is_valid():
            uf.save()
            project_name = uf.cleaned_data['service_name']
            if zabbix_on:
                ret = zabbix_group_add(project_name)
                if ret == 0:
                    pass
            if not init:
                return HttpResponseRedirect("/assets/server/type/list/")
            else:
                return HttpResponseRedirect("/assets/host_add/")
    else:
        uf = business_form()
        try:
            dev_group = department_Mode.objects.get(desc_gid=1003)
            user_list = CustomUser.objects.filter(department_id=dev_group.id)
        except:
            pass
        user_group = []
        # user_list = CustomUser.objects.filter(is_superuser__isnull=True)

    return render_to_response('assets/server_type_add.html', locals(), context_instance=RequestContext(request))
Beispiel #2
0
def auth_server_type_edit(request, uuid):
    """
    业务修改模块
    """
    status = check_auth(request, "edit_project")
    if not status:
        return render_to_response('auth/auth_jquery.html', locals(), context_instance=RequestContext(request))

    server_type = Project.objects.all()
    business_name = Project.objects.get(uuid=uuid)
    form_user_qs = ProjectUser.objects.filter(project=business_name)
    form_user = [one.user for one in form_user_qs]
    uf = business_form(instance=business_name)

    try:
        dev_group = department_Mode.objects.get(desc_gid=1003)
        dev_group_userlist = CustomUser.objects.filter(department_id=dev_group.id)
    except:
        pass

    if business_name.project_user_group:
        user_list_id = [int(i) for i in ast.literal_eval(business_name.project_user_group)]

    if request.method == 'POST':
        print "*" * 100
        print request.POST.getlist("project_user_group")
        uf = business_form(request.POST, instance=business_name)
        print uf
        if uf.is_valid():
            myform = uf.save()
            return render_to_response('assets/server_type_edit_ok.html', locals(),
                                      context_instance=RequestContext(request))

    return render_to_response('assets/server_type_edit.html', locals(), context_instance=RequestContext(request))
Beispiel #3
0
def product_add(request):
    """
    添加产品线
    """
    init = request.GET.get("init", False)
    status = check_auth(request, "add_line_auth")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    content = {}
    server_type = Project.objects.all()

    
    if request.method == 'POST':
        uf = product_from(request.POST)
        
        if uf.is_valid():
            zw = uf.save(commit=False)
            zw.save()
            if not init:
                return HttpResponseRedirect('/assets/server/')
            else:
                idc_count = IDC.objects.all().count()
                if idc_count == 0:
                    return HttpResponseRedirect('/assets/idc_add/?init=True')
                else:
                    return HttpResponseRedirect('/assets/host_add/')

    else:
        uf = product_from()
    return render_to_response('assets/product_add.html', locals(), context_instance=RequestContext(request))
Beispiel #4
0
def room_list(request):
    status = check_auth(request, "select_idc")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    room_list = IDC.objects.all()
    server_type = Project.objects.all()
    return render_to_response('assets/server_room_list.html', locals(), context_instance=RequestContext(request))
Beispiel #5
0
def swan_index(request):
    status = check_auth(request, "auth_project")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    swan_data = Project.objects.all()

    return render_to_response('swan/index.html', locals(), context_instance=RequestContext(request))
Beispiel #6
0
def auth_server_type_list(request):
    status = check_auth(request, "project_auth")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    business_list = Project.objects.all()

    swan_all = project_swan.objects.all()
    return render_to_response('assets/server_type_list.html', locals(), context_instance=RequestContext(request))
Beispiel #7
0
def room_delete(request,id):
    status = check_auth(request, "del_idc")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    room = IDC.objects.get(id=id)
    #TODO give a alert list page to show the host in this idc
    # hosts = room.
    room.delete()
    return HttpResponseRedirect("/assets/server/room/list/")
Beispiel #8
0
def product_list(request):
    """
    产品线列表
    """
    status = check_auth(request, "add_line_auth")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    product_data = Line.objects.all()
    return render_to_response('assets/product_list.html', locals(), context_instance=RequestContext(request))
Beispiel #9
0
def user_old(request):
    u"""
    离职用户
    """
    status = check_auth(request, "add_user")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    uf = CustomUser.objects.all().filter(is_active=False, is_staff=False)

    return render_to_response('user/user_list.html', locals(), context_instance=RequestContext(request))
Beispiel #10
0
def audit_list(request):
    """
    用户审计记录
    :param requests:
    :return:
    """
    status = check_auth(request, "server_audit")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    audit_data = ssh_audit.objects.all().order_by("-audit_data_time")
    return render_to_response('audit/list.html', locals(), context_instance=RequestContext(request))
Beispiel #11
0
def auto_index(request):
    status = check_auth(request, "auth_highstate")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    content = {}
    line_list = Line.objects.filter()
    content["line_list"] = line_list
    content["business_noline"] = Project.objects.filter(line__isnull=True)
    content.update(csrf(request))
    data = host_all()

    return render_to_response('autoinstall/install_list.html', locals(), context_instance=RequestContext(request))
Beispiel #12
0
def user_delete(request, id):
    u"""
    查看用户
    """
    status = check_auth(request, "delete_user")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    user = CustomUser.objects.get(pk=id)
    user.is_staff = False
    user.is_active = False
    user.save()

    return render_to_response('user/user_list.html', locals(), context_instance=RequestContext(request))
Beispiel #13
0
def room_edit(request, id):
    status = check_auth(request, "edit_idc")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    room = IDC.objects.get(id=id)
    if request.method == 'POST':    
        uf = Engine_RoomForm(request.POST, instance=room)   
        if uf.is_valid(): 
            uf.save()
            return HttpResponseRedirect("/assets/server/room/list/")
    uf = Engine_RoomForm(instance=room)

    return render_to_response('assets/server_room_add.html', locals(), context_instance=RequestContext(request))
Beispiel #14
0
def add_room(request):
    """
    添加机房
    """
    status = check_auth(request, "add_idc")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    server_type = Project.objects.all()
    if request.method == 'POST':    
        uf = Engine_RoomForm(request.POST)   
        if uf.is_valid(): 
            uf.save()
            return HttpResponseRedirect("/assets/server/room/list/")
    else:
        uf = Engine_RoomForm()
    return render_to_response('assets/server_room_add.html', locals(), context_instance=RequestContext(request))
Beispiel #15
0
def department_edit(request, id):
    u"""
    部门修改
    """
    status = check_auth(request, "add_department")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    data = department_Mode.objects.get(id=id)
    if request.method == 'POST':
        uf = department_from(request.POST, instance=data)
        u"验证数据有效性"
        if uf.is_valid():
            uf.save()
        return HttpResponseRedirect("/accounts/list_department/")

    uf = department_from(instance=data)
    return render_to_response('user/bootstorm_from.html', locals(), context_instance=RequestContext(request))
Beispiel #16
0
def auth_server_type_del(request, uuid):
    """
    业务删除
    """
    status = check_auth(request, "delete_project")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    if Project.objects.filter(uuid=uuid).count() > 0:
        business_item = Project.objects.get(uuid=uuid)
        project_swan.objects.filter(project_name_id=business_item.uuid).delete()
        # idc_log(request.user.username, business_item.service_name, "业务删除", request.user.username, time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), id, request.user.id)
        business_item.delete()  # 这个删除会删除该业务下的机器
        project_name = business_item.service_name
        ret = zabbix_group_del(project_name)
        if ret == 0:
            pass
    return HttpResponseRedirect("/assets/server/type/list/")
Beispiel #17
0
def product_edit(request, uuid):
    """
    修改产品线
    """
    status = check_auth(request, "add_line_auth")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))
    product_data = Line.objects.get(pk=uuid)

    if request.method == 'POST':
        uf = product_from(request.POST, instance=product_data)
        
        if uf.is_valid():
            zw = uf.save()
            return HttpResponseRedirect('/assets/product/list/')

    else:
        uf = product_from(instance=product_data)
    return render_to_response('assets/product_add.html', locals(), context_instance=RequestContext(request))
Beispiel #18
0
def department_view(request):
    u"""
    添加部门
    """
    status = check_auth(request, "add_department")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    #验证post方法
    if request.method == 'POST':
        uf = department_from(request.POST)

        if uf.is_valid():
            uf.save()
        # return render_to_response('user/department_add.html', locals(), context_instance=RequestContext(request))
        return HttpResponseRedirect("/accounts/list_department/")
    else:
        uf = department_from()
    return render_to_response('user/add_department.html', locals(), context_instance=RequestContext(request))
Beispiel #19
0
def register(request):
    status = check_auth(request, "add_user")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    content = {}
    if request.method == 'POST':
        form = UserCreateForm(request.POST)
        if form.is_valid():
            form.is_staff = 1
            new_user = form.save(commit=False)

            new_user.is_staff = 1
            new_user.session_key = ""
            new_user.uuid = cmdb_uuid()
            new_user.save()
            if EMAIL_PUSH:
                token = str(hashlib.sha1(new_user.username + auth_key + new_user.uuid +
                                         time.strftime('%Y-%m-%d', time.localtime(time.time()))).hexdigest())
                #
                url = u'http://%s/accounts/newpasswd/?uuid=%s&token=%s' % (request.get_host(), new_user.uuid, token)
                mail_title = u'运维自动化初始密码,注意密码设置需符合8位以上,字母+数字+特殊符合组合的形式'
                mail_msg = u"""
                Hi,%s:
                    请点击以下链接初始化运维自动化密码,此链接当天有效
                    注意密码设置需符合8位以上,字母+数字+特殊符合组合的形式,否则无法登录::
                        %s
                    有任何问题,请随时和运维组联系。
                """ % (new_user.first_name, url)
                #

                send_mail(mail_title, mail_msg, u'运维自动化<*****@*****.**>', [new_user.email], fail_silently=False)

            return HttpResponseRedirect('/accounts/user_list/')
        else:
            data = UserCreateForm()

            return render_to_response('user/reg.html', locals(), context_instance=RequestContext(request))
    else:
        data = UserCreateForm()
        return render_to_response('user/reg.html', locals(), context_instance=RequestContext(request))
Beispiel #20
0
def department_list(request):
    u"""
    添加部门
    """
    status = check_auth(request, "add_department")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    uf = department_Mode.objects.all()

    content = {}

    for i in uf:
        user_list = []
        dep_all = i.users.all().values("first_name")

        for t in dep_all:
            user_list.append(t.get("first_name"))
        content[i.department_name] = {"user_list": user_list, "department_id": i.id}

    return render_to_response('user/department_list.html', locals(), context_instance=RequestContext(request))
Beispiel #21
0
def user_edit(request, id):
    status = check_auth(request, "edit_user")
    if not status:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    data = CustomUser.objects.get(id=id)
    data_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    if request.method == 'POST':
        # if request.POST.getlist("password1") == request.POST.getlist("password2"):
        uf = useredit_from(request.POST, instance=data)
        # print uf
        if uf.is_valid():
            # zw = uf.save(commit=False)
            # zw.last_login = data_time
            # zw.date_joined = data_time
            # zw.username = data.username
            # zw.id = id
            uf.save()
            return HttpResponseRedirect("/accounts/user_list/")
    else:
        uf = useredit_from(instance=data)
        return render_to_response('user/user_edit.html', locals(), context_instance=RequestContext(request))