Пример #1
0
def open_view(request, plugin_id):
    (crashplan_key,
    crashplan_secret) = utils.get_crashplan_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key,
        secret=crashplan_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:
        crashplan = models.Crashplan.objects.order_by('-id')[0]
        crashplan.save()
    except IndexError:
        crashplan = models.Crashplan.objects.create()

    if crashplan.lic_accepted is False:
        return license(request, plugin_id, obj=crashplan)

    return render(request, "open.html", {
        'crashplan': crashplan,
        'kldload': _linux_loaded(server, plugin_id),
    })
Пример #2
0
def start(request, plugin_id):
    (crashplan_key, crashplan_secret) = utils.get_crashplan_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key, secret=crashplan_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

    kldload = _linux_loaded(server, plugin_id)

    if kldload is False:
        return HttpResponse(simplejson.dumps({
            'error':
            True,
            'message':
            'Add linux_load="YES" to System->Tunables and reboot',
        }),
                            content_type='application/json')

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

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

    cmd = "%s onestart" % utils.crashplan_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')
Пример #3
0
def start(request, plugin_id):
    (crashplan_key,
    crashplan_secret) = utils.get_crashplan_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key,
        secret=crashplan_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

    kldload = _linux_loaded(server, plugin_id)

    if kldload is False:
        return HttpResponse(simplejson.dumps({
            'error': True,
            'message': 'Add linux_load="YES" to System->Tunables and reboot',
        }), content_type='application/json')

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

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

    cmd = "%s onestart" % utils.crashplan_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')
Пример #4
0
def edit(request, plugin_id):
    (crashplan_key, crashplan_secret) = utils.get_crashplan_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key, secret=crashplan_secret)
    """
    Get the Crashplan object
    If it does not exist create a new entry
    """
    try:
        crashplan = models.Crashplan.objects.order_by('-id')[0]
    except IndexError:
        crashplan = models.Crashplan.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.CrashplanForm(instance=crashplan, 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.CrashplanForm(request.POST,
                               instance=crashplan,
                               jail_path=jail_path)
    if form.is_valid():
        form.save()

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

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

    return JsonResponse(request, form=form)
Пример #5
0
def edit(request, plugin_id):
    (crashplan_key,
    crashplan_secret) = utils.get_crashplan_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key,
        secret=crashplan_secret)

    """
    Get the Crashplan object
    If it does not exist create a new entry
    """
    try:
        crashplan = models.Crashplan.objects.order_by('-id')[0]
    except IndexError:
        crashplan = models.Crashplan.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.CrashplanForm(instance=crashplan,
            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.CrashplanForm(request.POST,
        instance=crashplan,
        jail_path=jail_path)
    if form.is_valid():
        form.save()

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

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

    return JsonResponse(request, form=form)
Пример #6
0
def stop(request, plugin_id):
    (crashplan_key, crashplan_secret) = utils.get_crashplan_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key, secret=crashplan_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:
        crashplan = models.Crashplan.objects.order_by('-id')[0]
        crashplan.enable = False
        crashplan.save()
    except IndexError:
        crashplan = models.Crashplan.objects.create(enable=False)

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

    cmd = "%s onestop" % utils.crashplan_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')
Пример #7
0
def stop(request, plugin_id):
    (crashplan_key,
    crashplan_secret) = utils.get_crashplan_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key,
        secret=crashplan_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:
        crashplan = models.Crashplan.objects.order_by('-id')[0]
        crashplan.enable = False
        crashplan.save()
    except IndexError:
        crashplan = models.Crashplan.objects.create(enable=False)

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

    cmd = "%s onestop" % utils.crashplan_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')
Пример #8
0
def open_view(request, plugin_id):
    (crashplan_key, crashplan_secret) = utils.get_crashplan_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key, secret=crashplan_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:
        crashplan = models.Crashplan.objects.order_by('-id')[0]
        crashplan.save()
    except IndexError:
        crashplan = models.Crashplan.objects.create()

    if crashplan.lic_accepted is False:
        return license(request, plugin_id, obj=crashplan)

    return render(request, "open.html", {
        'crashplan': crashplan,
        'kldload': _linux_loaded(server, plugin_id),
    })
Пример #9
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.
    """

    (crashplan_key, crashplan_secret) = utils.get_crashplan_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key, secret=crashplan_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 = "CrashPlan"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "Crashplan (%d)" % number
        except:
            pass

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

    return HttpResponse(json.dumps([plugin]), content_type='application/json')
Пример #10
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.
    """

    (crashplan_key,
    crashplan_secret) = utils.get_crashplan_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=crashplan_key,
        secret=crashplan_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 = "CrashPlan"
    if len(number) == 2:
        try:
            number = int(number)
            if number > 1:
                name = "Crashplan (%d)" % number
        except:
            pass

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

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