Module: Macos::Artifacts::Files

Defined in:
lib/macos/artifacts/files.rb

Class Method Summary collapse

Class Method Details

.cronTabsObject



166
167
168
169
170
171
172
173
174
# File 'lib/macos/artifacts/files.rb', line 166

def self.cronTabs
  cronTab = `/usr/bin/crontab -l`.strip
  puts "crontabs:"
  if cronTab.empty?
    puts "  No current crontabs"
  else
    puts "  #{cronTab}"
  end
end

.etcHostsObject



176
177
178
179
180
181
182
# File 'lib/macos/artifacts/files.rb', line 176

def self.etcHosts
  hostfiles = `cat /etc/hosts`.split("\n")
  puts "Hosts File:"
  hostfiles.each do |line|
    puts "  #{line}"
  end
end

.libraryPreferencesObject



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/macos/artifacts/files.rb', line 128

def self.libraryPreferences
  systemApplicationSupport = "/Library/Preferences"
  if Dir.exist?("#{systemApplicationSupport}")
    puts "Library Preferences:"
    Dir.entries("#{systemApplicationSupport}").each do  | filename |
      if filename != "." && filename != ".." && filename != ".DS_Store"
        puts "  #{systemApplicationSupport}/#{filename}"
      end
    end
  end
end

.listUsersAccountDirectoryObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/macos/artifacts/files.rb', line 74

def self.listUsersAccountDirectory
  $userHomeFolder = Dir.entries("/Users/#{$currentUser}")
  fileArray = []
  $userHomeFolder.each do  | filename |
    if filename != "." && filename != ".."
      filePath = "/Users/#{$currentUser}/#{filename}"
        fileArray.push("#{filePath}")
    end
  end
    
  fileArray = fileArray.sort
    
  puts "Home Directory for #{$currentUser}:"
  fileArray.each do |item|
    if ! Dir.exist?("#{item}")
      puts "  #{item}"
    elsif Dir.exist?("#{item}")
      puts "  #{item}:"
      $subDir = Dir.entries("#{item}")
      $subDir.each do  |subfile|
        if subfile != "." && subfile != ".."
          puts "    #{item}/#{subfile}"
        end
      end
    else
      puts "ERROR"
    end
  end
end

.privateTmpObject



244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/macos/artifacts/files.rb', line 244

def self.privateTmp
  path = "/private/tmp"
  
  puts "#{path} Directory:"
  if File.exists?("#{path}")
    output = `ls -al #{path}`.split("\n")
    output.shift
    output.each do |item|
      puts "  #{item}"
    end
  else
    puts "  No such file or directory"
  end
end

.scriptInstallLocationsObject



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/macos/artifacts/files.rb', line 259

def self.scriptInstallLocations
  history1 = `mdfind "kMDItemKind == 'Shell Script'"`.split("\n")
  puts "Script Install Locations:"
  history1.each do |item|
    if ! item.start_with?("/System", "/Library/Developer", "/usr/share", "/usr/bin", "/Library/Ruby")
      if ! item.include? "/Library/Application Support/Code/User/History"
          puts "  #{item.strip}"
      end
    end
  end

  history = `mdfind "kMDItemKind == '* Source'"`.split("\n")
  history.each do |item|
    if ! item.start_with?("/System", "/Library/Developer", "/usr/share", "/usr/bin", "/Library/Ruby")
      if ! item.include? "/Library/Application Support/Code/User/History"
        puts "  #{item.strip}"
      end
    end
  end
end

.systemApplicationSupportObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/macos/artifacts/files.rb', line 116

def self.systemApplicationSupport
  systemApplicationSupport = "/Library/Application Support"
    if Dir.exist?("#{systemApplicationSupport}")
      puts "System Application Support:"
      Dir.entries("#{systemApplicationSupport}").each do  | filename |
        if filename != "." && filename != ".." && filename != ".DS_Store"
          puts "  #{systemApplicationSupport}/#{filename}"
        end
      end
    end
end

.systemLaunchAgentsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/macos/artifacts/files.rb', line 9

def self.systemLaunchAgents
  $systemLaunchAgentsPath = "/Library/LaunchAgents"
  $launchAgentDir = Dir.entries("#{$systemLaunchAgentsPath}")
  puts "System Launchagents:"
  $launchAgentDir.each do  | filename |
    if filename != "." && filename != ".."
      puts "  #{$systemLaunchAgentsPath}/#{filename}"
      plist = CFPropertyList::List.new(:file => "#{$systemLaunchAgentsPath}/#{filename}")
      data = CFPropertyList.native_types(plist.value)
      data.each do |k,v|
        puts "    #{k}: #{v}"
      end
    end
  end
end

.systemLaunchDaemonsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/macos/artifacts/files.rb', line 25

def self.systemLaunchDaemons
  $systemLaunchAgentsPath = "/Library/LaunchDaemons"
  $launchAgentDir = Dir.entries("#{$systemLaunchAgentsPath}")
  puts "System LaunchDaemons:"
  $launchAgentDir.each do  | filename |
    if filename != "." && filename != ".."
      plistLint = `plutil -lint #{$systemLaunchAgentsPath}/#{filename} | cut -d ":" -f2 | xargs`.strip
      if plistLint == "OK"
        puts "  #{$systemLaunchAgentsPath}/#{filename}"
        plist = CFPropertyList::List.new(:file => "#{$systemLaunchAgentsPath}/#{filename}")
        data = CFPropertyList.native_types(plist.value)
        data.each do |k,v|
          puts "    #{k}: #{v}"
        end
      end
    end
  end
end

.userApplicationSupportObject



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/macos/artifacts/files.rb', line 104

def self.userApplicationSupport
  userApplicationSupport = "/Users/#{$currentUser}/Library/Application Support"
  if Dir.exist?("#{userApplicationSupport}")
    puts "#{$currentUser} Application Support:"
    Dir.entries("#{userApplicationSupport}").each do  | filename |
      if filename != "." && filename != ".." && filename != ".DS_Store"
        puts "  #{userApplicationSupport}/#{filename}"
      end
    end
  end
end

.userLaunchAgentsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/macos/artifacts/files.rb', line 44

def self.userLaunchAgents
  userArray = []
  Dir.entries("/Users").each do |username|
    if !username.start_with?(".")
      if username != "Shared" and username != "Guest"
        userArray.push("#{username}")
      end
    end
  end

  userArray.each do |username|
    userLaunchAgentsPath = "/Users/#{username}/Library/LaunchAgents"
    if Dir.exist?("#{userLaunchAgentsPath}")
      launchAgentDir = Dir.entries("#{userLaunchAgentsPath}")
      puts "#{username} LaunchAgents:"
      launchAgentDir.each do  | filename |
        if filename != "." && filename != ".." && filename != ".DS_Store"
          puts "  #{userLaunchAgentsPath}/#{filename}"
          plist = CFPropertyList::List.new(:file => "#{userLaunchAgentsPath}/#{filename}")
          data = CFPropertyList.native_types(plist.value)
          data.each do |k,v|
            puts "    #{k}: #{v}"
          end
        end
      end
    end

  end
end

.userLibraryPreferencesObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/macos/artifacts/files.rb', line 140

def self.userLibraryPreferences
  userArray = []
  Dir.entries("/Users").each do |username|
    if !username.start_with?(".")
      if username != "Shared" and username != "Guest"
        userArray.push("#{username}")
      end
    end
  end
  userArray.each do |username|
    filesArray = []
    userPreferences = "/Users/#{username}/Library/Preferences"
    if Dir.exist?("#{userPreferences}")
      puts "#{username} Preferences:"
      Dir.entries("#{userPreferences}").each do  | filename |
        if filename != "." && filename != ".." && filename != ".DS_Store"
          filesArray.push("#{userPreferences}/#{filename}")
        end
      end
    end
    filesArray.sort.each do |filename|
      puts "  #{filename}"
    end
  end
end

.usersSharedObject



229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/macos/artifacts/files.rb', line 229

def self.usersShared
  path = "/Users/Shared"
  
  puts "#{path} Directory:"
  if File.exists?("#{path}")
    output = `ls -al #{path}`.split("\n")
    output.shift
    output.each do |item|
      puts "  #{item}"
    end
  else
    puts "  No such file or directory"
  end
end

.usrLocalObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/macos/artifacts/files.rb', line 184

def self.usrLocal
  path = "/usr/local"
  
  puts "#{path} Directory:"
  if File.exists?("#{path}")
    output = `ls -al #{path}`.split("\n")
    output.shift
    output.each do |item|
      puts "  #{item}"
    end
  else
    puts "  No such file or directory"
  end
end

.usrLocalBinObject



199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/macos/artifacts/files.rb', line 199

def self.usrLocalBin
  path = "/usr/local/bin"
  
  puts "#{path} Directory:"
  if File.exists?("#{path}")
    output = `ls -al #{path}`.split("\n")
    output.shift
    output.each do |item|
      puts "  #{item}"
    end
  else
    puts "  No such file or directory"
  end
end

.usrLocalSbinObject



214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/macos/artifacts/files.rb', line 214

def self.usrLocalSbin
  path = "/usr/local/sbin"
  
  puts "#{path} Directory:"
  if File.exists?("#{path}")
    output = `ls -al #{path}`.split("\n")
    output.shift
    output.each do |item|
      puts "  #{item}"
    end
  else
    puts "  No such file or directory"
  end
end