Skip to content

Commit a9fe969

Browse files
committed
Ensure NTP source has configured
1 parent 263a72c commit a9fe969

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ git pull
5151
Sample output
5252

5353
````markdown
54-
# Windows Secure Auditor: 0.12.9
54+
# Windows Secure Auditor: 0.13.0
5555

5656
## System Information
5757

@@ -91,7 +91,8 @@ Sample output
9191

9292
## Network Time Sync
9393

94-
- [x] Windows Time Service Started
94+
- [x] Windows Time service started
95+
- [x] NTP source: time.windows.com
9596

9697
```log
9798
Leap Indicator: 0(no warning)

README.zh-TW.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ git pull
5151
範例輸出
5252

5353
````markdown
54-
# Windows Secure Auditor: 0.12.9
54+
# Windows Secure Auditor: 0.13.0
5555

5656
## 系統資訊
5757

@@ -91,7 +91,8 @@ git pull
9191

9292
## 網路校時
9393

94-
- [x] Windows 時間同步服務已啟動
94+
- [x] 網路校時服務已啟動
95+
- [x] 校時來源: time.windows.com
9596

9697
```log
9798
躍進式指示器: 0(沒有警告)
@@ -168,9 +169,9 @@ An TLS 1.2 connection request was received from a remote client application, but
168169

169170
- 2023-01-03T08:30:00+08:00 | 系統已重新開機,但未先正常關機。若系統停止回應、當機或電力意外中斷,就可能會造成此錯誤。
170171
- 2023-01-03T23:00:00+08:00 | 處理程序 C:\Windows\system32\svchost.exe (DEMO)已代表使用者 NT AUTHORITY\SYSTEM 啟動電腦 DEMO 的電源關閉,原因如下: 作業系統: Service Pack (計劃之中)
171-
理由代碼: 0x80020010
172-
關機類型: 重新啟動
173-
註解:
172+
理由代碼: 0x80020010
173+
關機類型: 重新啟動
174+
註解:
174175

175176
## 軟體安裝
176177

SecureAuditor.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# RootModule = ''
77

88
# Version number of this module.
9-
ModuleVersion = '0.12.9'
9+
ModuleVersion = '0.13.0'
1010

1111
# Supported PSEditions
1212
# CompatiblePSEditions = @()

rules/NTP.psm1

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# culture="en-US"
33
ConvertFrom-StringData @'
44
NTP = Network Time Protocol
5-
WindowsTimeServiceStarted = Windows Time Service Started
5+
NtpSource = NTP source
6+
ServiceStarted = Windows Time service started
67
'@
78
}
89

@@ -11,24 +12,25 @@ if ($PSUICulture -ne 'en-US') {
1112
}
1213

1314
function Test($config) {
15+
$ruleName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)
1416
if ($PSVersionTable.PSEdition -eq 'Core' -and $PSVersionTable.Platform -ne 'Win32NT') {
15-
$ruleName = [System.IO.Path]::GetFileNameWithoutExtension($PSCommandPath)
1617
Write-UnsupportedPlatform($ruleName)
1718
return
1819
}
20+
if (-not (IsLocalAdministrator)) {
21+
Write-RequireAdministrator($ruleName)
22+
return
23+
}
1924
Write-Output "`n## $($i18n.NTP)`n"
2025
# https://learn.microsoft.com/windows-server/networking/windows-time-service/windows-time-service-tools-and-settings
21-
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
22-
$pinfo.FileName = "w32tm"
23-
$pinfo.Arguments = "/query /status"
24-
$pinfo.RedirectStandardError = $true
25-
$pinfo.RedirectStandardOutput = $true
26-
$pinfo.UseShellExecute = $false
27-
$p = New-Object System.Diagnostics.Process
28-
$p.StartInfo = $pinfo
29-
$p.Start() | Out-Null
30-
$p.WaitForExit()
31-
$output = $p.StandardOutput.ReadToEnd().Trim()
32-
Write-CheckList ($p.ExitCode -eq 0) "$($i18n.WindowsTimeServiceStarted)"
33-
Write-Output "`n``````log`n$($output)`n``````"
26+
$service = Get-Service -Name w32time -ErrorAction SilentlyContinue
27+
Write-CheckList ($service.Status -eq 'Running') "$($i18n.ServiceStarted)"
28+
if ($service.Status -ne 'Running') {
29+
Write-CheckList $false "$($i18n.NtpSource)"
30+
return
31+
}
32+
$source = (& w32tm /query /source | Out-String).Trim()
33+
Write-CheckList ($source -inotmatch '(Free-running System Clock|Local CMOS Clock)') "$($i18n.NtpSource): $($source)"
34+
$status = (& w32tm /query /status | Out-String).Trim()
35+
Write-Output "`n``````log`n$($status)`n``````"
3436
}

rules/zh-TW/NTP.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# culture="zh-TW"
22
ConvertFrom-StringData -StringData @'
33
NTP = 網路校時
4-
WindowsTimeServiceStarted = Windows 時間同步服務已啟動
4+
NtpSource = 校時來源
5+
ServiceStarted = 網路校時服務已啟動
56
'@

0 commit comments

Comments
 (0)