Пример #1
0
def index(request):
    context = additional_context(request)
    if request.user.is_authenticated():

        ### delete job form start
        job_delete_form = JobDeleteForm(request.POST or None)
        if job_delete_form.is_valid():
            result = job_delete_form.rest_save(username=request.user.username)
            if result:
                messages.add_message(request, messages.SUCCESS, _(u'Backup was successfully deleted.'))
            else:
                messages.add_message(request, messages.ERROR, _(u'Backup couldn\'t be deleted.'))
        context['job_delete_form'] = job_delete_form

        rest_jobs = RestJobs(username=request.user.username)
        jobs = rest_jobs.get_all()
        #### delete job form end

        if jobs and 'errorType' in jobs:
            if jobs['errorType'] == 'org.backmeup.model.exceptions.UnknownUserException':
                logout(request)
                redirect('index')
            else:
                messages.error(request, _(jobs['errorMessage']))
                context['needs_email_validation'] = True
        else:
            rest_datasource_profile = RestDatasourceProfile(username=request.user.username)
            datasource_profiles = rest_datasource_profile.get_all()

            rest_datasink_profile = RestDatasinkProfile(username=request.user.username)
            datasink_profiles = rest_datasink_profile.get_all()

            for job in jobs:
                # need to cut of first 3 numbers to get valid unix timestamp
                if 'createDate' in job:
                    job['createDate'] = datetime.datetime.fromtimestamp(job['createDate']/1000)
                if 'startDate' in job:
                    job['startDate'] = datetime.datetime.fromtimestamp(job['startDate']/1000)
                if 'lastBackup' in job:
                    job['lastBackup'] = datetime.datetime.fromtimestamp(job['lastBackup']/1000)
                if 'nextBackup' in job:
                    job['nextBackup'] = datetime.datetime.fromtimestamp(job['nextBackup']/1000)
                if 'lastSuccessful' in job:
                    job['lastSuccessful'] = datetime.datetime.fromtimestamp(job['lastSuccessful']/1000)
                
                job['datasink']['title'] = get_sink_title(datasink_profiles, job['datasink']['datasinkId'])
                #job['datasources'] = []
                for datasource in job['datasources']:
                    datasource['title'] = get_source_title(datasource_profiles, datasource['datasourceId'])
            context['jobs'] = jobs

    return render_to_response(
        "www/index.html",
        context,
        context_instance=RequestContext(request))
Пример #2
0
def job_status(request, job_id):
	rest_jobs = RestJobs(username=request.user.username)
	job_status = rest_jobs.get_job_status(job_id=job_id)
	jobs = rest_jobs.get_all()
	job = get_job(jobs, job_id=job_id)
	response_data={}
	if job_status['backupStatus'][0]['type']=="info":
		response_data['status']=job['status']
	else:
		response_data['status']=job_status['backupStatus'][0]['type']
	return HttpResponse(json.dumps(response_data), content_type="application/json")
Пример #3
0
 def rest_save(self):
     source_options = []
     actions = []
     
     data = {}
     
     for key in self.cleaned_data:
         
         if key.startswith('datasource_options_value_') and self.cleaned_data[key]:
             source_options.append(self.cleaned_data[key.replace('_value_', '_key_')])
         
         if key.startswith('actions_value_') and self.cleaned_data[key]:
             if '_option_' in key:
                 action_key = self.cleaned_data[key.split('_option_')[0].replace('_value_', '_key_')]
                 
                 option_key = action_key + '.' + self.cleaned_data[key.replace('_value_', '_key_')]
                 
                 option_value = self.cleaned_data[key]
                 data[option_key] = option_value
             else:
                 value = self.cleaned_data[key.replace('_value_', '_key_')]
                 actions.append(value)
                 if value == 'org.backmeup.encryption':
                     actions.append('org.backmeup.filesplitting')
     
     rest_jobs = RestJobs(username=self.extra_data['username'])
     
     data["keyRing"] = self.extra_data['key_ring']
     data['timeExpression'] = self.cleaned_data['time_expression']
     data['sourceProfiles'] = self.extra_data['datasource_profile_id']
     data['sinkProfileId'] = self.extra_data['datasink_profile_id']
     data['jobTitle'] = self.cleaned_data['title']
     data['actions'] = actions
     
     for item in source_options:
         params_key = str(data['sourceProfiles']) + "." + item
         data[params_key] = "true"
     
     job_result = rest_jobs.post(data=data)
     
     return job_result
Пример #4
0
def job_log(request, job_id):
    rest_jobs = RestJobs(username=request.user.username)
    job_status = rest_jobs.get_job_status(job_id=job_id)

    rest_jobs = RestJobs(username=request.user.username)
    jobs = rest_jobs.get_all()

    job = get_job(jobs, job_id=job_id)

    rest_datasource_profile = RestDatasourceProfile(username=request.user.username)
    datasource_profiles = rest_datasource_profile.get_all()

    rest_datasink_profile = RestDatasinkProfile(username=request.user.username)
    datasink_profiles = rest_datasink_profile.get_all()

    job['datasink']['title'] = get_sink_title(datasink_profiles, job['datasink']['datasinkId'])
    #job['datasources'] = []
    for datasource in job['datasources']:
        datasource['title'] = get_source_title(datasource_profiles, datasource['datasourceId'])
    log=job_status['backupStatus']
    for l in log:
	l['message']=l['message'].encode("utf-8")
	if 'timeStamp' in l:
		l['timeStamp'] = datetime.datetime.fromtimestamp(int(l['timeStamp'])/1000)
    context = {
        'job': job,
        'log': log,
    }
    try:
        context['current_status'] = job_status['backupStatus'][0]['type']
    except:
        pass

    return render_to_response(
        "www/job_log.html",
        context,
        context_instance=RequestContext(request))
Пример #5
0
 def rest_save(self, username):
     rest_jobs = RestJobs(username=username)
     return rest_jobs.delete(job_id=self.cleaned_data['job_id'])
Пример #6
0
def job_edit(request, job_id):
    rest_jobs = RestJobs(username=request.user.username)
    job = rest_jobs.get(job_id=job_id)
    
    datasource_profile_id = job['sourceProfiles'][0]['id']
    datasink_profile_id = job['sinkProfileId']
    
    rest_datasource_profile = RestDatasourceProfile(username=request.user.username)
    datasource_profile_options = rest_datasource_profile.options(profile_id=datasource_profile_id, 
        data={'keyRing': request.session['key_ring']})['sourceOptions']
    
    rest_actions = RestAction()
    actions = rest_actions.get_all()
    
    for action in actions:
        action['options'] = rest_actions.options(action_id=action['actionId'])
        action['checked'] = False
        
        for job_action in job['actions']:
            if job_action['id'] == action['actionId']:
                action['checked'] = True
    
    extra_data = {
        'job': job,
        'datasource_profile_options': datasource_profile_options,
        'actions': actions,
    }
    
    form = JobEditForm(request.POST or None, extra_data=extra_data)
    
    if form.is_valid():
        new_source_options = []
        new_actions = []

        for key in form.cleaned_data:

            if key.startswith('datasource_options_value_') and form.cleaned_data[key]:
                new_source_options.append(form.cleaned_data[key.replace('_value_', '_key_')])

            if key.startswith('actions_value_') and form.cleaned_data[key]:
                value = form.cleaned_data[key.replace('_value_', '_key_')]
                new_actions.append(value)

        rest_jobs = RestJobs(username=request.user.username)
        data = {
            "keyRing": request.session['key_ring'],
            'timeExpression': form.cleaned_data['time_expression'],
            'sourceProfiles': datasource_profile_id,
            'sinkProfileId': datasink_profile_id,
            'jobTitle': form.cleaned_data['title'],
            'actions': new_actions,
        }
        for item in new_source_options:
            params_key = str(data['sourceProfiles']) + "." + item
            data[params_key] = "true"
        job_result = rest_jobs.put(job_id=job_id ,data=data)
        if hasError(job_result):
            messages.add_message(request, messages.ERROR, getErrorMsg(job_result))
        else:
            return redirect('index')
    
    return render_to_response("www/job_edit.html", {
        'form': form,
    }, context_instance=RequestContext(request))