コード例 #1
0
ファイル: views.py プロジェクト: ProtoSD/FreeNAS_8-Serviio
def stop(request):
    serviio_key, serviio_secret = utils.get_serviio_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=serviio_key,
        secret=serviio_secret)
    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
    jail = json.loads(server.plugins.jail.info())[0]
    assert auth

    try:
        serviio = models.Serviio.objects.order_by('-id')[0]
        serviio.enable = False
        serviio.save()
    except IndexError:
        serviio = models.Serviio.objects.create(enable=False)

    try:
        form = forms.ServiioForm(serviio.__dict__, instance=serviio, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        pass

    cmd = "%s onestop" % utils.serviio_control
    pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
        shell=True, close_fds=True)

    out = pipe.communicate()[0]
    return HttpResponse(simplejson.dumps({
        'error': False,
        'message': out,
        }))
コード例 #2
0
ファイル: views.py プロジェクト: ProtoSD/FreeNAS_8-Serviio
def start(request):
    serviio_key, serviio_secret = utils.get_serviio_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=serviio_key,
        secret=serviio_secret)
    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
    jail = json.loads(server.plugins.jail.info())[0]
    assert auth

    try:
        serviio = models.Serviio.objects.order_by('-id')[0]
        serviio.enable = True
        serviio.save()
    except IndexError:
        serviio = models.Serviio.objects.create(enable=True)

    try:
        form = forms.ServiioForm(serviio.__dict__, instance=serviio, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        return HttpResponse(simplejson.dumps({
            'error': True,
            'message': 'Serviio data did not validate, please configure it first.',
            }), content_type='application/json')


    libc = ctypes.cdll.LoadLibrary("libc.so.7")
    omask = (ctypes.c_uint32 * 4)(0, 0, 0, 0)
    mask = (ctypes.c_uint32 * 4)(0, 0, 0, 0)
    pmask = ctypes.pointer(mask)
    pomask = ctypes.pointer(omask)
    libc.sigprocmask(signal.SIGQUIT, pmask, pomask)
    cmd = "%s onestart" % utils.serviio_control
    _popen = os.popen(cmd)
    #pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
    #    shell=True)


    out = ''
    time.sleep(3)
    libc.sigprocmask(signal.SIGQUIT, pomask, None)
    return HttpResponse(simplejson.dumps({
        'error': False,
        'message': out,
        }))
コード例 #3
0
ファイル: views.py プロジェクト: ProtoSD/FreeNAS_8-Serviio
def edit(request):
    serviio_key, serviio_secret = utils.get_serviio_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=serviio_key,
        secret=serviio_secret)

    """
    Get the Serviio object
    If it does not exist create a new entry
    """
    try:
        serviio = models.Serviio.objects.order_by('-id')[0]
    except IndexError:
        serviio = models.Serviio.objects.create()

    try:
        server = jsonrpclib.Server(url, transport=trans)
        jail = json.loads(server.plugins.jail.info())[0]
        auth = server.plugins.is_authenticated(request.COOKIES.get("sessionid", ""))
        assert auth
    except Exception, e:
        raise