diff --git a/.ruby-version b/.ruby-version index 1f7da99..667b8b1 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1,2 @@ -2.7.7 +3.2.1 + diff --git a/Dockerfile b/Dockerfile index 2447e4b..d282997 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:2.7.7-bullseye AS base +FROM ruby:3.2.1-bullseye AS base SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN apt-get update \ @@ -31,7 +31,7 @@ RUN mkdir -p /opt/postal/app /opt/postal/config WORKDIR /opt/postal/app # Install bundler -RUN gem install bundler -v 2.4.7 --no-doc +RUN gem install bundler -v 2.4.9 --no-doc # Install the latest and active gem dependencies and re-run # the appropriate commands to handle installs. diff --git a/Gemfile b/Gemfile index 0d8b0c9..6f0bfed 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source "https://rubygems.org" -gem "authie", "~> 3.0" +gem "authie" gem "autoprefixer-rails" gem "basic_ssl" gem "bcrypt" @@ -15,25 +15,27 @@ gem "gelf" gem "haml" gem "hashie" gem "highline", require: false +gem "execjs", '~> 2.7', "< 2.8" gem "jwt" gem "kaminari" -gem "mail", git: "https://github.com/mikel/mail.git", branch: "2-7-stable" +gem "mail" gem "moonrope" gem "mysql2" gem "nifty-utils" gem "nilify_blanks" gem "nio4r" gem "puma" -gem "rails", "= 5.2.8.1" +gem "rails", "= 6.1.7.3" gem "resolv", "~> 0.2.1" gem "secure_headers" -gem "sentry-raven" +gem 'sentry-rails' +gem 'sentry-ruby' gem "turbolinks", "~> 5" group :development, :assets do - gem "coffee-rails", "~> 4.2" + gem "coffee-rails", "~> 5.0" gem "jquery-rails" - gem "sass-rails", "~> 5.0" + gem "sass-rails" gem "uglifier", ">= 1.3.0" end diff --git a/Gemfile.lock b/Gemfile.lock index fca59b0..f882cb5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,91 +1,108 @@ -GIT - remote: https://github.com/mikel/mail.git - revision: 873aa3876efb372b9a0bb7319fe60a994cedfd05 - branch: 2-7-stable - specs: - mail (2.7.2.edge) - mini_mime (>= 0.1.1) - GEM remote: https://rubygems.org/ specs: - actioncable (5.2.8.1) - actionpack (= 5.2.8.1) + actioncable (6.1.7.3) + actionpack (= 6.1.7.3) + activesupport (= 6.1.7.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) + actionmailbox (6.1.7.3) + actionpack (= 6.1.7.3) + activejob (= 6.1.7.3) + activerecord (= 6.1.7.3) + activestorage (= 6.1.7.3) + activesupport (= 6.1.7.3) + mail (>= 2.7.1) + actionmailer (6.1.7.3) + actionpack (= 6.1.7.3) + actionview (= 6.1.7.3) + activejob (= 6.1.7.3) + activesupport (= 6.1.7.3) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.8.1) - actionview (= 5.2.8.1) - activesupport (= 5.2.8.1) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.7.3) + actionview (= 6.1.7.3) + activesupport (= 6.1.7.3) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.8.1) - activesupport (= 5.2.8.1) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.7.3) + actionpack (= 6.1.7.3) + activerecord (= 6.1.7.3) + activestorage (= 6.1.7.3) + activesupport (= 6.1.7.3) + nokogiri (>= 1.8.5) + actionview (6.1.7.3) + activesupport (= 6.1.7.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.8.1) - activesupport (= 5.2.8.1) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.7.3) + activesupport (= 6.1.7.3) globalid (>= 0.3.6) - activemodel (5.2.8.1) - activesupport (= 5.2.8.1) - activerecord (5.2.8.1) - activemodel (= 5.2.8.1) - activesupport (= 5.2.8.1) - arel (>= 9.0) - activestorage (5.2.8.1) - actionpack (= 5.2.8.1) - activerecord (= 5.2.8.1) - marcel (~> 1.0.0) - activesupport (5.2.8.1) + activemodel (6.1.7.3) + activesupport (= 6.1.7.3) + activerecord (6.1.7.3) + activemodel (= 6.1.7.3) + activesupport (= 6.1.7.3) + activestorage (6.1.7.3) + actionpack (= 6.1.7.3) + activejob (= 6.1.7.3) + activerecord (= 6.1.7.3) + activesupport (= 6.1.7.3) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.7.3) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - amq-protocol (2.3.0) - annotate (2.7.4) - activerecord (>= 3.2, < 6.0) - rake (>= 10.4, < 13.0) - arel (9.0.0) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + amq-protocol (2.3.2) + annotate (3.2.0) + activerecord (>= 3.2, < 8.0) + rake (>= 10.4, < 14.0) ast (2.4.2) - authie (3.3.1) + authie (3.4.0) secure_random_string - autoprefixer-rails (9.1.3) - execjs + autoprefixer-rails (10.4.13.0) + execjs (~> 2) basic_ssl (1.0.3) - bcrypt (3.1.12) + bcrypt (3.1.18) builder (3.2.4) - bunny (2.14.4) - amq-protocol (~> 2.3, >= 2.3.0) - byebug (10.0.2) - changey (1.0.0) - activerecord (>= 4.2, < 6) + bunny (2.20.3) + amq-protocol (~> 2.3, >= 2.3.1) + sorted_set (~> 1, >= 1.0.2) + byebug (11.1.3) + changey (1.1.0) + activerecord (>= 4.2, < 7) chronic (0.10.2) - clockwork (2.0.3) + clockwork (3.0.2) + activesupport tzinfo - coffee-rails (4.2.2) + coffee-rails (5.0.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0) + railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.2.0) + concurrent-ruby (1.2.2) crass (1.0.6) - database_cleaner (1.7.0) - deep_merge (1.2.1) - diff-lcs (1.3) - dotenv (2.7.6) - dotenv-rails (2.7.6) - dotenv (= 2.7.6) + database_cleaner (2.0.2) + database_cleaner-active_record (>= 2, < 3) + database_cleaner-active_record (2.1.0) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) + date (3.3.3) + deep_merge (1.2.2) + diff-lcs (1.5.0) + dotenv (2.8.1) + dotenv-rails (2.8.1) + dotenv (= 2.8.1) railties (>= 3.2) dynamic_form (1.1.4) encrypto_signo (1.0.0) @@ -96,124 +113,139 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faraday (0.15.2) - multipart-post (>= 1.2, < 3) ffi (1.15.5) - foreman (0.85.0) - thor (~> 0.19.1) - gelf (3.0.0) + foreman (0.87.2) + gelf (3.1.0) json globalid (1.1.0) activesupport (>= 5.0) - haml (5.1.2) - temple (>= 0.8.0) + haml (6.1.1) + temple (>= 0.8.2) + thor tilt - hashie (3.6.0) - highline (2.0.0) + hashie (5.0.0) + highline (2.1.0) i18n (1.12.0) concurrent-ruby (~> 1.0) - jquery-rails (4.3.3) + jquery-rails (4.5.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.5.1) - jwt (2.1.0) - kaminari (1.2.1) + json (2.6.3) + jwt (2.7.0) + kaminari (1.2.2) activesupport (>= 4.1.0) - kaminari-actionview (= 1.2.1) - kaminari-activerecord (= 1.2.1) - kaminari-core (= 1.2.1) - kaminari-actionview (1.2.1) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) actionview - kaminari-core (= 1.2.1) - kaminari-activerecord (1.2.1) + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) activerecord - kaminari-core (= 1.2.1) - kaminari-core (1.2.1) + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (1.0.2) method_source (1.0.0) mini_mime (1.1.2) mini_portile2 (2.8.1) - minitest (5.17.0) + minitest (5.18.0) moonrope (2.0.2) deep_merge (~> 1.0) json rack (>= 1.4) - multipart-post (2.0.0) - mysql2 (0.5.3) + mysql2 (0.5.5) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol nifty-utils (1.1.7) - nilify_blanks (1.3.0) - activerecord (>= 3.0.0) - activesupport (>= 3.0.0) + nilify_blanks (1.4.0) + activerecord (>= 4.0.0) + activesupport (>= 4.0.0) nio4r (2.5.8) nokogiri (1.14.2) mini_portile2 (~> 2.8.0) racc (~> 1.4) + nokogiri (1.14.2-arm64-darwin) + racc (~> 1.4) + nokogiri (1.14.2-x86_64-linux) + racc (~> 1.4) parallel (1.22.1) parser (3.2.1.1) ast (~> 2.4.1) - puma (6.1.0) + puma (6.1.1) nio4r (~> 2.0) racc (1.6.2) rack (2.2.6.4) - rack-test (2.0.2) + rack-test (2.1.0) rack (>= 1.3) - rails (5.2.8.1) - actioncable (= 5.2.8.1) - actionmailer (= 5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) - activemodel (= 5.2.8.1) - activerecord (= 5.2.8.1) - activestorage (= 5.2.8.1) - activesupport (= 5.2.8.1) - bundler (>= 1.3.0) - railties (= 5.2.8.1) + rails (6.1.7.3) + actioncable (= 6.1.7.3) + actionmailbox (= 6.1.7.3) + actionmailer (= 6.1.7.3) + actionpack (= 6.1.7.3) + actiontext (= 6.1.7.3) + actionview (= 6.1.7.3) + activejob (= 6.1.7.3) + activemodel (= 6.1.7.3) + activerecord (= 6.1.7.3) + activestorage (= 6.1.7.3) + activesupport (= 6.1.7.3) + bundler (>= 1.15.0) + railties (= 6.1.7.3) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.5.0) loofah (~> 2.19, >= 2.19.1) - railties (5.2.8.1) - actionpack (= 5.2.8.1) - activesupport (= 5.2.8.1) + railties (6.1.7.3) + actionpack (= 6.1.7.3) + activesupport (= 6.1.7.3) method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + rake (>= 12.2) + thor (~> 1.0) rainbow (3.1.1) - rake (12.3.3) - rb-fsevent (0.10.3) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) + rake (13.0.6) + rbtree (0.4.6) regexp_parser (2.7.0) - resolv (0.2.1) + resolv (0.2.2) rexml (3.2.5) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.1) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.1) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.4) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-rails (3.8.0) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) + rspec-support (~> 3.12.0) + rspec-rails (6.0.1) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.11) + rspec-expectations (~> 3.11) + rspec-mocks (~> 3.11) + rspec-support (~> 3.11) + rspec-support (3.12.0) rubocop (1.48.1) json (~> 2.3) parallel (~> 1.10) @@ -231,50 +263,59 @@ GEM rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) ruby-progressbar (1.13.0) - sass (3.5.7) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - secure_headers (6.3.0) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + secure_headers (6.5.0) secure_random_string (1.0.0) - sentry-raven (2.7.4) - faraday (>= 0.7.6, < 1.0) - sprockets (3.7.2) + sentry-rails (5.8.0) + railties (>= 5.0) + sentry-ruby (~> 5.8.0) + sentry-ruby (5.8.0) + concurrent-ruby (~> 1.0, >= 1.0.2) + set (1.0.3) + sorted_set (1.0.3) + rbtree + set (~> 1.0) + sprockets (4.2.0) concurrent-ruby (~> 1.0) - rack (> 1, < 3) + rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - temple (0.8.2) - thor (0.19.4) - thread_safe (0.3.6) - tilt (2.0.10) - turbolinks (5.2.0) + temple (0.10.0) + thor (1.2.1) + tilt (2.1.0) + timeout (0.3.2) + turbolinks (5.2.1) turbolinks-source (~> 5.2) turbolinks-source (5.2.0) - tzinfo (1.2.11) - thread_safe (~> 0.1) - uglifier (4.1.18) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (2.4.2) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) + zeitwerk (2.6.7) PLATFORMS + arm64-darwin-22 ruby + x86_64-linux DEPENDENCIES annotate - authie (~> 3.0) + authie autoprefixer-rails basic_ssl bcrypt @@ -283,11 +324,12 @@ DEPENDENCIES changey chronic clockwork - coffee-rails (~> 4.2) + coffee-rails (~> 5.0) database_cleaner dotenv-rails dynamic_form encrypto_signo + execjs (~> 2.7, < 2.8) factory_bot_rails (~> 4.0) foreman gelf @@ -297,24 +339,25 @@ DEPENDENCIES jquery-rails jwt kaminari - mail! + mail moonrope mysql2 nifty-utils nilify_blanks nio4r puma - rails (= 5.2.8.1) + rails (= 6.1.7.3) resolv (~> 0.2.1) rspec rspec-rails rubocop rubocop-rails - sass-rails (~> 5.0) + sass-rails secure_headers - sentry-raven + sentry-rails + sentry-ruby turbolinks (~> 5) uglifier (>= 1.3.0) BUNDLED WITH - 2.4.7 + 2.4.9 diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index b16e53d..d41a159 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,3 +1,5 @@ //= link_tree ../images //= link_directory ../javascripts .js //= link_directory ../stylesheets .css +//= link application/application.css +//= link application/application.js diff --git a/app/jobs/unqueue_message_job.rb b/app/jobs/unqueue_message_job.rb index dadfc43..df2af6d 100644 --- a/app/jobs/unqueue_message_job.rb +++ b/app/jobs/unqueue_message_job.rb @@ -424,8 +424,8 @@ class UnqueueMessageJob < Postal::Job e.backtrace.each { |e| log("#{log_prefix} #{e}") } queued_message.retry_later log "#{log_prefix} Queued message was unlocked" - if defined?(Raven) - Raven.capture_exception(e, extra: { job_id: self.id, server_id: queued_message.server_id, message_id: queued_message.message_id }) + if defined?(Sentry) + Sentry.capture_exception(e, extra: { job_id: self.id, server_id: queued_message.server_id, message_id: queued_message.message_id }) end if queued_message.message queued_message.message.create_delivery("Error", details: "An internal error occurred while sending this message. This message will be retried automatically. If this persists, contact support for assistance.", output: "#{e.class}: #{e.message}", log_id: "J-#{self.id}") diff --git a/app/models/address_endpoint.rb b/app/models/address_endpoint.rb index a2609be..d1759ac 100644 --- a/app/models/address_endpoint.rb +++ b/app/models/address_endpoint.rb @@ -19,7 +19,7 @@ class AddressEndpoint < ApplicationRecord has_many :routes, as: :endpoint has_many :additional_route_endpoints, dependent: :destroy, as: :endpoint - validates :address, presence: true, format: { with: /@/ }, uniqueness: { scope: [:server_id], message: "has already been added" } + validates :address, presence: true, format: { with: /@/ }, uniqueness: { scope: [:server_id], message: "has already been added", case_sensitive: false } before_destroy :update_routes diff --git a/app/models/user/authentication.rb b/app/models/concerns/has_authentication.rb similarity index 53% rename from app/models/user/authentication.rb rename to app/models/concerns/has_authentication.rb index 3a9ff87..ec60b11 100644 --- a/app/models/user/authentication.rb +++ b/app/models/concerns/has_authentication.rb @@ -1,22 +1,28 @@ -class User +module HasAuthentication - has_secure_password + extend ActiveSupport::Concern - validates :password, length: { minimum: 8, allow_blank: true } + included do + has_secure_password - when_attribute :password_digest, changes_to: :anything do - before_save do - self.password_reset_token = nil - self.password_reset_token_valid_until = nil + validates :password, length: { minimum: 8, allow_blank: true } + + when_attribute :password_digest, changes_to: :anything do + before_save do + self.password_reset_token = nil + self.password_reset_token_valid_until = nil + end end end - def self.authenticate(email_address, password) - user = where(email_address: email_address).first - raise Postal::Errors::AuthenticationError, "InvalidEmailAddress" if user.nil? - raise Postal::Errors::AuthenticationError, "InvalidPassword" unless user.authenticate(password) + class_methods do + def authenticate(email_address, password) + user = where(email_address: email_address).first + raise Postal::Errors::AuthenticationError, "InvalidEmailAddress" if user.nil? + raise Postal::Errors::AuthenticationError, "InvalidPassword" unless user.authenticate(password) - user + user + end end def authenticate_with_previous_password_first(unencrypted_password) diff --git a/app/models/domain/dns_checks.rb b/app/models/concerns/has_dns_checks.rb similarity index 99% rename from app/models/domain/dns_checks.rb rename to app/models/concerns/has_dns_checks.rb index 07f44a7..920980b 100644 --- a/app/models/domain/dns_checks.rb +++ b/app/models/concerns/has_dns_checks.rb @@ -1,6 +1,6 @@ require "resolv" -class Domain +module HasDNSChecks def dns_ok? spf_status == "OK" && dkim_status == "OK" && ["OK", "Missing"].include?(mx_status) && ["OK", "Missing"].include?(return_path_status) diff --git a/app/models/credential.rb b/app/models/credential.rb index f65b483..1a774c0 100644 --- a/app/models/credential.rb +++ b/app/models/credential.rb @@ -23,7 +23,7 @@ class Credential < ApplicationRecord TYPES = ["SMTP", "API", "SMTP-IP"] - validates :key, presence: true, uniqueness: true + validates :key, presence: true, uniqueness: { case_sensitive: false } validates :type, inclusion: { in: TYPES } validates :name, presence: true validate :validate_key_cannot_be_changed diff --git a/app/models/domain.rb b/app/models/domain.rb index 6bd195a..8c35bc5 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -40,8 +40,7 @@ class Domain < ApplicationRecord include HasUUID - require_dependency "domain/dns_checks" - require_dependency "domain/dns_verification" + include HasDNSChecks VERIFICATION_EMAIL_ALIASES = ["webmaster", "postmaster", "admin", "administrator", "hostmaster"] @@ -52,7 +51,7 @@ class Domain < ApplicationRecord VERIFICATION_METHODS = ["DNS", "Email"] - validates :name, presence: true, format: { with: /\A[a-z0-9\-.]*\z/ }, uniqueness: { scope: [:owner_type, :owner_id], message: "is already added" } + validates :name, presence: true, format: { with: /\A[a-z0-9\-.]*\z/ }, uniqueness: { case_sensitive: false, scope: [:owner_type, :owner_id], message: "is already added" } validates :verification_method, inclusion: { in: VERIFICATION_METHODS } random_string :dkim_identifier_string, type: :chars, length: 6, unique: true, upper_letters_only: true @@ -138,6 +137,22 @@ class Domain < ApplicationRecord @resolver ||= Postal.config.general.use_local_ns_for_domains? ? Resolv::DNS.new : Resolv::DNS.new(nameserver: nameservers) end + def dns_verification_string + "#{Postal.config.dns.domain_verify_prefix} #{verification_token}" + end + + def verify_with_dns + return false unless verification_method == "DNS" + + result = resolver.getresources(name, Resolv::DNS::Resource::IN::TXT) + if result.map { |d| d.data.to_s.strip }.include?(dns_verification_string) + self.verified_at = Time.now + save + else + false + end + end + private def get_nameservers diff --git a/app/models/domain/dns_verification.rb b/app/models/domain/dns_verification.rb deleted file mode 100644 index 957d368..0000000 --- a/app/models/domain/dns_verification.rb +++ /dev/null @@ -1,23 +0,0 @@ -require "resolv" - -class Domain - - def dns_verification_string - "#{Postal.config.dns.domain_verify_prefix} #{verification_token}" - end - - def verify_with_dns - return false unless verification_method == "DNS" - - result = resolver.getresources(name, Resolv::DNS::Resource::IN::TXT) - if result.map { |d| d.data.to_s.strip }.include?(dns_verification_string) - self.verified_at = Time.now - save - else - false - end - end - -end - -# -*- SkipSchemaAnnotations diff --git a/app/models/organization.rb b/app/models/organization.rb index 6e78330..1af7d7d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -31,7 +31,7 @@ class Organization < ApplicationRecord include HasSoftDestroy validates :name, presence: true - validates :permalink, presence: true, format: { with: /\A[a-z0-9-]*\z/ }, uniqueness: true, exclusion: { in: RESERVED_PERMALINKS } + validates :permalink, presence: true, format: { with: /\A[a-z0-9-]*\z/ }, uniqueness: { case_sensitive: false }, exclusion: { in: RESERVED_PERMALINKS } validates :time_zone, presence: true default_value :time_zone, -> { "UTC" } diff --git a/app/models/server.rb b/app/models/server.rb index 88e9a68..506ec48 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -72,9 +72,9 @@ class Server < ApplicationRecord default_value :spam_threshold, -> { Postal.config.general.default_spam_threshold } default_value :spam_failure_threshold, -> { Postal.config.general.default_spam_failure_threshold } - validates :name, presence: true, uniqueness: { scope: :organization_id } + validates :name, presence: true, uniqueness: { scope: :organization_id, case_sensitive: false } validates :mode, inclusion: { in: MODES } - validates :permalink, presence: true, uniqueness: { scope: :organization_id }, format: { with: /\A[a-z0-9-]*\z/ }, exclusion: { in: RESERVED_PERMALINKS } + validates :permalink, presence: true, uniqueness: { scope: :organization_id, case_sensitive: false }, format: { with: /\A[a-z0-9-]*\z/ }, exclusion: { in: RESERVED_PERMALINKS } validate :validate_ip_pool_belongs_to_organization before_validation(on: :create) do diff --git a/app/models/track_domain.rb b/app/models/track_domain.rb index 42b5821..7108a76 100644 --- a/app/models/track_domain.rb +++ b/app/models/track_domain.rb @@ -27,8 +27,8 @@ class TrackDomain < ApplicationRecord belongs_to :server belongs_to :domain - validates :name, presence: true, format: { with: /\A[a-z0-9-]+\z/ }, uniqueness: { scope: :domain_id, message: "is already added" } - validates :domain_id, uniqueness: { scope: :server_id, message: "already has a track domain for this server" } + validates :name, presence: true, format: { with: /\A[a-z0-9-]+\z/ }, uniqueness: { scope: :domain_id, case_sensitive: false, message: "is already added" } + validates :domain_id, uniqueness: { scope: :server_id, case_sensitive: false, message: "already has a track domain for this server" } validate :validate_domain_belongs_to_server scope :ok, -> { where(dns_status: "OK") } diff --git a/app/models/user.rb b/app/models/user.rb index dc86e5c..ce111d1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -27,11 +27,11 @@ class User < ApplicationRecord include HasUUID - require_dependency "user/authentication" + include HasAuthentication validates :first_name, presence: true validates :last_name, presence: true - validates :email_address, presence: true, uniqueness: true, format: { with: /@/, allow_blank: true } + validates :email_address, presence: true, uniqueness: { case_sensitive: false }, format: { with: /@/, allow_blank: true } validates :time_zone, presence: true default_value :time_zone, -> { "UTC" } diff --git a/app/models/user_invite.rb b/app/models/user_invite.rb index 4db0863..35230df 100644 --- a/app/models/user_invite.rb +++ b/app/models/user_invite.rb @@ -18,7 +18,7 @@ class UserInvite < ApplicationRecord include HasUUID - validates :email_address, presence: true, uniqueness: true, format: { with: /@/, allow_blank: true } + validates :email_address, presence: true, uniqueness: { case_sensitive: false }, format: { with: /@/, allow_blank: true } has_many :organization_users, dependent: :destroy, as: :user has_many :organizations, through: :organization_users diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1d2e164..7176ef4 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -58,4 +58,3 @@ Powered by #{link_to "Postal", "https://postalserver.io", target: '_blank'} #{Postal.version}. %li= link_to "Documentation", "https://docs.postalserver.io", target: '_blank' %li= link_to "Ask for help", "https://discussions.postalserver.io", target: '_blank' - diff --git a/config/application.rb b/config/application.rb index 46daf09..bfb2c61 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,6 +15,8 @@ Bundler.require(*Rails.groups) module Postal class Application < Rails::Application + config.load_defaults 6.0 + # Disable most generators config.generators do |g| g.orm :active_record @@ -36,5 +38,7 @@ module Postal config.logger = Postal.logger_for(:rails) + config.hosts << Postal.config.web.host + end end diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index 36aad0a..22b6731 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -1,14 +1,7 @@ require "postal/config" if Postal.config.general&.exception_url - require "raven" - Raven.configure do |config| + Sentry.init do |config| config.dsn = Postal.config.general.exception_url - config.environments = ["production"] - if ENV["DEV_EXCEPTIONS"] - config.environments << "development" - end - config.silence_ready = true - config.tags = { process: ENV.fetch("PROC_NAME", nil) } end end diff --git a/lib/postal/message_parser.rb b/lib/postal/message_parser.rb index 06abf20..956e19f 100644 --- a/lib/postal/message_parser.rb +++ b/lib/postal/message_parser.rb @@ -50,8 +50,8 @@ module Postal rescue StandardError => e raise if Rails.env.development? - if defined?(Raven) - Raven.capture_exception(e) + if defined?(Sentry) + Sentry.capture_exception(e) end @actioned = false @tracked_links = 0 diff --git a/lib/postal/smtp_sender.rb b/lib/postal/smtp_sender.rb index 93846c9..bd6121d 100644 --- a/lib/postal/smtp_sender.rb +++ b/lib/postal/smtp_sender.rb @@ -197,8 +197,8 @@ module Postal safe_rset rescue StandardError => e log "#{e.class}: #{e.message}" - if defined?(Raven) - Raven.capture_exception(e, extra: { log_id: @log_id, server_id: message.server.id, message_id: message.id }) + if defined?(Sentry) + Sentry.capture_exception(e, extra: { log_id: @log_id, server_id: message.server.id, message_id: message.id }) end result.type = "SoftFail" result.retry = true diff --git a/lib/postal/smtp_server/server.rb b/lib/postal/smtp_server/server.rb index 94a830a..5aae3fb 100644 --- a/lib/postal/smtp_server/server.rb +++ b/lib/postal/smtp_server/server.rb @@ -113,8 +113,8 @@ module Postal monitor.value = client rescue StandardError => e # If something goes wrong, log as appropriate and disconnect the client - if defined?(Raven) - Raven.capture_exception(e, extra: { log_id: begin + if defined?(Sentry) + Sentry.capture_exception(e, extra: { log_id: begin client.id rescue StandardError nil @@ -227,8 +227,8 @@ module Postal rescue StandardError => e # Something went wrong, log as appropriate client_id = client ? client.id : "------" - if defined?(Raven) - Raven.capture_exception(e, extra: { log_id: begin + if defined?(Sentry) + Sentry.capture_exception(e, extra: { log_id: begin client.id rescue StandardError nil diff --git a/lib/postal/tracking_middleware.rb b/lib/postal/tracking_middleware.rb index b02bc6c..3386b58 100644 --- a/lib/postal/tracking_middleware.rb +++ b/lib/postal/tracking_middleware.rb @@ -44,7 +44,7 @@ module Postal rescue StandardError => e # Somethign else went wrong. We don't want to stop the image loading though because # this is our problem. Log this exception though. - Raven.capture_exception(e) if defined?(Raven) + Sentry.capture_exception(e) if defined?(Sentry) end source_image = request.params["src"] diff --git a/lib/postal/worker.rb b/lib/postal/worker.rb index 96b86fd..e738841 100644 --- a/lib/postal/worker.rb +++ b/lib/postal/worker.rb @@ -69,8 +69,8 @@ module Postal e.backtrace.each do |line| logger.warn "[#{message['id']}] " + line end - if defined?(Raven) - Raven.capture_exception(e, extra: { job_id: message["id"] }) + if defined?(Sentry) + Sentry.capture_exception(e, extra: { job_id: message["id"] }) end ensure logger.info "[#{message['id']}] Finished processing \e[34m#{message['class_name']}\e[0m job in #{Time.now - start_time}s"