Skip to content

Commit 2f50dcb

Browse files
docs: one-click Windows WebDAV mount script + quirks explained
Add scripts/mount-opencoperlock-windows.{ps1,cmd}: configures the WebClient service (Basic-over-HTTPS, raises the 50 MB cap, timeout), restarts it, maps the Drive to a chosen letter with a proper label, and self-elevates only for the registry/service part so the mapping stays visible in Explorer. Document it in the WebDAV section and explain the two cosmetic Windows quirks (mount named 'dav', bogus local-disk free space). Also drop a stray </content> tag left in the doc.
1 parent 2e4d1eb commit 2f50dcb

3 files changed

Lines changed: 149 additions & 1 deletion

File tree

‎docs/API.md‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,36 @@ curl -u "me:ocl_YOUR_TOKEN" -X PROPFIND -H "Depth: 1" https://<host>/api/dav/
167167

168168
### Windows Explorer
169169

170+
#### One-click setup script (recommended)
171+
172+
Rather than clicking through all of the below by hand, use the ready-made script in
173+
[`scripts/`](../scripts/):
174+
175+
- **`mount-opencoperlock-windows.cmd`** — double-click it. Edit the `SERVER` / `DRIVE` / `LABEL`
176+
values at the top first if you like (defaults: `copper.forgenet.fr`, drive `X:`, label
177+
`OpenCoperLock`). It calls the PowerShell script, which:
178+
1. configures the WebClient service (Basic-over-HTTPS, raises the 50 MB cap, longer timeout) —
179+
a UAC prompt appears for this part,
180+
2. restarts WebClient (clearing its "not a WebDAV server" cache),
181+
3. maps your Drive to the chosen letter (reconnecting at logon),
182+
4. gives the drive a proper label instead of Windows' default (`dav`).
183+
184+
You'll be asked to paste your **`ocl_…` API token** (Account → API tokens, unrestricted). Or run
185+
the PowerShell script directly with your own options:
186+
```powershell
187+
powershell -ExecutionPolicy Bypass -File .\mount-opencoperlock-windows.ps1 `
188+
-Server copper.forgenet.fr -Drive Z -Token ocl_XXXX -Label "My Drive"
189+
```
190+
191+
> **Two cosmetic Windows quirks the script can't change** (they're client-side, not the server):
192+
> - **The mount is named after the last URL segment** (`…/api/dav/` → "dav"). The script sets a
193+
> nicer label via the registry; you can also just rename it in *This PC*.
194+
> - **"Free space" often shows your local C: drive** (e.g. *33 GB free of 237 GB*), not your account
195+
> quota. Windows ignores the server's RFC-4331 quota on many builds. Your real usage is in the web
196+
> app — the server *does* report it correctly (a `PROPFIND` shows `quota-available-bytes`).
197+
198+
#### Doing it by hand
199+
170200
Windows' built-in WebDAV client (the *WebClient* / Mini-Redirector service) is strict and its
171201
errors are misleading — **`0x80070043` "The network name cannot be found"** almost always means
172202
Windows never completed the WebDAV handshake, **not** that the server is down. Work through these
@@ -200,4 +230,3 @@ in order:
200230
curl -u "me:ocl_YOUR_TOKEN" -X PROPFIND -H "Depth: 1" https://copper.forgenet.fr/api/dav/
201231
```
202232
A `207 Multi-Status` with XML = the server and proxy are perfect; the ball is in Windows' court.
203-
</content>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@echo off
2+
REM ===========================================================================
3+
REM OpenCoperLock — one-click WebDAV mount for Windows.
4+
REM Double-click this file. It runs the PowerShell script next to it, which
5+
REM configures Windows' WebClient service (a UAC prompt will appear) and maps
6+
REM your Drive to a drive letter.
7+
REM
8+
REM Edit the three values below to taste, then double-click. You'll be asked to
9+
REM paste your API token (Account -> API tokens; use an unrestricted one).
10+
REM ===========================================================================
11+
12+
set "SERVER=copper.forgenet.fr"
13+
set "DRIVE=X"
14+
set "LABEL=OpenCoperLock"
15+
16+
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0mount-opencoperlock-windows.ps1" -Server "%SERVER%" -Drive "%DRIVE%" -Label "%LABEL%"
17+
18+
echo.
19+
pause
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<#
2+
OpenCoperLock — mount your Drive as a Windows network drive over WebDAV.
3+
4+
Windows' built-in WebDAV client (the "WebClient" service) needs a few registry tweaks before it
5+
behaves, and it mislabels the mount. This script does the whole thing in one shot:
6+
7+
1. Configures the WebClient service (Basic-over-HTTPS, raises the 50 MB download cap, longer
8+
timeout) — this part self-elevates to Administrator.
9+
2. Restarts WebClient so the settings take effect and its "not a WebDAV server" cache is cleared.
10+
3. Maps your Drive to a drive letter (default X:) that reconnects at logon.
11+
4. Gives the drive a proper label instead of Windows' ugly default ("dav").
12+
13+
USAGE (right-click the .cmd wrapper → it calls this, or run directly):
14+
15+
powershell -ExecutionPolicy Bypass -File .\mount-opencoperlock-windows.ps1 `
16+
-Server copper.forgenet.fr -Drive X -Token ocl_XXXXXXXX -Label "OpenCoperLock"
17+
18+
The token is your PERSONAL API token (Account → API tokens) — an unrestricted one; folder-scoped
19+
tokens are refused by WebDAV. If you omit -Token the script prompts for it.
20+
21+
NOTE ON "free space": Windows often shows your LOCAL C: drive's size on a WebDAV mount instead of
22+
your account quota. That's a Windows limitation — the server does report the correct quota. Your
23+
real usage is always shown in the web app.
24+
#>
25+
[CmdletBinding()]
26+
param(
27+
[string]$Server = "copper.forgenet.fr",
28+
[string]$BasePath = "/api/dav",
29+
[string]$Drive = "X",
30+
[string]$Token,
31+
[string]$User = "me",
32+
[string]$Label = "OpenCoperLock",
33+
# Internal: set when the script relaunches itself elevated to do only the registry/service part.
34+
[switch]$ConfigureOnly
35+
)
36+
37+
$ErrorActionPreference = "Stop"
38+
$Drive = $Drive.TrimEnd(":")
39+
40+
function Test-Admin {
41+
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
42+
(New-Object Security.Principal.WindowsPrincipal($id)).IsInRole(
43+
[Security.Principal.WindowsBuiltinRole]::Administrator)
44+
}
45+
46+
# ── Phase A: the Administrator-only part (registry + service) ─────────────────────────────────
47+
function Set-WebClientConfig {
48+
$p = "HKLM:\SYSTEM\CurrentControlSet\Services\WebClient\Parameters"
49+
Set-ItemProperty $p -Name BasicAuthLevel -Value 2 -Type DWord
50+
Set-ItemProperty $p -Name FileSizeLimitInBytes -Value 0xFFFFFFFF -Type DWord # ~4 GB (was 50 MB)
51+
Set-ItemProperty $p -Name FsCtlRequestTimeoutInSec -Value 300 -Type DWord
52+
Set-Service WebClient -StartupType Automatic
53+
Restart-Service WebClient -Force
54+
Write-Host "[ok] WebClient configured and restarted." -ForegroundColor Green
55+
}
56+
57+
if ($ConfigureOnly) {
58+
# We are the elevated child: do only the privileged part, then exit.
59+
Set-WebClientConfig
60+
return
61+
}
62+
63+
# ── Phase B: the normal-user part (mapping must NOT run elevated, or Explorer won't see it) ─────
64+
if (-not $Token) { $Token = Read-Host "Paste your OpenCoperLock API token (ocl_...)" }
65+
if (-not $Token) { throw "No token provided." }
66+
67+
Write-Host "Configuring the WebClient service (a UAC prompt will appear)..." -ForegroundColor Cyan
68+
$childArgs = @(
69+
"-ExecutionPolicy","Bypass","-File","`"$PSCommandPath`"","-ConfigureOnly",
70+
"-Server",$Server,"-BasePath",$BasePath
71+
)
72+
$proc = Start-Process -FilePath "powershell.exe" -Verb RunAs -ArgumentList $childArgs -Wait -PassThru
73+
if ($proc.ExitCode -ne 0) { Write-Warning "The elevated configuration step reported an error; continuing to the mount anyway." }
74+
75+
# The @SSL UNC form routes reliably through the WebDAV redirector over HTTPS on port 443.
76+
$uncPath = "\\$Server@SSL" + ($BasePath -replace "/","\")
77+
78+
# Drop any stale mapping on that letter first (ignore "not connected" errors).
79+
& net.exe use "$($Drive):" /delete /y 2>$null | Out-Null
80+
81+
Write-Host "Mapping $($Drive): -> $uncPath ..." -ForegroundColor Cyan
82+
& net.exe use "$($Drive):" $uncPath /user:$User $Token /persistent:yes
83+
if ($LASTEXITCODE -ne 0) {
84+
throw "net use failed (exit $LASTEXITCODE). Make sure the WebClient service is running and the token is valid."
85+
}
86+
87+
# Give the drive a human label instead of Windows' default ("dav") via MountPoints2.
88+
try {
89+
$mangled = "##" + (($uncPath.TrimStart("\")) -replace "[\\/]","#")
90+
$mp = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\$mangled"
91+
New-Item -Path $mp -Force | Out-Null
92+
Set-ItemProperty -Path $mp -Name "_LabelFromReg" -Value $Label
93+
Write-Host "[ok] Drive labelled '$Label'." -ForegroundColor Green
94+
} catch {
95+
Write-Warning "Could not set the drive label (cosmetic only): $($_.Exception.Message)"
96+
}
97+
98+
Write-Host ""
99+
Write-Host "Done. Your Drive is mounted at $($Drive): — open 'This PC'." -ForegroundColor Green
100+
Write-Host "(Windows may show your local disk size for 'free space'; that's a Windows quirk, not your real quota.)" -ForegroundColor DarkGray

0 commit comments

Comments
 (0)