-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccesslog.ml
43 lines (34 loc) · 1.04 KB
/
accesslog.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
open Spotlib.Spot
open Orakuda.Std
open Regexp.Infix
open List
type t = {
time : string;
agent : string;
ip : string;
path : string
}
(*
let simplify_agent = <:s<\([^)]*\)//g>>
*)
let simplify_agent = id
let lines = Result.from_Ok & File.to_lines (Sys.argv.[1])
let accesses = flip filter_map lines (fun l ->
match l =~ <:m<(.*): access: connection for [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ from [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ \((.*)\) with X-Forwarded-For: ([^:]+): (.*)>> with
| None ->
!!% "??? %s@." l;
None
| Some p ->
Some { time = p#_1; agent = simplify_agent p#_2; ip = p#_3; path = p#_4 }
)
let agents = Hashtbl.create 101
let () = flip iter accesses & fun t -> incr & Hashtbl.find_or_add (fun _ -> ref 0) agents t.agent
let () =
Hashtbl.to_list agents
|> sort (fun x y -> compare !(snd y) !(snd x))
|> iter (fun (n, r) -> !!% "%d: %s@." !r n)
let () = flip iter accesses & fun t ->
match t.path =~ <:m<\?q=(.*)>> with
| None -> ()
| Some m ->
prerr_endline & Netencoding.Url.decode ~plus:true m#_1