New version with security in transport (https selfsigned), change deps, and preparing web version

This commit is contained in:
2019-11-21 10:58:26 +01:00
parent fb4dca9b4e
commit ec991abeed
12 changed files with 730 additions and 637 deletions

View File

@@ -1,4 +1,4 @@
# Build 11
# Build 13. Using API 2
param([Int32]$startup=0)
#Write-Host $startup
$srcdir = $PSCommandPath | Split-Path -Parent
@@ -9,7 +9,27 @@ $64bit = [Environment]::Is64BitOperatingSystem
$computerName = [System.Net.Dns]::GetHostName()
$UUID=(Get-CimInstance Win32_ComputerSystemProduct).UUID
$exists = Invoke-RestMethod -Method Get -Uri "$server/get/computerexists?ComputerName=$computerName&UUID=$UUID"
if ((Get-Host | Select-Object Version).Version.Major -lt 6){#Powershell Windows (Not Core)
add-type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
}else{ # Powershell Core
$PSDefaultParameterValues +=
@{'Invoke-RestMethod:SkipCertificateCheck' = $true}
}
$exists = Invoke-RestMethod -Method Post -Uri "$server/get/computerexists?ComputerName=$computerName&UUID=$UUID"
if ($exists.Result -eq "ERROR"){
if ($exists.EXITCODE -eq '3'){
Write-Host "Computer outside database:" $computerName
@@ -45,25 +65,25 @@ $diskResults = @()
$ThisVolume.FreeSpace = $([Math]::Round($disk.FreeSpace / 1GB,2))
$DiskResults += $ThisVolume
}
$DisksData = $DiskResults |ConvertTo-Json
$DisksData = ConvertTo-Json -Depth 4 $DiskResults
$DisksData = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($DisksData)) #I can't enter to database all without encode
$lastUser = (Get-CimInstance -ClassName Win32_ComputerSystem -Property UserName -ComputerName .).UserName
# Send it
$paramInvoke = -join("$server/upd/computer?ComputerName=$computerName&UUID=",$UUID,"&SOVersion=",$SOVersion,"&SOCaption=",$SOData.Caption,"&SOBit=",$SOData.OsArchitecture.Substring(0,2),"&LastConnection=",$Timestamp,"&RAM=",$RAMInstalled,"&RAMFree=",$RAMFree,"&CPUName=",$CPUName,"&LastUser=",$lastUser,"&HDD=",$DisksData)
Invoke-RestMethod -Method Get -Uri $paramInvoke | out-null
Invoke-RestMethod -Method Post -Uri $paramInvoke | out-null
# More info (Only if has to be)
# $paramInvoke = -join("$server/upd/computerhis?ComputerName=$computerName&UUID=",$UUID,"&RAMFree=",$RAMFree,"&RAMUsed=",$RAMUsed,"&Timestamp=",$Timestamp,"&DisksUse=",$disksUse)
# Invoke-RestMethod -Method Get -Uri $paramInvoke | out-null
# Invoke-RestMethod -Method Post -Uri $paramInvoke | out-null
# Load Cooks of computer
$cooks = Invoke-RestMethod -Method Get -Uri "$server/get/cookpend?ComputerName=$computerName&UUID=$UUID"
$cooks = Invoke-RestMethod -Method Post -Uri "$server/get/cookpend?ComputerName=$computerName&UUID=$UUID"
foreach ($CookName in $cooks){
Set-Location $env:temp # For downloading/copying items, use system temp location
$CookName = $CookName.CookName
$cook = Invoke-RestMethod -Method Get -Uri "$server/load/cook?CookName=$CookName&ComputerName=$computerName&UUID=$UUID"
$cook = Invoke-RestMethod -Method Post -Uri "$server/load/cook?CookName=$CookName&ComputerName=$computerName&UUID=$UUID"
Write-Host "Receta:" $cook.name
$CookRevision = $cook.revision
$atstartup = $cook.atstartup
@@ -261,7 +281,7 @@ foreach ($CookName in $cooks){
if ($cook.runever -eq "1"){
$err = -1 # This is for run but not for error, is by cook saw.
}
Invoke-RestMethod -Method Get -Uri "$server/upd/cookstatus?ComputerName=$computerName&UUID=$UUID&CookName=$CookName&Revision=$CookRevision&Error=$err&ErrorDesc=$errvar" | out-null
Invoke-RestMethod -Method Post -Uri "$server/set/cookstatus?ComputerName=$computerName&UUID=$UUID&CookName=$CookName&Revision=$CookRevision&Error=$err&ErrorDesc=$errvar" | out-null
#Delete files copied to temp for saving space
foreach ($element in $filesCopied) {