diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2023-10-04 01:35:06 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2023-10-04 02:11:48 +0200 |
commit | 1a64deeb894dc95e2645a75771732c6cc53a79ad (patch) | |
tree | 1b9df4838f894577a09b9b260151756272efeb53 /systems/eldiron/webstats | |
parent | fa25ffd4583cc362075cd5e1b4130f33306103f0 (diff) | |
download | Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.tar.gz Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.tar.zst Nix-1a64deeb894dc95e2645a75771732c6cc53a79ad.zip |
Squash changes containing private information
There were a lot of changes since the previous commit, but a lot of them
contained personnal information about users. All thos changes got
stashed into a single commit (history is kept in a different place) and
private information was moved in a separate private repository
Diffstat (limited to 'systems/eldiron/webstats')
-rw-r--r-- | systems/eldiron/webstats/default.nix | 80 | ||||
-rw-r--r-- | systems/eldiron/webstats/goaccess.conf | 100 |
2 files changed, 180 insertions, 0 deletions
diff --git a/systems/eldiron/webstats/default.nix b/systems/eldiron/webstats/default.nix new file mode 100644 index 0000000..0057f64 --- /dev/null +++ b/systems/eldiron/webstats/default.nix | |||
@@ -0,0 +1,80 @@ | |||
1 | { lib, pkgs, config, ... }: | ||
2 | let | ||
3 | name = "goaccess"; | ||
4 | cfg = config.services.webstats; | ||
5 | in { | ||
6 | options.services.webstats = { | ||
7 | dataDir = lib.mkOption { | ||
8 | type = lib.types.path; | ||
9 | default = "/var/lib/${name}"; | ||
10 | description = '' | ||
11 | The directory where Goaccess stores its data. | ||
12 | ''; | ||
13 | }; | ||
14 | sites = lib.mkOption { | ||
15 | type = lib.types.listOf (lib.types.submodule { | ||
16 | options = { | ||
17 | conf = lib.mkOption { | ||
18 | type = lib.types.nullOr lib.types.path; | ||
19 | default = null; | ||
20 | description = '' | ||
21 | use custom goaccess configuration file instead of the | ||
22 | default one. | ||
23 | ''; | ||
24 | }; | ||
25 | name = lib.mkOption { | ||
26 | type = lib.types.str; | ||
27 | description = '' | ||
28 | Domain name. Corresponds to the Apache file name and the | ||
29 | folder name in which the state will be saved. | ||
30 | ''; | ||
31 | }; | ||
32 | }; | ||
33 | }); | ||
34 | default = []; | ||
35 | description = "Sites to generate stats"; | ||
36 | }; | ||
37 | }; | ||
38 | |||
39 | config = lib.mkIf (builtins.length cfg.sites > 0) { | ||
40 | environment.systemPackages = [ | ||
41 | pkgs.goaccess | ||
42 | ]; | ||
43 | |||
44 | services.cron = { | ||
45 | enable = true; | ||
46 | systemCronJobs = let | ||
47 | stats = domain: conf: let | ||
48 | config = if builtins.isNull conf | ||
49 | then pkgs.runCommand "goaccess.conf" { | ||
50 | dbPath = "${cfg.dataDir}/${domain}"; | ||
51 | } "substituteAll ${./goaccess.conf} $out" | ||
52 | else conf; | ||
53 | d = pkgs.writeScriptBin "stats-${domain}" '' | ||
54 | #!${pkgs.stdenv.shell} | ||
55 | set -e | ||
56 | shopt -s nullglob | ||
57 | TMPFILE=$(mktemp) | ||
58 | trap "rm -f $TMPFILE" EXIT | ||
59 | |||
60 | mkdir -p ${cfg.dataDir}/${domain} | ||
61 | for i in /var/log/httpd/access-${domain}*.gz /var/log/httpd/*/access-${domain}*.gz; do | ||
62 | zcat "$i" >> $TMPFILE | ||
63 | done | ||
64 | cat /var/log/httpd/*access-${domain}.log /var/log/httpd/*/access-${domain}.log > $TMPFILE | ||
65 | ${pkgs.goaccess}/bin/goaccess $TMPFILE --no-progress -o ${cfg.dataDir}/${domain}/index.html -p ${config} | ||
66 | ''; | ||
67 | in "${d}/bin/stats-${domain}"; | ||
68 | allStats = sites: pkgs.writeScript "stats" '' | ||
69 | #!${pkgs.stdenv.shell} | ||
70 | |||
71 | mkdir -p ${cfg.dataDir} | ||
72 | ${builtins.concatStringsSep "\n" (map (v: stats v.name v.conf) sites)} | ||
73 | ''; | ||
74 | in | ||
75 | [ | ||
76 | "5 0 * * * root ${allStats cfg.sites}" | ||
77 | ]; | ||
78 | }; | ||
79 | }; | ||
80 | } | ||
diff --git a/systems/eldiron/webstats/goaccess.conf b/systems/eldiron/webstats/goaccess.conf new file mode 100644 index 0000000..c6c244a --- /dev/null +++ b/systems/eldiron/webstats/goaccess.conf | |||
@@ -0,0 +1,100 @@ | |||
1 | time-format %H:%M:%S | ||
2 | date-format %d/%b/%Y | ||
3 | |||
4 | log-format VCOMBINED | ||
5 | #= %v:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u" | ||
6 | |||
7 | html-prefs {"theme":"bright","layout":"vertical"} | ||
8 | |||
9 | # old | ||
10 | exclude-ip 188.165.209.148 | ||
11 | exclude-ip 178.33.252.96 | ||
12 | exclude-ip 2001:41d0:2:9c94::1 | ||
13 | exclude-ip 2001:41d0:2:9c94:: | ||
14 | # eldiron | ||
15 | exclude-ip 176.9.151.89 | ||
16 | exclude-ip 2a01:4f8:160:3445:: | ||
17 | # monitoring-1 | ||
18 | exclude-ip 95.216.164.150 | ||
19 | exclude-ip 2a01:4f9:c010:1c95:: | ||
20 | |||
21 | no-query-string true | ||
22 | |||
23 | persist true | ||
24 | restore true | ||
25 | db-path @dbPath@ | ||
26 | |||
27 | ignore-panel REFERRERS | ||
28 | ignore-panel KEYPHRASES | ||
29 | |||
30 | static-file .css | ||
31 | static-file .js | ||
32 | static-file .jpg | ||
33 | static-file .png | ||
34 | static-file .gif | ||
35 | static-file .ico | ||
36 | static-file .jpeg | ||
37 | static-file .pdf | ||
38 | static-file .csv | ||
39 | static-file .mpeg | ||
40 | static-file .mpg | ||
41 | static-file .swf | ||
42 | static-file .woff | ||
43 | static-file .woff2 | ||
44 | static-file .xls | ||
45 | static-file .xlsx | ||
46 | static-file .doc | ||
47 | static-file .docx | ||
48 | static-file .ppt | ||
49 | static-file .pptx | ||
50 | static-file .txt | ||
51 | static-file .zip | ||
52 | static-file .ogg | ||
53 | static-file .mp3 | ||
54 | static-file .mp4 | ||
55 | static-file .exe | ||
56 | static-file .iso | ||
57 | static-file .gz | ||
58 | static-file .rar | ||
59 | static-file .svg | ||
60 | static-file .bmp | ||
61 | static-file .tar | ||
62 | static-file .tgz | ||
63 | static-file .tiff | ||
64 | static-file .tif | ||
65 | static-file .ttf | ||
66 | static-file .flv | ||
67 | #static-file .less | ||
68 | #static-file .ac3 | ||
69 | #static-file .avi | ||
70 | #static-file .bz2 | ||
71 | #static-file .class | ||
72 | #static-file .cue | ||
73 | #static-file .dae | ||
74 | #static-file .dat | ||
75 | #static-file .dts | ||
76 | #static-file .ejs | ||
77 | #static-file .eot | ||
78 | #static-file .eps | ||
79 | #static-file .img | ||
80 | #static-file .jar | ||
81 | #static-file .map | ||
82 | #static-file .mid | ||
83 | #static-file .midi | ||
84 | #static-file .ogv | ||
85 | #static-file .webm | ||
86 | #static-file .mkv | ||
87 | #static-file .odp | ||
88 | #static-file .ods | ||
89 | #static-file .odt | ||
90 | #static-file .otf | ||
91 | #static-file .pict | ||
92 | #static-file .pls | ||
93 | #static-file .ps | ||
94 | #static-file .qt | ||
95 | #static-file .rm | ||
96 | #static-file .svgz | ||
97 | #static-file .wav | ||
98 | #static-file .webp | ||
99 | |||
100 | |||