chupacabra 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfaa094a87841fef12866c5ce7a1fc975cb642f0
4
- data.tar.gz: 7da4daa7002ce40c5053fad4d996aca648354927
3
+ metadata.gz: db7a66ca88de111dd84901ecdab5769515b6e043
4
+ data.tar.gz: f2a0dc74dc23193a7c4e081db08e7158feeac75b
5
5
  SHA512:
6
- metadata.gz: 9e0e18c05e3541a0d2c9f1ca95b8aca28e87e6535f0dcb32f4d11a26d182a463d4c21c7836705bd9b7b8177ff598185bd18c03221d34743955b29a2b08439712
7
- data.tar.gz: 129adb2c4fb29a30e32db9a0430c140eb21bf54d52a7ebfdf4cfa12337a1911c45cd27e5d7a4b446350da068015bb77672d3045f85b254a51e798309972dfc2e
6
+ metadata.gz: bdc590c9e5825d6dc5e1d85e67e5551e73eed25e4d7a16e84a6f75de7d59003683dea3031f2d9e7a52be35c559ce4d8eba954df4f5ce925e2b5ae1624300c2ca
7
+ data.tar.gz: 047356004cbeb3a60912cbff5c5af45c8a4dd4a1738daafa02f86f7a0d48c10220a3e158e262ef43f54eee083e00663a8943028180801d0d37a471a50edeed3a
data/bin/chupacabra CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
4
  require 'chupacabra'
3
5
  require 'optparse'
4
6
  require 'ostruct'
@@ -12,6 +14,33 @@ options.verbose = false
12
14
  OptionParser.new do |opts|
13
15
  opts.banner = "Usage: chupacabra [options]"
14
16
 
17
+ opts.on("-c", "--clear", "Wipe out all your chupacabra passwords") do |port|
18
+ Chupacabra::Storage.clear
19
+ puts "Your chupacabra is a virgin now."
20
+ exit
21
+ end
22
+
23
+ opts.on("-i", "--install", "Install Apple service") do |port|
24
+ Chupacabra::System.install
25
+ puts "Service installed in #{Chupacabra::System.user_service_path}"
26
+ puts ""
27
+ puts "You can create keyboard shortcut with:"
28
+ puts "System Preferences -> Keyboard -> Keyboard Shortcuts -> Services -> Chupacabra"
29
+ puts ''
30
+ exit
31
+ end
32
+
33
+ opts.on("-l", "--log", "Turns on logging to #{Chupacabra::System.log_path}") do |port|
34
+ Chupacabra.log = true
35
+ puts "Logging into #{Chupacabra::System.log_path}"
36
+ end
37
+
38
+ opts.on("-u", "--uninstall", "Uninstall Apple service") do |port|
39
+ Chupacabra::System.uninstall
40
+ puts "Service removed from #{Chupacabra::System.user_service_path}"
41
+ exit
42
+ end
43
+
15
44
  opts.on("-v", "--verbose", "Prints password") do |port|
16
45
  options.verbose = true
17
46
  end
@@ -16,11 +16,11 @@ module Chupacabra
16
16
  end
17
17
 
18
18
  def [](key)
19
- data[extract(key)]
19
+ data[key]
20
20
  end
21
21
 
22
22
  def []=(key, value)
23
- data[extract(key)] = value
23
+ data[key] = value
24
24
  save
25
25
  end
26
26
 
@@ -48,13 +48,5 @@ module Chupacabra
48
48
  file << Crypto.encrypt(Marshal.dump(@data), @password)
49
49
  end
50
50
  end
51
-
52
- def extract(key)
53
- if key =~ /https?\:\/\/(?:www.)?([^\/\?]+)/
54
- $1
55
- else
56
- raise ArgumentError, "#{key} doesn't look like url"
57
- end
58
- end
59
51
  end
60
52
  end
@@ -1,12 +1,15 @@
1
1
  require 'base64'
2
+ require 'digest'
3
+ require 'pathname'
4
+ require 'fileutils'
2
5
 
3
6
  module Chupacabra
4
7
  module System
5
8
  extend self
6
9
 
7
10
  def get_password
8
- return get_env_password if get_env_password
9
- password = get_password_from_dialog
11
+ return get_env_password unless get_env_password.empty?
12
+ password = Digest::SHA1.hexdigest(get_password_from_dialog)
10
13
  raise "Password can't be empty" if !password || password.empty?
11
14
  set_env_password(password)
12
15
  password
@@ -33,10 +36,99 @@ module Chupacabra
33
36
  `uname`.strip == 'Linux'
34
37
  end
35
38
 
39
+ def front_app
40
+ run_script(
41
+ <<-EOS
42
+ tell application "System Events"
43
+ return name of first application process whose frontmost is true
44
+ end tell
45
+ EOS
46
+ )
47
+ end
48
+
49
+ def get_browser_url
50
+ app = front_app
51
+ run_script(
52
+ case app
53
+ when 'Google Chrome', 'Google Chrome Canary'
54
+ %Q(tell application "#{app}" to return URL of active tab of front window)
55
+ when 'Camino'
56
+ %Q(tell application "#{app}" to return URL of current tab of front browser window)
57
+ when 'Safari', 'Webkit', 'Opera'
58
+ %Q(tell application "#{app}" to return URL of front document)
59
+ when 'firefox'
60
+ <<-EOS
61
+ tell application "System Events"
62
+ keystroke "l" using command down
63
+ keystroke "c" using command down
64
+ end tell
65
+ delay 0.1
66
+ return the clipboard
67
+ EOS
68
+ end
69
+ )
70
+ end
71
+
72
+ def alert(message)
73
+ run_script(
74
+ <<-EOS
75
+ tell application "#{front_app}"
76
+ activate
77
+ display alert "#{message}" as warning
78
+ end tell
79
+ EOS
80
+ )
81
+ end
82
+
83
+ def install
84
+ user_service_contents = user_service_path + 'Contents'
85
+ user_service_contents.mkpath unless user_service_contents.exist?
86
+ chupacabra_service_contents = Pathname.new(
87
+ File.expand_path('../../../osx/Chupacabra.workflow/Contents', __FILE__)
88
+ )
89
+
90
+ %w(document.wflow Info.plist).each do |filename|
91
+ (user_service_contents + filename).open('w') do |file|
92
+ file << (chupacabra_service_contents + filename).read
93
+ end
94
+ end
95
+ end
96
+
97
+ def uninstall
98
+ FileUtils.rm_rf user_service_path
99
+ end
100
+
101
+ def user_service_path
102
+ if Chupacabra.test?
103
+ Pathname.new(ENV['HOME']) + 'Library/Services/Chupacabra_test.workflow'
104
+ else
105
+ Pathname.new(ENV['HOME']) + 'Library/Services/Chupacabra.workflow'
106
+ end
107
+ end
108
+
109
+ def log(message)
110
+ return unless Chupacabra.log
111
+ log_path.open('a') do |file|
112
+ file << message
113
+ file << "\n"
114
+ end
115
+ message
116
+ end
117
+
118
+ def log_path
119
+ (Pathname.new(ENV['HOME']) + 'chupacabra.log')
120
+ end
121
+
36
122
  private
37
123
 
124
+ def run_script(script)
125
+ return unless script
126
+ raise ArgumentError, "Script can't contain single quotes" if script =~ /'/
127
+ `osascript #{script.split("\n").collect{|line| " -e '#{line.strip}'"}.join}`.strip
128
+ end
129
+
38
130
  def password_variable
39
- Chupacabra.test? ? 'CHUPACABRA' : 'CHUPACABRA_TEST'
131
+ Chupacabra.test? ? 'CHUPACABRA_TEST' : 'CHUPACABRA'
40
132
  end
41
133
 
42
134
  def get_password_from_dialog
@@ -53,17 +145,22 @@ module Chupacabra
53
145
  'with title "Chupacabra"' +
54
146
  'with icon caution with hidden answer'
55
147
 
56
- `osascript -e 'tell application "Finder"' -e "activate" -e '#{dialog}' -e 'end tell'`
148
+ script = <<-EOS
149
+ tell application "#{front_app}"
150
+ activate
151
+ #{dialog}
152
+ end tell
153
+ EOS
154
+
155
+ run_script(script)
57
156
  end
58
157
 
59
158
  def get_env_password
60
- password64 = `launchctl getenv #{password_variable}`.strip
61
- return if password64.empty?
62
- Base64.decode64(password64).strip
63
- end
159
+ `launchctl getenv #{password_variable}`.strip
160
+ end
64
161
 
65
162
  def set_env_password(password)
66
- `launchctl setenv #{password_variable} '#{Base64.encode64(password).strip}'`
163
+ `launchctl setenv #{password_variable} '#{password}'`
67
164
  end
68
165
  end
69
166
  end
@@ -1,3 +1,3 @@
1
1
  module Chupacabra
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/chupacabra.rb CHANGED
@@ -6,16 +6,24 @@ require 'chupacabra/version'
6
6
  module Chupacabra
7
7
  extend self
8
8
  attr_accessor :env
9
+ attr_accessor :log
9
10
 
10
11
  def get_password
12
+ Chupacabra::System.set_clipboard('')
11
13
  data = Storage.new(System.get_password)
12
- key = System.get_clipboard
14
+ key = extract_url(System.get_browser_url) || "app: #{System.front_app}"
15
+ System.log(key)
13
16
  if data[key]
14
17
  output(data[key])
15
18
  else
16
19
  data[key] = Crypto.generate_password
17
20
  output(data[key])
18
21
  end
22
+
23
+ rescue Chupacabra::Crypto::WrongPassword
24
+ System.clear
25
+ System.alert('Wrong password!')
26
+ 'Wrong password'
19
27
  end
20
28
 
21
29
  def test?
@@ -25,7 +33,12 @@ module Chupacabra
25
33
  private
26
34
 
27
35
  def output(text)
28
- System.set_clipboard(text)
36
+ System.set_clipboard(text) if System.osx?
29
37
  text
30
38
  end
39
+
40
+ def extract_url(key)
41
+ return unless key
42
+ "web: #{$1}" if key =~ /https?\:\/\/(?:www.)?([^\/\?]+)/
43
+ end
31
44
  end
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>NSServices</key>
6
+ <array>
7
+ <dict>
8
+ <key>NSMenuItem</key>
9
+ <dict>
10
+ <key>default</key>
11
+ <string>Chupacabra</string>
12
+ </dict>
13
+ <key>NSMessage</key>
14
+ <string>runWorkflowAsService</string>
15
+ </dict>
16
+ </array>
17
+ </dict>
18
+ </plist>
@@ -0,0 +1,203 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>AMApplicationBuild</key>
6
+ <string>339.2</string>
7
+ <key>AMApplicationVersion</key>
8
+ <string>2.2.4</string>
9
+ <key>AMDocumentVersion</key>
10
+ <string>2</string>
11
+ <key>actions</key>
12
+ <array>
13
+ <dict>
14
+ <key>action</key>
15
+ <dict>
16
+ <key>AMAccepts</key>
17
+ <dict>
18
+ <key>Container</key>
19
+ <string>List</string>
20
+ <key>Optional</key>
21
+ <true/>
22
+ <key>Types</key>
23
+ <array>
24
+ <string>com.apple.cocoa.string</string>
25
+ </array>
26
+ </dict>
27
+ <key>AMActionVersion</key>
28
+ <string>2.0.2</string>
29
+ <key>AMApplication</key>
30
+ <array>
31
+ <string>Automator</string>
32
+ </array>
33
+ <key>AMParameterProperties</key>
34
+ <dict>
35
+ <key>COMMAND_STRING</key>
36
+ <dict/>
37
+ <key>CheckedForUserDefaultShell</key>
38
+ <dict/>
39
+ <key>inputMethod</key>
40
+ <dict/>
41
+ <key>shell</key>
42
+ <dict/>
43
+ <key>source</key>
44
+ <dict/>
45
+ </dict>
46
+ <key>AMProvides</key>
47
+ <dict>
48
+ <key>Container</key>
49
+ <string>List</string>
50
+ <key>Types</key>
51
+ <array>
52
+ <string>com.apple.cocoa.string</string>
53
+ </array>
54
+ </dict>
55
+ <key>ActionBundlePath</key>
56
+ <string>/System/Library/Automator/Run Shell Script.action</string>
57
+ <key>ActionName</key>
58
+ <string>Run Shell Script</string>
59
+ <key>ActionParameters</key>
60
+ <dict>
61
+ <key>COMMAND_STRING</key>
62
+ <string>chupacabra</string>
63
+ <key>CheckedForUserDefaultShell</key>
64
+ <true/>
65
+ <key>inputMethod</key>
66
+ <integer>0</integer>
67
+ <key>shell</key>
68
+ <string>/bin/bash</string>
69
+ <key>source</key>
70
+ <string></string>
71
+ </dict>
72
+ <key>BundleIdentifier</key>
73
+ <string>com.apple.RunShellScript</string>
74
+ <key>CFBundleVersion</key>
75
+ <string>2.0.2</string>
76
+ <key>CanShowSelectedItemsWhenRun</key>
77
+ <false/>
78
+ <key>CanShowWhenRun</key>
79
+ <true/>
80
+ <key>Category</key>
81
+ <array>
82
+ <string>AMCategoryUtilities</string>
83
+ </array>
84
+ <key>Class Name</key>
85
+ <string>RunShellScriptAction</string>
86
+ <key>InputUUID</key>
87
+ <string>C2E1151F-70F9-45DA-A66F-E5821E7D65CE</string>
88
+ <key>Keywords</key>
89
+ <array>
90
+ <string>Shell</string>
91
+ <string>Script</string>
92
+ <string>Command</string>
93
+ <string>Run</string>
94
+ <string>Unix</string>
95
+ </array>
96
+ <key>OutputUUID</key>
97
+ <string>02C1B9C8-898D-4995-967A-73E7E47A97C2</string>
98
+ <key>UUID</key>
99
+ <string>4E665380-85F1-457E-B9A0-E49253C1AB30</string>
100
+ <key>UnlocalizedApplications</key>
101
+ <array>
102
+ <string>Automator</string>
103
+ </array>
104
+ <key>arguments</key>
105
+ <dict>
106
+ <key>0</key>
107
+ <dict>
108
+ <key>default value</key>
109
+ <integer>0</integer>
110
+ <key>name</key>
111
+ <string>inputMethod</string>
112
+ <key>required</key>
113
+ <string>0</string>
114
+ <key>type</key>
115
+ <string>0</string>
116
+ <key>uuid</key>
117
+ <string>0</string>
118
+ </dict>
119
+ <key>1</key>
120
+ <dict>
121
+ <key>default value</key>
122
+ <string></string>
123
+ <key>name</key>
124
+ <string>source</string>
125
+ <key>required</key>
126
+ <string>0</string>
127
+ <key>type</key>
128
+ <string>0</string>
129
+ <key>uuid</key>
130
+ <string>1</string>
131
+ </dict>
132
+ <key>2</key>
133
+ <dict>
134
+ <key>default value</key>
135
+ <false/>
136
+ <key>name</key>
137
+ <string>CheckedForUserDefaultShell</string>
138
+ <key>required</key>
139
+ <string>0</string>
140
+ <key>type</key>
141
+ <string>0</string>
142
+ <key>uuid</key>
143
+ <string>2</string>
144
+ </dict>
145
+ <key>3</key>
146
+ <dict>
147
+ <key>default value</key>
148
+ <string></string>
149
+ <key>name</key>
150
+ <string>COMMAND_STRING</string>
151
+ <key>required</key>
152
+ <string>0</string>
153
+ <key>type</key>
154
+ <string>0</string>
155
+ <key>uuid</key>
156
+ <string>3</string>
157
+ </dict>
158
+ <key>4</key>
159
+ <dict>
160
+ <key>default value</key>
161
+ <string>/bin/sh</string>
162
+ <key>name</key>
163
+ <string>shell</string>
164
+ <key>required</key>
165
+ <string>0</string>
166
+ <key>type</key>
167
+ <string>0</string>
168
+ <key>uuid</key>
169
+ <string>4</string>
170
+ </dict>
171
+ </dict>
172
+ <key>conversionLabel</key>
173
+ <integer>0</integer>
174
+ <key>isViewVisible</key>
175
+ <true/>
176
+ <key>location</key>
177
+ <string>423.000000:670.000000</string>
178
+ <key>nibPath</key>
179
+ <string>/System/Library/Automator/Run Shell Script.action/Contents/Resources/English.lproj/main.nib</string>
180
+ </dict>
181
+ <key>isViewVisible</key>
182
+ <true/>
183
+ </dict>
184
+ </array>
185
+ <key>connectors</key>
186
+ <dict/>
187
+ <key>workflowMetaData</key>
188
+ <dict>
189
+ <key>serviceApplicationBundleID</key>
190
+ <string></string>
191
+ <key>serviceApplicationPath</key>
192
+ <string></string>
193
+ <key>serviceInputTypeIdentifier</key>
194
+ <string>com.apple.Automator.nothing</string>
195
+ <key>serviceOutputTypeIdentifier</key>
196
+ <string>com.apple.Automator.nothing</string>
197
+ <key>serviceProcessesInput</key>
198
+ <integer>0</integer>
199
+ <key>workflowTypeIdentifier</key>
200
+ <string>com.apple.Automator.servicesMenu</string>
201
+ </dict>
202
+ </dict>
203
+ </plist>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chupacabra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dawid Sklodowski
@@ -65,11 +65,20 @@ files:
65
65
  - lib/chupacabra/system.rb
66
66
  - lib/chupacabra/version.rb
67
67
  - lib/chupacabra.rb
68
+ - osx/Chupacabra.workflow/Contents/document.wflow
69
+ - osx/Chupacabra.workflow/Contents/Info.plist
68
70
  homepage: http://github.com/dawid-sklodowski/chupacabra
69
71
  licenses:
70
72
  - MIT
71
73
  metadata: {}
72
- post_install_message:
74
+ post_install_message: |2+
75
+ Thank you for installing chupacabra.
76
+
77
+ To hook chupacabra into your MacOS please issue command:
78
+
79
+ chupacabra --install
80
+ --------------------
81
+
73
82
  rdoc_options: []
74
83
  require_paths:
75
84
  - lib