From a735144a550a2fb2250212730ebde2966d3b8d55 Mon Sep 17 00:00:00 2001 From: bsourisse Date: Sun, 20 Aug 2023 22:00:57 +0200 Subject: [PATCH] feat: unixUser is now unique and retrieved by env --- .../Repo/QuickCommands/QuickCommands.js | 7 ++--- Components/Repo/Repo.js | 1 - .../WizardSteps/WizardStep2/WizardStep2.js | 11 ++++---- .../WizardSteps/WizardStep3/WizardStep3.js | 26 ++++++++----------- .../WizardSteps/WizardStep4/WizardStep4.js | 3 ++- Containers/RepoList/RepoList.js | 1 - Containers/SetupWizard/SetupWizard.js | 2 -- pages/api/cronjob/checkStatus.js | 3 ++- pages/api/cronjob/getStorageUsed.js | 2 +- pages/api/repo/add.js | 1 - pages/api/repo/id/[slug]/delete.js | 5 ++-- pages/api/repo/id/[slug]/edit.js | 2 +- 12 files changed, 28 insertions(+), 36 deletions(-) diff --git a/Components/Repo/QuickCommands/QuickCommands.js b/Components/Repo/QuickCommands/QuickCommands.js index a06b155..bfdd549 100644 --- a/Components/Repo/QuickCommands/QuickCommands.js +++ b/Components/Repo/QuickCommands/QuickCommands.js @@ -9,6 +9,7 @@ export default function QuickCommands(props) { //Needed to generate command for borg over LAN instead of WAN if env vars are set and option enabled. let HOSTNAME; let SSH_SERVER_PORT; + let UNIX_USER = process.env.NEXT_PUBLIC_UNIX_USER; if ( props.lanCommand && process.env.NEXT_PUBLIC_HOSTNAME_LAN && @@ -29,7 +30,7 @@ export default function QuickCommands(props) { // Asynchronously call copy to clipboard navigator.clipboard .writeText( - `borg init -e repokey-blake2 ssh://${props.unixUser}@${HOSTNAME}:${SSH_SERVER_PORT}/./${props.repositoryName}` + `borg init -e repokey-blake2 ssh://${UNIX_USER}@${HOSTNAME}:${SSH_SERVER_PORT}/./${props.repositoryName}` ) .then(() => { // If successful, update the isCopied state value @@ -49,8 +50,8 @@ export default function QuickCommands(props) {
Copied !
) : (
- borg init -e repokey-blake2 ssh://{props.unixUser}@ - {HOSTNAME}:{SSH_SERVER_PORT}/./ + borg init -e repokey-blake2 ssh://{UNIX_USER}@{HOSTNAME}: + {SSH_SERVER_PORT}/./ {props.repositoryName}
)} diff --git a/Components/Repo/Repo.js b/Components/Repo/Repo.js index 76320b5..e8517dd 100644 --- a/Components/Repo/Repo.js +++ b/Components/Repo/Repo.js @@ -78,7 +78,6 @@ export default function Repo(props) { )} diff --git a/Components/WizardSteps/WizardStep2/WizardStep2.js b/Components/WizardSteps/WizardStep2/WizardStep2.js index 085c072..1e24d66 100644 --- a/Components/WizardSteps/WizardStep2/WizardStep2.js +++ b/Components/WizardSteps/WizardStep2/WizardStep2.js @@ -9,6 +9,7 @@ function WizardStep2(props) { //Needed to generate command for borg over LAN instead of WAN if env vars are set and option enabled. let HOSTNAME; let SSH_SERVER_PORT; + let UNIX_USER = process.env.NEXT_PUBLIC_UNIX_USER; if ( props.selectedOption.lanCommand && process.env.NEXT_PUBLIC_HOSTNAME_LAN && @@ -39,12 +40,11 @@ function WizardStep2(props) { >
borg init -e repokey-blake2 ssh:// - {props.selectedOption.unixUser}@{HOSTNAME}: - {SSH_SERVER_PORT}/./ + {UNIX_USER}@{HOSTNAME}:{SSH_SERVER_PORT}/./ {props.selectedOption.repositoryName}
@@ -95,12 +95,11 @@ function WizardStep2(props) { >
ssh:// - {props.selectedOption.unixUser}@{HOSTNAME}: - {SSH_SERVER_PORT}/./ + {UNIX_USER}@{HOSTNAME}:{SSH_SERVER_PORT}/./ {props.selectedOption.repositoryName}
For more information about the Vorta graphical client, please diff --git a/Components/WizardSteps/WizardStep3/WizardStep3.js b/Components/WizardSteps/WizardStep3/WizardStep3.js index 484a278..ddf4c1d 100644 --- a/Components/WizardSteps/WizardStep3/WizardStep3.js +++ b/Components/WizardSteps/WizardStep3/WizardStep3.js @@ -9,6 +9,7 @@ function WizardStep3(props) { //Needed to generate command for borg over LAN instead of WAN if env vars are set and option enabled. let HOSTNAME; let SSH_SERVER_PORT; + let UNIX_USER = process.env.NEXT_PUBLIC_UNIX_USER; if ( props.selectedOption.lanCommand && process.env.NEXT_PUBLIC_HOSTNAME_LAN && @@ -38,13 +39,12 @@ function WizardStep3(props) { >
borg create ssh:// - {props.selectedOption.unixUser}@{HOSTNAME}: - {SSH_SERVER_PORT}/./ + {UNIX_USER}@{HOSTNAME}:{SSH_SERVER_PORT}/./ {props.selectedOption.repositoryName} ::archive1 /your/pathToBackup
@@ -85,12 +85,11 @@ function WizardStep3(props) { >
borg check -v --progress ssh:// - {props.selectedOption.unixUser}@{HOSTNAME}: - {SSH_SERVER_PORT}/./ + {UNIX_USER}@{HOSTNAME}:{SSH_SERVER_PORT}/./ {props.selectedOption.repositoryName}
  • List the remote archives with :
  • @@ -103,12 +102,11 @@ function WizardStep3(props) { >
    borg list ssh:// - {props.selectedOption.unixUser}@{HOSTNAME}: - {SSH_SERVER_PORT}/./ + {UNIX_USER}@{HOSTNAME}:{SSH_SERVER_PORT}/./ {props.selectedOption.repositoryName}
  • Download a remote archive with the following command :
  • @@ -121,13 +119,12 @@ function WizardStep3(props) { >
    borg export-tar --tar-filter="gzip -9" ssh:// - {props.selectedOption.unixUser}@{HOSTNAME}: - {SSH_SERVER_PORT}/./ + {UNIX_USER}@{HOSTNAME}:{SSH_SERVER_PORT}/./ {props.selectedOption.repositoryName} ::archive1 archive1.tar.gz
  • @@ -143,13 +140,12 @@ function WizardStep3(props) { >
    borg mount ssh:// - {props.selectedOption.unixUser}@{HOSTNAME}: - {SSH_SERVER_PORT}/./ + {UNIX_USER}@{HOSTNAME}:{SSH_SERVER_PORT}/./ {props.selectedOption.repositoryName} ::archive1 /tmp/yourMountPoint

    diff --git a/Components/WizardSteps/WizardStep4/WizardStep4.js b/Components/WizardSteps/WizardStep4/WizardStep4.js index 51a269d..ac937ee 100644 --- a/Components/WizardSteps/WizardStep4/WizardStep4.js +++ b/Components/WizardSteps/WizardStep4/WizardStep4.js @@ -9,6 +9,7 @@ function WizardStep4(props) { //Needed to generate command for borg over LAN instead of WAN if env vars are set and option enabled. let HOSTNAME; let SSH_SERVER_PORT; + let UNIX_USER = process.env.NEXT_PUBLIC_UNIX_USER; if ( props.selectedOption.lanCommand && process.env.NEXT_PUBLIC_HOSTNAME_LAN && @@ -29,7 +30,7 @@ function WizardStep4(props) { repositories: # Paths of local or remote repositories to backup to. - - ssh://${props.selectedOption.unixUser}@${HOSTNAME}:${SSH_SERVER_PORT}/./${props.selectedOption.repositoryName} + - ssh://${UNIX_USER}@${HOSTNAME}:${SSH_SERVER_PORT}/./${props.selectedOption.repositoryName} storage: archive_name_format: '{HOSTNAME}-documents-{now}' diff --git a/Containers/RepoList/RepoList.js b/Containers/RepoList/RepoList.js index 4c53cc6..352e131 100644 --- a/Containers/RepoList/RepoList.js +++ b/Containers/RepoList/RepoList.js @@ -104,7 +104,6 @@ export default function RepoList() { storageSize={repo.storageSize} storageUsed={repo.storageUsed} sshPublicKey={repo.sshPublicKey} - unixUser={repo.unixUser} comment={repo.comment} lanCommand={repo.lanCommand} repoManageEditHandler={() => repoManageEditHandler(repo.id)} diff --git a/Containers/SetupWizard/SetupWizard.js b/Containers/SetupWizard/SetupWizard.js index 39487db..16dac1f 100644 --- a/Containers/SetupWizard/SetupWizard.js +++ b/Containers/SetupWizard/SetupWizard.js @@ -23,7 +23,6 @@ function SetupWizard(props) { const [selectedOption, setSelectedOption] = useState({ id: '#id', repository: 'repo', - unixUser: 'user', }); ////LifeCycle @@ -60,7 +59,6 @@ function SetupWizard(props) { value: `${repo.alias} - #${repo.id}`, id: repo.id, repositoryName: repo.repositoryName, - unixUser: repo.unixUser, lanCommand: repo.lanCommand, })); diff --git a/pages/api/cronjob/checkStatus.js b/pages/api/cronjob/checkStatus.js index 78ad381..b32d623 100644 --- a/pages/api/cronjob/checkStatus.js +++ b/pages/api/cronjob/checkStatus.js @@ -62,7 +62,8 @@ export default async function handler(req, res) { newRepoList = repoList; for (let index in newRepoList) { const repoFiltered = lastSave.filter( - (x) => x.user === newRepoList[index].unixUser + (x) => + x.repositoryName === newRepoList[index].repositoryName ); if (repoFiltered.length === 1) { //Write the timestamp of the last save diff --git a/pages/api/cronjob/getStorageUsed.js b/pages/api/cronjob/getStorageUsed.js index 62232b1..16cf508 100644 --- a/pages/api/cronjob/getStorageUsed.js +++ b/pages/api/cronjob/getStorageUsed.js @@ -59,7 +59,7 @@ export default async function handler(req, res) { let newRepoList = repoList; for (let index in newRepoList) { const repoFiltered = storageUsed.filter( - (x) => x.name === newRepoList[index].unixUser + (x) => x.name === newRepoList[index].repositoryName ); if (repoFiltered.length === 1) { newRepoList[index].storageUsed = repoFiltered[0].size; diff --git a/pages/api/repo/add.js b/pages/api/repo/add.js index b0e6a9d..705ec40 100644 --- a/pages/api/repo/add.js +++ b/pages/api/repo/add.js @@ -58,7 +58,6 @@ export default async function handler(req, res) { sshPublicKey: sshPublicKey, comment: comment, displayDetails: true, - unixUser: '', lanCommand: lanCommand, }; diff --git a/pages/api/repo/id/[slug]/delete.js b/pages/api/repo/id/[slug]/delete.js index 2ff87a2..e9b2738 100644 --- a/pages/api/repo/id/[slug]/delete.js +++ b/pages/api/repo/id/[slug]/delete.js @@ -47,10 +47,9 @@ export default async function handler(req, res) { const shellsDirectory = path.join(process.cwd(), '/helpers'); //Exec the shell const { stderr } = await exec( - `${shellsDirectory}/shells/deleteRepo.sh ${repoList[indexToDelete].unixUser}` + `${shellsDirectory}/shells/deleteRepo.sh ${repoList[indexToDelete].repositoryName}` ); - //Ignore this normal error with the command userdel in the shell : "userdel: USERXXX mail spool (/var/mail/USERXXX) not found". - if (stderr && !stderr.includes('mail spool')) { + if (stderr) { console.log('stderr:', stderr); res.status(500).json({ status: 500, diff --git a/pages/api/repo/id/[slug]/edit.js b/pages/api/repo/id/[slug]/edit.js index add16a2..0cb1969 100644 --- a/pages/api/repo/id/[slug]/edit.js +++ b/pages/api/repo/id/[slug]/edit.js @@ -49,7 +49,7 @@ export default async function handler(req, res) { const shellsDirectory = path.join(process.cwd(), '/helpers'); // //Exec the shell const { stderr } = await exec( - `${shellsDirectory}/shells/updateRepo.sh ${repoList[repoIndex].unixUser} "${sshPublicKey}" ${size}` + `${shellsDirectory}/shells/updateRepo.sh ${repoList[repoIndex].repositoryName} "${sshPublicKey}" ${size}` ); if (stderr) { console.log('stderr:', stderr);