Skip to content

Commit dfb979d

Browse files
committed
feat(menu): added menu password
1 parent 8cbc767 commit dfb979d

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

.deploy.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
22
debouncerInterval: 250,
3-
preReleaseExpirationDays: 21,
3+
preReleaseExpirationDays: 60,
44

55
//NOTE: to test the panel from LAN, change localhost to your LAN IP
66
//but the NUI will not work due to HTTPS->HTTP restrictions

resource/cl_main.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ CreateThread(function()
176176
'/txAdmin-menuAlignRight',
177177
'/txAdmin-menuPageKey',
178178
'/txAdmin-menuPlayerIdDistance',
179-
'/txAdmin-menuDrunkDuration'
179+
'/txAdmin-menuDrunkDuration',
180+
'/tx2faSecret'
180181
}
181182

182183
for _, suggestion in ipairs(suggestionsToRemove) do

resource/menu/client/cl_base.lua

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ lastTpCoords = false;
1414
-- Locals
1515
local noMenuReason = 'unknown reason'
1616
local awaitingReauth = false
17+
local passHelpMessage = 'To authenticate to txAdmin, use the command /txAdmin-reauth <password>.'
1718

1819
--- Logic to displaying the menu auth rejected snackbar
1920
local function displayAuthRejectedError()
20-
if noMenuReason == 'nui_admin_not_found' then
21+
if noMenuReason == 'password_required' then
22+
sendSnackbarMessage('error', passHelpMessage, false)
23+
elseif noMenuReason == 'nui_admin_not_found' then
2124
sendSnackbarMessage('error', 'nui_menu.misc.menu_not_admin', true)
2225
else
2326
sendSnackbarMessage('error', 'nui_menu.misc.menu_auth_failed', true, { reason = noMenuReason })
@@ -130,15 +133,25 @@ end)
130133

131134
--[[ Debug Events / Commands ]]
132135
-- Command/event to trigger a authentication attempt
136+
local authPassword = false
133137
local function retryAuthentication()
138+
if type(authPassword) ~= 'string' then
139+
return
140+
end
134141
debugPrint("^5[AUTH] Retrying menu authentication.")
135142
menuIsAccessible = false
136143
menuPermissions = {}
137144
sendMenuMessage('setPermissions', menuPermissions)
138-
TriggerServerEvent('txsv:checkIfAdmin')
145+
TriggerServerEvent('txsv:checkIfAdmin', authPassword)
139146
end
140147
RegisterNetEvent('txcl:reAuth', retryAuthentication)
141-
RegisterCommand('txAdmin-reauth', function()
148+
RegisterCommand('txAdmin-reauth', function(_, args)
149+
if type(args[1]) ~= 'string' then
150+
sendSnackbarMessage('error', passHelpMessage, false)
151+
return
152+
end
153+
154+
authPassword = args[1]
142155
sendSnackbarMessage('info', 'Retrying menu authentication.', false)
143156
awaitingReauth = true
144157
retryAuthentication()
@@ -158,7 +171,8 @@ CreateThread(function()
158171
TriggerEvent(
159172
'chat:addSuggestion',
160173
'/txAdmin-reauth',
161-
'Retries to authenticate the menu NUI.'
174+
'Retries to authenticate the menu NUI.',
175+
{ { name = "password", help = "2fa secret" } }
162176
)
163177
end)
164178

resource/sv_admins.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,30 @@ local function handleAuthFail(src, reason)
3535
end
3636

3737
-- Handle menu auth requests
38-
RegisterNetEvent('txsv:checkIfAdmin', function()
38+
RegisterNetEvent('txsv:checkIfAdmin', function(authPassword)
3939
local src = source
4040
local srcString = tostring(source)
41+
42+
--Early return if no password
43+
if type(authPassword) ~= 'string' or authPassword == '' then
44+
return TriggerClientEvent('txcl:setAdmin', src, false, false, 'password_required')
45+
end
4146
debugPrint('Handling authentication request from player #'..srcString)
4247

4348
-- Rate Limiter
4449
if type(failedAuths[srcString]) == 'number' and failedAuths[srcString] + attemptCooldown > GetGameTimer() then
4550
return handleAuthFail(source, "too many auth attempts")
4651
end
4752

53+
-- Check Password
54+
local expectedPassword = GetConvar('tx2faSecret', 'invalid')
55+
if expectedPassword == 'invalid' then
56+
return handleAuthFail(src, "invalid server 2FA configuration")
57+
end
58+
if authPassword ~= expectedPassword then
59+
return handleAuthFail(src, "invalid 2FA password")
60+
end
61+
4862
-- Prepping http request
4963
local url = "http://"..TX_LUACOMHOST.."/auth/self"
5064
local headers = {

0 commit comments

Comments
 (0)