Skip to content

Commit

Permalink
Update import-email-to-piler service and action scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Apr 25, 2024
1 parent a48036c commit d4d8a2f
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 7 deletions.
6 changes: 6 additions & 0 deletions imageroot/actions/get-configuration/20read
Original file line number Diff line number Diff line change
Expand Up @@ -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)
18 changes: 16 additions & 2 deletions imageroot/actions/get-configuration/validate-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -18,7 +20,9 @@
"http2https",
"lets_encrypt",
"mail_server",
"is_default_password"
"is_default_password",
"import_email_is_running",
"piler_is_running"
],
"properties": {
"host": {
Expand All @@ -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"
}
}
}
10 changes: 10 additions & 0 deletions imageroot/actions/import-email-to-piler/50start
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions imageroot/systemd/user/import-email-to-piler.service
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions ui/public/i18n/language.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"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 email is running",
"import_email_is_running_description": "Please wait until the import email is finished"
},
"about": {
"title": "About"
Expand All @@ -59,7 +61,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",
Expand Down
84 changes: 81 additions & 3 deletions ui/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
/>
</cv-column>
</cv-row>
<cv-row v-if="import_email_is_running">
<cv-column>
<NsInlineNotification
kind="warning"
:title="$t('settings.import_email_is_running_warning')"
:description="$t('settings.import_email_is_running_description')"
:showCloseButton="false"
/>
</cv-column>
</cv-row>
<cv-row>
<cv-column>
<cv-tile light>
Expand Down Expand Up @@ -94,11 +104,28 @@
ref="mail_server"
>
<template slot="tooltip">
{{
$t("settings.choose_the_mail_server_to_use")
}}
{{ $t("settings.choose_the_mail_server_to_use") }}
</template>
</NsComboBox>
<NsButton
v-if="piler_is_running"
kind="ghost"
:icon="Launch20"
:disabled="loading.getConfiguration || import_email_is_running"
@click="importEmailToPiler"
>
{{ $t("settings.import_email_to_piler") }}
</NsButton>
<cv-row v-if="error.importEmailToPiler">
<cv-column>
<NsInlineNotification
kind="error"
:title="$t('action.importEmailToPiler')"
:description="error.importEmailToPiler"
:showCloseButton="false"
/>
</cv-column>
</cv-row>
<cv-row v-if="error.configureModule">
<cv-column>
<NsInlineNotification
Expand Down Expand Up @@ -156,14 +183,18 @@ export default {
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: "",
Expand All @@ -190,6 +221,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 = "";
Expand Down Expand Up @@ -243,6 +319,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");
},
Expand Down

0 comments on commit d4d8a2f

Please sign in to comment.