Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcryan committed Jan 14, 2016
2 parents ad9993e + a3b8699 commit 540c0ce
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 55 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=JM6E65M2GLXHE" target="_blank"><img src="http://akamai.technicalnotebook.com/alfred-workflow-images/donate.png" border="0" alt="PayPal — The safer, easier way to pay online."></a>

Expand Down Expand Up @@ -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
Expand Down
Binary file added workflow/applescript.scpt
Binary file not shown.
126 changes: 72 additions & 54 deletions workflow/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<array>
<dict>
<key>destinationuid</key>
<string>D05CE8AC-DFE8-46FC-A600-3163BAF7AD23</string>
<string>D21298B3-763D-48F9-A804-C3B06D3B70E7</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
Expand Down Expand Up @@ -56,11 +56,11 @@
<array>
<dict>
<key>destinationuid</key>
<string>D05CE8AC-DFE8-46FC-A600-3163BAF7AD23</string>
<string>D21298B3-763D-48F9-A804-C3B06D3B70E7</string>
<key>modifiers</key>
<integer>262144</integer>
<key>modifiersubtext</key>
<string>Initiate LP Command Line Client Login</string>
<string>Login to LastPass Vault</string>
</dict>
<dict>
<key>destinationuid</key>
Expand Down Expand Up @@ -153,7 +153,7 @@
<string></string>
</dict>
</array>
<key>D05CE8AC-DFE8-46FC-A600-3163BAF7AD23</key>
<key>D21298B3-763D-48F9-A804-C3B06D3B70E7</key>
<array/>
<key>DE8D285B-733F-4B2D-91DA-4613717E2005</key>
<array>
Expand Down Expand Up @@ -188,6 +188,31 @@
<string>LastPass CLI</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>0</integer>
<key>script</key>
<string>--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 &gt; /dev/null 2&gt;&amp;1"end trytry 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 [email protected]' and try again." as critical returnend try--Try to get a login timeout if a custom one has been set, if not we set to defaulttry 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 28800end trytell application "Finder" set current_path to container of (path to me) as aliasend tellset current_unix_path to POSIX path of current_path--set osascript to current_unix_path &amp; "passwordInput.osascript"set osascript to (system attribute "alfred_preferences") &amp; "/workflows/" &amp; (system attribute "alfred_workflow_uid") &amp; "/passwordInput.osascript"do shell script "export LPASS_ASKPASS=\"" &amp; osascript &amp; "\""do shell script "launchctl setenv LPASS_ASKPASS \"" &amp; osascript &amp; "\""do shell script "launchctl setenv LPASS_AGENT_TIMEOUT " &amp; login_timeouttell 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 ifend tell--improvement required here, test if we actually HAVE an lpass_binary and if not error outif ("{query}" = "scriptlocationnotset") then
display notification "Please wait... the alfred search will be presented once login is complete." with title "LastPass Login"
end ifdo shell script "/bin/bash -c '" &amp; "export TERM=\"xterm-256color\" &amp;&amp; export LPASS_ASKPASS=\"" &amp; osascript &amp; "\" &amp;&amp; export LPASS_AGENT_TIMEOUT=" &amp; login_timeout &amp; " &amp;&amp; " &amp; lpass_binary &amp; " login --trust \"" &amp; login_email &amp; "\" &amp;&amp; clear &amp;&amp; " &amp; lpass_binary &amp; " ls --sync=now &gt; /dev/null 2&gt;&amp;1 &amp;&amp; exit 0'"

if ("{query}" = "scriptlocationnotset") then
tell application "Alfred 2" to search "lp "
end if</string>
<key>type</key>
<integer>6</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>D21298B3-763D-48F9-A804-C3B06D3B70E7</string>
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -234,40 +259,6 @@
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>escaping</key>
<integer>0</integer>
<key>script</key>
<string>killall -9 lpass &gt; /dev/null 2&gt;&amp;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 [email protected]'";
fi
launchctl setenv LPASS_AGENT_TIMEOUT $login_timeout &amp;&amp; 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" &amp;&amp; clear &amp;&amp; echo 'Forcing vault synchronisation... Please wait... (this window will close when complete)' &amp;&amp; $lpass_exec ls --sync=now &gt; /dev/null 2&gt;&amp;1 &amp;&amp; exit 0</string>
</dict>
<key>type</key>
<string>alfred.workflow.action.terminalcommand</string>
<key>uid</key>
<string>D05CE8AC-DFE8-46FC-A600-3163BAF7AD23</string>
<key>version</key>
<integer>0</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -332,7 +323,7 @@ print $details[0];
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>127</integer>
<integer>126</integer>
<key>keyword</key>
<string>lp</string>
<key>queuedelaycustom</key>
Expand All @@ -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{&lt;?xml version="1.0"?&gt;\n&lt;items&gt;\n};
print qq{&lt;item uid="error-login"&gt;&lt;arg&gt;scriptlocationnotset&lt;/arg&gt;&lt;title&gt;It appears you are not logged in to LastPass.&lt;/title&gt;&lt;subtitle&gt;Please login using the 'lplogin' command or press 'ctrl' + enter to login now.&lt;/subtitle&gt;&lt;icon&gt;icon.png&lt;/icon&gt;&lt;/item&gt;\n};
print "&lt;/items&gt;\n";
exit 1;
}
my ($agent, $agentErr, $agentErrCode) = capture {
system('ps -ef | grep "lpass \[agent\]" | grep -v grep | grep -v "perl"');
};
Expand All @@ -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{&lt;?xml version="1.0"?&gt;\n&lt;items&gt;\n};
Expand All @@ -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{&lt;item uid="$id"&gt;&lt;arg&gt;'$name', '$id'&lt;/arg&gt;&lt;title&gt;$name&lt;/title&gt;&lt;subtitle&gt;&lt;/subtitle&gt;&lt;icon&gt;icon.png&lt;/icon&gt;&lt;/item&gt;\n};
print qq{&lt;item uid="$id"&gt;&lt;arg&gt;&lt;![CDATA['$name', '$id']]&gt;&lt;/arg&gt;&lt;title&gt;&lt;![CDATA[$name]]&gt;&lt;/title&gt;&lt;subtitle&gt;&lt;/subtitle&gt;&lt;icon&gt;icon.png&lt;/icon&gt;&lt;/item&gt;\n};
}
print "&lt;/items&gt;\n";
}
exit 0;</string>
<key>subtext</key>
<string>Search Laspass Vault</string>
<string>Search Lastpass Vault</string>
<key>title</key>
<string>Search Laspass Vault</string>
<string>Search Lastpass Vault</string>
<key>type</key>
<integer>4</integer>
<key>withspace</key>
Expand Down Expand Up @@ -539,7 +552,7 @@ print $details[0];
<key>escaping</key>
<integer>127</integer>
<key>script</key>
<string>
<string>#!/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
Expand Down Expand Up @@ -657,7 +670,9 @@ exit 0;</string>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>security add-generic-password -a "alfred-lastpass-email-address" -s "alfred-lastpass-email-address" -w "{query}" -C "note" -U
<string>#!/bin/bash
security add-generic-password -a "alfred-lastpass-email-address" -s "alfred-lastpass-email-address" -w "{query}" -C "note" -U
echo "{query}"</string>
<key>type</key>
Expand Down Expand Up @@ -747,7 +762,9 @@ echo "{query}"</string>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>security add-generic-password -a "alfred-lastpass-login-timeout" -s "alfred-lastpass-login-timeout" -w "{query}" -C "note" -U
<string>#!/bin/bash
security add-generic-password -a "alfred-lastpass-login-timeout" -s "alfred-lastpass-login-timeout" -w "{query}" -C "note" -U
echo "{query}"</string>
<key>type</key>
Expand Down Expand Up @@ -781,13 +798,14 @@ echo "{query}"</string>
</dict>
</array>
<key>readme</key>
<string>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 —&gt; http://technicalnotebook.com/jira/browse/LPALFRED/
<string>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!</string>
My thanks go out to LastPass for their awesome product and the new CLI!
Version: 1.4.2</string>
<key>uidata</key>
<dict>
<key>01DFFE0F-13AB-4E19-AC39-8E2177548224</key>
Expand Down Expand Up @@ -870,7 +888,7 @@ My thanks go out to LastPass for their awesome product and the new CLI!</string>
<key>ypos</key>
<real>380</real>
</dict>
<key>D05CE8AC-DFE8-46FC-A600-3163BAF7AD23</key>
<key>D21298B3-763D-48F9-A804-C3B06D3B70E7</key>
<dict>
<key>ypos</key>
<real>160</real>
Expand Down
13 changes: 13 additions & 0 deletions workflow/passwordInput.osascript
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 540c0ce

Please sign in to comment.