Class: Dokuwiki::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/dokuwiki/helper.rb

Class Method Summary collapse

Class Method Details

.find_installsObject



5
6
7
8
9
10
11
12
13
# File 'lib/puppet_x/dokuwiki/helper.rb', line 5

def self.find_installs
  installs = Array.new
  dokufiles = `find / -type f -name doku.php`.split("\n")
  dokufiles.each do |doku|
    path = Pathname.new(doku)
    installs << path.dirname
  end
  return installs
end

.find_userhash(login) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puppet_x/dokuwiki/helper.rb', line 15

def self.find_userhash()
  installs = find_installs
  installs.each do |parent|
    authfile = File.join(parent,'conf','users.auth.php')
    if File.exist?(authfile) then
      File.open(authfile).each_line do |line|
        line.chomp!
        next if line.empty? || !(line =~ /^#{}:/)
        (name,password_hash,fullname,email,groups) = line.split(':')
        return password_hash
      end
    end
  end
  return nil
end

.generate_hash(login, password) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/puppet_x/dokuwiki/helper.rb', line 39

def self.generate_hash(, password)
  salt = nil
  userhash = find_userhash()
  if(userhash && userhash.length > 0) then
    (empty,type,salt,hash) = userhash.split('$')
  end
  return hash_password(salt, password)
end

.hash_password(salt, password) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/puppet_x/dokuwiki/helper.rb', line 31

def self.hash_password(salt, password)
  if salt && salt.length > 0
    return `openssl passwd -1 -salt #{salt} #{password}`.chomp!
  else
    return `openssl passwd -1 #{password}`.chomp!
  end
end