159 lines
4.1 KiB
PowerShell
159 lines
4.1 KiB
PowerShell
[cmdletbinding()]
|
|
Param(
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$Path
|
|
)
|
|
|
|
|
|
process
|
|
{
|
|
if([string]::IsNullOrWhitespace($Path))
|
|
{
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
|
|
$folderBrowser.Description = 'Bitte den zu teilenden Ordner wählen'
|
|
$folderBrowser.ShowNewFolderButton = $true
|
|
|
|
$result = $folderBrowser.ShowDialog()
|
|
|
|
if($result -ne [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
return;
|
|
}
|
|
$Path = $folderBrowser.SelectedPath
|
|
}
|
|
|
|
Copy-Item $MyInvocation.MyCommand.Path $Path -Force | Out-Null
|
|
|
|
$null = filebrowser config init -d $db_path -c $config_path | Out-Null
|
|
|
|
filebrowser users add guest "" `
|
|
--perm.download=true `
|
|
--perm.admin=false `
|
|
--perm.delete=false `
|
|
--perm.execute=false `
|
|
--perm.modify=false `
|
|
--perm.rename=false `
|
|
--perm.share=false `
|
|
--perm.create=false `
|
|
--locale=de `
|
|
--viewMode 'list' `
|
|
--scope "." `
|
|
--lockPassword `
|
|
-d $db_path `
|
|
-c $config_path | Out-Null
|
|
Write-Warning "Folgender Ordner ist nun öffentlich zugänglich: $Path"
|
|
filebrowser -r $Path -d $db_path -c $config_path -a "0.0.0.0"
|
|
}
|
|
|
|
begin
|
|
{
|
|
$config_json = '{
|
|
"settings": {
|
|
"signup": false,
|
|
"createUserDir": false,
|
|
"userHomeBasePath": "/users",
|
|
"defaults": {
|
|
"scope": ".",
|
|
"locale": "de",
|
|
"viewMode": "list",
|
|
"singleClick": false,
|
|
"sorting": {
|
|
"by": "name",
|
|
"asc": false
|
|
},
|
|
"perm": {
|
|
"admin": false,
|
|
"execute": false,
|
|
"create": false,
|
|
"rename": false,
|
|
"modify": false,
|
|
"delete": false,
|
|
"share": false,
|
|
"download": true
|
|
},
|
|
"commands": [],
|
|
"hideDotfiles": false,
|
|
"dateFormat": false
|
|
},
|
|
"authMethod": "json",
|
|
"branding": {
|
|
"name": "",
|
|
"disableExternal": false,
|
|
"disableUsedPercentage": false,
|
|
"files": "",
|
|
"theme": "",
|
|
"color": ""
|
|
},
|
|
"tus": {
|
|
"chunkSize": 10485760,
|
|
"retryCount": 5
|
|
},
|
|
"commands": {
|
|
"after_copy": [],
|
|
"after_delete": [],
|
|
"after_rename": [],
|
|
"after_save": [],
|
|
"after_upload": [],
|
|
"before_copy": [],
|
|
"before_delete": [],
|
|
"before_rename": [],
|
|
"before_save": [],
|
|
"before_upload": []
|
|
},
|
|
"shell": [],
|
|
"rules": []
|
|
},
|
|
"server": {
|
|
"root": ".",
|
|
"baseURL": "",
|
|
"socket": "",
|
|
"tlsKey": "",
|
|
"tlsCert": "",
|
|
"port": "8080",
|
|
"address": "0.0.0.0",
|
|
"log": "stdout",
|
|
"enableThumbnails": false,
|
|
"resizePreview": false,
|
|
"enableExec": false,
|
|
"typeDetectionByHeader": false,
|
|
"authHook": "",
|
|
"tokenExpirationTime": ""
|
|
},
|
|
"auther": {
|
|
"recaptcha": null
|
|
}
|
|
}'
|
|
$app_dir = Join-Path $env:PROGRAMDATA 'filebrowser'
|
|
if(-not (Test-Path $app_dir -PathType Container))
|
|
{
|
|
mkdir -p $app_dir
|
|
}
|
|
|
|
$filebrowser_exe = Join-Path $app_dir 'filebrowser.exe'
|
|
if(-not (Test-Path $filebrowser_exe -PathType Leaf))
|
|
{
|
|
try
|
|
{
|
|
Invoke-WebRequest -Uri 'https://git.itsscb.de/itsscb/filebrowser/releases/download/v2.32.0/filebrowser.exe' -OutFile $filebrowser_exe -ErrorAction Stop
|
|
} catch
|
|
{
|
|
throw "Failed to download filebrowser.exe"
|
|
}
|
|
}
|
|
|
|
Set-Alias 'filebrowser' $filebrowser_exe
|
|
$config_path = Join-Path $app_dir 'config.json'
|
|
# if(-not (Test-Path $config_path -PathType Leaf))
|
|
# {
|
|
$config_json > $config_path
|
|
# }
|
|
|
|
$db_path = Join-Path $app_dir "filebrowser.db"
|
|
if(Test-Path $db_path -PathType Leaf)
|
|
{
|
|
Remove-Item $db_path -Force
|
|
}
|
|
|
|
}
|