#!/usr/bin/env ruby require 'optparse' require 'ssl_info' # -------------------------------------------------------------------------------- # # Process Arguments # # -------------------------------------------------------------------------------- # # This function will process the input from the command line and work out what it # # is that the user wants to see. # # # # This is the main processing function where all the processing logic is handled. # # -------------------------------------------------------------------------------- # def process_arguments options = {} # Enforce the presence of mandatory = %I[domain] optparse = OptionParser.new do |opts| opts.banner = "Usage: #{$PROGRAM_NAME}" opts.on('-h', '--help', 'Display this screen') do puts opts exit(1) end opts.on('-d', '--domain string', 'The domain name to check') do |domain| options[:domain] = domain end end begin optparse.parse! options[:message] = ARGF.read if !STDIN.tty? # override message parameter if data is piped in missing = mandatory.select { |param| options[param].nil? } raise OptionParser::MissingArgument.new(missing.join(', ')) unless missing.empty? rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e puts e.to_s puts optparse exit end SSLInfo.get_cert(options[:domain]) SSLInfo.display_cert end # -------------------------------------------------------------------------------- # # Main() # # -------------------------------------------------------------------------------- # # The main function where all of the heavy lifting and script config is done. # # -------------------------------------------------------------------------------- # def main process_arguments end main # -------------------------------------------------------------------------------- # # End of Script # # -------------------------------------------------------------------------------- # # This is the end - nothing more to see here. # # -------------------------------------------------------------------------------- #