2025-07-18 17:36:37 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2011-05-29 13:11:52 -07:00
|
|
|
#-- copyright
|
2020-01-15 11:31:26 +01:00
|
|
|
# OpenProject is an open source project management software.
|
2024-07-30 13:42:36 +02:00
|
|
|
# Copyright (C) the OpenProject GmbH
|
2011-05-30 20:52:25 +02:00
|
|
|
#
|
2011-05-29 13:11:52 -07:00
|
|
|
# This program is free software; you can redistribute it and/or
|
2013-06-05 16:27:56 +02:00
|
|
|
# modify it under the terms of the GNU General Public License version 3.
|
2011-05-30 20:52:25 +02:00
|
|
|
#
|
2013-09-16 17:59:31 +02:00
|
|
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
2021-01-13 17:47:45 +01:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2013-09-16 17:59:31 +02:00
|
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
#
|
2021-09-02 21:49:06 +02:00
|
|
|
# See COPYRIGHT and LICENSE files for more details.
|
2011-05-29 13:11:52 -07:00
|
|
|
#++
|
2020-11-24 14:35:40 +01:00
|
|
|
require "open3"
|
2011-05-29 13:11:52 -07:00
|
|
|
|
2007-03-12 17:59:02 +00:00
|
|
|
class AdminController < ApplicationController
|
2009-12-17 18:21:02 +00:00
|
|
|
layout "admin"
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2021-02-01 10:45:13 +01:00
|
|
|
before_action :require_admin, except: %i[index]
|
|
|
|
|
before_action :authorize_global, only: %i[index]
|
2026-03-09 12:27:54 +00:00
|
|
|
before_action :validate_smtp_settings, only: %i[test_email]
|
2007-03-12 17:59:02 +00:00
|
|
|
|
2014-11-03 21:10:20 +01:00
|
|
|
menu_item :plugins, only: [:plugins]
|
|
|
|
|
menu_item :info, only: [:info]
|
2019-07-04 13:43:21 +02:00
|
|
|
menu_item :admin_overview, only: [:index]
|
2011-10-07 17:09:45 +02:00
|
|
|
|
2008-01-05 11:33:49 +00:00
|
|
|
def index
|
2022-04-22 11:16:59 +02:00
|
|
|
@menu_nodes = Redmine::MenuManager.items(:admin_menu).children.reject do |node|
|
|
|
|
|
name = node.name
|
|
|
|
|
condition = node.condition
|
|
|
|
|
|
|
|
|
|
name === :admin_overview ||
|
2025-01-16 14:13:35 +01:00
|
|
|
(condition && !condition.call(nil)) ||
|
2022-04-22 11:16:59 +02:00
|
|
|
hidden_admin_menu_items.include?(name.to_s)
|
|
|
|
|
end
|
2021-02-01 10:45:13 +01:00
|
|
|
|
|
|
|
|
if @menu_nodes.count == 1
|
|
|
|
|
redirect_to @menu_nodes.first.url
|
|
|
|
|
end
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-03-12 17:59:02 +00:00
|
|
|
def projects
|
2017-10-11 15:35:41 +02:00
|
|
|
redirect_to controller: "projects", action: "index"
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2008-11-16 11:58:41 +00:00
|
|
|
def plugins
|
2024-03-13 09:26:22 +01:00
|
|
|
@plugins = Redmine::Plugin.not_bundled.sort
|
2008-11-16 11:58:41 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2025-07-24 16:02:40 +02:00
|
|
|
def test_email # rubocop:disable Metrics/AbcSize
|
2007-08-14 10:36:19 +00:00
|
|
|
raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
|
|
|
|
|
# Force ActionMailer to raise delivery errors so we can catch it
|
|
|
|
|
ActionMailer::Base.raise_delivery_errors = true
|
|
|
|
|
begin
|
2026-03-09 12:27:54 +00:00
|
|
|
delivery_method_options = {}
|
|
|
|
|
|
|
|
|
|
if validated_smtp_settings?
|
2026-03-09 13:30:51 +00:00
|
|
|
delivery_method_options[:address] = @safe_ip.to_s
|
|
|
|
|
delivery_method_options[:tls_hostname] = @smtp_addr
|
2026-03-09 12:27:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@test = UserMailer.test_mail(User.current, delivery_method_options:).deliver_now
|
2018-08-16 08:50:08 +02:00
|
|
|
flash[:notice] = I18n.t(:notice_email_sent, value: User.current.mail)
|
2021-02-11 16:02:18 +01:00
|
|
|
rescue StandardError => e
|
2018-08-16 08:50:08 +02:00
|
|
|
flash[:error] = I18n.t(:notice_email_error, value: Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup))
|
2007-08-14 10:36:19 +00:00
|
|
|
end
|
|
|
|
|
ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
|
2025-07-24 16:02:40 +02:00
|
|
|
redirect_to admin_settings_mail_notifications_path, status: :see_other
|
2007-08-14 10:36:19 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-03-12 17:59:02 +00:00
|
|
|
def info
|
2021-02-16 13:46:27 +01:00
|
|
|
@db_version = OpenProject::Database.version
|
2009-12-19 20:33:24 +00:00
|
|
|
@checklist = [
|
2013-08-05 10:22:27 +02:00
|
|
|
[:text_default_administrator_account_changed, User.default_admin_account_changed?],
|
2018-02-15 17:31:51 +01:00
|
|
|
[:text_database_allows_tsv, OpenProject::Database.allows_tsv?]
|
2009-12-19 20:33:24 +00:00
|
|
|
]
|
2015-08-18 17:51:34 +02:00
|
|
|
|
2020-01-22 14:03:41 +01:00
|
|
|
@checklist += file_storage_checks
|
|
|
|
|
@checklist += plaintext_extraction_checks
|
|
|
|
|
@checklist += admin_information_hook_checks
|
2020-11-24 14:35:40 +01:00
|
|
|
@checklist += image_conversion_checks
|
2024-09-17 19:34:00 +03:00
|
|
|
@checklist += jemalloc_active_checks
|
2019-11-06 16:22:27 +01:00
|
|
|
|
2015-08-18 17:51:34 +02:00
|
|
|
@storage_information = OpenProject::Storage.mount_information
|
2011-05-30 20:52:25 +02:00
|
|
|
end
|
2012-02-14 14:13:24 +01:00
|
|
|
|
2018-02-15 18:37:09 +01:00
|
|
|
private
|
|
|
|
|
|
2026-03-09 12:27:54 +00:00
|
|
|
##
|
|
|
|
|
# When using SMTP, we make sure the used address is safe to use, preventing SSRF attacks.
|
|
|
|
|
# This does not apply when sendmail is used.
|
|
|
|
|
def validate_smtp_settings
|
|
|
|
|
return unless using_smtp?
|
2026-02-25 15:32:56 +00:00
|
|
|
|
2026-03-09 12:27:54 +00:00
|
|
|
@smtp_addr = ActionMailer::Base.smtp_settings[:address]
|
|
|
|
|
@safe_ip = OpenProject::SsrfProtection.safe_ip?(@smtp_addr)
|
|
|
|
|
|
2026-03-17 13:43:31 +01:00
|
|
|
unless @safe_ip
|
|
|
|
|
flash[:error] = I18n.t :notice_smtp_address_unsafe_env_hint,
|
|
|
|
|
address: @smtp_addr,
|
|
|
|
|
env_name: Settings::Definition[:ssrf_protection_ip_allowlist].env_name
|
2026-02-25 15:32:56 +00:00
|
|
|
|
|
|
|
|
redirect_to admin_settings_mail_notifications_path, status: :see_other
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2026-03-09 12:27:54 +00:00
|
|
|
def validated_smtp_settings?
|
|
|
|
|
@smtp_addr.present? && @safe_ip.present?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def using_smtp?
|
|
|
|
|
ActionMailer::Base.delivery_method == :smtp
|
|
|
|
|
end
|
|
|
|
|
|
2022-04-22 11:16:59 +02:00
|
|
|
def hidden_admin_menu_items
|
2024-01-04 17:01:17 +01:00
|
|
|
OpenProject::Configuration.hidden_menu_items[:admin_menu.to_s] || []
|
2022-04-22 11:16:59 +02:00
|
|
|
end
|
|
|
|
|
|
2018-02-15 18:37:09 +01:00
|
|
|
def plaintext_extraction_checks
|
2020-01-22 14:03:41 +01:00
|
|
|
if OpenProject::Database.allows_tsv?
|
|
|
|
|
[
|
|
|
|
|
[:"extraction.available.pdftotext", Plaintext::PdfHandler.available?],
|
2022-04-22 11:16:59 +02:00
|
|
|
[:"extraction.available.unrtf", Plaintext::RtfHandler.available?],
|
|
|
|
|
[:"extraction.available.catdoc", Plaintext::DocHandler.available?],
|
|
|
|
|
[:"extraction.available.xls2csv", Plaintext::XlsHandler.available?],
|
|
|
|
|
[:"extraction.available.catppt", Plaintext::PptHandler.available?],
|
2020-01-22 14:03:41 +01:00
|
|
|
[:"extraction.available.tesseract", Plaintext::ImageHandler.available?]
|
|
|
|
|
]
|
|
|
|
|
else
|
|
|
|
|
[]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-11-24 14:35:40 +01:00
|
|
|
def image_conversion_checks
|
|
|
|
|
[[:"image_conversion.imagemagick", image_conversion_libs_available?]]
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-17 19:34:00 +03:00
|
|
|
def jemalloc_active_checks
|
|
|
|
|
[[:"admin.jemalloc_allocator", jemalloc_libs_active?]]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def jemalloc_libs_active?
|
2024-09-17 21:23:14 +03:00
|
|
|
Open3.capture2e({ "MALLOC_CONF" => "true" }, "ruby", "-e", "exit").first.include?("jemalloc")
|
2024-09-17 19:34:00 +03:00
|
|
|
rescue StandardError
|
|
|
|
|
false
|
|
|
|
|
end
|
2024-09-17 20:25:27 +03:00
|
|
|
|
2020-11-24 14:35:40 +01:00
|
|
|
def image_conversion_libs_available?
|
|
|
|
|
Open3.capture2e("convert", "-version").first.include?("ImageMagick")
|
2021-02-11 16:02:18 +01:00
|
|
|
rescue StandardError
|
2021-01-09 19:52:19 +00:00
|
|
|
false
|
2020-11-24 14:35:40 +01:00
|
|
|
end
|
|
|
|
|
|
2020-01-22 14:03:41 +01:00
|
|
|
def file_storage_checks
|
|
|
|
|
# Add local directory test if we're not using fog
|
|
|
|
|
if OpenProject::Configuration.file_storage?
|
|
|
|
|
repository_writable = File.writable?(OpenProject::Configuration.attachments_storage_path)
|
|
|
|
|
[[:text_file_repository_writable, repository_writable]]
|
|
|
|
|
else
|
|
|
|
|
[]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def admin_information_hook_checks
|
2020-01-22 14:31:53 +01:00
|
|
|
call_hook(:admin_information_checklist).flat_map do |result|
|
2020-01-22 14:03:41 +01:00
|
|
|
result
|
2020-01-22 14:31:53 +01:00
|
|
|
end
|
2018-02-15 18:37:09 +01:00
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|