panes 0.1.2 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c27a4bafb78b8558831d8c2ac57112893220b7c
4
- data.tar.gz: 1b486182db4cd059de77597adeecf97b6b67cc8d
3
+ metadata.gz: 39df5d4ea25cbb2cfef47185adae2a0f2a69c62c
4
+ data.tar.gz: 9484c89050a4fcc4e284bb66f19fbe3a705ac0de
5
5
  SHA512:
6
- metadata.gz: 8378d0dca7f5dfce37bf6e79a668df7662644e10f97f1db9d86e3dcf199b98297ea8b145819188f65e972cfe9729d1b6c81c254190b25b8f7a5595c7d5a2d92a
7
- data.tar.gz: e8128bbcc4cc5b49a4af072b217bc856ff959249277a25bcc4aeb8ec4d9ecf60b1674f8c7d1b74818212e944cc349176eb5d11f4a60186f05dea2839f2f296e7
6
+ metadata.gz: 6431c4e758da1ff5cce4f1fe864eedd251f9c6f6776dc3254c1928db3349982ca6b418e4351ca43099d3d8563d2371fa6e465758d05486854f784a35ec8373ad
7
+ data.tar.gz: 2a878aecc8e62b9e3d240d25b93b6d886ebe45d2103f752d3d1369aeb4cec859e4924c6a0290b88045430bb2293a6d78777cde17eb1828a2babb9d410cc11dbc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in panes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 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,149 @@
1
+ # A ruby gem to disable or enable system preference panes for macOS
2
+
3
+ Version .0.2.0 was tested on macOS 10.14. It may or may not work on other OS versions.
4
+
5
+ Version .0.1.2 was tested on macOS 10.12. It may or may not work on other OS versions.
6
+
7
+ For more usage see this
8
+ [blog post](https://redlinetech.wordpress.com/2017/06/21/disable-system-preference-panes-in-macos/)
9
+
10
+ <img src="https://redlinetech.files.wordpress.com/2017/06/disabled.png?w=625">
11
+ ##### To install:
12
+ ```bash
13
+ sudo gem install panes
14
+ ```
15
+
16
+ ##### To verify:
17
+ ```bash
18
+ gem list
19
+ ```
20
+
21
+ ---
22
+ ## Usage:
23
+
24
+ Panes requires **sudo** access to read and write to the main plist file. You can run commands in two ways. From a ruby interactive shell, or running a ruby script directly from the command line.
25
+
26
+ ##### Example 1: IRB
27
+
28
+ ```ruby
29
+ sudo irb
30
+ require 'panes'
31
+ Panes.Disable("com.apple.preference.network")
32
+ ```
33
+
34
+
35
+
36
+ ##### Eaxmple 2: Run a ruby script from terminal
37
+
38
+ Put your commands in a ruby file and run it via the terminal. Example, create a file named "test-command.rb"
39
+
40
+ test-command.rb:
41
+
42
+ ```ruby
43
+ #!//usr/bin/ruby
44
+
45
+ require 'panes'
46
+ Panes.Disable("com.apple.preference.network")
47
+ ```
48
+ Run the command from terminal:
49
+ ```bash
50
+ sudo ruby test-command.rb
51
+ ```
52
+
53
+
54
+
55
+ You must require 'panes' in your ruby file. Then you can run the command below to see all your options.
56
+
57
+ ```ruby
58
+ Panes.Options
59
+ ```
60
+ This will return:
61
+ > - CFBundleIdentifier
62
+ > - CreateProfile
63
+ > - Disable
64
+ > - Enable
65
+ > - List
66
+ > - OptionalCFBundleIdentifier
67
+ > - Options
68
+ > - Reset
69
+
70
+ ---
71
+
72
+ # Examples ...
73
+
74
+ #### List CFBundleIdentifiers:
75
+
76
+ ```ruby
77
+ puts Panes.CFBundleIdentifier
78
+ ```
79
+ CFBundleIdentifier is a string usually in reverse DNS format, that specifies the specific app type of the bundle. Used in macOS to specify Applications.
80
+
81
+ ---
82
+ #### Create a new "com.apple.systempreferences.plist":
83
+ ```ruby
84
+ Panes.CreateProfile
85
+ ```
86
+ If the file "/Library/Preferences/com.apple.systempreferences.plist" doesn't exist, it will be created.
87
+
88
+ There's no real reason to run this independently, it's used internally when the file isn't found.
89
+
90
+ ---
91
+ #### Disable a Preference Pane:
92
+
93
+ The heart of this gem is the Disable method. It takes a specific CFBundleIdentifier or multiple CFBundleIdentifiers.
94
+
95
+ ##### examples:
96
+ ```ruby
97
+ #to disable one Pane
98
+ Panes.Disable("com.apple.preference.network")
99
+ ```
100
+ ```ruby
101
+ #to disable multiple Panes, use comma separated list
102
+ Panes.Disable(
103
+ "com.apple.preference.network",
104
+ "com.apple.preferences.Bluetooth")
105
+ ```
106
+
107
+ ---
108
+ #### Enable a Preference Pane:
109
+ ```ruby
110
+ Panes.Enable("com.apple.preference.network")
111
+ ```
112
+ If you decide to enable a pane after it's been disable.
113
+
114
+ ---
115
+ #### List all Preference Panes:
116
+ ```ruby
117
+ Panes.List
118
+ ```
119
+ you'll get a list of available preference panes:
120
+ > - Accounts.prefPane
121
+ > - Appearance.prefPane
122
+ > - AppStore.prefPane
123
+ > - Bluetooth.prefPane
124
+ > - and so forth ....
125
+
126
+ ---
127
+ #### List Optional Preference Panes:
128
+ ```ruby
129
+ puts Panes.OptionalCFBundleIdentifier
130
+ ```
131
+ These are usually Panes that have been installed by a user like Adobe Flash or Oracle Java
132
+
133
+ ##### example:
134
+ > - com.adobe.flashplayerpreferences
135
+ > - com.oracle.java.JavaControlPanel
136
+
137
+ ---
138
+ #### List options:
139
+ ```ruby
140
+ Panes.Options
141
+ ```
142
+ Prints available methods
143
+
144
+ ---
145
+ #### Reset all changes:
146
+ ```ruby
147
+ Panes.Reset
148
+ ```
149
+ This enables all panes and deletes the "/Library/Preferences/com.apple.systempreferences.plist" file
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "panes"
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
data/lib/panes.rb ADDED
@@ -0,0 +1,171 @@
1
+
2
+
3
+ require 'CFPropertyList'
4
+ require 'FileUtils'
5
+
6
+ module Panes
7
+ #======================================================================
8
+ # Variables
9
+
10
+ PATHTOPLIST="/System/Library/PreferencePanes"
11
+ PreferencePanes=Dir.entries("#{PATHTOPLIST}")
12
+
13
+ # Print .prePanes in /System/Library/PreferencePanes folder
14
+ def self.List
15
+ list_of_panes=[]
16
+ PreferencePanes.each do |prePane|
17
+ if !prePane.start_with?(".")
18
+ list_of_panes << prePane
19
+ end
20
+ end
21
+ puts list_of_panes
22
+ end
23
+
24
+ #print CFBundleIdentifier for each item in /System/Library/PreferencePanes folder
25
+ def self.CFBundleIdentifier
26
+ list_of_panes=[]
27
+ PreferencePanes.each do |prePane|
28
+ if !prePane.start_with?(".")
29
+ list_of_panes << prePane
30
+ end
31
+ end
32
+
33
+ final_list=[]
34
+ list_of_panes.each do |prePane|
35
+ plist = CFPropertyList::List.new(:file => "#{PATHTOPLIST}/#{prePane}/Contents/Info.plist")
36
+ results=CFPropertyList.native_types(plist.value)
37
+ final_list << results["CFBundleIdentifier"]
38
+ end
39
+ return final_list
40
+ end
41
+
42
+ #print CFBundleIdentifier for items installed by the user, typical installs would be flash or java
43
+ def self.OptionalCFBundleIdentifier
44
+ optionalpanes=Dir.entries("/Library/PreferencePanes")
45
+
46
+ list_of_panes=[]
47
+ optionalpanes.each do |prePane|
48
+ if !prePane.start_with?(".")
49
+ list_of_panes << prePane
50
+ end
51
+ end
52
+
53
+ final_list=[]
54
+ list_of_panes.each do |prePane|
55
+ plist = CFPropertyList::List.new(:file => "/Library/PreferencePanes/#{prePane}/Contents/Info.plist")
56
+ results=CFPropertyList.native_types(plist.value)
57
+ final_list << results["CFBundleIdentifier"]
58
+ end
59
+ return final_list
60
+ end
61
+
62
+
63
+ #creates an empty com.apple.systempreferences in tmp folder
64
+ def self.CreateProfile
65
+ profile = "/Library/preferences/com.apple.systempreferences.plist"
66
+ new_profile = File.open(profile, "w")
67
+ new_profile.puts '<?xml version="1.0" encoding="UTF-8"?>
68
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
69
+ <plist version="1.0">
70
+ <dict>
71
+ <key>DisabledPreferencePanes</key>
72
+ <array>
73
+ </array>
74
+ </dict>
75
+ </plist>
76
+ '
77
+ new_profile.close
78
+ FileUtils.chmod(0644,"#{profile}")
79
+ FileUtils.chown 'root', 'wheel', "#{profile}"
80
+ end
81
+
82
+ #to restrict access to a preference pane, put the CFBundleIdentifier as the argument
83
+ # example is Panes.Disable("com.apple.preference.network")
84
+ def self.Disable(*prefs)
85
+
86
+ if File.file?("/Library/preferences/com.apple.systempreferences.plist")
87
+ preference_panes_to_disable =[]
88
+
89
+ prefs.each do |x|
90
+ preference_panes_to_disable << x
91
+ end
92
+
93
+ plist = CFPropertyList::List.new(:file => "/Library/preferences/com.apple.systempreferences.plist")
94
+ results=CFPropertyList.native_types(plist.value)
95
+
96
+ results["DisabledPreferencePanes"].each do |x|
97
+ preference_panes_to_disable << x
98
+ end
99
+
100
+ preference_panes_to_disable.each do |x|
101
+ indexnumber = preference_panes_to_disable.index(x)
102
+ results["DisabledPreferencePanes"][indexnumber] = "#{x}"
103
+ end
104
+
105
+ plist.value = CFPropertyList.guess(results)
106
+ plist.save("/Library/preferences/com.apple.systempreferences.plist", CFPropertyList::List::FORMAT_BINARY)
107
+ else
108
+ Panes.CreateProfile
109
+ preference_panes_to_disable =[]
110
+
111
+ prefs.each do |x|
112
+ preference_panes_to_disable << x
113
+ end
114
+
115
+ plist = CFPropertyList::List.new(:file => "/Library/preferences/com.apple.systempreferences.plist")
116
+ results=CFPropertyList.native_types(plist.value)
117
+
118
+ results["DisabledPreferencePanes"].each do |x|
119
+ preference_panes_to_disable << x
120
+ end
121
+
122
+ preference_panes_to_disable.each do |x|
123
+ indexnumber = preference_panes_to_disable.index(x)
124
+ results["DisabledPreferencePanes"][indexnumber] = "#{x}"
125
+ end
126
+
127
+ plist.value = CFPropertyList.guess(results)
128
+ plist.save("/Library/preferences/com.apple.systempreferences.plist", CFPropertyList::List::FORMAT_BINARY)
129
+
130
+ end
131
+ command="sudo killall cfprefsd"
132
+ system(command)
133
+ end
134
+
135
+ #to remove a restriction, put the CFBundleIdentifier as the argument
136
+ def self.Enable(*prefs)
137
+ if File.file?("/Library/preferences/com.apple.systempreferences.plist")
138
+ plist = CFPropertyList::List.new(:file => "/Library/preferences/com.apple.systempreferences.plist")
139
+ results=CFPropertyList.native_types(plist.value)
140
+ prefs.each do |check_a|
141
+ results["DisabledPreferencePanes"].each do |check_b|
142
+ if check_a == check_b
143
+ results["DisabledPreferencePanes"].delete(check_a)
144
+ end
145
+ end
146
+ end
147
+ plist.value = CFPropertyList.guess(results)
148
+ plist.save("/Library/preferences/com.apple.systempreferences.plist", CFPropertyList::List::FORMAT_BINARY)
149
+ command="sudo killall cfprefsd"
150
+ system(command)
151
+ else
152
+ puts "Error: no plist. Try running 'sudo killall cfprefsd' from the terminal"
153
+ end
154
+ end
155
+
156
+
157
+ #reset all disable panes
158
+ def self.Reset
159
+ command="sudo rm -rf /Library/Preferences/com.apple.systempreferences.plist"
160
+ system(command)
161
+ cfprefsd="sudo killall cfprefsd"
162
+ system(cfprefsd)
163
+ end
164
+
165
+ #to print all the availbe options to use with the Panes command
166
+ def self.Options
167
+ puts (Panes.methods - Object.methods).sort
168
+ end
169
+ end
170
+ Panes.Disable("com.apple.preference.network")
171
+
@@ -0,0 +1,3 @@
1
+ module Panes
2
+ VERSION = "0.2.0"
3
+ end
data/panes-0.1.2.gem ADDED
Binary file
data/panes.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "panes/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "panes"
8
+ spec.version = Panes::VERSION
9
+ spec.authors = ["Nic Scott"]
10
+ spec.email = ["nls.inbox@gmail.com"]
11
+
12
+ spec.summary = "A ruby gem for MacAdmins to help manage access to System Preference Panes. Easily enable or disable access to individual panes."
13
+ spec.homepage = "https://github.com/nlscott/panes"
14
+ spec.license = "MIT"
15
+
16
+ =begin
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+ =end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.15"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "minitest", "~> 5.0"
37
+ spec.add_development_dependency "CFPropertyList", "~> 2.0"
38
+
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nic Scott
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-16 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,7 +72,19 @@ email:
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
- files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/panes.rb
85
+ - lib/panes/version.rb
86
+ - panes-0.1.2.gem
87
+ - panes.gemspec
76
88
  homepage: https://github.com/nlscott/panes
77
89
  licenses:
78
90
  - MIT
@@ -93,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
105
  version: '0'
94
106
  requirements: []
95
107
  rubyforge_project:
96
- rubygems_version: 2.5.1
108
+ rubygems_version: 2.5.2.3
97
109
  signing_key:
98
110
  specification_version: 4
99
111
  summary: A ruby gem for MacAdmins to help manage access to System Preference Panes.