mod_register_redirect/mod_register_redirect.lua
changeset 784 c6f1427da79d
parent 783 d039a8dace3b
child 805 7e474c7f450a
equal deleted inserted replaced
783:d039a8dace3b 784:c6f1427da79d
    34 					inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..url:match("^%w+[:](.*)$")
    34 					inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..url:match("^%w+[:](.*)$")
    35 				else
    35 				else
    36 					module:log("error", "This module supports only http/https, mailto or xmpp as URL formats.")
    36 					module:log("error", "This module supports only http/https, mailto or xmpp as URL formats.")
    37 					module:log("error", "If you want to use personalized instructions without an Out-Of-Band method,")
    37 					module:log("error", "If you want to use personalized instructions without an Out-Of-Band method,")
    38 					module:log("error", "specify: register_oob = false; -- in your configuration along your banner string (register_text).")
    38 					module:log("error", "specify: register_oob = false; -- in your configuration along your banner string (register_text).")
    39 					origin.send(st.error_reply(stanza, "wait", "internal-server-error")) ; return true -- bouncing request.
    39 					return origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request.
    40 				end
    40 				end
    41 			else
    41 			else
    42 				module:log("error", "Please check your configuration, the URL you specified is invalid")
    42 				module:log("error", "Please check your configuration, the URL you specified is invalid")
    43 				origin.send(st.error_reply(stanza, "wait", "internal-server-error")) ; return true -- bouncing request.
    43 				return origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request.
    44 			end
    44 			end
    45 		else
    45 		else
    46 			if admins_l then
    46 			if admins_l then
    47 				local ajid; for _,v in ipairs(admins_l) do ajid = v ; break end
    47 				local ajid; for _,v in ipairs(admins_l) do ajid = v ; break end
    48 				inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..ajid
    48 				inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..ajid
    51 					local ajid; for _,v in ipairs(admins_g) do ajid = v ; break end
    51 					local ajid; for _,v in ipairs(admins_g) do ajid = v ; break end
    52 					inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..ajid
    52 					inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..ajid
    53 				else
    53 				else
    54 					module:log("error", "Please be sure to, _at the very least_, configure one server administrator either global or hostwise...")
    54 					module:log("error", "Please be sure to, _at the very least_, configure one server administrator either global or hostwise...")
    55 					module:log("error", "if you want to use this module, or read it's configuration wiki at: http://code.google.com/p/prosody-modules/wiki/mod_register_redirect")
    55 					module:log("error", "if you want to use this module, or read it's configuration wiki at: http://code.google.com/p/prosody-modules/wiki/mod_register_redirect")
    56 					origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request.
    56 					return origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request.
    57 					return true
       
    58 				end
    57 				end
    59 			end
    58 			end
    60 		end
    59 		end
    61 	elseif inst_text and url and oob then
    60 	elseif inst_text and url and oob then
    62 		if not url:match("^%w+[:].*$") then
    61 		if not url:match("^%w+[:].*$") then
    63 			module:log("error", "Please check your configuration, the URL specified is not valid.")
    62 			module:log("error", "Please check your configuration, the URL specified is not valid.")
    64 			origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request.
    63 			return origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request.
    65 		end
    64 		end
    66 	end
    65 	end
    67 
    66 
    68 	if not no_wl then
    67 	if not no_wl then
    69 		for i,ip in ipairs(ip_wl) do
    68 		for i,ip in ipairs(ip_wl) do
    83 		reply:query("jabber:iq:register")
    82 		reply:query("jabber:iq:register")
    84 			:tag("instructions"):text(inst_text):up()
    83 			:tag("instructions"):text(inst_text):up()
    85 	end
    84 	end
    86 	
    85 	
    87 	if stanza.attr.type == "get" then
    86 	if stanza.attr.type == "get" then
    88 		origin.send(reply)
    87 		return origin.send(reply)
    89 		return true
       
    90 	else
    88 	else
    91 		origin.send(st.error_reply(stanza, "cancel", "not-authorized"))
    89 		return origin.send(st.error_reply(stanza, "cancel", "not-authorized"))
    92 		return true
       
    93 	end
    90 	end
    94 end
    91 end
    95 
    92 
    96 module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10)
    93 module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10)