Class: Ronin::Web::Server::Base

Inherits:
Sinatra::Base
  • Object
show all
Includes:
Conditions, Helpers, Routing
Defined in:
lib/ronin/web/server/base.rb

Overview

The base-class for all Ronin Web Servers. Extends Sinatra::Base with additional routing methods, helper methods and Sinatra conditions.

Routing Methods

  • any: registers a route that responds to GET, POST, PUT, PATCH, DELETE and OPTIONS requests.
  • default: registers the default route.
  • basic_auth: enables Basic-Auth authentication for the whole app.
  • redirect: adds a route that simply redirects to another URL.
  • file: mounts a file at the given path. a given file.
  • directory: mounts a directory at the given path.
  • public_dir: mounts a directory at the root.
  • vhost: mounts a Rack app for the given vhost.
  • mount: mounts a Rack app at the given path.

Helper Methods

Routing Conditions

  • client_ip: filters requests based on their client IP address.
  • asn: filters requests by the client IP's ASN number.
  • country_code: filters requests by the client IP's ASN country code.
  • asn_name: filters requests by the client IP's ASN company/ISP name.
  • host: filters requests based on the Host header.
  • referer: filters requests based on the Referer header.
  • user_agent: filters requests based on the User-Agent header.
  • browser: filters requests based on the browser name within the User-Agent header.
  • browser_version: filters requests based on the browser version within the User-Agent header.
  • device_type: filters requests based on the device type within the User-Agent header.
  • os: filters requests based on the OS within the User-Agent header.
  • os_version: filters requests based on the OS version within the User-Agent header.

Examples

require 'ronin/web/server'

class App < Ronin::Web::Server::Base

# mount a file
file '/sitemap.xml', './files/sitemap.xml'

# mount a directory
directory '/downloads/', '/tmp/downloads/'

get '/' do
  # renders views/index.erb
  erb :index
end

get '/test' do
  "raw text here"
end

end

App.run!

Direct Known Subclasses

App

Constant Summary collapse

DEFAULT_HOST =

Default interface to run the Web Server on

'0.0.0.0'
DEFAULT_PORT =

Default port to run the Web Server on

8000

Class Method Summary collapse

Methods included from Conditions

included

Methods included from Helpers

#content_type_for, #mime_type_for

Methods included from Routing

included

Class Method Details

.run!(options = {}, &block) ⇒ Object

Run the web server.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :host (String)

    The host the server will listen on.

  • :port (Integer)

    The port the server will bind to.

  • :server (String)

    The Web Server to run on.

  • :background (Boolean) — default: false

    Specifies wether the server will run in the background or run in the foreground.

Raises:

  • (Errno::EADDRINUSE)

    The port is already in use.



168
169
170
171
172
173
174
# File 'lib/ronin/web/server/base.rb', line 168

def self.run!(options={},&block)
  if options[:background]
    Thread.new(options) { |options| super(options) }
  else
    super(options,&block)
  end
end