diff --git a/imageroot/actions/get-configuration/20read b/imageroot/actions/get-configuration/20read index 902fcef..677099b 100755 --- a/imageroot/actions/get-configuration/20read +++ b/imageroot/actions/get-configuration/20read @@ -43,5 +43,11 @@ is_found_auditor = "$1$SLIIIS$JMBwGqQg4lIir2P2YU1y.0" in output.stdout config['is_default_password'] = True if is_found_admin or is_found_auditor else False +import_running = subprocess.run(['systemctl', '--user', 'is-active', "import-email-to-piler.service"], capture_output=True, text=True) +config['import_email_is_running'] = True if import_running.stdout.strip() == 'active' else False + +piler_running = subprocess.run(['systemctl', '--user', 'is-active', "piler-app.service"], capture_output=True, text=True) +config['piler_is_running'] = True if piler_running.stdout.strip() == 'active' else False + # Dump the configuratio to stdout json.dump(config, fp=sys.stdout) diff --git a/imageroot/actions/get-configuration/validate-output.json b/imageroot/actions/get-configuration/validate-output.json index c226e2e..1c09a2a 100644 --- a/imageroot/actions/get-configuration/validate-output.json +++ b/imageroot/actions/get-configuration/validate-output.json @@ -9,7 +9,9 @@ "http2https": true, "lets_encrypt": true, "mail_server": "xxxxxxxxxxxxxxxxxxxxxxxxx", - "is_default_password": false + "is_default_password": false, + "import_email_is_running": false, + "piler_is_running": true } ], "type": "object", @@ -18,7 +20,9 @@ "http2https", "lets_encrypt", "mail_server", - "is_default_password" + "is_default_password", + "import_email_is_running", + "piler_is_running" ], "properties": { "host": { @@ -45,6 +49,16 @@ "type": "boolean", "title": "Default password", "description": "True if the password is the default one" + }, + "import_email_is_running": { + "type": "boolean", + "title": "Import email is running", + "description": "True if the import email is running" + }, + "piler_is_running": { + "type": "boolean", + "title": "Piler is running", + "description": "True if the piler is running" } } } diff --git a/imageroot/actions/import-email-to-piler/50start b/imageroot/actions/import-email-to-piler/50start new file mode 100755 index 0000000..b16c071 --- /dev/null +++ b/imageroot/actions/import-email-to-piler/50start @@ -0,0 +1,10 @@ +#!/bin/bash + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +# If the control reaches this step, the service can be enabled and started + +systemctl --user start import-email-to-piler.service \ No newline at end of file diff --git a/imageroot/actions/restore-module/40restoreDB b/imageroot/actions/restore-module/40restoreDB old mode 100644 new mode 100755 diff --git a/imageroot/systemd/user/import-email-to-piler.service b/imageroot/systemd/user/import-email-to-piler.service new file mode 100644 index 0000000..6756f34 --- /dev/null +++ b/imageroot/systemd/user/import-email-to-piler.service @@ -0,0 +1,10 @@ +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# +[Unit] +Description= import emails to piler + +[Service] +Type=simple +ExecStart=/usr/local/bin/runagent import-emails diff --git a/ui/public/i18n/language.json b/ui/public/i18n/language.json index aebfb40..7d1b504 100644 --- a/ui/public/i18n/language.json +++ b/ui/public/i18n/language.json @@ -43,7 +43,12 @@ "host_pattern": "Must be a valid fully qualified domain name", "host_format": "Must be a valid fully qualified domain name", "password_warning": "The passwords are the default ones", - "password_warning_description": "Please change the password in the Piler webapp for admin@local(pilerrocks) and auditor@local(auditor)" + "password_warning_description": "Please change the password in the Piler webapp for admin@local(pilerrocks) and auditor@local(auditor)", + "import_email_is_running_warning": "Import emails is running", + "import_email_is_running_description": "Please wait until the import emails action is finished", + "import_email_to_piler": "Import emails to Piler", + "advanced": "Advanced", + "import_old_emails_to_piler_description": "Import old emails to Piler, this process may take a long time" }, "about": { "title": "About" @@ -59,7 +64,8 @@ "get-name": "Get name", "list-backup-repositories": "List backup repositories", "list-backups": "List backups", - "list-installed-modules": "List installed modules" + "list-installed-modules": "List installed modules", + "importEmailToPiler": "Import emails to Piler" }, "error": { "error": "Error", diff --git a/ui/src/views/Settings.vue b/ui/src/views/Settings.vue index 884902f..f6ae9e0 100644 --- a/ui/src/views/Settings.vue +++ b/ui/src/views/Settings.vue @@ -29,6 +29,16 @@ /> + + + + + @@ -94,11 +104,48 @@ ref="mail_server" > + + + + + + + + + + + + import to from "await-to-js"; import { mapState } from "vuex"; +import Play20 from "@carbon/icons-vue/es/play--outline/20"; import { QueryParamService, UtilService, @@ -152,18 +200,23 @@ export default { q: { page: "settings", }, + Play20, urlCheckInterval: null, host: "", mail_server: "", mail_server_URL: [], + import_email_is_running: false, + piler_is_running: false, is_default_password: false, isLetsEncryptEnabled: false, isHttpToHttpsEnabled: false, loading: { getConfiguration: false, configureModule: false, + importEmailToPiler: false, }, error: { + importEmailToPiler: "", getConfiguration: "", configureModule: "", host: "", @@ -190,6 +243,51 @@ export default { next(); }, methods: { + async importEmailToPiler() { + this.loading.getConfiguration = true; + this.error.getConfiguration = ""; + const taskAction = "import-email-to-piler"; + const eventId = this.getUuid(); + + // register to task error + this.core.$root.$once( + `${taskAction}-aborted-${eventId}`, + this.importEmailToPilerAborted + ); + + // register to task completion + this.core.$root.$once( + `${taskAction}-completed-${eventId}`, + this.importEmailToPilerCompleted + ); + + const res = await to( + this.createModuleTaskForApp(this.instanceName, { + action: taskAction, + extra: { + title: this.$t("action." + taskAction), + isNotificationHidden: true, + eventId, + }, + }) + ); + const err = res[0]; + + if (err) { + console.error(`error creating task ${taskAction}`, err); + this.errorimportEmailToPiler = this.getErrorMessage(err); + this.loading.importEmailToPiler = false; + return; + } + }, + importEmailToPilerAborted(taskResult, taskContext) { + console.error(`${taskContext.action} aborted`, taskResult); + this.error.importEmailToPiler = this.$t("error.generic_error"); + this.loading.importEmailToPiler = false; + }, + importEmailToPilerCompleted() { + this.getConfiguration(); + }, async getConfiguration() { this.loading.getConfiguration = true; this.error.getConfiguration = ""; @@ -243,6 +341,8 @@ export default { }); this.mail_server_URL = config.mail_server_URL; this.is_default_password = config.is_default_password; + this.import_email_is_running = config.import_email_is_running; + this.piler_is_running = config.piler_is_running; this.loading.getConfiguration = false; this.focusElement("host"); },