Exemple #1
0
def remove_client() -> Resnponse:
    """
    将连接对象添加到发送对象列表中
    """
    if not check_login(): return redirect('/login')
    key = request.form.get('key')
    removed, msg = service.remove_client_from_sendlist(key)
    if removed: return Resnponse.success(msg)
    return Resnponse.error(msg, CodeRequestOkButNoChange)
Exemple #2
0
def set_options() -> Resnponse:
    """

    :return: Response
    """
    target = str(request.form.get('target'))
    port = int(request.form.get('port'))
    err, msg = client.set_options(target, port)
    if err:
        return Resnponse.success(msg)
    else:
        return Resnponse.error(msg)
def set_options() -> Resnponse:
    """

    :return: Response
    """
    if not check_login(): return redirect('/login')
    host = str(request.form.get('host'))
    port = int(request.form.get('port'))
    err, msg = service.set_options(host, port)
    if err:
        return Resnponse.success(msg)
    else:
        return Resnponse.error(msg)
Exemple #4
0
def get_client_usage() -> Resnponse:
    if not check_login(): return redirect('/login')
    client_key = request.form.get('client_key')
    if client_key:
        if service.client_monitor is None:
            try:
                service.client[client_key].send(b'[::usage]')
            except KeyError:
                return Resnponse.error('没有这个连接对象')
            service.client_monitor = client_key
            return Resnponse.success('打开客户端 {} 监控成功'.format(client_key), type='SYSTEM')
        return Resnponse.error('已有在监控的客户端了', code=CodeRequestOkButNoChange)
    return Resnponse.error('打开客户端监控失败')
def stop_server() -> Resnponse:
    """
    关闭服务器, 只接收POST请求
    """
    if not check_login(): return redirect('/login')
    # 判断服务器是否有在运行
    if not service.status:
        return Resnponse.error("服务器没有在运行",
                               code=CodeRequestOkButNoChange,
                               status=StatusBadRequest)
    # 关闭服务器
    service.close()
    # 杀手后台线程
    thread.stop_thread()
    return Resnponse.success("关闭成功")
Exemple #6
0
def stop_client_usage() -> Resnponse:
    if not check_login(): return redirect('/login')
    client_key = request.form.get('client_key')
    if client_key and service.client_monitor is not None:
        try:
            service.client[client_key].send(b'[::nusage]')
        except KeyError:
            service.client_monitor = None
            return Resnponse.error('没有这个连接对象')
        except ConnectionResetError:
            socketio.emit('server_response', {'action': 'on_disconected', 'key': client_key}, namespace='/channel')
            service.remove_client(client_key)
        service.client_monitor = None
        return Resnponse.success('关闭客户端 {} 监控成功'.format(client_key), type='SYSTEM')
    return Resnponse.error('打开客户端监控失败')
def run_server() -> Resnponse:
    """
    开启服务器, 只接收POST请求
    """
    if not check_login(): return redirect('/login')
    # 判断服务器是否已经在运行
    if service.status:
        return Resnponse.error("服务器, 已经在运行",
                               code=CodeRequestOkButNoChange,
                               status=StatusBadRequest)
    try:
        service.run()
        service.status = True
    except OSError:
        return Resnponse.error(
            "端口 {} 已被占用, 通常每个套接字地址(协议/网络地址/端口)只允许使用一次".format(service.port))
    return Resnponse.success("服务器启动成功")
Exemple #8
0
def connect() -> Resnponse:
    """
    开启服务器, 只接收POST请求
    """

    # 判断服务器是否已经在运行
    if client.status:
        return Resnponse.error("已有连接, 请勿重连",
                               code=CodeRequestOkButNoChange,
                               status=StatusBadRequest)
    conn, msg = client.connect()
    if conn:
        print('....................................................')
        traffic.run()
        thread.threads.append(socketio.start_background_task(target=wait_recv))
        return Resnponse.success(msg)
    return Resnponse.error(msg)
Exemple #9
0
def disconnect() -> Resnponse:
    """
    与服务器断开连接, 关闭连接
    """

    global push_usage_status
    # 判断服务器是否有在运行
    if not client.status:
        return Resnponse.error("没有任何连接",
                               code=CodeRequestOkButNoChange,
                               status=StatusBadRequest)
    push_usage_status = False
    client.send_usaged = False
    # 关闭服务器
    client.disconnect()
    # 杀手后台线程
    thread.stop_thread()
    return Resnponse.success("断开连接成功")
Exemple #10
0
def send_file() -> Resnponse:
    # 验证登录
    if not check_login(): return redirect('/login')

    # 保存文件
    try:
        f = request.files['files']
        f.save(os.path.join(UPLOAD_PATH, f.filename))
    except Exception:
        return Resnponse.error("文件呢????", CodeRequestNo, StatusBadRequest)

    # 获取发送列表
    host_arr = request.form.get("host_arr")
    if not host_arr and not service.client:
        return Resnponse.error("没有连接对象,或没有选择连接对象", CodeRequestNo, StatusBadRequest)

    threading.Thread(target=service.send_file, args=(host_arr, f.filename)).start()

    return Resnponse.success("操作成功, 正在发送, 请耐心等待")
def get_service_status() -> Resnponse:
    """
    获取当前服务器信息, 只接收GET请求
    """
    if not check_login(): return redirect('/login')
    return Resnponse.defined({
        'code': CodeRequestOk,
        'log': log.read(),
        'message': '初始化获取数据成功',
        'type': 'INFO'
    })
Exemple #12
0
def get_service_status() -> Resnponse:
    """
    获取当前服务器信息, 只接收GET请求
    """

    return Resnponse.defined({
        'code': CodeRequestOk,
        'log': log.read(),
        'message': '初始化获取数据成功',
        'type': 'INFO'
    })
Exemple #13
0
def disconnect_client():
    if not check_login(): return redirect('/login')
    client_key = request.form.get('key')
    suc, msg = service.disconnect(client_key)
    if suc: return Resnponse.success(msg)
    return Resnponse.error(msg)
Exemple #14
0
def send() -> Resnponse:
    if not check_login(): return redirect('/login')
    msg = request.form.get('msg')
    service.send(msg)
    log.write(msg + '\n', 'SYSTEM')
    return Resnponse.success(msg, type='SYSTEM')