-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from 45Drives/dev-josh
Features/Fixes for File Sharing 3.2.4
- Loading branch information
Showing
11 changed files
with
384 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
## Cockpit File Sharing 3.2.3-1 | ||
## Cockpit File Sharing 3.2.4-1 | ||
|
||
* Fixed issue saving NFS exports file when /etc/exports.d DNE | ||
* Add settings menu for configuring smb.conf and exports file locations | ||
* Fix parsing "valid users" field for Samba shares |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<!-- | ||
Copyright (C) 2022 Josh Boudreau <jboudreau@45drives.com> | ||
|
||
This file is part of Cockpit File Sharing. | ||
|
||
Cockpit File Sharing is free software: you can redistribute it and/or modify it under the terms | ||
of the GNU General Public License as published by the Free Software Foundation, either version 3 | ||
of the License, or (at your option) any later version. | ||
|
||
Cockpit File Sharing is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License along with Cockpit File Sharing. | ||
If not, see <https://www.gnu.org/licenses/>. | ||
--> | ||
|
||
<template> | ||
<button | ||
type="button" | ||
@click="show = true" | ||
> | ||
<CogIcon class="size-icon icon-default" /> | ||
</button> | ||
<ModalPopup | ||
:showModal="show" | ||
headerText="File Sharing Settings" | ||
cancelText="Close" | ||
@apply="writeConfig" | ||
@cancel="hide" | ||
:disableContinue="noChanges" | ||
> | ||
<div class="flex flex-col items-stretch gap-content"> | ||
<div class="text-header">Samba</div> | ||
<div> | ||
<label class="text-label block"> | ||
Configuration Path | ||
</label> | ||
<input | ||
v-model="configTmp.samba.confPath" | ||
type="text" | ||
class="input-textlike w-full block" | ||
placeholder="default: /etc/samba/smb.conf" | ||
/> | ||
</div> | ||
<div class="text-header">NFS</div> | ||
<div> | ||
<label class="text-label block"> | ||
Configuration Path | ||
</label> | ||
<input | ||
v-model="configTmp.nfs.confPath" | ||
type="text" | ||
class="input-textlike w-full block" | ||
placeholder="default: /etc/exports.d/cockpit-file-sharing.exports" | ||
/> | ||
</div> | ||
</div> | ||
</ModalPopup> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { reactive, ref, defineComponent, watch, computed } from 'vue'; | ||
import { CogIcon } from '@heroicons/vue/solid'; | ||
import ModalPopup from './ModalPopup.vue'; | ||
|
||
declare global { | ||
var cockpit: any = {}; | ||
} | ||
|
||
interface FileSharingConfig { | ||
/** | ||
* Samba-specific settings | ||
*/ | ||
samba: { | ||
/** | ||
* Path to smb.conf | ||
*/ | ||
confPath: string; | ||
} | ||
/** | ||
* NFS-specific settings | ||
*/ | ||
nfs: { | ||
/** | ||
* Path to cockpit-file-sharing.exports or equivalent | ||
*/ | ||
confPath: string; | ||
} | ||
} | ||
|
||
function deepCopy<T>(obj: T): T { | ||
return JSON.parse(JSON.stringify(obj)); | ||
} | ||
|
||
const assignConfig = (target: any, source: FileSharingConfig, defaults: FileSharingConfig): FileSharingConfig => { | ||
Object.assign(target, { | ||
samba: { | ||
confPath: source?.samba?.confPath || defaults.samba.confPath, | ||
}, | ||
nfs: { | ||
confPath: source?.nfs?.confPath || defaults.nfs.confPath, | ||
} | ||
}); | ||
return target as FileSharingConfig; | ||
} | ||
|
||
const configPath = "/etc/cockpit-file-sharing.conf.json"; | ||
|
||
const configFile = cockpit.file(configPath, { | ||
superuser: 'try', | ||
syntax: { | ||
parse: (str: string) => JSON.parse(str), | ||
stringify: (obj: any) => JSON.stringify(obj, null, 2), | ||
} | ||
}); | ||
|
||
const configDefaults: FileSharingConfig = { | ||
samba: { | ||
confPath: "/etc/samba/smb.conf", | ||
}, | ||
nfs: { | ||
confPath: "/etc/exports.d/cockpit-file-sharing.exports" | ||
} | ||
}; | ||
|
||
const config: FileSharingConfig = reactive(deepCopy(configDefaults)); | ||
|
||
const loadConfig = (onDiskConfig: FileSharingConfig | null) => { | ||
console.log(onDiskConfig); | ||
if (onDiskConfig === null) { | ||
console.log('file DNE'); | ||
} else { | ||
console.log('has content'); | ||
assignConfig(config, onDiskConfig, configDefaults); | ||
} | ||
} | ||
|
||
configFile.watch(loadConfig); | ||
|
||
export function useConfig() { | ||
return config; | ||
} | ||
|
||
export default defineComponent({ | ||
setup() { | ||
const show = ref(false); | ||
const noChanges = computed(() => configTmp.nfs.confPath === config.nfs.confPath && configTmp.samba.confPath === config.samba.confPath); | ||
|
||
const configTmp: FileSharingConfig = reactive(deepCopy(configDefaults)); | ||
|
||
const writeConfig = () => { | ||
assignConfig(config, configTmp, configDefaults); | ||
configFile.replace(config); | ||
} | ||
|
||
const hide = () => { | ||
show.value = false; | ||
configFile.read(); // trigger watch to reset fields | ||
} | ||
|
||
watch(config, () => { | ||
assignConfig(configTmp, config, configDefaults); | ||
}); | ||
|
||
return { | ||
show, | ||
noChanges, | ||
configTmp, | ||
hide, | ||
writeConfig, | ||
config, | ||
} | ||
}, | ||
components: { | ||
ModalPopup, | ||
CogIcon, | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.