Files
WD-HN/setup-wifi.ps1
2026-05-20 23:01:18 +07:00

64 lines
2.3 KiB
PowerShell

# Chay MOT LAN bang PowerShell (Admin): urlacl + mo firewall cong 8080 + Wi-Fi -> Private
# Chuot phai -> Run as administrator
$ErrorActionPreference = "Stop"
$port = 8080
$url = "http://+:${port}/"
$fwRuleName = "Wedding Site LAN $port"
function Test-IsAdmin {
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object Security.Principal.WindowsPrincipal($id)
return $p.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if (-not (Test-IsAdmin)) {
Write-Host "Can quyen Administrator." -ForegroundColor Red
Write-Host "Chuot phai file setup-wifi.ps1 -> Run with PowerShell (Admin)" -ForegroundColor Yellow
exit 1
}
# --- URL ACL ---
netsh http delete urlacl url=$url 2>$null | Out-Null
$user = if ($env:USERDOMAIN -and $env:USERNAME) {
"$($env:USERDOMAIN)\$($env:USERNAME)"
} else {
$env:USERNAME
}
Write-Host "Dang them URL ACL cho user: $user" -ForegroundColor Cyan
netsh http add urlacl url=$url user="$user" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
netsh http delete urlacl url=$url 2>$null | Out-Null
netsh http add urlacl url=$url user=Everyone 2>&1 | Out-Null
}
if ($LASTEXITCODE -ne 0) {
Write-Host " URL ACL that bai. Xem huong dan trong README.md" -ForegroundColor Red
exit 1
}
Write-Host " URL ACL: OK" -ForegroundColor Green
# --- Firewall: cho phep dien thoai vao cong 8080 ---
Get-NetFirewallRule -DisplayName $fwRuleName -ErrorAction SilentlyContinue |
Remove-NetFirewallRule -ErrorAction SilentlyContinue
New-NetFirewallRule -DisplayName $fwRuleName `
-Direction Inbound -Action Allow -Protocol TCP -LocalPort $port `
-Profile Domain, Private, Public | Out-Null
Write-Host " Firewall: da mo cong TCP $port (Public + Private)" -ForegroundColor Green
# --- Dat Wi-Fi la Private ---
$wifi = Get-NetConnectionProfile -ErrorAction SilentlyContinue |
Where-Object { $_.InterfaceAlias -match 'Wi-?Fi' } | Select-Object -First 1
if ($wifi -and $wifi.NetworkCategory -eq 'Public') {
Set-NetConnectionProfile -InterfaceAlias $wifi.InterfaceAlias -NetworkCategory Private
Write-Host " Wi-Fi: da doi sang mang Rieng tu (Private)" -ForegroundColor Green
}
Write-Host ""
Write-Host " Xong. Chay start.bat - tren dien thoai dung IP Wi-Fi in ra." -ForegroundColor Green
Write-Host ""
$portPattern = ':' + $port
netsh http show urlacl | Select-String -Pattern $portPattern