|
|
@ -1362,70 +1362,6 @@ if ($executeMode -eq "MODIFY_ONLY") { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
<# |
|
|
|
# 🚫 已屏蔽:创建备份目录 |
|
|
|
if (-not (Test-Path $BACKUP_DIR)) { |
|
|
|
New-Item -ItemType Directory -Path $BACKUP_DIR | Out-Null |
|
|
|
} |
|
|
|
|
|
|
|
# 🚫 已屏蔽:备份现有配置 |
|
|
|
if (Test-Path $STORAGE_FILE) { |
|
|
|
Write-Host "$GREEN📁 [备份]$NC 正在备份配置文件..." |
|
|
|
$backupName = "storage.json.backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')" |
|
|
|
Copy-Item $STORAGE_FILE "$BACKUP_DIR\$backupName" |
|
|
|
} |
|
|
|
|
|
|
|
# 🚫 已屏蔽:生成新的 ID |
|
|
|
Write-Host "$GREEN🔄 [生成]$NC 正在生成新的 ID..." |
|
|
|
#> |
|
|
|
|
|
|
|
<# |
|
|
|
# 🚫 已屏蔽:随机ID生成函数 |
|
|
|
function Get-RandomHex { |
|
|
|
param ( |
|
|
|
[int]$length |
|
|
|
) |
|
|
|
|
|
|
|
$bytes = New-Object byte[] ($length) |
|
|
|
$rng = [System.Security.Cryptography.RNGCryptoServiceProvider]::new() |
|
|
|
$rng.GetBytes($bytes) |
|
|
|
$hexString = [System.BitConverter]::ToString($bytes) -replace '-','' |
|
|
|
$rng.Dispose() |
|
|
|
return $hexString |
|
|
|
} |
|
|
|
|
|
|
|
# 🚫 已屏蔽:改进 ID 生成函数 |
|
|
|
function New-StandardMachineId { |
|
|
|
$template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" |
|
|
|
$result = $template -replace '[xy]', { |
|
|
|
param($match) |
|
|
|
$r = [Random]::new().Next(16) |
|
|
|
$v = if ($match.Value -eq "x") { $r } else { ($r -band 0x3) -bor 0x8 } |
|
|
|
return $v.ToString("x") |
|
|
|
} |
|
|
|
return $result |
|
|
|
} |
|
|
|
|
|
|
|
# 🚫 已屏蔽:在生成 ID 时使用新函数 |
|
|
|
$MAC_MACHINE_ID = New-StandardMachineId |
|
|
|
$UUID = [System.Guid]::NewGuid().ToString() |
|
|
|
# 将 auth0|user_ 转换为字节数组的十六进制 |
|
|
|
$prefixBytes = [System.Text.Encoding]::UTF8.GetBytes("auth0|user_") |
|
|
|
$prefixHex = -join ($prefixBytes | ForEach-Object { '{0:x2}' -f $_ }) |
|
|
|
# 生成32字节(64个十六进制字符)的随机数作为 machineId 的随机部分 |
|
|
|
$randomPart = Get-RandomHex -length 32 |
|
|
|
$MACHINE_ID = "${prefixHex}${randomPart}" |
|
|
|
$SQM_ID = "{$([System.Guid]::NewGuid().ToString().ToUpper())}" |
|
|
|
#> |
|
|
|
|
|
|
|
<# |
|
|
|
# 🚫 已屏蔽:在Update-MachineGuid函数前添加权限检查 |
|
|
|
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { |
|
|
|
Write-Host "$RED❌ [错误]$NC 请使用管理员权限运行此脚本" |
|
|
|
Start-Process powershell "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs |
|
|
|
exit |
|
|
|
} |
|
|
|
#> |
|
|
|
|
|
|
|
# 📝 功能移植完成说明 |
|
|
|
# ✅ 已成功从旧版本移植以下关键功能: |
|
|
|