示例#1
0
    def login(self, str_command):
        command_list = str_command.split()
        if len(command_list) == 3:
            username = command_list[1]
            password = command_list[2]
            accounts_db = db_handler.handler(setting.DATABASE)
            if username in accounts_db:
                if password == accounts_db[username]["password"]:
                    self.login_flag = True
                    self.name = username
                    # 获取用户家目录
                    self.home_path = accounts_db[username]["home_path"]
                    # login之后,当前目录默认为家目录
                    self.curr_path = accounts_db[username]["home_path"]
                    # 从数据库中读取用户的磁盘配额
                    self.total_space = accounts_db[username]["total_space"]
                    # 计算用户已使用的磁盘配额
                    usage_space = os.path.getsize("{}/{}".format(
                        setting.BASE_DIR, self.home_path))
                    # 得到用户当前可用的磁盘配额
                    self.curr_space = self.total_space - usage_space

                else:
                    self.login_flag = False
            else:
                self.login_flag = False
        else:
            self.login_flag = False
        if self.login_flag:
            self.request.sendall(b"Login success.")
        else:
            self.request.sendall(b"Login failed.")
示例#2
0
文件: main.py 项目: jianbosky/host
def login():
    count = 0
    flage = False
    while count < 3:
        count += 1
        user_input = input("请输入用户名:").strip()
        pass_input = input("请输入密码:").strip()
        db = db_handler.handler(setting.DATABASE,user_input)
        if os.path.isfile(db):
            f = open(db,"rb")
            data = pickle.loads(f.read())
            f.close()
            if user_input == data["name"] and data["lock"] !=1:
                if pass_input == data["password"]:
                    flage = True
                    log.info("用户[%s]登陆成功!"%user_input)
                    break
                else:
                    print("用户名或密码错误!")
                    if count > 2:
                        with open(db,"wb") as f:
                            data["lock"] = 1
                            pickle.dump(data,f)
                            log.info("用户[%s]被锁定!"%user_input)
                            print("用户[%s]已被锁定!"%user_input)
            else:
                print("用户[%s]已被锁定!"%user_input)
                exit()
    if flage == True:
        print("用户[%s]登陆成功!"%user_input)
        men()
    else:
        exit()
示例#3
0
 def save_game(self):
     print("正在存档...")
     # 生成一个以当前时间为文件名的存档文件
     file_name = time.strftime("%Y%m%d_%H%M%S", time.gmtime(time.time()))
     db_path = db_handler.handler(setting.DATABASE, file_name)
     save_data.db_write(db_path, self)
     print("存档完成...此次存档文件名为:{}".format(file_name))
示例#4
0
	def login(self, str_command):
		command_list = str_command.split()
		if len(command_list) == 3:
			username = command_list[1]
			password = command_list[2]
			accounts_db = db_handler.handler(setting.DATABASE)
			if username in accounts_db:
				if password == accounts_db[username]["password"]:
					self.login_flag = True
					self.name = username
					# 获取用户家目录
					self.home_path = accounts_db[username]["home_path"]
					# login之后,当前目录默认为家目录
					self.curr_path = accounts_db[username]["home_path"]
					# 从数据库中读取用户的磁盘配额
					self.total_space = accounts_db[username]["total_space"]
					# 计算用户已使用的磁盘配额
					usage_space = os.path.getsize("{}/{}".format(setting.BASE_DIR, self.home_path))
					# 得到用户当前可用的磁盘配额
					self.curr_space = self.total_space - usage_space

				else:
					self.login_flag = False
			else:
				self.login_flag = False
		else:
			self.login_flag = False
		if self.login_flag:
			self.request.sendall(b"Login success.")
		else:
			self.request.sendall(b"Login failed.")
 def __init__(self,username,cmd_action,cmd_file,total_size=300):
     self.username = username
     self.total_size = total_size
     self.cmd_action = cmd_action
     self.cmd_file = cmd_file
     self.root = db_handler.handler(setting.DATABASE,self.username,"2")
     self.home = self.root
 def __init__(self, username, cmd_action, cmd_file, total_size=300):
     self.username = username
     self.total_size = total_size
     self.cmd_action = cmd_action
     self.cmd_file = cmd_file
     self.root = db_handler.handler(setting.DATABASE, self.username, "2")
     self.home = self.root
示例#7
0
文件: main.py 项目: jianbosky/host
def login():
    count = 0
    flage = False
    while count < 3:
        count += 1
        user_input = input("请输入用户名:").strip()
        pass_input = input("请输入密码:").strip()
        db = db_handler.handler(setting.DATABASE, user_input)
        if os.path.isfile(db):
            f = open(db, "rb")
            data = pickle.loads(f.read())
            f.close()
            if user_input == data["name"] and data["lock"] != 1:
                if pass_input == data["password"]:
                    flage = True
                    log.info("用户[%s]登陆成功!" % user_input)
                    break
                else:
                    print("用户名或密码错误!")
                    if count > 2:
                        with open(db, "wb") as f:
                            data["lock"] = 1
                            pickle.dump(data, f)
                            log.info("用户[%s]被锁定!" % user_input)
                            print("用户[%s]已被锁定!" % user_input)
            else:
                print("用户[%s]已被锁定!" % user_input)
                exit()
    if flage == True:
        print("用户[%s]登陆成功!" % user_input)
        men()
    else:
        exit()
示例#8
0
 def save_game(self):
     print("正在存档...")
     # 生成一个以当前时间为文件名的存档文件
     file_name = time.strftime('%Y%m%d_%H%M%S', time.gmtime(time.time()))
     db_path = db_handler.handler(setting.DATABASE, file_name)
     save_data.db_write(db_path, self)
     print("存档完成...此次存档文件名为:{}".format(file_name))
示例#9
0
def login(username,password):
    """
    FTP登陆验证函数
    :param username:
    :param password:
    :return:

    # testDict ={"username":"******","password":"******","file_dir":"E:\python","file_size":500}
    # file = 'jjb.pkl'
    # fp = open(file,'wb')
    # pickle.dump(testDict,fp)
    # fp.close()
    f = open("jjb.pkl","rb")
    data = pickle.loads(f.read())
    f.close()
    print(data)
    """
    #实例化加密函数
    hash = hashlib.sha512()
    db= db_handler.handler(setting.DATABASE,username)
    if os.path.isfile(db):
        f = open(db,"rb")
        data = pickle.loads(f.read())
        f.close()
        if username == data["name"]:
            hash.update(bytes(data["password"],"utf8"))
            hash_pwd = hash.hexdigest()
            if hash_pwd == password:
                filedir = data["file_dir"]
                filesize = data["file_size"]
                return "True|%s|%s"%(filedir,filesize)
            else:
                return "False||"
        else:
            return "False||"
    else:
        return "False||"
示例#10
0
def login(username, password):
    """
    FTP登陆验证函数
    :param username:
    :param password:
    :return:

    # testDict ={"username":"******","password":"******","file_dir":"E:\python","file_size":500}
    # file = 'jjb.pkl'
    # fp = open(file,'wb')
    # pickle.dump(testDict,fp)
    # fp.close()
    f = open("jjb.pkl","rb")
    data = pickle.loads(f.read())
    f.close()
    print(data)
    """
    #实例化加密函数
    hash = hashlib.sha512()
    db = db_handler.handler(setting.DATABASE, username)
    if os.path.isfile(db):
        f = open(db, "rb")
        data = pickle.loads(f.read())
        f.close()
        if username == data["name"]:
            hash.update(bytes(data["password"], "utf8"))
            hash_pwd = hash.hexdigest()
            if hash_pwd == password:
                filedir = data["file_dir"]
                filesize = data["file_size"]
                return "True|%s|%s" % (filedir, filesize)
            else:
                return "False||"
        else:
            return "False||"
    else:
        return "False||"
示例#11
0
def read_game(file_name):
    print("正在读取...")
    db_path = db_handler.handler(setting.DATABASE, file_name)
    return save_data.db_read(db_path)
示例#12
0
def save_game(player_object):
    print("正在存档...")
    # 生成一个以当前时间为文件名的存档文件
    file_name = time.strftime('%Y%m%d_%H%M%S', time.gmtime(time.time()))
    db_path = db_handler.handler(setting.DATABASE, file_name)
    save_data.db_write(db_path, player_object)
示例#13
0
文件: main.py 项目: icloudsme/cloud
def read_game(file_name):
	print("正在读取...")
	db_path = db_handler.handler(setting.DATABASE, file_name)
	return save_data.db_read(db_path)
示例#14
0
文件: main.py 项目: icloudsme/cloud
def save_game(player_object):
	print("正在存档...")
	# 生成一个以当前时间为文件名的存档文件
	file_name = time.strftime('%Y%m%d_%H%M%S', time.gmtime(time.time()))
	db_path = db_handler.handler(setting.DATABASE, file_name)
	save_data.db_write(db_path, player_object)
示例#15
0
#!/usr/bin/env python3.5
# -*- coding:utf8 -*-
import os,sys,pickle,re,logging
BASEDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASEDIR)
from conf import setting
from core import db_handler
from core import host_handler
db_path = db_handler.handler(setting.DATABASE,"host")
if os.path.exists(db_path):
    with open(db_path, "rb") as f:
        data = pickle.loads(f.read())
else:
    data =[]
# 初始化日志格式及对象
logging.basicConfig(level=logging.INFO, filename=os.path.join(BASEDIR,'log/ssh.log'), filemode='a',
                    format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y/%m/%d %H:%M:%S')
log = logging.getLogger(__name__)
def check_ip(ip):
    for data_ip in data:
        for ip_data in data_ip:
            for iptest in data_ip[ip_data]:
                if ip in iptest["ip"]:
                    return True
    else:
        return False
def check_group(group):
    for gc in data:
        if group in gc.keys():
            return True
    else:
示例#16
0
#!/usr/bin/env python3.5
# -*- coding:utf8 -*-
import os, sys, pickle, re, logging
BASEDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASEDIR)
from conf import setting
from core import db_handler
from core import host_handler
db_path = db_handler.handler(setting.DATABASE, "host")
if os.path.exists(db_path):
    with open(db_path, "rb") as f:
        data = pickle.loads(f.read())
else:
    data = []
# 初始化日志格式及对象
logging.basicConfig(level=logging.INFO,
                    filename=os.path.join(BASEDIR, 'log/ssh.log'),
                    filemode='a',
                    format='%(asctime)s %(levelname)s %(message)s',
                    datefmt='%Y/%m/%d %H:%M:%S')
log = logging.getLogger(__name__)


def check_ip(ip):
    for data_ip in data:
        for ip_data in data_ip:
            for iptest in data_ip[ip_data]:
                if ip in iptest["ip"]:
                    return True
    else:
        return False