Files
web-installer/windows-installer.hta
2024-08-08 11:07:59 +02:00

337 lines
8.3 KiB
HTML

<html>
<head>
<title>Webinstaller</title>
<HTA:APPLICATION
APPLICATIONNAME="webinstaller"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<STYLE>
body {
padding-top:20px;
text-align:center;
}
td,input {
font-family:Verdana;
font-size:12pt;
}
a {
font-size:9pt;
font-family:Verdana;
}
div#output {
text-align:left;
}
</STYLE>
<SCRIPT LANGUAGE=VBScript>
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Sub Window_OnLoad
Dim X, Y, strComputer, objWMIService, colItems, objItem, intHorizontal, strYear, wcRegPath
X=1024
Y=768
window.resizeTo X,Y
' resize the HTA
strComputer = "."
Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
For Each objItem in colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
window.moveTo (intHorizontal - X) / 2, (intVertical - Y) / 2
' centre it
'txtName.value=objNetwork.UserName
txtPort.focus
wcRegPath = "HKLM\SYSTEM\CurrentControlSet\Services\WebClient\Parameters\"
'WriteToRegistry wcRegPath & "BasicAuthLevel", 1, "REG_DWORD"
'WriteToRegistry wcRegPath & "FileAttributesLimitInBytes", 10000000, "REG_DWORD"
'WriteToRegistry wcRegPath & "FileSizeLimitInBytes", 512000000, "REG_DWORD"
'WriteToRegistry wcRegPath & "InternetServerTimeoutInSec", 600, "REG_DWORD"
'WriteToRegistry wcRegPath & "LocalServerTimeoutInSec", 600, "REG_DWORD"
'WriteToRegistry wcRegPath & "SendReceiveTimeoutInSec", 600, "REG_DWORD"
'WriteToRegistry wcRegPath & "ServerNotFoundCacheLifeTimeInSec", 0, "REG_DWORD"
'WriteToRegistry wcRegPath & "SupportLocking", 1, "REG_DWORD"
Dim dockerIsRunning
dockerIsRunning = CheckDockerStatus()
If dockerIsRunning Then
MsgBox "Docker is running in WSL.", vbInformation, "Docker Status"
Else
MsgBox "Docker is NOT running in WSL.", vbExclamation, "Docker Status"
End If
End Sub
Function CheckDockerStatus()
Dim objExec, outputLine, allOutput
' WSL command to check Docker status
Dim WSLCommand
WSLCommand = "wsl.exe --user root --exec sh -c ""docker info | grep 'Server Version'"""
' Execute the command
On Error Resume Next
Set objExec = objShell.Exec(WSLCommand)
allOutput = ""
' Loop through the command's output
Do While Not objExec.StdOut.AtEndOfStream
outputLine = objExec.StdOut.ReadLine()
allOutput = allOutput & outputLine & vbCrLf
Loop
logToFile(allOutput)
' Check if the output contains 'Server Version'
If InStr(allOutput, "Server Version") > 0 Then
CheckDockerStatus = True
Else
CheckDockerStatus = False
End If
End Function
Sub logToFile(output)
' Log the output to a file (optional for debugging)
Dim fso, logFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set logFile = fso.OpenTextFile("windows-installer.log", 2, True)
logFile.WriteLine "Docker Command Output:" & vbCrLf & output
logFile.Close
End Sub
Sub btnStart_OnClick
'If txtHost.value="" Then
' MsgBox "Please enter hostname",16,"ERROR"
' txtHost.focus
' Exit Sub
'End If
If txtPort.value="" Then
MsgBox "Please enter webserver port number",16,"ERROR"
txtPort.focus
Exit Sub
End If
StartWSL
'MsgBox "TEST STARTED",64,"DONE"
End Sub
Sub btnOpen_OnClick
MsgBox "Open",64,"DONE"
End Sub
Sub ShowOutput(objExec)
exitCode = objExec.ExitCode
If exitCode = 0 Then
' Read the output line by line
Do While Not objExec.StdOut.AtEndOfStream
outputLine = outputLine & objExec.StdOut.ReadLine() & vbCrLf
Loop
'WScript.Echo "Command executed successfully:" & vbCrLf & outputLine
Else
Dim errorLine
errorLine = ""
Do While Not objExec.StdErr.AtEndOfStream
errorLine = errorLine & objExec.StdErr.ReadLine() & vbCrLf
Loop
'WScript.Echo "Command failed with exit code: " & exitCode & vbCrLf & "Error Output:" & vbCrLf & errorLine
End If
' Call JS function to display output because Echo doesn't work in hta
Call UpdateOutput(outputLine, errorLine)
End Sub
Sub Delay(seconds)
' Simulate a delay by using a busy loop for the specified seconds
Dim start, now
start = Timer
Do
now = Timer
' Loop until the specified number of seconds has passed
If now - start >= seconds Then Exit Do
' Reset start if midnight is crossed
If now < start Then start = now
Loop
End Sub
Sub StartWSL()
'WSL = "wsl.exe --user root --exec docker ps > C:\Users\wslresult.txt"
'intReturn = objShell.Run(WSL, 0, True)
WSL = "wsl.exe --user root --exec docker ps --format ""table {{.Names}}\t{{.Status}}"" "
Set objExec = objShell.Exec(WSL)
outputLine = ""
ShowOutput(objExec)
Dim WSL
WSL = "wsl.exe --user root --exec docker run -d -v /var/run/docker.sock:/var/run/docker.sock --env WEBSERVER_PORT=" & txtPort.value & " registry.format.hu/framework-scheduler"
MsgBox WSL
intReturn = objShell.Run(WSL, 0, True)
If Err.Number <> 0 Then
MsgBox (Err.number & "-" & err.Description)
else
MsgBox "Framework scheduler has started"
WSL = "wsl.exe --user root --exec docker logs framework-scheduler"
iterationCount = 0
maxIterations = 12 ' Run for 1 minute (12 iterations of 5 seconds each)
Do
iterationCount = iterationCount + 1
Set objExec = objShell.Exec(WSL)
ShowOutput(objExec)
MsgBox "Please wait"
'Delay 5
If iterationCount >= maxIterations Then
MsgBox "Max iterations reached, stopping script."
Exit Do
End If
Loop
End If
End Sub
Sub MapDrive(DriveLetter,DrivePath)
If objFSO.DriveExists(DriveLetter) Then
objNetwork.RemoveNetworkDrive DriveLetter,true
End If
objNetwork.MapNetworkDrive DriveLetter, DrivePath, false, txtName.value,txtPassword.value
End Sub
Sub DeleteCredential(Target)
CredentialDelete = "cmdkey.exe /delete:" & Target
intReturn = objShell.Run(CredentialDelete, 0, True)
End Sub
Sub AddHost(Host)
Dim Exists, NewRow, HostsPath, fileREAD, fileAPPEND, TextLine
Exists = false
NewRow = "192.168.0.1 " & Host
HostsPath = "C:\Windows\System32\drivers\etc\hosts"
'Set oHosts = objFSO.GetFile(HostsPath)
'MsgBox oHosts.attributes
'1-read, 2-write, 8-append
Set fileREAD = objFSO.OpenTextFile(HostsPath, 1)
Do While fileREAD.AtEndOfStream <> True
TextLine = Trim(fileREAD.ReadLine)
If TextLine=NewRow Then
Exists = true
Else
Exists = false
End If
Loop
'MsgBox Exists
If Not Exists Then
Set fileAPPEND = objFSO.OpenTextFile(HostsPath, 8)
fileAPPEND.Write(vbCrLf & NewRow)
fileAPPEND.Close()
Set fileAPPEND = Nothing
End If
End Sub
Sub WriteToRegistry(path,value,vtype)
str1 = ReadFromRegistry(path)
strModify = objShell.RegWrite(path, value, vtype)
If Err.number <> 0 then
MsgBox Err.Number & vbcr & Err.Description,vbCritical,Title
End If
'str2 = ReadFromRegistry(path)
'If str2<>"" Then
' MsgBox path & ": " & str1 & "->" & str2
'End If
End Sub
Function ReadFromRegistry(strRegistryKey)
Dim value
On Error Resume Next
value = objShell.RegRead( strRegistryKey )
if Err.number <> 0 then
MsgBox Err.Number & vbcr & Err.Description,vbCritical,Title
ReadFromRegistry = ""
else
ReadFromRegistry = value
end if
End Function
Sub InstallCert(CertPath)
objShell.run "certmgr.exe -add -c """ & CertPath & """ -s -r localMachine root", 0, False
objShell.run "certmgr.exe -add """ & CertPath & """ -s -r localMachine trustedpublisher",0 ,False
If Err.Number <> 0 Then
MsgBox (Err.number & "-" & err.Description)
else
MsgBox "Certificate Install completed"
End If
End Sub
</SCRIPT>
<script language="JavaScript">
function UpdateOutput(output, errorOutput) {
var outputElement = document.getElementById('output');
if (output !== '') {
outputElement.innerText += output;
} else if (errorOutput !== '') {
outputElement.innerText += errorOutput;
} else {
outputElement.innerText = '...';
}
}
</script>
</head>
<body>
<table>
<tr>
<td>Hostname:</td>
<td><input type="text" name="txtHost" value="localhost" disabled="disabled"/></td>
</tr>
<tr>
<td>Webserver port:</td>
<td><input type="text" name="txtPort" value="8080" maxlength="5" size="6" /></td>
</tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td><input type="button" value="START INSTALL" id=btnStart /></td></tr>
</table>
<br><br>
<div id="output"></div>
</body>
</html>