Exemplo n.º 1
0
def noblink_device_process(device_id, session_id, account_id):
    for i in range(20):  # 循环20次
        ubus_cd(session_id, account_id, 'noblink', ["mnt", "noblink", {}],
                '&device_id=%s' % device_id)  #闪
        time.sleep(2)
        ubus_cd(session_id, account_id, 'blink', ["mnt", "blink", {}],
                '&device_id=%s' % device_id)  #不闪
Exemplo n.º 2
0
def progress_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')
    ubus_cd(session_id, account_id, 'get_progress', ["upgrade", "start", {}], '&device_id=%s' % device_id)
    ubus_cd(session_id, account_id, 'get_progress', ["upgrade", "get_progress", {}], '&device_id=%s' % device_id)

    return redirect(url_for('excavators'))
Exemplo n.º 3
0
def start_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    ubus_cd(session_id, account_id, 'check', ["dcdn", "start", {}], '&device_id=%s' % device_id)

    return redirect(url_for('excavators'))
Exemplo n.º 4
0
def reset_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    ubus_cd(session_id, account_id, 'reset', ["mnt", "reset", {}], '&device_id=%s' % device_id)

    return redirect(url_for('excavators'))
Exemplo n.º 5
0
def upgrade_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    ubus_cd(session_id, account_id, 'get_progress', ["upgrade", "start", {}], '&device_id=%s' % device_id)
    ubus_cd(session_id, account_id, 'get_progress', ["upgrade", "get_progress", {}], '&device_id=%s' % device_id)

    return redirect(url_for('excavators'))
Exemplo n.º 6
0
def set_device_name():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')
    new_name = request.values.get('new_name')

    ubus_cd(session_id, account_id, 'set_device_name',
            ["server", "set_device_name", {"device_name": new_name, "device_id": device_id}])

    return json.dumps(dict(status='success'))
Exemplo n.º 7
0
def set_device_schedule():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    schedule_text = request.values.get('schedule_text')
    schedules = schedule_text.replace('\r', '\n').replace(' ', '')
    listall = schedules.split('\n')
    list_valid = []
    session['error_message'] = ''
    session['action'] = 'pattern'
    try:
        for item in listall:
            nodes = item.split(',')
            if len(nodes) >= 2:
                time_span = nodes[0].split('-')
                if len(time_span) <= 1:
                    continue
                time_from = int(time_span[0])
                time_to = int(time_span[1])
                if time_from >= time_to or time_to > 24:
                    continue
                schedule = {'from': time_from, 'to': time_to}
                params = {}
                if nodes[1] == '全速':
                    schedule['type'] = 'unlimit'
                elif nodes[1] == '智能':
                    schedule['type'] = 'automatic'
                elif nodes[1] == '限速':
                    schedule['type'] = 'manual'
                    if len(nodes) >= 3:
                        speed_limits = nodes[2].split('-')
                        if len(speed_limits) <= 1:
                            continue
                        download_limit = int(speed_limits[0])
                        upload_limit = int(speed_limits[1])
                        params['download_speed'] = download_limit
                        params['upload_speed'] = upload_limit
                else:
                    continue
                schedule['params'] = params
                list_valid.append(schedule)
    except ValueError:
        session['error_message'] = session['error_message'] + session[
            'error_message'] + '日程格式错误,数字必须为整数。'

    schedule_param = {"hours": list_valid}
    ubus_cd(session_id, account_id, 'set_schedule',
            ["xqos", "set_schedule", schedule_param],
            '&device_id=%s' % device_id)
    session['info_message'] = '矿机计划设置已提交'
    session['device_id'] = device_id
    session['session_id'] = session_id
    session['account_id'] = account_id
    return render_admin_device()
Exemplo n.º 8
0
def noblink_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    for i in range(10):# 循环20次
        ubus_cd(session_id, account_id, 'noblink', ["mnt", "noblink", {}], '&device_id=%s' % device_id)#闪
        time.sleep(2)
        ubus_cd(session_id, account_id, 'blink', ["mnt", "blink", {}], '&device_id=%s' % device_id)#不闪

    return redirect(url_for('excavators'))
Exemplo n.º 9
0
def reset_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    ubus_cd(session_id, account_id, 'reset', ["mnt", "reset", {}], '&device_id=%s' % device_id)

    session['device_id'] = device_id
    session['session_id'] = session_id
    session['account_id'] = account_id
    session['info_message']='设备已恢复出厂设置'
    return render_admin_device()
Exemplo n.º 10
0
def start_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    ubus_cd(session_id, account_id, 'check', ["dcdn", "start", {}], '&device_id=%s' % device_id)

    session['device_id'] = device_id
    session['session_id'] = session_id
    session['account_id'] = account_id
    session['info_message'] = '设备已启动成功'
    return render_admin_device()
Exemplo n.º 11
0
def disable_upnp():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    ubus_cd(session_id, account_id, 'set_upnp', ["dcdn","set_upnp",{"enabled":False}], '&device_id=%s' % device_id)

    session['device_id'] = device_id
    session['session_id'] = session_id
    session['account_id'] = account_id
    session['info_message']='设备已关闭UPNP'
    return redirect(url_for('excavators'))
Exemplo n.º 12
0
def umount_disk():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')
    session['action']='pattern'

    ubus_cd(session_id, account_id, 'umount_usb', ["mnt", "umount_usb", {}], '&device_id=%s' % device_id)

    session['device_id'] = device_id
    session['session_id'] = session_id
    session['account_id'] = account_id
    session['info_message']='设备已开启UPNP'
    return render_admin_device()
Exemplo n.º 13
0
def disable_upnp():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')
    session['action']='pattern'

    ubus_cd(session_id, account_id, 'set_upnp', ["dcdn","set_upnp",{"enabled":False}], '&device_id=%s' % device_id)

    session['device_id'] = device_id
    session['session_id'] = session_id
    session['account_id'] = account_id
    session['info_message']='设备已关闭UPNP'
    return render_admin_device()
Exemplo n.º 14
0
def upgrade_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    ubus_cd(session_id, account_id, 'get_progress', ["upgrade", "start", {}], '&device_id=%s' % device_id)
    ubus_cd(session_id, account_id, 'get_progress', ["upgrade", "get_progress", {}], '&device_id=%s' % device_id)

    session['device_id'] = device_id
    session['session_id'] = session_id
    session['account_id'] = account_id
    session['info_message'] = '矿机已安排升级'
    return render_admin_device()
Exemplo n.º 15
0
def set_device_name():
    setting_url = request.values.get('url')
    new_name = request.values.get('name')
    query_s = parse_qs(urlparse(setting_url).query, keep_blank_values=True)

    device_id = query_s['device_id'][0]
    session_id = query_s['session_id'][0]
    account_id = query_s['user_id'][0]

    ubus_cd(session_id, account_id, 'set_device_name',
            ["server", "set_device_name", {"device_name": new_name, "device_id": device_id}])

    return json.dumps(dict(status='success'))
Exemplo n.º 16
0
def disable_upnp():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    ubus_cd(session_id, account_id, 'set_upnp',
            ["dcdn", "set_upnp", {
                "enabled": False
            }], '&device_id=%s' % device_id)

    session['device_id'] = device_id
    session['session_id'] = session_id
    session['account_id'] = account_id
    session['info_message'] = '设备已关闭UPNP'
    return redirect(url_for('excavators'))
Exemplo n.º 17
0
def async_umount_disk_all(user):
    accounts_key = 'accounts:%s' % user.get('username')
    for acct in r_session.smembers(accounts_key):
        account_key = 'account:%s:%s' % (user.get('username'), acct.decode("utf-8"))
        account_data_key = account_key + ':data'
        account_data_value = r_session.get(account_data_key)
        account_info = json.loads(r_session.get(account_key).decode("utf-8"))
        if account_data_value is not None:
            data = json.loads(account_data_value.decode("utf-8"))
            if 'device_info' in data.keys():
                for device in data['device_info']:
                    if device['status'] == 'offline':
                        continue
                    session_id = account_info['session_id']
                    device_id = device['device_id']
                    account_id = device['account_id']
                    ubus_cd(session_id, account_id, 'umount_usb', ["mnt", "umount_usb", {}], '&device_id=%s' % device_id)
                    time.sleep(5)
Exemplo n.º 18
0
def async_upgrade_device_all(user):
    accounts_key = 'accounts:%s' % user.get('username')
    for acct in r_session.smembers(accounts_key):
        account_key = 'account:%s:%s' % (user.get('username'), acct.decode("utf-8"))
        account_data_key = account_key + ':data'
        account_data_value = r_session.get(account_data_key)
        account_info = json.loads(r_session.get(account_key).decode("utf-8"))
        if account_data_value is not None:
            data = json.loads(account_data_value.decode("utf-8"))
            if 'device_info' in data.keys():
                for device in data['device_info']:
                    if not device['upgradeable']:
                        continue
                    session_id = account_info['session_id']
                    device_id = device['device_id']
                    account_id = device['account_id']
                    ubus_cd(session_id, account_id, 'get_progress', ["upgrade", "start", {}], '&device_id=%s' % device_id)
                    ubus_cd(session_id, account_id, 'get_progress', ["upgrade", "get_progress", {}], '&device_id=%s' % device_id)
                    time.sleep(5)
Exemplo n.º 19
0
def render_admin_device():
    user = session.get('user_info')

    err_msg = None
    if session.get('error_message') is not None:
        err_msg = session.get('error_message')
        session['error_message'] = None

    info_msg = None
    if session.get('info_message') is not None:
        info_msg = session.get('info_message')
        session['info_message'] = None
    action = None
    if session.get('action') is not None:
        action = session.get('action')
        session['action'] = None
    if session.get('device_id') is not None:
        device_id = session.get('device_id')
        session['device_id'] = None
    if session.get('session_id') is not None:
        session_id = session.get('session_id')
        session['session_id'] = None
    if session.get('account_id') is not None:
        account_id = session.get('account_id')
        session['account_id'] = None

    dev = ubus_cd(session_id, account_id,
                  ["server", "get_device", {
                      "device_id": device_id
                  }])
    #return json.dumps(dev)
    schedule_text = ''
    for schedule in dev['result'][1]['schedule_hours']:
        schedule_text = '%s%s-%s' % (schedule_text, schedule['from'],
                                     schedule['to'])
        if schedule['type'] == 'unlimit':
            schedule_text = '%s,%s\r\n' % (schedule_text, '全速')
        elif schedule['type'] == 'automatic':
            schedule_text = '%s,%s\r\n' % (schedule_text, '智能')
        else:
            schedule_text = '%s,%s,%s-%s\r\n' % (
                schedule_text, '限速', schedule['params']['download_speed'],
                schedule['params']['upload_speed'])
    return render_template('excavators_info.html',
                           err_msg=err_msg,
                           info_msg=info_msg,
                           action=action,
                           device_id=device_id,
                           session_id=session_id,
                           account_id=account_id,
                           dev=dev,
                           schedule_text=schedule_text)
Exemplo n.º 20
0
def admin_device():
    device_id = request.values.get('device_id')
    session_id = request.values.get('session_id')
    account_id = request.values.get('account_id')

    action = None
    if session.get('action') is not None:
        action = session.get('action')
        session['action'] = None

    device_info = ubus_cd(session_id, account_id, 'get_device', ["server", "get_device", {"device_id": device_id}])

    return render_template('excavators_info.html', action=action, session_id=session_id, account_id=account_id, device_info=device_info)
Exemplo n.º 21
0
def admin_root():
    import hashlib
    import base64
    user = session.get('user_info')
    user_key = '%s:%s' % ('user', user.get('username'))
    user_info = json.loads(r_session.get(user_key).decode('utf-8'))
    action = None
    if session.get('action') is not None:
        action = session.get('action')
        session['action'] = None
    if True or 'root_no' in user_info.keys() and user_info['root_no'] != 0:
        user_info['root_no'] = 0
        device_id = request.values.get('device_id')
        session_id = request.values.get('session_id')
        account_id = request.values.get('account_id')
        dev = ubus_cd(session_id, account_id, 'get_device',
                      ["server", "get_device", {
                          "device_id": device_id
                      }])
        if dev is not None:
            if 'result' in dev.keys():
                sn = dev['result'][1]['device_sn']
                mac = dev['result'][1]['mac_address']
                key = '%s%s%s' % (sn, mac, 'i8e%Fvj24nz024@d!c')
                m = hashlib.md5()
                m.update(key.encode('utf-8'))
                md5 = m.digest()
                passwd = base64.b64encode(md5).decode('utf-8')
                passwd = passwd[0:8]
                passwd = passwd.replace('+', '-')
                passwd = passwd.replace('/', '_')
                if 'root_passwd' not in user_info.keys():
                    user_info['root_passwd'] = {}
                user_info['root_passwd'][device_id] = passwd
                user_info['root_no'] = user_info['root_no'] - 0
                r_session.set(user_key, json.dumps(user_info))
            else:
                session['error_message'] = '获取ROOT所需信息失败'
        else:
            session['error_message'] = '请选择一个需要ROOT密码的设备'
        return redirect(url_for('excavators'))
    session['error_message'] = '您的账户没有ROOT机会了,请联系管理员获取。'
    return redirect(url_for('excavators'))
Exemplo n.º 22
0
def admin_debug_ubus():
    from api import ubus_cd
    try:
        session_id=request.values.get('session_id')
        account_id=request.values.get('account_id')
        command=request.values.get('command')
        action=request.values.get('action')
        params=request.values.get('params')
        extra_url=request.values.get('extra_url')
        session['info_message'] = ubus_cd(session_id, account_id, ["%s" % command,"%s" % action,json.loads(params)], extra_url)
        session['ubus_params']={
            'session_id':session_id,
            'account_id':account_id,
            'command':command,
            'action':action,
            'params':params,
            'extra_url':extra_url
        }
    except RuntimeError as e:
        session['error_message'] = json.dumps(e)
    return redirect(url_for('admin_debug'))
Exemplo n.º 23
0
def admin_debug_ubus():
    from api import ubus_cd
    try:
        session_id = request.values.get('session_id')
        account_id = request.values.get('account_id')
        command = request.values.get('command')
        action = request.values.get('action')
        params = request.values.get('params')
        extra_url = request.values.get('extra_url')
        session['info_message'] = ubus_cd(
            session_id, account_id,
            ["%s" % command, "%s" % action,
             json.loads(params)], extra_url)
        session['ubus_params'] = {
            'session_id': session_id,
            'account_id': account_id,
            'command': command,
            'action': action,
            'params': params,
            'extra_url': extra_url
        }
    except RuntimeError as e:
        session['error_message'] = json.dumps(e)
    return redirect(url_for('admin_debug'))
Exemplo n.º 24
0
def noblink(device_id, session_id, account_id):
    for i in range(10):
        ubus_cd(session_id, account_id, 'noblink', ["mnt", "noblink", {}], '&device_id=%s' % device_id)
        time.sleep(1)
        ubus_cd(session_id, account_id, 'blink', ["mnt", "blink", {}], '&device_id=%s' % device_id)
        time.sleep(1)