Add permission check for hooks directory

This commit is contained in:
CodeShakingSheep 2023-08-08 16:51:51 +02:00 committed by ljf (zamentur)
parent 62e4b2f9fb
commit 546b5b3e7a

View file

@ -12,13 +12,23 @@ YunoHost includes a hook mechanism triggered on a lot of operation changing the
The most obvious case is adding a user. If you had a `post_user_create` hook, this hook will be triggered as soon as a user is added. The most obvious case is adding a user. If you had a `post_user_create` hook, this hook will be triggered as soon as a user is added.
## How to add a custom hook on a specific instance ## How to add a custom hook on a specific instance
!!! Bellow we imagine we want to run a command after each user creation to add the user to samba user. !!! Below we imagine we want to run a command after each user creation to add the user to samba user.
You should create a directory with the name of the hooks into `/etc/yunohost/hooks.d/`: You should create a directory with the name of the hooks into `/etc/yunohost/hooks.d/`:
``` ```
mkdir -p /etc/yunohost/hooks.d/post_user_create mkdir -p /etc/yunohost/hooks.d/post_user_create
``` ```
After creating the directory check the permissions:
```
stat -c "%a" /etc/yunohost/hooks.d/post_user_create
```
The directory needs to have `777` permissions. Otherwise the hooks inside the directory won't be executed. If the command above doesn't print `777` modify permissions:
```
chmod 777 /etc/yunohost/hooks.d/post_user_create
```
Next create a bash script inside this directory prefixed by 2 numbers and a dash: Next create a bash script inside this directory prefixed by 2 numbers and a dash:
```bash ```bash
nano /etc/yunohost/hooks.d/post_user_create/05-add-user-to-samba nano /etc/yunohost/hooks.d/post_user_create/05-add-user-to-samba
@ -40,7 +50,7 @@ In the hooks dir, create a bash script called with the type of hook you want to
#### post_user_create #### post_user_create
[details summary="<i>Triggered after user creation</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered after user creation</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost user create` or equivalent action in webadmin. This hook is run at the end of the command `yunohost user create` or equivalent action in webadmin.
##### Environment variables ##### Environment variables
@ -80,7 +90,7 @@ echo $message | mail -s "Welcome on $domain !" $YNH_USER_MAIL
#### post_user_delete #### post_user_delete
[details summary="<i>Triggered at the end of user deletion</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered at the end of user deletion</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost user delete` or equivalent action in webadmin. This hook is run at the end of the command `yunohost user delete` or equivalent action in webadmin.
##### No environment variables ##### No environment variables
@ -104,7 +114,7 @@ This hooks is run at the end of the command `yunohost user delete` or equivalent
### post_user_update ### post_user_update
[details summary="<i>Triggered at the end of the user update</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered at the end of the user update</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost user update` or equivalent action in webadmin. This hook is run at the end of the command `yunohost user update` or equivalent action in webadmin.
##### Environment variables ##### Environment variables
@ -143,7 +153,7 @@ echo $message | mail -s "Your password has been changed on $domain !" $YNH_USER_
### post_app_addaccess ### post_app_addaccess
[details summary="<i>Triggered after adding a permission to users or groups </i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered after adding a permission to users or groups </i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost user permission add` or equivalent action in webadmin. This hook is run at the end of the command `yunohost user permission add` or equivalent action in webadmin.
##### No environment variables ##### No environment variables
@ -164,7 +174,7 @@ This hooks is run at the end of the command `yunohost user permission add` or eq
### post_app_removeaccess ### post_app_removeaccess
[details summary="<i>Triggered after removing a pemission to users or groups</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered after removing a pemission to users or groups</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost user permission remove` or equivalent action in webadmin. This hook is run at the end of the command `yunohost user permission remove` or equivalent action in webadmin.
##### No environment variables ##### No environment variables
@ -190,7 +200,7 @@ This hooks is run at the end of the command `yunohost user permission remove` or
### post_domain_add ### post_domain_add
[details summary="<i>Triggered at the end of the domain add operation</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered at the end of the domain add operation</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost domain add` or equivalent action in webadmin. This hook is run at the end of the command `yunohost domain add` or equivalent action in webadmin.
##### No environment variable ##### No environment variable
@ -214,7 +224,7 @@ This hooks is run at the end of the command `yunohost domain add` or equivalent
### post_domain_remove ### post_domain_remove
[details summary="<i>Triggered after removing the domain</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered after removing the domain</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost domain remove` or equivalent action in webadmin. This hook is run at the end of the command `yunohost domain remove` or equivalent action in webadmin.
##### No environment variable ##### No environment variable
@ -233,7 +243,7 @@ This hooks is run at the end of the command `yunohost domain remove` or equivale
### post_cert_update ### post_cert_update
[details summary="<i>Triggered after Let's encrypt certificate update</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered after Let's encrypt certificate update</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost domain cert update` or equivalent action in webadmin. This hook is run at the end of the command `yunohost domain cert update` or equivalent action in webadmin.
##### No environment variable ##### No environment variable
@ -258,9 +268,9 @@ systemctl restart gemserv
### custom_dns_rules ### custom_dns_rules
[details summary="<i>Customized your DNS rules for your domains</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Customized your DNS rules for your domains</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost domain dns suggest` or equivalent action in webadmin. This hook is run at the end of the command `yunohost domain dns suggest` or equivalent action in webadmin.
Thanks to this hooks you can customize Thanks to This hook you can customize
##### No environment variable ##### No environment variable
@ -309,7 +319,7 @@ fi
### post_app_change_url ### post_app_change_url
[details summary="<i>Triggered after an app has changed of URL</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered after an app has changed of URL</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost app change-url` or equivalent action in webadmin. This hook is run at the end of the command `yunohost app change-url` or equivalent action in webadmin.
##### Environment variables ##### Environment variables
@ -328,7 +338,7 @@ This hooks is run at the end of the command `yunohost app change-url` or equival
### post_app_upgrade ### post_app_upgrade
[details summary="<i>Triggered on app upgrade</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered on app upgrade</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost app upgrade` or equivalent action in webadmin. This hook is run at the end of the command `yunohost app upgrade` or equivalent action in webadmin.
##### Environment variables ##### Environment variables
@ -366,7 +376,7 @@ fi
### post_app_install ### post_app_install
[details summary="<i>Triggered at the end of an app installation</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered at the end of an app installation</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost app install` or equivalent action in webadmin. This hook is run at the end of the command `yunohost app install` or equivalent action in webadmin.
##### Environment variables ##### Environment variables
@ -388,7 +398,7 @@ This hooks is run at the end of the command `yunohost app install` or equivalent
### post_app_remove ### post_app_remove
[details summary="<i>Triggered after removing an app</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered after removing an app</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost app remove` or equivalent action in webadmin. This hook is run at the end of the command `yunohost app remove` or equivalent action in webadmin.
##### Environment variables ##### Environment variables
@ -410,7 +420,7 @@ This hooks is run at the end of the command `yunohost app remove` or equivalent
### backup ### backup
[details summary="<i>Add some files to backup</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Add some files to backup</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost backup create` or equivalent action in webadmin. This hook is run at the end of the command `yunohost backup create` or equivalent action in webadmin.
##### Environment variables ##### Environment variables
@ -455,7 +465,7 @@ ynh_backup "/etc/yunohost/hooks.d/restore/99-conf_custom"
### restore ### restore
[details summary="<i>Restore some files</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Restore some files</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost backup restore` or equivalent action in webadmin. This hook is run at the end of the command `yunohost backup restore` or equivalent action in webadmin.
##### Environment variables ##### Environment variables
@ -500,7 +510,7 @@ ynh_restore_file "/etc/yunohost/hooks.d/restore/99-conf_custom"
### backup_method ### backup_method
[details summary="<i>Define a new way to backup and restore files</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Define a new way to backup and restore files</i>" class="helper-card-subtitle text-muted"]
This hooks is run during the command `yunohost backup create` or equivalent action in webadmin. This hook is run during the command `yunohost backup create` or equivalent action in webadmin.
This hook is called several times with different action keywords. This hook is called several times with different action keywords.
@ -564,7 +574,7 @@ exit 0
### post_iptable_rules ### post_iptable_rules
[details summary="<i>Triggered after reloaded the firewall rules</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Triggered after reloaded the firewall rules</i>" class="helper-card-subtitle text-muted"]
This hooks is run at the end of the command `yunohost firewall reload` or equivalent action in webadmin. This hook is run at the end of the command `yunohost firewall reload` or equivalent action in webadmin.
##### No environment variables ##### No environment variables
@ -589,7 +599,7 @@ iptables -A OUTPUT -p tcp --dport 25 -m tcp -j REJECT --reject-with icmp-port-un
### conf_regen ### conf_regen
[details summary="<i>Change configuration suggested as default config in regen-conf mechanism</i>" class="helper-card-subtitle text-muted"] [details summary="<i>Change configuration suggested as default config in regen-conf mechanism</i>" class="helper-card-subtitle text-muted"]
This hooks is run during the command `yunohost tools regen-conf` or equivalent action in webadmin. This hook is run during the command `yunohost tools regen-conf` or equivalent action in webadmin.
This hook is called several times with different actions keywords (pre and post operations). This hook is called several times with different actions keywords (pre and post operations).