Exemplo n.º 1
0
def edit(request, plugin_id):
    (plexmediaserver_key,
    plexmediaserver_secret) = utils.get_plexmediaserver_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=plexmediaserver_key,
        secret=plexmediaserver_secret)

    """
    Get the PlexMediaServer object
    If it does not exist create a new entry
    """
    try:
        plexmediaserver = models.PlexMediaServer.objects.order_by('-id')[0]
    except IndexError:
        plexmediaserver = models.PlexMediaServer.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]
        auth = server.plugins.is_authenticated(
            request.COOKIES.get("sessionid", "")
            )
        assert auth
    except Exception as e:
        raise

    if request.method == "GET":
        form = forms.PlexMediaServerForm(instance=plexmediaserver,
            jail_path=jail_path)
        return render(request, "edit.html", {
            'form': form,
            'ipv4': jail_ipv4
        })

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

    form = forms.PlexMediaServerForm(request.POST,
        instance=plexmediaserver,
        jail_path=jail_path)
    if form.is_valid():
        cmd = "%s onestop" % utils.plexmediaserver_control
        pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
            shell=True, close_fds=True)
        form.save()

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

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

    return JsonResponse(request, form=form)
Exemplo n.º 2
0
def start(request, plugin_id):
    (plexmediaserver_key,
     plexmediaserver_secret) = utils.get_plexmediaserver_oauth_creds()

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

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

    cmd = "%s onestart" % utils.plexmediaserver_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.º 3
0
def start(request, plugin_id):
    (plexmediaserver_key,
    plexmediaserver_secret) = utils.get_plexmediaserver_oauth_creds()

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

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

    cmd = "%s onestart" % utils.plexmediaserver_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.º 4
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.
    """

    (plexmediaserver_key,
     plexmediaserver_secret) = utils.get_plexmediaserver_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url,
                           key=plexmediaserver_key,
                           secret=plexmediaserver_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 = "PlexMediaServer-PlexPass"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "PlexMediaServer-PlexPass (%d)" % number
        except:
            pass

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

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

    (plexmediaserver_key,
    plexmediaserver_secret) = utils.get_plexmediaserver_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=plexmediaserver_key,
        secret=plexmediaserver_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 = "PlexMediaServer"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "PlexMediaServer (%d)" % number
        except:
            pass

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

    return HttpResponse(json.dumps([plugin]), content_type='application/json')
Exemplo n.º 6
0
def edit(request, plugin_id):
    (plexmediaserver_key,
    plexmediaserver_secret) = utils.get_plexmediaserver_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=plexmediaserver_key,
        secret=plexmediaserver_secret)

    """
    Get the PlexMediaServer object
    If it does not exist create a new entry
    """
    try:
        plexmediaserver = models.PlexMediaServer.objects.order_by('-id')[0]
    except IndexError:
        plexmediaserver = models.PlexMediaServer.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]
        auth = server.plugins.is_authenticated(
            request.COOKIES.get("sessionid", "")
            )
        assert auth
    except Exception as e:
        raise

    if request.method == "GET":
        form = forms.PlexMediaServerForm(instance=plexmediaserver,
            jail_path=jail_path)
        return render(request, "edit.html", {
            'form': form,
            'ipv4': jail_ipv4
        })

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

    form = forms.PlexMediaServerForm(request.POST,
        instance=plexmediaserver,
        jail_path=jail_path)
    if form.is_valid():
        form.save()

        cmd = "%s restart" % utils.plexmediaserver_control
        pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
            shell=True, close_fds=True)
        out = pipe.communicate()[0]

        plexmediaserver = models.PlexMediaServer.objects.order_by('-id')[0]
        if plexmediaserver.disable_remote_security and \
            os.path.exists(PLEXMEDIASERVER_PREFERENCES_XML):
            preferences = tempfile.mktemp(dir='/tmp/')

            tree = ET.parse(PLEXMEDIASERVER_PREFERENCES_XML)
            root = tree.getroot()

            if 'disableRemoteSecurity' not in root.attrib:
                root.attrib['disableRemoteSecurity'] = "1"

            tree.write(preferences)
            if os.path.exists(preferences):  
                cmd = "/bin/mv '%s' '%s'" % (preferences, PLEXMEDIASERVER_PREFERENCES_XML)
                pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
                    shell=True, close_fds=True)
                out = pipe.communicate()[0]

                cmd = "chmod 600 '%s'" % PLEXMEDIASERVER_PREFERENCES_XML
                pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
                    shell=True, close_fds=True)
                out = pipe.communicate()[0]

                cmd = "chown plex:plex '%s'" % PLEXMEDIASERVER_PREFERENCES_XML
                pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
                    shell=True, close_fds=True)
                out = pipe.communicate()[0]

                cmd = "%s restart" % utils.plexmediaserver_control
                pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE,
                    shell=True, close_fds=True)
                out = pipe.communicate()[0]

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

    return JsonResponse(request, form=form)
Exemplo n.º 7
0
def edit(request, plugin_id):
    (plexmediaserver_key,
     plexmediaserver_secret) = utils.get_plexmediaserver_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url,
                           key=plexmediaserver_key,
                           secret=plexmediaserver_secret)
    """
    Get the PlexMediaServer object
    If it does not exist create a new entry
    """
    try:
        plexmediaserver = models.PlexMediaServer.objects.order_by('-id')[0]
    except IndexError:
        plexmediaserver = models.PlexMediaServer.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]
        auth = server.plugins.is_authenticated(
            request.COOKIES.get("sessionid", ""))
        assert auth
    except Exception as e:
        raise

    if request.method == "GET":
        form = forms.PlexMediaServerForm(instance=plexmediaserver,
                                         jail_path=jail_path)
        return render(request, "edit.html", {'form': form, 'ipv4': jail_ipv4})

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

    form = forms.PlexMediaServerForm(request.POST,
                                     instance=plexmediaserver,
                                     jail_path=jail_path)
    if form.is_valid():
        form.save()

        cmd = "%s restart" % utils.plexmediaserver_control
        pipe = Popen(cmd,
                     stdin=PIPE,
                     stdout=PIPE,
                     stderr=PIPE,
                     shell=True,
                     close_fds=True)
        out = pipe.communicate()[0]

        plexmediaserver = models.PlexMediaServer.objects.order_by('-id')[0]
        if plexmediaserver.disable_remote_security and \
            os.path.exists(PLEXMEDIASERVER_PREFERENCES_XML):
            preferences = tempfile.mktemp(dir='/tmp/')

            tree = ET.parse(PLEXMEDIASERVER_PREFERENCES_XML)
            root = tree.getroot()

            if 'disableRemoteSecurity' not in root.attrib:
                root.attrib['disableRemoteSecurity'] = "1"

            tree.write(preferences)
            if os.path.exists(preferences):
                cmd = "/bin/mv '%s' '%s'" % (preferences,
                                             PLEXMEDIASERVER_PREFERENCES_XML)
                pipe = Popen(cmd,
                             stdin=PIPE,
                             stdout=PIPE,
                             stderr=PIPE,
                             shell=True,
                             close_fds=True)
                out = pipe.communicate()[0]

                cmd = "chmod 600 '%s'" % PLEXMEDIASERVER_PREFERENCES_XML
                pipe = Popen(cmd,
                             stdin=PIPE,
                             stdout=PIPE,
                             stderr=PIPE,
                             shell=True,
                             close_fds=True)
                out = pipe.communicate()[0]

                cmd = "chown plex:plex '%s'" % PLEXMEDIASERVER_PREFERENCES_XML
                pipe = Popen(cmd,
                             stdin=PIPE,
                             stdout=PIPE,
                             stderr=PIPE,
                             shell=True,
                             close_fds=True)
                out = pipe.communicate()[0]

                cmd = "%s restart" % utils.plexmediaserver_control
                pipe = Popen(cmd,
                             stdin=PIPE,
                             stdout=PIPE,
                             stderr=PIPE,
                             shell=True,
                             close_fds=True)
                out = pipe.communicate()[0]

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

    return JsonResponse(request, form=form)