diff --git a/README.md b/README.md index 929e742..0b68fa0 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,16 @@ Simple yet powerful integration with the Lastpass CLI so you can now get your passwords out of your Lastpass vault and straight into the clipboard from within Alfred. +## Important note for v.1.4.2 +Please note, v1.4.2 and higer of the workflow require v0.7.1 or higher of the LastPass CLI to operate, if you do not have this then it will not work. Therefore please ensure you update to the latest version of the CLI. + ## How to use the workflow Check out the official YouTube video, it will give you a quick two and a half minute rundown (updated for v1.2 and above). [![ScreenShot](http://akamai.technicalnotebook.com/alfred-workflow-images/lastpass-cli-for-alfred/demonstration_of_lastpass_workflow_for_alfred_v1_2.png)](https://www.youtube.com/watch?v=DJvtjBs2r6E) ## Donations -This workflow represents many many hours effort of development, testing and rework. So if you love the workflow, and get use out of it every day, if you would like to donate as a thank you to buy me more caffeine giving Diet Coke, some Cake, or to put towards a shiny new gadget you can [donate to me via Paypal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JM6E65M2GLXHE). +This workflow (and the 1.4.2 update especially) represents many many hours effort of development, testing and rework. So if you love the workflow, and get use out of it every day, if you would like to donate as a thank you to buy me more caffeine giving Diet Coke, some Cake, or to put towards a shiny new gadget you can [donate to me via Paypal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JM6E65M2GLXHE). PayPal — The safer, easier way to pay online. @@ -49,6 +52,18 @@ This workflow represents many many hours effort of development, testing and rewo ## History +* Version 1.4.2 + 1. NOTE: This version *requires* the LastPass CLI v 0.7.1 or higher due to this new feature --> Login process completely changed over to use AppleScript (cleaner and nicer). This was thanks to work between myself and Bob from LastPass who maintains the official LastPass CLI to add a feature allowing an external login prompt to be used. + 2. Login password prompt now uses an AppleScript password prompt. + 3. Fix to allow you to search for words in any order. + 4. Vault item's which now require re-authentication will pop up the AppleScript login prompt. + 5. Has now been tested with a Vault with over 30,000 items for performance tweaks. (I have since been told by LastPass support their soft limit is significantly lower than this at ~2500 items explains why I was having some issues in testing). + 6. More resilient escaping of text in the XML to ensure that special characters should not cause any issues. + 7. Fixed missing quotes in some areas that could cause issues with spaces. + 8. Squashed a little regex bug and wiped up the goo. + 9. Fixed issues with spaces in certain paths we referenced + 10. Fixed how the initial login process is run after a reboot. This required the changes made to how we manage the login process and it has subsequently been cleaned up significantly. + 11. Other minor general tweaks. * Version 1.2 1. Bug - Removed deprecated framework code 2. Bug - Merged [pull request #4](https://github.com/stuartcryan/lastpass-alfred-workflow/pull/4) from [jsquyres](https://github.com/jsquyres) "we-love-macports-too" to support macports installs of the lastpass-CLI diff --git a/workflow/applescript.scpt b/workflow/applescript.scpt new file mode 100644 index 0000000..0dcf4a5 Binary files /dev/null and b/workflow/applescript.scpt differ diff --git a/workflow/info.plist b/workflow/info.plist index 7334ebf..4539d64 100644 --- a/workflow/info.plist +++ b/workflow/info.plist @@ -12,7 +12,7 @@ destinationuid - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 + D21298B3-763D-48F9-A804-C3B06D3B70E7 modifiers 0 modifiersubtext @@ -56,11 +56,11 @@ destinationuid - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 + D21298B3-763D-48F9-A804-C3B06D3B70E7 modifiers 262144 modifiersubtext - Initiate LP Command Line Client Login + Login to LastPass Vault destinationuid @@ -153,7 +153,7 @@ - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 + D21298B3-763D-48F9-A804-C3B06D3B70E7 DE8D285B-733F-4B2D-91DA-4613717E2005 @@ -188,6 +188,31 @@ LastPass CLI objects + + config + + concurrently + + escaping + 0 + script + --display notification "Please wait... preparing login process..." with title "LastPass Login" --Kill any previous login process as sometimes they hang or a user may interrupt them, if there are none (which there often are...) we will get an error response which we ignore. try do shell script "killall -9 lpass > /dev/null 2>&1" end try try set login_email to do shell script "`perl -e 'use strict; use warnings; my $emailAddress =`security find-generic-password -w -s \"alfred-lastpass-email-address\"`; chomp $emailAddress; print $emailAddress;'`" on error display alert "Email address not set" message "It appears that no email address has been set. Please run 'lpsetemail your_email@example.com' and try again." as critical return end try --Try to get a login timeout if a custom one has been set, if not we set to default try set login_timeout to do shell script "`perl -e 'use strict; use warnings; my $loginTimeout =`security find-generic-password -w -s \"alfred-lastpass-login-timeout\"`; chomp $loginTimeout; print $loginTimeout;'`" on error set login_timeout to 28800 end try tell application "Finder" set current_path to container of (path to me) as alias end tell set current_unix_path to POSIX path of current_path --set osascript to current_unix_path & "passwordInput.osascript" set osascript to (system attribute "alfred_preferences") & "/workflows/" & (system attribute "alfred_workflow_uid") & "/passwordInput.osascript" do shell script "export LPASS_ASKPASS=\"" & osascript & "\"" do shell script "launchctl setenv LPASS_ASKPASS \"" & osascript & "\"" do shell script "launchctl setenv LPASS_AGENT_TIMEOUT " & login_timeout tell application "Finder" if exists POSIX file "/usr/bin/lpass" then set lpass_binary to "/usr/bin/lpass" else if exists POSIX file "/usr/local/bin/lpass" then set lpass_binary to "/usr/local/bin/lpass" else if exists POSIX file "/opt/local/bin/lpass" then set lpass_binary to "/opt/local/bin/lpass" end if end tell --improvement required here, test if we actually HAVE an lpass_binary and if not error out if ("{query}" = "scriptlocationnotset") then +display notification "Please wait... the alfred search will be presented once login is complete." with title "LastPass Login" +end if do shell script "/bin/bash -c '" & "export TERM=\"xterm-256color\" && export LPASS_ASKPASS=\"" & osascript & "\" && export LPASS_AGENT_TIMEOUT=" & login_timeout & " && " & lpass_binary & " login --trust \"" & login_email & "\" && clear && " & lpass_binary & " ls --sync=now > /dev/null 2>&1 && exit 0'" + +if ("{query}" = "scriptlocationnotset") then +tell application "Alfred 2" to search "lp " +end if + type + 6 + + type + alfred.workflow.action.script + uid + D21298B3-763D-48F9-A804-C3B06D3B70E7 + version + 0 + config @@ -234,40 +259,6 @@ version 0 - - config - - escaping - 0 - script - killall -9 lpass > /dev/null 2>&1 -clear -login_email=`perl -e 'use strict; use warnings; my $emailAddress =\`security find-generic-password -w -s "alfred-lastpass-email-address"\`; chomp $emailAddress; print $emailAddress;'` -login_timeout=`perl -e 'use strict; use warnings; my $loginTimeout =\`security find-generic-password -w -s "alfred-lastpass-login-timeout"\`; chomp $loginTimeout; print $loginTimeout;'` -if [[ -z $login_timeout ]]; then -login_timeout="28800" -fi -clear -if [[ -z $login_email ]]; then -echo "It appears that no email address has been set"; -echo "Please run 'lpsetemail your_email@example.com'"; -fi -launchctl setenv LPASS_AGENT_TIMEOUT $login_timeout && export LPASS_AGENT_TIMEOUT=$login_timeout -for f in lpass /usr/local/bin/lpass /opt/local/bin/lpass /usr/bin/lpass; do -if test -x $f; then -lpass_exec=$f -fi -done -clear -$lpass_exec login --trust "$login_email" && clear && echo 'Forcing vault synchronisation... Please wait... (this window will close when complete)' && $lpass_exec ls --sync=now > /dev/null 2>&1 && exit 0 - - type - alfred.workflow.action.terminalcommand - uid - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 - version - 0 - config @@ -332,7 +323,7 @@ print $details[0]; argumenttype 0 escaping - 127 + 126 keyword lp queuedelaycustom @@ -359,6 +350,22 @@ $search=~ s/\'/\\'/g; # exit 0; #} +my $loginScriptLocation = `launchctl getenv LPASS_ASKPASS`; + +chomp($loginScriptLocation); + +#check if getenv LPASS_ASKPASS is not set... if it isn't a login definitely +#hasn't been completed by the flow and needs to be. + +if ($loginScriptLocation eq "") +{ +print qq{<?xml version="1.0"?>\n<items>\n}; +print qq{<item uid="error-login"><arg>scriptlocationnotset</arg><title>It appears you are not logged in to LastPass.</title><subtitle>Please login using the 'lplogin' command or press 'ctrl' + enter to login now.</subtitle><icon>icon.png</icon></item>\n}; + +print "</items>\n"; +exit 1; +} + my ($agent, $agentErr, $agentErrCode) = capture { system('ps -ef | grep "lpass \[agent\]" | grep -v grep | grep -v "perl"'); }; @@ -369,8 +376,13 @@ foreach my $f (qw@lpass /usr/local/bin/lpass /opt/local/bin/lpass /usr/bin/lpass if (-x $f); } +#add multiple grep statements to deal with multiple words as AWK on OSx +#does not allow for case insensitive searches + +$search=~ s/ /" | grep -i "/g; + my ($results, $err, $errorCode) = capture { - system($lpass_exec . ' ls --sync=no | grep -i ' . $search); + system($lpass_exec . ' ls --sync=no | grep -i "' . $search . '"'); }; print qq{<?xml version="1.0"?>\n<items>\n}; @@ -393,24 +405,25 @@ exit 2; }else { my @resultsArray = split /\n/, $results; + foreach my $result (@resultsArray) { my $id; my $name; -if ($result =~ '^(.*) \[id: ([0-9]*)\]$'){ -$name = $1; -$id = $2; +if ($result =~ '^(.*) +\[id: ([0-9]*)\]'){ +$name = "$1"; +$id = "$2"; } -print qq{<item uid="$id"><arg>'$name', '$id'</arg><title>$name</title><subtitle></subtitle><icon>icon.png</icon></item>\n}; +print qq{<item uid="$id"><arg><![CDATA['$name', '$id']]></arg><title><![CDATA[$name]]></title><subtitle></subtitle><icon>icon.png</icon></item>\n}; } print "</items>\n"; } exit 0; subtext - Search Laspass Vault + Search Lastpass Vault title - Search Laspass Vault + Search Lastpass Vault type 4 withspace @@ -539,7 +552,7 @@ print $details[0]; escaping 127 script - + #!/bin/bash for f in lpass /usr/local/bin/lpass /opt/local/bin/lpass /usr/bin/lpass; do if test -x $f; then lpass_exec=$f @@ -657,7 +670,9 @@ exit 0; escaping 102 script - security add-generic-password -a "alfred-lastpass-email-address" -s "alfred-lastpass-email-address" -w "{query}" -C "note" -U + #!/bin/bash + +security add-generic-password -a "alfred-lastpass-email-address" -s "alfred-lastpass-email-address" -w "{query}" -C "note" -U echo "{query}" type @@ -747,7 +762,9 @@ echo "{query}" escaping 102 script - security add-generic-password -a "alfred-lastpass-login-timeout" -s "alfred-lastpass-login-timeout" -w "{query}" -C "note" -U + #!/bin/bash + +security add-generic-password -a "alfred-lastpass-login-timeout" -s "alfred-lastpass-login-timeout" -w "{query}" -C "note" -U echo "{query}" type @@ -781,13 +798,14 @@ echo "{query}" readme - See installation instructions at http://technicalnotebook.com/wiki/display/ALFREDWORKFLOWS/Installation+Instructions+-+LastPass+Workflow+for+Alfred - -For support please log a ticket on my JIRA BugTracker —> http://technicalnotebook.com/jira/browse/LPALFRED/ + See installation instructions at https://github.com/stuartcryan/lastpass-alfred-workflow +For support please log a ticket on https://github.com/stuartcryan/lastpass-alfred-workflow NOTE: This Alfred Workflow is not affiliated in any way with LastPass. The LastPass trademark and logo are owned by LastPass.com. The LastPass logo and product name have been used with permission of the LastPass team. -My thanks go out to LastPass for their awesome product and the new CLI! +My thanks go out to LastPass for their awesome product and the new CLI! + +Version: 1.4.2 uidata 01DFFE0F-13AB-4E19-AC39-8E2177548224 @@ -870,7 +888,7 @@ My thanks go out to LastPass for their awesome product and the new CLI! ypos 380 - D05CE8AC-DFE8-46FC-A600-3163BAF7AD23 + D21298B3-763D-48F9-A804-C3B06D3B70E7 ypos 160 diff --git a/workflow/passwordInput.osascript b/workflow/passwordInput.osascript new file mode 100755 index 0000000..a0ec2b1 --- /dev/null +++ b/workflow/passwordInput.osascript @@ -0,0 +1,13 @@ +#!/usr/bin/osascript +set my_password to display dialog ¬ + "Please enter your LastPass Vault password:" with title ¬ + "Password" with icon caution ¬ + default answer ¬ + "" buttons {"Cancel", "OK"} default button 2 ¬ + giving up after 295 ¬ + with hidden answer +if length of (text returned of my_password) is not 0 then + return (text returned of my_password) +else + display dialog "You didn't enter a password!" buttons ["OK"] default button 1 +end if