summaryrefslogtreecommitdiff
path: root/swat2/scripting/preauth.esp
blob: e6d04faf8d9abf0faf946b2c01af0b0e3ca3439c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<%
include("/scripting/common.js");

/* this script is called on every web request. If it produces any
   output at all then that output is returned and the requested page
   is not given or processed.
*/ 

/*
  check if a uri is one of the 'always allowed' pages, even when not logged in
  This allows the login page to use the same style sheets and images
*/
function always_allowed(uri) {
	var str = string_init();

        /* allow jsonrpc-based applications to do their own authentication */
        var s = str.split('/', uri);
        if (s[0] == "" && s[1] == 'index.html') {
                return true;
        }

	var s = str.split('.', uri);
	if (s.length < 2) {
		return false;
	}

	var ext = s[s.length-1];
	var allowed = new Array("ico", "gif", "png","css", "js");
	for (i in allowed) {
		if (allowed[i] == ext) {
			return true;
		}
	}
	return false;
}


if (server['SERVER_PROTOCOL'] == "http" &&
    server['TLS_SUPPORT'] == "True") {
	write("redirect to https");
        redirect("https://" + headers['HOST'] + request['REQUEST_URI']);
} else if (always_allowed(request['REQUEST_URI']) != true && 
	   session['AUTHENTICATED'] == undefined) {
	/* present the login page */
	include("/login.esp");
}

%>