Sha256: 3dc0e70f6cddce9013fa13f01bba779fbe691b7f799bf9ddb9ded67d9c2fdbc3

Contents?: true

Size: 1.97 KB

Versions: 35

Compression:

Stored size: 1.97 KB

Contents

module Workarea
  class PingHomeBase
    URL = 'https://homebase.weblinc.com'
    SHARED_SECRET = 'e20750f19f5acfe314050da46e6aa77e'

    class << self
      def ping
        begin
          ENV['HTTP_PROXY'] || ENV['HTTPS_PROXY']
          request = Net::HTTP::Post.new('/ping')
          request['X-WeblincClientName'] = Workarea.config.site_name
          request['X-WeblincAuthToken'] = auth_token
          request.content_type = 'application/json'
          request.body = Request.new.to_json

          uri = URI(URL)
          http = Net::HTTP.new(uri.host, uri.port)
          http.use_ssl = true
          http.verify_mode = OpenSSL::SSL::VERIFY_NONE
          http.start { |h| h.request(request) }

        rescue Exception => e
          Rails.logger.error '-------------------------------------'
          Rails.logger.error "There was an error contacting #{URL}!"
          Rails.logger.error e.class
          Rails.logger.error e.message
          Rails.logger.error '-------------------------------------'
        end
      end

      def auth_token
        Digest::SHA256.hexdigest(Workarea.config.site_name + SHARED_SECRET)
      end
    end

    class Request
      PLUGINS_TO_SKIP = ["Workarea::Storefront", "Workarea::Admin"]
      delegate :to_json, to: :to_h

      def to_h
        {
          domain: Workarea.config.host,
          name: Workarea.config.site_name,
          version: Workarea::VERSION::STRING,
          environment: Rails.env,
          ruby_version: RUBY_VERSION,
          client_id: client_id,
          plugins: plugins
        }.compact
      end

      private

      def client_id
        return unless File.exist?(Rails.root.join('.client-id'))

        File.read(Rails.root.join('.client-id'))
      rescue
        nil
      end

      def plugins
        Workarea::Plugin.installed
          .reject { |plugin| PLUGINS_TO_SKIP.include?(plugin.to_s) }
          .map { |plugin| { name: plugin.homebase_name, version: plugin.version } }
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
workarea-core-3.4.45 lib/workarea/ping_home_base.rb
workarea-core-3.4.44 lib/workarea/ping_home_base.rb
workarea-core-3.4.43 lib/workarea/ping_home_base.rb
workarea-core-3.4.42 lib/workarea/ping_home_base.rb
workarea-core-3.4.41 lib/workarea/ping_home_base.rb
workarea-core-3.4.40 lib/workarea/ping_home_base.rb
workarea-core-3.4.39 lib/workarea/ping_home_base.rb
workarea-core-3.4.38 lib/workarea/ping_home_base.rb
workarea-core-3.4.37 lib/workarea/ping_home_base.rb
workarea-core-3.4.36 lib/workarea/ping_home_base.rb
workarea-core-3.4.35 lib/workarea/ping_home_base.rb
workarea-core-3.4.34 lib/workarea/ping_home_base.rb
workarea-core-3.4.33 lib/workarea/ping_home_base.rb
workarea-core-3.4.32 lib/workarea/ping_home_base.rb
workarea-core-3.4.31 lib/workarea/ping_home_base.rb
workarea-core-3.4.30 lib/workarea/ping_home_base.rb
workarea-core-3.4.29 lib/workarea/ping_home_base.rb
workarea-core-3.4.28 lib/workarea/ping_home_base.rb
workarea-core-3.4.27 lib/workarea/ping_home_base.rb
workarea-core-3.4.26 lib/workarea/ping_home_base.rb