Configuration custom - aide pour création de hooks

Bonjour,

voici ce que j’ai fais de mon côté:
Création du dossier /etc/yunohost/hooks.d/conf_regen/
Dedans j’y place les scripts hooks. Je commence la numérotation après ceux présent dans /usr/share/hooks/conf_regen/. J’ai commencé la numérotation à partir de 90.

  • Une configuration pour ssh : /etc/yunohost/hooks.d/conf_regen/90-ssh_customhook
#!/bin/bash

action=$1
pending_dir=$4
ssh_conf=$pending_dir/../ssh/etc/ssh/sshd_config

[[ $action == "pre" ]] || exit 0
[[ -e $ssh_conf ]] || exit 0

sed -i "s/PermitRootLogin yes/PermitRootLogin no/" $ssh_conf
sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" $ssh_conf
  • Un ajout pour Dovecot (qui pose problème sans cette conf): /etc/yunohost/hooks.d/conf_regen/91-dovecot_customhook
#!/bin/bash

action=$1
pending_dir=$4
dovecot_conf=$pending_dir/../dovecot/etc/dovecot/dovecot.conf

[[ $action == "pre" ]] || exit 0
[[ -e $dovecot_conf ]] || exit 0

echo "

service stats {
  unix_listener stats-reader {
    user = vmail
    group = mail
    mode = 0660
  }
  unix_listener stats-writer {
    user = vmail
    group = mail
    mode = 0660
  }
}

" >> $dovecot_conf
  • Configuration de restriction pour Nginx (GeoIP): /etc/yunohost/hooks.d/conf_regen/92-nginx_customhook
#!/bin/bash

# First install, add package:  geoip-database-extra geoipupdate
# Download configuration on your Maxmind account and replace /etc/GeoIP.conf file

action=$1
pending_dir=$4
nginx_dir=$pending_dir/../nginx/etc/nginx
nginx_security_conf=$nginx_dir/conf.d/security.conf.inc
nginx_country_conf=$nginx_dir/conf.d/country.conf
#geoip_conf=/etc/GeoIP.conf
#geoip_crontab=/etc/cron.d/geoipupdate

[[ $action == "pre" ]] || exit 0
[[ -d $nginx_dir ]] || exit 0
[[ -e $nginx_security_conf ]] || exit 0

echo "
# GeoIP databases
geoip_country /usr/share/GeoIP/GeoIP.dat;

map \$geoip_country_code \$allowed_country {
  default no;
  # France
  FR yes;
  # Italie
  #IT yes;
}

geo \$lan-ip {
  default no;
  192.168.10.0/24 yes;
  10.10.10.0/24 yes;
}
" > $nginx_country_conf

echo "

# allow local ip
if (\$lan-ip = yes) {
  set \$allowed_country yes;
}
# block the country
if (\$allowed_country = no) {
  return 444;
}

" >> $nginx_security_conf

Attention cette configuration de Nginx est suceptible de changer. Pour le moment c’est encore en test chez moi. Les réseaux sont ceux configurés chez moi.

En plus j’ai installé les paquets geoip-database-extra et geoipupdate (le dernier met en place un fichier pour une tâche cron pour les mises à jour des IP par pays).
Dans mon cas j’ai un compte chez Maxmind et je génère un fichier de conf chez eux.

Il faut aussi penser à éditer les pays suivant le besoin de chacun.

Je pense qu’il faut que j’adapte encore ces configurations mais pour le moment cela focntionne plutôt bien.