Exemple #1
0
def ztree_business(request):
    u"""
    树请求验证
    :param request:
    :return:
    """
    business_name = request.GET.get("name")
    get_token = str(request.GET.get("token"))
    user = request.GET.get("user")
    sum_token = str(hashlib.sha1(request.user.username + auth_key + business_name + time.strftime('%Y-%m-%d',
                                                                                                  time.localtime(
                                                                                                      time.time()))).hexdigest())
    userId = str(user)
    user_data = CustomUser.objects.get(uuid=userId)

    if get_token != sum_token:
        content_status = False

    if request.method == 'POST':
        data = request.POST
        auth_weights = data.get("auth_weights", False)
        auth = int(data.get("auth"))
        for i in data.getlist("node_name"):
            server = Host.objects.get(uuid=i)
            # if user_data.department.desc_gid == 1001:
            if AuthNode.objects.filter(user_name=user_data, node=server).count() == 0:
                data = AuthNode(user_name=user_data, auth=auth, node=server)
                data.save()

                args = {"user": user_data.username,
                        "type": 1,
                        "auth": auth,
                        "node": server.node_name,
                        "ip": server.eth1,
                        "uid": int(3000 + user_data.id),
                        "gid": int(user_data.department.desc_gid),
                        "ssh_key": (user_data.user_key).replace("ssh-rsa ", "")}
                print args
                s = RabApi(args=args)
                print s.SendMessage()
            else:
                print u"数据已存在"

    data = server_from()
    business = Project.objects.all()
    all_node = AuthNode.objects.filter(user_name=user_data)
    ip_list = [i.node.eth1 for i in all_node]
    node_count = all_node.count()

    if business_name != u"未分类":
        bus_data = Project.objects.get(pk=request.GET.get("name"))
        server_list = Host.objects.filter(business=bus_data).order_by("create_time")

    else:
        bus_data = u'未分类'
        idc_data = IDC.objects.filter(type=1)
        server_list = Host.objects.filter(business__isnull=True, idc=idc_data).order_by("create_time")

    ztree_data = ztree_tag(request.user.username)

    content_status = True

    return render_to_response('auth/add_host_auth_project.html', locals(), context_instance=RequestContext(request))
Exemple #2
0
def user_auth_server(request, uuid):
    """
    不同用户分配不同服务器权限
    server_ip = models.IPAddressField(blank=True, null=True, verbose_name=u'服务器')
    user_name = models.CharField(max_length=20, blank=True, null=True, verbose_name=u'用户名')
    auth_weights = models.CharField(max_length=32, blank=True, null=True, default=u"普通用户", choices=auth_id, verbose_name=u'权限')
    datetime = models.DateTimeField(auto_now=True)

    """

    if not request.user.is_superuser:
        return render_to_response('default/error_auth.html', locals(), context_instance=RequestContext(request))

    user_data = CustomUser.objects.get(uuid=str(uuid))
    if request.method == 'POST':
        data = request.POST
        auth_weights = data["auth_weights"]

        for i in data.getlist("node"):
            server = Host.objects.get(uuid=i)
            if user_data.department.desc_gid == 1001:
                data = AuthNode(user_name=user_data, auth=1, project=str(auth_weights), node=server)
            else:
                data = AuthNode(user_name=user_data, auth=0, project=str(auth_weights), node=server)
            data.save()
            if user_data.department.desc_gid == 1001:
                auth = 1
            else:
                auth = 0

            args = {"user": user_data.username, "type": 1, "auth": 0, "node": server.node_name, "ip": server.eth1,
                    "uid": int(3000 + user_data.id), "gid": int(user_data.department.desc_gid),
                    "ssh_key": (user_data.user_key).replace("ssh-rsa ", "")}
            s = RabApi(args=args)
            s.SendMessage()

        if auth_weights == "all":
            server_list = Host.objects.filter(business__isnull=True)
            server_auth_list = server_auth.objects.filter(first_name=user_data.first_name)
            ip_list = []
            ip_auth = {}
            for i in server_auth_list.values():
                ip_list.append(i["server_ip"])
                ip_auth[i["server_ip"]] = i["auth_weights"]
            return render_to_response('assets/auth_type.html', locals(), context_instance=RequestContext(request))

        else:
            business_name = Project.objects.get(pk=auth_weights)
            server_auth_list = server_auth.objects.filter(first_name=user_data.first_name)
            server_list = Host.objects.filter(business=business_name)
            ip_list = []
            data = AuthNode.objects.filter(project=str(business_name.uuid), user_name=user_data)
            for i in data:
                ip_list.append(i.node.uuid)

            return render_to_response('assets/auth_type.html', locals(), context_instance=RequestContext(request))

    data = server_from

    business = Project.objects.all()

    # return HttpResponse(json.dumps({"status": "403", "message": "Authentication failed"}, ensure_ascii=False, indent=4))
    return render_to_response('user/add_auth.html', locals(), context_instance=RequestContext(request))
Exemple #3
0
def ztree_business(request):
    u"""
    树请求验证
    :param request:
    :return:
    """
    business_name = request.GET.get("name")
    get_token = str(request.GET.get("token"))
    user = request.GET.get("user")
    sum_token = str(
        hashlib.sha1(request.user.username + auth_key + business_name +
                     time.strftime('%Y-%m-%d', time.localtime(time.time()))).
        hexdigest())
    userId = str(user)
    user_data = CustomUser.objects.get(uuid=userId)

    if get_token != sum_token:
        content_status = False

    if request.method == 'POST':
        data = request.POST
        auth_weights = data.get("auth_weights", False)
        auth = int(data.get("auth"))
        for i in data.getlist("node_name"):
            server = Host.objects.get(uuid=i)
            # if user_data.department.desc_gid == 1001:
            if AuthNode.objects.filter(user_name=user_data,
                                       node=server).count() == 0:
                data = AuthNode(user_name=user_data, auth=auth, node=server)
                data.save()

                args = {
                    "user": user_data.username,
                    "type": 1,
                    "auth": auth,
                    "node": server.node_name,
                    "ip": server.eth1,
                    "uid": int(3000 + user_data.id),
                    "gid": int(user_data.department.desc_gid),
                    "ssh_key": (user_data.user_key).replace("ssh-rsa ", "")
                }
                print args
                s = RabApi(args=args)
                print s.SendMessage()
            else:
                print u"数据已存在"

    data = server_from()
    business = Project.objects.all()
    all_node = AuthNode.objects.filter(user_name=user_data)
    ip_list = [i.node.eth1 for i in all_node]
    node_count = all_node.count()

    if business_name != u"未分类":
        bus_data = Project.objects.get(pk=request.GET.get("name"))
        server_list = Host.objects.filter(
            business=bus_data).order_by("create_time")

    else:
        bus_data = u'未分类'
        idc_data = IDC.objects.filter(type=1)
        server_list = Host.objects.filter(business__isnull=True,
                                          idc=idc_data).order_by("create_time")

    ztree_data = ztree_tag(request.user.username)

    content_status = True

    return render_to_response('auth/add_host_auth_project.html',
                              locals(),
                              context_instance=RequestContext(request))