Permalink
Browse files

Experinemts with colors

  • Loading branch information...
Bjarni R. Einarsson
Bjarni R. Einarsson committed Mar 29, 2011
1 parent 9c419ed commit aa087c665cd7c2cc4664025ce90a8e1b73ef6fd0
Showing with 65 additions and 4 deletions.
  1. +23 −0 HTTPD-PLAN.txt
  2. +31 −2 jsui/index.html
  3. +11 −2 pagekite.py
View
@@ -52,4 +52,27 @@ The HTTP UI should give human readable information about visits to a site.
This means adding visual cues such as grouping, pictures and colors so it
is easy to see that the same person is browsing your site.
+It should be possible to use clever mapping of IP addresses to colors, to
+make networks more recognizable:
+
+For example: a.b.c.d => rgb( (a+b+d)/3, (b+c+d)/3, (c+a+d)/3)
+
+def ip2rgb(ip):
+ # This basically gives each /24 it own hue, and then uses the final octet
+ # to tune the brightness. We avoid pitch-black and very bright colors.
+ o = [int(p) for p in ip.split('.')]
+ v = 55+( (19*o[3] + o[3]) % 180)
+ return '#%2.2x%2.2x%2.2x' % ( (v*o[0])/256, (v*o[1])/256, (v*o[2])/256 )
+
+for ip in ['10.1.2.3', '10.0.0.100', '127.0.0.1', '255.255.255.255',
+ '178.79.140.143', '69.164.211.158', '173.230.155.164',
+ '192.168.1.100', '192.168.1.1', '192.168.1.200', '192.168.1.56']:
+ print ('<span style="background: %s; color: #fff; ">%s</span>'
+ ) % (ip2rgb(ip), ip)
+
+10.1.2.3 => #030103
+192.168.1.1 => #5a2a30
+127.0.0.1 => #200020
+
+
View
@@ -1,5 +1,34 @@
-<html><title>
+<html><head>
<title>Hello world!</title>
-</title><body>
+</head><body>
<h1>Hello world!</h1>
+ <h2>Color test:</h2>
+
+<p>
+<span style="background: #040000; color: #fff; ">10.1.2.3</span>
+<span style="background: #020000; color: #fff; ">10.0.0.100</span>
+<span style="background: #250000; color: #fff; ">127.0.0.1</span>
+<span style="background: #954275; color: #fff; ">178.79.140.143</span>
+<span style="background: #29637f; color: #fff; ">69.164.211.158</span>
+<span style="background: #405539; color: #fff; ">173.230.155.164</span>
+<span style="background: #383100; color: #fff; ">192.168.1.100</span>
+<span style="background: #383100; color: #fff; ">192.168.1.1</span>
+<span style="background: #473e00; color: #fff; ">192.168.1.200</span>
+<span style="background: #473e00; color: #fff; ">192.168.1.56</span>
+</p>
+
+<p>
+<span style="background: #040000; color: #fff; ">10.1.2.3</span>
+<span style="background: #020000; color: #fff; ">10.0.0.100</span>
+<span style="background: #250000; color: #fff; ">127.0.0.1</span>
+<span style="background: #727272; color: #fff; ">255.255.255.255</span>
+<span style="background: #954275; color: #fff; ">178.79.140.143</span>
+<span style="background: #29637f; color: #fff; ">69.164.211.158</span>
+<span style="background: #405539; color: #fff; ">173.230.155.164</span>
+<span style="background: #383100; color: #fff; ">192.168.1.100</span>
+<span style="background: #383100; color: #fff; ">192.168.1.1</span>
+<span style="background: #473e00; color: #fff; ">192.168.1.200</span>
+<span style="background: #473e00; color: #fff; ">192.168.1.56</span>
+</p>
+
</body></html>
View
@@ -2519,7 +2519,7 @@ def ProcessChunk(self, data):
return False
else:
conn = UserConn.BackEnd(proto, host, sid, self, port,
- remote_ip=rIp, remote_port=rPort)
+ remote_ip=rIp, remote_port=rPort, data=data)
if proto in ('http', 'websocket'):
if not conn:
if not self.SendChunked('SID: %s\r\n\r\n%s' % (sid,
@@ -2671,7 +2671,8 @@ def _FrontEnd(conn, address, proto, host, on_port, body, conns):
('domain', self.host), ('is', 'FE')])
return None
- def _BackEnd(proto, host, sid, tunnel, on_port, remote_ip=None, remote_port=None):
+ def _BackEnd(proto, host, sid, tunnel, on_port,
+ remote_ip=None, remote_port=None, data=None):
# This is when we open a backend connection, because a user asked for it.
self = UserConn(None, ui=tunnel.conns.config.ui)
self.sid = sid
@@ -2704,6 +2705,14 @@ def _BackEnd(proto, host, sid, tunnel, on_port, remote_ip=None, remote_port=None
self.ui.Notify(('%s <=> %s://%s:%s (FAIL: no server)'
) % (remote_ip or 'unknown', proto, host, on_port),
prefix='?')
+
+ # FIXME: Do access control interception HERE.
+ # Non-HTTP protocols will just get rejected if they don't match,
+ # for HTTP we will do a captive portal kind of thing.
+ # For HTTP we are guaranteed to have the initial HTTP request in
+ # `data`, so we should be able to parse that for cookies etc.
+
+ if not backend:
logInfo.append(('err', 'No back-end'))
self.Log(logInfo)
return None

0 comments on commit aa087c6

Please sign in to comment.