mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
Windows scan jobs (#3034)
Implements simple package, service and file scanning for Windows.
This commit is contained in:
committed by
GitHub
parent
65ac7f8470
commit
7ef92a609f
102
awx/plugins/library/scan_files.ps1
Normal file
102
awx/plugins/library/scan_files.ps1
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
#!powershell
|
||||||
|
# This file is part of Ansible
|
||||||
|
#
|
||||||
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Ansible is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
|
$params = Parse-Args $args $true;
|
||||||
|
|
||||||
|
$paths = Get-Attr $params "paths" $FALSE;
|
||||||
|
If ($paths -eq $FALSE)
|
||||||
|
{
|
||||||
|
Fail-Json (New-Object psobject) "missing required argument: paths";
|
||||||
|
}
|
||||||
|
|
||||||
|
$get_checksum = Get-Attr $params "get_checksum" $false | ConvertTo-Bool;
|
||||||
|
$recursive = Get-Attr $params "recursive" $false | ConvertTo-Bool;
|
||||||
|
|
||||||
|
function Date_To_Timestamp($start_date, $end_date)
|
||||||
|
{
|
||||||
|
If($start_date -and $end_date)
|
||||||
|
{
|
||||||
|
Write-Output (New-TimeSpan -Start $start_date -End $end_date).TotalSeconds
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = @()
|
||||||
|
|
||||||
|
ForEach ($path In $paths)
|
||||||
|
{
|
||||||
|
"Path: " + $path
|
||||||
|
ForEach ($file in Get-ChildItem $path -Recurse: $recursive)
|
||||||
|
{
|
||||||
|
"File: " + $file.FullName
|
||||||
|
$fileinfo = New-Object psobject
|
||||||
|
Set-Attr $fileinfo "path" $file.FullName
|
||||||
|
$info = Get-Item $file.FullName;
|
||||||
|
$iscontainer = Get-Attr $info "PSIsContainer" $null;
|
||||||
|
$length = Get-Attr $info "Length" $null;
|
||||||
|
$extension = Get-Attr $info "Extension" $null;
|
||||||
|
$attributes = Get-Attr $info "Attributes" "";
|
||||||
|
If ($info)
|
||||||
|
{
|
||||||
|
$accesscontrol = $info.GetAccessControl();
|
||||||
|
}
|
||||||
|
Else
|
||||||
|
{
|
||||||
|
$accesscontrol = $null;
|
||||||
|
}
|
||||||
|
$owner = Get-Attr $accesscontrol "Owner" $null;
|
||||||
|
$creationtime = Get-Attr $info "CreationTime" $null;
|
||||||
|
$lastaccesstime = Get-Attr $info "LastAccessTime" $null;
|
||||||
|
$lastwritetime = Get-Attr $info "LastWriteTime" $null;
|
||||||
|
|
||||||
|
$epoch_date = Get-Date -Date "01/01/1970"
|
||||||
|
If ($iscontainer)
|
||||||
|
{
|
||||||
|
Set-Attr $fileinfo "isdir" $TRUE;
|
||||||
|
}
|
||||||
|
Else
|
||||||
|
{
|
||||||
|
Set-Attr $fileinfo "isdir" $FALSE;
|
||||||
|
Set-Attr $fileinfo "size" $length;
|
||||||
|
}
|
||||||
|
Set-Attr $fileinfo "extension" $extension;
|
||||||
|
Set-Attr $fileinfo "attributes" $attributes.ToString();
|
||||||
|
# Set-Attr $fileinfo "owner" $getaccesscontrol.Owner;
|
||||||
|
# Set-Attr $fileinfo "owner" $info.GetAccessControl().Owner;
|
||||||
|
Set-Attr $fileinfo "owner" $owner;
|
||||||
|
Set-Attr $fileinfo "creationtime" (Date_To_Timestamp $epoch_date $creationtime);
|
||||||
|
Set-Attr $fileinfo "lastaccesstime" (Date_To_Timestamp $epoch_date $lastaccesstime);
|
||||||
|
Set-Attr $fileinfo "lastwritetime" (Date_To_Timestamp $epoch_date $lastwritetime);
|
||||||
|
|
||||||
|
If (($get_checksum) -and -not $fileinfo.isdir)
|
||||||
|
{
|
||||||
|
$hash = Get-FileChecksum($file.FullName);
|
||||||
|
Set-Attr $fileinfo "checksum" $hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
$files += $fileinfo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = New-Object psobject @{
|
||||||
|
ansible_facts = New-Object psobject @{
|
||||||
|
files = $files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Exit-Json $result;
|
||||||
66
awx/plugins/library/scan_packages.ps1
Normal file
66
awx/plugins/library/scan_packages.ps1
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#!powershell
|
||||||
|
# This file is part of Ansible
|
||||||
|
#
|
||||||
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Ansible is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
|
$uninstall_native_path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||||
|
$uninstall_wow6432_path = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||||
|
|
||||||
|
if ([System.IntPtr]::Size -eq 4) {
|
||||||
|
|
||||||
|
# This is a 32-bit Windows system, so we only check for 32-bit programs, which will be
|
||||||
|
# at the native registry location.
|
||||||
|
|
||||||
|
$packages = Get-ChildItem -Path $uninstall_native_path |
|
||||||
|
Get-ItemProperty |
|
||||||
|
Select-Object -Property @{Name="name"; Expression={$_."DisplayName"}},
|
||||||
|
@{Name="version"; Expression={$_."DisplayVersion"}},
|
||||||
|
@{Name="publisher"; Expression={$_."Publisher"}},
|
||||||
|
@{Name="arch"; Expression={ "Win32" }} |
|
||||||
|
Where-Object { $_.name }
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
# This is a 64-bit Windows system, so we check for 64-bit programs in the native
|
||||||
|
# registry location, and also for 32-bit programs under Wow6432Node.
|
||||||
|
|
||||||
|
$packages = Get-ChildItem -Path $uninstall_native_path |
|
||||||
|
Get-ItemProperty |
|
||||||
|
Select-Object -Property @{Name="name"; Expression={$_."DisplayName"}},
|
||||||
|
@{Name="version"; Expression={$_."DisplayVersion"}},
|
||||||
|
@{Name="publisher"; Expression={$_."Publisher"}},
|
||||||
|
@{Name="arch"; Expression={ "Win64" }} |
|
||||||
|
Where-Object { $_.name }
|
||||||
|
|
||||||
|
$packages += Get-ChildItem -Path $uninstall_wow6432_path |
|
||||||
|
Get-ItemProperty |
|
||||||
|
Select-Object -Property @{Name="name"; Expression={$_."DisplayName"}},
|
||||||
|
@{Name="version"; Expression={$_."DisplayVersion"}},
|
||||||
|
@{Name="publisher"; Expression={$_."Publisher"}},
|
||||||
|
@{Name="arch"; Expression={ "Win32" }} |
|
||||||
|
Where-Object { $_.name }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = New-Object psobject @{
|
||||||
|
ansible_facts = New-Object psobject @{
|
||||||
|
packages = $packages
|
||||||
|
}
|
||||||
|
changed = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
Exit-Json $result;
|
||||||
30
awx/plugins/library/scan_services.ps1
Normal file
30
awx/plugins/library/scan_services.ps1
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#!powershell
|
||||||
|
# This file is part of Ansible
|
||||||
|
#
|
||||||
|
# Ansible is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Ansible is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# WANT_JSON
|
||||||
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
|
$result = New-Object psobject @{
|
||||||
|
ansible_facts = New-Object psobject @{
|
||||||
|
services = Get-Service |
|
||||||
|
Select-Object -Property @{Name="name"; Expression={$_."DisplayName"}},
|
||||||
|
@{Name="win_svc_name"; Expression={$_."Name"}},
|
||||||
|
@{Name="state"; Expression={$_."Status".ToString().ToLower()}}
|
||||||
|
}
|
||||||
|
changed = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
Exit-Json $result;
|
||||||
Reference in New Issue
Block a user