annotate mod_register_json/mod_register_json.lua @ 663:a826b61c8f3a

mod_admin_web: Utilize the shared module magic
author Florian Zeitz <florob@babelmonkeys.de>
date Mon, 30 Apr 2012 17:25:09 +0200
parents aa3fbb33700d
children b0c0acccd7c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
1 -- Expose a simple servlet to handle user registrations from web pages
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
2 -- via JSON.
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
3 --
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
4 -- A Good chunk of the code is from mod_data_access.lua by Kim Alvefur
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
5 -- aka Zash.
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
6
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
7 local jid_prep = require "util.jid".prep
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
8 local jid_split = require "util.jid".split
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
9 local usermanager = require "core.usermanager"
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
10 local b64_decode = require "util.encodings".base64.decode
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
11 local json_decode = require "util.json".decode
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
12 local os_time = os.time
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
13 local nodeprep = require "util.encodings".stringprep.nodeprep
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
14
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
15 module:depends("http")
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
16
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
17 -- Pick up configuration.
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
18
651
78a23a7dc613 mod_register_json: fixed typo, added https/http switch and default value to it.
Marco Cirillo <maranda@lightwitch.org>
parents: 648
diff changeset
19 local secure = module:get_option_boolean("reg_servlet_secure", true)
560
b62f5e38f865 mod_register_json: added auto-cleanup logic to the module so it can at least be unloaded and reloaded without fuss. (Experimental: works with server_select and trunk)
Marco Cirillo <maranda@lightwitch.org>
parents: 553
diff changeset
20 local set_realm_name = module:get_option_string("reg_servlet_realm", "Restricted")
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
21 local base_path = module:get_option_string("reg_servlet_base", "/register_account/")
560
b62f5e38f865 mod_register_json: added auto-cleanup logic to the module so it can at least be unloaded and reloaded without fuss. (Experimental: works with server_select and trunk)
Marco Cirillo <maranda@lightwitch.org>
parents: 553
diff changeset
22 local throttle_time = module:get_option_number("reg_servlet_ttime", nil)
550
d8143f627f9f mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
Marco Cirillo <maranda@lightwitch.org>
parents: 548
diff changeset
23 local whitelist = module:get_option_set("reg_servlet_wl", {})
d8143f627f9f mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
Marco Cirillo <maranda@lightwitch.org>
parents: 548
diff changeset
24 local blacklist = module:get_option_set("reg_servlet_bl", {})
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
25 local recent_ips = {}
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
26
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
27 -- Begin
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
28
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
29 local function http_response(event, code, message, headers)
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
30 local response = event.response
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
31
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
32 if headers then
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
33 for header, data in pairs(headers) do response.headers[header] = data end
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
34 end
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
35
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
36 response.headers.content_type = "application/json"
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
37 response.status_code = code
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
38 response:send(message)
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
39 end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
40
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
41 local function handle_req(event)
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
42 local request = event.request
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
43 local body = request.body
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
44
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
45 if request.method ~= "POST" then
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
46 return http_response(event, 405, "Bad method...", {["Allow"] = "POST"})
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
47 end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
48 if not request.headers["authorization"] then
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
49 return http_response(event, 401, "No... No...", {["WWW-Authenticate"]='Basic realm="'.. set_realm_name ..'"'})
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
50 end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
51
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
52 local user, password = b64_decode(request.headers.authorization:match("[^ ]*$") or ""):match("([^:]*):(.*)")
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
53 user = jid_prep(user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
54 if not user or not password then return http_response(event, 400, "What's this..?") end
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
55 local user_node, user_host = jid_split(user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
56 if not hosts[user_host] then return http_response(event, 401, "Negative.") end
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
57
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
58 module:log("warn", "%s is authing to submit a new user registration data", user)
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
59 if not usermanager.test_password(user_node, user_host, password) then
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
60 module:log("warn", "%s failed authentication", user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
61 return http_response(event, 401, "Who the hell are you?! Guards!")
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
62 end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
63
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
64 local req_body
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
65 -- We check that what we have is valid JSON wise else we throw an error...
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
66 if not pcall(function() req_body = json_decode(body) end) then
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
67 module:log("debug", "JSON data submitted for user registration by %s failed to Decode.", user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
68 return http_response(event, 400, "JSON Decoding failed.")
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
69 else
363
72a5778579c5 mod_register_json: Let's call it the first commit, fixed all code errors (aka it works).
Marco Cirillo <maranda@lightwitch.org>
parents: 362
diff changeset
70 -- Decode JSON data and check that all bits are there else throw an error
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
71 req_body = json_decode(body)
363
72a5778579c5 mod_register_json: Let's call it the first commit, fixed all code errors (aka it works).
Marco Cirillo <maranda@lightwitch.org>
parents: 362
diff changeset
72 if req_body["username"] == nil or req_body["password"] == nil or req_body["host"] == nil or req_body["ip"] == nil then
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
73 module:log("debug", "%s supplied an insufficent number of elements or wrong elements for the JSON registration", user)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
74 return http_response(event, 400, "Invalid syntax.")
363
72a5778579c5 mod_register_json: Let's call it the first commit, fixed all code errors (aka it works).
Marco Cirillo <maranda@lightwitch.org>
parents: 362
diff changeset
75 end
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
76 -- Check if user is an admin of said host
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
77 if not usermanager.is_admin(user, req_body["host"]) then
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
78 module:log("warn", "%s tried to submit registration data for %s but he's not an admin", user, req_body["host"])
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
79 return http_response(event, 401, "I obey only to my masters... Have a nice day.")
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
80 else
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
81 -- Checks for both Throttling/Whitelist and Blacklist (basically copycatted from prosody's register.lua code)
550
d8143f627f9f mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
Marco Cirillo <maranda@lightwitch.org>
parents: 548
diff changeset
82 if blacklist:contains(req_body["ip"]) then module:log("warn", "Attempt of reg. submission to the JSON servlet from blacklisted address: %s", req_body["ip"]) ; return http_response(403, "The specified address is blacklisted, sorry sorry.") end
d8143f627f9f mod_register_json: modified code to employ get_option_set for true sets, and contains meta method
Marco Cirillo <maranda@lightwitch.org>
parents: 548
diff changeset
83 if throttle_time and not whitelist:contains(req_body["ip"]) then
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
84 if not recent_ips[req_body["ip"]] then
597
1004d7176be2 mod_register_json: cleanup unused stuff
Marco Cirillo <maranda@lightwitch.org>
parents: 566
diff changeset
85 recent_ips[req_body["ip"]] = os_time()
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
86 else
597
1004d7176be2 mod_register_json: cleanup unused stuff
Marco Cirillo <maranda@lightwitch.org>
parents: 566
diff changeset
87 if os_time() - recent_ips[req_body["ip"]] < throttle_time then
1004d7176be2 mod_register_json: cleanup unused stuff
Marco Cirillo <maranda@lightwitch.org>
parents: 566
diff changeset
88 recent_ips[req_body["ip"]] = os_time()
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
89 module:log("warn", "JSON Registration request from %s has been throttled.", req_body["ip"])
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
90 return http_response(503, "Woah... How many users you want to register..? Request throttled, wait a bit and try again.")
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
91 end
597
1004d7176be2 mod_register_json: cleanup unused stuff
Marco Cirillo <maranda@lightwitch.org>
parents: 566
diff changeset
92 recent_ips[req_body["ip"]] = os_time()
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
93 end
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
94 end
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
95
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
96 -- We first check if the supplied username for registration is already there.
430
f0fafd19fd72 mod_register_json: changed pestered code to something less pestered. (added nodeprep)
Marco Cirillo <maranda@lightwitch.org>
parents: 429
diff changeset
97 -- And nodeprep the username
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
98 local username = nodeprep(req_body["username"])
430
f0fafd19fd72 mod_register_json: changed pestered code to something less pestered. (added nodeprep)
Marco Cirillo <maranda@lightwitch.org>
parents: 429
diff changeset
99 if not usermanager.user_exists(username, req_body["host"]) then
f0fafd19fd72 mod_register_json: changed pestered code to something less pestered. (added nodeprep)
Marco Cirillo <maranda@lightwitch.org>
parents: 429
diff changeset
100 if not username then
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
101 module:log("debug", "%s supplied an username containing invalid characters: %s", user, username)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
102 return http_response(event, 406, "Supplied username contains invalid characters, see RFC 6122.")
429
ea6641deec12 mod_register_json: added check for invalid characters in the username.
Marco Cirillo <maranda@lightwitch.org>
parents: 370
diff changeset
103 else
553
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
104 local ok, error = usermanager.create_user(username, req_body["password"], req_body["host"])
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
105 if ok then
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
106 hosts[req_body["host"]].events.fire_event("user-registered", { username = username, host = req_body["host"], source = "mod_register_json", session = { ip = req_body["ip"] } })
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
107 module:log("debug", "%s registration data submission for %s@%s is successful", user, username, req_body["host"])
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
108 return http_response(event, 200, "Done.")
553
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
109 else
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
110 module:log("error", "user creation failed: "..error)
651
78a23a7dc613 mod_register_json: fixed typo, added https/http switch and default value to it.
Marco Cirillo <maranda@lightwitch.org>
parents: 648
diff changeset
111 return http_response(event, 500, "Encountered server error while creating the user: "..error)
553
7310ceb7564f mod_register_json: checking out if the user creation succeeded or not is good practice.
Marco Cirillo <maranda@lightwitch.org>
parents: 551
diff changeset
112 end
429
ea6641deec12 mod_register_json: added check for invalid characters in the username.
Marco Cirillo <maranda@lightwitch.org>
parents: 370
diff changeset
113 end
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
114 else
529
84e992f70ba3 mod_register_json: stick to one code "punctuation" style.
Marco Cirillo <maranda@lightwitch.org>
parents: 430
diff changeset
115 module:log("debug", "%s registration data submission for %s failed (user already exists)", user, username)
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
116 return http_response(event, 409, "User already exists.")
361
146496a3be78 mod_register_json: Failed at JSON successful decode check, fixed with a code refactor.
Marco Cirillo <maranda@lightwitch.org>
parents: 360
diff changeset
117 end
355
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
118 end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
119 end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
120 end
a5da789b2e7d mod_register_json: First commit (needs tests).
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
121
359
5d22ebcb9ec5 mod_register_json: Changed log levels, added a few primitive throttling/whitelist/blacklist options
Marco Cirillo <maranda@lightwitch.org>
parents: 358
diff changeset
122 -- Set it up!
560
b62f5e38f865 mod_register_json: added auto-cleanup logic to the module so it can at least be unloaded and reloaded without fuss. (Experimental: works with server_select and trunk)
Marco Cirillo <maranda@lightwitch.org>
parents: 553
diff changeset
123
655
81d269f97ea2 mod_register_json: revert change, it's not needed (providing http provides https as well)
Marco Cirillo <maranda@lightwitch.org>
parents: 651
diff changeset
124 module:provides("http", {
648
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
125 default_path = base_path,
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
126 route = {
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
127 ["GET /"] = handle_req,
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
128 ["POST /"] = handle_req
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
129 }
6f0e0d6790a7 mod_register_json: updated to current HTTP API.
Marco Cirillo <maranda@lightwitch.org>
parents: 607
diff changeset
130 })