示例#1
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.
    """

    (madsonic_key, madsonic_secret) = utils.get_madsonic_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=madsonic_key, secret=madsonic_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 = "Madsonic"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "Madsonic (%d)" % number
        except:
            pass

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

    return HttpResponse(json.dumps([plugin]), content_type='application/json')
示例#2
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.
    """

    (madsonic_key, madsonic_secret) = utils.get_madsonic_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=madsonic_key, secret=madsonic_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 = "Madsonic"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "Madsonic (%d)" % number
        except:
            pass

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

    return HttpResponse(json.dumps([plugin]), content_type='application/json')
示例#3
0
def edit(request, plugin_id):
    (madsonic_key,
    madsonic_secret) = utils.get_madsonic_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=madsonic_key,
        secret=madsonic_secret)

    """
    Get the Madsonic object
    If it does not exist create a new entry
    """
    try:
        madsonic = models.Madsonic.objects.order_by('-id')[0]
    except IndexError:
        madsonic = models.Madsonic.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 madsonic.madsonic_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.MadsonicForm(instance=madsonic,
            jail_path=jail_path)
        return render(request, "edit.html", {
            'form': form,
            'ipv4': jail_ipv4,
            'scheme': scheme,
            'port': madsonic.madsonic_port,
            'webroot': madsonic.madsonic_context_path
        })

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

    form = forms.MadsonicForm(request.POST,
        instance=madsonic,
        jail_path=jail_path)
    if form.is_valid():
        form.save()

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

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

    return JsonResponse(request, form=form)
示例#4
0
def edit(request, plugin_id):
    (madsonic_key, madsonic_secret) = utils.get_madsonic_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=madsonic_key, secret=madsonic_secret)

    """
    Get the Madsonic object
    If it does not exist create a new entry
    """
    try:
        madsonic = models.Madsonic.objects.order_by('-id')[0]
    except IndexError:
        madsonic = models.Madsonic.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 madsonic.madsonic_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.MadsonicForm(instance=madsonic, jail_path=jail_path)
        return render(request, "edit.html", {
            'form': form,
            'ipv4': jail_ipv4,
            'scheme': scheme,
            'port': madsonic.madsonic_port,
            'webroot': madsonic.madsonic_context_path
        })

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

    form = forms.MadsonicForm(request.POST, instance=madsonic, jail_path=jail_path)
    if form.is_valid():
        form.save()

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

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

    return JsonResponse(request, form=form)
示例#5
0
def start(request, plugin_id):
    (madsonic_key, madsonic_secret) = utils.get_madsonic_oauth_creds()

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

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

    cmd = "%s onestart" % utils.madsonic_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')
示例#6
0
def start(request, plugin_id):
    (madsonic_key,
    madsonic_secret) = utils.get_madsonic_oauth_creds()

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

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

    cmd = "%s onestart" % utils.madsonic_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')