From 54f8549c43ea9c7ce10ea036ebe94ea0b371824a Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 30 Nov 2016 13:39:58 +0100 Subject: [PATCH] Set up sandbox --- app/controllers/sandbox_controller.rb | 27 +++++++++++ app/views/sandbox/index.html.erb | 13 ++++++ app/views/sandbox/test_sandbox.html.erb | 61 +++++++++++++++++++++++++ config/routes.rb | 5 ++ 4 files changed, 106 insertions(+) create mode 100644 app/controllers/sandbox_controller.rb create mode 100644 app/views/sandbox/index.html.erb create mode 100644 app/views/sandbox/test_sandbox.html.erb diff --git a/app/controllers/sandbox_controller.rb b/app/controllers/sandbox_controller.rb new file mode 100644 index 000000000..ea5a3e96b --- /dev/null +++ b/app/controllers/sandbox_controller.rb @@ -0,0 +1,27 @@ +class SandboxController < ApplicationController + skip_authorization_check + + def index + @templates = Dir.glob(Rails.root.join('app/views/sandbox/*.html.erb').to_s).map do |filename| + filename = File.basename(filename, File.extname(filename)) + filename unless filename.starts_with?('_') || filename == 'index.html' + end.compact + end + + def show + if params[:template].index('.') # CVE-2014-0130 + render :action => "index" + elsif lookup_context.exists?("sandbox/#{params[:template]}") + if params[:template] == "index" + render :action => "index" + else + render "sandbox/#{params[:template]}" + end + + elsif lookup_context.exists?("sandbox/#{params[:template]}/index") + render "sandbox/#{params[:template]}/index" + else + render :action => "index" + end + end +end diff --git a/app/views/sandbox/index.html.erb b/app/views/sandbox/index.html.erb new file mode 100644 index 000000000..9d6303698 --- /dev/null +++ b/app/views/sandbox/index.html.erb @@ -0,0 +1,13 @@ +
+
+
+

Welcome to sandbox

+ +
    + <% @templates.each do |template| %> +
  • <%= link_to template, "/sandbox/" + template %>
  • + <% end %> +
+
+
+
diff --git a/app/views/sandbox/test_sandbox.html.erb b/app/views/sandbox/test_sandbox.html.erb new file mode 100644 index 000000000..5d61aab9d --- /dev/null +++ b/app/views/sandbox/test_sandbox.html.erb @@ -0,0 +1,61 @@ +
+ +
diff --git a/config/routes.rb b/config/routes.rb index 07200f76c..6d6e23686 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,10 @@ Rails.application.routes.draw do + if Rails.env.development? || Rails.env.staging? + get '/sandbox' => 'sandbox#index' + get '/sandbox/*template' => 'sandbox#show' + end + devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions',