A Rails engine that provides a browser-based admin interface and Rails console for your applications.
- 📊 Dashboard: Real-time Rails application statistics and system information
- 💻 Browser Console: Execute Ruby code directly in your Rails environment
- 🎨 Modern UI: Clean, responsive interface
- 🌐 Multi-language Support: English and Japanese interface
- 🔧 Easy Integration: Simple gem installation and mounting process
- 🔐 Built-in Authentication: Simple authentication options (Basic Auth, API keys, Custom)
Add this line to your application's Gemfile:
gem 'stomp_base'
Then, execute:
bundle install
After installing the gem, you can mount the engine in your routes.rb
file:
Rails.application.routes.draw do
mount StompBase::Engine => "/stomp_base"
end
You can configure the language in an initializer file (config/initializers/stomp_base.rb
):
# Set to Japanese
StompBase.configure do |config|
config.locale = :ja
end
# Or set directly
StompBase.locale = :ja
# Default is English (:en)
StompBase.configure do |config|
config.locale = :en
end
Stomp Base includes built-in authentication features that can be easily configured:
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.locale = :ja
config.enable_authentication(
method: :basic_auth,
username: 'admin',
password: 'your_secure_password'
)
end
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.enable_authentication(
method: :api_key,
keys: ['your-api-key-1', 'your-api-key-2']
)
end
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.enable_authentication(
method: :custom,
authenticator: ->(request, params) {
# Your custom authentication logic
request.headers['Authorization'] == 'Bearer your-token'
}
)
end
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.disable_authentication
end
For more detailed authentication configuration examples, see the Authentication Details section below.
Available locales:
- `:en` - English (default)
- `:ja` - Japanese (日本語)
### Accessing the Interface
- Dashboard: `/stomp_base/` or `/stomp_base/dashboard`
- Console: `/stomp_base/console`
- Settings: `/stomp_base/settings`
You can also change the language through the web interface by accessing the Settings page.
## Development
To contribute to Stomp Base, clone the repository and run the following commands:
```bash
bundle install
To run tests, use:
rspec
StompBase.configure do |config|
config.locale = :ja # Set interface language
config.available_locales = [:en, :ja] # Available language options (read-only)
# Authentication options
config.enable_authentication( # Enable authentication
method: :basic_auth, # :basic_auth, :api_key, or :custom
username: 'admin', # For basic_auth
password: 'password', # For basic_auth
keys: ['api-key'], # For api_key (array of valid keys)
authenticator: -> { } # For custom (callable object)
)
config.disable_authentication # Disable authentication
end
# Check if authentication is enabled
StompBase.authentication_enabled? # => true or false
# Enable authentication
StompBase.enable_authentication(method: :basic_auth, username: 'admin', password: 'pass')
# Disable authentication
StompBase.disable_authentication
# Get current locale
StompBase.locale # => :en
# Set locale directly
StompBase.locale = :ja # Set to Japanese
StompBase.locale = :en # Set to English (default)
When included in controllers or views:
include StompBase::I18nHelper
# Translate keys with automatic "stomp_base." prefix
t('dashboard.title') # => "Stomp Base Dashboard" or "Stomp Base ダッシュボード"
t('console.placeholder') # => "Enter Ruby code..." or "Ruby コードを入力してください..."
# Get available locales
available_locales # => [:en, :ja]
# Get current locale
current_locale # => :en or :ja
# Get locale display name
locale_name(:en) # => "English"
locale_name(:ja) # => "日本語"
The engine automatically saves the selected language to the user's session:
# Language preference is stored in session[:stomp_base_locale]
# and persists across page reloads and browser sessions
Translation files are located in config/locales/
:
en.yml
- English translationsja.yml
- Japanese translations
You can add more languages by creating additional YAML files and updating the configuration.
StompBase has built-in authentication features that can be easily enabled through configuration files without using database or session functionality.
The most basic authentication method. Set a username and password.
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.locale = :ja
# Enable Basic Authentication
config.enable_authentication(
method: :basic_auth,
username: 'admin',
password: 'secret123'
)
end
API key-based authentication. Multiple keys can be configured.
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.locale = :ja
# Enable API Key Authentication
config.enable_authentication(
method: :api_key,
keys: ['your-api-key-1', 'your-api-key-2']
)
end
API keys can be sent in the following ways:
- HTTP Header:
X-API-Key: your-api-key
- URL Parameter:
?api_key=your-api-key
You can implement your own custom authentication logic.
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.locale = :ja
# Enable Custom Authentication
config.enable_authentication(
method: :custom,
authenticator: ->(request, params) {
# Implement your custom authentication logic
# Return true for authentication success, false for failure
token = request.headers['Authorization']
token == 'Bearer your-custom-token'
}
)
end
To disable authentication:
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.disable_authentication
end
# Or simply
StompBase.disable_authentication
To skip authentication for specific controllers or actions:
class MyController < StompBase::ApplicationController
skip_before_action :authenticate_stomp_base, only: [:public_action]
def public_action
# Accessible without authentication
end
def private_action
# Requires authentication
end
end
Example of using different settings for production and development environments:
# config/initializers/stomp_base.rb
StompBase.configure do |config|
config.locale = :ja
if Rails.env.production?
# Strong authentication for production
config.enable_authentication(
method: :api_key,
keys: [ENV['STOMP_BASE_API_KEY']]
)
elsif Rails.env.development?
# Simple authentication for development
config.enable_authentication(
method: :basic_auth,
username: 'dev',
password: 'dev'
)
else
# Disable authentication for test environment
config.disable_authentication
end
end
- It is recommended to manage Basic Auth passwords and API keys using environment variables
- Use HTTPS (especially when using Basic Authentication)
- Update API keys regularly
- Be careful not to output authentication information to log files
The authentication feature is implemented with the following approach:
-
Simple Authentication
- Basic Authentication (username/password)
- API Key Authentication (header or parameter)
- Custom Authentication (custom logic)
-
Configuration via initializer file
# config/initializers/stomp_base.rb StompBase.configure do |config| config.enable_authentication( method: :basic_auth, username: 'admin', password: 'password' ) end
-
No database or session functionality
- Memory-based configuration management
- Authentication information via HTTP headers or parameters
- Simple implementation without persistence
lib/stomp_base/authentication.rb
- Authentication feature implementationlib/stomp_base/configuration.rb
- Added authentication configuration functionalityspec/controllers/stomp_base/authentication_spec.rb
- Controller testsspec/lib/stomp_base/configuration_spec.rb
- Configuration class testsspec/unit/configuration_spec.rb
- Unit tests
lib/stomp_base.rb
- Authentication feature loading and helper method additionsapp/controllers/stomp_base/application_controller.rb
- Authentication module integrationstomp_base.gemspec
- Added authentication feature descriptionGemfile
- Added bigdecimal dependency
- Access without authentication: Correctly rejected with 401 Unauthorized
- Correct authentication credentials: Successfully accessed with 200 OK
- Incorrect authentication credentials: Correctly rejected with 401 Unauthorized
- Demo application: Working normally at localhost:3001
Authentication feature implementation is complete. The following extensions are possible if needed:
- Add authentication logging
- Rate limiting functionality
- Dynamic authentication configuration changes
- Addition of more authentication methods
This project is licensed under the MIT License. See the LICENSE file for details.