Comments (4)
Why is the apache grammar builder being used? Also the quoted upstream_addr will give you a problem.
from lua_sandbox_extensions.
sorry it is a typo, and unquoted upstream_addr it works, so I did a little dig
if logformat is "$upstream_addr
- with a single quote
local log_format = '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" "$upstream_addr'
local grammar = clf.build_nginx_grammar(log_format)
local data = '10.100.27.90 - - [22/Dec/2016:14:32:22 +0800] "GET /index HTTP/1.1" 200 10057 "http://rid.p.nxin.com/login.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36" "-" "10.211.14.10:8080"'
local fields = grammar:match(data)
for _,u in pairs(fields.upstream_addr) do
print(u)
end
console
----
10.211.14.10:8080"
can a upstream_addr contains a quote?
from lua_sandbox_extensions.
my fix, this will get upstream_addr with quote
local l = require "lpeg"
l.locale(l)
local ip = require "lpeg.ip_address"
--[[ nginx upstream server config
config
server unix:!"$%&'()*+,-./:<>=?@[\]^_`\;\{|\}~abc.123你好;
server localhost;
server [::1];
output in access log
unix:!\x22$%&'()*+,-./:<>=?@[\x5C]^_`\x5C;\x5C{|\x5C}~abc.123\xE4\xBD\xA0\xE5\xA5\xBD
127.0.0.1:80
[::1]:80
]]--
-- 0 to 65535
local port = l.P"6553" * l.R"05"
+ l.P"655" * l.R"02" * l.digit
+ l.P"65" * l.R"04" * l.digit * l.digit
+ l.P"6" * l.R"04" * l.digit * l.digit * l.digit
+ l.R"15" * l.digit * l.digit * l.digit * l.digit
+ l.R"19" * l.digit^-3
local utf8 = l.P"\\x" * (l.R"09" + l.R"AF") * (l.R"09" + l.R"AF")
local safe_char = l.P"\\x5C" * l.S";{}" + l.P"\\x22" + l.P"\\x5C" + (l.R"\20\126" - l.S"\"\\;{}") + utf8
local unix_sock = l.P"unix:" * safe_char^1
local nginx_upstream_sep = ", "
local nginx_upstream_addr = l.C((unix_sock + (l.P"[" * ip.v6 * l.P"]" + ip.v4) * l.P":" * port) - l.S(nginx_upstream_sep))
-- test port
for i=1,65535 do
local s = tostring(i)
local m = l.C(port):match(s)
assert(m == s, s .. "not match" .. m)
end
-- test nginx_upstream_addr
print(nginx_upstream_addr:match(
"unix:!\x22$%&'()*+,-./:<>=?@[\\x5C]^_`\\x5C;\\x5C{|\\x5C}~abc.123\\xE4\\xBD\\xA0\\xE5\\xA5\\xBD"))
print(nginx_upstream_addr:match("192.168.0.1:80"))
print(nginx_upstream_addr:match("[2002:0:0:0:0:0:65e2:a259]:8888"))
I can pull a PR if needed
from lua_sandbox_extensions.
https://github.com/nxintech/Charlie/blob/master/logs/common_log_format.lua.patch
from lua_sandbox_extensions.
Related Issues (20)
- taskcluster - the project is NULL when there is treeherder data but no taskcluster route HOT 1
- taskcluster - remove the migration code HOT 1
- lfs - tail.lua is not erroring on an invalid checkpoint HOT 1
- taskcluster - update sql queries to handle latent billing data HOT 2
- taskcluster - update mozilla_com table with people.m.o data HOT 3
- taskcluster - deprecate derived_kind_costs
- taskcluster - add the calculated_taskgroup_bins scheduled query to source control
- taskcluster - derived_taskgroup_costs tweak HOT 3
- gcp - bigquery output load failure in the timer_event will not alert HOT 1
- taskcluster - refactor the live_log decoder HOT 1
- gcp - bigquery output 'hung' when the bq command never returned HOT 1
- papertrail - invalidate outdated checkpoints HOT 1
- Support s3-sqs extension
- taskcluster - generalize/simplify the nightly taskcluster backfill
- taskcluster - use the artifact list to determine what perfherder data is available
- taskcluster - investigate analysis.influx_workertype OOM termination
- es_index_from_timestamp behavior
- Travis CI free usage ends Dec 3; mozilla repos should switch to other CI platforms
- Do I have to install aws-cpp-sdk-core by myself?
- Migrate CircleCI from mozilla/cidockerbases:docker-latest HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua_sandbox_extensions.