Skip to content

Commit 3ac4348

Browse files
author
user
committed
More
1 parent 8683736 commit 3ac4348

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

lua/admin.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
-- Very limited "admin" interface via web.
2+
--
3+
-- Default password is "hello" so change that!
4+
--
15
-- see: https://github.com/openresty/lua-nginx-module#nginx-api-for-lua
26

37
-- must be before any content
@@ -12,7 +16,7 @@ if err then
1216
end
1317

1418
local curpw, _ = config_table:get('passwd')
15-
ngx.log(ngx.INFO, 'PW = ' .. curpw)
19+
--ngx.log(ngx.INFO, 'PW = ' .. curpw)
1620

1721
if args.pw ~= curpw then
1822
LOG("Wrong PW")

lua/pusher.lua

+3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ while true do
131131
wb:send_ping('')
132132
elseif msg == 'CLOSE' then
133133
wb:send_close()
134+
elseif msg == 'KILL' then
135+
wb:send_close()
136+
kill_session()
134137
else
135138
-- normal traffic on the channel; copy to websocket
136139
local ok, err = wb:send_text(msg)

python/cfcapp.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def ws_new_connection(self, wsid, fid):
160160
rv.created()
161161
return rv
162162

163-
def tx(self, msg, conn = None, fid=None, wsid=None, bcast=False):
163+
def tx(self, msg, conn=None, fid=None, wsid=None, bcast=False):
164164
'''
165165
Send a message via websocket to a specific browser, specific tab (wsid) or all
166166
@@ -185,17 +185,23 @@ def tx(self, msg, conn = None, fid=None, wsid=None, bcast=False):
185185

186186
def ws_close(self, wsid_or_conn):
187187
'''
188-
Close a specific web socket from server side; perhaps because it mis-behaved.
188+
Close a specific web socket from server side.
189189
190190
LUA code detects this message and kills it's connection.
191191
'''
192192
self.tx('CLOSE', wsid=getattr(wsid_or_conn, 'wsid', wsid_or_conn))
193193

194+
def ws_kill(self, conn):
195+
'''
196+
Close all web sockets from server side; because user mis-behaved, and
197+
also kill it's session on CFC. User will have to wait for javascript POW.
198+
'''
199+
self.tx('KILL', fid=conn.fid)
200+
194201
@setupmethod
195202
def ws_rx_handler(self, f):
196203
"""
197204
Registers a function to be called when traffic is received via web sockets
198-
199205
"""
200206
self.ws_rx_handlers.append(f)
201207
return f

python/example_app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def rx_data(vhost, conn, msg):
1212
app.tx(m, bcast=True)
1313

1414
class Robot(object):
15+
" Just a super-simple robot "
1516
def __init__(self):
1617
self.heard = set()
1718

@@ -30,7 +31,7 @@ def rx_data(vhost, conn, msg):
3031

3132
user = conn.fid[-8:].upper()
3233
if user not in self.heard:
33-
m = {'from': 'Robot1', 'content': "Hello %s" % user}
34+
m = {'from': 'Robot1', 'content': "Hello %s. Looking good!" % user}
3435
app.tx(m, bcast=True)
3536
self.heard.add(user)
3637

python/templates/chat.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727

2828
#output {
29-
max-height: 320px;
29+
height: 320px;
3030
overflow-y: scroll;
3131
}
3232

python/upload.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
#!/usr/bin/env python
22
#
3+
# A program to demonstate how to upload a static website into the CFC.
4+
#
5+
# You'd need to run it a few times:
6+
# - upload content with "upload.py multi path-to-topdir"
7+
# - commit that to disk in CFC: "upload.py write"
8+
# - add some redirects, like root => index.html
9+
# - ./upload.py redirect / /index.html
10+
#
11+
#
312
import os, sys, re, requests
413
from redis import Redis
514
import click

0 commit comments

Comments
 (0)