Ejemplo n.º 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.
    """

    (sickbeard_key, sickbeard_secret) = utils.get_sickbeard_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=sickbeard_key, secret=sickbeard_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 = "SickBeard"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "SickBeard (%d)" % number
        except:
            pass

    plugin = {
        "name": name,
        "append_to": "plugins",
        "icon": reverse("treemenu_icon", kwargs={"plugin_id": plugin_id}),
        "type": "pluginsfcgi",
        "url": reverse("sickbeard_edit", kwargs={"plugin_id": plugin_id}),
        "kwargs": {"plugin_name": "sickbeard", "plugin_id": plugin_id},
    }

    return HttpResponse(json.dumps([plugin]), content_type="application/json")
Ejemplo n.º 2
0
def stop(request, plugin_id):
    (sickbeard_key, sickbeard_secret) = utils.get_sickbeard_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=sickbeard_key, secret=sickbeard_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:
        sickbeard = models.SickBeard.objects.order_by("-id")[0]
        sickbeard.enable = False
        sickbeard.save()
    except IndexError:
        sickbeard = models.SickBeard.objects.create(enable=False)

    try:
        form = forms.SickBeardForm(sickbeard.__dict__, instance=sickbeard, jail_path=jail_path)
        form.is_valid()
        form.save()
    except ValueError:
        pass

    cmd = "%s onestop" % utils.sickbeard_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")
Ejemplo n.º 3
0
def edit(request, plugin_id):
    from syslog import *
    (sickbeard_key, sickbeard_secret) = utils.get_sickbeard_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=sickbeard_key, secret=sickbeard_secret)
    """
    Get the Sickbeard object
    If it does not exist create a new entry
    """
    try:
        sickbeard = models.Sickbeard.objects.order_by('-id')[0]
    except IndexError:
        sickbeard = models.Sickbeard.objects.create()

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

    if request.method == "GET":
        form = forms.SickbeardForm(instance=sickbeard, jail_path=jail_path)
        return render(request, "edit.html", {
            'form': form,
        })

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

    form = forms.SickbeardForm(request.POST,
                               instance=sickbeard,
                               jail_path=jail_path)
    if form.is_valid():
        form.save()

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

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

    return JsonResponse(request, form=form)
Ejemplo n.º 4
0
def open_view(request, plugin_id):
    (sickbeard_key,
    sickbeard_secret) = utils.get_sickbeard_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=sickbeard_key,
        secret=sickbeard_secret)
    server = jsonrpclib.Server(url, transport=trans)
    jail = json.loads(server.plugins.jail.info(plugin_id))[0]
    jail_ipv4 = jail['fields']['jail_ipv4'].split('/', 1)[0]

    return render(request, "open.html", {
        'ipv4': jail_ipv4,
    })
Ejemplo n.º 5
0
def start(request, plugin_id):
    (sickbeard_key, sickbeard_secret) = utils.get_sickbeard_oauth_creds()

    url = utils.get_rpc_url(request)

    trans = OAuthTransport(url, key=sickbeard_key, secret=sickbeard_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:
        sickbeard = models.Sickbeard.objects.order_by('-id')[0]
        sickbeard.enable = True
        sickbeard.save()
    except IndexError:
        sickbeard = models.Sickbeard.objects.create(enable=True)

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

    cmd = "%s onestart" % utils.sickbeard_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')
Ejemplo n.º 6
0
def edit(request, plugin_id):
    from syslog import *

    (sickbeard_key, sickbeard_secret) = utils.get_sickbeard_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=sickbeard_key, secret=sickbeard_secret)

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

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

    if request.method == "GET":
        form = forms.SickbeardForm(instance=sickbeard, jail_path=jail_path)
        return render(request, "edit.html", {"form": form})

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

    form = forms.SickbeardForm(request.POST, instance=sickbeard, jail_path=jail_path)
    if form.is_valid():
        form.save()

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

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

    return JsonResponse(request, form=form)
Ejemplo n.º 7
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.
    """

    (sickbeard_key, sickbeard_secret) = utils.get_sickbeard_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=sickbeard_key, secret=sickbeard_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 = "sickbeard"

    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "sickbeard (%d)" % number
        except:
            pass

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

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

    (sickbeard_key,
    sickbeard_secret) = utils.get_sickbeard_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=sickbeard_key,
        secret=sickbeard_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 = "SickBeard"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "SickBeard (%d)" % number
        except:
            pass

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

    return HttpResponse(json.dumps([plugin]), content_type='application/json')