PCI-MSI
  5   ˆl–Ãa¾”ªeJe@ãB¸©‹Fÿ�þC³r²ËB”¤óÂƒt!sÁÀ¿ Ì    #!/usr/bin/ruby
#  Phusion Passenger - https://www.phusionpassenger.com/
#  Copyright (c) 2010-2017 Phusion Holding B.V.
#
#  "Passenger", "Phusion Passenger" and "Union Station" are registered
#  trademarks of Phusion Holding B.V.
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.

## Magic comment: begin bootstrap ##
require 'phusion_passenger'
## Magic comment: end bootstrap ##

PhusionPassenger.locate_directories
PhusionPassenger.require_passenger_lib 'platform_info'
PhusionPassenger.require_passenger_lib 'platform_info/ruby'
PhusionPassenger.require_passenger_lib 'admin_tools/memory_stats'
PhusionPassenger.require_passenger_lib 'utils/ansi_colors'
require 'optparse'

include PhusionPassenger

# Container for tabular data.
class Table
  def initialize(column_names, colors)
    @column_names = column_names
    @rows = []
    @colors = colors
  end

  def add_row(values)
    @rows << values.to_a
  end

  def add_rows(list_of_rows)
    list_of_rows.each do |row|
      add_row(row)
    end
  end

  def remove_column(name)
    i = @column_names.index(name)
    @column_names.delete_at(i)
    @rows.each do |row|
      row.delete_at(i)
    end
  end

  def to_s(title = nil)
    max_column_widths = [1] * @column_names.size
    (@rows + [@column_names]).each do |row|
      row.each_with_index do |value, i|
        max_column_widths[i] = [value.to_s.size, max_column_widths[i]].max
      end
    end

    format_string = max_column_widths.map{ |i| "%#{-i}s" }.join("  ")
    header = sprintf(format_string, *@column_names).rstrip << "\n"
    if title
      free_space = header.size - title.size - 2
      if free_space <= 0
        left_bar_size = 3
        right_bar_size = 3
      else
        left_bar_size = free_space / 2
        right_bar_size = free_space - left_bar_size
      end
      result = "#{@colors.blue_bg}#{@colors.bold}#{@colors.yellow}\n"
      result << "#{"-" * left_bar_size} #{title} #{"-" * right_bar_size}\n"
      if !@rows.empty?
        result << @colors.white
        result << header
      end
    else
      result = header.dup
    end
    if @rows.empty?
      result << @colors.reset
    else
      result << ("-" * header.size) << "#{@colors.reset}\n"
      @rows.each do |row|
        result << sprintf(format_string, *row).rstrip << "\n"
      end
    end
    result
  end
end

# Parses the specific commandline options.
#
# Modeled after `passenger-status` logic, with minor tweaks.
#
class CommandLineOptionsParser
  def parse
    options = {}
    parser = create_option_parser(options)

    begin
      parser.parse!
      options
    rescue OptionParser::ParseError => e
      STDERR.puts e
      STDERR.puts
      STDERR.puts "Please see '--help' for valid options."

      exit 1
    end
  end

  private

  def create_option_parser(options)
    OptionParser.new do |opts|
      opts.banner = "Usage: #{File.basename(__FILE__)} [-h|--help] [--no-apache] [--no-nginx]"

      opts.separator ""
      opts.separator "Tool for inspecting the