milton 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/History.txt +7 -0
  2. data/lib/milton.rb +47 -10
  3. metadata +3 -3
@@ -1,3 +1,10 @@
1
+ === 1.1.0 / 2009-07-09
2
+
3
+ * 1 major enhancement
4
+ * milton will now automatically update your password with a random one
5
+ * 1 minor enhancement
6
+ * Added --debug which prints out lots of stuff you don't care about
7
+
1
8
  === 1.0.1 / 2009-06-30
2
9
 
3
10
  * 1 Bugfix
@@ -12,7 +12,7 @@ require 'yaml'
12
12
 
13
13
  class Milton
14
14
 
15
- VERSION = '1.0.1'
15
+ VERSION = '1.1.0'
16
16
 
17
17
  def self.load_config config_file
18
18
  unless File.exist? config_file then
@@ -32,8 +32,9 @@ class Milton
32
32
 
33
33
  def self.parse_args argv
34
34
  options = {
35
- 'date' => nil,
36
- 'view' => false
35
+ 'date' => nil,
36
+ 'debug' => false,
37
+ 'view' => false,
37
38
  }
38
39
 
39
40
  opts = OptionParser.new do |opt|
@@ -59,6 +60,11 @@ the current week with eight hours/day.
59
60
  options['date'] = value
60
61
  end
61
62
 
63
+ opt.on('--debug',
64
+ 'Print out URLs we visit') do |debug|
65
+ options['debug'] = debug
66
+ end
67
+
62
68
  opt.on('--month [DATE]', Date, 'Select month by day') do |value|
63
69
  options['view'] = true # For your safety, you can only view months
64
70
  options['month'] = value || Date.today
@@ -119,7 +125,7 @@ the current week with eight hours/day.
119
125
  form['txtPassword'] = password
120
126
  form['__EVENTTARGET'] = 'btnLogin'
121
127
  }.submit
122
- change_password if @page.body =~ /Old Password/
128
+ change_password password if @page.body =~ /Old Password/
123
129
  @page = @page.link_with(:text => 'Time Sheet').click
124
130
  end
125
131
 
@@ -140,11 +146,17 @@ the current week with eight hours/day.
140
146
  end
141
147
 
142
148
  def run config
149
+ @debug = config['debug']
150
+ if @debug then
151
+ @agent.log = Logger.new $stderr
152
+ @agent.log.formatter = proc do |s, t, p, m| "#{m}\n" end
153
+ end
154
+
143
155
  self.client_name = config['client_name']
144
156
  login config['username'], config['password']
145
157
 
146
- date = config['date']
147
- month = config['month']
158
+ date = config['date']
159
+ month = config['month']
148
160
 
149
161
  if date then
150
162
  select_week_of date
@@ -160,6 +172,9 @@ the current week with eight hours/day.
160
172
  end
161
173
 
162
174
  extract_timesheet
175
+ rescue => e
176
+ $stderr.puts @page.parser if @debug and @page
177
+ raise
163
178
  end
164
179
 
165
180
  ##
@@ -265,10 +280,32 @@ the current week with eight hours/day.
265
280
 
266
281
  private
267
282
 
268
- def change_password
269
- puts "Your password needs to be updated. :-("
270
- puts "\t#{@page.uri}"
271
- exit
283
+ def change_password old_password
284
+ new_password = (0...8).map { (rand(26) + 97).chr }.join
285
+
286
+ @page = @page.form('Form1') { |form|
287
+ form['portPasswordReset:fldOldPassword'] = old_password
288
+ form['portPasswordReset:fldNewPassword'] = new_password
289
+ form['portPasswordReset:fldConfirmPassword'] = new_password
290
+ form['__PageDirty'] = 'False'
291
+ form['__EVENTTARGET'] = 'portPasswordReset:btnSubmit'
292
+ }.submit
293
+
294
+ if @page then
295
+ config_file = File.join Gem.user_home, '.milton'
296
+
297
+ config = YAML.load_file config_file
298
+
299
+ config['password'] = new_password
300
+
301
+ open config_file, 'w' do |io|
302
+ io.write config.to_yaml
303
+ end
304
+
305
+ puts 'Changed your password and updated ~/.milton'
306
+ else
307
+ raise 'unable to change password :('
308
+ end
272
309
  end
273
310
 
274
311
  def select_range start, finish
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milton
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-30 00:00:00 -07:00
12
+ date: 2009-07-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.2.0
33
+ version: 2.3.2
34
34
  version:
35
35
  description: Milton fills out your ADP ezLaborManager timesheet
36
36
  email: