This repository was archived by the owner on Feb 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMakefile
More file actions
84 lines (68 loc) · 3.03 KB
/
Copy pathMakefile
File metadata and controls
84 lines (68 loc) · 3.03 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
.PHONY: docs
default: help
## certs : Create TLS certs used by the HTTPS dummy server in "var/https/certs"
certs:
-mkdir -p var/https/certs
openssl req -x509 -subj "/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=localhost" -newkey rsa:4096 -keyout var/https/certs/key.pem -out var/https/certs/cert.pem -days 3650 -nodes
## enable_all_rules : Enable all the rule files present in ./rules/rules-available/
enable_all_rules:
ln -rs ./rules/rules-available/*.yml ./rules/rules-enabled/
## docker_build : Build Docker image
docker_build:
docker build . -t melody
## docker_run : Run local Docker image
docker_run:
@echo "This will only run the locally built image."
@echo "MELODY_CLI example : 'export MELODY_CLI=\"-s -i lo -F 'dst port 10080'\"'"
@-mkdir logs
docker run \
--net=host \
-e "MELODY_CLI=${MELODY_CLI}" \
--mount type=bind,source="$(shell pwd)/filter.bpf",target=/app/filter.bpf,readonly \
--mount type=bind,source="$(shell pwd)/config.yml",target=/app/config.yml,readonly \
--mount type=bind,source="$(shell pwd)/var",target=/app/var,readonly \
--mount type=bind,source="$(shell pwd)/rules",target=/app/rules,readonly \
--mount type=bind,source="$(shell pwd)/logs",target=/app/logs/ \
melody
## docker : Build and run Docker image
docker: docker_build docker_run
## docs : Deploy documentation
docs:
cd docs/; mkdocs gh-deploy
## run_local_stdout : Start Melody and log to stdout
run_local_stdout: build
./melody -s
## build : Build and set network capabilities to start Melody without elevated privileges
build:
go build -ldflags="-s -w" -o melody ./cmd/melody
sudo setcap cap_net_raw,cap_setpcap=ep ./melody
## cap : Set network capabilities to start Melody without elevated privileges
cap:
sudo setcap cap_net_raw,cap_setpcap=ep ./melody
## setup : Init meloctl, install net-tools dependency and patch listen.interface config key with the current default interface
setup:
@echo "Ensure net-tools is installed in order to use the 'route' command"
sudo apt install net-tools
@echo "> Setting listening interface to \"$(shell route | grep '^default' | awk '{print $$8; exit}')\""
sed -i "s/# listen.interface: \"lo\"/listen.interface: \"$(shell route | grep '^default' | awk '{print $$8; exit}')\"/g" ./config.yml
@echo
@echo -n "Current listening interface :\n\t"
@grep listen.interface ./config.yml
@echo -n "Current BPF is :\n\t"
@cat ./filter.bpf
# Don't forget to filter the noise by editing ./filter.bpf
## supervisor : Create Melody's supervisor configuration
supervisor:
sudo ln -s $(shell pwd)/etc/melody.conf /etc/supervisor/conf.d/
sudo supervisorctl reload
sudo supervisorctl status all
## service : Create Melody's systemd configuration and enable start at boot
service:
sudo ln -s $(shell pwd)/etc/melody.service /etc/systemd/system/melody.service
sudo systemctl daemon-reload && sudo systemctl enable melody
sudo systemctl stop melody && sudo systemctl status melody
## help : Show this help
help: Makefile
@printf "\n Melody helpers\n\n"
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@printf ""