مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-11-30 21:32:30 +00:00
feat: new configuration system (and schema) (#2819)
هذا الالتزام موجود في:
@@ -1,24 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require File.expand_path("../lib/postal/config", __dir__)
|
||||
require "openssl"
|
||||
require "securerandom"
|
||||
require "fileutils"
|
||||
|
||||
unless File.directory?(Postal.config_root)
|
||||
FileUtils.mkdir_p(Postal.config_root)
|
||||
end
|
||||
|
||||
unless File.exist?(Postal.config_file_path)
|
||||
content = File.read(Postal.app_root.join("config", "postal.example.yml"))
|
||||
content.gsub!("{{secretkey}}", SecureRandom.hex(128))
|
||||
File.write(Postal.config_file_path, content)
|
||||
puts "Created example config file at #{Postal.config_file_path}"
|
||||
end
|
||||
|
||||
unless File.exist?(Postal.signing_key_path)
|
||||
key = OpenSSL::PKey::RSA.new(1024).to_s
|
||||
File.write(Postal.signing_key_path, key)
|
||||
puts "Created new signing key for DKIM & HTTP requests"
|
||||
end
|
||||
@@ -3,21 +3,24 @@
|
||||
require File.expand_path("../lib/postal/config", __dir__)
|
||||
require "openssl"
|
||||
|
||||
unless File.exist?(Postal.smtp_private_key_path)
|
||||
key_path = Postal::Config.smtp_server.tls_private_key_path
|
||||
cert_path = Postal::Config.smtp_server.tls_certificate_path
|
||||
|
||||
unless File.exist?(key_path)
|
||||
key = OpenSSL::PKey::RSA.new(2048).to_s
|
||||
File.write(Postal.smtp_private_key_path, key)
|
||||
puts "Created new private key for encrypting SMTP connections"
|
||||
File.write(key_path, key)
|
||||
puts "Created new private key for encrypting SMTP connections at #{key_path}"
|
||||
end
|
||||
|
||||
unless File.exist?(Postal.smtp_certificate_path)
|
||||
unless File.exist?(cert_path)
|
||||
cert = OpenSSL::X509::Certificate.new
|
||||
cert.subject = cert.issuer = OpenSSL::X509::Name.parse("/C=GB/O=Test/OU=Test/CN=Test")
|
||||
cert.not_before = Time.now
|
||||
cert.not_after = Time.now + (365 * 24 * 60 * 60)
|
||||
cert.public_key = Postal.smtp_private_key.public_key
|
||||
cert.public_key = SMTPServer::Server.tls_private_key.public_key
|
||||
cert.serial = 0x0
|
||||
cert.version = 2
|
||||
cert.sign Postal.smtp_private_key, OpenSSL::Digest.new("SHA256")
|
||||
File.write(Postal.smtp_certificate_path, cert.to_pem)
|
||||
puts "Created new self signed certificate for encrypting SMTP connections"
|
||||
cert.sign SMTPServer::Server.tls_private_key, OpenSSL::Digest.new("SHA256")
|
||||
File.write(cert_path, cert.to_pem)
|
||||
puts "Created new self signed certificate for encrypting SMTP connections at #{cert_path}"
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@ end
|
||||
|
||||
message = server.message_db.new_message
|
||||
message.scope = "incoming"
|
||||
message.rcpt_to = "#{server.token}@#{Postal.config.dns.return_path}"
|
||||
message.rcpt_to = "#{server.token}@#{Postal::Config.dns.return_path_domain}"
|
||||
message.mail_from = "MAILER-DAEMON@smtp.infra.atech.io"
|
||||
message.raw_message = template
|
||||
message.bounce = true
|
||||
|
||||
@@ -5,11 +5,11 @@ require_relative "../lib/postal/config"
|
||||
require "mysql2"
|
||||
|
||||
client = Mysql2::Client.new(
|
||||
host: Postal.config.main_db.host,
|
||||
username: Postal.config.main_db.username,
|
||||
password: Postal.config.main_db.password,
|
||||
port: Postal.config.main_db.port,
|
||||
database: Postal.config.main_db.database
|
||||
host: Postal::Config.main_db.host,
|
||||
username: Postal::Config.main_db.username,
|
||||
password: Postal::Config.main_db.password,
|
||||
port: Postal::Config.main_db.port,
|
||||
database: Postal::Config.main_db.database
|
||||
)
|
||||
result = client.query("SELECT COUNT(id) as size FROM `queued_messages` WHERE retry_after IS NULL OR " \
|
||||
"retry_after <= ADDTIME(UTC_TIMESTAMP(), '30') AND locked_at IS NULL")
|
||||
|
||||
@@ -5,5 +5,9 @@ $stderr.sync = true
|
||||
|
||||
require_relative "../config/environment"
|
||||
|
||||
HealthServer.start(name: "smtp-server", default_port: 9091)
|
||||
HealthServer.start(
|
||||
name: "smtp-server",
|
||||
default_port: Postal::Config.smtp_server.default_health_server_port,
|
||||
default_bind_address: Postal::Config.smtp_server.default_health_server_bind_address
|
||||
)
|
||||
SMTPServer::Server.new(debug: true).run
|
||||
|
||||
@@ -25,9 +25,9 @@ rescue StandardError => e
|
||||
puts "\e[31mMessage was not delivered successfully to SMTP server.\e[0m"
|
||||
puts "Error: #{e.class} (#{e.message})"
|
||||
puts
|
||||
puts " SMTP Host: #{Postal.config.smtp.host}"
|
||||
puts " SMTP Port: #{Postal.config.smtp.port}"
|
||||
puts " SMTP Username: #{Postal.config.smtp.username}"
|
||||
puts " SMTP Password: #{Postal.config.smtp.password}"
|
||||
puts " SMTP Host: #{Postal::Config.smtp.host}"
|
||||
puts " SMTP Port: #{Postal::Config.smtp.port}"
|
||||
puts " SMTP Username: #{Postal::Config.smtp.username}"
|
||||
puts " SMTP Password: #{Postal::Config.smtp.password}"
|
||||
puts
|
||||
end
|
||||
|
||||
@@ -6,5 +6,10 @@ $stderr.sync = true
|
||||
|
||||
require_relative "../config/environment"
|
||||
|
||||
HealthServer.start(name: "worker", default_port: 9090)
|
||||
HealthServer.start(
|
||||
name: "worker",
|
||||
default_port: Postal::Config.worker.default_health_server_port,
|
||||
default_bind_address: Postal::Config.worker.default_health_server_bind_address
|
||||
)
|
||||
|
||||
Worker::Process.new.run
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم