Get-FirefoxInfo

In less than 2 weeks, the Mozilla foundation released two security updates for both the ESR (Extended Support Release) and the ‘Release’ channel version of Firefox.

With all previous releases of Firefox, we used to check the version of firefox.exe to find out which version it was.

With Firefox 10.0 executable, we had a version 10.0.0.4412 for the ESR and 10.0.0.4411 for the release update channel but for firefox 10.0.1, we have both 10.0.1.4421 which doesn’t allow us to differentiate between the ESR and the release channel version anymore.

I’ve asked the Enterprise Working group and got the following answer from the Ben Hearsum

The only way to distinguish between the two versions these days is through the application.ini file. The SourceRepository field in the [App] section will be “http://hg.mozilla.org/releases/mozilla-esr10” for this line of ESR builds. (When we start the next line of ESR at Firefox 17 this will change, of course.)

The version you’re looking at isn’t used by us at all. The only thing we do is guarantee that it doesn’t go backwards.

Powershell, to the rescue… 😉

#Requires -Version 3.0

<#
.SYNOPSIS    
    Get the channel and version of Mozilla Firefox
 
.DESCRIPTION  
    Get the channel and version of Mozilla Firefox
 
.PARAMETER ComputerName
    Non mandatory parameter, array of remote computernames
 
.PARAMETER Credential
    Non mandatory parameter, credential used to contact remote computer

.NOTES    
    Name: Get-FirefoxInfo
    Author: Emin Atac
    DateCreated: 19/02/2012
 
.LINK    
    https://p0w3rsh3ll.wordpress.com
 
.EXAMPLE    
    .\Get-FirefoxInfo.ps1

    Channel         Version
    -------         -------
    release         10.0
    
    Returns the channel and version of Mozilla Firefox found locally
.EXAMPLE    
    .\Get-FirefoxInfo.ps1 -ComputerName "PAR903","127.0.0.1"
    Returns the channel and version of Mozilla Firefox of the two remote computers

.EXAMPLE    
    .\Get-FirefoxInfo.ps1 -ComputerName "remoteComputer1","remoteComputer2" -Credential (Get-Credential) 
    Use the credentials you specified to retrieve the channel and version of Mozilla Firefox of the two remote computers
#>

[cmdletbinding(DefaultParameterSetName='',SupportsTransactions=$false)]
param(
    [Parameter(Mandatory=$false,ParameterSetName='',ValueFromPipeline=$true,Position=0)]
    [system.array]$ComputerName=$null,

    [parameter(Mandatory=$false,ParameterSetName='',ValueFromPipeline=$true,Position=1)]
    [System.Management.Automation.PSCredential]$Credential = $null
)

# Build a hashtable for splatting
$otherparams = @{}
if ($credential)
{
    $otherparams += @{Credential = $Credential}
}
# Note to myself: both test-path and get-content support PScredential inputs

if ($ComputerName -ne $null)
{
    foreach ($computer in $ComputerName)
    {
        # Variable reset
        $osprop = $programfiles = $appinipath = $content = $sourcerep = $URL = $channel = $sourcever = $version = $MFOjb = $null
        # We need to get the target OS architecture and systemdrive
        try
        {
            $osprop = @(Get-WmiObject -Query "Select * FROM Win32_operatingsystem" -ComputerName $computer -ErrorAction Stop @otherparams)
        } 
        catch
        {
            # WMI was unable to retrieve the information
            switch ($_)
            {
                {$_.Exception.ErrorCode -eq 0x800706ba} { $reason =  "Unavailable (offline, firewall)" }
                {$_.CategoryInfo.Reason -eq 'UnauthorizedAccessException' } { $reason = "Access denied" }
                default { $reason  = $_.Exception.Message }
            }
            Write-Host -ForegroundColor Yellow  -Object "Failed to connect to WMI on $Computer because: $reason"
            # break
        } # end of catch
        
        if (($osprop.Count -ne 0) -and ($osprop -ne $null))
        {
            # Based on the OS architecture, we set the target program files directory
            if ($osprop[0].OSArchitecture -eq "64-bit")
            {
                $programfiles = "Program Files (x86)"
            } else {
                $programfiles = "Program Files"
            }
            # Now we are ready to build the full target path
            $appinipath = "\\" + $computer + "\" + ($osprop[0].SystemDrive -Replace ":","$") + "\" +  $programfiles + "\Mozilla Firefox\application.ini"
            # $appinipath
            if (Test-Path -Path $appinipath @otherparams)
            {
                try
                {
                    $content = Get-Content -Path $appinipath @otherparams
                } catch {
                    $reason  = $_.Exception.Message
                    Write-Host -ForegroundColor Yellow  -Object "Failed to use get-content against $computer because: $reason"
                }
                if ($content -ne $null)
                {
                    # Look for the SourceRepository into the application.ini file
                    $sourcerep = @($content | Select-String -Pattern "^SourceRepository=http")
    
                    if ($sourcerep.Count -ne 0)
                    {
                        # Cast the URL into a System.URI object and split its segments properties
                        $URL = ([System.URI](($sourcerep[0] -split "=")[1].ToString())).Segments[2]
                        if ($URL -eq "mozilla-release")
                        {
                            $channel = "release"
                        } elseif ($URL -match "mozilla-esr") {
                            $channel = "esr"
                        } else {
                            Write-Host -ForegroundColor Red -Object ("SourceRepository not recognised in $appinipath")
                            $channel = "Unknown"
                        }
                    } else {
                        Write-Host -ForegroundColor Red -Object ("SourceRepository not found in $appinipath")
                    }
    
                    # Look for the Version into the application.ini file
                    $sourcever = @($content | Select-String -Pattern "^Version=\d{2}\.\d{1}")
                    if ($sourcever.Count -ne 0)
                    {
                        $version = [system.version]($sourcever[0] -split "=")[1].ToString()
                    } else {
                        Write-Host -ForegroundColor Red -Object ("Version not found in $appinipath")
                        $version = "Unknown"
                    }
                    # Build a custom object
                    $MFobj = New-Object -TypeName PSObject -Property @{
                        Channel = $Channel
                        Version = $Version
                    }
                    # Return it
                    Write-Output -InputObject $MFobj
                } #end of if $content -ne $null
            } else {
                Write-Host -ForegroundColor Red -Object ("Cannot find a recent installed version of Firefox in $appinipath")
            } # end of test-path
        } # end of osprop is null
    } # end of foreach computer
} else {
    # No paramter has been passed, so we can use the new .Net 4 static property of system.environnemet for performance reasons compared to WMI
    if ([system.environment]::Is64BitOperatingSystem)
    {
        $programfiles = ${env:ProgramFiles(x86)}
    } else {
        $programfiles = $env:ProgramFiles
    }

    if (Test-Path -Path "$programfiles\Mozilla Firefox\application.ini")
    {
        $content = Get-Content -Path "$programfiles\Mozilla Firefox\application.ini"
    
        # Look for the SourceRepository into the application.ini file
        $sourcerep = @($content | Select-String -Pattern "^SourceRepository=http")
    
        if ($sourcerep.Count -ne 0)
        {
            # Cast the URL into a System.URI object and split its segments properties
            $URL = ([System.URI](($sourcerep[0] -split "=")[1].ToString())).Segments[2]
            if ($URL -eq "mozilla-release")
            {
                $channel = "release"
            } elseif ($URL -match "mozilla-esr") {
                $channel = "esr"
            } else {
                Write-Host -ForegroundColor Red -Object ("SourceRepository not recognised in your $programfiles\Mozilla Firefox\application.ini")
                $channel = "Unknown"
            }
        } else {
            Write-Host -ForegroundColor Red -Object ("SourceRepository not found in your $programfiles\Mozilla Firefox\application.ini")
        }
    
        # Look for the Version into the application.ini file
        $sourcever = @($content | Select-String -Pattern "^Version=\d{2}\.\d{1}")
        if ($sourcever.Count -ne 0)
        {
            $version = [system.version]($sourcever[0] -split "=")[1].ToString()
        } else {
            Write-Host -ForegroundColor Red -Object ("Version not found in your $programfiles\Mozilla Firefox\application.ini")
            $version = "Unknown"
        }
        # Build a custom object
        $MFobj = New-Object -TypeName PSObject -Property @{
            Channel = $Channel
            Version = $Version
        }
        # Return it
        Write-Output -InputObject $MFobj
    } else {
        Write-Host -ForegroundColor Red -Object ("Cannot find a recent installed version of Firefox in $programfiles")
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s