def cheungssh_login(request): info = {"msgtype": "ERR", "content": "", "auth": "no"} logintime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) client_ip = request.META['REMOTE_ADDR'] limit_ip = 'fail.limit.%s' % (client_ip) ip_threshold_r = cache.get('ip.threshold') ip_threshold = lambda x: x if x is not None else 4 ip_threshold = ip_threshold(ip_threshold_r) if cache.has_key(limit_ip): if cache.get(limit_ip) > ip_threshold: info['content'] = "无效登陆" cache.incr(limit_ip) cache.expire(limit_ip, 8640000) info = json.dumps(info) return HttpResponse(info) if request.method == "POST": username = request.POST.get("username", '非法用户名') password = request.POST.get("password", False) print username, password, request.POST user = authenticate(username=username, password=password) if user is not None: if user.is_active: print "成功登陆" login(request, user) request.session["username"] = username info["msgtype"] = "OK" info['auth'] = "yes" info['content'] = "成功登录" request.session.set_expiry(0) if cache.has_key(limit_ip): cache.delete(limit_ip) print request.COOKIES, request.session.keys( ), request.session['_auth_user_id'] info['sid'] = str(request.session.session_key) else: info["content"] = "用户状态无效" print info["content"] else: if cache.has_key(limit_ip): cache.incr(limit_ip) else: cache.set(limit_ip, 1, 3600) info["content"] = "用户名或密码错误" info["IP"] = client_ip info["IP-Locate"] = IP.find(client_ip) info["username"] = username info["logintime"] = logintime redis_to_redis.set_redis_data( 'sign.record', json.dumps(info, encoding='utf-8', ensure_ascii=False)) else: info["content"] = "No Get" info = json.dumps(info, encoding="utf-8", ensure_ascii=False) response = HttpResponse(info) response["Access-Control-Allow-Origin"] = "*" response["Access-Control-Allow-Methods"] = "POST" response["Access-Control-Allow-Credentials"] = "true" return response
def cheungssh_login(request): info={"msgtype":"ERR","content":"","auth":"no"} logintime=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) client_ip=request.META['REMOTE_ADDR'] limit_ip='fail.limit.%s'%(client_ip) ip_threshold_r=cache.get('ip.threshold') ip_threshold=lambda x:x if x is not None else 4 ip_threshold=ip_threshold(ip_threshold_r) if cache.has_key(limit_ip): if cache.get(limit_ip)>ip_threshold: info['content']="无效登陆" cache.incr(limit_ip) cache.expire(limit_ip,8640000) info=json.dumps(info) return HttpResponse(info) if request.method=="POST": username = request.POST.get("username", '非法用户名') password = request.POST.get("password", False) print username,password,request.POST user=authenticate(username=username,password=password) if user is not None: if user.is_active: print "成功登陆" login(request,user) request.session["username"]=username info["msgtype"]="OK" info['auth']="yes" info['content']="成功登录" request.session.set_expiry(0) if cache.has_key(limit_ip):cache.delete(limit_ip) print request.COOKIES,request.session.keys(),request.session['_auth_user_id'] info['sid']=str(request.session.session_key) else: info["content"]="用户状态无效" print info["content"] else: if cache.has_key(limit_ip): cache.incr(limit_ip) else: cache.set(limit_ip,1,3600) info["content"]="用户名或密码错误" info["IP"]=client_ip info["IP-Locate"]=IP.find(client_ip) info["username"]=username info["logintime"]=logintime redis_to_redis.set_redis_data('sign.record',json.dumps(info,encoding='utf-8',ensure_ascii=False)) else: info["content"]="No Get" info=json.dumps(info,encoding="utf-8",ensure_ascii=False) response=HttpResponse(info) response["Access-Control-Allow-Origin"] = "*" response["Access-Control-Allow-Methods"] = "POST" response["Access-Control-Allow-Credentials"] = "true" return response
finally: ssh.close() #sendinfo.sendinfo(str({ie_key:info})) if Data.excutetype == 'cmd': sendinfo.sendinfo(str({ie_key: info})) print '这是发送给socket' else: print '这是sudo' checktime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) hwinfo = cache.get('hwinfo') if not hwinfo: hwinfo = {} ipinfo = {Data.hwtype: ResultSum, 'ip': ip, 'checktime': checktime} hwinfo[ip] = ipinfo else: #hwinfo[ip][Data.hwtype]=ResultSum if hwinfo.has_key(ip): hwinfo[ip][Data.hwtype] = ResultSum else: ipinfo = { Data.hwtype: ResultSum, 'ip': ip, 'checktime': checktime } hwinfo[ip] = ipinfo hwinfo[ip][Data.hwtype] = ResultSum cache.set('hwinfo', hwinfo, 864000000) set_redis_data('cmd.%s.%s' % (tid, ip), json.dumps(ResultSum, encoding="utf-8", ensure_ascii=False))
ResultSum=str(e) bufflog=str(e) Show_Result_web_status=Format_Char_Show_web.Show_Char(str(e).replace("<","<")+"\n"+ip,color_status) jindu=int(float(Data.All_Servers_num)/float(Data.All_Servers_num_all)*100) if color_status==0: info={"msgtype":1,"content":[{"group":group,"servers":[{"ip":ip,"status":"OK","jindu":jindu,"cmd":cmd,"info":Show_Result_web_status}]}]} else: info={"msgtype":1,"content":[{"group":group,"servers":[{"ip":ip,"status":"ERR","jindu":jindu,"cmd":cmd,"info":Show_Result_web_status}]}]} info['id']=(str(random.randint(999999999,99999999999999999))) info=json.dumps(info,encoding='utf8',ensure_ascii=False) print ResultSum if Data.excutetype=='cmd': sendinfo.sendinfo(str({ie_key:info})) else: checktime=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) hwinfo=cache.get('hwinfo') if not hwinfo: hwinfo={} ipinfo={Data.hwtype:ResultSum,'ip':ip,'checktime':checktime} hwinfo[ip]=ipinfo else: if hwinfo.has_key(ip): hwinfo[ip][Data.hwtype]=ResultSum else: ipinfo={Data.hwtype:ResultSum,'ip':ip,'checktime':checktime} hwinfo[ip]=ipinfo hwinfo[ip][Data.hwtype]=ResultSum cache.set('hwinfo',hwinfo,864000000) set_redis_data('cmd.%s.%s'%(tid,ip),json.dumps(ResultSum,encoding="utf-8",ensure_ascii=False))