-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.rb
179 lines (125 loc) · 4.42 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# encoding: UTF-8
# Copyright (c) 2016-2024, Claudio Bustos Navarrete
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
require "bundler/setup"
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
# Windows doesn't have proper management of certificates for SSL.
# So, we have to user 'certified' gem to fix it
require 'certified'
end
require 'sinatra'
require 'haml'
require 'logger'
require 'i18n'
require 'dotenv'
require 'digest/sha1'
require 'libcache'
require_relative("lib/buhos")
Dir.glob("lib/*.rb").each do |f|
require_relative(f)
end
$test_mode=ENV['RACK_ENV'].to_s == "test"
$cache = CacheBuilder.with(Cache).set_expiry('120s').set_max(1000).build
installed_file= $test_mode ? "config/installed_test" : "config/installed"
if (!$test_mode and !File.exist?(installed_file)) or ENV['TEST_INSTALLER']
load('installer.rb')
Buhos::Installer.run!
exit 1
end
if !$test_mode
Dotenv.load("./.env")
end
set :session_secret, 'd290f527d209bd4cd94db2dbdecf29cabaa6499c04bcd83278e3863cd7b25490859df1173c2aa2fd2ede7db09b9208b588badf8298519c23fc16220b356c0029'
use Rack::Session::Cookie, :key => 'rack.session',
:path => '/',
:secret => 'd290f527d209bd4cd94db2dbdecf29cabaa6499c04bcd83278e3863cd7b25490859df1173c2aa2fd2ede7db09b9208b588badf8298519c23fc16220b356c0029'
enable :logging, :dump_errors, :raise_errors
configure :development do |c|
c.enable :logging, :dump_errors, :raise_errors, :show_errors, :show_exceptions
set :show_exceptions, :after_handler
end
configure :production do |c|
c.enable :logging, :dump_errors, :raise_errors, :show_errors, :show_exceptions
set :show_exceptions, :after_handler
end
# this is required if you want to assume the default path
set :root, File.dirname(__FILE__)
# Arreglo a lo bestia para el force_encoding
unless "".respond_to? :force_encoding
class String
def force_encoding(s)
self
end
end
end
Dir.glob("controllers/**/*.rb").each do |f|
require_relative(f)
end
unless File.exist?("log")
FileUtils.mkdir("log")
end
if $test_mode
$log = Logger.new('log/test_app.log')
$log_sql = Logger.new('log/test_app_sql.log')
else
$log = Logger.new('log/app.log')
$log_sql = Logger.new('log/app_sql.log')
end
#$log.info(Encoding.default_external)
require_relative 'model/init.rb'
require_relative 'model/models.rb'
require_relative 'lib/sinatra/partials.rb'
Dir.glob("model/*.rb").each do |f|
require_relative(f)
end
helpers Sinatra::Partials
helpers DOIHelpers
helpers HTMLHelpers
helpers Buhos::Helpers
helpers Buhos::StagesMixin
helpers Buhos::ControllerReview
error 403 do
haml :error403, escape_html:false
end
error 404 do
haml :error404, escape_html:false
end
# INICIO
#require 'flamegraph'
get '/' do
#Flamegraph.generate("test") do
log.info("Parto en /")
if session['user'].nil?
log.info("/ sin id: basico")
redirect url('/login')
else
@user=User[session['user_id']]
haml :main, :escape_html=>false
end
#end
end