Tcl / Tk. GUI development for command line utilities
While testing the cloud token on various platforms, I did not leave the thought of a certain injustice: why PKCS # 11 token configuration utilities on the MS Windows platform have a graphical interface, but for other platforms it does not. And first of all it concerns the basic p11conf utility, which is available for free use and is a command line utility, the interaction with which is carried out through standard input / output.
The output could be writing in the C / C ++ GUI language for the p11conf utility, for example, using the Qt library. But then it came to my mind that there is a high-level scripting language Tcl (Tool Command Language), which, in conjunction with the Tk graphics library (Tool Kit), allows you to quickly create graphical interfaces for console programs or command-line utilities. I first met the Tk / Tcl package back in 1997, when it was planned to write a graphical interface for an access control system (ACS) on it. Then the graphical capabilities of the package made a strong impression and, in particular, tetris:
One of the reasons why they refused to use Tk / Tcl was the lack of a designer (designer) for him at that time similar to today's, say, QT-designer. Refreshing the capabilities of Tk / Tcl, and we were interested, in addition to graphical capabilities, the organization of interaction with command-line utilities, and making sure that we were on the right track, we set about searching for a constructor. After the analysis of existing designers, the choice fell on the designer tkBuilder_for_tcl8.4 :
Further development showed the correct choice. The designer turned out to be not only with a clear interface, but also has excellent functionality. It allows during the development to track the project not only as a whole:
but also to control its individual parts:
The developer can always see the code of the entire project or its part:
Interaction with the utility of the command line for which the graphical shell is developed is carried out via the program channel:
When the project is completed, it is necessary to save it in the final tcl file:
It would seem that everything, take and run the utility. But without a spoon (actually two spoons) tar is impossible. The first spoon is related to the formation of the xScrollCommand and yScrollComand. Commands for widgets (in our case, the text widget), namely:
They do not want to get into the final file. As a result, they had to be prescribed with pens. Well, the second fly in the ointment is classic. Designer tkBuilder_for_tcl8.4 refuses to work with Russian letters (maybe I didn’t overlook what). I emphasize that this applies only to the designer and does not apply to Tcl / Tk, for which Russian as a home is native. Here, too, had to work with pens:
As a result, we got GUI support for the p11conf command-line utility through the GUITKP11Conf.tcl utility:
Now you can safely work with PKCS # 11 tokens, including the LIBLS11CLOUD cloud token, for example, see which objects are stored on it:
GUIP11CONF.tkb project file and GUIP11CONF.tcl utility can be downloaded here. The p11conf utility for various platforms can be downloaded here. A little remark. The GUIP11CONF.tcl utility contains the path in the p11conf utility (see above):
Most likely, you will have to adjust the path to the p11conf utility based on your configuration.
Down and Out trouble started
In conclusion, I note that the appetite comes with eating and there is already a desire to write similar graphical shells for such command-line utilities as openssl or NSS (Network Security Services) utilities. As they say, dashing trouble began.
tkBuilder - graphic designer
The output could be writing in the C / C ++ GUI language for the p11conf utility, for example, using the Qt library. But then it came to my mind that there is a high-level scripting language Tcl (Tool Command Language), which, in conjunction with the Tk graphics library (Tool Kit), allows you to quickly create graphical interfaces for console programs or command-line utilities. I first met the Tk / Tcl package back in 1997, when it was planned to write a graphical interface for an access control system (ACS) on it. Then the graphical capabilities of the package made a strong impression and, in particular, tetris:
One of the reasons why they refused to use Tk / Tcl was the lack of a designer (designer) for him at that time similar to today's, say, QT-designer. Refreshing the capabilities of Tk / Tcl, and we were interested, in addition to graphical capabilities, the organization of interaction with command-line utilities, and making sure that we were on the right track, we set about searching for a constructor. After the analysis of existing designers, the choice fell on the designer tkBuilder_for_tcl8.4 :
Further development showed the correct choice. The designer turned out to be not only with a clear interface, but also has excellent functionality. It allows during the development to track the project not only as a whole:
but also to control its individual parts:
The developer can always see the code of the entire project or its part:
Interaction with the utility of the command line for which the graphical shell is developed is carried out via the program channel:
When the project is completed, it is necessary to save it in the final tcl file:
About tar spoons
It would seem that everything, take and run the utility. But without a spoon (actually two spoons) tar is impossible. The first spoon is related to the formation of the xScrollCommand and yScrollComand. Commands for widgets (in our case, the text widget), namely:
text .fr1.fr2_list -background #ffffff \
-yscrollcommand [list .fr1.ysc set] -xscrollcommand [list .fr1.scx set]
They do not want to get into the final file. As a result, they had to be prescribed with pens. Well, the second fly in the ointment is classic. Designer tkBuilder_for_tcl8.4 refuses to work with Russian letters (maybe I didn’t overlook what). I emphasize that this applies only to the designer and does not apply to Tcl / Tk, for which Russian as a home is native. Here, too, had to work with pens:
#!/bin/sh
# the next line restarts using wish \
exec wish8.5 "$0" ${1+"$@"}
wm title . "GUI P11CONF"
global p11conf
global libpkcs11
set res ""
set libpkcs11 ""
set p11conf "/usr/local/bin64/p11conf"
. configure -background #18f1d7
frame .fr1 -background #18f1d7
grid .fr1 -column 0 -row 0
button .fr1.b1 -command {InitTok . .fr1.fr2_list;} -padx 1 -text "Инициализировать" -width 24
grid .fr1.b1 -column 0 -row 0
button .fr1.b2 -command {ChangeUserPin . .fr1.fr2_list; } -padx 1 -text "Сменить USER PIN" -width 24
grid .fr1.b2 -column 0 -row 1
button .fr1.b6_3 -command {ChangeSOPin . .fr1.fr2_list "SO"; } -padx 1 -text "Сменить SO PIN" -width 24
grid .fr1.b6_3 -column 0 -row 2
button .fr1.b7 -command {InfoObj . .fr1.fr2_list "Obj"; } -padx 1 -text "Просмотреть объекты" -width 24
grid .fr1.b7 -column 0 -row 3
button .fr1.b8 -command {InfoObj . .fr1.fr2_list "Clear";} -padx 1 -text "Удалить все объекты" -width 24
grid .fr1.b8 -column 0 -row 4
button .fr1.b9_6 -command {InfoToken . .fr1.fr2_list; } -padx 1 -text "Информация о токене" -width 24
grid .fr1.b9_6 -column 0 -row 5
button .fr1.b0 -command {InfoMech . .fr1.fr2_list;} -padx 1 -text "Поддерживаемые механизмы" -width 24
grid .fr1.b0 -column 0 -row 6
button .fr1.b3_8 -command {ChangeSOPin . .fr1.fr2_list "Deblock"; } -padx 1 -text "Разблоктровать USER PIN" -width 24
grid .fr1.b3_8 -column 0 -row 7
button .fr1.b4_9 -command {InfoDump . .fr1.fr2_list; } -padx 1 -text "DUMP всех объектов" -width 24
grid .fr1.b4_9 -column 0 -row 8
button .fr1.b5_10 -command {exit} -text "Выход" -width 10
As a result, we got GUI support for the p11conf command-line utility through the GUITKP11Conf.tcl utility:
bash-4.3$ ./GUITKP11Conf.tcl
Now you can safely work with PKCS # 11 tokens, including the LIBLS11CLOUD cloud token, for example, see which objects are stored on it:
GUIP11CONF.tkb project file and GUIP11CONF.tcl utility can be downloaded here. The p11conf utility for various platforms can be downloaded here. A little remark. The GUIP11CONF.tcl utility contains the path in the p11conf utility (see above):
global p11conf
…
set p11conf "/usr/local/bin64/p11conf"
Most likely, you will have to adjust the path to the p11conf utility based on your configuration.
Down and Out trouble started
In conclusion, I note that the appetite comes with eating and there is already a desire to write similar graphical shells for such command-line utilities as openssl or NSS (Network Security Services) utilities. As they say, dashing trouble began.