diff --git a/.github/workflows/glua_lint.yml b/.github/workflows/glua_lint.yml new file mode 100644 index 0000000..bc3bcca --- /dev/null +++ b/.github/workflows/glua_lint.yml @@ -0,0 +1,10 @@ +name: GLuaFixer + +on: + pull_request: + +jobs: + Lint: + uses: CFC-Servers/github_action_workflows/.github/workflows/lint_glua.yml@feature/shareable + with: + config: "https://cfc.gg/configs/gluafixer/glualint.json" diff --git a/lua/autorun/cfc_http_whitelist_init.lua b/lua/autorun/cfc_http_whitelist_init.lua index f23ead3..a66dc70 100644 --- a/lua/autorun/cfc_http_whitelist_init.lua +++ b/lua/autorun/cfc_http_whitelist_init.lua @@ -8,8 +8,8 @@ local function includeClient( f ) end end -include("cfc_http_restrictions/config_loader.lua") -includeClient("cfc_http_restrictions/config_loader.lua") +include( "cfc_http_restrictions/config_loader.lua" ) +includeClient( "cfc_http_restrictions/config_loader.lua" ) includeClient( "cfc_http_restrictions/client/list_manager.lua" ) includeClient( "cfc_http_restrictions/client/list_view.lua" ) diff --git a/lua/cfc_http_restrictions/client/list_manager.lua b/lua/cfc_http_restrictions/client/list_manager.lua index a9cd63a..9c8c74f 100644 --- a/lua/cfc_http_restrictions/client/list_manager.lua +++ b/lua/cfc_http_restrictions/client/list_manager.lua @@ -7,14 +7,14 @@ function CFCHTTP.getAddress( url ) if cached then return cached end local pattern = "(%a+)://([%a%d%.-]+):?(%d*)/?.*" - local _, _, protocol, addr, port = string.find( url, pattern ) + local _, _, _, addr, _ = string.find( url, pattern ) parsedAddressCache[url] = addr return addr end -function CFCHTTP.isAssetURI(url) - return string.StartWith(url, "asset://") +function CFCHTTP.isAssetURI( url ) + return string.StartWith( url, "asset://" ) end -- escapes all lua pattern characters and allows the use of * as a wildcard @@ -23,7 +23,7 @@ local function escapeAddr( addr ) if escapedCache[addr] then return escapedCache[addr] end local split = string.Split( addr, "*" ) - for i=1, #split do + for i = 1, #split do split[i] = string.PatternSafe( split[i] ) end @@ -32,10 +32,10 @@ local function escapeAddr( addr ) end -- TODO reimmplement caching -function CFCHTTP.getOptionsForURI(url) +function CFCHTTP.getOptionsForURI( url ) if not url then return CFCHTTP.config.defaultOptions end - if CFCHTTP.isAssetURI(url) then return CFCHTTP.config.defaultAssetURIOptions end + if CFCHTTP.isAssetURI( url ) then return CFCHTTP.config.defaultAssetURIOptions end local address = CFCHTTP.getAddress( url ) if not address then return CFCHTTP.config.defaultOptions end @@ -45,25 +45,25 @@ function CFCHTTP.getOptionsForURI(url) return options end - for allowedAddr, options in pairs( CFCHTTP.config.addresses ) do - if not options.pattern then + for allowedAddr, optionsAddr in pairs( CFCHTTP.config.addresses ) do + if not optionsAddr.pattern then allowedAddr = escapeAddr( allowedAddr ) end - if string.match( address, "^"..allowedAddr.."$" ) then - return options + if string.match( address, "^" .. allowedAddr .. "$" ) then + return optionsAddr end end - return CFCHTTP.config.defaultOptions + return CFCHTTP.config.defaultOptions end local function getUrlsInHTML( html ) local pattern = "%a+://[%a%d%.-]+:?%d*/?[a-zA-Z0-9%.]*" local urls = {} - for url in string.gmatch(html, pattern) do - table.insert(urls, url) + for url in string.gmatch( html, pattern ) do + table.insert( urls, url ) end return urls @@ -71,10 +71,10 @@ end function CFCHTTP.isHTMLAllowed( html ) local urls = getUrlsInHTML( html ) - for _, url in pairs(urls) do - local options = CFCHTTP.getOptionsForURI(url) - - if options and not options.allowed then + for _, url in pairs( urls ) do + local options = CFCHTTP.getOptionsForURI( url ) + + if options and not options.allowed then return false, url end end @@ -91,8 +91,8 @@ function CFCHTTP.allowAddress( addr ) end CFCHTTP.config.addresses[addr] = { - _edited=true, - allowed=true, + _edited = true, + allowed = true, } return true @@ -105,8 +105,8 @@ function CFCHTTP.blockAddress( addr ) end CFCHTTP.config.addresses[addr] = { - _edited=true, - allowed=false, + _edited = true, + allowed = false, } return true @@ -121,4 +121,4 @@ function CFCHTTP.removeAddress( addr ) CFCHTTP.config.addresses[addr] = nil return true -end \ No newline at end of file +end diff --git a/lua/cfc_http_restrictions/client/list_view.lua b/lua/cfc_http_restrictions/client/list_view.lua index c947a9d..7411870 100644 --- a/lua/cfc_http_restrictions/client/list_view.lua +++ b/lua/cfc_http_restrictions/client/list_view.lua @@ -7,13 +7,13 @@ local function removeByValue( listView, value ) end end -local function populatePanel( form ) +local function populatePanel( form ) local warning = vgui.Create( "DLabel" ) warning:SetText( "Adding a domain here could expose your ip to other players (and other vulnerabilities)" ) - warning:SetColor( Color(255, 0, 0) ) - warning:SetFont("GModToolHelp") + warning:SetColor( Color( 255, 0, 0 ) ) + warning:SetFont( "GModToolHelp" ) warning:SetWrap( true ) - warning:SetSize(300, 100) + warning:SetSize( 300, 100 ) form:AddItem( warning ) @@ -21,25 +21,25 @@ local function populatePanel( form ) form:CheckBox( "Log blocked requests", "cfc_http_restrictions_log_blocks" ) form:CheckBox( "Detailed logging", "cfc_http_restrictions_log_verbose" ) - local list = vgui.Create( "DListView") + local list = vgui.Create( "DListView" ) list:Dock( TOP ) list:SetMultiSelect( false ) list:AddColumn( "Address" ) list:AddColumn( "Allowed" ) - list:SetTall(300) + list:SetTall( 300 ) form:AddItem( list ) for k, v in pairs( CFCHTTP.config.addresses ) do - list:AddLine( k, (v and v.allowed) and "yes" or "no" ) + list:AddLine( k, ( v and v.allowed ) and "yes" or "no" ) end local textEntry, _ = form:TextEntry( "Address" ) - list.OnRowSelected = function( self, index, pnl ) + list.OnRowSelected = function( _, _, pnl ) textEntry:SetValue( pnl:GetColumnText( 1 ) ) end - local allow = form:Button("Allow") + local allow = form:Button( "Allow" ) allow.DoClick = function() local v = textEntry:GetValue() if not CFCHTTP.allowAddress( v ) then return end @@ -48,7 +48,7 @@ local function populatePanel( form ) list:AddLine( v, "yes" ) end - local block = form:Button("Block") + local block = form:Button( "Block" ) block.DoClick = function() local v = textEntry:GetValue() if not CFCHTTP.blockAddress( v ) then return end @@ -58,25 +58,25 @@ local function populatePanel( form ) end -- TODO when a config is removed we should reload the default values from the lua based configs instead of just removing it from the entire list - local remove = form:Button("Remove") + local remove = form:Button( "Remove" ) remove.DoClick = function() local v = textEntry:GetValue() if not CFCHTTP.removeAddress( v ) then return end removeByValue( list, v ) end - local save = form:Button("Save") + local save = form:Button( "Save" ) save.DoClick = function() - local conf = CFCHTTP.copyConfig(CFCHTTP.config) - for addr, options in pairs(conf.addresses) do + local conf = CFCHTTP.copyConfig( CFCHTTP.config ) + for addr, options in pairs( conf.addresses ) do if not options._edited then conf.addresses[addr] = nil end end - CFCHTTP.saveFileConfig({ + CFCHTTP.saveFileConfig( { version = "1", addresses = conf.addresses - }) + } ) end end diff --git a/lua/cfc_http_restrictions/client/wrap_functions.lua b/lua/cfc_http_restrictions/client/wrap_functions.lua index a2edee5..6262d1f 100644 --- a/lua/cfc_http_restrictions/client/wrap_functions.lua +++ b/lua/cfc_http_restrictions/client/wrap_functions.lua @@ -42,12 +42,12 @@ local function wrapHTTP() print( "HTTP wrapped, original function at '_G._HTTP'" ) HTTP = function( req ) - local options = CFCHTTP.getOptionsForURI(req.url) + local options = CFCHTTP.getOptionsForURI( req.url ) local isAllowed = options and options.allowed local noisy = options and options.noisy - local stack = string.Split(debug.traceback(), "\n") - logRequest( req.method, req.url, stack[3], isAllowed, noisy) + local stack = string.Split( debug.traceback(), "\n" ) + logRequest( req.method, req.url, stack[3], isAllowed, noisy ) local onFailure = req.failed if not isAllowed then if onFailure then onFailure( "URL is not whitelisted" ) end @@ -62,11 +62,11 @@ local function wrapFetch() print( "http.Fetch wrapped, original function at '_http_Fetch'" ) http.Fetch = function( url, onSuccess, onFailure, headers ) - local options = CFCHTTP.getOptionsForURI(url) + local options = CFCHTTP.getOptionsForURI( url ) local isAllowed = options and options.allowed local noisy = options and options.noisy - local stack = string.Split(debug.traceback(), "\n") + local stack = string.Split( debug.traceback(), "\n" ) logRequest( "GET", url, stack[3], isAllowed, noisy ) if not isAllowed then if onFailure then onFailure( "URL is not whitelisted" ) end @@ -82,11 +82,11 @@ local function wrapPost() print( "http.Post wrapped, original function at '_http_Post'" ) http.Post = function( url, params, onSuccess, onFailure, headers ) - local options = CFCHTTP.getOptionsForURI(url) + local options = CFCHTTP.getOptionsForURI( url ) local isAllowed = options and options.allowed local noisy = options and options.noisy - local stack = string.Split(debug.traceback(), "\n") + local stack = string.Split( debug.traceback(), "\n" ) logRequest( "POST", url, stack[3], isAllowed, noisy ) if not isAllowed then if onFailure then onFailure( "URL is not whitelisted" ) end @@ -103,7 +103,7 @@ local function wrapPlayURL() print( "sound.PlayURL wrapped, original function at _sound_PlayUrl" ) sound.PlayURL = function( url, flags, callback ) - local options = CFCHTTP.getOptionsForURI(url) + local options = CFCHTTP.getOptionsForURI( url ) local isAllowed = options and options.allowed local noisy = options and options.noisy @@ -121,32 +121,32 @@ end local function wrapHTMLPanel( panelName ) print( "Wrapping SetHTML and OpenURL for " .. panelName ) local funcName = function( functionName ) - return "_"..panelName.."_"..functionName + return "_" .. panelName .. "_" .. functionName end local controlTable = vgui.GetControlTable( panelName ) - + local setHTML = funcName( "SetHTML" ) local openURL = funcName( "OpenURL" ) _G[setHTML] = _G[setHTML] or controlTable.SetHTML _G[openURL] = _G[openURL] or controlTable.OpenURL - + controlTable.SetHTML = function( self, html, ... ) - local isAllowed, url = CFCHTTP.isHTMLAllowed( html ) + local isAllowed, url = CFCHTTP.isHTMLAllowed( html ) local stack = string.Split( debug.traceback(), "\n" ) logRequest( "GET", url, stack[3], isAllowed ) if not isAllowed then - html = [[