Bläddra i källkod

Added Windows Client files

3ndur4nce 3 år sedan
förälder
incheckning
e6e8fec613
3 ändrade filer med 82 tillägg och 3 borttagningar
  1. 51 0
      Clients/PS-Windows-Client.ps1
  2. 31 0
      Clients/PS-Windows-Install.ps1
  3. 0 3
      WebPage/inform/poll/index.php

+ 51 - 0
Clients/PS-Windows-Client.ps1

@@ -0,0 +1,51 @@
+$logfile = "C:\Windows\SRM\SRM.log"
+$BaseURL = Get-ItemPropertyValue -Path HKLM:\SOFTWARE\SRM -Name MasterURL
+$Secret = Get-ItemPropertyValue -Path HKLM:\SOFTWARE\SRM -Name AssetToken
+$Hostname = hostname
+
+$fullurl = "$BaseURL/inform/poll/?hostname=$Hostname"
+$webClient = New-Object System.Net.WebClient
+$webClient.Headers.add('Authorization',$Secret)
+$pollanswer = $webClient.DownloadString($fullurl)
+
+if($pollanswer -eq 0){
+    $now = (get-date).tostring("yyyy-MM-dd HH:mm:ss")
+    Add-Content $logfile "$now - Master has no tasks"
+}else{
+    $fullurl = "$BaseURL/inform/run/?hostname=$Hostname&schedid=$pollanswer"
+    $webClient = New-Object System.Net.WebClient
+    $webClient.Headers.add('Authorization',$Secret)
+    $rawscript = $webClient.DownloadString($fullurl)
+
+    $shell = ($rawscript -split '\:' ,2)[0]
+    $script = ($rawscript -split '\:' ,2)[1]
+
+    if($shell -eq "cmd"){
+        set-content -Path C:\Windows\SRM\run.cmd -Value $script
+        $output = & C:\Windows\SRM\run.cmd
+    }elseif($shell -eq "powershell"){
+        set-content -Path C:\Windows\SRM\run.ps1 -Value $script
+        $output = & C:\Windows\SRM\run.ps1
+    }else{
+        $now = (get-date).tostring("yyyy-MM-dd HH:mm:ss")
+        $output = "Cannot run $shell script"
+        Add-Content -Path $logfile "$now - $output"
+    }
+    $URL = "$BaseURL/inform/return/?hostname=$Hostname&schedid=$pollanswer"
+	$wc = new-object net.WebClient
+	$wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
+	$wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727)")
+	$wc.Headers.Add("Authorization", $Secret)
+    $wc.UseDefaultCredentials = $true
+
+	$NVC = New-Object System.Collections.Specialized.NameValueCollection
+	$NVC.Add("__VIEWSTATE", $viewstate);
+	$NVC.Add("__EVENTVALIDATION", $eventvalidation);
+	$NVC.Add("status", "complete");
+	$NVC.Add("output", $output);
+	$NVC.Add("ctl00`$MainContent`$Submit", "Submit");
+	$wc.QueryString = $NVC
+	$Result = $WC.UploadValues($URL,"POST", $NVC)
+	$readableoutput = [System.Text.Encoding]::UTF8.GetString($Result)
+	$WC.Dispose();
+}

+ 31 - 0
Clients/PS-Windows-Install.ps1

@@ -0,0 +1,31 @@
+#Installation
+$InstallationToken = ''
+$BaseURL = ''
+$Hostname = hostname
+if(!(Test-Path HKLM:\SOFTWARE\SRM\)){
+    $fullurl = "$BaseURL/inform/register/?hostname=$Hostname&do=newasset"
+    $webClient = New-Object System.Net.WebClient
+    $webClient.Headers.add('Authorization',$InstallationToken)
+    $realtoken = $webClient.DownloadString($fullurl)
+}
+New-Item -Path HKLM:\SOFTWARE -Name SRM
+New-ItemProperty -Path HKLM:\SOFTWARE\SRM -Name AssetToken -Value $realtoken
+New-ItemProperty -Path HKLM:\SOFTWARE\SRM -Name MasterURL -Value $BaseURL
+
+New-Item "C:\Windows\SRM" -Type Directory
+
+$clientscript = "
+add-content -Path C:\logs.txt -Value test
+"
+
+Set-Content -Path C:\Windows\SRM\client.ps1 -Value $clientscript
+
+$account = Get-Credential
+
+$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NonInteractive -NoLogo -NoProfile -File "C:\Windows\SRM\client.ps1"'
+$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5)
+$Settings = New-ScheduledTaskSettingsSet
+$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
+Register-ScheduledTask -TaskName 'SRM Poller' -InputObject $Task -User (Read-Host Username)
+
+New-ItemProperty -Path HKLM:\SOFTWARE\SRM -Name ClientSetup -Value 1

+ 0 - 3
WebPage/inform/poll/index.php

@@ -2,9 +2,6 @@
 
 require_once "../../config.php";
 
-if(isset($_GET['do'])){
-    $do = $_GET['do'];
-}
 if(isset($_GET['hostname'])){
     $hostname = $_GET['hostname'];
 }