def exec_cmd(): _cmds = [] _rrt = {} port=21860 center = Center() _id = request.form.get('serverid', '') _ip = request.form.get('serverip', '') print "id is %s,ip is %s" %(_id,_ip) _user_manage_passwd = request.form.get('manage-passwd','') _cmd = request.form.get('cmd','') print _cmd for x in _cmd.split(';'): _cmds.append(x) print _cmds print "cmds is %s,passwd is %s" %(_cmds,_user_manage_passwd) _rt = User.validate_login('admin',_user_manage_passwd) if _rt: #_result,_error = Remote_cmd.ssh_execute(_ip,'root','1meWsgvYeSjMA0pecBMg',port,_cmds) _result = center.request(str(_cmds)) for r in _result: if not r[2]: if len(r[1]) > 0: _rrt[r[0]] = r[1] else: _rrt[r[0]] = r[2] else: if not _error: return json.dumps({'is_ok':'true', 'error':'', 'success':'true','result':_result}) return json.dumps({'is_ok':'false', 'error':'', 'success':'false','result':'执行失败,请您确认已正确输入管理员密码和命令行!'})
def login(): username = request.form.get('username', '') #接收用户提交的数据 password = request.form.get('password', '') #print request.form['username'] #print "username is %s" %username # _users,_error = user.get_info(username=username) # if _users: # _id = _users[0]['id'] # age = _users[0]['age'] # else: # _id = '' #希望把ID加进去作为session绑定,后面根据id修改对应用户的密码! #需要验证用户名密码是否正确 _user = User.validate_login(username, password) if _user: #判断用户登录是否合法 session['user'] = _user #设置session,绑定用户身份信息,和用户名绑定,类似办银行卡 flash("登陆成功!") #flask的消息闪现,一次生成一个, 通过函数get_flashed_messages()获取 print session #打印session信息,用于查看,理解session return redirect('/dashboard/') #跳转到url展示用户页面 else: #登录失败 return render_template('login.html', username=username, error='用户名或密码错误')