Sha256: f1e4d4cbdb2a9adcb9be9eced3d368d47cf8934f88e48184b74c630dd0b8a722

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module ClientHelper
  require 'socket'

  def host_for_client(client)
    host = CLIENT_MAP[client] or client.gsub(/-fd$/, '')
  end

  def check_interminably(host, port)
    begin
      s = TCPSocket.new(host, port)
      s.close
      s ? "okay.png" : "error.png"
    rescue SocketError
      "dunno.png"
    rescue 
      "error.png"
    end
  end

  def client_check(host, port = 9102)
    t = Thread.new { check_interminably(host, port) }
    t.join(5) ? t.value : "error.png"
  end

  def client_image
    @client = Client.find(params[:id])
    host = host_for_client(@client.name)
    @image = client_check(host)
  end

  def check_tag(cid)
    if cid == 0
      content_tag('td',
        content_tag('a', "OK?",
          :href => "#", :onclick => "return check_through(#{@clients.size})"))
    else
      content_tag('td',
        content_tag('a',
          content_tag('div', image_tag('dunno.png', :class => "em1"),
            :class => "center", :id => "client-#{cid}"),
          :href => "#", :onclick => "return check(#{cid})"))
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bacuview-1.5 app/helpers/client_helper.rb