JamfReports 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 77a38bd8791ce0cc7a828f3d99301e9bc3c263e2e94ddebd7396da49de534c43
4
+ data.tar.gz: 52e54858b28f7d94695007554123401e26c9ff3dd7fc83de20a06ba350f96adc
5
+ SHA512:
6
+ metadata.gz: 07e344536853fca76d8b07ae166cff9dccae9c5d3acca87045569b9244662d878f34d11cbfbde0ce87e363cc1be21a39ea58f73d7cb59507c92da08498f239e2
7
+ data.tar.gz: 6d1c9e64d051340b8702bd7e5fb1aae7106fda7f02c349929807a7e92e5c681a10b7540f06ecb30a7401ba7c65f7e1e0189ad1bfebd1396a9a3614ef48f16daf
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+
2
+ ## 0.1.1 (2023.06.28)
3
+ - Update: update module syntax
4
+
5
+ ## 0.1.0 (2023.06.28)
6
+ - Initial Build
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in JamfReports.gemspec
6
+ gemspec
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "JamfReports/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "JamfReports"
8
+ spec.version = JamfReports::VERSION
9
+ spec.authors = ["nic scott"]
10
+ spec.email = ["nls.inbox@gmail.com"]
11
+
12
+ spec.summary = %q{A gem that uses the Jamf Pro API to generate reports for hosted Jamf Pro instance}
13
+ spec.homepage = "https://github.com/nlscott/marshmallow"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", ">= 2.2.33"
26
+ spec.add_development_dependency "rake", ">= 11.2.2"
27
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 nic scott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # JamfReports
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/JamfReports`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'JamfReports'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install JamfReports
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/JamfReports.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "JamfReports"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module JamfReports
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,153 @@
1
+ require "JamfReports/version"
2
+ require "uri"
3
+ require "json"
4
+ require "time"
5
+ require "net/http"
6
+ require "openssl"
7
+ require "fileutils"
8
+
9
+ module JamfReports
10
+ class Error < StandardError; end
11
+
12
+ def self.getToken
13
+ #request New token
14
+ url = URI("#{$jamfpro_url}/api//v1/auth/token")
15
+ https = Net::HTTP.new(url.host, url.port)
16
+ https.use_ssl = true
17
+ request = Net::HTTP::Post.new(url)
18
+ request["Content-Type"] = "application/json"
19
+ request["Authorization"] = "Basic #{$api_pw}"
20
+ response = https.request(request)
21
+ results = JSON.parse(response.read_body)
22
+ $bearerToken=results['token']
23
+ $tokenExpiration=results['expires']
24
+ $tokenExpirationEpoch=Time.parse($tokenExpiration).to_i
25
+
26
+ ### SANITY CHECK
27
+ # puts "Token granted"
28
+ # puts "#{$bearerToken}"
29
+ end
30
+
31
+ def self.checkTokenExpiration
32
+ #check if token is valid
33
+
34
+ current_time= Time.now.to_i
35
+ # puts "Checking if Token is valid"
36
+ if $tokenExpirationEpoch >= current_time
37
+ # puts "Epoch time is #{$tokenExpirationEpoch}"
38
+ time_difference = $tokenExpirationEpoch - current_time
39
+ time_till_token_expire = Time.at(time_difference).utc.strftime("%H:%M:%S")
40
+ # puts "Token is valid"
41
+ # puts "Token expires in: " + time_till_token_expire
42
+ else
43
+ # puts "Token is invalid"
44
+ end
45
+ end
46
+
47
+ def self.invalidateToken
48
+ #revoke token
49
+ url = URI("#{$jamfpro_url}/api/v1/auth/invalidate-token")
50
+ https = Net::HTTP.new(url.host, url.port)
51
+ https.use_ssl = true
52
+ request = Net::HTTP::Post.new(url)
53
+ request["Authorization"] = "Bearer #{$bearerToken}"
54
+ response = https.request(request)
55
+ status = response.code
56
+
57
+ ### SANITY CHECK
58
+ # if status == "204"
59
+ # puts "Token successfully invalidated"
60
+ # elsif status == "401"
61
+ # puts "Token already invalid"
62
+ # else
63
+ # puts "error: something went wrong"
64
+ # end
65
+ end
66
+
67
+
68
+
69
+ def self.getAllApplicationInventory
70
+ #this is the main function
71
+ #loops through all computers inventory and only looks at Applications section
72
+ $applicationHash = Hash.new(0)
73
+
74
+ url = URI("#{$jamfpro_url}/api/v1/computers-inventory?section=APPLICATIONS&page=0&page-size=2000&sort=id%3Aasc")
75
+ http = Net::HTTP.new(url.host, url.port)
76
+ http.use_ssl = true
77
+ request = Net::HTTP::Get.new(url)
78
+ request["accept"] = 'application/json'
79
+ request["Authorization"] = "Bearer #{$bearerToken}"
80
+ response = http.request(request)
81
+ results = JSON.parse(response.read_body)
82
+
83
+ results["results"].each do |item|
84
+ item["applications"].each do |item|
85
+ $applicationName = item["name"]
86
+ $applicationHash["#{$applicationName}"] +=1
87
+ end
88
+ end
89
+ end
90
+
91
+
92
+ def self.listAllInstalledApps
93
+ # Prints back report sorty by most installed apps to least
94
+ $applicationHash.sort_by {|_key, value| value}.reverse.each do |k,v|
95
+ puts " #{k} = #{v}"
96
+ end
97
+ end
98
+
99
+
100
+ def self.totalNumberOfOneInstalledApps
101
+ #prints the total number of apps that have been installed once
102
+ @oneOffApps = Hash.new
103
+ $applicationHash.each do |name, count|
104
+ if count == 1
105
+ @oneOffApps["#{name}"] = "#{count}"
106
+ end
107
+ end
108
+
109
+ puts @oneOffApps.count
110
+ end
111
+
112
+
113
+ def self.listofOneInstallApps
114
+ #prints list of all apps by name that have been installed once
115
+ @oneInstalledApps = Hash.new
116
+ $applicationHash.each do |name, count|
117
+ if count == 1
118
+ @oneInstalledApps["#{name}"] = "#{count}"
119
+ end
120
+ end
121
+
122
+ puts @oneInstalledApps.keys
123
+ end
124
+
125
+
126
+ def self.webBrowserReport
127
+ #reports back on how many installs of these browsers there are
128
+ $webBroswerArray = [
129
+ "Google Chrome.app",
130
+ "Google Chrome Canary.app",
131
+ "Firefox.app",
132
+ "Firefox Developer Edition.app",
133
+ "Safari.app",
134
+ "Safari Technology Preview.app",
135
+ "Microsoft Edge.app",
136
+ "Brave Browser.app",
137
+ "Arc.app",
138
+ "Opera.app",
139
+ "LinCastor Browser.app",
140
+ "LockDown Browser.app",
141
+ "Tor Browser.app",
142
+ "Vivaldi.app",
143
+ "DuckDuckGo.app"
144
+ ]
145
+
146
+ $applicationHash.sort_by {|_key, value| value}.reverse.each do |k,v|
147
+ if $webBroswerArray.include?("#{k}")
148
+ puts "#{k} = #{v}"
149
+ end
150
+ end
151
+ end
152
+
153
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: JamfReports
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - nic scott
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.33
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.33
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 11.2.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 11.2.2
41
+ description:
42
+ email:
43
+ - nls.inbox@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - Gemfile
50
+ - JamfReports.gemspec
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/JamfReports.rb
57
+ - lib/JamfReports/version.rb
58
+ homepage: https://github.com/nlscott/marshmallow
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.0.3.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A gem that uses the Jamf Pro API to generate reports for hosted Jamf Pro
81
+ instance
82
+ test_files: []