Skip to content

Commit

Permalink
{...}: refactor code.
Browse files Browse the repository at this point in the history
- Remove trailing dots
- Fix check for anonymous hosts
  • Loading branch information
maranda committed Jun 2, 2018
1 parent 61cce72 commit 0909927
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 65 deletions.
8 changes: 4 additions & 4 deletions plugins/incidents_handling/mod_incidents_handling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ local function list_incidents_command_handler(self, data, state)
local single_incident_layout = ih_lib.render_single(incidents[fields.ids])
return { status = "executing", actions = { "prev", "complete", default = "complete" }, form = single_incident_layout }, { step = 1, form_layout = single_incident_layout, id = fields.ids }
else
return { status = "completed", error = { message = "You need to select the report ID to continue." } }
return { status = "completed", error = { message = "You need to select the report ID to continue" } }
end
end
else
Expand All @@ -264,7 +264,7 @@ local function send_inquiry_command_handler(self, data, state)
local fields = send_inquiry_layout:data(data.form)

if not fields.hostname or not fields.id or not fields.server then
return { status = "completed", error = { message = "You must supply the server to quest, the involved incident host and the incident ID." } }
return { status = "completed", error = { message = "You must supply the server to quest, the involved incident host and the incident ID" } }
else
local iq_send = st.iq({ from = my_host, to = fields.server, type = "get" })
:tag("inquiry", { xmlns = xmlns_inc })
Expand All @@ -273,7 +273,7 @@ local function send_inquiry_command_handler(self, data, state)

module:log("debug", "Sending incident inquiry to %s", fields.server)
module:send(iq_send)
return { status = "completed", info = "Inquiry sent, if an answer can be obtained from the remote server it'll be listed between incidents." }
return { status = "completed", info = "Inquiry sent, if an answer can be obtained from the remote server it'll be listed between incidents" }
end
else
return { status = "executing", form = send_inquiry_layout }, "executing"
Expand All @@ -282,7 +282,7 @@ end

local function rr_command_handler(self, data, state, formtype)
local send_layout = ih_lib.get_incident_layout(formtype)
local err_no_fields = { status = "completed", error = { message = "You need to fill all fields, except the eventual related incident." } }
local err_no_fields = { status = "completed", error = { message = "You need to fill all fields, except the eventual related incident" } }
local err_proc = { status = "completed", error = { message = "There was an error processing your request, check out the syntax" } }

if state then
Expand Down
12 changes: 6 additions & 6 deletions plugins/mod_auth_anonymous.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ function new_default_provider(host)
local provider = { name = "anonymous" };

function provider.test_password(username, password)
return nil, "Password based auth not supported.";
return nil, "Password based auth not supported";
end

function provider.get_password(username)
return nil, "Password not available.";
return nil, "Password not available";
end

function provider.set_password(username, password)
return nil, "Password based auth not supported.";
return nil, "Password based auth not supported";
end

function provider.user_exists(username)
local user_session = my_host.sessions[username];
if not user_session then
return nil, "No anonymous user connected with that username.";
return nil, "No anonymous user connected with that username";
end

return true;
end

function provider.create_user(username, password)
return nil, "Account creation/modification not supported.";
return nil, "Account creation/modification not supported";
end

function provider.get_sasl_handler(session)
Expand All @@ -60,7 +60,7 @@ function new_default_provider(host)
end

if not test_mode and not multi_resourcing and my_host.sessions[username] then
return nil, "not-authorized", "You're allowed to have only one anonymous session at any given time, good bye.";
return nil, "not-authorized", "You're allowed to have only one anonymous session at any given time, good bye";
end

session.is_anonymous = true;
Expand Down
16 changes: 8 additions & 8 deletions plugins/mod_auth_internal_hashed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ function new_hashpass_provider(host)

if credentials.password ~= nil and string.len(credentials.password) ~= 0 then
if credentials.password ~= password then
return nil, "Auth failed. Provided password is incorrect.";
return nil, "Auth failed, provided password is incorrect";
end

if provider.set_password(username, credentials.password) == nil then
return nil, "Auth failed. Could not set hashed password from plaintext.";
return nil, "Auth failed, could not set hashed password from plaintext";
else
return true;
end
end

if credentials.iteration_count == nil or credentials.salt == nil or string.len(credentials.salt) == 0 then
return nil, "Auth failed. Stored salt and iteration count information is not complete.";
return nil, "Auth failed, stored salt and iteration count information is not complete";
end

local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, credentials.salt, credentials.iteration_count);
Expand All @@ -54,7 +54,7 @@ function new_hashpass_provider(host)
if valid and stored_key_hex == credentials.stored_key and server_key_hex == credentials.server_key then
return true;
else
return nil, "Auth failed. Invalid username, password, or password hash information.";
return nil, "Auth failed.. invalid username, password, or password hash information";
end
end

Expand All @@ -73,22 +73,22 @@ function new_hashpass_provider(host)
account.password = nil;
return datamanager.store(username, host, "accounts", account);
end
return nil, "Account not available.";
return nil, "Account not available";
end

function provider.user_exists(username)
local account = datamanager.load(username, host, "accounts");
if not account then
log("debug", "account not found for username '%s' at host '%s'", username, module.host);
return nil, "Auth failed. Invalid username";
return nil, "Auth failed, invalid username";
end
return true;
end

function provider.is_locked(username)
local account = datamanager.load(username, host, "accounts");
if not account then
return nil, "Auth failed. Invalid username";
return nil, "Auth failed, invalid username";
elseif account and account.locked then
return true;
end
Expand All @@ -98,7 +98,7 @@ function new_hashpass_provider(host)
function provider.unlock_user(username)
local account = datamanager.load(username, host, "accounts");
if not account then
return nil, "Auth failed. Invalid username";
return nil, "Auth failed, invalid username";
elseif account and account.locked then
account.locked = nil;
local bare_session = bare_sessions[username.."@"..host];
Expand Down
10 changes: 5 additions & 5 deletions plugins/mod_auth_internal_plain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function new_default_provider(host)
if password == credentials.password then
return true;
else
return nil, "Auth failed. Invalid username or password.";
return nil, "Auth failed, invalid username or password";
end
end

Expand All @@ -44,22 +44,22 @@ function new_default_provider(host)
account.password = password;
return datamanager.store(username, host, "accounts", account);
end
return nil, "Account not available.";
return nil, "Account not available";
end

function provider.user_exists(username)
local account = datamanager.load(username, host, "accounts");
if not account then
log("debug", "account not found for username '%s' at host '%s'", username, module.host);
return nil, "Auth failed. Invalid username";
return nil, "Auth failed, invalid username";
end
return true;
end

function provider.is_locked(username)
local account = datamanager.load(username, host, "accounts");
if not account then
return nil, "Auth failed. Invalid username";
return nil, "Auth failed, invalid username";
elseif account and account.locked then
return true;
end
Expand All @@ -69,7 +69,7 @@ function new_default_provider(host)
function provider.unlock_user(username)
local account = datamanager.load(username, host, "accounts");
if not account then
return nil, "Auth failed. Invalid username";
return nil, "Auth failed, invalid username";
elseif account and account.locked then
account.locked = nil;
local bare_session = bare_sessions[username.."@"..host];
Expand Down
4 changes: 2 additions & 2 deletions plugins/mod_gate_guard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ local function rr_hook(event)
end
module:log("info", "%s attempted to connect to a blocked remote host %s", stanza.attr.from or event.origin.full_jid, to_host);
if stanza.attr.type ~= "error" then
send(error_reply(event.stanza, "cancel", "policy-violation", "Communicating with a blocked remote server is not allowed."));
send(error_reply(event.stanza, "cancel", "policy-violation", "Communicating with a blocked remote server is not allowed"));
end
return true;
end
Expand Down Expand Up @@ -99,7 +99,7 @@ function module.add_host(module)
module:set_component_inheritable();

local host = module.host;
if not host.anonymous then
if not host.anonymous_host then
module:hook("route/remote", rr_hook, 500);
module:hook("stanza/jabber:server:dialback:result", function(event)
return filter(event.origin, event.stanza.attr.from, event.stanza.attr.to);
Expand Down
2 changes: 1 addition & 1 deletion plugins/mod_messagefilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local function message_filter(event)

if body_text then
local host = ahosts:contains(fromhost) and hosts[fromhost];
if not host or not host.anonymous then return; end
if not host or not host.anonymous_host then return; end

for _, pattern in ipairs(patterns) do
if body_text:match(pattern) then
Expand Down
2 changes: 1 addition & 1 deletion plugins/mod_muc_limits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module:hook("muc-fields-process", function(room, fields, stanza, changed)
room:set_option("limits_enabled", enabled, changed);
if enabled then
if not tonumber(stanzas) or not tonumber(seconds) then
return st.error_reply(stanza, "cancel", "forbidden", "You need to submit valid number values for muc_limits fields.");
return st.error_reply(stanza, "cancel", "forbidden", "You need to submit valid number values for muc_limits fields");
end
stanzas, seconds = math.max(tonumber(stanzas), 1), math.max(tonumber(seconds), 0);
room:set_option("limits_stanzas", stanzas, changed);
Expand Down
12 changes: 6 additions & 6 deletions plugins/mod_register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local additional_fields = module:get_option("additional_registration_fields", {}
local min_pass_len = module:get_option_number("register_min_pass_length", 8);
local max_pass_len = module:get_option_number("register_max_pass_length", 30);
local require_verification = module:get_option_boolean("register_require_verification", false);
local register_tos = module:get_option_string("register_tos", "By registering you implicitly accept our terms of service");
local register_tos = module:get_option_string("register_tos", "By registering you implicitly accept our terms of service.");

local field_map = {
username = { name = "username", type = "text-single", label = "Username", required = true };
Expand Down Expand Up @@ -110,7 +110,7 @@ local function validate_password(stanza, session, password)
session.send(st.error_reply(stanza, "modify", "policy-violation",
"Passwords must contain at least one digit or one special character, one uppercase letter " ..
"and must be at least " .. tostring(min_pass_len) .. " chars in length and not exceed " ..
tostring(max_pass_len) .. " chars."
tostring(max_pass_len) .. " chars"
));
return false;
end
Expand Down Expand Up @@ -259,7 +259,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event)
else
-- Check that the user is not blacklisted or registering too often
if match_ip(session.ip) or (whitelist_only and not match_ip(session.ip, true)) then
session.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not allowed to register an account."));
session.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not allowed to register an account"));
return true;
elseif min_seconds_between_registrations and not match_ip(session.ip, true) then
if not recent_ips[session.ip] then
Expand All @@ -280,13 +280,13 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event)
data.username, data.password = nil, nil;
local host = module.host;
if not username or username == "" then
session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid."));
session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid"));
elseif usermanager_user_exists(username, host) then
session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists."));
session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists"));
else
if not validate_password(stanza, session, password) then return true; end

local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk.");
local error_reply = st.error_reply(stanza, "wait", "internal-server-error", "Failed to write data to disk");
if usermanager_create_user(username, password, host, require_verification and true) then
if next(data) and not datamanager.store(username, host, "account_details", data) then
usermanager_delete_user(username, host, "mod_register");
Expand Down
8 changes: 4 additions & 4 deletions plugins/mod_server_presence.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ local function subscribe_command_handler(self, data, state)

local peer = fields.peerjid;
if not peer or peer == "" then
return { status = "completed", error = { message = "You need to supply the server QDN." } };
return { status = "completed", error = { message = "You need to supply the server QDN" } };
else
if peer == my_host then
return { status = "completed", error = { message = "I can't subscribe to myself!!! *rolls eyes*" } };
elseif subscribed[peer] then
return { status = "completed", error = { message = "I'm already subscribed to this entity." } };
return { status = "completed", error = { message = "I'm already subscribed to this entity" } };
end
local subscribe = st.presence({ to = peer, from = my_host, type = "subscribe" });
outbound[peer] = true;
module:send(subscribe);
datamanager.store("outbound", my_host, "server_presence", outbound);
return { status = "completed", info = "Subscription request sent." };
return { status = "completed", info = "Subscription request sent" };
end
else
return { status = "executing", form = layout }, "executing"
Expand Down Expand Up @@ -159,7 +159,7 @@ local function remove_command_handler(self, data, state)
end

if _changed then datamanager.store("subscribed", my_host, "server_presence", subscribed); end
return { status = "completed", info = "Done." };
return { status = "completed", info = "Done" };
else
return { status = "executing", form = layout }, "executing"
end
Expand Down
14 changes: 7 additions & 7 deletions plugins/mod_vjud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ local function search_process_handler(event)
if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")) return end

if form.attr.type == "cancel" then origin.send(st.reply(stanza)) ; return end
if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "You need to submit the search form.")) ; return end
if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "You need to submit the search form")) ; return end

local fields = search_form_layout():data(form)
if fields.FORM_TYPE ~= "jabber:iq:search" then
Expand Down Expand Up @@ -198,7 +198,7 @@ local function optin_command_handler(self, data, state)
local fields = optin_layout:data(data.form)
if restrict_to_hosts then
local node, host = jid_split(data.from)
if not restrict_to_hosts:contains(host) then return { status = completed, error = { message = "Signup to this directory is restricted." } } end
if not restrict_to_hosts:contains(host) then return { status = completed, error = { message = "Signup to this directory is restricted" } } end
end
if not fields.nickname and not fields.realname and not fields.country and not fields.email then
return { status = "completed", error = { message = "You need to fill at least one field." } }
Expand All @@ -210,10 +210,10 @@ local function optin_command_handler(self, data, state)
if datamanager.store("store", my_host, "directory", directory) then
return { status = "completed", info = "Success." }
else
return { status = "completed", error = { message = "Adding was successful but I failed to write to the directory store, please report to the admin." } }
return { status = "completed", error = { message = "Adding was successful but I failed to write to the directory store, please report to the admin" } }
end
else
return { status = "completed", error = { message = "You have already opted in, please opt out first, if you want to change your data." } }
return { status = "completed", error = { message = "You have already opted in, please opt out first, if you want to change your data" } }
end
end
else
Expand All @@ -226,7 +226,7 @@ local function optin_vcard_command_handler(self, data, state)
local jid = jid_bare(data.from)

if host ~= synchronize_to_host or not hosts[synchronize_to_host] then
return { status = completed, error = { message = "You can't signup to this directory sorry." } }
return { status = completed, error = { message = "You can't signup to this directory sorry" } }
end

local vcard = metronome.events.fire_event("vcard-synchronize", { node = node, host = host })
Expand All @@ -239,7 +239,7 @@ local function optin_vcard_command_handler(self, data, state)
if datamanager.store("store", my_host, "directory", directory) then
return { status = "completed", info = "Success." }
else
return { status = "completed", error = { message = "Adding was successful but I failed to write to the directory store, please report to the admin." } }
return { status = "completed", error = { message = "Adding was successful but I failed to write to the directory store, please report to the admin" } }
end
end

Expand All @@ -249,7 +249,7 @@ local function optout_command_handler(self, data, state)
if datamanager.store("store", my_host, "directory", directory) then
return { status = "completed", info = "You have been removed from the user directory." }
else
return { status = "completed", error = { message = "Removal was successful but I failed to write to the directory store, please report to the admin." } }
return { status = "completed", error = { message = "Removal was successful but I failed to write to the directory store, please report to the admin" } }
end
else
return { status = "completed", error = { message = "You need to optin first!" } }
Expand Down
8 changes: 4 additions & 4 deletions plugins/privacy/mod_privacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module:hook("iq-set/self/"..blocking_xmlns..":block", function(data)
simple_create_list(privacy_lists);
local entries = simple_process_entries(block);
if not entries then
origin.send(st.error_reply(stanza, "modify", "bad-request", "Item stanza is not well formed."));
origin.send(st.error_reply(stanza, "modify", "bad-request", "Item stanza is not well formed"));
return true;
end

Expand All @@ -121,7 +121,7 @@ module:hook("iq-set/self/"..blocking_xmlns..":block", function(data)

origin.send(st.reply(stanza));
else
origin.send(st.error_reply(stanza, "modify", "bad-request", "You need to specify at least one item to add."));
origin.send(st.error_reply(stanza, "modify", "bad-request", "You need to specify at least one item to add"));
end

store_save(origin.username, origin.host, "privacy", privacy_lists);
Expand All @@ -133,7 +133,7 @@ module:hook("iq-set/self/"..blocking_xmlns..":unblock", function(data)
local privacy_lists = store_load(origin.username);

if not privacy_lists or not privacy_lists.lists.simple then
origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Blocking list is empty."));
origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Blocking list is empty"));
return true;
end

Expand All @@ -144,7 +144,7 @@ module:hook("iq-set/self/"..blocking_xmlns..":unblock", function(data)

local entries = simple_process_entries(unblock);
if not entries then
origin.send(st.error_reply(stanza, "modify", "bad-request", "Item stanza is not well formed."));
origin.send(st.error_reply(stanza, "modify", "bad-request", "Item stanza is not well formed"));
return true;
end

Expand Down
Loading

0 comments on commit 0909927

Please sign in to comment.