Skip to content

Commit

Permalink
Merge pull request #18 from NethServer/sdl-6951
Browse files Browse the repository at this point in the history
Fix escaping issue in create-task configuration
  • Loading branch information
DavidePrincipi authored Jun 25, 2024
2 parents 4031f68 + ecb9e62 commit 5139ccc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
1 change: 0 additions & 1 deletion imageroot/actions/list-tasks/validate-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"remoteport": "143",
"security": "tls",
"delete_local": false,
"delete_local": true,
"exclude": "",
"remotepassword": "password",
"cron": "1h"
Expand Down
32 changes: 19 additions & 13 deletions imapsync/usr/local/bin/syncctl
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ fi
action=${1}
task_id=${2}

source /etc/imapsync/${task_id}.env
while IFS= read -r line; do
# Trim leading/trailing whitespace
line=$(echo "$line" | xargs)
# Ignore empty lines
[ -z "$line" ] && continue
# Export the variable
export "${line?}"
done < "/etc/imapsync/${task_id}.env"

if [[ "${action}" == "start" ]]; then

if [[ "$action" == "start" ]]; then

if [[ $FOLDERSYNCHRONIZATION == "exclusion" ]];then
if [[ "${FOLDERSYNCHRONIZATION}" == "exclusion" ]];then
# source breaks with `|`
exclude_regex=$(echo "$EXCLUDE" | tr ',' '|')
exclude_regex=$(echo "${EXCLUDE}" | tr ',' '|')
fi
if [[ "${REMOTEHOSTNAME}" == 'imap.gmail.com' ]]; then
gmail='--gmail1'
Expand All @@ -43,9 +49,9 @@ if [[ "$action" == "start" ]]; then
--passfile1 "/etc/imapsync/${task_id}.pwd" --port1 "${REMOTEPORT}" "${SECURITY}" "$gmail" \
--host2 "${MAIL_HOST}" --user2 "${LOCALUSER}*vmail" \
--port2 143 --tls2 --passfile2 /etc/imapsync/vmail.pwd \
${FOLDER_INBOX} --exclude "^Public$|^Shared$"${exclude_regex}"" > /proc/1/fd/1 2>&1
${FOLDER_INBOX} --exclude '^Public$|^Shared$'"${exclude_regex}" > /proc/1/fd/1 2>&1

elif [[ "$action" == "stop" ]];then
elif [[ "${action}" == "stop" ]];then
if [[ -f "/etc/imapsync/${task_id}.pid" ]]; then
kill "$(cat "/etc/imapsync/${task_id}.pid")"
# it can take a long time to imapsync to fully stop
Expand All @@ -54,25 +60,25 @@ elif [[ "$action" == "stop" ]];then
echo "Not Running"
fi

elif [[ "$action" == "status" ]];then
elif [[ "${action}" == "status" ]];then
if [[ -f "/etc/imapsync/${task_id}.pid" ]];then
echo 'Running'
else
echo 'Stopped'
fi
elif [[ "$action" == "validation" ]];then
elif [[ "${action}" == "validation" ]];then
/usr/bin/imapsync --nolog \
--host1 "${REMOTEHOSTNAME}" --user1 "${REMOTEUSERNAME}" \
--passfile1 "/etc/imapsync/${task_id}.pwd" --port1 "${REMOTEPORT}" "${SECURITY}" \
--host2 "${MAIL_HOST}" --user2 "${LOCALUSER}*vmail" \
--port2 143 --tls2 --passfile2 /etc/imapsync/vmail.pwd \
--justlogin --timeout 10

elif [[ "$action" == "list-informations" ]]; then
elif [[ "${action}" == "list-informations" ]]; then

if [[ $FOLDERSYNCHRONIZATION == "exclusion" ]];then
if [[ "${FOLDERSYNCHRONIZATION}" == "exclusion" ]];then
# source breaks with `|`
exclude_regex=$(echo "$EXCLUDE" | tr ',' '|')
exclude_regex=$(echo "${EXCLUDE}" | tr ',' '|')
fi
if [[ "${REMOTEHOSTNAME}" == 'imap.gmail.com' ]]; then
gmail='--gmail1'
Expand All @@ -84,5 +90,5 @@ elif [[ "$action" == "list-informations" ]]; then
--passfile1 "/etc/imapsync/${task_id}.pwd" --port1 "${REMOTEPORT}" "${SECURITY}" "$gmail" \
--host2 "${MAIL_HOST}" --user2 "${LOCALUSER}*vmail" \
--port2 143 --tls2 --passfile2 /etc/imapsync/vmail.pwd \
${FOLDER_INBOX} --exclude "^Public$|^Shared$"${exclude_regex}"" --justfoldersizes --timeout1 10
${FOLDER_INBOX} --exclude '^Public$|^Shared$'"${exclude_regex}" --justfoldersizes --timeout1 10
fi
18 changes: 18 additions & 0 deletions ui/src/components/CreateOrEditTask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
:label="$t('tasks.exclude_folder')"
v-model.trim="task.exclude"
ref="exclude"
:invalid-message="$t(error.exclude)"
:placeholder="$t('tasks.write_one_exclusion_per_line')"
:helper-text="$t('tasks.start_by^_and_end_by$')"
>
Expand Down Expand Up @@ -242,6 +243,12 @@ export default {
error: {
enabled_mailboxe: "",
createTask: "",
exclude: "",
localuser: "",
remoteusername: "",
remotepassword: "",
remotehostname: "",
remoteport: "",
},
};
},
Expand Down Expand Up @@ -293,6 +300,17 @@ export default {
}
isValidationOk = false;
}
if (
this.task.foldersynchronization == "exclusion" &&
!this.task.exclude
) {
this.error.exclude = "common.required";

if (isValidationOk) {
this.focusElement("exclude");
}
isValidationOk = false;
}
return isValidationOk;
},
createTaskValidationFailed(validationErrors) {
Expand Down

0 comments on commit 5139ccc

Please sign in to comment.