Class: Mop

Inherits:
Object
  • Object
show all
Defined in:
lib/mop.rb,
lib/mop/version.rb

Constant Summary collapse

IPv4_ADDRESSES =
%r/((\d+\.){3}\d+)/
HEXDIGIT =

XXX a-f

%r/[a-z0-9]/i
IPv6_ADDRESSES =
%r/((#{HEXDIGIT}+:){5}#{HEXDIGIT}+)/
EQUATE =
%r/\s*(?:=>|[:=]|,)\s*/
USER_EQUALS =
%r/(user#{EQUATE})\S+/i
HOME_DIRS =

not worried about spaces in usernames.

%r((/(?:Users|home)/)\S+)
USER_PATTERN =
%r/(?:#{USER_EQUALS}|#{HOME_DIRS})/
PASSWORD_EQUALS =
%r/(passw?(or)?d?#{EQUATE})\S+/i
UN =
%r[\b(?:[ul]\/?n?)\b]i
PW =
%r[\b(?:p\/?w?)\b]i
USERNAME_AND_PASSWORD =
%r/(#{UN}#{EQUATE})\S+(\s*#{PW}#{EQUATE})\S+/
GITHUB_URL =
%r[((?:git@|(?:https?|git)://)github.com[:/])[^/]+/.+(\.git)?]i
GIT_URL =
%r[(ssh|git|https?|ftp|rsync)://\S+(\.git)]
SSH_URL =
%r[(ssh://)\S+]i
CAPISTRANO_KEYWORDS =
%r/((?:host_name|port|deploy_to|application)(?:#{EQUATE}))\S+/
CAPISTRANO_SERVER =
%r/(\bserver\s+)\S+,/
PASSTHRU_ADDRESSES =
%w(127.0.0.1 0.0.0.0)
VERSION =
'0.0.6'

Class Method Summary collapse

Class Method Details

.check_address(addr) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/mop.rb', line 55

def self.check_address addr
  if PASSTHRU_ADDRESSES.include? addr
    addr
  else
    'XX.YY.ZZ.AA'
  end
end

.find_hostnameObject



52
# File 'lib/mop.rb', line 52

def self.find_hostname; `hostname`.chomp || 'weird, no hostname' end

.hostname_cleanupObject



49
50
51
# File 'lib/mop.rb', line 49

def self.hostname_cleanup
  [ %r/\b#{find_hostname}\b/, -> { 'hiddenhost' } ]
end

.read_etc_passwdObject



47
# File 'lib/mop.rb', line 47

def self.read_etc_passwd; File.read '/etc/passwd' end

.username_cleanupsObject



38
39
40
41
42
43
44
45
46
# File 'lib/mop.rb', line 38

def self.username_cleanups
  users = read_etc_passwd.split(/\n/).map do |e|
    username, archaic, uid, *junk = e.split ':'
    uid.to_i >= 1000 and username
  end.compact
  users.map do |e|
    [ %r/\b#{e}\b/, -> { 'hiddenuser' } ]
  end
end

.wipe(input) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mop.rb', line 19

def self.wipe input
  cleanups = username_cleanups + [
    hostname_cleanup,
    [ IPv4_ADDRESSES, -> { check_address $1 } ],
    [ IPv6_ADDRESSES, -> { 'aa:bb:cc:dd:ee:ff' } ],
    [ USER_PATTERN, -> { "#$1hiddenuser" } ],
    [ PASSWORD_EQUALS, -> { "#$1hiddenpass" } ],
    [ USERNAME_AND_PASSWORD, -> { "#$1hiddenuser#$2hiddenpass" } ],
    [ GITHUB_URL, -> { "#$1hiddenrepo#$2" } ],
    [ GIT_URL, -> { "#$1://hiddenrepo" } ],
    [ SSH_URL, -> { "#$1hiddensshurl" } ],
    [ CAPISTRANO_KEYWORDS, -> { "#$1caphidden" } ],
    [ CAPISTRANO_SERVER, -> { "#$1capserver" } ],
  ]
  cleanups.inject input do |result, xform|
    result.gsub xform[0] do xform[1].call end
  end
end