Skip to content

Commit

Permalink
Add Safeties before using Settings (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
pglombardo authored Oct 13, 2022
1 parent a007512 commit b405208
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 118 deletions.
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ApplicationHelper
# Set the HTML title for the page with a trailing site identifier.
def title(content)
if Settings.brand.title
if Settings.brand && Settings.brand.title
return content_for(:html_title) { "#{content} | #{Settings.brand.title}" }
else
return content_for(:html_title) { "#{content} | #{_('Password Pusher')}" }
Expand Down
2 changes: 1 addition & 1 deletion app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def headers
from: Settings.mail.mailer_sender
}

if Settings.brand.title
if Settings.brand && Settings.brand.title
headers[:subject] = Settings.brand.title + ' Feedback'
else
headers[:subject] = _('Password Pusher Feedback')
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/mailer/email_changed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p>
<%= _('We\'re contacting you to notify you that your email at') %>
<% if Settings.brand.title %>
<% if Settings.brand && Settings.brand.title %>
<%= link_to Settings.brand.title, root_url %>
<% else %>
<%= link_to _('Password Pusher'), root_url %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/mailer/password_change.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p>
<%= _('We\'re contacting you to notify you that your password has been changed on') %>
<% if Settings.brand.title %>
<% if Settings.brand && Settings.brand.title %>
<%= link_to Settings.brand.title, root_url %>.
<% else %>
<%= link_to _('Password Pusher'), root_url %>.
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<% if Settings.brand.title %>
<% if Settings.brand && Settings.brand.title %>
<title><%= content_for?(:html_title) ? yield(:html_title) : Settings.brand.title %></title>
<% else %>
<title><%= content_for?(:html_title) ? yield(:html_title) : _('Password Pusher') %></title>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/bare.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<% if Settings.brand.title %>
<% if Settings.brand && Settings.brand.title %>
<title><%= content_for?(:html_title) ? yield(:html_title) : Settings.brand.title %></title>
<% else %>
<title><%= content_for?(:html_title) ? yield(:html_title) : _('Password Pusher') %></title>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/login.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<% if Settings.brand.title %>
<% if Settings.brand && Settings.brand.title %>
<title><%= content_for?(:html_title) ? yield(:html_title) : Settings.brand.title %></title>
<% else %>
<title><%= content_for?(:html_title) ? yield(:html_title) : _('Password Pusher') %></title>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/naked.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<% if Settings.brand.title %>
<% if Settings.brand && Settings.brand.title %>
<title><%= content_for?(:html_title) ? yield(:html_title) : Settings.brand.title %></title>
<% else %>
<title><%= content_for?(:html_title) ? yield(:html_title) : _('Password Pusher') %></title>
Expand Down
12 changes: 8 additions & 4 deletions app/views/passwords/audit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
<p><%= _('Secret URL for this push') %>:</p>
<div class='input-group mb-5 w-75'>
<input class='form-control', id='secret_url' value='<%= secret_url(@password) %>' spellcheck='false' readonly='true'>
<button type="button" class="btn btn-primary"><%= Settings.language_codes[params["push_locale"] || I18n.locale] %></button>
<% if Settings.language_codes %>
<button type="button" class="btn btn-primary"><%= Settings.language_codes[params["push_locale"] || I18n.locale] %></button>
<% end %>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><span class="dropdown-item-text"><%= _('Secret Link Lanugage') %></span></li>
<li><hr class="dropdown-divider"></li>
<% I18n.available_locales.each do |lang| %>
<li class='dropdown-item' style='display: none;'><%= link_to Settings.language_codes[lang], url_for(locale: lang.to_s), hreflang: lang.to_s, rel: 'alternate', class: "nav-link px-2 text-muted" %></li>
<li class='dropdown-item'><%= link_to Settings.language_codes[lang], audit_password_path(@password, push_locale: lang), class: "nav-link px-2 text-muted" %></li>
<% if Settings.language_codes %>
<% I18n.available_locales.each do |lang| %>
<li class='dropdown-item' style='display: none;'><%= link_to Settings.language_codes[lang], url_for(locale: lang.to_s), hreflang: lang.to_s, rel: 'alternate', class: "nav-link px-2 text-muted" %></li>
<li class='dropdown-item'><%= link_to Settings.language_codes[lang], audit_password_path(@password, push_locale: lang), class: "nav-link px-2 text-muted" %></li>
<% end %>
<% end %>
</ul>
<button id='copy-to-clipboard-button' class='input-group-text btn-success'
Expand Down
11 changes: 7 additions & 4 deletions app/views/passwords/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@

<div class='input-group mb-5'>
<input class='form-control' id='secret_url' value="<%=@secret_url%>" spellcheck='false' readonly='true'>
<button type="button" class="btn btn-primary"><%= Settings.language_codes[params["push_locale"] || I18n.locale] %></button>
<% if Settings.language_codes %>
<button type="button" class="btn btn-primary"><%= Settings.language_codes[params["push_locale"] || I18n.locale] %></button>
<% end %>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><span class="dropdown-item-text"><%= _('Secret Link Lanugage') %></span></li>
<li><hr class="dropdown-divider"></li>
<% I18n.available_locales.each do |lang| %>
<li class='dropdown-item'><%= link_to Settings.language_codes[lang], preview_password_path(@password, push_locale: lang), class: "nav-link px-2 text-muted" %></li>

<% if Settings.language_codes %>
<% I18n.available_locales.each do |lang| %>
<li class='dropdown-item'><%= link_to Settings.language_codes[lang], preview_password_path(@password, push_locale: lang), class: "nav-link px-2 text-muted" %></li>
<% end %>
<% end %>
</ul>
<button id='copy-to-clipboard-button' class='input-group-text btn-success'
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_email_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<p>
-- <br/>
<%= _('Your Friendly Neighborhood') %>
<% if Settings.brand.title %>
<% if Settings.brand && Settings.brand.title %>
<%= link_to Settings.brand.title, root_url %>
<% else %>
<%= link_to _('Password Pusher'), root_url %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<%= link_to root_path, class: "col-md-2 d-flex align-items-center justify-content-center mb-3 mb-md-0 me-md-auto link-dark text-decoration-none" do %>
<picture>
<% if Settings.brand.light_logo.nil? %>
<% if Settings.brand.nil? || Settings.brand.light_logo.nil? %>
<source srcset="<%= asset_pack_path('media/img/logo-transparent-sm-bare.png') %>" media="(prefers-color-scheme: light) or (prefers-color-scheme: no-preference)">
<source srcset="<%= asset_pack_path('media/img/logo-transparent-sm-dark-bare.png') %>" media="(prefers-color-scheme: dark)">
<img src="<%= asset_pack_path('media/img/logo-transparent-sm-bare.png') %>" alt="<%= _('Password Pusher Logo') %>" style='height: 40px;' />
Expand All @@ -18,7 +18,7 @@
</picture>
<% end %>

<% if Settings.brand.show_footer_menu %>
<% if Settings.brand && Settings.brand.show_footer_menu %>
<ul class="nav col-md-5 justify-content-end">
<li class="nav-item"><%= link_to _('Front Page'), root_path, class: 'nav-link px-2 text-muted' %></li>
<li class="nav-item dropdown">
Expand Down
12 changes: 7 additions & 5 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= link_to root_path, class: 'd-flex align-items-center mb-3 mb-md-0 me-md-auto text-dark text-decoration-none' do %>
<div class='me-2'>
<picture>
<% if Settings.brand.light_logo.nil? %>
<% if Settings.brand.nil? || Settings.brand.light_logo.nil? %>
<source srcset="<%= asset_pack_path('media/img/logo-transparent-sm-bare.png') %>" media="(prefers-color-scheme: light) or (prefers-color-scheme: no-preference)">
<source srcset="<%= asset_pack_path('media/img/logo-transparent-sm-dark-bare.png') %>" media="(prefers-color-scheme: dark)">
<img src="<%= asset_pack_path('media/img/logo-transparent-sm-bare.png') %>" alt="<%= _('Password Pusher Logo') %>" style='height: 50px;' />
Expand All @@ -15,13 +15,13 @@
</picture>
</div>
<div>
<% if Settings.brand.title %>
<% if Settings.brand && Settings.brand.title %>
<span class="fs-4 display-1"><%= Settings.brand.title %></span>
<% else %>
<span class="fs-4 display-1"><%= _('Password Pusher') %></span>
<% end %>
<br/>
<% if Settings.brand.tagline%>
<% if Settings.brand && Settings.brand.tagline%>
<span class="fs-6 text-muted"><%= Settings.brand.tagline %></span>
<% else %>
<span class="fs-6 text-muted"><%= _('Go Ahead. Email Another Password.') %></span>
Expand Down Expand Up @@ -69,8 +69,10 @@
<%= _('Language') %>
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<% I18n.available_locales.each do |lang| %>
<li class='dropdown-item'><%= link_to Settings.language_codes[lang], url_for(locale: lang.to_s), hreflang: lang.to_s, rel: 'alternate', class: "nav-link text-muted" %></li>
<% if Settings.language_codes %>
<% I18n.available_locales.each do |lang| %>
<li class='dropdown-item'><%= link_to Settings.language_codes[lang], url_for(locale: lang.to_s), hreflang: lang.to_s, rel: 'alternate', class: "nav-link text-muted" %></li>
<% end %>
<% end %>
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_layout_icons.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<% if Settings.brand.icon_57x57 %>
<% if Settings.brand && Settings.brand.icon_57x57 %>
<link rel="apple-touch-icon" sizes="57x57" href="<%=asset_pack_path(Settings.brand.icon_57x57)%>">
<link rel="apple-touch-icon" sizes="60x60" href="<%=asset_pack_path(Settings.brand.icon_60x60)%>">
<link rel="apple-touch-icon" sizes="72x72" href="<%=asset_pack_path(Settings.brand.icon_72x72)%>">
Expand Down
42 changes: 20 additions & 22 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,30 @@
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

config.action_mailer.raise_delivery_errors = Settings.mail.raise_delivery_errors

config.action_mailer.perform_caching = false

config.action_mailer.default_url_options = { host: '127.0.0.1:5100', protocol: 'https' }

config.action_mailer.smtp_settings = {
address: Settings.mail.smtp_address,
port: Settings.mail.smtp_port,
user_name: Settings.mail.smtp_user_name,
password: Settings.mail.smtp_password,
authentication: Settings.mail.smtp_authentication,
enable_starttls_auto: Settings.mail.smtp_enable_starttls_auto,
open_timeout: Settings.mail.smtp_open_timeout,
read_timeout: Settings.mail.smtp_read_timeout
}
if Settings.mail
config.action_mailer.raise_delivery_errors = Settings.mail.raise_delivery_errors

config.action_mailer.perform_caching = false

config.action_mailer.default_url_options = { host: '127.0.0.1:5100', protocol: 'https' }

config.action_mailer.smtp_settings = {
address: Settings.mail.smtp_address,
port: Settings.mail.smtp_port,
user_name: Settings.mail.smtp_user_name,
password: Settings.mail.smtp_password,
authentication: Settings.mail.smtp_authentication,
enable_starttls_auto: Settings.mail.smtp_enable_starttls_auto,
open_timeout: Settings.mail.smtp_open_timeout,
read_timeout: Settings.mail.smtp_read_timeout
}

if Settings.mail.smtp_domain
config.action_mailer.smtp_settings[:domain] = Settings.mail.smtp_domain
end

if Settings.mail.smtp_openssl_verify_mode
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_sym
end
if Settings.mail.smtp_openssl_verify_mode
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_sym
end

if Settings.mail.smtp_enable_starttls
config.action_mailer.smtp_settings[:enable_starttls] = Settings.mail.smtp_enable_starttls
end

Expand Down
72 changes: 38 additions & 34 deletions config/environments/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,45 @@
config.force_ssl = ENV.key?('FORCE_SSL') ? true : false

config.logger = Logger.new(STDOUT) if Settings.log_to_stdout
config.log_level = Settings.log_level.downcase.to_sym

config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = Settings.mail.raise_delivery_errors

config.action_mailer.default_url_options = {
host: Settings.host_domain,
protocol: Settings.host_protocol
}

config.middleware.use Rack::Throttle::Daily, max: Settings.throttling.daily
config.middleware.use Rack::Throttle::Hourly, max: Settings.throttling.hourly
config.middleware.use Rack::Throttle::Minute, max: Settings.throttling.minute
config.middleware.use Rack::Throttle::Second, max: Settings.throttling.second

config.action_mailer.smtp_settings = {
address: Settings.mail.smtp_address,
port: Settings.mail.smtp_port,
user_name: Settings.mail.smtp_user_name,
password: Settings.mail.smtp_password,
authentication: Settings.mail.smtp_authentication,
enable_starttls_auto: Settings.mail.smtp_enable_starttls_auto,
open_timeout: Settings.mail.smtp_open_timeout,
read_timeout: Settings.mail.smtp_read_timeout
}

if Settings.mail.smtp_domain
config.action_mailer.smtp_settings[:domain] = Settings.mail.smtp_domain
end

if Settings.mail.smtp_openssl_verify_mode
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_sym
config.log_level = Settings.log_level ? Settings.log_level.downcase.to_sym : 'error'

if Settings.throttling
config.middleware.use Rack::Throttle::Daily, max: Settings.throttling.daily
config.middleware.use Rack::Throttle::Hourly, max: Settings.throttling.hourly
config.middleware.use Rack::Throttle::Minute, max: Settings.throttling.minute
config.middleware.use Rack::Throttle::Second, max: Settings.throttling.second
end

if Settings.mail.smtp_enable_starttls
config.action_mailer.smtp_settings[:enable_starttls] = Settings.mail.smtp_enable_starttls
if Settings.mail
config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = Settings.mail.raise_delivery_errors

config.action_mailer.default_url_options = {
host: Settings.host_domain,
protocol: Settings.host_protocol
}

config.action_mailer.smtp_settings = {
address: Settings.mail.smtp_address,
port: Settings.mail.smtp_port,
user_name: Settings.mail.smtp_user_name,
password: Settings.mail.smtp_password,
authentication: Settings.mail.smtp_authentication,
enable_starttls_auto: Settings.mail.smtp_enable_starttls_auto,
open_timeout: Settings.mail.smtp_open_timeout,
read_timeout: Settings.mail.smtp_read_timeout
}

if Settings.mail.smtp_domain
config.action_mailer.smtp_settings[:domain] = Settings.mail.smtp_domain
end

if Settings.mail.smtp_openssl_verify_mode
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_sym
end

if Settings.mail.smtp_enable_starttls
config.action_mailer.smtp_settings[:enable_starttls] = Settings.mail.smtp_enable_starttls
end
end
end
Loading

0 comments on commit b405208

Please sign in to comment.