You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.8 KiB
66 lines
1.8 KiB
# Rollback Mikrotik ke single ISP (ether1) — hapus dual-WAN PCC |
|
# Usage: .\scripts\rollback-single-wan-mikrotik.ps1 |
|
|
|
param( |
|
[string]$HostAddr = "10.100.1.1", |
|
[switch]$DryRun |
|
) |
|
|
|
$SshPort = 255 |
|
$SshUser = "admin" |
|
$KeyFile = Join-Path $env:USERPROFILE ".ssh\id_rsa_mikrotik" |
|
$RscLocal = Join-Path (Split-Path $PSScriptRoot -Parent) "server\mikrotik-rollback-single-wan.rsc" |
|
$RscRemote = "rollback-single-wan.rsc" |
|
|
|
$SshBase = @( |
|
"-o", "BatchMode=yes", |
|
"-o", "IdentitiesOnly=yes", |
|
"-i", $KeyFile, |
|
"-o", "PubkeyAcceptedAlgorithms=rsa-sha2-256,rsa-sha2-512,ssh-rsa", |
|
"-o", "StrictHostKeyChecking=accept-new", |
|
"-m", "hmac-sha1", |
|
"-p", $SshPort, |
|
"${SshUser}@${HostAddr}" |
|
) |
|
|
|
function Invoke-Mikrotik { |
|
param([string]$Cmd) |
|
if ($DryRun) { |
|
Write-Host "[dry-run] $Cmd" |
|
return |
|
} |
|
$out = & ssh @SshBase $Cmd 2>&1 |
|
foreach ($line in $out) { Write-Host $line } |
|
if ($LASTEXITCODE -ne 0) { Write-Warning "ssh exit $LASTEXITCODE" } |
|
} |
|
|
|
Write-Host "=== Rollback Single-WAN Mikrotik ===" |
|
Write-Host "Target: $HostAddr" |
|
Write-Host "File: $RscLocal" |
|
|
|
if (-not $DryRun) { |
|
Write-Host "Upload $RscRemote ..." |
|
& scp -P $SshPort -o MACs=hmac-sha1 -o StrictHostKeyChecking=accept-new ` |
|
-i $KeyFile $RscLocal "${SshUser}@${HostAddr}:$RscRemote" |
|
if ($LASTEXITCODE -ne 0) { throw "SCP gagal" } |
|
|
|
Write-Host "Import rollback ..." |
|
Invoke-Mikrotik "/import file=$RscRemote" |
|
Invoke-Mikrotik "/file remove $RscRemote" |
|
} |
|
|
|
Write-Host "`n=== Verifikasi ===" |
|
@( |
|
'/interface ethernet print where name=sfp-sfpplus1', |
|
'/ip dhcp-client print', |
|
'/ip route print where dst-address=0.0.0.0/0', |
|
'/routing rule print', |
|
'/ip firewall mangle print', |
|
'/ip firewall nat print where chain=srcnat' |
|
) | ForEach-Object { |
|
Write-Host "--- $_ ---" |
|
Invoke-Mikrotik $_ |
|
Write-Host "" |
|
} |
|
|
|
Write-Host "Selesai."
|
|
|