Module: Macos::Artifacts::Files

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

Class Method Summary collapse

Class Method Details

.cronTabsObject



179
180
181
182
183
184
185
186
187
# File 'lib/macos/artifacts/files.rb', line 179

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

.etcHostsObject



189
190
191
192
193
194
195
# File 'lib/macos/artifacts/files.rb', line 189

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

.libraryPreferencesObject



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/macos/artifacts/files.rb', line 141

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/macos/artifacts/files.rb', line 87

def self.listUsersAccountDirectory
  $userHomeFolder = Dir.entries("/Users/#{$currentUser}")
  fileArray = []
  $userHomeFolder.each do  | filename |
    if filename != "." && filename != ".." && filename != ".Trash" && filename != ".cups"
      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



257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/macos/artifacts/files.rb', line 257

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



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/macos/artifacts/files.rb', line 272

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



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

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
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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}"
          plistPath = "#{$systemLaunchAgentsPath}/#{filename}"
          if File.exist?("#{plistPath}")
              plist = CFPropertyList::List.new(:file => "#{$systemLaunchAgentsPath}/#{filename}")
              data = CFPropertyList.native_types(plist.value)
              data.each do |k,v|
                  puts "    #{k}: #{v}"
              end
          end
          if File.symlink?("#{plistPath}")
              filename = File.readlink("#{plistPath}")
              if File.exist?("#{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
end

.systemLaunchDaemonsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/macos/artifacts/files.rb', line 38

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



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

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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/macos/artifacts/files.rb', line 57

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



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/macos/artifacts/files.rb', line 153

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



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

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



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

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



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

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



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

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