Zenity at the service of the system administrator

Somehow, one company decided to switch to free software. And downloaded Linux on all computers, and set up a server with disks overseas, and made user accounts. And the chief ordered that all employees set themselves tricky passwords. And although they listened to stories about what kind of beast in front of them, they don’t know where to change the password. Or they can’t find it in the settings. And from the console they run headlong. And they start to run to the admin with the words "admin-admin, help me find the button", and the admin starts to run and get nervous, distracted from important thoughts ...

It's no secret that for many users (especially those not directly related to IT), the transition to a new operating system and software is often painful. And this is largely due to habits. People remember what is located on their computer and, if you rearrange everything, they get lost. As a result, many simple actions can cause difficulties, such as wasting time and nerves.

An idea came up: what if for a task requiring immediate user intervention (such as replacing the password from the bylina above), not yet familiar with the system interface, he should be explicitly given a window with the ability to solve this problem? Looking for a simple solution, I came across zenity. This is a small utility that allows you to display dialog boxes. It uses GTK + and, as it turned out, comes with most popular Linux distributions. In addition to this, it can be used directly in BASH scripts, which makes it possible to quickly make a script “on the knee” and run it at the user at a certain time. Consider an example:

function change_password() {
    local passwords=$(zenity --forms --title="Change your password" \
        --text="Set new password (minimum length 8 characters)" \
        --separator="," \
        --add-password="Your password" \
        --add-password="Repeate password")
    local password1=$( echo $passwords | awk -F ',' '{print $1}' )
    local password2=$( echo $passwords | awk -F ',' '{print $2}' )
    if [[ $password1 == $password2 ]]; then
        if [[ ${#password1} == 0 ]]; then
            zenity --warning --text "Please, select Your password"
            change_password
            return
        fi
        if [[ ${#password1} < 8 ]]; then
            zenity --warning --text "Your password too easy."
            change_password
            return
        fi
        local username=$(whoami)
        # закомментируем само изменение пароля
        # чтобы незадачливый пользователь Ctrl+C - Ctrl+V случайно его себе не поменял
        #echo "$username:$password1" | chpasswd
        local expire_time=$(chage -l $username | awk 'FNR==2{print $4}')
        local full_name=$(cat /etc/passwd | grep "^$username" \
            | awk -F ':' '{print $5}' | awk -F ',' '{print $1}')
        zenity --info --text "$full_name, Your password has been changed. Your new password expires: $expire_time"
    else
        zenity --warning --text "Passwords does not match"
        change_password
        return
    fi
}
change_password

As a result, we get a window with a form for the password, which will "appear itself" probably using the at utility or its analogue to the user and he will only have to enter his new password, saving time for him and the administrator. It looks something like this (using the standard window decoration from your system):

image

Zenity not only displays the window, but also outputs to standard output what the user in the window did. In our case, he filled out two fields in the form. We need to intercept this very conclusion. Thus, we can get the values ​​of all fields from the dialog box in one line through the separator - the default symbol is "|", in the example we replace it with a comma. Parameter assignment zenity speaks for itself, especially if you immediately look at the result.

passwords=$(zenity --forms --title="Change your password" \
    --text="Set new password (minimum length 8 characters)" \
    --separator="," \
    --add-password="Your password" \
    --add-password="Repeate password")

All that remains for us is to process the received data (checking for a length of less than 8 characters for the password - this is an example, never do this!), And inform the user about the results. To do this, the windows with messages turned out to be very useful, which are created even easier than with forms:

zenity --warning --text "Your password too easy." --width=300

image

In conclusion, we can reassure the user with the help of another message, already contacting him by name:

username=$(whoami)
expire_time=$(chage -l $username | awk 'FNR==2{print $4}')
full_name=$(cat /etc/passwd | grep "^$username" \
    | awk -F ':' '{print $5}' | awk -F ',' '{print $1}')
zenity --info --width=400 --text "$full_name, Your password has been changed. Your new password expires: $expire_time"

image

Alternatively, you can use standard notifications:

zenity --notification --window-icon="info" \
    --text="$full_name, Your password has been changed. Your new password expires: $expire_time"

image

WARNING ! In older versions of the zenity package, there is a bug due to which the process that creates the notification window cannot be completed. This is solved by adding a nonzero timeout:

zenity --notification --window-icon="info" --text="..." --timeout=1

The idea of ​​using such windows was positively received, and soon the idea came to ask the user to evaluate the work of his computer on a five-point scale. This is generally a very useful exercise - it allows you to track the rate of increase of satisfied people and identify those who have the most difficulties with the development of a new environment, and, accordingly, take measures to eliminate the difficulties. In its simplest form, it looked like this:

mark=$(zenity --scale \
    --text "Rate your experience" \
    --value=3 \
    --min-value=1\
    --max-value=5 \
    --step=1)
if [[ $? == 0 ]]; then
    zenity --notification --window-icon="info" --text="Thank You!" --timeout=1
fi

The names of the options are intuitive and require no explanation.

image

Unfortunately, zenity is not able to replace such a scale with asterisks (there is an opinion that asterisks are more intuitive), but soon an analogue with a list was found:

zenity --list --text="What do you think about your PC?" \
    --radiolist --column "Pick" --column "Opinion" \
    TRUE "All is good" \
    FALSE "All is good, but..." \
    FALSE "I don't know" \
    FALSE "Too dificult to use it" \
    FALSE "A-A-A \(O_O)/ A-A-A" \
    --height=350

image

Using cron, you can run and watch the results once a day. It remains only to resolve the issue of transferring the collected data to the server. It seems to be a good idea to attach a monitoring system that already has an agent on each computer as part of the experiment - and draw graphs for user polls.

Despite the fact that the examples in this article are clearly not the most relevant, I hope that they will lead someone to interesting thoughts about using graphical interfaces in small scripts to communicate with users. Perhaps these will be important messages for all employees (in the spirit of the wall team, only with a window), notifications about the beginning of the lunch break or voting about the venue of the corporate party. I also want to note that if you know ready-made software solutions for this kind of tasks, you can share them in the comments, and my scripts “on the knee” are nothing more than an interesting experiment, which can later develop into something more.

In conclusion, I quote again the link to the zenity manual: https://help.gnome.org/users/zenity/stable/

Also popular now: