OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add settings for AV
Oliver Güntherae99133a3e4d
diff --git a/app/controllers/admin/settings/attachments_settings_controller.rb b/app/controllers/admin/settings/attachments_settings_controller.rbindex 98633cee7f9..b5e20af8811 100644--- a/app/controllers/admin/settings/attachments_settings_controller.rb+++ b/app/controllers/admin/settings/attachments_settings_controller.rb@@ -34,6 +34,18 @@ module Admin::Settingst(:'attributes.attachments')end+ def av_form+ selected = params.dig(:settings, :antivirus_scan_mode)&.to_sym || :disabled++ respond_to do |format|+ format.turbo_stream do+ render turbo_stream: turbo_stream.replace(:attachments_av_subform,+ partial: "admin/settings/attachments_settings/av_form",+ locals: { selected: })+ end+ end+ end+privatedef settings_paramsdiff --git a/app/views/admin/settings/attachments_settings/_av_form.html.erb b/app/views/admin/settings/attachments_settings/_av_form.html.erbnew file mode 100644index 00000000000..683f01ec5a4--- /dev/null+++ b/app/views/admin/settings/attachments_settings/_av_form.html.erb@@ -0,0 +1,40 @@+<turbo-frame id="attachments_av_subform">+ <% if selected == :clamav_socket %>+ <div class="form--field">+ <%= setting_text_field :antivirus_scan_target, container_class: '-wide', not_translated_label: 'ClamAV (Socket)' %>+ <div class="form--field-instructions">+ <p><%= t('settings.antivirus.modes.clamav_socket_html',+ example: content_tag(:code, '/var/run/clamav/clamd.ctl'),+ ) %>+ </p>+ </div>+ </div>+ <% elsif selected == :clamav_host %>+ <div class="form--field">+ <%= setting_text_field :antivirus_scan_target, container_class: '-wide', not_translated_label: 'ClamAV (Host)' %>+ <div class="form--field-instructions">+ <p><%= t('settings.antivirus.modes.clamav_host_html',+ example: content_tag(:code, 'remotehost:1024'),+ ) %>+ </p>+ </div>+ </div>+ <% end %>+ <div class="form--field">+ <%= setting_select :antivirus_scan_action,+ [+ [t('settings.antivirus.actions.log'), :log],+ [t('settings.antivirus.actions.quarantine'), :quarantine],+ [t('settings.antivirus.actions.delete'), :delete],+ ],+ container_class: '-wide'+ %>+ <div class="form--field-instructions">+ <p><%= t('settings.antivirus.actions.instructions_html',+ log_option: t('settings.antivirus.actions.log'),+ quarantine_option: t('settings.antivirus.actions.quarantine'),+ delete_option: t('settings.antivirus.actions.delete')+ ) %></p>+ </div>+ </div>+</turbo-frame>diff --git a/app/views/admin/settings/attachments_settings/show.html.erb b/app/views/admin/settings/attachments_settings/show.html.erbindex 478d0cf5d5d..3a650a42cde 100644--- a/app/views/admin/settings/attachments_settings/show.html.erb+++ b/app/views/admin/settings/attachments_settings/show.html.erb@@ -28,7 +28,15 @@ See COPYRIGHT and LICENSE files for more details.++#%><%= toolbar title: t(:'attributes.attachments') %>-<%= styled_form_tag(admin_settings_update_attachments_path, method: :patch) do %>+<%= styled_form_tag(+ admin_settings_update_attachments_path,+ method: :patch,+ data: {+ 'controller': 'refresh-on-form-changes',+ 'refresh-on-form-changes-target': 'form',+ 'refresh-on-form-changes-turbo-stream-url-value': url_for(action: 'av_form')+ }+ ) do %><section class="form--section"><div class="form--field"><%= setting_text_field :attachment_max_size, size: 6, unit: t(:"number.human.storage_units.units.kb"), container_class: '-slim' %>@@ -39,10 +47,34 @@ See COPYRIGHT and LICENSE files for more details.<%= t('settings.attachments.whitelist_text_html',ext_example: '*.jpg',mime_example: 'image/jpeg',- ) %>+ ) %></div></div></section>+ <fieldset class="form--fieldset">+ <legend class="form--fieldset-legend"><%= t('settings.antivirus.title') %></legend>+ <div class="form--field">+ <%= setting_select :antivirus_scan_mode,+ [+ [t(:label_disabled), :disabled],+ ['ClamAV (Socket)', :clamav_socket],+ ['ClamAV (Host)', :clamav_host],+ ],+ container_class: '-wide',+ data: {+ action: 'refresh-on-form-changes#triggerTurboStream'+ }+ %>+ <div class="form--field-instructions">+ <p><%= t('settings.antivirus.modes.description_html',+ disabled_option: t(:label_disabled),+ socket_option: 'ClamAV (Socket)',+ host_option: 'ClamAV (Host)',+ ) %></p>+ </div>+ </div>+ <%= render partial: 'av_form', locals: { selected: Setting.antivirus_scan_mode } %>+ </fieldset><%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %><% end %>diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 0c278d7fdd3..a56fe708878 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -92,6 +92,23 @@ module Settingsdescription: 'Time in minutes to wait before uploaded files not attached to any container are removed',default: 180},+ antivirus_scan_mode: {+ description: 'Virus scanning option for files uploaded to OpenProject',+ format: :symbol,+ default: :disabled,+ allowed: %i[disabled clamav_socket clamav_host]+ },+ antivirus_scan_target: {+ description: 'The socket or hostname to connect to ClamAV',+ format: :string,+ default: nil+ },+ antivirus_scan_action: {+ description: 'Virus scanning action for found infected files',+ format: :symbol,+ default: :quarantine,+ allowed: %i[log quarantine delete]+ },auth_source_sso: {description: 'Configuration for Header-based Single Sign-On',format: :hash,diff --git a/config/locales/en.yml b/config/locales/en.ymlindex bfca26aeffa..93b45579f08 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2874,6 +2874,8 @@ en:setting_app_subtitle: "Application subtitle"setting_app_title: "Application title"setting_attachment_max_size: "Attachment max. size"+ setting_antivirus_scan_mode: "Scan mode"+ setting_antivirus_scan_action: "Infected file action"setting_autofetch_changesets: "Autofetch repository changes"setting_autologin: "Autologin"setting_available_languages: "Available languages"@@ -2979,6 +2981,31 @@ en:<br/>Leave empty to allow any file type to be uploaded.Multiple values allowed (one line for each value).+ antivirus:+ title: "Virus scanning"+ actions:+ log: 'Log only'+ delete: 'Delete the file'+ quarantine: 'Quarantine the file'+ instructions_html: >+ Select the action to perform for files on which a virus has been detected:+ <br/>+ <ul>+ <li><strong>%{log_option}</strong>: Log the found virus, but do not block access to the file.</li>+ <li><strong>%{quarantine_option}</strong>: Quarantine the file, preventing users from accessing it. Administrators can manually override the decision or delete the file in the administration.</li>+ <li><strong>%{delete_option}</strong>: Delete the file immediately.</li>+ </ul>+ modes:+ clamav_socket_html: Enter the socket to the clamd daemon, e.g., %{example}+ clamav_host_html: Enter the hostname and port to the clamd daemon separated by colon. e.g., %{example}+ description_html: >+ Select the mode in which the antivirus scanner integration should operate.+ <br/>+ <ul>+ <li><strong>%{disabled_option}</strong>: Uploaded files are not scanned for viruses.</li>+ <li><strong>%{socket_option}</strong>: You have set up ClamAV on the same server as OpenProject and the scan daemon clamd is running in the background</li>+ <li><strong>%{host_option}</strong>: You are streaming files to an external virus scanning host.</li>+ </ul>brute_force_prevention: "Automated user blocking"date_format:first_date_of_week_and_year_set: >diff --git a/config/routes.rb b/config/routes.rbindex 11de0c2a584..0d041130771 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -422,6 +422,8 @@ Rails.application.routes.draw dopatch tab[:name], controller: tab[:controller], action: :update, as: "update_#{tab[:name]}"end+ get 'attachments/av_form', controller: '/admin/settings/attachments_settings', action: 'av_form'+resource :authentication, controller: '/admin/settings/authentication_settings', only: %i[show update]resource :incoming_mails, controller: '/admin/settings/incoming_mails_settings', only: %i[show update]resource :aggregation, controller: '/admin/settings/aggregation_settings', only: %i[show update]