Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // SJS file that receives violation reports and then responds with nothing. |
michael@0 | 2 | |
michael@0 | 3 | const CC = Components.Constructor; |
michael@0 | 4 | const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", |
michael@0 | 5 | "nsIBinaryInputStream", |
michael@0 | 6 | "setInputStream"); |
michael@0 | 7 | |
michael@0 | 8 | const STATE_KEY = "bug836922_ro_violations"; |
michael@0 | 9 | |
michael@0 | 10 | function handleRequest(request, response) |
michael@0 | 11 | { |
michael@0 | 12 | var query = {}; |
michael@0 | 13 | request.queryString.split('&').forEach(function (val) { |
michael@0 | 14 | var [name, value] = val.split('='); |
michael@0 | 15 | query[name] = unescape(value); |
michael@0 | 16 | }); |
michael@0 | 17 | |
michael@0 | 18 | if ('results' in query) { |
michael@0 | 19 | // if asked for the received data, send it. |
michael@0 | 20 | response.setHeader("Content-Type", "text/javascript", false); |
michael@0 | 21 | if (getState(STATE_KEY)) { |
michael@0 | 22 | response.write(getState(STATE_KEY)); |
michael@0 | 23 | } else { |
michael@0 | 24 | // no state has been recorded. |
michael@0 | 25 | response.write(JSON.stringify({})); |
michael@0 | 26 | } |
michael@0 | 27 | } else if ('reset' in query) { |
michael@0 | 28 | //clear state |
michael@0 | 29 | setState(STATE_KEY, JSON.stringify(null)); |
michael@0 | 30 | } else { |
michael@0 | 31 | // ... otherwise, just respond "ok". |
michael@0 | 32 | response.write("null"); |
michael@0 | 33 | |
michael@0 | 34 | var bodystream = new BinaryInputStream(request.bodyInputStream); |
michael@0 | 35 | var avail; |
michael@0 | 36 | var bytes = []; |
michael@0 | 37 | while ((avail = bodystream.available()) > 0) |
michael@0 | 38 | Array.prototype.push.apply(bytes, bodystream.readByteArray(avail)); |
michael@0 | 39 | |
michael@0 | 40 | var data = String.fromCharCode.apply(null, bytes); |
michael@0 | 41 | |
michael@0 | 42 | // figure out which test was violating a policy |
michael@0 | 43 | var testpat = new RegExp("testid=([a-z0-9_]+)"); |
michael@0 | 44 | var testid = testpat.exec(data)[1]; |
michael@0 | 45 | |
michael@0 | 46 | // store the violation in the persistent state |
michael@0 | 47 | var s = JSON.parse(getState(STATE_KEY) || "{}"); |
michael@0 | 48 | s[testid] ? s[testid]++ : s[testid] = 1; |
michael@0 | 49 | setState(STATE_KEY, JSON.stringify(s)); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 |