foist
[fingerprinter.git] / javascript / fetch_whorls.js
1 $("#flashcontent").flash(
2   {
3     "src": "/resources/fonts2.swf",
4     "width": "1",
5     "height": "1",
6     "swliveconnect": "true",
7     "id": "flashfontshelper",
8     "name": "flashfontshelper"
9   },
10   { update: false }
11 );
12
13 function identify_plugins(){
14   // fetch and serialize plugins
15   var plugins = "";
16   // in Mozilla and in fact most non-IE browsers, this is easy
17   if (navigator.plugins) {
18     var np = navigator.plugins;
19     var plist = new Array();
20     // sorting navigator.plugins is a right royal pain
21     // but it seems to be necessary because their order
22     // is non-constant in some browsers
23     for (var i = 0; i < np.length; i++) {
24       plist[i] = np[i].name + "; ";
25       plist[i] += np[i].description + "; ";
26       plist[i] += np[i].filename + ";";
27       for (var n = 0; n < np[i].length; n++) {
28         plist[i] += " (" + np[i][n].description +"; "+ np[i][n].type +
29                    "; "+ np[i][n].suffixes + ")";
30       }
31       plist[i] += ". ";
32     }
33     plist.sort(); 
34     for (i = 0; i < np.length; i++)
35       plugins+= "Plugin "+i+": " + plist[i];
36   }
37   // in IE, things are much harder; we use PluginDetect to get less
38   // information (only the plugins listed below & their version numbers)
39   if (plugins == "") {
40     var pp = new Array();
41     pp[0] = "Java"; pp[1] = "QuickTime"; pp[2] = "DevalVR"; pp[3] = "Shockwave";
42     pp[4] = "Flash"; pp[5] = "WindowsMediaplayer"; pp[6] = "Silverlight"; 
43     pp[7] = "VLC";
44     var version;
45     for ( p in pp ) {
46       version = PluginDetect.getVersion(pp[p]);
47       if (version) 
48         plugins += pp[p] + " " + version + "; "
49     }
50     plugins += ieAcrobatVersion();
51   }
52   return plugins;
53 }
54
55 function ieAcrobatVersion() {
56   // estimate the version of Acrobat on IE using horrible horrible hacks
57   if (window.ActiveXObject) {
58     for (var x = 2; x < 10; x++) {
59       try {
60         oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
61         if (oAcro) 
62           return "Adobe Acrobat version" + x + ".?";
63       } catch(ex) {}
64     }
65     try {
66       oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
67       if (oAcro4)
68         return "Adobe Acrobat version 4.?";
69     } catch(ex) {}
70     try {
71       oAcro7=new ActiveXObject('AcroPDF.PDF.1');
72       if (oAcro7)
73         return "Adobe Acrobat version 7.?";
74     } catch (ex) {}
75     return "";
76   }
77 }
78
79 function get_fonts() {
80   // Try flash first
81         var fonts = "";
82         var obj = document.getElementById("flashfontshelper");
83         if (obj && typeof(obj.GetVariable) != "undefined") {
84                 fonts = obj.GetVariable("/:user_fonts");
85     fonts = fonts.replace(/,/g,", ");
86     fonts += " (via Flash)";
87         } else {
88     // Try java fonts
89     try {
90       var javafontshelper = document.getElementById("javafontshelper");
91       var jfonts = javafontshelper.getFontList();
92       for (var n = 0; n < jfonts.length; n++) {
93         fonts = fonts + jfonts[n] + ", ";
94       }
95     fonts += " (via Java)";
96     } catch (ex) {}
97   }
98   if ("" == fonts)
99     fonts = "No Flash or Java fonts detected";
100   return fonts;
101 }
102
103 function set_dom_storage(){
104   try { 
105     localStorage.panopticlick = "yea";
106     sessionStorage.panopticlick = "yea";
107   } catch (ex) { }
108 }
109
110 function test_dom_storage(){
111   var supported = "";
112   try {
113     if (localStorage.panopticlick == "yea") {
114        supported += "DOM localStorage: Yes";
115     } else {
116        supported += "DOM localStorage: No";
117     }
118   } catch (ex) { supported += "DOM localStorage: No"; }
119
120   try {
121     if (sessionStorage.panopticlick == "yea") {
122        supported += ", DOM sessionStorage: Yes";
123     } else {
124        supported += ", DOM sessionStorage: No";
125     }
126   } catch (ex) { supported += ", DOM sessionStorage: No"; }
127
128   return supported;
129 }
130
131 function test_ie_userdata(){
132   try {
133     oPersistDiv.setAttribute("remember", "remember this value");
134     oPersistDiv.save("oXMLStore");
135     oPersistDiv.setAttribute("remember", "overwritten!");
136     oPersistDiv.load("oXMLStore");
137     if ("remember this value" == (oPersistDiv.getAttribute("remember"))) {
138       return ", IE userData: Yes";
139     } else { 
140       return ", IE userData: No";
141     }
142   } catch (ex) {
143       return ", IE userData: No";
144   }
145 }
146
147 var success = 0;
148 var retries = 20;
149
150 function retry_post() {
151   retries = retries -1;
152   if (success || retries == 0)
153     return 0;
154   // no luck yet
155   fetch_client_whorls()
156 }
157
158 function fetch_client_whorls(){
159   // fetch client-side vars
160   var whorls = new Object();
161
162   // this is a backup plan
163   setTimeout("retry_post()",1100);
164
165   try { 
166     whorls['plugins'] = identify_plugins(); 
167   } catch(ex) { 
168     whorls['plugins'] = "permission denied";
169   }
170
171   whorls['fonts'] = get_fonts();
172   
173   try { 
174     whorls['timezone'] = new Date().getTimezoneOffset();
175   } catch(ex) {
176     whorls['timezone'] = "permission denied";
177   }
178
179   try {
180     whorls['video'] = screen.width+"x"+screen.height+"x"+screen.colorDepth;
181   } catch(ex) {
182     whorls['video'] = "permission denied";
183   }
184
185   whorls['supercookies'] = test_dom_storage() + test_ie_userdata();
186
187   // send to server for logging / calculating
188   // and fetch results
189   $.post("/SaveDetails.php?saveData=true", whorls,
190     function(input){
191       success = 1;
192       $('#content').html(input);
193     }, "html" );
194   
195 };
196
197
198 set_dom_storage();
199
200 $(document).ready(function(){
201   // wait some time for the flash font detection:
202   setTimeout("fetch_client_whorls()",1000);
203 });