Last active
August 13, 2020 11:50
-
-
Save lshaf/dd534dc8a27092c5b15f78461455c15d to your computer and use it in GitHub Desktop.
Custom mysql lua script for vernemq.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- /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