depot3 3.0.15 → 3.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +21 -1
- data/README.md +6 -6
- data/bin/d3 +3 -3
- data/bin/d3admin +257 -293
- data/lib/d3/admin/add.rb +98 -94
- data/lib/d3/admin/interactive.rb +195 -161
- data/lib/d3/admin/options.rb +424 -412
- data/lib/d3/admin/prefs.rb +73 -42
- data/lib/d3/admin/validate.rb +50 -43
- data/lib/d3/client/auth.rb +4 -2
- data/lib/d3/client/class_methods.rb +169 -119
- data/lib/d3/client/receipt.rb +2 -2
- data/lib/d3/database.rb +167 -180
- data/lib/d3/log.rb +2 -3
- data/lib/d3/package/server_actions.rb +2 -3
- data/lib/d3/package/validate.rb +63 -70
- data/lib/d3/version.rb +1 -2
- metadata +2 -2
data/lib/d3/client/receipt.rb
CHANGED
@@ -572,7 +572,7 @@ module D3
|
|
572
572
|
end
|
573
573
|
|
574
574
|
@apple_pkg_ids = args[:apple_pkg_ids]
|
575
|
-
@installed_at = args[:installed_at]
|
575
|
+
@installed_at = args[:installed_at] ? args[:installed_at].to_time : Time.now
|
576
576
|
|
577
577
|
@removable = args[:removable]
|
578
578
|
@prohibiting_processes = args[:prohibiting_processes]
|
@@ -1130,7 +1130,7 @@ Last brought to foreground: #{last_usage_display}
|
|
1130
1130
|
usage_times = D3.parse_plist plist
|
1131
1131
|
my_usage_keys = usage_times.keys.map{|p| Pathname.new(p)}
|
1132
1132
|
exp_paths_with_usage = @expiration_paths & my_usage_keys
|
1133
|
-
exp_paths_with_usage.each{|p| all_usages << usage_times[p.to_s] }
|
1133
|
+
exp_paths_with_usage.each{|p| all_usages << usage_times[p.to_s].to_time }
|
1134
1134
|
end # do plist
|
1135
1135
|
|
1136
1136
|
@last_usage = all_usages.compact.max
|
data/lib/d3/database.rb
CHANGED
@@ -22,76 +22,74 @@
|
|
22
22
|
###
|
23
23
|
###
|
24
24
|
|
25
|
-
|
26
25
|
###
|
27
26
|
module D3
|
28
27
|
|
28
|
+
###
|
29
29
|
module Database
|
30
30
|
|
31
31
|
################# Module Constants #################
|
32
32
|
|
33
|
-
|
34
33
|
### Booleans are stored as 1's and 0's in the db.
|
35
34
|
TRUE_VAL = 1
|
36
35
|
FALSE_VAL = 0
|
37
36
|
|
38
37
|
# This table has info about the JSS schema
|
39
|
-
SCHEMA_TABLE =
|
38
|
+
SCHEMA_TABLE = 'db_schema_information'.freeze
|
40
39
|
|
41
|
-
# the minimum JSS schema version
|
42
|
-
MIN_SCHEMA_VERSION =
|
40
|
+
# the minimum JSS schema version allowed
|
41
|
+
MIN_SCHEMA_VERSION = '9.4'.freeze
|
43
42
|
|
44
|
-
# the
|
45
|
-
MAX_SCHEMA_VERSION = "
|
43
|
+
# the max JSS schema version allowed
|
44
|
+
MAX_SCHEMA_VERSION = "10.999.0"
|
46
45
|
|
47
46
|
### these Proc objects allow us to encapsulate and pass around various
|
48
47
|
### blocks of code more easily for converting data between their mysql
|
49
48
|
### representation and the Ruby classses we use internally.
|
50
49
|
|
51
50
|
### Ruby Time objects are stored as JSS epochs (unix epoch plus milliseconds)
|
52
|
-
EPOCH_TO_TIME =
|
51
|
+
EPOCH_TO_TIME = proc { |v| v.nil? || v.to_s.empty? ? nil : JSS.epoch_to_time(v) }
|
53
52
|
|
54
53
|
### JSS epochs (unix epoch plus milliseconds) as used as Ruby Time objects
|
55
|
-
TIME_TO_EPOCH =
|
54
|
+
TIME_TO_EPOCH = proc { |v| v.nil? || v.to_s.empty? ? nil : v.to_jss_epoch }
|
56
55
|
|
57
56
|
### Integers come from the database as strings, but empty ones should be nil, not zero, as #to_i would do
|
58
|
-
STRING_TO_INT =
|
57
|
+
STRING_TO_INT = proc { |v| v.nil? || v.to_s.empty? ? nil : v.to_i }
|
59
58
|
|
60
59
|
### Some values are stored as comma-separated strings, but used as Arrays
|
61
|
-
COMMA_STRING_TO_ARRAY =
|
60
|
+
COMMA_STRING_TO_ARRAY = proc { |v| JSS.to_s_and_a(v)[:arrayform] }
|
62
61
|
|
63
62
|
### Some values are stored as comma-separated strings, but used as Arrays of Pathnames
|
64
|
-
COMMA_STRING_TO_ARRAY_OF_PATHNAMES =
|
65
|
-
ARRAY_OF_PATHNAMES_TO_COMMA_STRING =
|
63
|
+
COMMA_STRING_TO_ARRAY_OF_PATHNAMES = proc { |v| JSS.to_s_and_a(v)[:arrayform].map { |p| Pathname.new(p) } }
|
64
|
+
ARRAY_OF_PATHNAMES_TO_COMMA_STRING = proc { |v| v.is_a?(Array) ? v.join(', ') : '' }
|
66
65
|
|
67
66
|
### Some values are used as Arrays but stored as comma-separated strings
|
68
|
-
ARRAY_TO_COMMA_STRING =
|
67
|
+
ARRAY_TO_COMMA_STRING = proc { |v| JSS.to_s_and_a(v)[:stringform] }
|
69
68
|
|
70
69
|
### Some values are stored in the DB as YAML dumps
|
71
|
-
RUBY_TO_YAML =
|
70
|
+
RUBY_TO_YAML = proc { |v| YAML.dump v }
|
72
71
|
|
73
|
-
YAML_TO_RUBY =
|
72
|
+
YAML_TO_RUBY = proc { |v| YAML.load v.to_s }
|
74
73
|
|
75
74
|
### Booleans are stored as zero and one
|
76
|
-
BOOL_TO_INT =
|
75
|
+
BOOL_TO_INT = proc { |v| v == true ? TRUE_VAL : FALSE_VAL }
|
77
76
|
|
78
77
|
### Booleans are stored as zero and one
|
79
|
-
INT_TO_BOOL =
|
78
|
+
INT_TO_BOOL = proc { |v| v.to_i == FALSE_VAL ? false : true }
|
80
79
|
|
81
80
|
### Regexps are stored as strings
|
82
|
-
STRING_TO_REGEXP =
|
81
|
+
STRING_TO_REGEXP = proc { |v| v.to_s.empty? ? nil : Regexp.new(v.to_s) }
|
83
82
|
|
84
83
|
### Regexps are stored as strings
|
85
|
-
REGEXP_TO_STRING =
|
84
|
+
REGEXP_TO_STRING = proc { |v| v.to_s }
|
86
85
|
|
87
86
|
### Status values are stored as strings, but used as symbols
|
88
|
-
STATUS_TO_STRING =
|
89
|
-
STRING_TO_STATUS =
|
87
|
+
STATUS_TO_STRING = proc { |v| v.to_s }
|
88
|
+
STRING_TO_STATUS = proc { |v| v.to_sym }
|
90
89
|
|
91
90
|
### Expiration paths are stored as strings, but used as Pathnames
|
92
|
-
STRING_TO_PATHNAME =
|
93
|
-
PATHNAME_TO_STRING =
|
94
|
-
|
91
|
+
STRING_TO_PATHNAME = proc { |v| Pathname.new v.to_s }
|
92
|
+
PATHNAME_TO_STRING = proc { |v| v.to_s }
|
95
93
|
|
96
94
|
### The MySQL table that defines which JSS Packages are a part of d3
|
97
95
|
###
|
@@ -173,177 +171,176 @@ module D3
|
|
173
171
|
###
|
174
172
|
### See also the attributes of {D3::Package}, which mostly mirror the
|
175
173
|
###
|
176
|
-
PACKAGE_TABLE = {
|
174
|
+
PACKAGE_TABLE = {
|
175
|
+
table_name: 'd3_packages',
|
177
176
|
|
178
|
-
:
|
177
|
+
field_definitions: {
|
179
178
|
|
180
|
-
:
|
181
|
-
:
|
182
|
-
:
|
183
|
-
:
|
184
|
-
:
|
185
|
-
:
|
179
|
+
id: {
|
180
|
+
field_name: 'package_id',
|
181
|
+
sql_type: 'int(11) NOT NULL',
|
182
|
+
index: :unique,
|
183
|
+
to_sql: nil,
|
184
|
+
to_ruby: STRING_TO_INT
|
186
185
|
},
|
187
186
|
|
188
|
-
:
|
189
|
-
:
|
190
|
-
:
|
191
|
-
:
|
192
|
-
:
|
193
|
-
:
|
187
|
+
basename: {
|
188
|
+
field_name: 'basename',
|
189
|
+
sql_type: 'varchar(60) NOT NULL',
|
190
|
+
index: true,
|
191
|
+
to_sql: nil,
|
192
|
+
to_ruby: nil
|
194
193
|
},
|
195
194
|
|
196
|
-
:
|
197
|
-
:
|
198
|
-
:
|
199
|
-
:
|
200
|
-
:
|
201
|
-
:
|
195
|
+
version: {
|
196
|
+
field_name: 'version',
|
197
|
+
sql_type: 'varchar(30) NOT NULL',
|
198
|
+
index: nil,
|
199
|
+
to_sql: nil,
|
200
|
+
to_ruby: nil
|
202
201
|
},
|
203
202
|
|
204
|
-
:
|
205
|
-
:
|
206
|
-
:
|
207
|
-
:
|
208
|
-
:
|
209
|
-
:
|
203
|
+
revision: {
|
204
|
+
field_name: 'revision',
|
205
|
+
sql_type: 'int(4) NOT NULL',
|
206
|
+
index: nil,
|
207
|
+
to_sql: nil,
|
208
|
+
to_ruby: STRING_TO_INT
|
210
209
|
},
|
211
210
|
|
212
|
-
:
|
213
|
-
:
|
214
|
-
:
|
215
|
-
:
|
216
|
-
:
|
217
|
-
:
|
211
|
+
apple_receipt_data: {
|
212
|
+
field_name: 'apple_receipt_data',
|
213
|
+
sql_type: 'text',
|
214
|
+
index: nil,
|
215
|
+
to_sql: RUBY_TO_YAML,
|
216
|
+
to_ruby: YAML_TO_RUBY
|
218
217
|
},
|
219
218
|
|
220
|
-
:
|
221
|
-
:
|
222
|
-
:
|
223
|
-
:
|
224
|
-
:
|
225
|
-
:
|
219
|
+
added_date: {
|
220
|
+
field_name: 'added_date_epoch',
|
221
|
+
sql_type: 'bigint(32) DEFAULT NULL',
|
222
|
+
index: nil,
|
223
|
+
to_sql: TIME_TO_EPOCH,
|
224
|
+
to_ruby: EPOCH_TO_TIME
|
226
225
|
},
|
227
226
|
|
228
|
-
:
|
229
|
-
:
|
230
|
-
:
|
231
|
-
:
|
232
|
-
:
|
233
|
-
:
|
227
|
+
added_by: {
|
228
|
+
field_name: 'added_by',
|
229
|
+
sql_type: 'varchar(30)',
|
230
|
+
index: nil,
|
231
|
+
to_sql: nil,
|
232
|
+
to_ruby: nil
|
234
233
|
},
|
235
234
|
|
236
|
-
:
|
237
|
-
:
|
238
|
-
:
|
239
|
-
:
|
240
|
-
:
|
241
|
-
:
|
235
|
+
status: {
|
236
|
+
field_name: 'status',
|
237
|
+
sql_type: "varchar(30) DEFAULT 'pilot'",
|
238
|
+
index: nil,
|
239
|
+
to_sql: STATUS_TO_STRING,
|
240
|
+
to_ruby: STRING_TO_STATUS
|
242
241
|
},
|
243
242
|
|
244
|
-
:
|
245
|
-
:
|
246
|
-
:
|
247
|
-
:
|
248
|
-
:
|
249
|
-
:
|
243
|
+
release_date: {
|
244
|
+
field_name: 'release_date_epoch',
|
245
|
+
sql_type: 'bigint(32) DEFAULT NULL',
|
246
|
+
index: nil,
|
247
|
+
to_sql: TIME_TO_EPOCH,
|
248
|
+
to_ruby: EPOCH_TO_TIME
|
250
249
|
},
|
251
250
|
|
252
|
-
:
|
253
|
-
:
|
254
|
-
:
|
255
|
-
:
|
256
|
-
:
|
257
|
-
:
|
251
|
+
released_by: {
|
252
|
+
field_name: 'released_by',
|
253
|
+
sql_type: 'varchar(30)',
|
254
|
+
index: nil,
|
255
|
+
to_sql: nil,
|
256
|
+
to_ruby: nil
|
258
257
|
},
|
259
258
|
|
260
|
-
:
|
261
|
-
:
|
262
|
-
:
|
263
|
-
:
|
264
|
-
:
|
265
|
-
:
|
259
|
+
auto_groups: {
|
260
|
+
field_name: 'auto_install_groups',
|
261
|
+
sql_type: 'text',
|
262
|
+
index: nil,
|
263
|
+
to_sql: ARRAY_TO_COMMA_STRING,
|
264
|
+
to_ruby: COMMA_STRING_TO_ARRAY
|
266
265
|
},
|
267
266
|
|
268
|
-
:
|
269
|
-
:
|
270
|
-
:
|
271
|
-
:
|
272
|
-
:
|
273
|
-
:
|
267
|
+
excluded_groups: {
|
268
|
+
field_name: 'excluded_groups',
|
269
|
+
sql_type: 'text',
|
270
|
+
index: nil,
|
271
|
+
to_sql: ARRAY_TO_COMMA_STRING,
|
272
|
+
to_ruby: COMMA_STRING_TO_ARRAY
|
274
273
|
},
|
275
274
|
|
276
|
-
:
|
277
|
-
:
|
278
|
-
:
|
279
|
-
:
|
280
|
-
:
|
281
|
-
:
|
275
|
+
prohibiting_processes: {
|
276
|
+
field_name: 'prohibiting_process',
|
277
|
+
sql_type: 'varchar(100)',
|
278
|
+
index: nil,
|
279
|
+
to_sql: ARRAY_TO_COMMA_STRING,
|
280
|
+
to_ruby: COMMA_STRING_TO_ARRAY
|
282
281
|
},
|
283
282
|
|
284
|
-
:
|
285
|
-
:
|
286
|
-
:
|
287
|
-
:
|
288
|
-
:
|
289
|
-
:
|
283
|
+
remove_first: {
|
284
|
+
field_name: 'remove_first',
|
285
|
+
sql_type: "tinyint(1) DEFAULT '0'",
|
286
|
+
index: nil,
|
287
|
+
to_sql: BOOL_TO_INT,
|
288
|
+
to_ruby: INT_TO_BOOL
|
290
289
|
},
|
291
290
|
|
292
|
-
:
|
293
|
-
:
|
294
|
-
:
|
295
|
-
:
|
296
|
-
:
|
297
|
-
:
|
291
|
+
pre_install_script_id: {
|
292
|
+
field_name: 'pre_install_id',
|
293
|
+
sql_type: 'int(11)',
|
294
|
+
index: nil,
|
295
|
+
to_sql: nil,
|
296
|
+
to_ruby: STRING_TO_INT
|
298
297
|
},
|
299
298
|
|
300
|
-
:
|
301
|
-
:
|
302
|
-
:
|
303
|
-
:
|
304
|
-
:
|
305
|
-
:
|
299
|
+
post_install_script_id: {
|
300
|
+
field_name: 'post_install_id',
|
301
|
+
sql_type: 'int(11)',
|
302
|
+
index: nil,
|
303
|
+
to_sql: nil,
|
304
|
+
to_ruby: STRING_TO_INT
|
306
305
|
},
|
307
306
|
|
308
|
-
:
|
309
|
-
:
|
310
|
-
:
|
311
|
-
:
|
312
|
-
:
|
313
|
-
:
|
307
|
+
pre_remove_script_id: {
|
308
|
+
field_name: 'pre_remove_id',
|
309
|
+
sql_type: 'int(11)',
|
310
|
+
index: nil,
|
311
|
+
to_sql: nil,
|
312
|
+
to_ruby: STRING_TO_INT
|
314
313
|
},
|
315
314
|
|
316
|
-
:
|
317
|
-
:
|
318
|
-
:
|
319
|
-
:
|
320
|
-
:
|
321
|
-
:
|
315
|
+
post_remove_script_id: {
|
316
|
+
field_name: 'post_remove_id',
|
317
|
+
sql_type: 'int(11)',
|
318
|
+
index: nil,
|
319
|
+
to_sql: nil,
|
320
|
+
to_ruby: STRING_TO_INT
|
322
321
|
},
|
323
322
|
|
324
|
-
:
|
325
|
-
:
|
326
|
-
:
|
327
|
-
:
|
328
|
-
:
|
329
|
-
:
|
323
|
+
expiration: {
|
324
|
+
field_name: 'expiration',
|
325
|
+
sql_type: 'int(11)',
|
326
|
+
index: nil,
|
327
|
+
to_sql: nil,
|
328
|
+
to_ruby: STRING_TO_INT
|
330
329
|
},
|
331
330
|
|
332
|
-
:
|
333
|
-
:
|
334
|
-
:
|
335
|
-
:
|
336
|
-
:
|
337
|
-
:
|
331
|
+
expiration_paths: {
|
332
|
+
field_name: 'expiration_app_path',
|
333
|
+
sql_type: 'varchar(300)',
|
334
|
+
index: nil,
|
335
|
+
to_sql: ARRAY_OF_PATHNAMES_TO_COMMA_STRING,
|
336
|
+
to_ruby: COMMA_STRING_TO_ARRAY_OF_PATHNAMES
|
338
337
|
}
|
339
338
|
},
|
340
339
|
|
341
|
-
:
|
342
|
-
|
340
|
+
other_indexes: [
|
341
|
+
'UNIQUE KEY `edition` (`basename`,`version`,`revision`)'
|
343
342
|
]
|
344
|
-
}
|
345
|
-
|
346
|
-
|
343
|
+
}.freeze # end PACKAGE_TABLE
|
347
344
|
|
348
345
|
################# Module Methods #################
|
349
346
|
|
@@ -363,20 +360,17 @@ module D3
|
|
363
360
|
###
|
364
361
|
###
|
365
362
|
def self.table_records(table_def)
|
366
|
-
|
367
363
|
recs = []
|
368
364
|
|
369
365
|
result = JSS.db.query "SELECT * FROM #{table_def[:table_name]}"
|
370
366
|
|
371
367
|
# parse each record into a hash
|
372
368
|
result.each_hash do |record|
|
373
|
-
|
374
369
|
rec = {}
|
375
370
|
|
376
371
|
# go through each field in the record, adding it to the hash
|
377
372
|
# converting it to its ruby data type if defined in field conversions
|
378
|
-
table_def[:field_definitions].each_pair do |key,field_def|
|
379
|
-
|
373
|
+
table_def[:field_definitions].each_pair do |key, field_def|
|
380
374
|
# do we convert the value from the DB to something else in ruby?
|
381
375
|
if field_def[:to_ruby]
|
382
376
|
rec[key] = field_def[:to_ruby].call record[field_def[:field_name]]
|
@@ -385,14 +379,12 @@ module D3
|
|
385
379
|
else
|
386
380
|
rec[key] = record[field_def[:field_name]]
|
387
381
|
end # if
|
388
|
-
|
389
382
|
end # do key, field_def
|
390
383
|
|
391
384
|
recs << rec
|
392
|
-
|
393
385
|
end # do record
|
394
386
|
|
395
|
-
|
387
|
+
recs
|
396
388
|
end # self.table_records(table_def)
|
397
389
|
|
398
390
|
### Print the sql for creating the d3_packages table
|
@@ -404,7 +396,6 @@ module D3
|
|
404
396
|
puts self.create_table(:display)
|
405
397
|
end
|
406
398
|
|
407
|
-
|
408
399
|
### Raise an exception if JSS schema is to old or too new
|
409
400
|
def self.check_schema_version
|
410
401
|
raw = JSS::DB_CNX.db.query("SELECT version FROM #{SCHEMA_TABLE}").fetch[0]
|
@@ -412,8 +403,8 @@ module D3
|
|
412
403
|
current = JSS.parse_jss_version(simmered)[:version]
|
413
404
|
min = JSS.parse_jss_version(MIN_SCHEMA_VERSION)[:version]
|
414
405
|
max = JSS.parse_jss_version(MAX_SCHEMA_VERSION)[:version]
|
415
|
-
raise JSS::InvalidConnectionError, "Invalid JSS database schema version: #{raw}, min: #{MIN_SCHEMA_VERSION}, max: #{MAX_SCHEMA_VERSION}" if current < min
|
416
|
-
|
406
|
+
raise JSS::InvalidConnectionError, "Invalid JSS database schema version: #{raw}, min: #{MIN_SCHEMA_VERSION}, max: #{MAX_SCHEMA_VERSION}" if (current < min) || (current > max)
|
407
|
+
true
|
417
408
|
end
|
418
409
|
|
419
410
|
private
|
@@ -429,8 +420,7 @@ module D3
|
|
429
420
|
###
|
430
421
|
### @return [void]
|
431
422
|
###
|
432
|
-
def self.create_table(display=false)
|
433
|
-
|
423
|
+
def self.create_table(display = false)
|
434
424
|
# as of now, only one table.
|
435
425
|
table_constant = PACKAGE_TABLE
|
436
426
|
|
@@ -438,22 +428,21 @@ module D3
|
|
438
428
|
indexes = ''
|
439
429
|
|
440
430
|
table_constant[:field_definitions].keys.sort.each do |key|
|
441
|
-
|
442
431
|
field = table_constant[:field_definitions][key]
|
443
432
|
|
444
433
|
sql += "\n `#{field[:field_name]}` #{field[:sql_type]},"
|
445
434
|
|
446
435
|
indexes += case field[:index]
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
end #each do key
|
436
|
+
when :primary
|
437
|
+
"\n PRIMARY KEY (`#{field[:field_name]}`),"
|
438
|
+
when :unique
|
439
|
+
"\n UNIQUE KEY (`#{field[:field_name]}`),"
|
440
|
+
when true
|
441
|
+
"\n KEY (`#{field[:field_name]}`),"
|
442
|
+
else
|
443
|
+
''
|
444
|
+
end # indexes += case
|
445
|
+
end # each do key
|
457
446
|
|
458
447
|
sql += indexes
|
459
448
|
|
@@ -461,7 +450,7 @@ module D3
|
|
461
450
|
sql += "\n #{idx},"
|
462
451
|
end
|
463
452
|
|
464
|
-
sql.chomp!
|
453
|
+
sql.chomp! ','
|
465
454
|
sql += "\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"
|
466
455
|
|
467
456
|
if display
|
@@ -471,15 +460,12 @@ module D3
|
|
471
460
|
|
472
461
|
stmt = JSS::DB_CNX.db.prepare sql
|
473
462
|
stmt.execute
|
474
|
-
|
475
463
|
end # create d3 table
|
476
464
|
|
477
|
-
|
478
|
-
|
479
465
|
### @return [Array<String>] A list of all d3-related tables in the database
|
480
466
|
###
|
481
467
|
def self.tables
|
482
|
-
res = JSS::DB_CNX.db.query
|
468
|
+
res = JSS::DB_CNX.db.query 'show tables'
|
483
469
|
d3_tables = []
|
484
470
|
res.each do |t|
|
485
471
|
d3_tables << t[0] if t[0].start_with? 'd3_'
|
@@ -489,4 +475,5 @@ module D3
|
|
489
475
|
end
|
490
476
|
|
491
477
|
end # module Database
|
478
|
+
|
492
479
|
end # module D3
|