Ejemplo n.º 1
0
def index(request):
    user = request.user
    profile = Profile.objects.get(user=user)
    pcol1 = profile.dashboardcol1
    if pcol1 is not None and pcol1 != '':
        col1 = pcol1.split(',')
    else:
        col1 = []
    pcol2 = profile.dashboardcol2
    if pcol2 is not None and pcol2 != '':
        col2 = pcol2.split(',')
    else:
        col2 = []
    section1 = []
    for w in col1:
        widget = Dashboardwidgets.objects.get(user=user, widget__widgetid=w)
        if widget.enabled:
            section1.append(widget)
    section2 = []
    for w in col2:
        widget = Dashboardwidgets.objects.get(user=user, widget__widgetid=w)
        if widget.enabled:
            section2.append(widget)
    context = {'contentheader': 'Dashboard', 'contentheadersmall': 'Control Panel',
               'Section1': section1, 'Section2': section2}
    updateMenuNumbers(request, context)
    updateservicestatus(context)
    # messages.info(request, 'Three credits <a href="%s">remain</a> in your account.' % reverse('home'),
    #               extra_tags='AAA')
    # messages.error(request, 'It is a standard error.', extra_tags='ERROR')
    # messages.warning(request, 'about something.', extra_tags='Warning')
    return render(request, 'pages/index.html', context)
Ejemplo n.º 2
0
def addalias(request):
    departments = getUserDepartmentsList(request)
    st = getDIRStorageNamesnAlias(request)
    storages = ()
    for s in st:
        storages += ((s, s),)
    ip = detectipall()
    ipall = [(a, a) for a in ip]
    if request.method == 'GET':
        form = StorageAliasForm(storages=storages, storageips=ipall, departments=departments)
        form.fields['address'].disabled = True
        context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Add', 'Alias'], 'form': form}
        updateMenuNumbers(request, context)
        return render(request, 'storage/addalias.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            form = StorageAliasForm(data=request.POST, storages=storages, storageips=ipall, departments=departments)
            if form.is_valid():
                name = form.cleaned_data['name'].encode('ascii', 'ignore')
                descr = form.cleaned_data['descr']
                storage = form.cleaned_data['storagelist']
                storageip = form.cleaned_data['storageip']
                depart = form.cleaned_data['departments']
                # create a Storage resource
                with transaction.atomic():
                    createStorageAlias(request, storname=name, descr=descr, storage=storage, address=storageip,
                                       department=depart)
                directorreload()
                # response['Location'] += '?n=1'
                return redirect('storageinfo', name)
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('storagedefined')
Ejemplo n.º 3
0
def info(request, name):
    """ Storage info and status """
    storageres = getDIRStorageinfo(name=name)
    if storageres is None:
        raise Http404()
    storage = extractstorageparams(storageres)
    departs = storage.get('Departments')
    dlist = []
    if departs is not None:
        for d in departs:
            dlist.append(getDepartment(d))
    storage.update({'Departments': dlist})
    storagealert = request.GET.get('n', 0)
    storagealertheader = "Restart required!"
    try:
        if int(storagealert) == 1:
            # new storage added
            storagealertheader = "New Storage added!"
        if int(storagealert) == 2:
            # new storage added
            storagealertheader = "Storage hardware configuration changed!"
    except (ValueError, TypeError):
        storagealert = None
    context = {'contentheader': 'Storage', 'apppath': ['Storage', 'Info', name], 'Storage': storage,
               'storagealert': storagealert, 'storagealertheader': storagealertheader, 'storagestatusdisplay': 1}
    updateMenuNumbers(request, context)
    return render(request, 'storage/storage.html', context)
Ejemplo n.º 4
0
def editrole(request, rolename):
    group = get_object_or_404(Group, name=rolename)
    if group.roles.internal:
        raise Http404
    data = makeinitailadata(group)
    if request.method == 'GET':
        form = RolesForm(initial=data)
        context = {'contentheader': 'Roles', 'apppath': ['Roles', 'Edit', rolename], 'form': form,
                   'rolestatusdisplay': 1, 'Role': group.roles}
        updateMenuNumbers(request, context)
        return render(request, 'roles/edit.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            form = RolesForm(data=request.POST, initial=data)
            if form.is_valid():
                if form.has_changed():
                    with transaction.atomic():
                        if 'name' in form.changed_data:
                            rname = truncateunicodestr(form.cleaned_data['name'], 80)
                            group.name = rname
                        if 'descr' in form.changed_data:
                            group.roles.description = form.cleaned_data['descr']
                        if 'color' in form.changed_data:
                            group.roles.color = form.cleaned_data['color']
                        group.save()
                        log = Log(jobid_id=0, logtext='Role modified: %s by %s' % (rolename, request.user.username))
                        log.save()
                    messages.success(request, 'Role "%s" updated.' % group.name, extra_tags="Success")
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('rolesdefined')
Ejemplo n.º 5
0
def info(request, name):
    """ Department details info """
    department = get_object_or_404(Departments, shortname=name)
    labelcolor = LABELCOLORSDICT.get(department.color, 'bg-blue')
    members = Profile.objects.filter(departments=department)
    memberlist = []
    for m in members:
        memberlist.append(m.user.username)
    userlist = getUserListfiltered(memberlist)
    form = DepartmentAddmemberForm(users=userlist)
    context = {
        'contentheader':
        'Department',
        'contentheadersmall':
        'Info',
        'apppath': ['Departments', 'Info', name],
        'departmentdisplay':
        1,
        'Department':
        department,
        'form':
        form,
        'membersnr':
        members.count(),
        'labelcolor':
        labelcolor,
        'deldepart':
        getDepartmentssnr(request) > 1
        or (request.user.is_superuser and request.user.is_staff)
    }
    updateMenuNumbers(request, context)
    return render(request, 'departments/info.html', context)
Ejemplo n.º 6
0
def volumes(request):
    context = {
        'contentheader': 'Volumes list',
        'apppath': ['Storage', 'Volumes']
    }
    updateMenuNumbers(request, context)
    return render(request, 'storage/volumes.html', context)
Ejemplo n.º 7
0
def addalias(request):
    departments = getUserDepartmentsList(request)
    st = getDIRStorageNamesnAlias(request)
    storages = ()
    for s in st:
        storages += ((s, s),)
    ip = detectipall()
    ipall = [(a, a) for a in ip]
    if request.method == 'GET':
        form = StorageAliasForm(storages=storages, storageips=ipall, departments=departments)
        form.fields['address'].disabled = True
        context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Add', 'Alias'], 'form': form}
        updateMenuNumbers(request, context)
        return render(request, 'storage/addalias.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            form = StorageAliasForm(data=request.POST, storages=storages, storageips=ipall, departments=departments)
            if form.is_valid():
                name = form.cleaned_data['name'].encode('ascii', 'ignore')
                descr = form.cleaned_data['descr']
                storage = form.cleaned_data['storagelist']
                storageip = form.cleaned_data['storageip']
                depart = form.cleaned_data['departments']
                # create a Storage resource
                with transaction.atomic():
                    createStorageAlias(request, storname=name, descr=descr, storage=storage, address=storageip,
                                       department=depart)
                directorreload()
                # response['Location'] += '?n=1'
                return redirect('storageinfo', name)
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('storagedefined')
Ejemplo n.º 8
0
def jobidfiles(request, jobid=None):
    if jobid is None:
        raise Http404()
    jobp = getJobidinfo(request, jobid)
    if jobp is None:
        raise Http404()
    jobids = bvfs_get_jobids(jobid)
    if jobids is not None:
        jobidlist = [int(j) for j in jobids.split(',')]
        jobidsparams = []
        for j in jobidlist:
            jj = Job.objects.get(jobid=j)
            jobidsparams.append({
                'jobid': j,
                'level': jj.level,
            })
    else:
        jobids = 'unavl'
        jobidsparams = []
    cl = getDIRClientsNames(request)
    clients = ()
    for c in cl:
        clients += ((c, c),)
    client = jobp['Client']
    form = RestoreFilesForm(clients=clients, initial={'client': client, 'restoreclient': client})
    context = {'contentheader': 'Restore', 'contentheadersmall': 'JobId: ' + str(jobp['JobId']),
               'apppath': ['Restore', 'JobId', jobp['JobId']], 'Job': jobp, 'Jobidsparams': jobidsparams,
               'Jobids': jobids, 'form': form, 'JobTypeURL': reverse('restoretree', args=[jobids, 'root']),
               'JobTypeQueryURL': reverse('restoretree_rel', args=[jobids]),
               'JobTypePrepareURL': reverse('restoreprepare', args=[jobids])}
    updateMenuNumbers(request, context)
    return render(request, 'restore/jobidfiles.html', context)
Ejemplo n.º 9
0
def userprofile(request):
    user = request.user
    profile = Profile.objects.get(user=user)
    departments = profile.departments.all()
    dashboard = Dashboardwidgets.objects.filter(user=user).order_by('widget')
    if not dashboard.count():
        # no widgets in profile populate default
        widgets = Widgets.objects.all()
        for w in widgets:
            dbwidget = Dashboardwidgets(user=user, widget=w)
            dbwidget.enabled = False
            dbwidget.save()
        dashboard = Dashboardwidgets.objects.filter(user=user)
    clientlist = getUserClients(request)
    clients = []
    for clientres in clientlist:
        clientparams = getDIRClientparams(clientres)
        clientparams = extractclientparams(clientparams)
        clients.append({
            'Name': clientparams['Name'],
            'OS': clientparams['OS'],
        })
    context = {'User': user, 'Profile': profile, 'Departments': departments, 'contentheader': 'User Profile',
               'apppath': ['Profile'], 'Clients': clients, 'Dashboard': dashboard}
    updateMenuNumbers(request, context)
    return render(request, 'users/profile.html', context)
Ejemplo n.º 10
0
def info(request, name):
    """ Storage info and status """
    storageres = getDIRStorageinfo(name=name)
    if storageres is None:
        raise Http404()
    storage = extractstorageparams(storageres)
    departs = storage.get('Departments')
    dlist = []
    if departs is not None:
        for d in departs:
            dlist.append(getDepartment(d))
    storage.update({'Departments': dlist})
    storagealert = request.GET.get('n', 0)
    storagealertheader = "Restart required!"
    try:
        if int(storagealert) == 1:
            # new storage added
            storagealertheader = "New Storage added!"
        if int(storagealert) == 2:
            # new storage added
            storagealertheader = "Storage hardware configuration changed!"
    except (ValueError, TypeError):
        storagealert = None
    context = {'contentheader': 'Storage', 'apppath': ['Storage', 'Info', name], 'Storage': storage,
               'storagealert': storagealert, 'storagealertheader': storagealertheader, 'storagestatusdisplay': 1}
    updateMenuNumbers(request, context)
    return render(request, 'storage/storage.html', context)
Ejemplo n.º 11
0
def editstd(request, name):
    clientres = getDIRClientinfo(request, name=name)
    if clientres is None:
        raise Http404()
    departments = getUserDepartmentsList(request)
    client = extractclientparams(clientres)
    if request.method == 'GET':
        backurl = request.GET.get('b', None)
        data = makeinitialdata(name, client, backurl)
        form = ClientStdForm(initial=data, departments=departments)
        form.fields['name'].disabled = True
        form.fields['os'].disabled = True
        if client.get('InternalClient'):
            form.fields['address'].disabled = True
        context = {'contentheader': 'Client', 'apppath': ['Clients', 'Edit', name], 'clientstatusdisplay': 1,
                   'Client': client, 'form': form, 'OS': client['OS']}
        updateMenuNumbers(request, context)
        updateClientsOSnrlist(request, context)
        return render(request, 'clients/editstd.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        backurl = request.POST.get('backurl')
        if backurl is None or backurl == '':
            backurl = 'clientsinfo'
        if not cancel:
            # print "Save!"
            post = request.POST.copy()
            post['name'] = name
            post['os'] = client['OS']
            if client.get('InternalClient'):
                post['address'] = client['Address']
            data = makeinitialdata(name, client, backurl)
            form = ClientStdForm(data=post, initial=data, departments=departments)
            if form.is_valid():
                if form.has_changed():
                    # print "form valid and changed ... "
                    with transaction.atomic():
                        if 'descr' in form.changed_data:
                            # print "Update description"
                            updateClientDescr(request, name=name, descr=form.cleaned_data['descr'])
                        if 'address' in form.changed_data:
                            # print "Update address"
                            updateClientAddress(request, name=name, address=form.cleaned_data['address'])
                        if 'departments' in form.changed_data:
                            # update department
                            depart = form.cleaned_data['departments']
                            # check if default department selected = No department in config
                            if depart == ' ':
                                depart = None
                            updateClientDepartment(request, name=name, department=depart)
                        if 'os' in form.changed_data:
                            # print "Update OS"
                            # TODO: Unsupported right now. Do we really want to support this feature?
                            # updateClientOS(name=name, os=form.cleaned_data['os'])
                            pass
                    directorreload()
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect(backurl, name)
Ejemplo n.º 12
0
def index(request):
    user = request.user
    profile = Profile.objects.get(user=user)
    pcol1 = profile.dashboardcol1
    if pcol1 is not None and pcol1 != '':
        col1 = pcol1.split(',')
    else:
        col1 = []
    pcol2 = profile.dashboardcol2
    if pcol2 is not None and pcol2 != '':
        col2 = pcol2.split(',')
    else:
        col2 = []
    section1 = []
    for w in col1:
        widget = Dashboardwidgets.objects.get(user=user, widget__widgetid=w)
        if widget.enabled:
            section1.append(widget)
    section2 = []
    for w in col2:
        widget = Dashboardwidgets.objects.get(user=user, widget__widgetid=w)
        if widget.enabled:
            section2.append(widget)
    context = {'contentheader': 'Dashboard', 'contentheadersmall': 'Control Panel',
               'Section1': section1, 'Section2': section2}
    updateMenuNumbers(request, context)
    updateservicestatus(context)
    # messages.info(request, 'Three credits <a href="%s">remain</a> in your account.' % reverse('home'),
    #               extra_tags='AAA')
    # messages.error(request, 'It is a standard error.', extra_tags='ERROR')
    # messages.warning(request, 'about something.', extra_tags='Warning')
    return render(request, 'pages/index.html', context)
Ejemplo n.º 13
0
def job(request, name=None):
    if name is None:
        return redirect('jobsdefined')
    jobres = getDIRJobinfo(request, name=name)
    if jobres is None:
        raise Http404()
    jobparams = extractjobparams(jobres)
    if jobparams.get('Disabledfordelete', None):
        # the job is disabled so redirect to defined jobs
        return redirect('jobsdefined')
    jobminmax = Job.objects.filter(name=name,
                                   jobstatus__in=['T', 'I']).aggregate(
                                       Max('endtime'), Min('endtime'))
    jobmin = jobminmax['endtime__min']
    if jobmin is None:
        jobmin = datetime.today() + timedelta(days=1)
    jobmax = jobminmax['endtime__max']
    if jobmax is None:
        jobmax = datetime.today() + timedelta(days=-1)
    context = {
        'contentheader': 'Restore',
        'contentheadersmall': 'Job ' + name,
        'apppath': ['Restore', 'Job', name],
        'Job': jobparams,
        'jobmin': jobmin,
        'jobmax': jobmax
    }
    updateMenuNumbers(request, context)
    return render(request, 'restore/job.html', context)
Ejemplo n.º 14
0
def jobidkvm(request, jobid=None):
    if jobid is None:
        raise Http404()
    jobp = getJobidinfo(request, jobid)
    if jobp is None:
        raise Http404()
    jobids = bvfs_get_jobids(jobid)
    if jobids is not None:
        jobidlist = [int(j) for j in jobids.split(',')]
        jobidsparams = []
        for j in jobidlist:
            jj = Job.objects.get(jobid=j)
            jobidsparams.append({
                'jobid': j,
                'level': jj.level,
            })
    else:
        jobids = 'unavl'
        jobidsparams = []
    cl = getDIRClientsNames(request)
    clients = ()
    for c in cl:
        clients += ((c, c),)
    clientname = jobp['Client']
    form = RestoreFilesForm(clients=clients, initial={'client': clientname, 'restoreclient': clientname})
    context = {'contentheader': 'Restore', 'contentheadersmall': 'JobId: ' + str(jobp['JobId']),
               'apppath': ['Restore', 'JobId', jobp['JobId']], 'Job': jobp, 'Jobidsparams': jobidsparams,
               'Jobids': jobids, 'form': form, 'JobTypeURL': reverse('restoretreekvm', args=[jobids, 'root']),
               'JobTypeQueryURL': reverse('restoretreekvm_rel', args=[jobids]),
               'JobTypePrepareURL': reverse('restoreprepare', args=[jobids])}
    updateMenuNumbers(request, context)
    return render(request, 'restore/jobidkvm.html', context)
Ejemplo n.º 15
0
def stats_server(request):
    params = StatDaterange.objects.filter(Q(parid__name__contains='bacula.daemon') |
                                          Q(parid__name__contains='ibadmin.daemon')).order_by('parid')
    context = {'contentheader': 'System Statistics', 'contentheadersmall': 'Server Daemons',
               'apppath': ['Statistics', 'Daemons', 'Server'], 'params': params}
    updateMenuNumbers(request, context)
    return render(request, 'stats/default.html', context)
Ejemplo n.º 16
0
def client(request, name=None):
    if name is None:
        return redirect('clientsdefined')
    clientres = getDIRClientinfo(request, name=name)
    if clientres is None:
        raise Http404()
    updateClientres(clientres)
    clientp = extractclientparams(clientres)
    if clientp.get('Disabledfordelete', None):
        # the job is disabled so redirect to defined jobs
        return redirect('clientsdefined')
    jobslist = getDIRClientJobsList(request, client=name)
    jobdefined = []
    for jobres in jobslist:
        jobparams = extractjobparams(jobres)
        jobdefined.append(jobparams)
    context = {
        'contentheader': 'Restore',
        'contentheadersmall': 'Client ' + name,
        'apppath': ['Restore', 'Client', name],
        'Client': clientp,
        'ClientJobsdefined': jobdefined
    }
    updateMenuNumbers(request, context)
    return render(request, 'restore/client.html', context)
Ejemplo n.º 17
0
def defined(request):
    """ Defined Storages table - list """
    storagelist = getUserStorages(request)
    userdeparts = getUserDepartments(request)
    storagedefined = []
    for storage in storagelist:
        storageparams = extractstorageparams(getDIRStorageparams(storage))
        departs = storageparams.get('Departments')
        dlist = []
        if departs is not None:
            for d in departs:
                if userdeparts.filter(shortname=d).count() > 0:
                    dlist.append(getDepartment(d))
            if len(dlist) > 3:
                dlist = dlist[:2]
                storageparams['departslice'] = 1
        storageparams.update({'Departments': dlist})
        storagedefined.append(storageparams)
    context = {
        'contentheader': 'Storage',
        'contentheadersmall': 'currently defined',
        'apppath': ['Storage', 'Defined'],
        'StorageDefined': storagedefined
    }
    updateMenuNumbers(request, context)
    return render(request, 'storage/defined.html', context)
Ejemplo n.º 18
0
def adddep(request):
    if request.method == 'GET':
        form = DepartmentForm()
        context = {'contentheader': 'Departments', 'apppath': ['Departments', 'Add'], 'form': form}
        updateMenuNumbers(request, context)
        return render(request, 'departments/add.html', context)
    else:
        # print request.POST
        add = request.POST.get('add', 0)
        cancel = request.POST.get('cancel', 0)
        if add and not cancel:
            form = DepartmentForm(request.POST)
            if form.is_valid():
                username = request.user.username
                department = form.cleaned_data['name']
                descr = form.cleaned_data['descr']
                short = form.cleaned_data['shortname']
                color = form.cleaned_data['color']
                # create Department
                with transaction.atomic():
                    depart = Departments(name=department, shortname=short, description=descr, color=color)
                    depart.save()
                    user = request.user
                    if not user.is_superuser or not user.is_staff:
                        profile = Profile.objects.get(user=user)
                        profile.departments.add(depart)
                    log = Log(jobid_id=0, logtext='Department "%s" created by %s' % (department, str(username)))
                    log.save()
                return redirect('departsdefined')
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('departsdefined')
Ejemplo n.º 19
0
def backup_sizes(request):
    params = StatDaterange.objects.filter(Q(parid__name__contains='bacula.size') |
                                          Q(parid__name__contains='catalog.size')).order_by('parid')
    context = {'contentheader': 'Backup Statistics', 'contentheadersmall': 'Sizes',
               'apppath': ['Statistics', 'Backup', 'Sizes'], 'params': params}
    updateMenuNumbers(request, context)
    return render(request, 'stats/default.html', context)
Ejemplo n.º 20
0
def info(request, name):
    """ Client info """
    clientres = getDIRUserClientinfo(request, name=name)
    if clientres is None:
        raise Http404()
    updateClientres(clientres)
    client = extractclientparams(clientres)
    if client.get('Disabledfordelete', None):
        # the job is disabled so redirect to defined jobs
        return redirect('clientsdefined')
    depart = client.get('Department')
    if depart is not None:
        client.update({'Department': getDepartment(depart)})
    clientvmhost = False
    clientos = client.get('OS', None)
    if clientos in VMHOSTSOSTYPES:
        clientvmhost = True
    context = {
        'contentheader': 'Clients',
        'apppath': ['Clients', 'Info', name],
        'Client': client,
        'clientstatusdisplay': 1,
        'clientvmhost': clientvmhost
    }
    updateMenuNumbers(request, context)
    updateClientsOSnrlist(request, context)
    return render(request, 'clients/client.html', context)
Ejemplo n.º 21
0
def addkvmhost(request):
    departments = getUserDepartmentsList(request)
    if request.method == 'GET':
        # initialclient = request.GET.get('c', None)
        form = VMhostForm(departments=departments)
        context = {'contentheader': 'Add VM Host', 'apppath': ['Virtual', 'Add', 'KVM'], 'form': form}
        updateMenuNumbers(request, context)
        return render(request, 'vmhosts/addkvmhost.html', context)
    else:
        # print request.POST
        add = request.POST.get('add', 0)
        cancel = request.POST.get('cancel', 0)
        if add and not cancel:
            form = VMhostForm(data=request.POST, departments=departments)
            if form.is_valid():
                name = form.cleaned_data['name'].encode('ascii', 'ignore')
                descr = form.cleaned_data['descr']
                address = form.cleaned_data['address']
                defjob = form.cleaned_data['defjob']
                depart = form.cleaned_data['departments']
                # create a Client resource based on a Client component
                with transaction.atomic():
                    createClient(name=name, address=address, os='kvm', descr=descr, department=depart)
                    if defjob:
                        checkDIRKVMJobDef()
                        createDefaultKVMJob(clientname=name)
                directorreload()
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('vmskvmhostdefined')
Ejemplo n.º 22
0
def userprofile(request):
    user = request.user
    profile = Profile.objects.get(user=user)
    departments = profile.departments.all()
    dashboard = Dashboardwidgets.objects.filter(user=user).order_by('widget')
    if not dashboard.count():
        # no widgets in profile populate default
        widgets = Widgets.objects.all()
        for w in widgets:
            dbwidget = Dashboardwidgets(user=user, widget=w)
            dbwidget.enabled = False
            dbwidget.save()
        dashboard = Dashboardwidgets.objects.filter(user=user)
    clientlist = getUserClients(request)
    clients = []
    for clientres in clientlist:
        clientparams = getDIRClientparams(clientres)
        clientparams = extractclientparams(clientparams)
        clients.append({
            'Name': clientparams['Name'],
            'OS': clientparams['OS'],
        })
    context = {
        'User': user,
        'Profile': profile,
        'Departments': departments,
        'contentheader': 'User Profile',
        'apppath': ['Profile'],
        'Clients': clients,
        'Dashboard': dashboard
    }
    updateMenuNumbers(request, context)
    return render(request, 'users/profile.html', context)
Ejemplo n.º 23
0
def addrole(request):
    perms = get_system_permissions()
    if request.method == 'GET':
        form = RolesForm(perms=perms)
        context = {
            'contentheader': 'Roles',
            'apppath': ['Roles', 'Add'],
            'form': form
        }
        updateMenuNumbers(request, context)
        return render(request, 'roles/add.html', context)
    else:
        # print request.POST
        add = request.POST.get('add', 0)
        cancel = request.POST.get('cancel', 0)
        if add and not cancel:
            form = RolesForm(data=request.POST, perms=perms)
            if form.is_valid():
                rolename = form.cleaned_data['name']
                # Ugly hack for limiting database varchar(80)
                rolenamelen = len(rolename.encode('UTF-8'))
                if rolenamelen > 80:
                    rolename = rolename[:(80 - rolenamelen) / 2]
                descr = form.cleaned_data['descr']
                color = form.cleaned_data['color']
                perms = form.cleaned_data['perms']
                # create Role
                with transaction.atomic():
                    role = Group.objects.create(name=rolename)
                    role.roles.description = descr
                    role.roles.color = color
                    newperms = []
                    for p in perms:
                        if p.startswith('addallperms_'):
                            (n, applabel) = p.split('_')
                            allperms = Permission.objects.filter(content_type__model='permissions',
                                                                 content_type__app_label=applabel)\
                                .exclude(codename__icontains='_permissions')
                            for ap in allperms:
                                newperms.append(ap.codename)
                        else:
                            newperms.append(p)
                    permlist = Permission.objects.filter(
                        codename__in=newperms,
                        content_type__model='permissions')
                    role.permissions.set(permlist)
                    role.save()
                    log = Log(jobid_id=0,
                              logtext='Create role: %s by %s' %
                              (rolename, request.user.username))
                    log.save()
                    messages.success(request,
                                     'Role "%s" defined.' % role.name,
                                     extra_tags="Success")
            else:
                messages.error(request,
                               "Cannot validate a form: %s" % form.errors,
                               extra_tags='Error')
    return redirect('rolesdefined')
Ejemplo n.º 24
0
def addtape(request):
    departments = getUserDepartmentsList(request, default=False)
    st = getStorageNames()
    storages = ()
    for s in st:
        storages += ((s, s),)
    libs = detectlibs()
    tapelibs = ()
    tlavl = False
    stortapeids = getDIRStorageTapeids()
    for l in libs:
        if l['id'] not in stortapeids:
            tapelibs += ((l['id'], l['name'] + l['id']),)
            tlavl = True
    if request.method == 'GET':
        form = StorageTapeForm(storages=storages, tapelibs=tapelibs, departments=departments)
        form.fields['address'].disabled = True
        context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Add', 'Tape storage'], 'form': form,
                   'tlavl': tlavl}
        updateMenuNumbers(request, context)
        messages.info(request, """Here <b>IBAdmin</b> will detect a storage you select. It will require to execute 
            tape load/unload operations which will take some time to complete. You should check the operation 
            progress below.<br>
            By default IBAdmin will automatically <u>initialize</u> all tapes found in library for future use.
            If you want to make this initialization later you have to deselect the checkbox below.""",
                      extra_tags="noslide:Info")
        return render(request, 'storage/addtape.html', context)
    else:
        # print (request.POST)
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            form = StorageTapeForm(data=request.POST, storages=storages, tapelibs=tapelibs, departments=departments)
            if form.is_valid():
                taskid = form.cleaned_data['taskid']
                task = get_object_or_404(Tasks, taskid=taskid)
                if task.status == 'F':
                    storname = form.cleaned_data['name'].encode('ascii', 'ignore')
                    descr = form.cleaned_data['descr']
                    storage = form.cleaned_data['storagelist']
                    # address = form.cleaned_data['address']
                    tapelist = form.cleaned_data['tapelist']
                    libdata = None
                    for l in libs:
                        if l['id'] == tapelist:
                            libdata = l
                    tapelib = {
                        'Lib': libdata,
                        'Devices': ast.literal_eval(task.output)
                    }
                    # create a Storage resource
                    with transaction.atomic():
                        extendStoragetape(storname=storname, descr=descr, sdcomponent=storage, tapelib=tapelib)
                    directorreload()
                    response = redirect('storageinfo', storname)
                    response['Location'] += '?n=1'
                    return response
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('storagedefined')
Ejemplo n.º 25
0
def addtape(request):
    departments = getUserDepartmentsList(request, default=False)
    st = getStorageNames()
    storages = ()
    for s in st:
        storages += ((s, s),)
    libs = detectlibs()
    tapelibs = ()
    tlavl = False
    stortapeids = getDIRStorageTapeids()
    for l in libs:
        if l['id'] not in stortapeids:
            tapelibs += ((l['id'], l['name'] + l['id']),)
            tlavl = True
    if request.method == 'GET':
        form = StorageTapeForm(storages=storages, tapelibs=tapelibs, departments=departments)
        form.fields['address'].disabled = True
        context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Add', 'Tape storage'], 'form': form,
                   'tlavl': tlavl}
        updateMenuNumbers(request, context)
        messages.info(request, """Here <b>IBAdmin</b> will detect a storage you select. It will require to execute 
            tape load/unload operations which will take some time to complete. You should check the operation 
            progress below.<br>
            By default IBAdmin will automatically <u>initialize</u> all tapes found in library for future use.
            If you want to make this initialization later you have to deselect the checkbox below.""",
                      extra_tags="noslide:Info")
        return render(request, 'storage/addtape.html', context)
    else:
        # print (request.POST)
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            form = StorageTapeForm(data=request.POST, storages=storages, tapelibs=tapelibs, departments=departments)
            if form.is_valid():
                taskid = form.cleaned_data['taskid']
                task = get_object_or_404(Tasks, taskid=taskid)
                if task.status == 'F':
                    storname = form.cleaned_data['name'].encode('ascii', 'ignore')
                    descr = form.cleaned_data['descr']
                    storage = form.cleaned_data['storagelist']
                    # address = form.cleaned_data['address']
                    tapelist = form.cleaned_data['tapelist']
                    libdata = None
                    for l in libs:
                        if l['id'] == tapelist:
                            libdata = l
                    tapelib = {
                        'Lib': libdata,
                        'Devices': ast.literal_eval(task.output)
                    }
                    # create a Storage resource
                    with transaction.atomic():
                        extendStoragetape(storname=storname, descr=descr, sdcomponent=storage, tapelib=tapelib)
                    directorreload()
                    response = redirect('storageinfo', storname)
                    response['Location'] += '?n=1'
                    return response
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('storagedefined')
Ejemplo n.º 26
0
def vcenterinfo(request, name):
    """ Client info """
    vcenter = get_object_or_404(vCenterHosts, name=name)
    clnr = ConfParameter.objects.filter(name='.vCenterName', value=name).count()
    context = {'contentheader': 'Virtual', 'apppath': ['Virtual', 'vCenter', 'Info'], 'vCenter': vcenter,
               'vcenterproxynr': clnr}
    updateMenuNumbers(request, context)
    return render(request, 'vmhosts/vcenterinfo.html', context)
Ejemplo n.º 27
0
def vcenterdefined(request):
    """ Defined VM Hosts table - list """
    context = {
        'contentheader': 'VMware vCenter Hosts',
        'contentheadersmall': 'currently defined',
        'apppath': ['Virtual', 'VMware']
    }
    updateMenuNumbers(request, context)
    return render(request, 'vmhosts/vcenter.html', context)
Ejemplo n.º 28
0
def kvmhostdefined(request):
    """ Defined VM Hosts table - list """
    context = {
        'contentheader': 'XenServer Hosts',
        'contentheadersmall': 'currently defined',
        'apppath': ['Virtual', 'KVM']
    }
    updateMenuNumbers(request, context)
    return render(request, 'vmhosts/kvmhost.html', context)
Ejemplo n.º 29
0
def editdedup(request, name):
    storageres = getDIRStorageinfo(name=name)
    if storageres is None:
        raise Http404()
    departments = getUserDepartmentsList(request, default=False)
    storage = extractstorageparams(storageres)
    st = getStorageNames()
    storages = ()
    for s in st:
        storages += ((s, s),)
    if request.method == 'GET':
        data = makeinitialdata(name, storage)
        form = StorageDedupForm(storages=storages, departments=departments, initial=data)
        form.fields['name'].disabled = True
        form.fields['address'].disabled = True
        form.fields['storagelist'].disabled = True
        context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Edit', 'Dedup storage'], 'form': form,
                   'storagestatusdisplay': 1, 'Storage': storage}
        updateMenuNumbers(request, context)
        return render(request, 'storage/editdedup.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            post = request.POST.copy()
            post['name'] = name
            post['address'] = storage['Address']
            post['storagelist'] = storage['StorageComponent']
            data = makeinitialdata(name, storage)
            form = StorageDedupForm(data=post, storages=storages, departments=departments, initial=data)
            if form.is_valid():
                descr = form.cleaned_data['descr']
                departs = form.cleaned_data['departments']
                dedupidxdir = form.cleaned_data['dedupidxdir']
                dedupdir = form.cleaned_data['dedupdir']
                if form.has_changed():
                    # print "form valid and changed ... "
                    if 'descr' in form.changed_data:
                        # update description
                        with transaction.atomic():
                            updateDIRStorageDescr(request, name=name, descr=descr)
                    if 'dedupidxdir' in form.changed_data:
                        # update archivedir
                        with transaction.atomic():
                            updateStorageDedupidxdir(storname=name, dedupidxdir=dedupidxdir)
                    if 'dedupdir' in form.changed_data:
                        # update archivedir
                        with transaction.atomic():
                            updateStorageDedupdir(storname=name, dedupdir=dedupdir)
                    if 'departments' in form.changed_data:
                        # update departments
                        updateDIRStorageDepartments(request, name=name, departments=departs)
                    directorreload()
                return redirect('storageinfo', name)
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('storagedefined')
Ejemplo n.º 30
0
def editvcenter(request, name):
    departments = getUserDepartmentsList(request)
    vcenter = get_object_or_404(vCenterHosts, name=name)
    data = {
        'name': vcenter.name,
        'descr': vcenter.description,
        'username': vcenter.username,
        'password': '******',
        'address': vcenter.address,
        'url': vcenter.url,
        'thumbprint': vcenter.thumbprint,
        'client': [],
        'departments': vcenter.department,
    }
    if request.method == 'GET':
        form = vCenterForm(initial=data, departments=departments)
        form.fields['name'].disabled = True
        context = {'contentheader': 'Virtual', 'apppath': ['Virtual', 'vCenter', 'Edit'], 'form': form,
                   'vCenter': vcenter}
        updateMenuNumbers(request, context)
        updateClientsOSnrlist(request, context)
        return render(request, 'vmhosts/editvcenter.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            # print "Save!"
            post = request.POST.copy()
            post['name'] = name
            form = vCenterForm(data=post, initial=data, departments=departments)
            if form.is_valid():
                if form.has_changed():
                    # print "form valid and changed ... "
                    with transaction.atomic():
                        if 'descr' in form.changed_data:
                            vcenter.description = form.cleaned_data['descr']
                        if 'username' in form.changed_data:
                            vcenter.username = form.cleaned_data['username']
                        if 'password' in form.changed_data:
                            password = form.cleaned_data['password']
                            encpass = getencpass(name, password)
                            vcenter.password = encpass
                        if 'address' in form.changed_data:
                            vcenter.address = form.cleaned_data['address']
                        if 'url' in form.changed_data:
                            vcenter.url = form.cleaned_data['url']
                        if 'thumbprint' in form.changed_data:
                            vcenter.thumbprint = form.cleaned_data['thumbprint']
                        if 'departments' in form.changed_data:
                            depart = form.cleaned_data['departments']
                            if depart in ['', ' ', '#']:
                                depart = None
                            vcenter.department = depart
                        vcenter.save()
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('vmsvcenterdefined')
Ejemplo n.º 31
0
def addservice(request):
    departments = getUserDepartmentsList(request)
    cl = getDIRUserClusters(request)
    if not len(cl):
        messages.info(
            request,
            "No clusters defined, so cannot add a cluster service. Add cluster node first.",
            extra_tags="Info!")
        return redirect('clientsaddnode')
    clusters = ()
    for c in cl:
        clusters += ((c, c), )
    if request.method == 'GET':
        form = ClientServiceForm(clusters=clusters, departments=departments)
        context = {
            'contentheader': 'Client',
            'apppath': ['Clients', 'Add', 'Cluster service'],
            'form': form
        }
        updateMenuNumbers(request, context)
        updateClientsOSnrlist(request, context)
        return render(request, 'clients/addservice.html', context)
    else:
        # print request.POST
        add = request.POST.get('add', 0)
        cancel = request.POST.get('cancel', 0)
        if add and not cancel:
            form = ClientServiceForm(data=request.POST,
                                     clusters=clusters,
                                     departments=departments)
            if form.is_valid():
                name = form.cleaned_data['name'].encode('ascii', 'ignore')
                descr = form.cleaned_data['descr']
                address = form.cleaned_data['address']
                cluster = form.cleaned_data['cluster']
                defjob = form.cleaned_data['defjob']
                depart = form.cleaned_data['departments']
                # check if default department selected = No department in config
                if depart == ' ':
                    depart = None
                # create a Client resource and a Client component and all required resources
                with transaction.atomic():
                    createClientService(request,
                                        name=name,
                                        address=address,
                                        cluster=cluster,
                                        descr=descr,
                                        department=depart)
                    if defjob:
                        createDefaultClientJob(request, name=name, client=name)
                directorreload()
                return redirect('clientsinfo', name)
            else:
                messages.error(request,
                               "Cannot validate a form: %s" % form.errors,
                               extra_tags='Error')
    return redirect('clientsdefined')
Ejemplo n.º 32
0
def defined(request):
    """ Defined Roles table - list """
    context = {
        'contentheader': 'Roles',
        'contentheadersmall': 'currently defined',
        'apppath': ['Roles', 'Defined']
    }
    updateMenuNumbers(request, context)
    return render(request, 'roles/defined.html', context)
Ejemplo n.º 33
0
def daemons(request):
    context = {
        'contentheader': 'Daemons',
        'contentheadersmall': 'Manage',
        'apppath': ['Backup', 'Daemons']
    }
    updateMenuNumbers(request, context)
    updateservicestatus(context)
    return render(request, 'system/daemons.html', context)
Ejemplo n.º 34
0
def editdedup(request, name):
    storageres = getDIRStorageinfo(name=name)
    if storageres is None:
        raise Http404()
    departments = getUserDepartmentsList(request, default=False)
    storage = extractstorageparams(storageres)
    st = getStorageNames()
    storages = ()
    for s in st:
        storages += ((s, s),)
    if request.method == 'GET':
        data = makeinitialdata(name, storage)
        form = StorageDedupForm(storages=storages, departments=departments, initial=data)
        form.fields['name'].disabled = True
        form.fields['address'].disabled = True
        form.fields['storagelist'].disabled = True
        context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Edit', 'Dedup storage'], 'form': form,
                   'storagestatusdisplay': 1, 'Storage': storage}
        updateMenuNumbers(request, context)
        return render(request, 'storage/editdedup.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            post = request.POST.copy()
            post['name'] = name
            post['address'] = storage['Address']
            post['storagelist'] = storage['StorageComponent']
            data = makeinitialdata(name, storage)
            form = StorageDedupForm(data=post, storages=storages, departments=departments, initial=data)
            if form.is_valid():
                descr = form.cleaned_data['descr']
                departs = form.cleaned_data['departments']
                dedupidxdir = form.cleaned_data['dedupidxdir']
                dedupdir = form.cleaned_data['dedupdir']
                if form.has_changed():
                    # print "form valid and changed ... "
                    if 'descr' in form.changed_data:
                        # update description
                        with transaction.atomic():
                            updateDIRStorageDescr(request, name=name, descr=descr)
                    if 'dedupidxdir' in form.changed_data:
                        # update archivedir
                        with transaction.atomic():
                            updateStorageDedupidxdir(storname=name, dedupidxdir=dedupidxdir)
                    if 'dedupdir' in form.changed_data:
                        # update archivedir
                        with transaction.atomic():
                            updateStorageDedupdir(storname=name, dedupdir=dedupdir)
                    if 'departments' in form.changed_data:
                        # update departments
                        updateDIRStorageDepartments(request, name=name, departments=departs)
                    directorreload()
                return redirect('storageinfo', name)
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('storagedefined')
Ejemplo n.º 35
0
def proxmoxdefined(request):
    """ Defined VM Hosts table - list """
    context = {
        'contentheader': 'Proxmox Hosts',
        'contentheadersmall': 'currently defined',
        'apppath': ['Virtual', 'Proxmox']
    }
    updateMenuNumbers(request, context)
    return render(request, 'vmhosts/proxmox.html', context)
Ejemplo n.º 36
0
def editservice(request, name):
    clientres = getDIRClientinfo(request, name=name)
    if clientres is None:
        raise Http404()
    client = extractclientparams(clientres)
    departments = getUserDepartmentsList(request)
    cl = getDIRClientsClusters(request)
    if not len(cl):
        messages.error(request, "No clusters defined! Report it to service!", extra_tags="Error!")
        return redirect('clientsaddnode')
    clusters = ()
    for c in cl:
        clusters += ((c, c),)
    if request.method == 'GET':
        backurl = request.GET.get('b', None)
        data = makeinitialdata(name, client, backurl)
        form = ClientServiceForm(initial=data, clusters=clusters, departments=departments)
        form.fields['name'].disabled = True
        context = {'contentheader': 'Client', 'apppath': ['Clients', 'Edit', name], 'clientstatusdisplay': 1,
                   'Client': client, 'form': form, 'OS': client['OS']}
        updateMenuNumbers(request, context)
        updateClientsOSnrlist(request, context)
        return render(request, 'clients/editservice.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        backurl = request.POST.get('backurl')
        if backurl is None or backurl == '':
            backurl = 'clientsinfo'
        if not cancel:
            # print "Save!"
            post = request.POST.copy()
            post['name'] = name
            data = makeinitialdata(name, client, backurl)
            form = ClientServiceForm(data=post, initial=data, clusters=clusters, departments=departments)
            if form.is_valid():
                if form.has_changed():
                    # print "form valid and changed ... "
                    with transaction.atomic():
                        if 'descr' in form.changed_data:
                            # print "Update description"
                            updateClientDescr(request, name=name, descr=form.cleaned_data['descr'])
                        if 'address' in form.changed_data:
                            # print "Update address"
                            updateClientAddress(request, name=name, address=form.cleaned_data['address'])
                        if 'cluster' in form.changed_data:
                            # print "Update cluster"
                            updateClientCluster(request, name=name, cluster=form.cleaned_data['cluster'])
                        if 'departments' in form.changed_data:
                            # update department
                            depart = form.cleaned_data['departments']
                            updateClientDepartment(request, name=name, department=depart)
                    directorreload()
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect(backurl, name)
Ejemplo n.º 37
0
def volinfo(request, name):
    volume = get_object_or_404(Media.objects.select_related('poolid'), volumename=name)
    if volume.lastwritten is None:
        expired = '-'
    else:
        expired = volume.lastwritten + timedelta(seconds=volume.volretention)
    context = {'contentheader': 'Volume Info', 'apppath': ['Storage', 'Volume', 'Info', name], 'Volume': volume,
                'Volexpired': expired, 'volumestatusdisplay': 1}
    updateMenuNumbers(request, context)
    return render(request, 'storage/volinfo.html', context)
Ejemplo n.º 38
0
def defined(request):
    """ Defined Clients table - list """
    context = {
        'contentheader': 'Clients',
        'contentheadersmall': 'currently defined',
        'apppath': ['Clients', 'Defined']
    }
    updateMenuNumbers(request, context)
    updateClientsOSnrlist(request, context)
    return render(request, 'clients/defined.html', context)
Ejemplo n.º 39
0
def volinfo(request, name):
    volume = get_object_or_404(Media.objects.select_related('poolid'), volumename=name)
    if volume.lastwritten is None:
        expired = '-'
    else:
        expired = volume.lastwritten + timedelta(seconds=volume.volretention)
    context = {'contentheader': 'Volume Info', 'apppath': ['Storage', 'Volume', 'Info', name], 'Volume': volume,
                'Volexpired': expired, 'volumestatusdisplay': 1}
    updateMenuNumbers(request, context)
    return render(request, 'storage/volinfo.html', context)
Ejemplo n.º 40
0
def info(request, rolename):
    role = get_object_or_404(Roles, group__name=rolename)
    labelcolor = LABELCOLORSDICT.get(role.color, 'bg-blue')
    perms = get_system_permissions_filtered(role.group)
    perms.insert(0, (None, ''))
    form = RolesAddpermForm(perms=perms)
    context = {'contentheader': 'Roles', 'apppath': ['Roles', 'Info', rolename], 'Role': role, 'rolestatusdisplay': 1,
               'labelcolor': labelcolor, 'form': form}
    updateMenuNumbers(request, context)
    return render(request, 'roles/info.html', context)
Ejemplo n.º 41
0
def addvcenterclient(request):
    departments = getUserDepartmentsList(request)
    clesx = getDIRClientsNamesesx(request)
    cl = getDIRClientsNames(request, os='rhel') + clesx
    clients = ()
    for c in cl:
        clients += ((c, c),)
    vcn = getUservCenters(request).order_by('name')
    vcenters = ()
    for vc in vcn:
        vcenters += ((vc.name, vc.name),)
    if request.method == 'GET':
        form = vCenterClientForm(clients=clients, vcenter=vcenters, departments=departments)
        context = {'contentheader': 'Virtual', 'apppath': ['Virtual', 'vCenter Assign'], 'form': form,
                   'vCenter': {'name': 'Assign'}}
        updateMenuNumbers(request, context)
        updateClientsOSnrlist(request, context)
        return render(request, 'vmhosts/assignvcenter.html', context)
    else:
        # print request.POST
        add = request.POST.get('add', 0)
        cancel = request.POST.get('cancel', 0)
        if add and not cancel:
            form = vCenterClientForm(data=request.POST, clients=clients, vcenter=vcenters, departments=departments)
            if form.is_valid():
                name = form.cleaned_data['vcenter']
                clients = form.cleaned_data['client']
                # create a Client resource and a Client component and all required resources
                try:
                    with transaction.atomic():
                        for cl in clients:
                            depart = form.cleaned_data['departments']
                            if cl in clesx:
                                clname = cl
                            else:
                                clname = 'vmware-' + name + '-' + cl
                            clientexist = ConfResource.objects.filter(name=clname, type__name='Client')
                            if len(clientexist) > 0:
                                updateDirClientVMware(clientres=clientexist[0], vcenter=name, department=depart)
                                messages.info(request,
                                              "VMware Proxy Client <b>%s</b> already exist. Parameters updated!" %
                                              clname,
                                              extra_tags='Updated!')
                            else:
                                createVMwareAlias(request, name=clname, client=cl,
                                                  descr='VMware Proxy Client for ' + name,
                                                  vcenter=name, department=depart)
                                messages.success(request, "VMware Proxy Client <b>%s</b> created." % clname,
                                                 extra_tags=' Success!')
                    directorreload()
                except DatabaseError as e:
                    messages.error(request, "Database error: %s" % e, extra_tags='Error')
            else:
                messages.error(request, "Cannot parse form: %s" % form.errors.as_data(), extra_tags='Error')
    return redirect('vmsvcenterdefined')
Ejemplo n.º 42
0
def editalias(request, name):
    storageres = getDIRStorageinfo(name=name)
    if storageres is None:
        raise Http404()
    departments = getUserDepartmentsList(request)
    storage = extractstorageparams(storageres)
    st = getDIRStorageNamesnAlias(request)
    storages = ()
    for s in st:
        storages += ((s, s),)
    if len(storages) == 0:
        alias = storage.get('Alias', 'Default storage')
        storages = ((alias, alias),)
    ip = detectipall()
    ipall = [(a, a) for a in ip]
    if request.method == 'GET':
        data = makeinitialaliasdata(name, storage)
        form = StorageAliasForm(storages=storages, storageips=ipall, initial=data, departments=departments)
        form.fields['name'].disabled = True
        form.fields['storagelist'].disabled = True
        context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Edit', 'Alias'], 'form': form,
                   'storagestatusdisplay': 1, 'Storage': storage}
        updateMenuNumbers(request, context)
        return render(request, 'storage/editalias.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            post = request.POST.copy()
            post['name'] = name
            post['storagelist'] = storage['Alias']
            data = makeinitialaliasdata(name, storage)
            form = StorageAliasForm(data=post, storages=storages, storageips=ipall, initial=data,
                                    departments=departments)
            if form.is_valid():
                descr = form.cleaned_data['descr']
                departs = [form.cleaned_data['departments'], ]
                if form.has_changed():
                    with transaction.atomic():
                        # print "form valid and changed ... "
                        if 'descr' in form.changed_data:
                            # update description
                            updateDIRStorageDescr(request, name=name, descr=descr)
                        # if 'storageip' in form.changed_data:
                            # update archivedir
                            # updateStorageAliasAddress(storname=name, address=form.cleaned_data['storageip'])
                        if 'departments' in form.changed_data:
                            # update departments
                            print (departs)
                            updateDIRStorageDepartments(request, name=name, departments=departs)
                    directorreload()
                return redirect('storageinfo', name)
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('storagedefined')
Ejemplo n.º 43
0
def editalias(request, name):
    storageres = getDIRStorageinfo(name=name)
    if storageres is None:
        raise Http404()
    departments = getUserDepartmentsList(request)
    storage = extractstorageparams(storageres)
    st = getDIRStorageNamesnAlias(request)
    storages = ()
    for s in st:
        storages += ((s, s),)
    if len(storages) == 0:
        alias = storage.get('Alias', 'Default storage')
        storages = ((alias, alias),)
    ip = detectipall()
    ipall = [(a, a) for a in ip]
    if request.method == 'GET':
        data = makeinitialaliasdata(name, storage)
        form = StorageAliasForm(storages=storages, storageips=ipall, initial=data, departments=departments)
        form.fields['name'].disabled = True
        form.fields['storagelist'].disabled = True
        context = {'contentheader': 'Storages', 'apppath': ['Storage', 'Edit', 'Alias'], 'form': form,
                   'storagestatusdisplay': 1, 'Storage': storage}
        updateMenuNumbers(request, context)
        return render(request, 'storage/editalias.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        if not cancel:
            post = request.POST.copy()
            post['name'] = name
            post['storagelist'] = storage['Alias']
            data = makeinitialaliasdata(name, storage)
            form = StorageAliasForm(data=post, storages=storages, storageips=ipall, initial=data,
                                    departments=departments)
            if form.is_valid():
                descr = form.cleaned_data['descr']
                departs = [form.cleaned_data['departments'], ]
                if form.has_changed():
                    with transaction.atomic():
                        # print "form valid and changed ... "
                        if 'descr' in form.changed_data:
                            # update description
                            updateDIRStorageDescr(request, name=name, descr=descr)
                        # if 'storageip' in form.changed_data:
                            # update archivedir
                            # updateStorageAliasAddress(storname=name, address=form.cleaned_data['storageip'])
                        if 'departments' in form.changed_data:
                            # update departments
                            # print (departs)
                            updateDIRStorageDepartments(request, name=name, departments=departs)
                    directorreload()
                return redirect('storageinfo', name)
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('storagedefined')
Ejemplo n.º 44
0
def userprofileedit(request):
    user = request.user
    if request.method == 'GET':
        backurl = request.GET.get('b', None)
        data = makeinitailadata(user, backurl)
        form = UserForm(departments=[], initial=data, usertypes=USERTYPE)
        form.fields['username'].disabled = True
        context = {'contentheader': 'Profile Edit', 'apppath': ['Profile', 'Edit'], 'form': form,
                   'User': user}
        updateMenuNumbers(request, context)
        return render(request, 'users/editprofile.html', context)
    else:
        # print request.POST
        cancel = request.POST.get('cancel', 0)
        backurl = request.POST.get('backurl')
        if backurl is None or backurl == '':
            backurl = reverse('usersprofile')
        if not cancel:
            data = makeinitailadata(user, backurl)
            post = request.POST.copy()
            post['username'] = user.username
            form = UserForm(data=post, departments=[], initial=data, usertypes=USERTYPE)
            if form.is_valid():
                if form.has_changed():
                    with transaction.atomic():
                        if 'firstname' in form.changed_data:
                            firstname = form.cleaned_data['firstname']
                            # Ugly hack for limiting database varchar(30)
                            firstnamelen = len(firstname.encode('UTF-8'))
                            if firstnamelen > 30:
                                firstname = firstname[:(30 - firstnamelen)/2]
                            user.first_name = firstname
                        if 'lastname' in form.changed_data:
                            lastname = form.cleaned_data['lastname']
                            # Ugly hack for limiting database varchar(30)
                            lastnamelen = len(lastname.encode('UTF-8'))
                            if lastnamelen > 30:
                                lastname = lastname[:(30 - lastnamelen)/2]
                            user.last_name = lastname
                        if 'email' in form.changed_data:
                            user.email = form.cleaned_data['email']
                        if 'password' in form.changed_data:
                            user.set_password(form.cleaned_data['password'])
                            # special case
                            user.save()
                            return redirect('logout')
                        log = Log(jobid_id=0, logtext='User profile modification: ' + user.username)
                        log.save()
                        user.save()
                        messages.success(request, "User profile updated", extra_tags='Success')
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect(backurl)
Ejemplo n.º 45
0
def dedup(request, name):
    """ Storage online status """
    storageres = getDIRStorageinfo(name=name)
    if storageres is None:
        raise Http404()
    storage = extractstorageparams(storageres)
    if not storage.get('MediaType', '').startswith('Dedup'):
        raise Http404()
    context = {'contentheader': 'Storage', 'apppath': ['Storage', 'Dedup Engine', name], 'Storage': storage,
               'storagestatusdisplay': 1, 'blk': range(1, 66)}
    updateMenuNumbers(request, context)
    return render(request, 'storage/dedup.html', context)
Ejemplo n.º 46
0
def status(request, name):
    """ Storage online status """
    storageres = getDIRStorageinfo(name=name)
    if storageres is None:
        raise Http404()
    storage = extractstorageparams(storageres)
    devname = storage['Device']
    devices = getSDDevicesList(component=storage['StorageComponent'], storage=devname)
    context = {'contentheader': 'Storage', 'apppath': ['Storage', 'Status', name], 'Storage': storage,
               'Devices': devices, 'storagestatusdisplay': 1}
    updateMenuNumbers(request, context)
    return render(request, 'storage/status.html', context)
Ejemplo n.º 47
0
def info(request, username):
    user = get_object_or_404(User, username=username)
    nrsuperusers = User.objects.filter(is_superuser=True).count()
    profile = Profile.objects.get(user=user)
    canlock = not (user.username == request.user.username or (user.is_superuser and nrsuperusers < 2))
    dl = getDepartmentsListfilter(request, user.profile.departments.all())
    departform = UserAdddepartmentForm(departments=dl)
    rl = getRolesListfilter(user.groups.all())
    rolesform = UserAddroleForm(roles=rl)
    context = {'User': user, 'Profile': profile, 'userstatusdisplay': 1,
               'contentheader': 'Users', 'apppath': ['Users', 'Info', username], 'canlock': canlock,
               'nrsuperusers': nrsuperusers, 'formdepart': departform, 'formrole': rolesform}
    updateMenuNumbers(request, context)
    return render(request, 'users/info.html', context)
Ejemplo n.º 48
0
def addnode(request):
    departments = getUserDepartmentsList(request)
    cl = getDIRClientsClusters(request)
    clusters = (('', ''),)
    for c in cl:
        clusters += ((c, c),)
    if request.method == 'GET':
        form = ClientNodeForm(clusters=clusters, departments=departments)
        if len(clusters) == 0:
            form.fields['clusterlist'].disabled = True
        backurl = request.GET.get('b', None)
        context = {'contentheader': 'Client', 'apppath': ['Clients', 'Add', 'Cluster node'], 'form': form}
        updateMenuNumbers(request, context)
        updateClientsOSnrlist(request, context)
        return render(request, 'clients/addnode.html', context)
    else:
        # print request.POST
        add = request.POST.get('add', 0)
        cancel = request.POST.get('cancel', 0)
        backurl = request.POST.get('backurl')
        if add and not cancel:
            form = ClientNodeForm(data=request.POST, clusters=clusters, departments=departments)
            if form.is_valid():
                name = form.cleaned_data['name'].encode('ascii', 'ignore')
                descr = form.cleaned_data['descr']
                cluster = form.cleaned_data.get('cluster', None)
                if cluster is not None:
                    cluster = cluster.encode('ascii', 'ignore')
                clusterlist = form.cleaned_data.get('clusterlist', None)
                address = form.cleaned_data['address']
                os = form.cleaned_data['os']
                defjob = form.cleaned_data['defjob']
                depart = form.cleaned_data['departments']
                # check if default department selected = No department in config
                if depart == ' ':
                    depart = None
                # create a Client resource and a Client component and all required resources
                with transaction.atomic():
                    createClientNode(name=name, address=address, os=os, descr=descr, cluster=cluster,
                                     clusterlist=clusterlist, department=depart)
                    if defjob:
                        createDefaultClientJob(request, name=name, clientos=os)
                directorreload()
                return redirect('clientsinfo', name)
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    if backurl is not None and backurl != '':
        return redirect(backurl)
    return redirect('clientsdefined')
Ejemplo n.º 49
0
def status(request, taskid):
    task = get_object_or_404(Tasks, taskid=taskid)
    procedure = TASKSPROCSDESCR[task.proc]
    if task.log is None:
        log = ''
    else:
        log = task.log.replace('\n', '<br>')
    if task.endtime is None:
        estr = '-'
    else:
        estr = task.endtime.strftime('%Y-%m-%d %H:%M:%S')
    context = {'contentheader': 'Tasks', 'contentheadersmall': 'All', 'Task': task, 'Procedure': procedure, 'Log': log,
               'EndTime': estr}
    updateMenuNumbers(request, context)
    return render(request, 'tasks/status.html', context)
Ejemplo n.º 50
0
def info(request, name):
    """ Department details info """
    department = get_object_or_404(Departments, shortname=name)
    labelcolor = LABELCOLORSDICT.get(department.color, 'bg-blue')
    members = Profile.objects.filter(departments=department)
    memberlist = []
    for m in members:
        memberlist.append(m.user.username)
    userlist = getUserListfiltered(memberlist)
    form = DepartmentAddmemberForm(users=userlist)
    context = {'contentheader': 'Department', 'contentheadersmall': 'Info', 'apppath': ['Departments', 'Info', name],
               'departmentdisplay': 1, 'Department': department, 'form': form, 'membersnr': members.count(),
               'labelcolor': labelcolor,
               'deldepart': getDepartmentssnr(request) > 1 or (request.user.is_superuser and request.user.is_staff)}
    updateMenuNumbers(request, context)
    return render(request, 'departments/info.html', context)
Ejemplo n.º 51
0
def addrole(request):
    perms = get_system_permissions()
    if request.method == 'GET':
        form = RolesForm(perms=perms)
        context = {'contentheader': 'Roles', 'apppath': ['Roles', 'Add'], 'form': form}
        updateMenuNumbers(request, context)
        return render(request, 'roles/add.html', context)
    else:
        # print request.POST
        add = request.POST.get('add', 0)
        cancel = request.POST.get('cancel', 0)
        if add and not cancel:
            form = RolesForm(data=request.POST, perms=perms)
            if form.is_valid():
                rolename = form.cleaned_data['name']
                # Ugly hack for limiting database varchar(80)
                rolenamelen = len(rolename.encode('UTF-8'))
                if rolenamelen > 80:
                    rolename = rolename[:(80 - rolenamelen)/2]
                descr = form.cleaned_data['descr']
                color = form.cleaned_data['color']
                perms = form.cleaned_data['perms']
                # create Role
                with transaction.atomic():
                    role = Group.objects.create(name=rolename)
                    role.roles.description = descr
                    role.roles.color = color
                    newperms = []
                    for p in perms:
                        if p.startswith('addallperms_'):
                            (n, applabel) = p.split('_')
                            allperms = Permission.objects.filter(content_type__model='permissions',
                                                                 content_type__app_label=applabel)\
                                .exclude(codename__icontains='_permissions')
                            for ap in allperms:
                                newperms.append(ap.codename)
                        else:
                            newperms.append(p)
                    permlist = Permission.objects.filter(codename__in=newperms, content_type__model='permissions')
                    role.permissions.set(permlist)
                    role.save()
                    log = Log(jobid_id=0, logtext='Create role: %s by %s' % (rolename, request.user.username))
                    log.save()
                    messages.success(request, 'Role "%s" defined.' % role.name, extra_tags="Success")
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('rolesdefined')
Ejemplo n.º 52
0
def status(request, name):
    """ Client online status """
    clientres = getDIRClientinfo(request, name=name)
    if clientres is None:
        raise Http404()
    client = extractclientparams(clientres)
    if client.get('Disabledfordelete', None):
        # the job is disabled so redirect to defined jobs
        return redirect('clientsdefined')
    clientvmhost = False
    clientos = client.get('OS', None)
    if clientos in VMHOSTSOSTYPES:
        clientvmhost = True
    context = {'contentheader': 'Clients', 'apppath': ['Clients', 'Status', name], 'Client': client,
               'clientstatusdisplay': 1, 'clientvmhost': clientvmhost}
    updateMenuNumbers(request, context)
    updateClientsOSnrlist(request, context)
    return render(request, 'clients/status.html', context)
Ejemplo n.º 53
0
def addvcenter(request):
    departments = getUserDepartmentsList(request)
    cl = getDIRClientsNames(request, os='rhel')
    clients = ()
    for c in cl:
        clients += ((c, c),)
    if request.method == 'GET':
        form = vCenterForm(clients=clients, departments=departments)
        context = {'contentheader': 'Virtual', 'apppath': ['Virtual', 'Add', 'vCenter'], 'form': form}
        updateMenuNumbers(request, context)
        updateClientsOSnrlist(request, context)
        return render(request, 'vmhosts/addvcenter.html', context)
    else:
        # print request.POST
        add = request.POST.get('add', 0)
        cancel = request.POST.get('cancel', 0)
        if add and not cancel:
            form = vCenterForm(data=request.POST, clients=clients, departments=departments)
            if form.is_valid():
                name = form.cleaned_data['name'].encode('ascii', 'ignore')
                descr = form.cleaned_data['descr']
                username = form.cleaned_data['username']
                password = form.cleaned_data['password']
                encpass = getencpass(name, password)
                address = form.cleaned_data['address']
                url = form.cleaned_data['url']
                thumbprint = form.cleaned_data['thumbprint']
                clients = form.cleaned_data['client']
                depart = form.cleaned_data['departments']
                if depart in ['', ' ', '#']:
                    depart = None
                # create a Client resource and a Client component and all required resources
                with transaction.atomic():
                    vcenter = vCenterHosts(name=name, description=descr, username=username, password=encpass,
                                           address=address, url=url, thumbprint=thumbprint, department=depart)
                    vcenter.save()
                    for cl in clients:
                        clname = 'vmware-' + name + '-' + cl
                        createVMwareAlias(request, name=clname, client=cl, descr='VMware Proxy Client for ' + name,
                                          vcenter=name, department=depart)
                directorreload()
            else:
                messages.error(request, "Cannot validate a form: %s" % form.errors, extra_tags='Error')
    return redirect('vmsvcenterdefined')