コード例 #1
0
def login(sock, data):
    db = ConnDb()
    result = db.select('name,password', 'user', "ID='" + str(data['ID']) + "'")
    if len(result) == 0:
        sock.send(b'4')
        print(sock.recv(1024).decode('utf-8'))
        sock.send(b'fail')
        db.insert(
            'operation', ('opr_time', 'user', 'operation', 'result'),
            f"('{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}','{data['ID']}','login_in','fail')"
        )
    elif result[0][1] == data['password']:
        server.login_users.append(data['ID'])
        print(server.login_users)
        d = json.dumps({
            "result": "login in success",
            "name": result[0][0]
        }).encode('utf-8')
        sock.send(str(len(d)).encode('utf-8'))
        print(sock.recv(1024).decode('utf-8'))
        sock.send(d)
        db.insert(
            'operation', ('opr_time', 'user', 'operation', 'result'),
            f"('{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}','{data['ID']}','login_in','success')"
        )
    else:
        d = json.dumps({"result": "fail"}).encode('utf-8')
        sock.send(str(len(d)).encode('utf-8'))
        print(sock.recv(1024).decode('utf-8'))
        sock.send(d)
        db.insert(
            'operation', ('opr_time', 'user', 'operation', 'result', 'object'),
            values=
            f"('{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}','{data['ID']}','login_in','fail','none')"
        )
コード例 #2
0
def download_head(sock, opr):
    db = ConnDb()
    file_list = db.select('*', 'map', 'None')
    d = {"result": "success", "file": []}
    for file in file_list:
        d['file'].append({'ID': file[0], 'title': file[1], 'type': file[2]})
    # print(d)
    d = json.dumps(d).encode('utf-8')
    sock.send(str(len(d)).encode('utf-8'))
    print(sock.recv(1024).decode('utf-8'))
    sock.send(d)
コード例 #3
0
def download(sock, opr):
    db = ConnDb()
    try:
        OID = db.select('OID', 'map', f"ID = '{opr['ID']}'")[0][0]
        if opr['type'] == 'image':
            file = db.select('data', 'image', f"ID = '{OID}'")[0][0]
        else:
            file = db.select('data', 'txt',
                             f"ID = '{OID}'")[0][0].encode('utf-8')
        sock.send(str(len(file)).encode('utf-8'))
        print(sock.recv(1024).decode('utf-8'))
        sock.sendall(file)
        if opr['operation'] == 'download file':
            # 插入操作记录
            db.insert(
                'operation',
                ('opr_time', 'user', 'operation', 'result', 'object'),
                f"('{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}','{opr['user']}','download file','success','{opr['ID']}')"
            )
        elif opr['operation'] == 'open project: download':
            # 插入操作记录
            db.insert(
                'operation',
                ('opr_time', 'user', 'operation', 'result', 'object'),
                f"('{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}','{opr['user']}','open project','success','{opr['ID']}')"
            )
    except:
        if opr['operation'] == 'download file':
            # 插入操作记录
            db.insert(
                'operation',
                ('opr_time', 'user', 'operation', 'result', 'object'),
                f"('{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}','{opr['user']}','download file','failed','{opr['ID']}')"
            )
        elif opr['operation'] == 'open project: download':
            # 插入操作记录
            db.insert(
                'operation',
                ('opr_time', 'user', 'operation', 'result', 'object'),
                f"('{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}','{opr['user']}','open project','failed','{opr['ID']}')"
            )
コード例 #4
0
 def clear_users(self):  # 检查当前登录账号两小时内的最近操作记录
     db = ConnDb()
     while True:
         update_time = (
             datetime.datetime.now() -
             datetime.timedelta(hours=2)).strftime('%Y%m%d%H%M%S')
         for user in self.login_users:
             data = db.select(
                 'MAX(opr_time)', 'operation',
                 f'opr_time > {update_time} AND user = {user}')
             if data[0][0] is None:  # 两小时内没有操作记录,视为登录超时,释放该账号
                 self.login_users.remove(user)
                 # print(datetime.datetime.now() - db.select('MAX(opr_time)', 'operation', f'user = {user}')[0][0])
         # print(self.login_users)
         time.sleep(7200)
コード例 #5
0
def select_err(sock, opr):
    db = ConnDb()
    error_list = db.select(
        'ID,pos,type,detail', 'error',
        f"OID = '{opr['OID']}' AND (type LIKE '%{opr['key']}%' OR detail LIKE '%{opr['key']}%')"
    )
    d = {"result": "success", "error": []}
    for err in error_list:
        d['error'].append({
            'ID': err[0],
            'pos': err[1],
            'type': err[2],
            'detail': err[3]
        })
    d = json.dumps(d).encode('utf-8')
    sock.send(str(len(d)).encode('utf-8'))
    print(sock.recv(1024).decode('utf-8'))
    sock.send(d)