Example #1
0
def start(request, plugin_id):
    (elephantdrive_key, elephantdrive_secret) = utils.get_elephantdrive_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=elephantdrive_key, secret=elephantdrive_secret)

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

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

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

    cmd1 = "#!/bin/sh\n"
    cmd2 = "date >> /tmp/s3.log \n"
    cmd3 = "%s -c %s/.s3cfg ls  >>  /tmp/s3.log \n" % (utils.elephantdrive_bin_path,utils.elephantdrive_root_cfg)
    cmd4 = "date >> /tmp/s3.log \n"
    with open(utils.elephantdrive_script_file, 'w') as f:
        f.write(cmd1)
        f.write(cmd2)
        f.write(cmd3)
        f.write(cmd4)

    cmd = "chmod 777 %s " % utils.elephantdrive_script_file
    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')
Example #2
0
def stop(request, plugin_id):
    (elephantdrive_key,
     elephantdrive_secret) = utils.get_elephantdrive_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url,
                           key=elephantdrive_key,
                           secret=elephantdrive_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:
        elephantdrive = models.elephantdrive.objects.order_by('-id')[0]
        elephantdrive.enable = False
        elephantdrive.save()
    except IndexError:
        elephantdrive = models.elephantdrive.objects.create(enable=False)

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

    cmd = "%s onestop" % utils.elephantdrive_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')
Example #3
0
def stop(request, plugin_id):
    (elephantdrive_key, elephantdrive_secret) = utils.get_elephantdrive_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=elephantdrive_key, secret=elephantdrive_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:
        elephantdrive = models.elephantdrive.objects.order_by('-id')[0]
        elephantdrive.enable = False
        elephantdrive.save()
    except IndexError:
        elephantdrive = models.elephantdrive.objects.create(enable=False)

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


    cmd = "%s onestop" % utils.elephantdrive_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')
Example #4
0
def edit(request, plugin_id):
    (elephantdrive_key, elephantdrive_secret) = utils.get_elephantdrive_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url, key=elephantdrive_key, secret=elephantdrive_secret)

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

    if request.method == "GET":
        form = forms.elephantdriveForm(instance=elephantdrive, 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.elephantdriveForm(request.POST, instance=elephantdrive, jail_path=jail_path)
    if form.is_valid():
        form.save()

        if elephantdrive.gpg_path_enable :
            cmd1 = "#!/bin/sh\n"
            cmd2 = "date >> /tmp/s3.log \n"
            cmd3 = "%s -c %s/.s3cfg put --encrypt --progress --recursive /%s s3://%s  >>  /tmp/s3.log \n" % (utils.elephantdrive_bin_path,utils.elephantdrive_root_cfg,elephantdrive.source_dir,elephantdrive.dest_dir)
            cmd4 = "date >> /tmp/s3.log \n"
            with open(utils.elephantdrive_script_file, 'w') as f:
                f.write(cmd1)
                f.write(cmd2)
                f.write(cmd3)
                f.write(cmd4)
        else:
            cmd1 = "#!/bin/sh\n"
            cmd2 = "date >> /tmp/s3.log \n"
            cmd3 = "%s -c %s/.s3cfg sync --progress --recursive /%s s3://%s  >>  /tmp/s3.log \n" % (utils.elephantdrive_bin_path,utils.elephantdrive_root_cfg,elephantdrive.source_dir,elephantdrive.dest_dir)
            cmd4 = "date >> /tmp/s3.log \n"
            with open(utils.elephantdrive_script_file, 'w') as f:
               f.write(cmd1)
               f.write(cmd2)
               f.write(cmd3)
               f.write(cmd4)

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

        cmd = "%s onestart" % utils.elephantdrive_control
        pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)
        out = pipe.communicate()[0]
        return JsonResponse(request, error=False, message='elephantdrive started')

    return JsonResponse(request, form=form)
Example #5
0
def edit(request, plugin_id):
    (elephantdrive_key,
     elephantdrive_secret) = utils.get_elephantdrive_oauth_creds()
    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url,
                           key=elephantdrive_key,
                           secret=elephantdrive_secret)
    """
    Get the elephantdrive object
    If it does not exist create a new entry
    """
    try:
        elephantdrive = models.elephantdrive.objects.order_by('-id')[0]
    except IndexError:
        elephantdrive = models.elephantdrive.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", "test"))
        assert auth
    except Exception as e:
        raise

    if request.method == "GET":
        form = forms.elephantdriveForm(instance=elephantdrive,
                                       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.elephantdriveForm(request.POST,
                                   instance=elephantdrive,
                                   jail_path=jail_path)
    if form.is_valid():
        form.save()

        if elephantdrive.gpg_path_enable:
            cmd1 = "#!/bin/sh\n"
            cmd2 = "date >> /tmp/s3.log \n"
            cmd3 = "%s -c %s/.s3cfg put --encrypt --progress --recursive /%s s3://%s  >>  /tmp/s3.log \n" % (
                utils.elephantdrive_bin_path, utils.elephantdrive_root_cfg,
                elephantdrive.source_dir, elephantdrive.dest_dir)
            cmd4 = "date >> /tmp/s3.log \n"
            with open(utils.elephantdrive_script_file, 'w') as f:
                f.write(cmd1)
                f.write(cmd2)
                f.write(cmd3)
                f.write(cmd4)
        else:
            cmd1 = "#!/bin/sh\n"
            cmd2 = "date >> /tmp/s3.log \n"
            cmd3 = "%s -c %s/.s3cfg sync --progress --recursive /%s s3://%s  >>  /tmp/s3.log \n" % (
                utils.elephantdrive_bin_path, utils.elephantdrive_root_cfg,
                elephantdrive.source_dir, elephantdrive.dest_dir)
            cmd4 = "date >> /tmp/s3.log \n"
            with open(utils.elephantdrive_script_file, 'w') as f:
                f.write(cmd1)
                f.write(cmd2)
                f.write(cmd3)
                f.write(cmd4)

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

        cmd = "%s onestart" % utils.elephantdrive_control
        pipe = Popen(cmd,
                     stdin=PIPE,
                     stdout=PIPE,
                     stderr=PIPE,
                     shell=True,
                     close_fds=True)
        out = pipe.communicate()[0]
        return JsonResponse(request,
                            error=False,
                            message='elephantdrive started')

    return JsonResponse(request, form=form)
Example #6
0
def start(request, plugin_id):
    (elephantdrive_key,
     elephantdrive_secret) = utils.get_elephantdrive_oauth_creds()

    url = utils.get_rpc_url(request)
    trans = OAuthTransport(url,
                           key=elephantdrive_key,
                           secret=elephantdrive_secret)

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

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

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

    cmd1 = "#!/bin/sh\n"
    cmd2 = "date >> /tmp/s3.log \n"
    cmd3 = "%s -c %s/.s3cfg ls  >>  /tmp/s3.log \n" % (
        utils.elephantdrive_bin_path, utils.elephantdrive_root_cfg)
    cmd4 = "date >> /tmp/s3.log \n"
    with open(utils.elephantdrive_script_file, 'w') as f:
        f.write(cmd1)
        f.write(cmd2)
        f.write(cmd3)
        f.write(cmd4)

    cmd = "chmod 777 %s " % utils.elephantdrive_script_file
    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')