Example #1
0
func accessLogIndexAction(user *User, req *http.Request, session *Session, db *sqlx.Tx) response {
	selectedSecrets := getIntList(req, "secrets[]")
	selectedConsumers := getIntList(req, "consumers[]")
	selectedStates := getIntList(req, "status[]")

	// get current page
	page, err := strconv.Atoi(req.FormValue("page"))
	if err != nil {
		page = 0
	}

	if page < 0 {
		page = 0
	}

	limit := 25
	offset := page * limit

	accessLog := NewAccessLog(db)
	entries := accessLog.Find(selectedSecrets, selectedConsumers, selectedStates, limit, offset)
	total := accessLog.Count(selectedSecrets, selectedConsumers, selectedStates)

	pgr := pager.NewBasicPager(page, total, limit)
	data := &accessLogListData{layoutData: NewLayoutData("Access Log", "accesslog", user, session.CsrfToken)}

	data.Entries = entries
	data.Pager = pgr
	data.Secrets = []accessSecret{}
	data.Consumers = []accessConsumer{}
	data.States = make(map[int]bool)

	for _, secret := range findAllSecrets(false, db) {
		selected := isInIntList(secret.Id, selectedSecrets)
		data.Secrets = append(data.Secrets, accessSecret{secret.Id, secret.Name, selected})
	}

	for _, consumer := range findAllConsumers(db) {
		selected := isInIntList(consumer.Id, selectedConsumers)
		data.Consumers = append(data.Consumers, accessConsumer{consumer.Id, consumer.Name, selected})
	}

	for _, status := range selectedStates {
		data.States[status] = true
	}

	// re-create the query string
	url := url.Values{}
	addIntsToUrl(&url, "secrets[]", selectedSecrets)
	addIntsToUrl(&url, "consumers[]", selectedConsumers)
	addIntsToUrl(&url, "status[]", selectedStates)

	data.Query = template.URL(url.Encode())

	return renderTemplate(200, "access_log/index", data)
}
Example #2
0
func auditLogIndexAction(user *User, req *http.Request, session *Session, db *sqlx.Tx) response {
	selectedSecrets := getIntList(req, "secrets[]")
	selectedConsumers := getIntList(req, "consumers[]")
	selectedUsers := getIntList(req, "users[]")
	selectedCreators := getIntList(req, "creators[]")
	selectedActions := getStringList(req, "actions[]")

	// get current page
	page, err := strconv.Atoi(req.FormValue("page"))
	if err != nil {
		page = 0
	}

	if page < 0 {
		page = 0
	}

	limit := 25
	offset := page * limit

	auditLog := NewAuditLog(db, req)
	entries := auditLog.Find(selectedSecrets, selectedConsumers, selectedUsers, selectedCreators, selectedActions, limit, offset)
	total := auditLog.Count(selectedSecrets, selectedConsumers, selectedUsers, selectedCreators, selectedActions)

	pgr := pager.NewBasicPager(page, total, limit)
	data := &auditLogListData{layoutData: NewLayoutData("Audit Log", "auditlog", user, session.CsrfToken)}

	data.Entries = entries
	data.Pager = pgr
	data.Secrets = []auditSecret{}
	data.Consumers = []auditConsumer{}
	data.Users = []auditUser{}
	data.Creators = []auditUser{}
	data.Actions = make(map[string]bool)

	for _, secret := range findAllSecrets(false, db) {
		selected := isInIntList(secret.Id, selectedSecrets)
		data.Secrets = append(data.Secrets, auditSecret{secret.Id, secret.Name, selected})
	}

	for _, consumer := range findAllConsumers(db) {
		selected := isInIntList(consumer.Id, selectedConsumers)
		data.Consumers = append(data.Consumers, auditConsumer{consumer.Id, consumer.Name, selected})
	}

	for _, user := range findAllUsers(false, db) {
		selected := isInIntList(user.Id, selectedUsers)
		data.Users = append(data.Users, auditUser{user.Id, user.Name, selected})

		selected = isInIntList(user.Id, selectedCreators)
		data.Creators = append(data.Creators, auditUser{user.Id, user.Name, selected})
	}

	for _, action := range selectedActions {
		data.Actions[action] = true
	}

	// re-create the query string
	url := url.Values{}
	addIntsToUrl(&url, "secrets[]", selectedSecrets)
	addIntsToUrl(&url, "consumers[]", selectedConsumers)
	addIntsToUrl(&url, "users[]", selectedUsers)
	addIntsToUrl(&url, "creators[]", selectedCreators)

	if len(selectedActions) > 0 {
		for i, value := range selectedActions {
			if i == 0 {
				url.Set("actions[]", value)
			} else {
				url.Add("actions[]", value)
			}
		}
	}

	data.Query = template.URL(url.Encode())

	return renderTemplate(200, "audit_log/index", data)
}