Пример #1
0
def stop(request, plugin_id):
    firefly_key, firefly_secret = utils.get_firefly_oauth_creds()

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

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

    cmd = "%s onestop" % utils.firefly_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
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.
    """

    firefly_key, firefly_secret = utils.get_firefly_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=firefly_key, secret=firefly_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 = "Firefly"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "Firefly (%d)" % number
        except:
            pass

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

    return HttpResponse(json.dumps([plugin]), content_type='application/json')
Пример #3
0
def start(request, plugin_id):
    firefly_key, firefly_secret = utils.get_firefly_oauth_creds()

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

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

    cmd = "%s onestart" % utils.firefly_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,
    }))
Пример #4
0
def edit(request, plugin_id):
    firefly_key, firefly_secret = utils.get_firefly_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=firefly_key, secret=firefly_secret)
    """
    Get the Firefly object
    If it does not exist create a new entry
    """
    try:
        firefly = models.Firefly.objects.order_by('-id')[0]
    except IndexError:
        firefly = models.Firefly.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, e:
        raise
Пример #5
0
def edit(request, plugin_id):
    firefly_key, firefly_secret = utils.get_firefly_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=firefly_key,
        secret=firefly_secret)

    """
    Get the Firefly object
    If it does not exist create a new entry
    """
    try:
        firefly = models.Firefly.objects.order_by('-id')[0]
    except IndexError:
        firefly = models.Firefly.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, e:
        raise
Пример #6
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.
    """

    firefly_key, firefly_secret = utils.get_firefly_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=firefly_key, secret=firefly_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 = "Firefly"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "Firefly (%d)" % number
        except:
            pass

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

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