178c39eacc00df43a582ea70d94ecc1cc349e883
1 /***************************************************************************
2 * Copyright (C) 2003-2011 Polytechnique.org *
3 * http://opensource.polytechnique.org/ *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
21 var is_IE
= $.browser
.msie
;
23 // {{{ function getNow()
24 var days
= ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
25 var months
= ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
26 'août', 'septembre', 'octobre', 'novembre', 'décembre']
31 var mh
= dt
.getMonth();
32 var wd
= dt
.getDate();
33 var yr
= dt
.getYear();
34 if (yr
<1000) yr
+= 1900;
35 var hr
= dt
.getHours();
36 var mi
= dt
.getMinutes();
40 var se
= dt
.getSeconds();
45 $(".date-heure").html(days
[dy
] + ' ' + wd
+ ' ' + months
[mh
] + ' ' + yr
+ '<br />'
46 + hr
+ ':' + mi
+ ':' + se
);
52 function canAddSearchEngine()
54 if (((typeof window
.sidebar
== "object") && $.isFunction(window
.sidebar
.addSearchEngine
))
55 || ((typeof window
.external
== "object") && $.isFunction(window
.external
.AddSearchProvider
))) {
61 function addSearchEngine()
63 var searchURI
= "http://www.polytechnique.org/xorg.opensearch.xml";
64 if ((typeof window
.sidebar
== "object") && $.isFunction(window
.sidebar
.addSearchEngine
)) {
65 window
.sidebar
.addSearchEngine(
67 "http://www.polytechnique.org/images/xorg.png",
68 "Annuaire Polytechnique.org",
72 window
.external
.AddSearchProvider(searchURI
);
74 alert("Impossible d'installer la barre de recherche");
81 /***************************************************************************
85 // {{{ function goodiesPopup()
87 var __goodies_active
= true;
89 var __goodies_ical
= {
90 default_title
: 'Calendrier iCal',
93 'img': 'images/icons/calendar_view_day.gif',
94 'title': 'Calendrier iCal'},
95 {'url_prefix': 'http://www.google.com/calendar/render?cid=',
96 'img': 'images/goodies/add-google-calendar.gif',
97 'title': 'Ajouter à Google Calendar'},
98 {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
99 'img': 'images/goodies/add-google-calendar.gif',
100 'title': 'Ajouter à Google Apps / Calendar'}
104 var __goodies_rss
= {
105 default_title
: 'Fils RSS',
108 'img': 'images/icons/feed.gif',
110 {'url_prefix': 'http://fusion.google.com/add?feedurl=',
111 'img': 'images/goodies/add-google.gif',
112 'alt': 'Add to Google',
113 'title': 'Ajouter à iGoogle/Google Reader'},
114 {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=',
115 'img': 'images/goodies/add-netvibes.gif',
116 'title': 'Ajouter à Netvibes'},
117 {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=',
118 'img': 'images/goodies/add-yahoo.gif',
119 'alt': 'Add to My Yahoo!',
120 'title': 'Ajouter à My Yahoo!'}
124 function disableGoodiesPopups() {
125 __goodies_active
= false;
128 function goodiesPopup(node
, goodies
) {
129 var text
= '<div style="text-align: center; line-height: 2.2">';
130 for (var site
in goodies
.sites
) {
131 var entry
= goodies
.sites
[site
];
132 var s_alt
= entry
["alt"] ? entry
["alt"] : "";
133 var s_img
= entry
["img"];
134 var s_title
= entry
["title"] ? entry
["title"] : "";
135 var s_url
= entry
["url_prefix"].length
> 0 ? entry
["url_prefix"] + escape(this.href
) : this.href
;
137 text
+= '<a href="' + s_url
+ '"><img src="' + s_img
+ '" title="' + s_title
+ '" alt="' + s_alt
+ '"></a><br />';
139 text
+= '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
141 var title
= node
.title
? node
.title
: goodies
.default_title
;
146 if (__goodies_active
) {
147 return overlib(text
, CAPTION
, title
, CLOSETEXT
, 'Fermer', DELAY
, 800, STICKY
, WIDTH
, 150);
155 // {{{ function auto_links()
157 function auto_links() {
158 var url
= document
.URL
;
159 var fqdn
= url
.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
160 var light
= url
.indexOf('display=light') > url
.indexOf('?');
161 var resource_page
= url
.contains('rss') || url
.contains('ical');
163 $("a,link").each(function(i
) {
165 var href
= this.href
;
170 if(!href
|| node
.hasClass('xdx')
171 || href
.startsWith('mailto:') || href
.startsWith('javascript:')) {
174 if ((!href
.contains(fqdn
) && !this.className
.contains('popup')) || node
.hasClass('popup')) {
175 node
.click(function () {
180 if (href
.contains(fqdn
) && light
) {
181 href
= href
.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
184 rss
= href
.contains('rss');
185 ical
= href
.contains('ical');
187 if (!href
.startsWith('http')) {
188 href
= 'http://' + fqdn + '/' + href
;
191 if (this.nodeName
.toLowerCase() == 'a' && !resource_page
) {
192 if (rss
&& !href
.contains('prefs/rss') && (href
.contains('xml') || href
.contains('hash'))) {
193 goodiesPopup(this, __goodies_rss
);
195 goodiesPopup(this, __goodies_ical
);
198 if(matches
= (/^popup_([0-9]*)x([0-9]*)$/).exec(this.className
)) {
199 var w
= matches
[1], h
= matches
[2];
203 $('.popup2').popWin(840, 600);
204 $('.popup3').popWin(640, 800);
210 /***************************************************************************
214 // {{{ function checkPassword
216 /* {{{ SHA1 Implementation */
219 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
221 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
222 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
223 * Distributed under the BSD License
224 * See http://pajhome.org.uk/crypt/md5 for details.
228 * Configurable variables. You may need to tweak these to be compatible with
229 * the server-side, but the defaults work in most cases.
231 var hexcase
= 0; /* hex output format. 0 - lowercase; 1 - uppercase */
232 var b64pad
= ""; /* base-64 pad character. "=" for strict RFC compliance */
233 var chrsz
= 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
236 * These are the functions you'll usually want to call
237 * They take string arguments and return either hex or base-64 encoded strings
239 function hex_sha1(s
){return binb2hex(core_sha1(str2binb(s
),s
.length
* chrsz
));}
240 function b64_sha1(s
){return binb2b64(core_sha1(str2binb(s
),s
.length
* chrsz
));}
241 function str_sha1(s
){return binb2str(core_sha1(str2binb(s
),s
.length
* chrsz
));}
242 function hex_hmac_sha1(key
, data
){ return binb2hex(core_hmac_sha1(key
, data
));}
243 function b64_hmac_sha1(key
, data
){ return binb2b64(core_hmac_sha1(key
, data
));}
244 function str_hmac_sha1(key
, data
){ return binb2str(core_hmac_sha1(key
, data
));}
247 * Perform a simple self-test to see if the VM is working
249 function sha1_vm_test()
251 return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
255 * Calculate the SHA-1 of an array of big-endian words, and a bit length
257 function core_sha1(x
, len
)
260 x
[len
>> 5] |= 0x80 << (24 - len
% 32);
261 x
[((len
+ 64 >> 9) << 4) + 15] = len
;
270 for(var i
= 0; i
< x
.length
; i
+= 16)
278 for(var j
= 0; j
< 80; j
++)
280 if(j
< 16) w
[j
] = x
[i
+ j
];
281 else w
[j
] = rol(w
[j
-3] ^ w
[j
-8] ^ w
[j
-14] ^ w
[j
-16], 1);
282 var t
= safe_add(safe_add(rol(a
, 5), sha1_ft(j
, b
, c
, d
)),
283 safe_add(safe_add(e
, w
[j
]), sha1_kt(j
)));
291 a
= safe_add(a
, olda
);
292 b
= safe_add(b
, oldb
);
293 c
= safe_add(c
, oldc
);
294 d
= safe_add(d
, oldd
);
295 e
= safe_add(e
, olde
);
297 return Array(a
, b
, c
, d
, e
);
302 * Perform the appropriate triplet combination function for the current
305 function sha1_ft(t
, b
, c
, d
)
307 if(t
< 20) return (b
& c
) | ((~b
) & d
);
308 if(t
< 40) return b
^ c
^ d
;
309 if(t
< 60) return (b
& c
) | (b
& d
) | (c
& d
);
314 * Determine the appropriate additive constant for the current iteration
318 return (t
< 20) ? 1518500249 : (t
< 40) ? 1859775393 :
319 (t
< 60) ? -1894007588 : -899497514;
323 * Calculate the HMAC-SHA1 of a key and some data
325 function core_hmac_sha1(key
, data
)
327 var bkey
= str2binb(key
);
328 if(bkey
.length
> 16) bkey
= core_sha1(bkey
, key
.length
* chrsz
);
330 var ipad
= Array(16), opad
= Array(16);
331 for(var i
= 0; i
< 16; i
++)
333 ipad
[i
] = bkey
[i
] ^ 0x36363636;
334 opad
[i
] = bkey
[i
] ^ 0x5C5C5C5C;
337 var hash
= core_sha1(ipad
.concat(str2binb(data
)), 512 + data
.length
* chrsz
);
338 return core_sha1(opad
.concat(hash
), 512 + 160);
342 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
343 * to work around bugs in some JS interpreters.
345 function safe_add(x
, y
)
347 var lsw
= (x
& 0xFFFF) + (y
& 0xFFFF);
348 var msw
= (x
>> 16) + (y
>> 16) + (lsw
>> 16);
349 return (msw
<< 16) | (lsw
& 0xFFFF);
353 * Bitwise rotate a 32-bit number to the left.
355 function rol(num
, cnt
)
357 return (num
<< cnt
) | (num
>>> (32 - cnt
));
361 * Convert an 8-bit or 16-bit string to an array of big-endian words
362 * In 8-bit function, characters >255 have their hi-byte silently ignored.
364 function str2binb(str
)
367 var mask
= (1 << chrsz
) - 1;
368 for(var i
= 0; i
< str
.length
* chrsz
; i
+= chrsz
)
369 bin
[i
>>5] |= (str
.charCodeAt(i
/ chrsz
) & mask
) << (32 - chrsz
- i
%32);
374 * Convert an array of big-endian words to a string
376 function binb2str(bin
)
379 var mask
= (1 << chrsz
) - 1;
380 for(var i
= 0; i
< bin
.length
* 32; i
+= chrsz
)
381 str
+= String
.fromCharCode((bin
[i
>>5] >>> (32 - chrsz
- i
%32)) & mask
);
386 * Convert an array of big-endian words to a hex string.
388 function binb2hex(binarray
)
390 var hex_tab
= hexcase
? "0123456789ABCDEF" : "0123456789abcdef";
392 for(var i
= 0; i
< binarray
.length
* 4; i
++)
394 str
+= hex_tab
.charAt((binarray
[i
>>2] >> ((3 - i
%4)*8+4)) & 0xF) +
395 hex_tab
.charAt((binarray
[i
>>2] >> ((3 - i
%4)*8 )) & 0xF);
401 * Convert an array of big-endian words to a base-64 string
403 function binb2b64(binarray
)
405 var tab
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
407 for(var i
= 0; i
< binarray
.length
* 4; i
+= 3)
409 var triplet
= (((binarray
[i
>> 2] >> 8 * (3 - i
%4)) & 0xFF) << 16)
410 | (((binarray
[i
+1 >> 2] >> 8 * (3 - (i
+1)%4)) & 0xFF) << 8 )
411 | ((binarray
[i
+2 >> 2] >> 8 * (3 - (i
+2)%4)) & 0xFF);
412 for(var j
= 0; j
< 4; j
++)
414 if(i
* 8 + j
* 6 > binarray
.length
* 32) str
+= b64pad
;
415 else str
+= tab
.charAt((triplet
>> 6*(3-j
)) & 0x3F);
423 function hash_encrypt(a
) {
427 var hexa_h
= "0123456789abcdef";
430 return hexa_h
.charAt(a
);
434 return hexa_h
.indexOf(a
);
437 function hash_xor(a
, b
) {
447 for (k
= 0; k
< j
; k
++)
448 c
+= dechex(hexdec(a
.charAt(k
)) ^ hexdec(b
.charAt(k
)));
455 function getType(c
) {
456 if (c
>= 'a' && c
<= 'z') {
458 } else if (c
>= 'A' && c
<= 'Z') {
460 } else if (c
>= '0' && c
<= '9') {
467 function differentTypes(password
) {
470 for (i
= 0 ; i
< password
.length
; ++i
) {
471 var type
= getType(password
.charAt(i
));
472 if (prev
!= 0 && prev
!= type
) {
480 function passwordStrength(password
) {
483 var firstType
= true;
484 var types
= Array(0, 0, 0, 0, 0);
486 for (i
= 0 ; i
< password
.length
; ++i
) {
487 var type
= getType(password
.charAt(i
));
488 if (prev
!= 0 && prev
!= type
) {
493 if (types
[type
] == 0 && !firstType
) {
499 if (password
.length
< 6) {
507 } else if (prop
< 0) {
514 function checkPassword(box
, okLabel
) {
515 var password
= box
.value
;
516 var prop
= passwordStrength(password
);
522 } else if (prop
>= 35) {
531 $("#passwords_measure")
533 .animate({ width
: prop
+ "%",
534 backgroundColor
: color
537 .animate({ backgroundColor
: bgcolor
}, 750);
538 var submitButton
= $(":submit[name='" + passwordprompt_submit
+ "']");
539 if (ok
&& password
.length
>= 6 && differentTypes(password
)) {
540 submitButton
.attr("value", okLabel
);
541 submitButton
.removeAttr("disabled");
543 submitButton
.attr("value", "Mot de passe trop faible");
544 submitButton
.attr("disabled", "disabled");
548 function hashResponse(password1
, password2
, hasConfirmation
) {
549 pw1
= $('[name=' + password1
+ ']').val();
551 if (hasConfirmation
) {
552 pw2
= $('[name=' + password2
+ ']').val();
554 alert("\nErreur : les deux champs ne sont pas identiques !");
557 $('[name=' + password2
+ ']').val('');
558 } else if (pw1
== '********') {
562 if (pw1
.length
< 6) {
563 alert("\nErreur : le nouveau mot de passe doit faire au moins 6 caractères !");
566 if (!differentTypes(pw1
)) {
567 alert ("\nErreur : le nouveau mot de passe doit comporter au moins deux types de caractères parmi les suivants : lettres minuscules, lettres majuscules, chiffres, caractères spéciaux.");
571 alert("Le mot de passe que tu as rentré va être chiffré avant de nous parvenir par Internet ! Ainsi il ne circulera pas en clair.");
572 $('[name=' + password1
+ ']').val('');
573 $('[name=pwhash]').val(hash_encrypt(pw1
));
577 function correctUserName() {
578 var u
= document
.forms
.login
.username
;
579 // login with no space
580 if (u
.value
.indexOf(' ') < 0) return true;
581 var mots
= u
.value
.split(' ');
582 // jean paul.du pont -> jean-paul.du-pont
583 if (u
.value
.indexOf('.') > 0) { u
.value
= mots
.join('-'); return true; }
584 // jean dupont -> jean.dupont
585 if (mots
.length
== 2) { u
.value
= mots
[0]+"."+mots
[1]; return true; }
586 // jean dupont 2001 -> jean.dupont.2001
587 if (mots
.length
== 3 && mots
[2] > 1920 && mots
[2] < 3000) { u
.value
= mots
.join('.'); return true; }
588 // jean de la vallee -> jean.de-la-vallee
589 if (mots
[1].toUpperCase() == 'DE') { u
.value
= mots
[0]+"."+mots
.join('-').substr(mots
[0].length
+1); return true; }
590 // jean paul dupont -> jean-paul.dupont
591 if (mots
.length
== 3 && mots
[0].toUpperCase() == 'JEAN') { u
.value
= mots
[0]+"-"+mots
[1]+"."+mots
[2]; return true; }
593 alert('Ton email ne doit pas contenir de blanc.\nLe format standard est\n\nprenom.nom.promotion\n\nSi ton nom ou ton prenom est composé,\nsépare les mots par des -');
598 function doChallengeResponse() {
600 if (!correctUserName()) return false;
602 var new_pass
= hash_encrypt(document
.forms
.login
.password
.value
);
603 var old_pass
= hash_encrypt(document
.forms
.login
.password
.value
.substr(0, 10));
605 str
= document
.forms
.login
.username
.value
+ ":" +
607 document
.forms
.loginsub
.challenge
.value
;
609 document
.forms
.loginsub
.response
.value
= hash_encrypt(str
);
610 if (new_pass
!= old_pass
) {
611 document
.forms
.loginsub
.xorpass
.value
= hash_xor(new_pass
, old_pass
);
613 document
.forms
.loginsub
.username
.value
= document
.forms
.login
.username
.value
;
614 document
.forms
.loginsub
.remember
.value
= document
.forms
.login
.remember
.checked
;
615 document
.forms
.loginsub
.domain
.value
= document
.forms
.login
.domain
.value
;
616 document
.forms
.login
.password
.value
= "";
617 document
.forms
.loginsub
.submit();
620 function doChallengeResponseLogged() {
621 var new_pass
= hash_encrypt(document
.forms
.login
.password
.value
);
623 str
= document
.forms
.loginsub
.username
.value
+ ":" +
624 hash_encrypt(document
.forms
.login
.password
.value
) + ":" +
625 document
.forms
.loginsub
.challenge
.value
;
627 document
.forms
.loginsub
.response
.value
= hash_encrypt(str
);
628 document
.forms
.loginsub
.remember
.value
= document
.forms
.login
.remember
.checked
;
629 document
.forms
.login
.password
.value
= "";
630 document
.forms
.loginsub
.submit();
634 // {{{ send test email
636 function sendTestEmail(token
, hruid
)
638 var url
= 'emails/test';
639 var msg
= "Un email a été envoyé avec succès";
642 msg
+= " sur l'adresse de " + hruid
+ ".";
644 msg
+= " sur ton addresse.";
646 $('#mail_sent').successMessage($url
+ '?token=' + token
, msg
);
653 /***************************************************************************
660 setInterval(getNow
, 1000);
663 if ($(this).val() === 'Recherche dans l\'annuaire') {
666 $("#quick_button").show();
669 $("#quick_button").hide();
671 $("#quick_button").click(function() {
672 if ($("#quick").val() === 'Recherche dans l\'annuaire'
673 || $("#quick").val() === '') {
680 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: