Beispiel #1
0
 def process_add(self, **kwargs): # We don't specify the args explicitly since we are using wtforms here.
     form = GroupAddForm(request_params())
     if form.validate():
         group = groups.create(name=form.name.data)
         auditlog.log(auditlog.CODE_CONTENT_ADD, target=group)
         notify_entity_activity(group, 'created')
         raise cherrypy.HTTPRedirect('/group/list')
     else:
         return render("group/add.html", {'form': form})
Beispiel #2
0
 def process_add(self, **kwargs):
     form = OperatorAddForm(request_params())
     form.access_id.choices = [(l.id, l.description) for l in access.list()]
     if form.validate():
         operator = operators.create(username=form.username.data,
                                     password=form.password.data,
                                     access_id=form.access_id.data)
         auditlog.log(auditlog.CODE_CONTENT_ADD, target=operator)
         notify_entity_activity(operator, 'created')
         raise cherrypy.HTTPRedirect('/user/list')
     else:
         return render('user/add.html', {'form': form })
Beispiel #3
0
 def process_add(self, **kwargs):
     form = AccessAddForm(request_params())
     if form.validate():
         level_mask = 0
         for i in form.levels.data:
             level_mask |= int(i)
 
         level = access.create(level_mask, form.description.data)
         auditlog.log(auditlog.CODE_CONTENT_ADD, target=level)
         notify_entity_activity(level, 'created')
         raise cherrypy.HTTPRedirect('/access/list')
     else:
         return render('access/add.html', {'form': form})
Beispiel #4
0
 def process_edit(self, **kwargs):
     """
     Updates a group (changes name).
     """
     form = GroupEditForm(request_params())
     if form.validate():
         (group, modified) = groups.modify(form.group_id.data, name=form.name.data)
     
         auditlog.log(auditlog.CODE_CONTENT_MOD, target=group, attributes_modified=modified)
         notify_entity_activity(group, 'updated')
         raise cherrypy.HTTPRedirect('/group/list')
     else:
         return render('group/edit.html', {'form': form})
Beispiel #5
0
 def process_add(self, **kwargs):
     form = PasswordAddForm(request_params())
     if form.validate():
         pw = passwords.create(username=form.username.data,
                               resource_id=form.resource_id.data,
                               password=form.password_decrypted.data,
                               description=form.description.data,
                               tags=form.tags.data)
         auditlog.log(auditlog.CODE_CONTENT_ADD, target=pw)
         notify_entity_activity(pw, 'created')
         raise cherrypy.HTTPRedirect('/resource/view/%d' % pw.resource_id)
     else:
         return render('password/add.html', {'form': form})
Beispiel #6
0
 def process_add(self, **kwargs):
     form = ResourceAddForm(request_params())
     form.group_ids.choices = [(g.id, g.label) for g in groups.list()]
     if form.validate():
         resource = resources.create(name=form.name.data,
                                     group_ids=form.group_ids.data,
                                     addr=form.addr.data,
                                     description=form.description.data, 
                                     notes=form.notes_decrypted.data,
                                     tags=form.tags.data) # XXX: process
         auditlog.log(auditlog.CODE_CONTENT_ADD, target=resource)
         notify_entity_activity(resource, 'created')
         raise cherrypy.HTTPRedirect('/resource/view/{0}'.format(resource.id))
     else:
         return render('resource/add.html', {'form': form })
Beispiel #7
0
 def process_edit(self, **kwargs):
     form = PasswordEditForm(request_params())
     if form.validate():
         (pw, modified) = passwords.modify(form.password_id.data, 
                                           username=form.username.data, 
                                           password=form.password_decrypted.data, 
                                           description=form.description.data,
                                           tags=form.tags.data)
 
         auditlog.log(auditlog.CODE_CONTENT_MOD, target=pw,
                      attributes_modified=modified)
         notify_entity_activity(pw, 'updated')
         raise cherrypy.HTTPRedirect('/resource/view/{0}'.format(pw.resource_id))
     else:
         log.warning("Form failed validation: {0}".format(form.errors))
         return render('password/edit.html', {'form': form})
Beispiel #8
0
 def delete(self, group_id):
     """
     Deletes a group.
     """
     group = groups.get(group_id)
     
     all_resources = group.resources.all()
     
     # This is very lazy (could be done in SQL), but simple/easy-to-debug.
     resources_only_in_this_group = []
     resources_in_other_groups_too = [] 
     for r in all_resources:
         if r.groups.all() == [group]:
             resources_only_in_this_group.append(r)
         else:
             resources_in_other_groups_too.append(r)
     
     if cherrypy.request.method == 'POST':
    
         # First remove any resources that are only owned by this group. 
         for r in resources_only_in_this_group:
             # Remove any passwords in this resource
             for pw in r.passwords:
                 del_pw = passwords.delete(pw.id)
                 auditlog.log(auditlog.CODE_CONTENT_DEL, target=del_pw)
             del_r = resources.delete(r.id)
             auditlog.log(auditlog.CODE_CONTENT_DEL, target=del_r)
         
         # Next we manually remove the group from any other resources that were associated
         # with this group.
         for r in resources_in_other_groups_too:
             group_ids = set([g.id for g in r.groups.all()])
             group_ids.remove(group.id)
             (mod_r, modified) = resources.modify(r.id, group_ids=group_ids)
             if modified:
                 auditlog.log(auditlog.CODE_CONTENT_MOD, target=mod_r, attributes_modified=modified)
         
         # And finally we can delete the group itself.
         group = groups.delete(group.id)
         auditlog.log(auditlog.CODE_CONTENT_DEL, target=group)
         
         notify_entity_activity(group, 'deleted')
         raise cherrypy.HTTPRedirect('/group/list')
     else:
         return render('group/delete.html', {'group_id': group_id,
                                             'del_resources': resources_only_in_this_group,
                                             'mod_resources': resources_in_other_groups_too})
Beispiel #9
0
 def process_edit(self, **kwargs):
     form = ResourceEditForm(request_params())
     form.group_ids.choices = [(g.id, g.label) for g in groups.list()]
     if form.validate():
         (resource, modified) = resources.modify(form.resource_id.data,
                                                 name=form.name.data,
                                                 addr=form.addr.data,
                                                 group_ids=form.group_ids.data,
                                                 notes=form.notes_decrypted.data,
                                                 description=form.description.data,
                                                 tags=form.tags.data) # XXX: process
         auditlog.log(auditlog.CODE_CONTENT_MOD, target=resource, attributes_modified=modified)
         notify_entity_activity(resource, 'updated')
         raise cherrypy.HTTPRedirect('/resource/view/{0}'.format(resource.id))
     else:
         log.warning("Form validation failed.")
         log.warning(form.errors)
         return render('resource/edit.html', {'form': form})
Beispiel #10
0
 def process_edit(self, **kwargs):
     log.debug("params = %r" % request_params())
     form = OperatorEditForm(request_params())
     form.access_id.choices = [(l.id, l.description) for l in access.list()]
     if form.validate():
         params = dict(operator_id=form.operator_id.data,
                       username=form.username.data,
                       access_id=form.access_id.data)
         
         # If password is blank, let's just not change it.
         if form.password.data:
             params['password'] = form.password.data
             
         (operator, modified) = operators.modify(**params)
         auditlog.log(auditlog.CODE_CONTENT_MOD, target=operator, attributes_modified=modified)
         notify_entity_activity(operator, 'updated')
         raise cherrypy.HTTPRedirect('/user/list')
     else:
         return render('user/edit.html', {'form': form, 'externally_managed': operator.externally_managed})
Beispiel #11
0
 def delete(self, resource_id, redirect_to=None):
     resource = resources.get(resource_id)
     if cherrypy.request.method == 'POST':
         
         # First remove any passwords for this resource.
         for pw in resource.passwords:
             del_pw = passwords.delete(pw.id)
             auditlog.log(auditlog.CODE_CONTENT_DEL, target=del_pw)
     
         # Then remove the actual resource
         resource = resources.delete(resource_id)
         auditlog.log(auditlog.CODE_CONTENT_DEL, target=resource)
         notify_entity_activity(resource, 'deleted')
         if redirect_to:
             raise cherrypy.HTTPRedirect(redirect_to)
         else:
             raise cherrypy.HTTPRedirect('/resource/list')
     else:
         return render('resource/delete.html', {'resource': resource,
                                                'redirect_to': redirect_to})
Beispiel #12
0
 def delete(self, access_id):
     level = access.delete(access_id)
     auditlog.log(auditlog.CODE_CONTENT_DEL, target=level)
     notify_entity_activity(level, 'deleted')
     raise cherrypy.HTTPRedirect('/access/list')
Beispiel #13
0
 def delete(self, operator_id):
     operator = operators.delete(operator_id)
     auditlog.log(auditlog.CODE_CONTENT_DEL, target=operator)
     notify_entity_activity(operator, 'deleted')
     raise cherrypy.HTTPRedirect('/user/list')
Beispiel #14
0
 def delete(self, password_id):
     pw = passwords.delete(password_id)
     auditlog.log(auditlog.CODE_CONTENT_DEL, target=pw)
     notify_entity_activity(pw, 'deleted')
     raise cherrypy.HTTPRedirect('/resource/view/%d' % int(pw.resource_id))