Example #1
0
def seeting(request):
    username = request.GET.get('save')
    username = request.POST.get('user')
    password = request.POST.get('old_pass')
    new_pass1 = request.POST.get('new_pass1')
    new_pass2 = request.POST.get('new_pass2')
    if username:
        if new_pass1 == new_pass2:
            user = auth.authenticate(username=username, password=password)
            if user and user.is_active:
                newuser = User.objects.get(username=username)
                newuser.set_password(new_pass1)
                try:
                    newuser.save()
                    save_log(request.user, "修改密码", "修改成功")
                    return render(request, 'account/login.html')
                except Exception, e:
                    kwvars = {
                        'user': request.user,
                        'log': "修改失败!!!",
                    }
                    save_log(request.user, "修改密码", "修改失败")
                    return render(request, "account/change_pass.html", kwvars)
            else:
                kwvars = {
                    'user': request.user,
                    'log': "请输入正确的密码!!!",
                }
                return render(request, "account/change_pass.html", kwvars)
        else:
            kwvars = {
                'user': request.user,
                'log': "两次输入的密码不一致",
            }
            return render(request, "account/change_pass.html", kwvars)
Example #2
0
def versioning_show(request):
    svn_list = svn_info.objects.all()
    edit = request.GET.get('edit')
    save = request.GET.get('save')
    update = request.GET.get('update')
    remove = request.GET.get('remove')
    if edit:
        edit_info = svn_info.objects.get(svn_id=edit)
        kwvars = {
            'user': request.user,
            'info': edit_info,
            'id': edit,
        }
        return render_to_response("version/svn_change.html", kwvars)
    elif save:
        save_id = request.GET.get('save')
        info = svn_info.objects.get(svn_id=save_id)
        info.svn_url = request.POST.get('svn_url')
        info.svn_user = request.POST.get('svn_user')
        info.password = request.POST.get('password')
        info.notes = request.POST.get('notes')
        try:
            info.save()
            save_log(request.user, "修改版本库信息:" + info.svn_url, "修改成功")
            return HttpResponseRedirect('/version/info/')
        except Exception, e:
            kwvars = {
                'user': request.user,
                'log': e,
            }
            save_log(request.user, "修改版本库信息:" + info.svn_url, e)
            return render_to_response("version/svn_change.html", kwvars)
Example #3
0
def items_add(request):
	host = request.POST.get('host')
	name = request.POST.get('name')
	service = request.POST.get('service')
	path = request.POST.get('path')
	shell = request.POST.get('shell')
	process = request.POST.get('process')
	port = request.POST.get('port')
	status = request.POST.get('status')
	group = request.POST.get('group')
	notes = request.POST.get('notes')
	not_null = [host,name,service,path,shell]
	for i in not_null:
		if i is None:
			kwvars = {
				'user':request.user,
				'log':'应用信息不完整,请填充完整',
			}
			return render_to_response("items/add.html",kwvars)
		else:
			info = items_info(host=host,name=name,service=service,path=path,shell=shell,process=process,port=port,status=status,group=group,notes=notes)
			try:
				info.save()
				save_log(request.user,"添加应用信息:" + info.name ,"添加成功")		
				return HttpResponseRedirect('/items/info/')
			except Exception,e:
				kwvars = {
					'user':request.user,
					'log':'应用信息添加失败',
				}
				save_log(request.user,"添加应用信息:" + info.name ,"添加失败")
				return render_to_response("items/add.html",kwvars)
Example #4
0
def files_rsync(request):
    host = request.POST.getlist('ip')
    files = request.POST.getlist('file')
    path = request.POST.get('dir')

    file_list = os.listdir(upload_dir)
    host_list = host_info.objects.all()

    if host is not None and files is not None and path is not None:
        action = []
        for ip in host:
            for file_name in files:
                try:
                    action.extend(["File:", files])
                    action.extend(["Host:", ip])
                    action.extend(["Path:", path])
                    files_transfe(ip, file_name, path)
                except Exception, e:
                    save_log(request.user, '文件传输:' + ip + files, e)
        kwvars = {
            'user': request.user,
            'file_list': file_list,
            'host_list': host_list,
            'logs': action,
        }
        return render_to_response('files/rsync.html', kwvars)
Example #5
0
def account_login(request):
    if request.method == "POST":
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(username=username, password=password)
        if user and user.is_active:
            auth.login(request, user)
            save_log(username, "登陆系统", "登陆成功")
            return HttpResponseRedirect('/home/')
        else:
            return render(request, 'account/login.html',
                          {'login_err': '登陆失败,请确认后重新输入'})
    else:
        return render(request, 'account/login.html')
Example #6
0
def files_upload(request):
    from django import forms

    class UploadFileForm(forms.Form):
        title = forms.CharField(max_length=1000000)
        file = forms.FileField()

    if request.method == "GET":
        data = 'get'
    if request.method == "POST":
        if (request.FILES['t_file']) is not None:
            try:
                f = save_upload_file(request.FILES['t_file'])
                save_log(request.user, '上传文件:' + f.name, '上传成功')
                return HttpResponseRedirect('/files/info')
            except Exception, e:
                save_log(request.user, '上传文件', e)
Example #7
0
def versioning_add(request):
    svn_url = request.POST.get('svn_url')
    svn_user = request.POST.get('svn_user')
    password = request.POST.get('password')
    notes = request.POST.get('notes')
    if svn_url is not None and svn_user is not None and password is not None:
        sql_info = svn_info(svn_url=svn_url,
                            svn_user=svn_user,
                            password=password,
                            notes=notes)
        try:
            sql_info.save()
            save_log(request.user, "添加版本库:" + svn_url, "添加成功")
            return HttpResponseRedirect('/version/info/')
        except Exception, e:
            kwvars = {
                'user': request.user,
                'result': e,
            }
            save_log(request.user, "添加版本库:" + svn_url, e)
            return render_to_response("version/add.html", kwvars)
Example #8
0
def items_info_echo(request):
	items_list = items_info.objects.all()
	edit_id = request.GET.get('edit')
	save_id = request.GET.get('save')
	start_id = request.GET.get('start')
	stop_id = request.GET.get('stop')
	restart_id = request.GET.get('restart')
	update_id = request.GET.get('update')
	remove_id = request.GET.get('remove')
	if edit_id:
		items_list = items_info.objects.get(items_id=edit_id)
		kwvars = {
			'user':request.user,
			'items':items_list,
		}
		return render_to_response("items/items_change.html",kwvars)
	elif save_id:
		info = items_info.objects.get(items_id=save_id)	
		info.host = request.POST.get('host')
		info.name = request.POST.get('name')
		info.service = request.POST.get('service')
		info.path = request.POST.get('path')
		info.shell = request.POST.get('shell')
		info.process = request.POST.get('process')
		info.port = request.POST.get('port')
		info.status = request.POST.get('status')
		info.group = request.POST.get('group')
		info.notes = request.POST.get('notes')
		try:
			info.save()
			save_log(request.user,"修改应用信息:" + info.name ,"修改成功")
			return HttpResponseRedirect('/items/info/')
		except Exception,e:
			kwvars = {
				'user':request.user,
				'items':items_list,
				'log':"应用信息修改失败",
			}
			save_log(request.user,"修改应用信息:" + info.name ,"修改失败")
			return render_to_response("items/info.html",kwvars)
Example #9
0
def files_del(request):
    del_list = request.POST.getlist('del')
    if del_list is not None:
        for name in del_list:
            del_file = os.path.join(upload_dir, name)
            if os.path.isfile(del_file):
                try:
                    os.remove(del_file)
                    save_log(request.user, "删除文件:" + name, "删除成功")
                    return HttpResponseRedirect('/files/info/')
                except Exception, e:
                    save_log(request.user, "删除文件:" + name, e)
                    return HttpResponseRedirect('/system/logs/')
            elif os.path.isdir(del_file):
                try:
                    #os.removedirs(del_file)
                    import shutil
                    shutil.rmtree(del_file)
                    save_log(request.user, "删除目录:" + name, "删除成功")
                    return HttpResponseRedirect('/files/info/')
                except Exception, e:
                    save_log(request.user, "删除目录:" + name, e)
                    return HttpResponseRedirect('/system/logs/')
Example #10
0
def files_transfe(host, file_name, remote_dir):
    server = ssh_info.objects.get(ip=host)
    try:
        t = paramiko.Transport((server.ip, int(server.port)))
        t.connect(username=server.username, password=server.password)
        sftp = paramiko.SFTPClient.from_transport(t)

        local_file = os.path.join(upload_dir, file_name)
        remote_file = os.path.join(remote_dir, file_name)
        try:
            sftp.put(local_file, remote_file)
            save_log(server.username,
                     "传输文件:" + local_file + "  |  Host:" + server.ip, "ok")
        except Exception, e:
            save_log(server.username,
                     "传输文件:" + local_file + "  |  Host:" + server.ip, e)
    except Exception, e:
        save_log(server.username,
                 "传输文件:" + local_file + "  |  Host:" + server.ip, e)
Example #11
0
def account_logout(request):
    save_log(request.user, "退出系统", "成功")
    auth.logout(request)
    return render(request, "account/login.html")
Example #12
0
             'log': e,
         }
         save_log(request.user, "修改版本库信息:" + info.svn_url, e)
         return render_to_response("version/svn_change.html", kwvars)
 elif update:
     update_info = svn_info.objects.filter(svn_id=update)
     kwvars = {
         'user': request.user,
         'svn_list': svn_list,
     }
     return render_to_response("version/show.html", kwvars)
 elif remove:
     del_info = svn_info.objects.filter(svn_id=remove)
     try:
         del_info.delete()
         save_log(request.user, "删除版本库:" + remove, "删除成功")
         kwvars = {
             'user': request.user,
             'svn_list': svn_list,
         }
         return render_to_response("version/show.html", kwvars)
     except Exception, e:
         kwvars = {
             'user': request.user,
             'svn_list': svn_list,
             'result': e,
         }
         save_log(request.user, "删除版本库:" + remove, e)
         return render_to_response("version/show.html", kwvars)
 else:
     kwvars = {