xolo-server 1.0.1 → 2.0.2

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/data/client/xolo +152 -79
  3. data/lib/xolo/core/base_classes/title.rb +254 -18
  4. data/lib/xolo/core/base_classes/version.rb +47 -7
  5. data/lib/xolo/core/constants.rb +7 -3
  6. data/lib/xolo/core/security_cmd.rb +128 -0
  7. data/lib/xolo/core/version.rb +1 -1
  8. data/lib/xolo/core.rb +1 -0
  9. data/lib/xolo/server/app.rb +7 -0
  10. data/lib/xolo/server/configuration.rb +243 -37
  11. data/lib/xolo/server/constants.rb +10 -0
  12. data/lib/xolo/server/helpers/auth.rb +19 -2
  13. data/lib/xolo/server/helpers/autopkg.rb +157 -0
  14. data/lib/xolo/server/helpers/client_data.rb +90 -60
  15. data/lib/xolo/server/helpers/file_transfers.rb +412 -82
  16. data/lib/xolo/server/helpers/jamf_pro.rb +30 -7
  17. data/lib/xolo/server/helpers/log.rb +2 -0
  18. data/lib/xolo/server/helpers/maintenance.rb +1 -0
  19. data/lib/xolo/server/helpers/notification.rb +4 -3
  20. data/lib/xolo/server/helpers/pkg_signing.rb +16 -12
  21. data/lib/xolo/server/helpers/progress_streaming.rb +9 -12
  22. data/lib/xolo/server/helpers/subscriptions.rb +119 -0
  23. data/lib/xolo/server/helpers/titles.rb +27 -3
  24. data/lib/xolo/server/helpers/versions.rb +23 -11
  25. data/lib/xolo/server/mixins/changelog.rb +9 -16
  26. data/lib/xolo/server/mixins/title_jamf_access.rb +375 -385
  27. data/lib/xolo/server/mixins/title_ted_access.rb +29 -3
  28. data/lib/xolo/server/mixins/version_jamf_access.rb +95 -112
  29. data/lib/xolo/server/mixins/version_ted_access.rb +25 -0
  30. data/lib/xolo/server/object_locks.rb +2 -1
  31. data/lib/xolo/server/routes/auth.rb +2 -2
  32. data/lib/xolo/server/routes/jamf_pro.rb +11 -1
  33. data/lib/xolo/server/routes/maint.rb +2 -1
  34. data/lib/xolo/server/routes/subscriptions.rb +126 -0
  35. data/lib/xolo/server/routes/title_editor.rb +1 -1
  36. data/lib/xolo/server/routes/titles.rb +26 -11
  37. data/lib/xolo/server/routes/uploads.rb +0 -14
  38. data/lib/xolo/server/routes/versions.rb +14 -13
  39. data/lib/xolo/server/routes.rb +9 -0
  40. data/lib/xolo/server/title.rb +100 -77
  41. data/lib/xolo/server/version.rb +177 -15
  42. data/lib/xolo/server.rb +8 -0
  43. metadata +7 -9
@@ -0,0 +1,128 @@
1
+ # Copyright 2025 Pixar
2
+ #
3
+ # Licensed under the terms set forth in the LICENSE.txt file available at
4
+ # at the root of this project.
5
+ #
6
+ #
7
+
8
+ # frozen_string_literal: true
9
+
10
+ # main module
11
+ module Xolo
12
+
13
+ module Core
14
+
15
+ # Personal credentials for users of 'xadm', stored in the login keychain
16
+ #
17
+ module SecurityCmd
18
+
19
+ # Constants
20
+ ##############################
21
+ ##############################
22
+
23
+ # The security command
24
+ SEC_COMMAND = '/usr/bin/security'
25
+
26
+ # exit status when the login keychain can't be accessed because we aren't in a GUI session
27
+ SEC_STATUS_NO_GUI_ERROR = 36
28
+
29
+ # exit status when the keychain password provided is incorrect
30
+ SEC_STATUS_AUTH_ERROR = 51
31
+
32
+ # exit status when the desired item isn't found in the keychain
33
+ SEC_STATUS_NOT_FOUND_ERROR = 44
34
+
35
+ # Module methods
36
+ ##############################
37
+ ##############################
38
+
39
+ # when this module is included
40
+ def self.included(includer)
41
+ Xolo.verbose_include includer, self
42
+ end
43
+
44
+ # Instance Methods
45
+ ##########################
46
+ ##########################
47
+
48
+ # Run the security command in interactive mode on a given keychain,
49
+ # passing in a subcommand and its arguments. so that they don't appear in the
50
+ # `ps` output
51
+ #
52
+ # @param cmd [String] the subcommand being passed to 'security' with
53
+ # all needed options. It will not be visible outide this process, so
54
+ # its OK to put passwords into the options.
55
+ #
56
+ # @return [String] the stdout of the 'security' command.
57
+ #
58
+ ######
59
+ def run_security(cmd)
60
+ output = Xolo::BLANK
61
+ errs = Xolo::BLANK
62
+
63
+ Open3.popen3("#{SEC_COMMAND} -i") do |stdin, stdout, stderr, wait_thr|
64
+ # pid = wait_thr.pid # pid of the started process.
65
+ stdin.puts cmd
66
+ stdin.close
67
+
68
+ output = stdout.read
69
+ errs = stderr.read
70
+
71
+ @security_exit_status = wait_thr.value # Process::Status object returned.
72
+ end
73
+
74
+ # exit 44 is 'The specified item could not be found in the keychain'
75
+ return output.chomp if @security_exit_status.success?
76
+
77
+ case @security_exit_status.exitstatus
78
+ when SEC_STATUS_AUTH_ERROR
79
+ raise Xolo::KeychainError, 'Problem accessing login keychain. Is it locked?'
80
+
81
+ when SEC_STATUS_NOT_FOUND_ERROR
82
+ raise Xolo::NoSuchItemError, "No xolo admin password. Please run 'xadm config'"
83
+
84
+ else
85
+ errs.chomp!
86
+ errs =~ /: returned\s+(-?\d+)$/
87
+ errnum = Regexp.last_match(1)
88
+ desc = errnum ? security_error_desc(errnum) : errs
89
+ desc ||= errs
90
+ raise Xolo::KeychainError, "#{desc.gsub("\n", '; ')}; exit status #{@security_exit_status.exitstatus}"
91
+ end # case
92
+ end # run_security
93
+
94
+ # use `security error` to get a description of an error number
95
+ ##############
96
+ def security_error_desc(num)
97
+ desc = `#{SEC_COMMAND} error #{num}`
98
+ return if desc.include?('unknown error')
99
+
100
+ desc.chomp.split(num).last
101
+ rescue
102
+ nil
103
+ end
104
+
105
+ # given a string, wrap it in single quotes and escape internal single quotes
106
+ # and backslashes so it can be used in the interactive 'security' command
107
+ #
108
+ # @param str[String] the string to escape
109
+ #
110
+ # @return [String] the escaped string
111
+ ###################
112
+ def security_escape(str)
113
+ # first escape backslashes
114
+ str = str.to_s.gsub '\\', '\\\\\\'
115
+
116
+ # then single quotes
117
+ str.gsub! "'", "\\\\'"
118
+
119
+ # if other things need escaping, add them here
120
+
121
+ "'#{str}'"
122
+ end # security_escape
123
+
124
+ end # module Prefs
125
+
126
+ end # module Admin
127
+
128
+ end # module Xolo
@@ -12,7 +12,7 @@ module Xolo
12
12
 
13
13
  module Version
14
14
 
15
- VERSION = '1.0.1'.freeze
15
+ VERSION = '2.0.2'.freeze
16
16
 
17
17
  end
18
18
 
data/lib/xolo/core.rb CHANGED
@@ -39,6 +39,7 @@ module Xolo
39
39
  end # module Xolo
40
40
 
41
41
  require 'xolo/core/json_wrappers'
42
+ require 'xolo/core/security_cmd'
42
43
  require 'xolo/core/base_classes/configuration'
43
44
  require 'xolo/core/base_classes/server_object'
44
45
  require 'xolo/core/base_classes/title'
@@ -19,6 +19,7 @@ module Xolo
19
19
  ##############################
20
20
  ##############################
21
21
 
22
+ # register Sinatra extensions - this 'extends' the app class with the extension's methods
22
23
  register Xolo::Server::Routes
23
24
  register Xolo::Server::Routes::Auth
24
25
  register Xolo::Server::Routes::Maint
@@ -27,9 +28,13 @@ module Xolo
27
28
  register Xolo::Server::Routes::Titles
28
29
  register Xolo::Server::Routes::Versions
29
30
  register Xolo::Server::Routes::Uploads
31
+ register Xolo::Server::Routes::Subscriptions
30
32
 
33
+ # include helper modules - this 'includes' the app class with the helper module's methods
34
+ # making them available as instance methods in routes and views
31
35
  helpers Xolo::Core::Constants
32
36
  helpers Xolo::Core::JSONWrappers
37
+ helpers Xolo::Core::SecurityCmd
33
38
  helpers Xolo::Server::Helpers::Log
34
39
  helpers Xolo::Server::Helpers::Notification
35
40
  helpers Xolo::Server::Helpers::Auth
@@ -41,7 +46,9 @@ module Xolo
41
46
  helpers Xolo::Server::Helpers::PkgSigning
42
47
  helpers Xolo::Server::Helpers::ProgressStreaming
43
48
  helpers Xolo::Server::Helpers::ClientData
49
+ helpers Xolo::Server::Helpers::Subscriptions
44
50
  helpers Xolo::Server::Helpers::Maintenance
51
+ helpers Xolo::Server::Helpers::AutoPkg
45
52
 
46
53
  # Sinatra setup
47
54
  ##############################