Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created July 4, 2009 05:10
Show Gist options
  • Save ohadlevy/140457 to your computer and use it in GitHub Desktop.
Save ohadlevy/140457 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
class Puppetca
# removes old certificate if it exists and removes autosign entry
# parameter is the fqdn to use
def self.clean fqdn
command = "/usr/bin/sudo -S /usr/sbin/puppetca --clean #{fqdn}< /dev/null"
system "#{command} >> /tmp/puppetca.log 2>&1"
#remove fqdn from autosign if exists
entries = open("/etc/puppet/autosign.conf", File::RDONLY).readlines.collect do |l|
l if l.chomp != fqdn
end
entries.uniq!
entries.delete(nil)
autosign = open("/etc/puppet/autosign.conf", File::TRUNC|File::RDWR)
autosign.write entries
autosign.close
return true
end
# add fqdn to puppet autosigns file
# parameter is fqdn to use
def self.sign fqdn
autosign = open("/etc/puppet/autosign.conf", File::RDWR)
# Check that we dont have that host already
found = false
autosign.each_line { |line| found = true if line.chomp == fqdn }
autosign.puts fqdn if found == false
autosign.close
return true
end
end
=begin
CGI starts here
=end
require 'cgi'
cgi=CGI.new
fqdn = ENV['REMOTE_ADDR']
if (Puppetca.clean(fqdn) and Puppetca.sign(fqdn))
cgi.out("status" => "OK", "connection" => "close") {""}
else
cgi.out("status" => "BAD_REQUEST", "connection" => "close") {""}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment