bcrypt_gui 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/sh
  2. #(c) Barry Kauler, April 2009. GPL v3 licence (refer: /usr/share/doc/legal).
  3. #gui for 'bcrypt' file encrypt/decrypt.
  4. #$1 is normally invoked by clicking on a .bfe file in rox, $1 has full path.
  5. #also supports drag and drop.
  6. #most of this code was written by coolpup, I have just butchered it a bit.
  7. #w482 dogone: password must be 8 chars, logic fixed.
  8. #120201 rodin.s: internationalized.
  9. #120226 01micko: convert to gtkdialog4.
  10. #120323 call pupmessage instead of xmessage.
  11. #131130 zigbert: gui (gtkdialog) improvements.
  12. export TEXTDOMAIN=bcrypt_gui
  13. export TEXTDOMAINDIR=/usr/share/locale
  14. export OUTPUT_CHARSET=UTF-8
  15. . gettext.sh
  16. export LANGORG=$LANG
  17. if [ "`which bcrypt`" = "" ];then
  18. pupmessage -center -bg red -title "$(gettext 'Bcrypt error')" "$(gettext "The 'bcrypt' package must be installed first.")"
  19. exit
  20. fi
  21. #if [ ! $1 ];then
  22. #run from the menu. this section was originally created by 'coolpup', jan. 2009.
  23. #modified by BK april 2009.
  24. SOURCEFILE=""
  25. if [ $1 ];then
  26. SOURCEFILE="$1"
  27. [ ! -f "$SOURCEFILE" ] && exit
  28. fi
  29. while [ 1 ];do
  30. if [ "$SOURCEFILE" = "" ];then
  31. DEFAULT=""
  32. else
  33. DEFAULT="<default>${SOURCEFILE}</default>"
  34. fi
  35. #main gui
  36. S='
  37. <window title="Bcrypt - '$(gettext 'File encryption')'" icon-name="gtk-file">
  38. <vbox space-expand="true" space-fill="true">
  39. '"`/usr/lib/gtkdialog/xml_info scale "file_lock.svg" 60 "$(gettext 'Bcrypt is a utility to encrypt or decrypt a file')" "$(gettext 'Drag the file you want to <b>encrypt or decrypt</b> into the field or use the browse-button.')" "<b><span color='"'red'"'>$MSG2</span></b>"`"'
  40. <frame>
  41. <vbox space-expand="false" space-fill="false">
  42. <hbox>
  43. <text space-expand="false" space-fill="false"><label>"'$(gettext 'File to encrypt / decrypt')' "</label></text>
  44. <text space-expand="true" space-fill="true"><label>""</label></text>
  45. </hbox>
  46. <hbox>
  47. <entry accept="file" fs-title="Bcrypt">
  48. '${DEFAULT}'
  49. <variable>SOURCEFILE</variable>
  50. </entry>
  51. <button>
  52. '"`/usr/lib/gtkdialog/xml_button-icon open`"'
  53. <action type="fileselect">SOURCEFILE</action>
  54. </button>
  55. </hbox>
  56. <text><label>""</label></text>
  57. <hbox>
  58. <text><label>"'$(gettext 'Enter password')' "</label></text>
  59. <entry width-request="200" space-expand="false" space-fill="false">
  60. <visible>password</visible>
  61. <variable>PASSWORD1</variable>
  62. </entry>
  63. </hbox>
  64. <hbox>
  65. <text><label>"'$(gettext 'Reenter password')' "</label></text>
  66. <entry width-request="200" space-expand="false" space-fill="false">
  67. <visible>password</visible>
  68. <variable>PASSWORD2</variable>
  69. <action signal="activate">exit:OK</action>
  70. </entry>
  71. </hbox>
  72. <text height-request="5"><label>""</label></text>
  73. </vbox>
  74. </frame>
  75. <hbox space-expand="false" space-fill="false">
  76. <hbox space-expand="false" space-fill="false">
  77. <button>
  78. <label>'$(gettext "Help")'</label>
  79. '"`/usr/lib/gtkdialog/xml_button-icon help`"'
  80. <action>bcrypt_gui_help</action>
  81. </button>
  82. </hbox>
  83. <text space-expand="true" space-fill="true"><label>""</label></text>
  84. <button space-expand="false" space-fill="false">
  85. <label>'$(gettext "Cancel")'</label>
  86. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  87. <action>exit:CANCEL</action>
  88. </button>
  89. <button space-expand="false" space-fill="false">
  90. <label>'$(gettext "Ok")'</label>
  91. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  92. <action>exit:OK</action>
  93. </button>
  94. '"`/usr/lib/gtkdialog/xml_scalegrip`"'
  95. </hbox>
  96. </vbox>
  97. </window>'
  98. export Bcrypt="$S"
  99. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  100. RETVALS="`gtkdialog -p Bcrypt`"
  101. eval "$RETVALS"
  102. [ "$EXIT" != "OK" ] && break
  103. [ "$PASSWORD1" = "" ] && break
  104. [ "$PASSWORD2" = "" ] && break
  105. [ "$SOURCEFILE" = "" ] && break
  106. [ ! -f "$SOURCEFILE" ] && break
  107. BYTES1=`echo -n "$PASSWORD1" | wc -c`
  108. if [ $BYTES1 -lt 8 ];then #w482 dogone advised, change from -le.
  109. MSG2="$(gettext 'Password needs to be at least 8 characters!')"
  110. continue
  111. fi
  112. if [ "$PASSWORD1" != "$PASSWORD2" ];then
  113. MSG2="$(gettext 'The password entries do not match!')"
  114. continue
  115. fi
  116. DIRNAME="`dirname "$SOURCEFILE"`"
  117. BASENAME="`basename "$SOURCEFILE"`"
  118. cd "$DIRNAME"
  119. if [ "`echo "$BASENAME" | grep '\.bfe$'`" != "" ];then
  120. echo "$PASSWORD1" | bcrypt $BASENAME 2>/tmp/bcrypt_error
  121. else
  122. echo "$PASSWORD1
  123. $PASSWORD2" | bcrypt $BASENAME 2>/tmp/bcrypt_error
  124. fi
  125. if [ $? -ne 0 ];then
  126. MSG2="`cat /tmp/bcrypt_error | tail -n 1`"
  127. continue
  128. fi
  129. break
  130. done
  131. exit
  132. #fi
  133. ###END###