def ls():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    path = rq['path']
    h = False
    if rq.has_key('showhidden'):
        h = rq['showhidden']
        if h == 'false': h = False
        else: h = True
    if path.startswith('trash:///'): return _lstrash(u, h)
    if path.startswith('root:///'): return _lsroot(u)
    if path.startswith('file:///C:/') and not a: return 403
    p = _get_path(path, u)
    if not os.path.exists(p) or os.path.isfile(p): return 404
    rw, _r = _get_rw(u, a, p)
    if not rw and path != 'file:///': return 403
    if path in [
            'home:///', 'desktop:///', 'public:///', 'file:///', 'share:///'
    ]:
        _r[8] = path
    R = {'prop': _r}
    r = []
    l = os.listdir(p)
    l.sort()  #key=unicode.lower
    for f in l:
        if f.startswith('.'):
            if not h: continue
        fp = '%s/%s' % (p, f)
        if not os.path.exists(fp): continue
        _r = _fileinfo(fp)
        if path == 'file:///' and not _r[7]: continue
        if _r: r.append(_r)
    R['children'] = r
    return R
Exemple #2
0
def craid():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    p1 = rq['path1']
    p2 = rq['path2']
    return _craid(p1, p2)
def restart():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    n = rq['name']
    _systemctl('restart', n)
    return 200
def stop():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    n = rq['name']
    _systemctl('stop', n)
    return 200
def enable():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    n = rq['name']
    e = rq['enabled']
    return _enable(e, n)
def getbluetooth():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    from service import _service_status
    if not _service_status('bluetooth'):
        os.system('sudo systemctl restart bluetooth.service')
    if not _service_status('bluealsa'):
        os.system('sudo systemctl restart bluealsa.service')
    os.system('sudo killall bt-adapter')
    c = 'sudo bt-adapter -d > /dev/null 2>&1 &'
    r = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE)
    pid = r.pid
    if not rq.has_key('pid') or (
            rq.has_key('pid') and
        (rq['pid'] == ''
         or subprocess.Popen('ps aux|grep bt-adapter |grep %s' % rq['pid'],
                             shell=True,
                             stdout=subprocess.PIPE).stdout.read() == '')):
        time.sleep(10)
    c = 'sudo bt-device -l'
    r = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE)
    l = r.stdout.readlines()
    _r = []
    for i in l:
        if i.startswith('Added devices:') or i.startswith('No devices found'):
            continue
        x = i.rindex('(')
        m = i[x:].strip('()\n')
        __r = _get_bt_info(m)
        if not __r: continue
        _r.append(__r)
    return {'pid': pid, 'dev': _r}
Exemple #7
0
def remove():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    n = rq['name']
    os.system('sudo zerotier-cli leave %s' % n)
    return 200
Exemple #8
0
def rmraid():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    p = rq['path']
    d = rq['dev']
    return _rmraid(p, d)
def status():
    u, a = auth._auth()
    if not a: return 403
    c = 'ps aux|grep kodi_v7.bin'
    r = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE).stdout.read()
    if '--lircdev' in r: return {'running': True}
    return {'running': False}
Exemple #10
0
def add():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    n = rq['name']
    os.system('sudo zerotier-cli join %s' % n)
    return 200
def stop():
	u,a=auth._auth()
	if not u:return 403
	rq=web.input()
	p=rq['pid']
	r=rq['rid']
	return _stop(p,r)
Exemple #12
0
def rmpart():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    p = rq['path']
    n = rq['number']
    return _rmpart(p, n)
def gettemp():
    u, a = auth._auth()
    if not u: return 403
    c = 'sudo cat /sys/class/thermal/thermal_zone0/temp'
    r = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE).stdout.read()
    t = round(float(r) / 1000, 1)
    return {'temp': '%s°C\n' % t}
def unzip():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    p = rq['path']
    p = _get_path(p, u)
    return _unzip(p)
def disconnectbluetooth():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    m = rq['dev']
    os.system('echo "disconnect %s\n" |sudo bluetoothctl' % m)
    return 200
def stoprecord():
	u,a=auth._auth()
	if not u:return 403
	rq=web.input()
	d=rq['pid']
	d=int(d)
	os.kill(d,3)
	return 200
def set():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    o = rq['option']
    n = rq['name']
    _systemctl(o, n)
    return 200
def screen():
	u,a=auth._auth()
	if not u:return 403
	rq=web.input()
	d=rq['dev']
	p=8000+int(d)
	_play('http://127.0.0.1:%s/?action=stream'%p,'')
	return 200
def unpairbluetooth():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    m = rq['dev']
    os.system('sudo bt-device --set %s Trusted false' % m)
    os.system('sudo bt-device -r %s' % m)
    return 200
def getconf():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    p = rq['path']
    c = _getconf(p, u)
    c['to'] = _get_uipath(c['to'], u)
    return c
def setworkgroup():
    u, a = auth._auth()
    if not u or not a: return 403
    rq = web.input()
    n = rq['name']
    n = n.replace(' ', '')
    _set_name_value('/box/etc/workgroup.conf', {'workgroup': n})
    os.system('sudo systemctl restart smbd.service')
    return 200
def find():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    p = rq['path']
    f = rq['file']
    if f.strip() == '' or p == 'trash:///' or p == 'root:///': return ls()
    p = _get_path(p, u)
    return _find(p, f)
def pairbluetooth():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    m = rq['dev']
    os.system('sudo bt-device --set %s Trusted true' % m)
    os.system('echo "yes"|sudo bt-device -c %s' % m)
    _set_asound(m)
    return 200
Exemple #24
0
def set():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    e = rq['enable']
    o = rq['option']
    service._enable(e, NAME)
    service._systemctl(o, NAME)
    return 200
Exemple #25
0
def get():
    u, a = auth._auth()
    if not a: return 403
    p = {'directories': ''}
    info._get_name_value(CONF, p, equal='=')
    p['directories'] = files._get_uipath(p['directories'].strip(' {"}'), u)
    p['active'] = service._service_status(NAME)
    p['enabled'] = service._service_enabled(NAME)
    return p
def get():
    u, a = auth._auth()
    if not a: return 403
    p = {'media_dir': ''}
    info._get_name_value(CONF, p)
    p['media_dir'] = files._get_uipath(p['media_dir'], u)
    p['active'] = service._service_status(NAME)
    p['enabled'] = service._service_enabled(NAME)
    return p
Exemple #27
0
def mkpart():
    u, a = auth._auth()
    if not a: return 403
    rq = web.input()
    p = rq['path']
    t = rq['type']
    s = rq['start']
    e = rq['end']
    return _mkpart(p, t, s, e)
def zip():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    f = rq['file']
    f = json.loads(f)
    _f = []
    for i in f:
        _f.append(_get_path(i, u))
    return _zip(_f)
def mkdir():
    u, a = auth._auth()
    if not u: return a
    rq = web.input()
    pt = rq['path']
    p = _get_path(pt, u)
    if not p: return 400
    os.mkdir(p)
    _set_rw(u, p)
    return 200
def top():
    u, a = auth._auth()
    if not u or not a: return 403
    c = 'sudo cat /sys/class/thermal/thermal_zone0/temp'
    r0 = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE).stdout.read()
    c = 'sudo top -bn 2 -i -c'
    r1 = subprocess.Popen(c, shell=True, stdout=subprocess.PIPE).stdout.read()
    t = round(float(r0) / 1000, 1)
    r1 = r1.replace('top - ', 'uptime: ')
    return {'message': 'temperature: %s°C\n%s' % (t, r1)}