]>
Commit | Line | Data |
---|---|---|
60024cc8 MT |
1 | $.query = function(name){ |
2 | var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); | |
3 | return results[1] || 0; | |
4 | } | |
5 | ||
6 | $("a.download-splash").click(function(event) { | |
7 | event.preventDefault(); | |
8 | linkLocation = this.href; | |
9 | ||
10 | window.location = "http://downloads.ipfire.org/download-splash?file="+linkLocation; | |
11 | }); | |
12 | ||
13 | if (/.*download-splash.*/i.test(window.location.href)) { | |
14 | $("p.download-path").ready(function(){ | |
15 | var valid = false; | |
16 | var allowed_prefixes = [ | |
17 | "http://downloads.ipfire.org/", | |
18 | ] | |
19 | ||
20 | var file_url = $.query("file"); | |
21 | ||
22 | // Only accept URLs beginning with our known prefix. | |
23 | for (i in allowed_prefixes) { | |
24 | prefix = allowed_prefixes[i]; | |
25 | if (file_url.substring(0, prefix.length) == prefix) { | |
26 | valid = true; | |
27 | } | |
28 | } | |
29 | ||
30 | if (valid) { | |
31 | $("p.download-path").prepend($("<a>", { | |
32 | href: encodeURI(file_url), | |
33 | text: file_url | |
34 | })) | |
35 | setTimeout(function() { window.location = file_url }, "2000"); | |
36 | } | |
37 | }); | |
38 | } | |
0e824faf MT |
39 | |
40 | function getCookie(name) { | |
41 | var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); | |
42 | return r ? r[1] : undefined; | |
43 | } | |
44 | ||
45 | jQuery.postJSON = function(url, args, callback) { | |
46 | args._xsrf = getCookie("_xsrf"); | |
47 | $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST", | |
48 | success: function(response) { | |
49 | callback(eval("(" + response + ")")); | |
50 | } | |
51 | }); | |
52 | }; |