Exemplo n.º 1
0
def edit(request, plugin_id):
    (subsonic_key,
    subsonic_secret) = utils.get_subsonic_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key,
        secret=subsonic_secret)

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

    try:
        server = jsonrpclib.Server(url, transport=trans)
        jail_path = server.plugins.jail.path(plugin_id)
        jail = json.loads(server.plugins.jail.info(plugin_id))[0]['fields']
        jail_ipv4 = jail['jail_ipv4'].split('/')[0]
	if subsonic.subsonic_ssl:
		scheme = "https"
	else:
		scheme = "http"
        auth = server.plugins.is_authenticated(
            request.COOKIES.get("sessionid", "")
            )
        assert auth
    except Exception as e:
        raise

    if request.method == "GET":
        form = forms.SubsonicForm(instance=subsonic,
            jail_path=jail_path)
        return render(request, "edit.html", {
            'form': form,
            'ipv4': jail_ipv4,
            'scheme': scheme,
            'port': subsonic.subsonic_port,
            'webroot': subsonic.subsonic_context_path
        })

    if not request.POST:
        return JsonResponse(request, error=True, message="A problem occurred.")

    form = forms.SubsonicForm(request.POST,
        instance=subsonic,
        jail_path=jail_path)
    if form.is_valid():
        form.save()

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

        return JsonResponse(request, error=True,
            message="Subsonic settings successfully saved.")

    return JsonResponse(request, form=form)
Exemplo n.º 2
0
def stop(request):
    subsonic_key, subsonic_secret = utils.get_subsonic_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key,
        secret=subsonic_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:
        subsonic = models.Subsonic.objects.order_by('-id')[0]
        subsonic.enable = False
        subsonic.save()
    except IndexError:
        subsonic = models.Subsonic.objects.create(enable=False)

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

    cmd = "%s onestop" % utils.subsonic_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,
        }))
Exemplo n.º 3
0
def treemenu(request, plugin_id):
    """
    This is how we inject nodes to the Tree Menu

    The FreeNAS GUI will access this view, expecting for a JSON
    that describes a node and possible some children.
    """

    (subsonic_key, subsonic_secret) = utils.get_subsonic_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key, secret=subsonic_secret)
    server = jsonrpclib.Server(url, transport=trans)
    jail = json.loads(server.plugins.jail.info(plugin_id))[0]
    jail_name = jail['fields']['jail_host']
    number = jail_name.rsplit('_', 1)
    name = "Subsonic"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "Subsonic (%d)" % number
        except:
            pass

    plugin = {
        'name': name,
        'append_to': 'plugins',
        'icon': reverse('treemenu_icon', kwargs={'plugin_id': plugin_id}),
        'type': 'pluginsfcgi',
        'url': reverse('subsonic_edit', kwargs={'plugin_id': plugin_id}),
        'kwargs': {'plugin_name': 'subsonic', 'plugin_id': plugin_id },
    }

    return HttpResponse(json.dumps([plugin]), content_type='application/json')
Exemplo n.º 4
0
def start(request, plugin_id):
    (subsonic_key, subsonic_secret) = utils.get_subsonic_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key, secret=subsonic_secret)

    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(request.COOKIES.get(
        "sessionid", ""))
    jail_path = server.plugins.jail.path(plugin_id)
    assert auth

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

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

    cmd = "%s onestart" % utils.subsonic_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,
    }),
                        content_type='application/json')
Exemplo n.º 5
0
def start(request):
    subsonic_key, subsonic_secret = utils.get_subsonic_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key,
        secret=subsonic_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:
        subsonic = models.Subsonic.objects.order_by('-id')[0]
        subsonic.enable = True
        subsonic.save()
    except IndexError:
        subsonic = models.Subsonic.objects.create(enable=True)

    try:
        form = forms.SubsonicForm(subsonic.__dict__, instance=subsonic, jail=jail)
        form.is_valid()
        form.save()
    except ValueError:
        return HttpResponse(simplejson.dumps({
            'error': True,
            'message': 'Subsonic 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.subsonic_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,
        }))
Exemplo n.º 6
0
def start(request, plugin_id):
    (subsonic_key,
    subsonic_secret) = utils.get_subsonic_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key,
        secret=subsonic_secret)

    server = jsonrpclib.Server(url, transport=trans)
    auth = server.plugins.is_authenticated(
        request.COOKIES.get("sessionid", "")
        )
    jail_path = server.plugins.jail.path(plugin_id)
    assert auth

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

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

    cmd = "%s onestart" % utils.subsonic_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,
        }), content_type='application/json')
Exemplo n.º 7
0
def edit(request):
    subsonic_key, subsonic_secret = utils.get_subsonic_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key,
        secret=subsonic_secret)

    """
    Get the Subsonic object
    If it does not exist create a new entry
    """
    try:
        subsonic = models.Subsonic.objects.order_by('-id')[0]
    except IndexError:
        subsonic = models.Subsonic.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
Exemplo n.º 8
0
def treemenu(request, plugin_id):
    """
    This is how we inject nodes to the Tree Menu

    The FreeNAS GUI will access this view, expecting for a JSON
    that describes a node and possible some children.
    """

    (subsonic_key, subsonic_secret) = utils.get_subsonic_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key, secret=subsonic_secret)
    server = jsonrpclib.Server(url, transport=trans)
    jail = json.loads(server.plugins.jail.info(plugin_id))[0]
    jail_name = jail['fields']['jail_host']
    number = jail_name.rsplit('_', 1)
    name = "Subsonic"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "Subsonic (%d)" % number
        except:
            pass

    plugin = {
        'name': name,
        'append_to': 'plugins',
        'icon': reverse('treemenu_icon', kwargs={'plugin_id': plugin_id}),
        'type': 'pluginsfcgi',
        'url': reverse('subsonic_edit', kwargs={'plugin_id': plugin_id}),
        'kwargs': {
            'plugin_name': 'subsonic',
            'plugin_id': plugin_id
        },
    }

    return HttpResponse(json.dumps([plugin]), content_type='application/json')
Exemplo n.º 9
0
def edit(request, plugin_id):
    (subsonic_key, subsonic_secret) = utils.get_subsonic_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=subsonic_key, secret=subsonic_secret)
    """
    Get the Subsonic object
    If it does not exist create a new entry
    """
    try:
        subsonic = models.Subsonic.objects.order_by('-id')[0]
    except IndexError:
        subsonic = models.Subsonic.objects.create()

    try:
        server = jsonrpclib.Server(url, transport=trans)
        jail_path = server.plugins.jail.path(plugin_id)
        jail = json.loads(server.plugins.jail.info(plugin_id))[0]['fields']
        jail_ipv4 = jail['jail_ipv4'].split('/')[0]
        if subsonic.subsonic_ssl:
            scheme = "https"
        else:
            scheme = "http"
        auth = server.plugins.is_authenticated(
            request.COOKIES.get("sessionid", ""))
        assert auth
    except Exception as e:
        raise

    if request.method == "GET":
        form = forms.SubsonicForm(instance=subsonic, jail_path=jail_path)
        return render(
            request, "edit.html", {
                'form': form,
                'ipv4': jail_ipv4,
                'scheme': scheme,
                'port': subsonic.subsonic_port,
                'webroot': subsonic.subsonic_context_path
            })

    if not request.POST:
        return JsonResponse(request, error=True, message="A problem occurred.")

    form = forms.SubsonicForm(request.POST,
                              instance=subsonic,
                              jail_path=jail_path)
    if form.is_valid():
        form.save()

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

        return JsonResponse(request,
                            error=True,
                            message="Subsonic settings successfully saved.")

    return JsonResponse(request, form=form)