mdm 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +37 -0
- data/app/controllers/mdm/application_controller.rb +4 -0
- data/app/controllers/mdm/commands_controller.rb +60 -0
- data/app/controllers/mdm/enrollment/enrollment_controller.rb +47 -0
- data/app/controllers/mdm/management/accounts_controller.rb +15 -0
- data/app/controllers/mdm/management/devices_controller.rb +35 -0
- data/app/controllers/mdm/management/profiles_controller.rb +35 -0
- data/app/controllers/mdm/management/services_controller.rb +13 -0
- data/app/controllers/mdm/server_controller.rb +44 -0
- data/app/helpers/mdm/application_helper.rb +4 -0
- data/app/models/mdm/command.rb +23 -0
- data/app/models/mdm/cursor.rb +11 -0
- data/app/models/mdm/device.rb +39 -0
- data/app/models/mdm/payload.rb +158 -0
- data/app/models/mdm/profile.rb +14 -0
- data/app/views/layouts/mdm/application.html.erb +14 -0
- data/config/routes.rb +18 -0
- data/db/migrate/20150816150227_create_mdm_commands.rb +12 -0
- data/db/migrate/20150816150732_create_mdm_devices.rb +34 -0
- data/db/migrate/20150823153933_create_mdm_cursors.rb +10 -0
- data/db/migrate/20150827082737_create_mdm_profiles.rb +24 -0
- data/lib/mdm.rb +21 -0
- data/lib/mdm/configuration.rb +14 -0
- data/lib/mdm/engine.rb +5 -0
- data/lib/mdm/enrollment/client.rb +47 -0
- data/lib/mdm/enrollment/service/account.rb +32 -0
- data/lib/mdm/enrollment/service/assign_profile.rb +35 -0
- data/lib/mdm/enrollment/service/auth.rb +100 -0
- data/lib/mdm/enrollment/service/base.rb +67 -0
- data/lib/mdm/enrollment/service/create_profile.rb +69 -0
- data/lib/mdm/enrollment/service/devices.rb +92 -0
- data/lib/mdm/enrollment/service/profile.rb +62 -0
- data/lib/mdm/enrollment/service/sync.rb +43 -0
- data/lib/mdm/railtie.rb +22 -0
- data/lib/mdm/version.rb +3 -0
- data/lib/tasks/mdm_tasks.rake +4 -0
- data/test/controllers/mdm/commands_controller_test.rb +13 -0
- data/test/controllers/mdm/enrollment/accounts_controller_test.rb +13 -0
- data/test/controllers/mdm/enrollment/devices_controller_test.rb +13 -0
- data/test/controllers/mdm/enrollment/enrollment_controller_test.rb +13 -0
- data/test/controllers/mdm/enrollment/profiles_controller_test.rb +13 -0
- data/test/controllers/mdm/services_controller_test.rb +13 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/mdm/commands.yml +11 -0
- data/test/fixtures/mdm/cursors.yml +9 -0
- data/test/fixtures/mdm/devices.yml +25 -0
- data/test/fixtures/mdm/profiles.yml +35 -0
- data/test/integration/navigation_test.rb +9 -0
- data/test/mdm_test.rb +7 -0
- data/test/models/mdm/command_test.rb +9 -0
- data/test/models/mdm/cursor_test.rb +9 -0
- data/test/models/mdm/device_test.rb +9 -0
- data/test/models/mdm/profile_test.rb +9 -0
- data/test/test_helper.rb +20 -0
- metadata +254 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module Mdm
|
|
2
|
+
|
|
3
|
+
module Enrollment
|
|
4
|
+
|
|
5
|
+
class CreateProfile < Service::Base
|
|
6
|
+
|
|
7
|
+
attr_accessor :devices
|
|
8
|
+
|
|
9
|
+
attr_reader :profile
|
|
10
|
+
|
|
11
|
+
def self.accepted_params
|
|
12
|
+
[
|
|
13
|
+
:devices,
|
|
14
|
+
:profile_name,
|
|
15
|
+
:org_magic,
|
|
16
|
+
:url,
|
|
17
|
+
:allow_pairing,
|
|
18
|
+
:is_supervised,
|
|
19
|
+
:is_mandatory,
|
|
20
|
+
:await_device_configured,
|
|
21
|
+
:is_mdm_removable,
|
|
22
|
+
:support_phone_number,
|
|
23
|
+
:support_email_address,
|
|
24
|
+
:anchor_certs,
|
|
25
|
+
:supervising_host_certs,
|
|
26
|
+
:skip_setup_items,
|
|
27
|
+
:department
|
|
28
|
+
]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
super
|
|
33
|
+
@devices = []
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def start
|
|
37
|
+
params[:devices] = devices.map(&:serial_number)
|
|
38
|
+
# TODO: A string that uniquely identifies various services that are managed by a single organization.
|
|
39
|
+
# wtf, so what do we use?
|
|
40
|
+
params[:org_magic] = SecureRandom.uuid
|
|
41
|
+
|
|
42
|
+
super
|
|
43
|
+
|
|
44
|
+
@profile = Profile.new(params)
|
|
45
|
+
@profile.profile_uuid = client.response['profile_uuid']
|
|
46
|
+
@profile.save!
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def path
|
|
50
|
+
'/profile'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def method
|
|
54
|
+
:post
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def result
|
|
58
|
+
if @profile.persisted?
|
|
59
|
+
{ profile: @profile.to_json }
|
|
60
|
+
else
|
|
61
|
+
{ errors: @profile.errors }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module Mdm
|
|
2
|
+
|
|
3
|
+
module Enrollment
|
|
4
|
+
|
|
5
|
+
class Devices < Service::Base
|
|
6
|
+
|
|
7
|
+
attr_accessor :limit
|
|
8
|
+
|
|
9
|
+
attr_reader :devices,
|
|
10
|
+
:cursor
|
|
11
|
+
|
|
12
|
+
def self.accepted_params
|
|
13
|
+
[:limit, :cursor]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def path
|
|
17
|
+
'/server/devices'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def start
|
|
21
|
+
params[:limit] = limit
|
|
22
|
+
params[:cursor] = cursor.content
|
|
23
|
+
|
|
24
|
+
super
|
|
25
|
+
|
|
26
|
+
cursor.content, device_payloads, more_to_follow = client.extract_from_response(
|
|
27
|
+
'cursor',
|
|
28
|
+
'devices',
|
|
29
|
+
'more_to_follow')
|
|
30
|
+
|
|
31
|
+
create_or_update_devices(device_payloads)
|
|
32
|
+
|
|
33
|
+
if cursor.save && more_to_follow
|
|
34
|
+
start
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def method
|
|
39
|
+
:post
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def result
|
|
43
|
+
{
|
|
44
|
+
devices: devices,
|
|
45
|
+
cursor: cursor
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
attr_accessor :devices
|
|
52
|
+
|
|
53
|
+
def limit
|
|
54
|
+
@limit ||= 1000
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def devices
|
|
58
|
+
@devices ||= []
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def cursor
|
|
62
|
+
@cursor ||= Cursor.find_or_create_by(
|
|
63
|
+
service: Cursor::DEVICES)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def create_or_update_devices(device_payloads)
|
|
67
|
+
devices.concat device_payloads.map { |device_payload|
|
|
68
|
+
create_or_update_device(device_payload) }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def create_or_update_device(device_payload)
|
|
72
|
+
Device.find_or_create_by(serial_number: device_payload['serial_number']) do |device|
|
|
73
|
+
device.model = device_payload['model']
|
|
74
|
+
device.description = device_payload['description']
|
|
75
|
+
device.color = device_payload['color']
|
|
76
|
+
device.asset_tag = device_payload['asset_tag']
|
|
77
|
+
device.profile_status = device_payload['profile_status']
|
|
78
|
+
device.profile_uuid = device_payload['profile_uuid']
|
|
79
|
+
device.profile_assign_time = device_payload['profile_assign_time']
|
|
80
|
+
device.profile_push_time = device_payload['profile_push_time']
|
|
81
|
+
device.op_type = device_payload['op_type']
|
|
82
|
+
device.op_date = device_payload['op_date']
|
|
83
|
+
device.device_assigned_by = device_payload['device_assigned_by']
|
|
84
|
+
device.device_assigned_date = device_payload['device_assigned_date']
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Mdm
|
|
2
|
+
|
|
3
|
+
module Enrollment
|
|
4
|
+
|
|
5
|
+
class Profile < Service::Base
|
|
6
|
+
|
|
7
|
+
def start
|
|
8
|
+
super
|
|
9
|
+
find_or_create_profile
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def path
|
|
13
|
+
'/profile'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def method
|
|
17
|
+
:get
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def result
|
|
21
|
+
{
|
|
22
|
+
profile: @profile.to_json
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def find_or_create_profile
|
|
29
|
+
@profile ||= begin
|
|
30
|
+
profile = Profile.find_or_create_by(
|
|
31
|
+
profile_uuid: client.response['profile_uuid']
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
profile.update!(
|
|
35
|
+
profile_uuid: client.response['profile_uuid'],
|
|
36
|
+
profile_name: client.response['profile_name'],
|
|
37
|
+
url: client.response['url'],
|
|
38
|
+
is_supervised: client.response['is_supervised'],
|
|
39
|
+
allow_pairing: client.response['allow_pairing'],
|
|
40
|
+
is_mandatory: client.response['is_mandatory'],
|
|
41
|
+
await_device_configured: client.response['await_device_configured'],
|
|
42
|
+
is_mdm_removable: client.response['is_mdm_removable'],
|
|
43
|
+
department: client.response['department'],
|
|
44
|
+
org_magic: client.response['org_magic'],
|
|
45
|
+
support_phone_number: client.response['support_phone_number'],
|
|
46
|
+
support_email_address: client.response['support_email_address'],
|
|
47
|
+
anchor_certs: client.response['anchor_certs'],
|
|
48
|
+
supervising_host_certs: client.response['supervising_host_certs'],
|
|
49
|
+
skip_setup_items: client.response['skip_setup_items'],
|
|
50
|
+
devices: client.response['devices']
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
profile
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Mdm
|
|
2
|
+
|
|
3
|
+
module Enrollment
|
|
4
|
+
|
|
5
|
+
class Sync < Devices
|
|
6
|
+
|
|
7
|
+
class DevicesCursorNotFound < StandardError
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def path
|
|
11
|
+
'/devices/sync'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def cursor
|
|
15
|
+
@cursor ||=
|
|
16
|
+
begin
|
|
17
|
+
cursor = Mdm::Cursor.where(
|
|
18
|
+
service: Mdm::Cursor::SYNC
|
|
19
|
+
).first || begin
|
|
20
|
+
# Create sync cursor based on Device service cursor
|
|
21
|
+
device_cursor = Cursor.where(
|
|
22
|
+
service: Cursor::DEVICES).first
|
|
23
|
+
|
|
24
|
+
# Raise if no device service cursor found
|
|
25
|
+
# Device service must be called first
|
|
26
|
+
if device_cursor.nil?
|
|
27
|
+
raise DevicesCursorNotFound
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Use device service cursor to create sync service cursor
|
|
31
|
+
Cursor.create(
|
|
32
|
+
service: Cursor::SYNC,
|
|
33
|
+
content: device_cursor.content)
|
|
34
|
+
end
|
|
35
|
+
cursor
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
data/lib/mdm/railtie.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Mdm
|
|
2
|
+
class Railtie < Rails::Railtie
|
|
3
|
+
initializer 'mdm.mime_types' do
|
|
4
|
+
Mime::Type.register 'application/plist', :plist, [
|
|
5
|
+
'application/x-apple-aspen-mdm-checkin',
|
|
6
|
+
'application/x-apple-aspen-mdm'
|
|
7
|
+
]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
initializer 'mdm.plist_parser' do
|
|
11
|
+
require 'plist'
|
|
12
|
+
|
|
13
|
+
Rails.application.config.middleware.delete ActionDispatch::ParamsParser
|
|
14
|
+
Rails.application.config.middleware.use(
|
|
15
|
+
ActionDispatch::ParamsParser, {
|
|
16
|
+
Mime::PLIST => lambda do |body|
|
|
17
|
+
Plist.parse_xml(body)
|
|
18
|
+
end
|
|
19
|
+
})
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/mdm/version.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
== README
|
|
2
|
+
|
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
|
4
|
+
application up and running.
|
|
5
|
+
|
|
6
|
+
Things you may want to cover:
|
|
7
|
+
|
|
8
|
+
* Ruby version
|
|
9
|
+
|
|
10
|
+
* System dependencies
|
|
11
|
+
|
|
12
|
+
* Configuration
|
|
13
|
+
|
|
14
|
+
* Database creation
|
|
15
|
+
|
|
16
|
+
* Database initialization
|
|
17
|
+
|
|
18
|
+
* How to run the test suite
|
|
19
|
+
|
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
|
21
|
+
|
|
22
|
+
* Deployment instructions
|
|
23
|
+
|
|
24
|
+
* ...
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|