[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [check/master] Add a user agent check for TBB



commit 9162164ad821bcebd4cf79d25bae6965128643d4
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Mon May 5 20:26:36 2014 -0700

    Add a user agent check for TBB
    
     * Warn if it isn't a known Firefox.
    
     * This is trac 9041.
---
 check.pot              |    3 +++
 handlers.go            |   18 ++++++++++++++++--
 public/base.html       |    2 +-
 public/img/tor-not.png |  Bin 0 -> 9745 bytes
 public/index.html      |   20 +++++++++++++++-----
 utils.go               |   11 +++++++++++
 6 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/check.pot b/check.pot
index 0b06910..ed65512 100644
--- a/check.pot
+++ b/check.pot
@@ -86,3 +86,6 @@ msgstr ""
 
 msgid "JavaScript is disabled."
 msgstr ""
+
+msgid "However, it does not appear to be the Tor Browser Bundle."
+msgstr ""
diff --git a/handlers.go b/handlers.go
index db5fe0b..3b220e0 100644
--- a/handlers.go
+++ b/handlers.go
@@ -20,6 +20,7 @@ type Page struct {
 	IsTor       bool
 	NotUpToDate bool
 	Small       bool
+	NotTBB      bool
 	Fingerprint string
 	OnOff       string
 	Lang        string
@@ -55,10 +56,22 @@ func RootHandler(Layout *template.Template, Exits *Exits, domain *gettext.Domain
 			return
 		}
 
+		// try to determine if it's TBB
+		notTBB := !LikelyTBB(r.UserAgent())
+
+		// users shouldn't be relying on check
+		// to determine the TBB is up-to-date
+		// always return false to this param
+		notUpToDate := IsParamSet(r, "uptodate")
+
 		// string used for classes and such
 		// in the template
 		if isTor {
-			onOff = "on"
+			if notTBB || notUpToDate {
+				onOff = "not"
+			} else {
+				onOff = "on"
+			}
 		} else {
 			onOff = "off"
 		}
@@ -66,8 +79,9 @@ func RootHandler(Layout *template.Template, Exits *Exits, domain *gettext.Domain
 		// instance of your page model
 		p := Page{
 			isTor,
-			IsParamSet(r, "uptodate"),
+			notUpToDate,
 			IsParamSet(r, "small"),
+			notTBB,
 			fingerprint,
 			onOff,
 			Lang(r),
diff --git a/public/base.html b/public/base.html
index bd46b69..366d912 100644
--- a/public/base.html
+++ b/public/base.html
@@ -13,7 +13,7 @@
       font-family: Helvetica, sans-serif;
       margin: 0;
     }
-    h1 { font-size: 2.4em; }
+    h1 { font-size: 2.2em; }
     a { text-decoration: none; }
     a:hover { text-decoration: underline; }
     ul { margin: 0; padding: 0; }
diff --git a/public/img/tor-not.png b/public/img/tor-not.png
new file mode 100644
index 0000000..591e7cd
Binary files /dev/null and b/public/img/tor-not.png differ
diff --git a/public/index.html b/public/index.html
index dec740a..82360a7 100644
--- a/public/index.html
+++ b/public/index.html
@@ -3,6 +3,7 @@
 {{ define "css" }}
   .on { color: green; }
   .off { color: red; }
+  .not { color: goldenrod; }
   .mid { margin: 3em 0; }
   .mid a {
     text-decoration: underline;
@@ -77,11 +78,20 @@
     {{ end }}
   </h1>
   <p>{{ GetText .Lang "Your IP address appears to be: " }} <strong>{{ .IP }}</strong></p>
-  {{ if And .IsTor .NotUpToDate }}
-    <p class="security">
-      {{ GetText .Lang "There is a security update available for the Tor Browser Bundle." }}<br />
-      {{ GetText .Lang "<a href=\"https://www.torproject.org/download/download-easy.html\";>Click here to go to the download page</a>" | UnEscaped }}
-    </p>
+  {{ if .IsTor }}
+      {{ if .NotUpToDate }}
+        <p class="security">
+          {{ GetText .Lang "There is a security update available for the Tor Browser Bundle." }}<br />
+          {{ GetText .Lang "<a href=\"https://www.torproject.org/download/download-easy.html\";>Click here to go to the download page</a>" | UnEscaped }}
+        </p>
+      {{ else }}
+        {{ if .NotTBB }}
+          <p class="security">
+            {{ GetText .Lang "However, it does not appear to be the Tor Browser Bundle." }}<br />
+            {{ GetText .Lang "<a href=\"https://www.torproject.org/download/download-easy.html\";>Click here to go to the download page</a>" | UnEscaped }}
+          </p>
+        {{ end }}
+      {{ end }}
   {{ end }}
   <p class="mid">
     {{ if .IsTor }}
diff --git a/utils.go b/utils.go
index 79ba81e..8e05a07 100644
--- a/utils.go
+++ b/utils.go
@@ -57,6 +57,17 @@ func GetHost(r *http.Request) (host string, err error) {
 	return
 }
 
+var TBBUserAgents = map[string]bool{
+	"Mozilla/5.0 (Windows NT 6.1; rv:10.0) Gecko/20100101 Firefox/10.0": true,
+	"Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0": true,
+	"Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0": true,
+}
+
+func LikelyTBB(ua string) bool {
+	_, ok := TBBUserAgents[ua]
+	return ok
+}
+
 var HaveManual = map[string]bool{
 	"ar":    true,
 	"cs":    true,

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits