示例#1
0
def run(id):
    if not allow():
        LOGS.error('系统激活失败,请联系厂家获取支持')
        return
    #解析任务
    db.connect()
    task = Task.get(Task.finger == id)
    if task is None:
        LOGS.error('找不到对应任务:'+str(id))
        exit(-1)
    # 增加运行次数
    task.count = task.count + 1
    task.save()
    db.close()
    LOGS.info('开始任务:' + str(id)+":"+task.name)

    #执行任务
    files =getDataFile(task)
    if len(files) == 0:
        LOGS.info('未获取到任何数据:' + str(id) + ':' + task.name)
        return 0

    #发送文件
    r = redis.Redis()
    for f in files:
        #subprocess.call('./transfer_file -s '+f, shell=True)
        #改为发送文件列表到redis
        print(f)
        r.lpush('file',f)
        #记录日志
    LOGS.info('数据加入发送队列,等待发送:'+str(id)+':'+task.name)
示例#2
0
def changeNetwork(device, ip, netmask, gateway):
    """
    @attention: change the network of the system
    """
    #print(get_ip_address('eth5'))

    path = "/etc/sysconfig/network-scripts/ifcfg-" + str(device)
    file_handler = open(path, "r")
    network_content = file_handler.read()
    file_handler.close()
    conte = "IPADDR=%s\nNETMASK=%s\nGATEWAY=%s\n" % (ip, netmask, gateway)
    num = network_content.find("IPADDR")
    if num != -1:
        network_content = network_content[:num] + conte
        file_handler = open(path, "w")
        file_handler.write(network_content)
        file_handler.close()
    LOGS.info('ip修改成功:%s:%s:%s:%s' % (device, ip, gateway, netmask))
    try:
        result = subprocess.call("sudo ifdown %s && sudo ifup %s" %
                                 (device, device),
                                 shell=True)
        if result == 0:
            LOGS.info('网卡重启成功:%s:%s:%s:%s' % (device, ip, gateway, netmask))
            return True
        else:
            LOGS.info('网卡重启失败:%s:%s:%s:%s' % (device, ip, gateway, netmask))
            return False
    except Exception as e:
        LOGS.error(str(e))
        return False
示例#3
0
def retrieveFile(samba, share, path, id_str):
    file_path = 'temp/' + share + path + '.' + id_str
    try:
        mkdir(file_path)
        with open(file_path, 'wb') as f:
            samba.retrieveFile(share, path, f)
            LOGS.info('获取文件:' + path)
    except Exception as e:
        LOGS.error('SMB获取文件错误:' + str(e))
    return file_path
示例#4
0
def run(finger):
    import subprocess
    try:
        out_bytes = subprocess.check_output(
            '/usr/local/python3/bin/python3 run_sender.py ' + finger,
            shell=True,
            stderr=subprocess.PIPE)
    except Exception as e:
        LOGS.error('测试执行出现错误:' + str(e))
        return render_template('fragment/message.html',
                               message="运行过程中出现错误,请检查任务配置是否正常\n详情可参考日志\n信息:" +
                               str(e))
    out = out_bytes.decode('utf-8')
    return render_template('fragment/message.html', message=out)
示例#5
0
def login():
    form = LoginForm()
    #print(form.rememberme.data)
    if form.validate_on_submit():
        try:
            user = User.get(User.username == form.username.data)
            if user.verify_password(form.password.data):
                login_user(user)
                return redirect(
                    request.args.get('next') or url_for('main.index'))
            else:
                flash('用户名或密码错误')
        except Exception as e:
            LOGS.error(repr(e))
            flash('用户名不存在')
    stat = '外网端'
    if current_app.config.get('CLIENT_TYPE') == 'receiver':
        stat = '内网端'
    return render_template('auth/login.html', form=form, stat=stat)
示例#6
0
def getSMB(task):
    files = []
    try:
        samba = SMBConnection(task.username, task.password, 'mybase',
                              task.target)
        samba.connect(task.dir, int(task.port))
        list = task.tables.split(' ')
        share = list[0]
        path = list[1]
        id_str = str(task.finger)
        if len(list) == 3:  #指定文件
            file = list[2]
            p = path + '/' + file
            retrieveFile(samba, share, p, id_str)
            files.append(p)
        else:
            list = retrieveFileList(samba, share, path)
            for l in list:
                file = retrieveFile(samba, share, l, id_str)
                files.append(file)
        return files

    except Exception as e:
        LOGS.error('SMB连接出错:' + str(e))
示例#7
0
    files =getDataFile(task)
    if len(files) == 0:
        LOGS.info('未获取到任何数据:' + str(id) + ':' + task.name)
        return 0

    #发送文件
    r = redis.Redis()
    for f in files:
        #subprocess.call('./transfer_file -s '+f, shell=True)
        #改为发送文件列表到redis
        print(f)
        r.lpush('file',f)
        #记录日志
    LOGS.info('数据加入发送队列,等待发送:'+str(id)+':'+task.name)

    # 删除文件
    # try:
    #     for f in files:
    #         os.remove(f)
    # except:
    #     pass

if __name__ == '__main__':

    if len(sys.argv) > 1:
        id = sys.argv[1]
        run(id)
    else:
        LOGS.error('参数错误,未提供文件名')
        exit(-1)