utils.c: Use long rather than int for random() return value

This matches the random(3) definition even though with the % 64, we
only get a number in the range 0-63 back.

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_helpers: Add a add_csrf_token() function

Given a template varlist, this function will add a csrf token variable
to the list.

This is a common operation and makes sense to factor it out into its own
function.

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert receipt_info() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert delete_image() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert admin_add_user() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert admin_edit_user() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert prefs_fmap() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert prefs_edit_user() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert approve_receipts() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert process_receipt() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert receipts() to use add_csrf_token()

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Fix a memory leak in process_receipt()

We need to free the TMPL_varlist regardless of whether we sent the
template or not.

This would happen if the receipt info form was filled out correctly, we
wouldn't re-send the form for additional changes and the TMPL_varlist
wouldn't get free'd.

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
pagination; Factor main pagination code into its own fucntion

Several pages may need to be comprised of multiple pages and they
all do the commonn thing of displaying the right page navigation links
(if any) at the bottom of the page.

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert reviewed_receipts() to new pagination code

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
templates: admin_list_users: Fix page pagination links

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert admin_list_users() to new pagination code

The pagination was also broken here, we need to get the total of rows of
our query, not just the rows within the specified limits.

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert admin_pending_activations() to new pagination code

The pagination was also broken here, we need to get the total of
rows of our query, not just the rows within the specified limits.

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert approve_receipts() to new pagination code

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>
url_handlers: Convert tagged_receipts() to new pagination code

Signed-off-by: Andrew Clayton <andrew@opentechlabs.co.uk>