# encoding: utf-8 require "cuba" #include Basica module Mutx class App < Cuba lib_folder = File.expand_path("./lib/**/*.rb", File.dirname(__FILE__)) routes_folder = File.expand_path("./routes/**/*.rb", File.dirname(__FILE__)) Dir[lib_folder].each { |rb| require rb } Dir[routes_folder].each { |rb| require rb } include Mote::Helpers include Mutx::MonkeyPatch use Mutx::DatabaseMiddleware use Mutx::LoggerMiddleware use Rack::Session::Cookie, key: 'mutx', secret: 'a_key' use Rack::Static, root: File.expand_path("./public", File.dirname(__FILE__)), urls: ["/js", "/css", "/img"] plugin Basica plugin Mutx::Helpers plugin Mutx::Paths plugin Mutx::Authentication Mutx::FlashMiddleware.used_in(self) # Mutx::Support::Log.start Mutx::Support::Configuration.get define do begin on root do res.redirect path_for(:tasks_index) end on('admin') { run Mutx::Routes::Admin::Routes } on('alerts') { run Mutx::Routes::Alerts::Routes } on('tasks') { run Mutx::Routes::Tasks::Routes } on('tests') { run Mutx::Routes::Tests::Routes } on('task-results') { run Mutx::Routes::TaskResults::Routes } on('results') { run Mutx::Routes::Results::Routes } on('features') { run Mutx::Routes::Features::Routes } on('repositories') { run Mutx::Routes::Repositories::Routes } on('api') { run Mutx::Routes::Api::Routes } on('logs') { run Mutx::Routes::Logs::Routes } on('message') { run Mutx::Routes::Message::Routes } on('help') { run Mutx::Routes::Help::Routes } on get do on "logout" do $result = nil $result = false if env["SERVER_NAME"].eql? "localhost" $result = false a = env["HTTP_REFERER"] || env["REQUEST_URI"] logout = a.match(/\D{4,5}:\/\//).to_s+"user:pass@"+env["SERVER_NAME"].to_s+":"+env["SERVER_PORT"].to_s res.redirect "#{logout}/" else $result = false res.redirect "http://user@mutx.garba.ninja/" end end on "screenshot/:file_name" do |file_name| template = Mote.parse(File.read("#{Mutx::View.path}/screenshot.mote"),self, [:file_name]) res.write template.call(file_name:file_name) end on "error" do args= {query_string:Mutx::Support::QueryString.new(req), exception:nil} template = Mote.parse(File.read("#{Mutx::View.path}/error_handler.mote"),self, [:args]) res.write template.call(args:args) end on "clean" do Mutx::Support::Clean.start res.redirect "/tasks?msg=Tasks and results cleanned" end on "404" do template = Mote.parse(File.read("#{Mutx::View.path}/not_found.mote"),self, []) res.write template.call() end on "version" do res.redirect "api/version" end on ":any" do res.redirect("/tests") end end rescue => exception Mutx::Support::Log.error "Cuba: #{exception} #{exception.backtrace}" if Mutx::Support::Log error_title , error_msg = Mutx::Support::ErrorHandlerHelper.evaluate exception res.write view('Error', error_title: error_title, error_msg: error_msg) end end end end