Skip to content

Instantly share code, notes, and snippets.

@lshaf
Last active August 13, 2020 11:50
Show Gist options
  • Save lshaf/dd534dc8a27092c5b15f78461455c15d to your computer and use it in GitHub Desktop.
Save lshaf/dd534dc8a27092c5b15f78461455c15d to your computer and use it in GitHub Desktop.
Custom mysql lua script for vernemq.
-- /usr/share/vernemq/lua/auth/mysql.lua
-- Only replace the function
function auth_on_register(reg)
if reg.username ~= nil and reg.password ~= nil then
raw_client_id = reg.client_id
form_client_id = raw_client_id:gsub("#", "%")
results = mysql.execute(pool,
[[SELECT publish_acl, subscribe_acl
FROM vmq_auth_acl
WHERE
mountpoint = ? AND
? LIKE REPLACE(client_id, "#", "%") AND
username = ? AND
password = ]]..mysql.hash_method(),
reg.mountpoint,
reg.client_id,
reg.username,
reg.password)
if #results == 1 then
row = results[1]
publish_acl = json.decode(row.publish_acl)
subscribe_acl = json.decode(row.subscribe_acl)
cache_insert(
reg.mountpoint,
reg.client_id,
reg.username,
publish_acl,
subscribe_acl
)
return true
else
return false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment