Exemplo n.º 1
0
def user():
    s = request.environ.get('beaker.session')
    username = s.get('username')
    oldpwd = request.forms.get("oldpwd")
    newpwd = request.forms.get("newpwd")
    newpwds = request.forms.get("newpwds")
    sql = " select passwd from user where username=%s "
    result = readDb(sql, (username, ))
    if result[0].get('passwd') != LoginCls().encode(keys, oldpwd):
        msg = {'color': 'red', 'message': u'旧密码验证失败,请重新输入'}
        return template('changepasswd', session=s, msg=msg, info={})
    if newpwd != newpwds:
        msg = {'color': 'red', 'message': u'密码两次输入不一致,请重新输入'}
        return template('changepasswd', session=s, msg=msg, info={})
    m_encrypt = LoginCls().encode(keys, newpwd)
    sql2 = " update user set passwd=%s where username=%s "
    result = writeDb(sql2, (m_encrypt, username))
    if result == True:
        wrtlog('User', '更改密码成功', username, s.get('clientip'))
        msg = {'color': 'green', 'message': u'密码更新成功,后续请以新密码登录系统'}
        return template('changepasswd', session=s, msg=msg, info={})
    else:
        wrtlog('User', '更改密码失败', username, s.get('clientip'))
        msg = {'color': 'red', 'message': u'密码更新失败,请核对错误'}
        return template('changepasswd', session=s, msg=msg, info={})
Exemplo n.º 2
0
def adduser():
    s = request.environ.get('beaker.session')
    username = request.forms.get("username")
    passwd = request.forms.get("passwd")
    policy = request.forms.get("policy")
    access = request.forms.get("access")
    comment = request.forms.get("comment")
    #把密码进行md5加密码处理后再保存到数据库中
    m_encrypt = LoginCls().encode(keys, passwd)
    #检查表单长度
    if len(username) < 4 or (len(passwd) > 0 and len(passwd) < 8):
        message = "用户名或密码长度不符要求!"
        return '-2'
    #检测表单各项值,如果出现为空的表单,则返回提示
    if not (username and policy and access):
        message = "表单不允许为空!"
        return '-2'
    sql = """
            INSERT INTO
                user(username,passwd,policy,access,comment)
            VALUES(%s,%s,%s,%s,%s)
        """
    data = (username, m_encrypt, policy, access, comment)
    result = writeDb(sql, data)
    if result:
        wrtlog('User', '新增用户成功:%s' % username, s['username'],
               s.get('clientip'))
        return '0'
    else:
        wrtlog('User', '新增用户失败:%s' % username, s['username'],
               s.get('clientip'))
        return '-1'
Exemplo n.º 3
0
def getfileshareinfo(path):
    import chardet
    from MySQL import readDb
    s = request.environ.get('beaker.session')
    ftpuser = s['username']
    ftppass = LoginCls().decode(AppServer().getConfValue('keys', 'pkey'),
                                s['skeyid'])
    sql = """ select listenaddr,listenport,passiveenable,passiveaddr from ftpserv """
    result = readDb(sql, )
    if int(result[0].get('passiveenable')) == 0:
        if result[0].get('listenaddr') == "*":
            servaddr = "127.0.0.1"
        else:
            servaddr = result[0].get('listenaddr')
    else:
        if result[0].get('passiveaddr') == "*":
            servaddr = "127.0.0.1"
        else:
            servaddr = result[0].get('passiveaddr')
    try:
        ftp = FTPHandle(servaddr, int(result[0].get('listenport')), '0', '1')
    except:
        newflist = []
        return json.dumps(newflist)
    try:
        ftp.Login(ftpuser, ftppass)
    except:
        newflist = []
        return json.dumps(newflist)
    if path == 'root':
        flistdict = ftp.getdirs()
    else:
        charstr = chardet.detect(path).get('encoding')
        if str(charstr).lower() != "gbk":
            try:
                path = path.decode('utf-8').encode('gbk')
            except:
                path = path
        flistdict = ftp.getdirs(path)
    ftp.close()
    newflist = []
    for i in flistdict.get('files'):
        charstr = chardet.detect(i.get('name')).get('encoding')
        if str(charstr).lower() != "utf-8":
            try:
                i['name'] = i.get('name').decode('gbk').encode('utf-8')
                newflist.append(i)
            except:
                continue
        else:
            newflist.append(i)
    return json.dumps(newflist)
Exemplo n.º 4
0
def do_upload():
    import chardet
    s = request.environ.get('beaker.session')
    dstdir = request.forms.get('dstdir')
    charstr = chardet.detect(dstdir).get('encoding')
    if str(charstr).lower() != "gbk":
        try:
            dstdir = dstdir.decode('utf-8').encode('gbk')
        except:
            dstdir = dstdir
    ftpuser = s['username']
    ftppass = LoginCls().decode(AppServer().getConfValue('keys', 'pkey'),
                                s['skeyid'])
    sql = """ select listenaddr,listenport,passiveenable,passiveaddr from ftpserv """
    result = readDb(sql, )
    if int(result[0].get('passiveenable')) == 0:
        if result[0].get('listenaddr') == "*":
            servaddr = "127.0.0.1"
        else:
            servaddr = result[0].get('listenaddr')
    else:
        if result[0].get('passiveaddr') == "*":
            servaddr = "127.0.0.1"
        else:
            servaddr = result[0].get('passiveaddr')
    try:
        ftp = FTPHandle(servaddr, int(result[0].get('listenport')), '0', '1')
    except:
        return -1
    fname = request.forms.get('fname')
    if fname:
        charstr = chardet.detect(fname).get('encoding')
        if str(charstr).lower() != "gbk":
            try:
                fname = fname.decode('utf-8').encode('gbk')
            except:
                pass
        os.system('rm -f /tmp/%s_ftpfile' % ftpuser)
        softfile = request.POST.get('fdesc')
        softfile.save('/tmp/%s_ftpfile' % ftpuser, overwrite=True)
        try:
            ftp.Login(ftpuser, ftppass)
            ftp.UpLoadFile("/tmp/%s_ftpfile" % ftpuser, fname, dstdir)
            ftp.close()
        except:
            return -1
        os.system('rm -f /tmp/%s_ftpfile' % ftpuser)
        return 0
    else:
        return -1
Exemplo n.º 5
0
def do_login():
    s = request.environ.get('beaker.session')
    s['sitename'] = AppServer().getConfValue('site', 'sitename')
    """用户登陆过程,判断用户帐号密码,保存SESSION"""
    username = request.forms.get('username').strip()
    password = request.forms.get('passwd').strip()
    spass = LoginCls().encode(AppServer().getConfValue('keys', 'pkey'),
                              password)
    if not username or not password:
        message = u'帐号或密码不能为空!'
        return template('login', message=message)
    m = hashlib.md5()
    m.update(password)
    password = m.hexdigest()
    auth_sql = '''
        SELECT
            id,username,access
        FROM
            user
        WHERE
            username=%s and password=%s
        '''
    auth_user = readDb(auth_sql, (username, password))
    if auth_user:
        s['webhost'] = request.environ.get('HTTP_HOST')
        s['clientip'] = request.environ.get('REMOTE_ADDR')
        s['username'] = username
        s['skeyid'] = spass
        s['userid'] = auth_user[0]['id']
        s['access'] = auth_user[0]['access']
        # session中添加系统环境检测警报
        s['admemail'] = '*****@*****.**'
        s['errnum'] = errnum
        s['PayInfo'] = AppServer().getPayinfo()
        s.save()
        wrtlog('Login', '登录成功', username, s['clientip'])
    else:
        clientip = request.environ.get('REMOTE_ADDR')
        wrtlog('Login', '登录失败', username, clientip)
        message = u'帐号或密码错误!'
        return template('login', session=s, message=message)
    #如果用户是普通用户,返回项目页面
    if auth_user[0]['access'] == 0:
        return redirect('/project')
    return redirect('/')
Exemplo n.º 6
0
def fileshare(path):
    s = request.environ.get('beaker.session')
    # 获取FTP目录列表
    ftpuser = s['username']
    ftppass = LoginCls().decode(AppServer().getConfValue('keys', 'pkey'),
                                s['skeyid'])
    sql = """ select listenaddr,listenport,passiveenable,passiveaddr from ftpserv """
    result = readDb(sql, )
    if int(result[0].get('passiveenable')) == 0:
        if result[0].get('listenaddr') == "*":
            servaddr = "127.0.0.1"
        else:
            servaddr = result[0].get('listenaddr')
    else:
        if result[0].get('passiveaddr') == "*":
            servaddr = "127.0.0.1"
        else:
            servaddr = result[0].get('passiveaddr')
    try:
        ftp = FTPHandle(servaddr, int(result[0].get('listenport')), '0', '1')
    except:
        newflist = []
        msg = {'color': 'red', 'message': u'FTP服务连接失败,请检查FTP配置'}
        return template('fileshare', session=s, msg=msg, path=path, ftpdirs=[])
    try:
        ftp.Login(ftpuser, ftppass)
    except:
        newflist = []
        msg = {'color': 'red', 'message': u'FTP服务连接失败,请检查FTP配置'}
        return template('fileshare', session=s, msg=msg, path=path, ftpdirs=[])
    try:
        flistdict = ftp.getdirs()
    except:
        newflist = []
        msg = {'color': 'red', 'message': u'目录读取失败,请检查FTP配置'}
        return template('fileshare', session=s, msg=msg, path=path, ftpdirs=[])
    ftp.close()
    return template('fileshare',
                    session=s,
                    msg={},
                    path=path,
                    ftpdirs=flistdict.get('dirs'))
Exemplo n.º 7
0
def do_changeuser(id):
    s = request.environ.get('beaker.session')
    username = request.forms.get("username")
    passwd = request.forms.get("passwd")
    policy = request.forms.get("policy")
    access = request.forms.get("access")
    comment = request.forms.get("comment")
    #把密码进行加密处理后再保存到数据库中
    if not passwd :
       sql = "select passwd from user where id = %s"
       m_encrypt = readDb(sql,(id,))[0].get('passwd')
    else:
       m_encrypt = LoginCls().encode(keys,passwd)
    # 判断用户表单跳转
    if int(access) == 0:
       formaddr='user'
    else :
       formaddr='admin'
    #检查表单长度
    if len(username) < 4 or (len(passwd) > 0 and len(passwd) < 8) :
        msg = {'color':'red','message':'用户名或密码长度错误,提交失败!'}
        return template(formaddr,session=s,msg=msg,plylist_result=plylist_result)
    if not (username and policy):
        msg = {'color':'red','message':'必填字段为空,提交失败!'}
        return template(formaddr,session=s,msg=msg,plylist_result=plylist_result)
    sql = """
            UPDATE user SET
            username=%s,passwd=%s,policy=%s,access=%s,comment=%s
            WHERE id=%s
        """
    data = (username,m_encrypt,int(policy),access,comment,id)
    result = writeDb(sql,data)
    if result == True:
       wrtlog('User','更新用户成功:%s' % username,s['username'],s.get('clientip'))
       msg = {'color':'green','message':'更新成功!'}
       writeVPNconf(action='uptuser')
       return template(formaddr,session=s,msg=msg,plylist_result=plylist_result)
    else:
       wrtlog('User','更新用户失败:%s' % username,s['username'],s.get('clientip'))
       msg = {'color':'red','message':'更新失败!'}
    return template(formaddr,session=s,msg=msg)
Exemplo n.º 8
0
def do_changeuser(id):
    s = request.environ.get('beaker.session')
    username = request.forms.get("username")
    passwd = request.forms.get("passwd")
    stopdate = request.forms.get("stopdate")
    policy = request.forms.get("policy")
    access = request.forms.get("access")
    comment = request.forms.get("comment")
    #把密码进行加密处理后再保存到数据库中
    if not passwd:
        sql = "select passwd from user where id = %s"
        m_encrypt = readDb(sql, (id, ))[0].get('passwd')
    else:
        m_encrypt = LoginCls().encode(keys, passwd)
    # 判断用户表单跳转[弃用]
    #if int(access) == 0:
    #   formaddr='user'
    #else :
    #   formaddr='admin'
    #检查表单长度
    if len(username) < 4 or (len(passwd) > 0 and len(passwd) < 8):
        return -1
    if not (username and policy):
        return -2
    sql = """
            UPDATE user SET
            username=%s,passwd=%s,stopdate=%s,policy=%s,access=%s,comment=%s
            WHERE id=%s
        """
    data = (username, m_encrypt, stopdate, int(policy), access, comment, id)
    result = writeDb(sql, data)
    if result == True:
        wrtlog('User', '更新用户成功:%s' % username, s['username'],
               s.get('clientip'))
        writeVPNconf(action='uptuser')
        return 0
    else:
        wrtlog('User', '更新用户失败:%s' % username, s['username'],
               s.get('clientip'))
        return -1
Exemplo n.º 9
0
def do_login():
    s = request.environ.get('beaker.session')
    s['sitename'] = AppServer().getConfValue('site','sitename')
    """用户登陆过程,判断用户帐号密码,保存SESSION"""
    username = request.forms.get('username').strip()
    passwd = request.forms.get('passwd').strip()
    if not username or not passwd:
        message = u'帐号或密码不能为空!'
        return template('login',message=message)

    m_encrypt = LoginCls().encode(keys,passwd)
    auth_sql = '''
        SELECT
            id,username,access
        FROM
            user
        WHERE
            username=%s and passwd=%s
        '''
    auth_user = readDb(auth_sql,(username,m_encrypt))
    if auth_user:
       s['webhost'] = request.environ.get('HTTP_HOST')
       s['clientip'] = request.environ.get('REMOTE_ADDR')
       s['username'] = username
       s['userid'] = auth_user[0]['id']
       s['access'] = auth_user[0]['access']
       # session中添加系统环境检测警报
       s['admemail'] = '*****@*****.**'
       s['errnum'] = errnum
       s['PayInfo'] = AppServer().getPayinfo()
       s.save()
       wrtlog('Login','登录成功',username,s['clientip'])
    else:
       clientip = request.environ.get('REMOTE_ADDR')
       wrtlog('Login','登录失败',username,clientip)
       message = u'帐号或密码错误!'
       return template('login',message=message,session=s)
    if auth_user[0]['access'] == 0 :
       return redirect('/project')
    return redirect('/')