author | Dan |
Sun, 15 Jul 2007 11:41:06 -0400 | |
changeset 71 | 21770a1a5213 |
parent 60 | 71b50f8c8f85 |
child 74 | 68469a95658d |
permissions | -rw-r--r-- |
1 | 1 |
// Some additional DHTML functions |
2 |
||
3 |
function fetch_offset(obj) { |
|
4 |
var left_offset = obj.offsetLeft; |
|
5 |
var top_offset = obj.offsetTop; |
|
6 |
while ((obj = obj.offsetParent) != null) { |
|
7 |
left_offset += obj.offsetLeft; |
|
8 |
top_offset += obj.offsetTop; |
|
9 |
} |
|
10 |
return { 'left' : left_offset, 'top' : top_offset }; |
|
11 |
} |
|
12 |
||
13 |
function fetch_dimensions(o) { |
|
14 |
var w = o.offsetWidth; |
|
15 |
var h = o.offsetHeight; |
|
16 |
return { 'w' : w, 'h' : h }; |
|
17 |
} |
|
18 |
||
19 |
function findParentForm(o) |
|
20 |
{ |
|
21 |
// Not implemented - someone please let me know how to do this, what I need to do is |
|
22 |
// find the first parent <form> tag above param 'o', not sure how to do it with DOM |
|
23 |
} |
|
24 |
||
25 |
function ajaxReverseDNS(o, text) |
|
26 |
{ |
|
27 |
if(text) var ipaddr = text; |
|
28 |
else var ipaddr = o.innerHTML; |
|
29 |
rDnsObj = o; |
|
30 |
rDnsBannerObj = bannerOn('Retrieving reverse DNS info...'); |
|
31 |
ajaxGet(stdAjaxPrefix+'&_mode=rdns&ip='+ipaddr, function() { |
|
32 |
if(ajax.readyState == 4) |
|
33 |
{ |
|
34 |
off = fetch_offset(rDnsObj); |
|
35 |
dim = fetch_dimensions(rDnsObj); |
|
36 |
right = off['left'] + dim['w']; |
|
37 |
top = off['top'] + dim['h']; |
|
38 |
var thediv = document.createElement('div'); |
|
39 |
thediv.className = 'info-box'; |
|
40 |
thediv.style.margin = '0'; |
|
41 |
thediv.style.position = 'absolute'; |
|
42 |
thediv.style.top = top + 'px'; |
|
43 |
thediv.style.display = 'none'; |
|
44 |
thediv.style.zIndex = getHighestZ() + 2; |
|
45 |
thediv.id = 'mdgDynamic_rDnsInfoDiv_'+Math.floor(Math.random() * 1000000); |
|
46 |
thediv.innerHTML = '<b>Reverse DNS:</b><br />'+ajax.responseText+' <a href="#" onclick="elem = document.getElementById(\''+thediv.id+'\'); elem.innerHTML = \'\'; elem.style.display = \'none\';return false;">Close</a>'; |
|
47 |
var body = document.getElementsByTagName('body'); |
|
48 |
body = body[0]; |
|
49 |
bannerOff(rDnsBannerObj); |
|
50 |
body.appendChild(thediv); |
|
51 |
thediv.style.display = 'block'; |
|
52 |
left = fetch_dimensions(thediv); |
|
53 |
thediv.style.display = 'none'; |
|
54 |
left = right - left['w']; |
|
55 |
thediv.style.left = left + 'px'; |
|
56 |
thediv.style.display = 'block'; |
|
57 |
fadeInfoBoxes(); |
|
58 |
} |
|
59 |
}); |
|
60 |
} |
|
61 |
||
62 |
function bannerOn(text) |
|
63 |
{ |
|
64 |
darken(true); |
|
65 |
var thediv = document.createElement('div'); |
|
66 |
thediv.className = 'mdg-comment'; |
|
67 |
thediv.style.padding = '0'; |
|
68 |
thediv.style.marginLeft = '0'; |
|
69 |
thediv.style.position = 'absolute'; |
|
70 |
thediv.style.display = 'none'; |
|
71 |
thediv.style.padding = '4px'; |
|
72 |
thediv.style.fontSize = '14pt'; |
|
73 |
thediv.id = 'mdgDynamic_bannerDiv_'+Math.floor(Math.random() * 1000000); |
|
74 |
thediv.innerHTML = text; |
|
75 |
||
76 |
var body = document.getElementsByTagName('body'); |
|
77 |
body = body[0]; |
|
78 |
body.appendChild(thediv); |
|
79 |
body.style.cursor = 'wait'; |
|
80 |
||
81 |
thediv.style.display = 'block'; |
|
82 |
dim = fetch_dimensions(thediv); |
|
83 |
thediv.style.display = 'none'; |
|
84 |
bdim = { 'w' : getWidth(), 'h' : getHeight() }; |
|
85 |
so = getScrollOffset(); |
|
86 |
||
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
87 |
var left = (bdim['w'] / 2) - ( dim['w'] / 2 ); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
88 |
|
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
89 |
var top = (bdim['h'] / 2); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
90 |
top = top - ( dim['h'] / 2 ); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
91 |
|
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
92 |
top = top + so; |
1 | 93 |
|
94 |
thediv.style.top = top + 'px'; |
|
95 |
thediv.style.left = left + 'px'; |
|
96 |
||
97 |
thediv.style.display = 'block'; |
|
98 |
||
99 |
return thediv.id; |
|
100 |
} |
|
101 |
||
102 |
function bannerOff(id) |
|
103 |
{ |
|
104 |
e = document.getElementById(id); |
|
105 |
if(!e) return; |
|
106 |
e.innerHTML = ''; |
|
107 |
e.style.display = 'none'; |
|
108 |
var body = document.getElementsByTagName('body'); |
|
109 |
body = body[0]; |
|
110 |
body.style.cursor = 'default'; |
|
111 |
enlighten(true); |
|
112 |
} |
|
113 |
||
114 |
function disableUnload(message) |
|
115 |
{ |
|
116 |
if(typeof message != 'string') message = 'You may want to save your changes first.'; |
|
117 |
var body = document.getElementsByTagName('body'); |
|
118 |
body = body[0]; |
|
119 |
body.onbeforeunload='return unescape(\''+escape(message)+'\')'; |
|
120 |
} |
|
121 |
||
122 |
function enableUnload() |
|
123 |
{ |
|
124 |
var body = document.getElementsByTagName('body'); |
|
125 |
body = body[0]; |
|
126 |
body.onbeforeunload = null; |
|
127 |
} |
|
128 |
||
129 |
/** |
|
130 |
* Gets the highest z-index of all divs in the document |
|
131 |
* @return integer |
|
132 |
*/ |
|
133 |
function getHighestZ() |
|
134 |
{ |
|
135 |
z = 0; |
|
136 |
var divs = document.getElementsByTagName('div'); |
|
137 |
for(var i = 0; i < divs.length; i++) |
|
138 |
{ |
|
139 |
if(divs[i].style.zIndex > z) z = divs[i].style.zIndex; |
|
140 |
} |
|
141 |
return z; |
|
142 |
} |
|
143 |
||
144 |
function isKeyPressed(event) |
|
145 |
{ |
|
146 |
if (event.shiftKey==1) |
|
147 |
{ |
|
148 |
shift = true; |
|
149 |
} |
|
150 |
else |
|
151 |
{ |
|
152 |
shift = false; |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
function moveDiv(div, newparent) |
|
157 |
{ |
|
158 |
var backup = div; |
|
159 |
var oldparent = div.parentNode; |
|
160 |
oldparent.removeChild(div); |
|
161 |
newparent.appendChild(backup); |
|
162 |
} |
|
163 |
||
164 |
function readCookie(name) {var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;} |
|
165 |
function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";} |
|
166 |
function eraseCookie(name) {createCookie(name,"",-1);} |
|
167 |
||
168 |
var busyBannerID; |
|
169 |
function goBusy(msg) |
|
170 |
{ |
|
171 |
if(!msg) msg = 'Please wait...'; |
|
172 |
body = document.getElementsByTagName('body'); |
|
173 |
body = body[0]; |
|
174 |
body.style.cursor = 'wait'; |
|
175 |
busyBannerID = bannerOn(msg); |
|
176 |
} |
|
177 |
||
178 |
function unBusy() |
|
179 |
{ |
|
180 |
body = document.getElementsByTagName('body'); |
|
181 |
body = body[0]; |
|
182 |
body.style.cursor = 'default'; |
|
183 |
bannerOff(busyBannerID); |
|
184 |
} |
|
185 |
||
186 |
function setAjaxLoading() |
|
187 |
{ |
|
188 |
if ( document.getElementById('ajaxloadicon') ) |
|
189 |
{ |
|
190 |
document.getElementById('ajaxloadicon').src=scriptPath + '/images/loading.gif'; |
|
191 |
} |
|
192 |
} |
|
193 |
||
194 |
function unsetAjaxLoading() |
|
195 |
{ |
|
196 |
if ( document.getElementById('ajaxloadicon') ) |
|
197 |
{ |
|
198 |
document.getElementById('ajaxloadicon').src=scriptPath + '/images/spacer.gif'; |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
/* |
|
203 |
* Search boxes |
|
204 |
*/ |
|
205 |
||
206 |
function buildSearchBoxes() |
|
207 |
{ |
|
208 |
var divs = document.getElementsByTagName('*'); |
|
209 |
var boxes = new Array(); |
|
210 |
for ( var i = 0; i < divs.length; i++ ) |
|
211 |
{ |
|
212 |
if ( divs[i].className) |
|
213 |
{ |
|
214 |
if ( divs[i].className.substr(0, 9) == 'searchbox' ) |
|
215 |
{ |
|
216 |
boxes.push(divs[i]); |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
for ( var i = 0; i < boxes.length; i++ ) |
|
221 |
{ |
|
222 |
if ( boxes[i].className.match(/^searchbox\[([0-9]+)px\]$/) ) |
|
223 |
{ |
|
224 |
var width = boxes[i].className.match(/^searchbox\[([0-9]+)px\]$/); |
|
225 |
width = parseInt(width[1]); |
|
226 |
} |
|
227 |
else |
|
228 |
{ |
|
229 |
var width = 120; |
|
230 |
} |
|
231 |
createSearchBox(boxes[i], width); |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
function createSearchBox(parent, width) |
|
236 |
{ |
|
237 |
if ( typeof(parent) != 'object') |
|
238 |
{ |
|
239 |
alert('BUG: createSearchBox(): parent is not an object'); |
|
240 |
return false; |
|
241 |
} |
|
242 |
//parent.style.padding = '0px'; |
|
243 |
//parent.style.textAlign = 'center'; |
|
244 |
parent.style.width = width + 'px'; |
|
245 |
var submit = document.createElement('div'); |
|
246 |
submit.onclick = function() { searchFormSubmit(this); }; |
|
247 |
submit.className = 'js-search-submit'; |
|
248 |
var input = document.createElement('input'); |
|
249 |
input.className = 'js-search-box'; |
|
250 |
input.value = 'Search'; |
|
251 |
input.name = 'q'; |
|
252 |
input.style.width = ( width - 28 ) + 'px'; |
|
253 |
input.onfocus = function() { if ( this.value == 'Search' ) this.value = ''; }; |
|
254 |
input.onblur = function() { if ( this.value == '' ) this.value = 'Search'; }; |
|
255 |
parent.appendChild(input); |
|
256 |
var off = fetch_offset(input); |
|
257 |
var top = off['top'] + 'px'; |
|
258 |
var left = ( parseInt(off['left']) + ( width - 24 ) ) + 'px'; |
|
259 |
submit.style.top = top; |
|
260 |
submit.style.left = left; |
|
261 |
parent.appendChild(submit); |
|
262 |
} |
|
263 |
||
264 |
function searchFormSubmit(obj) |
|
265 |
{ |
|
266 |
var input = obj.previousSibling; |
|
267 |
if ( input.value == 'Search' || input.value == '' ) |
|
268 |
return false; |
|
269 |
var p = obj; |
|
270 |
while(true) |
|
271 |
{ |
|
272 |
p = p.parentNode; |
|
273 |
if ( !p ) |
|
274 |
break; |
|
275 |
if ( typeof(p.tagName) != 'string' ) |
|
276 |
break; |
|
277 |
else if ( p.tagName.toLowerCase() == 'form' ) |
|
278 |
{ |
|
279 |
p.submit(); |
|
280 |
} |
|
281 |
else if ( p.tagName.toLowerCase() == 'body' ) |
|
282 |
{ |
|
283 |
break; |
|
284 |
} |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
/* |
|
289 |
* AJAX login box (experimental) |
|
290 |
*/ |
|
291 |
||
292 |
var ajax_auth_prompt_cache = false; |
|
293 |
var ajax_auth_mb_cache = false; |
|
294 |
var ajax_auth_level_cache = false; |
|
295 |
||
296 |
function ajaxPromptAdminAuth(call_on_ok, level) |
|
297 |
{ |
|
298 |
if ( typeof(call_on_ok) == 'function' ) |
|
299 |
{ |
|
300 |
ajax_auth_prompt_cache = call_on_ok; |
|
301 |
} |
|
302 |
if ( !level ) |
|
60
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
303 |
level = USER_LEVEL_MEMBER; |
1 | 304 |
ajax_auth_level_cache = level; |
305 |
var loading_win = '<div align="center" style="text-align: center;"> \ |
|
306 |
<p>Fetching an encryption key...</p> \ |
|
307 |
<p><small>Not working? Use the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">alternate login form</a>.</p> \ |
|
308 |
<p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
|
309 |
</div>'; |
|
60
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
310 |
var title = ( level > USER_LEVEL_MEMBER ) ? 'You are requesting a sensitive operation.' : 'Please enter your username and password to continue.'; |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
311 |
ajax_auth_mb_cache = new messagebox(MB_OKCANCEL|MB_ICONLOCK, title, loading_win); |
1 | 312 |
ajax_auth_mb_cache.onbeforeclick['OK'] = ajaxValidateLogin; |
313 |
ajaxAuthLoginInnerSetup(); |
|
314 |
} |
|
315 |
||
316 |
function ajaxAuthLoginInnerSetup() |
|
317 |
{ |
|
318 |
ajaxGet(makeUrlNS('Special', 'Login', 'act=getkey'), function() { |
|
319 |
if ( ajax.readyState == 4 ) |
|
320 |
{ |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
321 |
var response = String(ajax.responseText); |
1 | 322 |
if ( response.substr(0,1) != '{' ) |
323 |
{ |
|
324 |
alert('Invalid JSON response from server: ' + response); |
|
325 |
return false; |
|
326 |
} |
|
327 |
response = parseJSON(response); |
|
60
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
328 |
var level = ajax_auth_level_cache; |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
329 |
var form_html = ''; |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
330 |
if ( level > USER_LEVEL_MEMBER ) |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
331 |
{ |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
332 |
form_html += 'Please re-enter your login details, to verify your identity.<br /><br />'; |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
333 |
} |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
334 |
form_html += ' \ |
1 | 335 |
<table border="0" align="center"> \ |
336 |
<tr> \ |
|
337 |
<td>Username:</td><td><input tabindex="1" id="ajaxlogin_user" type="text" size="25" /> \ |
|
338 |
</tr> \ |
|
339 |
<tr> \ |
|
340 |
<td>Password:</td><td><input tabindex="2" id="ajaxlogin_pass" type="password" size="25" /> \ |
|
341 |
</tr> \ |
|
342 |
<tr> \ |
|
343 |
<td colspan="2" style="text-align: center;"> \ |
|
60
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
344 |
<br /><small>Trouble logging in? Try the <a href="'+makeUrlNS('Special', 'Login/' + title)+'">full login form</a>.<br />'; |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
345 |
if ( level <= USER_LEVEL_MEMBER ) |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
346 |
{ |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
347 |
form_html += ' \ |
1 | 348 |
Did you <a href="'+makeUrlNS('Special', 'PasswordReset')+'">forget your password</a>?<br /> \ |
60
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
349 |
Maybe you need to <a href="'+makeUrlNS('Special', 'Register')+'">create an account</a>.</small>'; |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
350 |
} |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
351 |
form_html += ' \ |
1 | 352 |
</td> \ |
353 |
</tr> \ |
|
354 |
</table> \ |
|
355 |
<input type="hidden" id="ajaxlogin_crypt_key" value="' + response.key + '" /> \ |
|
356 |
<input type="hidden" id="ajaxlogin_crypt_challenge" value="' + response.challenge + '" /> \ |
|
357 |
</form>'; |
|
358 |
ajax_auth_mb_cache.updateContent(form_html); |
|
359 |
$('messageBox').object.nextSibling.firstChild.tabindex = '3'; |
|
60
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
360 |
if ( typeof(response.username) == 'string' ) |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
361 |
{ |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
362 |
$('ajaxlogin_user').object.value = response.username; |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
363 |
$('ajaxlogin_pass').object.focus(); |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
364 |
} |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
365 |
else |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
366 |
{ |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
367 |
$('ajaxlogin_user').object.focus(); |
71b50f8c8f85
Changed administration login request to use the AJAX login form; made high-level authentication more apparent in the AJAX box; recompiled Oxygen Mint
Dan
parents:
40
diff
changeset
|
368 |
} |
9
1e61232606d6
Following fixes: admin theme supports <button> tag now, PageProcessor can eval now, and SpecialAdmin.php plugin can no longer be disabled
dan@fuhry
parents:
1
diff
changeset
|
369 |
$('ajaxlogin_pass').object.onblur = function(e) { if ( !shift ) $('messageBox').object.nextSibling.firstChild.focus(); }; |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
370 |
$('ajaxlogin_pass').object.onkeypress = function(e) { if ( !e && IE ) return true; if ( e.keyCode == 13 ) $('messageBox').object.nextSibling.firstChild.click(); }; |
1 | 371 |
} |
372 |
}); |
|
373 |
} |
|
374 |
||
375 |
function ajaxValidateLogin() |
|
376 |
{ |
|
377 |
var username,password,auth_enabled,crypt_key,crypt_data,challenge_salt,challenge_data; |
|
378 |
username = document.getElementById('ajaxlogin_user'); |
|
379 |
if ( !username ) |
|
380 |
return false; |
|
381 |
username = document.getElementById('ajaxlogin_user').value; |
|
382 |
password = document.getElementById('ajaxlogin_pass').value; |
|
383 |
auth_enabled = false; |
|
384 |
||
385 |
disableJSONExts(); |
|
386 |
||
387 |
// |
|
388 |
// Encryption test |
|
389 |
// |
|
390 |
||
391 |
var str = ''; |
|
392 |
for(i=0;i<keySizeInBits/4;i++) |
|
393 |
{ |
|
394 |
str+='0'; |
|
395 |
} |
|
396 |
str = hexToByteArray(str); |
|
397 |
var ct = rijndaelEncrypt(str, str, 'ECB'); |
|
398 |
ct = byteArrayToHex(ct); |
|
399 |
var v; |
|
400 |
switch(keySizeInBits) |
|
401 |
{ |
|
402 |
case 128: |
|
403 |
v = '66e94bd4ef8a2c3b884cfa59ca342b2e'; |
|
404 |
break; |
|
405 |
case 192: |
|
406 |
v = 'aae06992acbf52a3e8f4a96ec9300bd7aae06992acbf52a3e8f4a96ec9300bd7'; |
|
407 |
break; |
|
408 |
case 256: |
|
409 |
v = 'dc95c078a2408989ad48a21492842087dc95c078a2408989ad48a21492842087'; |
|
410 |
break; |
|
411 |
} |
|
412 |
auth_enabled = ( ct == v && md5_vm_test() ); |
|
413 |
if ( !auth_enabled ) |
|
414 |
{ |
|
415 |
alert('Login error: encryption sanity check failed\n'); |
|
416 |
return true; |
|
417 |
} |
|
418 |
||
419 |
crypt_key = document.getElementById('ajaxlogin_crypt_key').value; |
|
420 |
challenge_salt = document.getElementById('ajaxlogin_crypt_challenge').value; |
|
421 |
||
422 |
var crypt_key_md5 = hex_md5(crypt_key); |
|
423 |
||
424 |
challenge_data = hex_md5(password + challenge_salt) + challenge_salt; |
|
425 |
||
426 |
password = stringToByteArray(password); |
|
427 |
crypt_key = hexToByteArray(crypt_key); |
|
428 |
||
429 |
crypt_data = rijndaelEncrypt(password, crypt_key, 'ECB'); |
|
430 |
crypt_data = byteArrayToHex(crypt_data); |
|
431 |
||
432 |
var json_data = { |
|
433 |
'username' : username, |
|
434 |
'crypt_key' : crypt_key_md5, |
|
435 |
'challenge' : challenge_data, |
|
436 |
'crypt_data' : crypt_data, |
|
437 |
'level' : ajax_auth_level_cache |
|
438 |
}; |
|
439 |
||
440 |
json_data = toJSONString(json_data); |
|
441 |
json_data = ajaxEscape(json_data); |
|
442 |
||
443 |
var loading_win = '<div align="center" style="text-align: center;"> \ |
|
444 |
<p>Logging in...</p> \ |
|
445 |
<p><img alt="Please wait..." src="'+scriptPath+'/images/loading-big.gif" /></p> \ |
|
446 |
</div>'; |
|
447 |
||
448 |
ajax_auth_mb_cache.updateContent(loading_win); |
|
449 |
||
450 |
ajaxPost(makeUrlNS('Special', 'Login', 'act=ajaxlogin'), 'params=' + json_data, function() { |
|
451 |
if ( ajax.readyState == 4 ) |
|
452 |
{ |
|
453 |
var response = ajax.responseText; |
|
454 |
if ( response.substr(0,1) != '{' ) |
|
455 |
{ |
|
456 |
alert('Invalid JSON response from server: ' + response); |
|
457 |
ajaxAuthLoginInnerSetup(); |
|
458 |
return false; |
|
459 |
} |
|
460 |
response = parseJSON(response); |
|
461 |
switch(response.result) |
|
462 |
{ |
|
463 |
case 'success': |
|
464 |
if ( typeof(ajax_auth_prompt_cache) == 'function' ) |
|
465 |
{ |
|
466 |
ajax_auth_prompt_cache(response.key); |
|
467 |
} |
|
468 |
break; |
|
469 |
case 'success_reset': |
|
470 |
var conf = confirm('You have logged in using a temporary password. Before you can log in, you must finish resetting your password. Do you want to reset your real password now?'); |
|
471 |
if ( conf ) |
|
472 |
{ |
|
473 |
var url = makeUrlNS('Special', 'PasswordReset/stage2/' + response.user_id + '/' + response.temppass); |
|
474 |
window.location = url; |
|
475 |
} |
|
476 |
else |
|
477 |
{ |
|
478 |
ajaxAuthLoginInnerSetup(); |
|
479 |
} |
|
480 |
break; |
|
481 |
case 'error': |
|
482 |
alert(response.error); |
|
483 |
ajaxAuthLoginInnerSetup(); |
|
484 |
break; |
|
485 |
default: |
|
486 |
alert(ajax.responseText); |
|
487 |
break; |
|
488 |
} |
|
489 |
} |
|
490 |
}); |
|
491 |
||
492 |
return true; |
|
493 |
||
494 |
} |
|
495 |
||
496 |
// This code is in the public domain. Feel free to link back to http://jan.moesen.nu/ |
|
497 |
function sprintf() |
|
498 |
{ |
|
499 |
if (!arguments || arguments.length < 1 || !RegExp) |
|
500 |
{ |
|
501 |
return; |
|
502 |
} |
|
503 |
var str = arguments[0]; |
|
504 |
var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/; |
|
505 |
var a = b = [], numSubstitutions = 0, numMatches = 0; |
|
506 |
while (a = re.exec(str)) |
|
507 |
{ |
|
508 |
var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4]; |
|
509 |
var pPrecision = a[5], pType = a[6], rightPart = a[7]; |
|
510 |
||
511 |
//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision); |
|
512 |
||
513 |
numMatches++; |
|
514 |
if (pType == '%') |
|
515 |
{ |
|
516 |
subst = '%'; |
|
517 |
} |
|
518 |
else |
|
519 |
{ |
|
520 |
numSubstitutions++; |
|
521 |
if (numSubstitutions >= arguments.length) |
|
522 |
{ |
|
523 |
alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).'); |
|
524 |
} |
|
525 |
var param = arguments[numSubstitutions]; |
|
526 |
var pad = ''; |
|
527 |
if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1); |
|
528 |
else if (pPad) pad = pPad; |
|
529 |
var justifyRight = true; |
|
530 |
if (pJustify && pJustify === "-") justifyRight = false; |
|
531 |
var minLength = -1; |
|
532 |
if (pMinLength) minLength = parseInt(pMinLength); |
|
533 |
var precision = -1; |
|
534 |
if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1)); |
|
535 |
var subst = param; |
|
536 |
if (pType == 'b') subst = parseInt(param).toString(2); |
|
537 |
else if (pType == 'c') subst = String.fromCharCode(parseInt(param)); |
|
538 |
else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0; |
|
539 |
else if (pType == 'u') subst = Math.abs(param); |
|
540 |
else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param); |
|
541 |
else if (pType == 'o') subst = parseInt(param).toString(8); |
|
542 |
else if (pType == 's') subst = param; |
|
543 |
else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase(); |
|
544 |
else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase(); |
|
545 |
} |
|
546 |
str = leftpart + subst + rightPart; |
|
547 |
} |
|
548 |
return str; |
|
549 |
} |
|
550 |
||
551 |
function paginator_goto(parentobj, this_page, num_pages, perpage, url_string) |
|
552 |
{ |
|
553 |
var height = $(parentobj).Height(); |
|
554 |
var width = $(parentobj).Width(); |
|
555 |
var left = $(parentobj).Left(); |
|
556 |
var top = $(parentobj).Top(); |
|
557 |
var left_pos = left + width ; |
|
558 |
var top_pos = height + top; |
|
559 |
var div = document.createElement('div'); |
|
560 |
div.style.position = 'absolute'; |
|
561 |
div.style.top = top_pos + 'px'; |
|
562 |
div.className = 'question-box'; |
|
563 |
div.style.margin = '1px 0 0 2px'; |
|
564 |
var vtmp = 'input_' + Math.floor(Math.random() * 1000000); |
|
565 |
div.innerHTML = 'Go to page:<br /><input type="text" size="2" style="padding: 1px; font-size: 8pt;" value="'+(parseInt(this_page)+1)+'" id="'+vtmp+'" /> <a href="#" onclick="paginator_submit(this, '+num_pages+', '+perpage+', unescape(\'' + escape(url_string) + '\')); return false;" style="font-size: 14pt; text-decoration: none;">»</a> <a href="#" onclick="fly_out_top(this.parentNode, false, true); return false;" style="font-size: 14pt; text-decoration: none;">×</a>'; |
|
566 |
||
567 |
var body = document.getElementsByTagName('body')[0]; |
|
568 |
body.appendChild(div); |
|
569 |
||
570 |
document.getElementById(vtmp).onkeypress = function(e){if(e.keyCode==13)this.nextSibling.nextSibling.onclick();}; |
|
571 |
document.getElementById(vtmp).focus(); |
|
572 |
||
573 |
// fade the div |
|
574 |
/* |
|
575 |
if(!div.id) div.id = 'autofade_'+Math.floor(Math.random() * 100000); |
|
576 |
var from = '#33FF33'; |
|
577 |
Fat.fade_element(div.id,30,2000,from,Fat.get_bgcolor(div.id)); |
|
578 |
*/ |
|
579 |
fly_in_bottom(div, false, true); |
|
580 |
||
581 |
var divh = $(div).Width(); |
|
582 |
left_pos = left_pos - divh; |
|
583 |
div.style.left = left_pos + 'px'; |
|
584 |
} |
|
585 |
||
586 |
function paginator_submit(obj, max, perpage, formatstring) |
|
587 |
{ |
|
588 |
var userinput = obj.previousSibling.previousSibling.value; |
|
589 |
userinput = parseInt(userinput); |
|
590 |
var offset = ( userinput - 1 ) * perpage; |
|
591 |
if ( userinput > max || isNaN(userinput) || userinput < 1 ) |
|
592 |
{ |
|
593 |
new messagebox(MB_OK|MB_ICONSTOP, 'Invalid entry', 'Please enter a page number between 1 and ' + max + '.'); |
|
594 |
return false; |
|
595 |
} |
|
596 |
var url = sprintf(formatstring, String(offset)); |
|
597 |
fly_out_top(obj.parentNode, false, true); |
|
598 |
window.location = url; |
|
599 |
} |
|
600 |