Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

186 lines
5.9 KiB
Ruby
Raw Permalink Normal View History

2025-07-18 17:36:37 +01:00
# frozen_string_literal: true
#-- copyright
2020-01-15 11:31:26 +01:00
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
2011-05-30 20:52:25 +02:00
#
# This program is free software; you can redistribute it and/or
# 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.
#
# See COPYRIGHT and LICENSE files for more details.
#++
require "open3"
class AdminController < ApplicationController
layout "admin"
2011-05-30 20:52:25 +02:00
before_action :require_admin, except: %i[index]
before_action :authorize_global, only: %i[index]
before_action :validate_smtp_settings, only: %i[test_email]
2014-11-03 21:10:20 +01:00
menu_item :plugins, only: [:plugins]
menu_item :info, only: [:info]
menu_item :admin_overview, only: [:index]
2011-10-07 17:09:45 +02: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 ||
(condition && !condition.call(nil)) ||
2022-04-22 11:16:59 +02:00
hidden_admin_menu_items.include?(name.to_s)
end
if @menu_nodes.count == 1
redirect_to @menu_nodes.first.url
end
end
2011-05-30 20:52:25 +02:00
def projects
redirect_to controller: "projects", action: "index"
end
2011-05-30 20:52:25 +02:00
def plugins
2024-03-13 09:26:22 +01:00
@plugins = Redmine::Plugin.not_bundled.sort
end
2011-05-30 20:52:25 +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
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
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
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
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?],
[:text_database_allows_tsv, OpenProject::Database.allows_tsv?]
2009-12-19 20:33:24 +00:00
]
2020-01-22 14:03:41 +01:00
@checklist += file_storage_checks
@checklist += plaintext_extraction_checks
@checklist += admin_information_hook_checks
@checklist += image_conversion_checks
2024-09-17 19:34:00 +03:00
@checklist += jemalloc_active_checks
2019-11-06 16:22:27 +01:00
@storage_information = OpenProject::Storage.mount_information
2011-05-30 20:52:25 +02:00
end
2018-02-15 18:37:09 +01:00
private
##
# 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?
@smtp_addr = ActionMailer::Base.smtp_settings[:address]
@safe_ip = OpenProject::SsrfProtection.safe_ip?(@smtp_addr)
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
redirect_to admin_settings_mail_notifications_path, status: :see_other
end
end
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
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
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
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