- http_output_headers(web);
- EVENT_FD_WRITEABLE(web->conn->event.fde);
- web->output.output_pending = True;
+}
+
+
+/*
+ perform pre-authentication on every page is /scripting/preauth.esp
+ exists. If this script generates any non-whitepace output at all,
+ then we don't run the requested URL.
+
+ note that the preauth is run even for static pages such as images.
+*/
+static BOOL http_preauth(struct esp_state *esp)
+{
+ const char *path = http_local_path(esp->web, HTTP_PREAUTH_URI);
+ int i;
+ if (path == NULL) {
+ http_error(esp->web, 500, "Internal server error");
+ return False;
+ }
+ if (!file_exist(path)) {
+ /* if the preath script is not installed then allow access */
+ return True;
+ }
+ esp_request(esp, HTTP_PREAUTH_URI);
+ for (i=0;i<esp->web->output.content.length;i++) {
+ if (!isspace(esp->web->output.content.data[i])) {
+ /* if the preauth has generated content, then force it to be
+ html, so that we can show the login page for failed
+ access to images */
+ http_setHeader(esp->web, "Content-Type: text/html", 0);
+ return False;
+ }
+ }
+ data_blob_free(&esp->web->output.content);
+ return True;