Passed
Push — master ( 0ee451...32da1e )
by Ahmad
07:31
created

Application.parse_bool()   A

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
1
# frozen_string_literal: true
2
3
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
#
5
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
6
#
7
# This program is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU Lesser General Public License as published by the Free Software
9
# Foundation; either version 3.0 of the License, or (at your option) any later
10
# version.
11
#
12
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
#
16
# You should have received a copy of the GNU Lesser General Public License along
17
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
19
require_relative 'boot'
20
21
require 'rails/all'
22
23
# Require the gems listed in Gemfile, including any gems
24
# you've limited to :test, :development, or :production.
25
Bundler.require(*Rails.groups)
26
27
module Greenlight
28
  class Application < Rails::Application
29
    # Initialize configuration defaults for originally generated Rails version.
30
    config.load_defaults 5.2
31
32
    # Settings in config/environments/* take precedence over those specified here.
33
    # Application configuration should go into files in config/initializers
34
    # -- all .rb files in that directory are automatically loaded.
35
36
    def parse_bool(val, default = false)
37
      val = ActiveModel::Type::Boolean.new.cast(val)
38
      val.nil? ? default : val
39
    end
40
41
    # Use custom error routes.
42
    config.exceptions_app = routes
43
44
    # Configure I18n localization.
45
    config.i18n.available_locales = [:en]
46
    config.i18n.default_locale = :en
47
48
    # Check if a loadbalancer is configured.
49
    config.loadbalanced_configuration = ENV["LOADBALANCER_ENDPOINT"].present? && ENV["LOADBALANCER_SECRET"].present?
50
51
    # The default callback url that bn launcher will redirect to
52
    config.gl_callback_url = ENV["GL_CALLBACK_URL"]
53
54
    # Default credentials (test-install.blindsidenetworks.com/bigbluebutton).
55
    config.bigbluebutton_endpoint_default = "http://test-install.blindsidenetworks.com/bigbluebutton/api/"
56
    config.bigbluebutton_secret_default = "8cd8ef52e8e101574e400365b55e11a6"
57
58
    # Use standalone BigBlueButton server.
59
    config.bigbluebutton_endpoint = if ENV["BIGBLUEBUTTON_ENDPOINT"].present?
60
      ENV["BIGBLUEBUTTON_ENDPOINT"]
61
    else
62
      config.bigbluebutton_endpoint_default
63
    end
64
65
    config.bigbluebutton_secret = if ENV["BIGBLUEBUTTON_SECRET"].present?
66
      ENV["BIGBLUEBUTTON_SECRET"]
67
    else
68
      config.bigbluebutton_secret_default
69
    end
70
71
    # Fix endpoint format if required.
72
    config.bigbluebutton_endpoint += "/" unless config.bigbluebutton_endpoint.ends_with?('/')
73
    config.bigbluebutton_endpoint += "api/" if config.bigbluebutton_endpoint.ends_with?('bigbluebutton/')
74
    config.bigbluebutton_endpoint +=
75
      "bigbluebutton/api/" unless config.bigbluebutton_endpoint.ends_with?('bigbluebutton/api/')
76
77
    if config.loadbalanced_configuration
78
      # Settings for fetching credentials from a loadbalancer based on provider.
79
      config.loadbalancer_endpoint = ENV["LOADBALANCER_ENDPOINT"]
80
      config.loadbalancer_secret = ENV["LOADBALANCER_SECRET"]
81
      config.launcher_secret = ENV["LAUNCHER_SECRET"]
82
83
      # Fix endpoint format if required.
84
      config.loadbalancer_endpoint += "/" unless config.bigbluebutton_endpoint.ends_with?("/")
85
      config.loadbalancer_endpoint = config.loadbalancer_endpoint.chomp("api/")
86
87
      # Configure which settings are available to user on room creation/edit after creation
88
      config.url_host = ENV['URL_HOST'] || ''
89
    end
90
91
    # Specify the email address that all mail is sent from
92
    config.smtp_sender = ENV['SMTP_SENDER'] || "[email protected]"
93
94
    # Determine if GreenLight should enable email verification
95
    config.enable_email_verification = parse_bool(ENV['ALLOW_MAIL_NOTIFICATIONS'])
96
97
    # Determine if GreenLight should allow non-omniauth signup/login.
98
    config.allow_user_signup = parse_bool(ENV['ALLOW_GREENLIGHT_ACCOUNTS'])
99
100
    # Configure custom banner message.
101
    config.banner_message = ENV['BANNER_MESSAGE']
102
103
    # Enable/disable recording thumbnails.
104
    config.recording_thumbnails = parse_bool(ENV['RECORDING_THUMBNAILS'], true)
105
106
    # Configure which settings are available to user on room creation/edit after creation
107
    config.room_features = ENV['ROOM_FEATURES'] || ""
108
109
    # The maximum number of rooms included in one bbbapi call
110
    config.pagination_number = ENV['PAGINATION_NUMBER'].to_i.zero? ? 25 : ENV['PAGINATION_NUMBER'].to_i
111
112
    # Number of rows to display per page
113
    config.pagination_rows = ENV['NUMBER_OF_ROWS'].to_i.zero? ? 25 : ENV['NUMBER_OF_ROWS'].to_i
114
115
    # Whether the user has defined the variables required for recaptcha
116
    config.recaptcha_enabled = ENV['RECAPTCHA_SITE_KEY'].present? && ENV['RECAPTCHA_SECRET_KEY'].present?
117
118
    # Show/hide "Add to Google Calendar" button in the room page
119
    config.enable_google_calendar_button = parse_bool(ENV['ENABLE_GOOGLE_CALENDAR_BUTTON'])
120
121
    # Enum containing the different possible registration methods
122
    config.registration_methods = { open: "0", invite: "1", approval: "2" }
123
124
    config.google_analytics = ENV["GOOGLE_ANALYTICS_TRACKING_ID"].present?
125
126
    # Will always be true unless explicitly set to false
127
    config.enable_cache = parse_bool(ENV["ENABLE_CACHED_PROVIDER"], true)
128
129
    # MAINTENANCE
130
    config.maintenance_window = ENV["MAINTENANCE_WINDOW"]
131
    config.maintenance_mode = parse_bool(ENV["MAINTENANCE_MODE"])
132
133
    config.report_issue_url = ENV["REPORT_ISSUE_URL"]
134
    config.help_url = ENV["HELP_URL"].nil? ? "https://docs.bigbluebutton.org/greenlight/gl-overview.html" : ENV["HELP_URL"]
135
136
    # File types allowed in preupload presentation
137
    config.allowed_file_types = ".doc,.docx,.ppt,.pptx,.pdf,.xls,.xlsx,.txt,.rtf,.odt,.ods,.odp,.odg,.odc,.odi,.jpg,.jpeg,.png"
138
139
    # Default locale
140
    config.default_locale = ENV["DEFAULT_LOCALE"]
141
142
    # DEFAULTS
143
144
    # Default branding image if the user does not specify one
145
    config.branding_image_default = "https://raw.githubusercontent.com/bigbluebutton/greenlight/master/app/assets/images/logo_with_text.png"
146
147
    # Default primary color if the user does not specify one
148
    config.primary_color_default = "#467fcf"
149
150
    # Default primary color lighten if the user does not specify one
151
    config.primary_color_lighten_default = "#e8eff9"
152
153
    # Default primary color darken if the user does not specify one
154
    config.primary_color_darken_default = "#316cbe"
155
156
    # Default registration method if the user does not specify one
157
    config.registration_method_default = case ENV["DEFAULT_REGISTRATION"]
158
                                         when "invite"
159
      config.registration_methods[:invite]
160
    when "approval"
161
      config.registration_methods[:approval]
162
    else
163
      config.registration_methods[:open]
164
    end
165
166
    # Default limit on number of rooms users can create
167
    config.number_of_rooms_default = 15
168
169
    # Allow users to share rooms by default
170
    config.shared_access_default = "true"
171
172
    # Don't require recording consent by default
173
    config.require_consent_default = "false"
174
175
    # Don't allow users to preupload presentations by default
176
    config.preupload_presentation_default = "false"
177
178
    # Default admin password
179
    config.admin_password_default = ENV['ADMIN_PASSWORD'] || 'administrator'
180
  end
181
end
182