› Forums › Network Management › ZeroShell › [Janus / twin Alix2] #6 Hack the GUI to run custom commands
- This topic is empty.
-
AuthorPosts
-
July 12, 2015 at 10:06 am #44333
PatrickB
MemberHello.
In my post #5 of this series I described scripts performing backup & restore operations.
This is an example of task to be run manually, and doing it from a command in ZS’s GUI would be handier than having to open a shell…
In this thread I asked for a customizable page in the GUI to do such things:
https://www.zeroshell.org/forum/viewtopic.php?t=4964In the meantime, here is the poor solution I found to do it 😥
The scripts in the GUI and what is behind
The GUI page SETUP / Scripts/Cron leads to a Script Editor with a list where are predefined some scripts. Then it is possible to add scheduled jobs.
The implementation is done in:
/Database/var/register/system/startup/scripts
root@janus2> ll /Database/var/register/system/startup/scripts
total 48K
drwxr-xr-x 2 root root 4.0K May 8 23:09 Backup
drwxr-xr-x 3 root root 4.0K Feb 21 18:46 NTPupdate-Cron
drwxr-xr-x 3 root root 4.0K Feb 4 2000 Shibboleth-Cron
drwxr-xr-x 2 root root 4.0K Jun 27 2008 cpauth
drwxr-xr-x 2 root root 4.0K Jun 27 2008 cpgw
drwxr-xr-x 2 root root 4.0K Jun 27 2008 firewallchain
drwxr-xr-x 2 root root 4.0K Jun 27 2008 nat
drwxr-xr-x 2 root root 4.0K Jun 26 2008 postboot
drwxr-xr-x 2 root root 4.0K Jun 27 2008 preboot
drwxr-xr-x 2 root root 4.0K Jun 27 2008 qos
drwxr-xr-x 2 root root 4.0K Jun 27 2008 test
drwxr-xr-x 2 root root 4.0K Jun 27 2008 wireless
root@janus2> ll /Database/var/register/system/startup/scripts/NTPupdate-Cron
total 16K
-rw-r--r-- 1 root root 14 Feb 21 18:46 Description
-rw-r--r-- 1 root root 4 Feb 21 18:46 Enabled
-rwxr-xr-x 1 root root 54 Feb 21 18:46 File
drwxr-xr-x 2 root root 4.0K Feb 21 18:46 cronIt is possible to create a script as a Cron job, but after that:
– the folder is suffixed with ‘-Cron’,
– a priori there is a mandatory scheduling,
– the name in the list can no longer be changed from the GUI…But from the shell it is possible to rename the main folder and the name in file ‘Description’, and also to remove the folder ‘cron’, what removes the scheduling.
This enables to have a new manual command available in the list of the GUI’s Script Editor.I also wanted to have my commands at the top of the list. This can be done through a smart choice for the main folder name:
– prefixing with ‘_’ is ignored in the sorting,
– using ‘!’ or ‘-‘ causes problems as they are taken as command options,
– using ‘.’ makes the command invisible,
– finally I choosed ‘,’ this way:drwxr-xr-x 2 root root 4.0K May 15 21:45 ,Export-Data
drwxr-xr-x 2 root root 4.0K May 15 21:48 ,Import-Data
drwxr-xr-x 3 root root 4.0K Feb 21 18:46 NTPupdate-Cron
drwxr-xr-x 3 root root 4.0K Feb 4 2000 Shibboleth-CronIn the ‘Description’ files there is no comma of course, but “Export Data” and “Import Data” are on top of the list in the GUI, as I wanted.
Content of such commands
Of course I could create a dedicated command for every data kind to backup and also to restore, but it would be a mess.
I preferred to have a unique script per function, with an option to select inside.It would have been simple to code a old style menu there, but such scripts are run with no possible interactivity 👿
Finally it looks like this:
# Backup to MyBackupServer
#
# No interactivity is possible. Set BackupOption with a value predefined below.
# Backup options:
#
#
# 1 - DNS
#
# The option keys for 'export-from-ldap-one.sh' are defined in '/opt/etc/ldap-attribute-map.txt'
#
BackupOption=1
#
# DO NOT MODIFY BELOW in USER MODE
PATH=/opt/bin:$PATH
case $BackupOption in
1)
echo "Backup of LDAP's section: DNS" ;
bash /opt/bin/export-from-ldap-one.sh "DNS" ;
exit $? ;
;;
*) echo -e "Invalid backup option '$BackupOption'. Aborting.n" ;
exit 1 ;;
esac
exit 0;In the GUI’s Script Editor, I adjust BackupOption then run the script 😕
Of course I would prefer to run that by clicking on a button in a User-defined page of the GUI, taking the option in a checkbox of the form !
But in the meantime it works quite easily this way…Hope it can help someone.
Ideas for improvements are welcome.
Best regards.
-
AuthorPosts
- You must be logged in to reply to this topic.