This commit is contained in:
Iwan Clement
2020-06-12 21:16:40 +02:00
parent 6aebc550c9
commit 10c178bbb2
3 changed files with 205 additions and 116 deletions

5
scripts/CreateRoutes.py Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/python3
import yaml
f = open('rules.yaml')
dohicky = yaml.safe_load(f)
f.close()

83
scripts/ReadYaml.sh Executable file
View File

@@ -0,0 +1,83 @@
#!/usr/bin/env bash
# shellcheck disable=SC1003
# Based on https://gist.github.com/pkuczynski/8665367
parse_yaml() {
local yaml_file=$1
local prefix=$2
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_.-]*'
fs="$(echo @|tr @ '\034')"
(
sed -e '/- [^\“]'"[^\']"'.*: /s|\([ ]*\)- \([[:space:]]*\)|\1-\'$'\n'' \1\2|g' |
sed -ne '/^--/s|--||g; s|\"|\\\"|g; s/[[:space:]]*$//g;' \
-e "/#.*[\"\']/!s| #.*||g; /^#/s|#.*||g;" \
-e "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)${s}[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" |
awk -F"$fs" '{
indent = length($1)/2;
if (length($2) == 0) { conj[indent]="+";} else {conj[indent]="";}
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, conj[indent-1],$3);
}
}' |
sed -e 's/_=/+=/g' |
awk 'BEGIN {
FS="=";
OFS="="
}
/(-|\.).*=/ {
gsub("-|\\.", "_", $1)
}
{ print }'
) < "$yaml_file"
}
create_variables() {
local yaml_file="$1"
local prefix="$2"
eval "$(parse_yaml "$yaml_file" "$prefix")"
}
parse_yaml rules.yaml
exit 0
yaml() {
python3 -c "import yaml;print(yaml.load(open('$1'))$2)"
}
yaml rules.yaml
exit 0
VALUE=$(yaml ~/my_yaml_file.yaml "['a_key']")
function parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
parse_yaml rules.yaml

View File

@@ -1,206 +1,207 @@
---
items:
- actions:
- 5ce42a14bf802e0001684668:
actions:
- store()
- stop()
description: Suppression UDEMY
expression: match_recipient("iwan*.udemy@mg.*.space")
id: 5ce42a14bf802e0001684668
priority: 0
- actions:
- 5cd48c308b3cd70001f79bfb:
actions:
- forward("nadinepub.clement@free.fr")
- stop()
description: EU domains for Nadine
expression: match_recipient("nadine.*@mg.*.eu")
id: 5cd48c308b3cd70001f79bfb
priority: 0
- actions:
- 5cd48b47a4764a00013cee72:
actions:
- forward("iwan.clement@gmx.fr")
- stop()
description: EU domains
expression: match_recipient("iwan.*@mg.*.eu")
id: 5cd48b47a4764a00013cee72
priority: 0
- actions:
- 5db1e61d11c830a64e8e2dba:
actions:
- forward("iwan.clement@mail.fr")
- stop()
description: iwanpub@mg.*.eu
expression: match_recipient("iwanpub.*@mg.*.eu")
id: 5db1e61d11c830a64e8e2dba
priority: 1
- actions:
- 5ce18c92629574000195c8de:
actions:
- forward("iwan.pubclement@gmx.fr")
- stop()
description: Tout ce qui arrive sur le domaine pour mg.iwanclement.eu
expression: match_recipient(".*@mg.iade-lyon.eu")
id: 5ce18c92629574000195c8de
priority: 2
- actions:
- 5ca2330d6295740001322814:
actions:
- forward("iwan.pubclement@mail.fr, nadinepub.clement@free.fr")
- stop()
description: LIDL
expression: match_recipient("iwanpub.lidl@mg.*.space")
id: 5ca2330d6295740001322814
priority: 2
- actions:
- 5c726e2f8b3cd70001237ee5:
actions:
- forward("nadineclement@mail.fr")
- stop()
description: Tout pour Nadine Clement
expression: match_recipient(".*@mg.iade-lyon.eu")
id: 5c726e2f8b3cd70001237ee5
priority: 2
- actions:
- 5c570e59bf802e00012989e9:
actions:
- forward("iwanpro.clement@free.fr")
- stop()
description: Iwan Professionnel
expression: match_recipient("iwanpro.*@mg.*.space")
id: 5c570e59bf802e00012989e9
priority: 2
- actions:
- 5baa01368ecd8700013c5010:
actions:
- forward("nadineclement@mail.fr")
- stop()
description: Tout pour Nadine Clement
expression: match_recipient(".*@mg.nadineclement.eu")
id: 5baa01368ecd8700013c5010
priority: 2
- actions:
- 5b6d4d826295740001913849:
actions:
- forward("aristide1clement@gmail.com,iwan.clement@free.fr")
- stop()
description: Aristide MG
expression: match_recipient("aristidepub.*@mg.*.space")
id: 5b6d4d826295740001913849
priority: 2
- actions:
- 5b6d4c278b3cd70001ebdfda:
actions:
- forward("iwanadm@free.fr")
- stop()
description: ''
expression: match_recipient("backup.*@mg.*.space")
id: 5b6d4c278b3cd70001ebdfda
priority: 2
- actions:
- 5c5499376295740001fe1e27:
actions:
- forward("iwanadm@free.fr")
- stop()
description: applications
expression: match_recipient("iwanapp.*@mg.*.space")
id: 5c5499376295740001fe1e27
priority: 3
- actions:
- 5c5343c345d85900018ceee6:
actions:
- forward("iwan.pubclement@gmx.fr")
- stop()
description: pour les jobs.
expression: match_recipient("iwanjob.*@mg.*.space")
id: 5c5343c345d85900018ceee6
priority: 3
- actions:
- 5c5eb3376295740001546abf:
actions:
- forward("nadinepub.clement@free.fr")
- stop()
description: Les pubs pour Nadine
expression: match_recipient("nadinepub.*@mg.*.space")
id: 5c5eb3376295740001546abf
priority: 4
- actions:
- 5c534e78bf802e00013232e5:
actions:
- forward("iwan.pubclement@gmx.fr")
- stop()
description: Iwanpub
expression: match_recipient("iwanpub.*@mg.*.space")
id: 5c534e78bf802e00013232e5
priority: 4
- actions:
- 5bbe45dc6295740001b26ffd:
actions:
- forward("iwanadm@free.fr")
- stop()
description: admin.qqchose
expression: match_recipient("admin.*@mg.*.space")
id: 5bbe45dc6295740001b26ffd
priority: 4
- actions:
- 5b9b758aa4764a000133bfbe:
actions:
- forward("iwanadm@free.fr")
- stop()
description: ''
expression: match_recipient("proxmox.*@mg.*.space")
id: 5b9b758aa4764a000133bfbe
priority: 4
- actions:
- 5bae76a745d8590001287978:
actions:
- forward("iwanadm@free.fr")
- stop()
description: ''
expression: match_recipient("adm.*@mg.*.space")
id: 5bae76a745d8590001287978
priority: 5
- actions:
- 5b8d79f98b3cd700019d5205:
actions:
- forward("ivan.pubclement@free.fr")
- stop()
description: aristide chez Sosh
expression: match_recipient("aristide.sosh@mg.*.space")
id: 5b8d79f98b3cd700019d5205
priority: 5
- actions:
- 5b799e80a4764a000192cf3b:
actions:
- forward("iwanadm@free.fr")
- stop()
description: Pour Piwigo
expression: match_recipient("iwanadm@free.fr")
id: 5b799e80a4764a000192cf3b
priority: 5
- actions:
- 5c726e7e8ecd870001264998:
actions:
- forward("aristide1clement@gmail.com")
- stop()
description: ''
expression: match_recipient("aristide.*@mg.*.space")
id: 5c726e7e8ecd870001264998
priority: 6
- actions:
- 5c726b408ecd870001264739:
actions:
- forward("gwladys.clement@gmail.com")
- stop()
description: Gwladys.qqc
expression: match_recipient("gwladys.*@mg.*.space")
id: 5c726b408ecd870001264739
priority: 6
- actions:
- 5c726b19bf802e000162d921:
actions:
- forward("ophelie.clement@gmail.com")
- stop()
description: Tout Ophelie.qqc
expression: match_recipient("ophelie.*@mg.*.space")
id: 5c726b19bf802e000162d921
priority: 6
- actions:
- 5c419a518b3cd70001c5ddea:
actions:
- forward("iwan.clement@gmx.fr")
- stop()
description: ''
expression: match_recipient("iwan.*@mg.*.space")
id: 5c419a518b3cd70001c5ddea
priority: 6
- actions:
- 5b8a5bcd8b3cd700017130ed:
actions:
- forward("emmanuellelou@gmail.com")
- stop()
description: MG Emmanuelle Clément
expression: match_recipient("emmanuelle.*@mg.*.space")
id: 5b8a5bcd8b3cd700017130ed
priority: 6
- actions:
- 5ce18d97bf802e00019eaace:
actions:
- forward("sandrine.peinnequin@gmail.com")
- stop()
description: Sandrine Peinnequin
expression: match_recipient("sandrine.*@mg.*.space")
id: 5ce18d97bf802e00019eaace
priority: 8
- actions:
- 5ce18cf4a4764a0001d95b58:
actions:
- forward("bruno.joachim@gmail.com")
- stop()
description: Bruno Joachim
expression: match_recipient("bruno.*@mg.*.space")
id: 5ce18cf4a4764a0001d95b58
priority: 8
- actions:
- 5baf5ac78b3cd70001ebae82:
actions:
- forward("stephane.guillot_32@kindle.com")
- stop()
description: Kindle de Stephane
expression: match_recipient("kindle.stephane@mg.*.space")
id: 5baf5ac78b3cd70001ebae82
priority: 8
- actions:
- 5b6cbd328b3cd70001eb4eb2:
actions:
- forward("iwan.pubclement@gmx.fr")
- stop()
description: On ramasse tout
expression: catch_all()
id: 5b6cbd328b3cd70001eb4eb2
id:
priority: 10
...