-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTailscale_ACL_Switcher.ps1
67 lines (55 loc) · 2 KB
/
Tailscale_ACL_Switcher.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
###powershell###
# Set OAuth client ID and client secret
$clientID = "your_client_id"
$clientSecret = "your_client_secret"
# Log start of the script
Write-Output "Starting Tailscale ACL update script..."
try {
# Send request to obtain an access token
Write-Output "Requesting access token..."
$tokenResponse = Invoke-RestMethod -Method Post -Uri "https://api.tailscale.com/api/v2/oauth/token" -Body @{
client_id = $clientID
client_secret = $clientSecret
}
# Extract access token from the response
$accessToken = $tokenResponse.access_token
Write-Output "Access token obtained: $accessToken"
# Set IP address you want to update
$oldIPAddress = "current_IP_in_ACL"
$newIPAddress = "IP_wants_Mullvad_access"
Write-Output "Updating ACL policy for IP address: $oldIPAddress -> $newIPAddress"
# Retrieve current ACL policy
try {
$aclPolicyResponse = Invoke-RestMethod -Method Get -Uri "https://api.tailscale.com/api/v2/tailnet/-/acl" -Headers @{
Authorization = "Bearer $accessToken"
}
}
catch {
Write-Host "Error retrieving ACL policy: $_"
}
# Log retrieved ACL policy
#####Write-Output "Retrieved ACL policy:"
#####Write-Output $aclPolicyResponse
# Modify ACL policy
$modifiedPolicy = $aclPolicyResponse -replace $oldIPAddress, $newIPAddress
# Send modified ACL policy back to Tailscale
try {
$response = Invoke-RestMethod -Method Post -Uri "https://api.tailscale.com/api/v2/tailnet/-/acl" -Headers @{
Authorization = "Bearer $accessToken"
"Content-Type" = "application/json"
} -Body $modifiedPolicy
Write-Output "ACL update response:"
Write-Output $response
}
catch {
Write-Host "Error sending updated ACL policy: $_"
}
# Log end of the script
Write-Output "ACL update completed."
}
catch {
# Log any errors that occur
Write-Output "An error occurred: $_"
}
# Pause to keep PowerShell window open
#####pause