Guest User

Untitled

a guest
Sep 27th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. [[ -z $TARGET ]] || PASS=`python -c "import keyring; print(keyring.get_password("$TARGET", "(printf '%q' $USERNAME)"))"`
  2.  
  3. #!/bin/bash
  4.  
  5. SAVE=FALSE
  6.  
  7. case $# in
  8. 1)
  9. USERVAR=USER
  10. PASSVAR=PASS
  11. USERNAME=$1
  12. ;;
  13. 3)
  14. USERVAR=$1
  15. PASSVAR=$2
  16. USERNAME=$3
  17. ;;
  18. 4)
  19. USERVAR=$1
  20. PASSVAR=$2
  21. USERNAME=$3
  22. TARGET=$4
  23. ;;
  24. *)
  25. echo '
  26. getpasswd: invalid number of arguments.
  27.  
  28. Presents a username and password prompt dialog, with keyring support.
  29. The user can accept the offered username or change it, and enter a password.
  30.  
  31. Use: getpasswd [usernamevar passwordvar] initial_username [targetname]
  32.  
  33. usernamevar defaults to USER
  34. passwordvar defaults to PASS
  35. User name and password will be returned in usernamevar and passwordvar
  36.  
  37. If targetname is specified,
  38. - the password wil be taken from the keyring if the user/target combination exists.
  39. - if the combination does not exist, the caller will be prompted
  40. and given the option to store it in the keyring.
  41. '
  42. exit 1
  43. ;;
  44. esac
  45.  
  46. #echo USERVAR=$USERVAR
  47. #echo PASSVAR=$PASSVAR
  48. #echo USERNAME=$USERNAME
  49. #echo TARGET=$TARGET
  50.  
  51. [[ -z $TARGET ]] || PASS=`python -c "import keyring; print(keyring.get_password("$TARGET", "(printf '%q' $USERNAME)"))"`
  52.  
  53. #echo from keyring: $PASS
  54.  
  55. if [[ -z $PASS || $PASS == "None" ]]
  56. then
  57. if [[ -z $TARGET ]]
  58. then
  59. FORM=$(yad --center --width=380
  60. --window-icon="gtk-execute" --image="gcr-password"
  61. --title "Login"
  62. --form --field="User name" "$USERNAME"
  63. --field="Password":H
  64. --focus-field=2)
  65. else
  66. FORM=$(yad --center --width=380
  67. --window-icon="gtk-execute" --image="gcr-password"
  68. --title "Login"
  69. --form --field="User name" "$USERNAME"
  70. --field="Password":H
  71. --field="Save in keyring?":CHK
  72. --focus-field=2)
  73. printf -v SAVE "%s" $(echo $FORM | awk -F '|' '{ print $3 }')
  74. fi
  75. #echo $FORM
  76. printf -v USERNAME "%s" $(echo $FORM | awk -F '|' '{ print $1 }')
  77. printf -v PASS "%s" $(echo $FORM | awk -F '|' '{ print $2 }')
  78. fi
  79.  
  80. #echo eval $USERVAR=$(printf '%q' $USERNAME)
  81. #echo eval $PASSVAR=$(printf '%q' $PASS)
  82. eval $USERVAR=$(printf '%q' $USERNAME)
  83. eval $PASSVAR=$(printf '%q' $PASS)
  84.  
  85. #echo .
  86. #echo TARGET=$TARGET
  87. #echo USERNAME=$USERNAME
  88. #echo PASS=$PASS
  89. #echo SAVE=$SAVE
  90.  
  91. if [[ -n $TARGET && -n $PASS && $PASS != "None" && $SAVE != "FALSE" ]]
  92. then
  93. #echo saving to keyring
  94. python -c "import keyring; keyring.set_password("$TARGET", "(printf '%q' $USERNAME)", "$PASS")"
  95. fi
  96.  
  97. . getpasswd USER PASS domain\user computername
  98. [[ -z $PASS || $PASS == "None" ]] && exit 1
  99. xfreerdp /v:hostname_or_ip /f /u:$USER /p:$PASS /cert-ignore +fonts /drive:ubuntu-home,$HOME /printer
Add Comment
Please, Sign In to add comment