diff --git a/NextDNS API/Stream the logs - Customized Output for Microsoft.ps1 b/NextDNS API/Stream the logs - Customized Output for Microsoft.ps1 index 0fdd54d..366959f 100644 --- a/NextDNS API/Stream the logs - Customized Output for Microsoft.ps1 +++ b/NextDNS API/Stream the logs - Customized Output for Microsoft.ps1 @@ -127,12 +127,26 @@ try { # Sometimes it identifies sub-domains as root domains, so here we make sure it doesn't happen # first see if the root domain has more than 1 dot in it, indicating that it contains sub-domains if ($Log.root -like '*.*.*') { - # Define a regex pattern that starting from the end, captures everything until the 2nd dot + # Define a regex pattern that starts from the end (rightmost side), captures everything until the 2nd dot (goes towards the left) if ($Log.root -match '(?s).*\.(.+?\..+?)$') { - - $RootDomain = $matches[1] - - Write-Host "$RootDomain is Regex cleared" -ForegroundColor Yellow + + # Assign the regex matches to a custom variable because there will be a 2nd $matches variable later and we don't want it to be overwritten + $Possibility = $matches + + # If NextDNS didn't properly provide the correct root domain, check if it contains any of these sub-TLDs + # If it does then select the entire string + if ($Possibility[1] -match '(?co|ac|com|t|uk|eu|app|org|net)[.](?.*)$') { + + $RootDomain = $Possibility[0] + + Write-Host "Sub-TLD detected in $RootDomain, applying the appropriate filters." -ForegroundColor Magenta + } + + else { + $RootDomain = $Possibility[1] + + Write-Host "$RootDomain is Regex cleared" -ForegroundColor Yellow + } } } @@ -141,15 +155,17 @@ try { $RootDomain = $Log.root Write-Host "$RootDomain is OK" -ForegroundColor Magenta - } - + } + # If the root domain's name resembles Microsoft domain names if ($RootDomain -like '*msft*' ` -or $RootDomain -like '*microsoft*' ` -or $RootDomain -like '*bing*' ` -or $RootDomain -like '*xbox*' ` -or $RootDomain -like '*azure*' ` - -or $RootDomain -like '*.ms*' + -or $RootDomain -like '*.ms*' ` + -or $RootDomain -like '*.msn*' ` + -or $RootDomain -like '*edge*' ) { # If the domain that resembles Microsoft domain was blocked if ($Log.status -eq 'blocked') {