feat: add configurable SMB archival and notification queues
This commit is contained in:
1 parent
34770ed338
commit
c2f16a5c56
29 files changed
+809
-26
No files matched your search
@@ -0,0 +1,33 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
|
||||
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
||||
try {
|
||||
$orderSmbRequest = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
||||
Add-Type -TypeDefinition @'
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
public static class OrderSmbNative {
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
public struct NETRESOURCE {
|
||||
public int scope, type, displayType, usage;
|
||||
public string localName, remoteName, comment, provider;
|
||||
}
|
||||
[DllImport("mpr.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern int WNetAddConnection2W(ref NETRESOURCE resource, string password, string username, int flags);
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern bool MoveFileExW(string existingName, string newName, int flags);
|
||||
}
|
||||
'@
|
||||
if ($orderSmbRequest.operation -eq 'connect') {
|
||||
$orderSmbResource = New-Object OrderSmbNative+NETRESOURCE
|
||||
$orderSmbResource.type = 1
|
||||
$orderSmbResource.remoteName = $orderSmbRequest.remote
|
||||
$orderSmbCode = [OrderSmbNative]::WNetAddConnection2W([ref]$orderSmbResource, $orderSmbRequest.password, $orderSmbRequest.username, 4)
|
||||
} elseif ($orderSmbRequest.operation -eq 'publish') {
|
||||
$orderSmbMoved = [OrderSmbNative]::MoveFileExW($orderSmbRequest.source, $orderSmbRequest.target, 8)
|
||||
$orderSmbCode = if ($orderSmbMoved) { 0 } else { [Runtime.InteropServices.Marshal]::GetLastWin32Error() }
|
||||
} else { throw 'Unsupported operation' }
|
||||
@{ ok = ($orderSmbCode -eq 0); code = $orderSmbCode } | ConvertTo-Json -Compress
|
||||
} catch {
|
||||
@{ ok = $false; code = -1 } | ConvertTo-Json -Compress
|
||||
}
|
||||
Reference in new issue
Block a user