Post action script in Webmin

In Virtualmin we can invoke the post action script to trigger additional actions. I wonder can we do something like that in Webmin. For example, we have the MySQL root password set in /etc/my.cnf file's [client] section like so:

[client]
user=root
password=$PASS

to make easier database manipulation for users with proper privileges. But if someone changes the database root password through Webmin's UI then things get de-synced and we have to update the above line manually. I wonder how can we catch the "Change Administration Password" action to be able to sync the password in my.cnf?

I know if changed the new password can be found in /etc/webmin/mysql/config, but it doesn't make sense to cron-watch when that file changes. So would be wonderful somehow to trigger custom script in case of any Webmin action and there we could filter out if the action was about the database root password change.

Status: 
Active

Comments

There is a way to define post-action scripts in webmin that are run after ALL operations, including the mysql password change. Your script would need to check what action is being performed (via environment variables) and do what you want only for the specific action you're interested in though .... would that work?

Yes, of course, it would. We need any trigger to know when to check password change in /etc/webmin/mysql/config.

Basically, you need to create a script like :

#!/bin/sh
if [ "$ACTION_MODULE" = "mysql" -a "$ACTION_ACTION" = "root" ]; then
  # your code here
fi

Name this script something like /etc/webmin-actions/mysql.sh

Then edit the file /etc/webmin/config and add the line action_script_dir=/etc/webmin-actions

Excellent! I do really appreciate your help in this too, Jamie!

After creating the following test script at /etc/webmin-actions/mysql.sh:

#!/bin/sh
if [ "$ACTION_MODULE" = "mysql" -a "$ACTION_ACTION" = "root" ]; then
  echo "test" >> /etc/my.cnf
fi

Chmoding it to 755, adding the action_script_dir=/etc/webmin-actions line to /etc/webmin/config, restarting Webmin and finally attemting to change the password through UI, it gives:

Error - Perl execution failed

Illegal division by zero at ../web-lib-funcs.pl line 5721.

so something is not clicking, please take another look at this.

Will this be fixed and pushed to the next release not to apply patch every time?