Skip to content

Commit e7153bc

Browse files
committed
Modified Server regex pattern to accept single label names.
1 parent b6535a9 commit e7153bc

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

LabTech.psm1

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ Function Uninstall-LTService{
648648
}
649649
Foreach ($Svr in $Server) {
650650
If (-not ($GoodServer)) {
651-
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]*(\.[a-z0-9][a-z0-9_-]*){1,})$') {
651+
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]+(\.[a-z0-9][a-z0-9_-]*)*)$') {
652652
Try{
653653
If ($Svr -notmatch 'https?://.+') {$Svr = "http://$($Svr)"}
654654
$SvrVerCheck = "$($Svr)/Labtech/Agent.aspx"
@@ -984,14 +984,15 @@ Function Install-LTService{
984984

985985
Begin{
986986
Clear-Variable DotNET,OSVersion,PasswordArg,Result,logpath,logfile,curlog,installer,installerTest,installerResult,GoodServer,GoodTrayPort,TestTrayPort,Svr,SVer,SvrVer,SvrVerCheck,iarg,timeout,sw,tmpLTSI -EA 0 -WhatIf:$False -Confirm:$False #Clearing Variables for use
987-
Write-Debug "Starting $($myInvocation.InvocationName)"
987+
Set-Alias -name LINENUM -value Get-CurrentLineNumber -WhatIf:$False -Confirm:$False
988+
Write-Debug "Starting $($myInvocation.InvocationName) at line $(LINENUM)"
988989

989990
If (!($Force)) {
990991
If (Get-Service 'LTService','LTSvcMon' -ErrorAction SilentlyContinue) {
991992
If ($WhatIfPreference -ne $True) {
992-
Write-Error "Services are already installed." -ErrorAction Stop
993+
Write-Error "ERROR: Line $(LINENUM): Services are already installed." -ErrorAction Stop
993994
} Else {
994-
Write-Error "What if: Stopping: Services are already installed." -ErrorAction Stop
995+
Write-Error "ERROR: Line $(LINENUM): What if: Stopping: Services are already installed." -ErrorAction Stop
995996
}#End If
996997
}#End If
997998
}#End If
@@ -1018,7 +1019,7 @@ Function Install-LTService{
10181019
}
10191020
}
10201021
catch{
1021-
Write-Error "ERROR: .NET 3.5 install failed." -ErrorAction Continue
1022+
Write-Error "ERROR: Line $(LINENUM): .NET 3.5 install failed." -ErrorAction Continue
10221023
if (!($Force)) { Write-Error $Install -ErrorAction Stop }
10231024
}
10241025
}
@@ -1032,7 +1033,7 @@ Function Install-LTService{
10321033
Write-Warning ".Net Framework 3.5 has been installed and enabled."
10331034
}
10341035
Else {
1035-
Write-Error "ERROR: .NET 3.5 install failed." -ErrorAction Continue
1036+
Write-Error "ERROR: Line $(LINENUM): .NET 3.5 install failed." -ErrorAction Continue
10361037
If (!($Force)) { Write-Error $Result -ErrorAction Stop }
10371038
}#End If
10381039
}#End If
@@ -1044,12 +1045,12 @@ Function Install-LTService{
10441045
If (-not ($DotNet -like '3.5.*')){
10451046
If (($Force)) {
10461047
If ($DotNet -like '2.0.*'){
1047-
Write-Error "ERROR: .NET 3.5 is not detected and could not be installed." -ErrorAction Continue
1048+
Write-Error "ERROR: Line $(LINENUM): .NET 3.5 is not detected and could not be installed." -ErrorAction Continue
10481049
} Else {
1049-
Write-Error "ERROR: .NET 2.0 is not detected and could not be installed." -ErrorAction Stop
1050+
Write-Error "ERROR: Line $(LINENUM): .NET 2.0 is not detected and could not be installed." -ErrorAction Stop
10501051
}#End If
10511052
} Else {
1052-
Write-Error "ERROR: .NET 3.5 is not detected and could not be installed." -ErrorAction Stop
1053+
Write-Error "ERROR: Line $(LINENUM): .NET 3.5 is not detected and could not be installed." -ErrorAction Stop
10531054
}#End If
10541055
}#End If
10551056
}#End If
@@ -1078,7 +1079,7 @@ Function Install-LTService{
10781079
}
10791080
Foreach ($Svr in $Server) {
10801081
If (-not ($GoodServer)) {
1081-
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]*(\.[a-z0-9][a-z0-9_-]*){1,})$') {
1082+
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]+(\.[a-z0-9][a-z0-9_-]*)*)$') {
10821083
If ($Svr -notmatch 'https?://.+') {$Svr = "http://$($Svr)"}
10831084
Try {
10841085
$SvrVerCheck = "$($Svr)/Labtech/Agent.aspx"
@@ -1207,7 +1208,7 @@ Function Install-LTService{
12071208
$svcRun = ('LTService') | Get-Service -EA 0 | Measure-Object | Select-Object -Expand Count
12081209
} Until ($InstallAttempt -ge 3 -or $svcRun -eq 1)
12091210
If ($svcRun -eq 0) {
1210-
Write-Error "LTService was not installed. Installation failed."
1211+
Write-Error "ERROR: Line $(LINENUM): LTService was not installed. Installation failed."
12111212
return
12121213
}
12131214
}#End If
@@ -1255,7 +1256,7 @@ Function Install-LTService{
12551256
}#End Try
12561257

12571258
Catch{
1258-
Write-Error "ERROR: There was an error during the install process. $($Error[0])"
1259+
Write-Error "ERROR: Line $(LINENUM): There was an error during the install process. $($Error[0])"
12591260
return
12601261
}#End Catch
12611262

@@ -1265,16 +1266,16 @@ Function Install-LTService{
12651266
If (($tmpLTSI|Select-Object -Expand 'ID' -EA 0) -gt 1) {
12661267
Write-Output "LabTech has been installed successfully. Agent ID: $($tmpLTSI|Select-Object -Expand 'ID' -EA 0) LocationID: $($tmpLTSI|Select-Object -Expand 'LocationID' -EA 0)"
12671268
} ElseIf (!($NoWait)) {
1268-
Write-Error "ERROR: LabTech installation completed but Agent failed to register within expected period." -ErrorAction Continue
1269+
Write-Error "ERROR: Line $(LINENUM): LabTech installation completed but Agent failed to register within expected period." -ErrorAction Continue
12691270
} Else {
12701271
Write-Warning "WARNING: LabTech installation completed but Agent did not yet register." -WarningAction Continue
12711272
}#End If
12721273
} Else {
12731274
If (($Error)) {
1274-
Write-Error "ERROR: There was an error installing LabTech. Check the log, $($env:windir)\temp\LabTech\LTAgentInstall.log $($Error[0])"
1275+
Write-Error "ERROR: Line $(LINENUM): There was an error installing LabTech. Check the log, $($env:windir)\temp\LabTech\LTAgentInstall.log $($Error[0])"
12751276
return
12761277
} ElseIf (!($NoWait)) {
1277-
Write-Error "ERROR: There was an error installing LabTech. Check the log, $($env:windir)\temp\LabTech\LTAgentInstall.log"
1278+
Write-Error "ERROR: Line $(LINENUM): There was an error installing LabTech. Check the log, $($env:windir)\temp\LabTech\LTAgentInstall.log"
12781279
return
12791280
} Else {
12801281
Write-Warning "WARNING: LabTech installation may not have succeeded." -WarningAction Continue
@@ -1283,9 +1284,9 @@ Function Install-LTService{
12831284
}#End If
12841285
If (($Rename) -and $Rename -notmatch 'False'){ Rename-LTAddRemove -Name $Rename }
12851286
} ElseIf ( $WhatIfPreference -ne $True ) {
1286-
Write-Error "ERROR: No valid server was reached to use for the install."
1287+
Write-Error "ERROR: Line $(LINENUM): No valid server was reached to use for the install."
12871288
}#End If
1288-
Write-Debug "Exiting $($myInvocation.InvocationName)"
1289+
Write-Debug "Exiting $($myInvocation.InvocationName) at line $(LINENUM)"
12891290
}#End End
12901291
}#End Function Install-LTService
12911292

@@ -1547,7 +1548,7 @@ Function Update-LTService{
15471548

15481549
Foreach ($Svr in $Server) {
15491550
If (-not ($GoodServer)) {
1550-
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]*(\.[a-z0-9][a-z0-9_-]*){1,})$') {
1551+
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]+(\.[a-z0-9][a-z0-9_-]*)*)$') {
15511552
If ($Svr -notmatch 'https?://.+') {$Svr = "http://$($Svr)"}
15521553
Try {
15531554
$SvrVerCheck = "$($Svr)/Labtech/Agent.aspx"
@@ -2238,7 +2239,7 @@ Function Test-LTPorts{
22382239
)
22392240

22402241
$RemoteServer = If ([string]::IsNullOrEmpty($ComputerName)) {$IPAddress} Else {$ComputerName};
2241-
If ([string]::IsNullOrEmpty($RemoteServer)) {Write-Error "No ComputerName or IPAddress was provided to test."; return}
2242+
If ([string]::IsNullOrEmpty($RemoteServer)) {Write-Error "ERROR: Line $(LINENUM): No ComputerName or IPAddress was provided to test."; return}
22422243

22432244
$test = New-Object System.Net.Sockets.TcpClient;
22442245
Try
@@ -2260,7 +2261,8 @@ Function Test-LTPorts{
22602261
}#End Function TestPort
22612262

22622263
Clear-Variable CleanSvr,svr,proc,processes,port,netstat,line -EA 0 -WhatIf:$False -Confirm:$False #Clearing Variables for use
2263-
Write-Debug "Starting $($myInvocation.InvocationName)"
2264+
Set-Alias -name LINENUM -value Get-CurrentLineNumber -WhatIf:$False -Confirm:$False
2265+
Write-Debug "Starting $($myInvocation.InvocationName) at line $(LINENUM)"
22642266

22652267
}#End Begin
22662268

@@ -2312,7 +2314,7 @@ Function Test-LTPorts{
23122314
return
23132315
}
23142316

2315-
if ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]*(\.[a-z0-9][a-z0-9_-]*){1,})$') {
2317+
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]+(\.[a-z0-9][a-z0-9_-]*)*)$') {
23162318
Try{
23172319
$CleanSvr = ($Svr -replace 'https?://',''|ForEach-Object {$_.Trim()})
23182320
Write-Output "Testing connectivity to required TCP ports:"
@@ -2324,9 +2326,9 @@ Function Test-LTPorts{
23242326
}#End Try
23252327

23262328
Catch{
2327-
Write-Error "ERROR: There was an error testing the ports. $($Error[0])" -ErrorAction Stop
2329+
Write-Error "ERROR: Line $(LINENUM): There was an error testing the ports. $($Error[0])" -ErrorAction Stop
23282330
}#End Catch
2329-
} else {
2331+
} Else {
23302332
Write-Warning "Server address $($Svr) is not a valid address or is not formatted correctly. Example: https://lt.domain.com"
23312333
}#End If
23322334
}#End Foreach
@@ -2339,7 +2341,7 @@ Function Test-LTPorts{
23392341
}
23402342
}
23412343
Else{$Error[0]}
2342-
Write-Debug "Exiting $($myInvocation.InvocationName)"
2344+
Write-Debug "Exiting $($myInvocation.InvocationName) at line $(LINENUM)"
23432345
}#End End
23442346
}#End Function Test-LTPorts
23452347

@@ -3199,7 +3201,8 @@ Function Set-LTProxy{
31993201

32003202
Begin {
32013203
Clear-Variable LTServiceSettingsChanged,LTSS,LTServiceRestartNeeded,proxyURL,proxyUser,proxyPass,passwd,Svr -EA 0 -WhatIf:$False -Confirm:$False #Clearing Variables for use
3202-
Write-Debug "Starting $($myInvocation.InvocationName)"
3204+
Set-Alias -name LINENUM -value Get-CurrentLineNumber -WhatIf:$False -Confirm:$False
3205+
Write-Debug "Starting $($myInvocation.InvocationName) at line $(LINENUM)"
32033206

32043207
try {
32053208
$LTSS=Get-LTServiceSettings -EA 0 -Verbose:$False -WA 0 -Debug:$False
@@ -3215,11 +3218,11 @@ Function Set-LTProxy{
32153218
((($ProxyServerURL) -or ($ProxyUsername) -or ($ProxyPassword) -or ($EncodedProxyUsername) -or ($EncodedProxyPassword)) -and (($ResetProxy -eq $True) -or ($DetectProxy -eq $True))) -or
32163219
((($ProxyUsername) -or ($ProxyPassword)) -and (-not ($ProxyServerURL) -or ($EncodedProxyUsername) -or ($EncodedProxyPassword) -or ($ResetProxy -eq $True) -or ($DetectProxy -eq $True))) -or
32173220
((($EncodedProxyUsername) -or ($EncodedProxyPassword)) -and (-not ($ProxyServerURL) -or ($ProxyUsername) -or ($ProxyPassword) -or ($ResetProxy -eq $True) -or ($DetectProxy -eq $True)))
3218-
) {Write-Error "Set-LTProxy: Invalid Parameter specified" -ErrorAction Stop}
3221+
) {Write-Error "ERROR: Line $(LINENUM): Set-LTProxy: Invalid Parameter specified" -ErrorAction Stop}
32193222
If (-not (($ResetProxy -eq $True) -or ($DetectProxy -eq $True) -or ($ProxyServerURL) -or ($ProxyUsername) -or ($ProxyPassword) -or ($EncodedProxyUsername) -or ($EncodedProxyPassword)))
32203223
{
3221-
If ($Args.Count -gt 0) {Write-Error "Set-LTProxy: Unknown Parameter specified" -ErrorAction Stop}
3222-
Else {Write-Error "Set-LTProxy: Required Parameters Missing" -ErrorAction Stop}
3224+
If ($Args.Count -gt 0) {Write-Error "ERROR: Line $(LINENUM): Set-LTProxy: Unknown Parameter specified" -ErrorAction Stop}
3225+
Else {Write-Error "ERROR: Line $(LINENUM): Set-LTProxy: Required Parameters Missing" -ErrorAction Stop}
32233226
}
32243227

32253228
Try{
@@ -3242,7 +3245,7 @@ Function Set-LTProxy{
32423245
$Servers = @($("$($LTSS|Select-Object -Expand 'ServerAddress' -EA 0)|www.connectwise.com").Split('|')|ForEach-Object {$_.Trim()})
32433246
Foreach ($Svr In $Servers) {
32443247
If (-not ($Script:LTProxy.Enabled)) {
3245-
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]*(\.[a-z0-9][a-z0-9_-]*){1,})$') {
3248+
If ($Svr -match '^(https?://)?(([12]?[0-9]{1,2}\.){3}[12]?[0-9]{1,2}|[a-z0-9][a-z0-9_-]+(\.[a-z0-9][a-z0-9_-]*)*)$') {
32463249
$Svr = $Svr -replace 'https?://',''
32473250
Try{
32483251
$Script:LTProxy.ProxyServerURL=$Script:LTWebProxy.GetProxy("http://$($Svr)").Authority
@@ -3309,7 +3312,7 @@ Function Set-LTProxy{
33093312
}#End Try
33103313

33113314
Catch{
3312-
Write-Error "ERROR: There was an error during the Proxy Configuration process. $($Error[0])" -ErrorAction Stop
3315+
Write-Error "ERROR: Line $(LINENUM): There was an error during the Proxy Configuration process. $($Error[0])" -ErrorAction Stop
33133316
}#End Catch
33143317
}#End Process
33153318

@@ -3360,7 +3363,7 @@ Function Set-LTProxy{
33603363
}#End If
33613364
}#End If
33623365
Else {$Error[0]}
3363-
Write-Debug "Exiting $($myInvocation.InvocationName)"
3366+
Write-Debug "Exiting $($myInvocation.InvocationName) at line $(LINENUM)"
33643367
}#End End
33653368

33663369
}#End Function Set-LTProxy

0 commit comments

Comments
 (0)