bcrypt_gui 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #140712 SFR: fix special chars in PASSWORD + some other minor improvements
  13. export TEXTDOMAIN=bcrypt_gui
  14. export TEXTDOMAINDIR=/usr/share/locale
  15. export OUTPUT_CHARSET=UTF-8
  16. . gettext.sh
  17. export LANGORG=$LANG
  18. if [ "`which bcrypt`" = "" ];then
  19. /usr/lib/gtkdialog/box_ok "Bcrypt" error "$(gettext "The 'bcrypt' package must be installed first.")"
  20. exit
  21. fi
  22. #if [ ! $1 ];then
  23. #run from the menu. this section was originally created by 'coolpup', jan. 2009.
  24. #modified by BK april 2009.
  25. SOURCEFILE=""
  26. if [ "$1" ];then
  27. SOURCEFILE="$1"
  28. [ ! -f "$SOURCEFILE" ] && exit
  29. fi
  30. while [ 1 ];do
  31. if [ "$SOURCEFILE" = "" ];then
  32. DEFAULT=""
  33. else
  34. DEFAULT="<default>${SOURCEFILE}</default>"
  35. fi
  36. #main gui
  37. S='
  38. <window title="Bcrypt - '$(gettext 'File encryption')'" icon-name="gtk-file">
  39. <vbox space-expand="true" space-fill="true">
  40. '"`/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>"`"'
  41. <frame>
  42. <vbox space-expand="false" space-fill="false">
  43. <hbox>
  44. <text space-expand="false" space-fill="false"><label>"'$(gettext 'File to encrypt / decrypt')' "</label></text>
  45. <text space-expand="true" space-fill="true"><label>""</label></text>
  46. </hbox>
  47. <hbox>
  48. <entry accept="file" fs-title="Bcrypt">
  49. '${DEFAULT}'
  50. <variable>SOURCEFILE</variable>
  51. </entry>
  52. <button>
  53. '"`/usr/lib/gtkdialog/xml_button-icon open`"'
  54. <action type="fileselect">SOURCEFILE</action>
  55. </button>
  56. </hbox>
  57. <hbox>
  58. <checkbox>
  59. <variable>KEEPINPUTFILE</variable>
  60. <label>"'$(gettext "Do NOT remove input file after processing")'"</label>
  61. </checkbox>
  62. </hbox>
  63. <text><label>""</label></text>
  64. <hbox>
  65. <text><label>"'$(gettext 'Enter password')' "</label></text>
  66. <entry width-request="200" space-expand="false" space-fill="false">
  67. <visible>password</visible>
  68. <variable>PASSWORD1</variable>
  69. </entry>
  70. </hbox>
  71. <hbox>
  72. <text><label>"'$(gettext 'Reenter password')' "</label></text>
  73. <entry width-request="200" space-expand="false" space-fill="false">
  74. <visible>password</visible>
  75. <variable>PASSWORD2</variable>
  76. <action signal="activate">exit:OK</action>
  77. </entry>
  78. </hbox>
  79. <text height-request="5"><label>""</label></text>
  80. </vbox>
  81. </frame>
  82. <hbox space-expand="false" space-fill="false">
  83. <hbox space-expand="false" space-fill="false">
  84. <button>
  85. <label>'$(gettext "Help")'</label>
  86. '"`/usr/lib/gtkdialog/xml_button-icon help`"'
  87. <action>bcrypt_gui_help</action>
  88. </button>
  89. </hbox>
  90. <text space-expand="true" space-fill="true"><label>""</label></text>
  91. <button space-expand="false" space-fill="false">
  92. <label>'$(gettext "Cancel")'</label>
  93. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  94. <action>exit:CANCEL</action>
  95. </button>
  96. <button space-expand="false" space-fill="false">
  97. <label>'$(gettext "Ok")'</label>
  98. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  99. <action>exit:OK</action>
  100. </button>
  101. '"`/usr/lib/gtkdialog/xml_scalegrip`"'
  102. </hbox>
  103. </vbox>
  104. </window>'
  105. export Bcrypt="$S"
  106. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  107. I=$IFS; IFS='
  108. '
  109. for RETVAL in `gtkdialog -p Bcrypt`; do
  110. if [[ "$RETVAL" == "PASSWORD1"* ]]; then
  111. PASSWORD1="`echo $RETVAL | cut -f2- -d '"' | rev | cut -f2- -d '"' | rev`"
  112. elif [[ "$RETVAL" == "PASSWORD2"* ]]; then
  113. PASSWORD2="`echo $RETVAL | cut -f2- -d '"' | rev | cut -f2- -d '"' | rev`"
  114. else
  115. eval "$RETVAL"
  116. fi
  117. done
  118. IFS=$I
  119. [ "$EXIT" != "OK" ] && break
  120. [ "$PASSWORD1" = "" ] && break
  121. [ "$PASSWORD2" = "" ] && break
  122. [ "$SOURCEFILE" = "" ] && break
  123. [ ! -f "$SOURCEFILE" ] && break
  124. [ "$KEEPINPUTFILE" = "true" ] && BOPTS='-r' || BOPTS=''
  125. BYTES1=`echo -n "$PASSWORD1" | wc -c`
  126. if [ $BYTES1 -lt 8 ];then #w482 dogone advised, change from -le.
  127. MSG2="$(gettext 'Password needs to be at least 8 characters!')"
  128. continue
  129. fi
  130. if [ "$PASSWORD1" != "$PASSWORD2" ];then
  131. MSG2="$(gettext 'The password entries do not match!')"
  132. continue
  133. fi
  134. DIRNAME="`dirname "$SOURCEFILE"`"
  135. BASENAME="`basename "$SOURCEFILE"`"
  136. cd "$DIRNAME"
  137. if [ "`echo "$BASENAME" | grep '\.bfe$'`" != "" ];then
  138. echo "$PASSWORD1" | bcrypt $BOPTS "$BASENAME" 2>/tmp/bcrypt_error
  139. else
  140. echo "$PASSWORD1
  141. $PASSWORD2" | bcrypt $BOPTS "$BASENAME" 2>/tmp/bcrypt_error
  142. fi
  143. if [ $? -ne 0 ];then
  144. MSG2="`cat /tmp/bcrypt_error | tail -n 1`"
  145. continue
  146. fi
  147. break
  148. done
  149. exit
  150. #fi
  151. ###END###