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.
Comments
Submitted by yngens on Wed, 09/06/2017 - 01:56 Comment #1
Anything on this?
Submitted by JamieCameron on Wed, 09/06/2017 - 20:07 Comment #2
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?
Submitted by yngens on Wed, 09/06/2017 - 20:28 Comment #3
Yes, of course, it would. We need any trigger to know when to check password change in /etc/webmin/mysql/config.
Submitted by JamieCameron on Sat, 09/09/2017 - 18:56 Comment #4
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 lineaction_script_dir=/etc/webmin-actions
Submitted by yngens on Sun, 09/10/2017 - 13:43 Comment #5
Excellent! I do really appreciate your help in this too, Jamie!
Submitted by yngens on Wed, 09/20/2017 - 23:11 Comment #6
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.
Submitted by JamieCameron on Sat, 09/23/2017 - 16:01 Comment #7
Urgh, it turns out that this feature has a bug that's existed for years due to it being rarely used.
You can fix it by applying this patch : https://github.com/webmin/webmin/commit/6e74b7b6d40f91a2b5bea2aece9a9cd1...
and then restarting Webmin.
Submitted by yngens on Mon, 10/02/2017 - 23:08 Comment #8
Will this be fixed and pushed to the next release not to apply patch every time?