[tor-commits] [flashproxy/master] Add opt-in page html and javascript.

dcf at torproject.org dcf at torproject.org
Fri Dec 28 14:13:53 UTC 2012


commit 453589d0c15428428a48970c416be3748b90d7fd
Author: Alexandre Allaire <alexandre.allaire at mail.mcgill.ca>
Date:   Tue Dec 4 21:33:33 2012 -0500

    Add opt-in page html and javascript.
    
    Add some functional html and javascript for
    the opt-in page (ticket #7063). There is no CSS
    for the page yet.
---
 proxy/options.html |   32 +++++++++++++++++++++++++
 proxy/options.js   |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/proxy/options.html b/proxy/options.html
new file mode 100644
index 0000000..109c626
--- /dev/null
+++ b/proxy/options.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+<div>
+  <h4>Flash proxy options</h4>
+  <p>
+    This page enables you to use your web browser as a proxy to help
+    censored Internet users. When you click yes, your browser will act as a
+    censorship circumvention proxy as long as you are viewing a page with the
+    flash proxy badge: <img src="badge.png" alt="Internet Freedom">
+  </p>
+  <p>
+    <a href="http://crypto.stanford.edu/flashproxy/">For more information on this system click here</a>.
+  </p>
+</div>
+<div id="setting">
+</div>
+<div id="buttons" style="display: none;">
+  <button id="yes">Yes</button><button id="no">No</button>
+</div>
+<div id="cookies_disabled" style="display: none;">
+  <p>
+    It seems your browser has cookies disabled. You will need to enable them in
+    order to set flash proxy settings.
+  </p>
+</div>
+<script type="text/javascript" src="options.js"></script>
+</body>
+</html>
diff --git a/proxy/options.js b/proxy/options.js
new file mode 100644
index 0000000..9dd06d2
--- /dev/null
+++ b/proxy/options.js
@@ -0,0 +1,66 @@
+/* This is the javascript for the opt-in page. It sets/deletes
+   a cookie which controls whether the flashproxy javascript
+   code should run or disable itself. */
+
+var COOKIE_NAME = "flashproxy";
+/* In seconds. */
+var COOKIE_LIFETIME = 60 * 60 * 24 * 365;
+
+window.addEventListener("load", function () {
+
+    /* This checks if cookies are enabled in the browser.
+       document.cookie has special behavior, if cookies
+       are disabled it will not retain any values stored in it. */
+    function cookies_enabled() {
+        /*Not supported in all browsers.*/
+        if (navigator.cookieEnabled) {
+            return true;
+        } else if (navigator.cookieEnabled === undefined) {
+            document.cookie = "test";
+            if (document.cookie.indexOf("test") !== -1)
+                return true;
+        }
+        return false;
+    }
+
+    /* Updates the text telling the user what his current setting is.
+       According to the DOM level 2 specification,
+       http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038,
+       document.cookie is always defined and non-null, so this function
+       is safe if cookies are disabled. */
+    function update_setting_text() {
+        var setting = document.getElementById("setting");
+        var prefix = "<p>Your current setting is: ";
+
+        if (document.cookie.indexOf(COOKIE_NAME) !== -1) {
+            setting.innerHTML = prefix + "use my browser as a proxy. " +
+                                         "Click no below to change your setting.</p>";
+        } else {
+            setting.innerHTML = prefix + "do not use my browser as a proxy. " +
+                                         "Click yes below to change your setting.</p>";
+        }
+    }
+
+    function set_cookie() {
+        document.cookie = COOKIE_NAME + "=; max-age=" + COOKIE_LIFETIME;
+    }
+
+    function del_cookie() {
+        document.cookie = COOKIE_NAME + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
+    }
+
+    if (cookies_enabled()) {
+        var buttons = document.getElementById("buttons");
+        buttons.addEventListener("click", update_setting_text);
+        document.getElementById("yes").addEventListener("click", set_cookie);
+        document.getElementById("no").addEventListener("click", del_cookie);
+        buttons.style.display = "block";
+        update_setting_text();
+    } else {
+        document.getElementById("cookies_disabled").style.display = "block";
+        /* Manually set the text here as it refers to the buttons,
+           which won't show up if cookies are disabled. */
+        document.getElementById("setting").innerHTML = "<p>Your current setting is: " +
+                                                       "do not use my browser as a proxy.</p>";
+    }
+});





More information about the tor-commits mailing list