Sha256: a0ee6ff24b44c03b23b183bd0fd597f17ef473b5cad4ce81eb14f208aa9a16b8

Contents?: true

Size: 659 Bytes

Versions: 3

Compression:

Stored size: 659 Bytes

Contents

module WebSandboxConsole
  class ApplicationController < ActionController::Base
    protect_from_forgery with: :exception
    
    before_action :restrict_ip
    http_basic_authenticate_with name: WebSandboxConsole.http_basic_auth[:name].to_s, password: WebSandboxConsole.http_basic_auth[:password].to_s if WebSandboxConsole.http_basic_auth.present?


    # 限制ip
    def restrict_ip
      return unless ip_whitelist = WebSandboxConsole.ip_whitelist
      
      request_ip = IPAddr.new(request.remote_ip)
      unless ip_whitelist.any? {|legal_ip| IPAddr.new(legal_ip).include?(request_ip)}
        render text: "非法请求"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
web_sandbox_console-0.6.0 app/controllers/web_sandbox_console/application_controller.rb
web_sandbox_console-0.5.0 app/controllers/web_sandbox_console/application_controller.rb
web_sandbox_console-0.4.0 app/controllers/web_sandbox_console/application_controller.rb