Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: work on dns database #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions PowerFGT/Public/cmdb/system/dnsdatabase.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#
# Copyright 2019, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be need also to update my copyright year ;)

# Copyright 2021, Jelmer Jaarsma <jelmerjaarsma at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#

function Get-FGTSystemDnsDatabase {

<#
.SYNOPSIS
Get DNS database entries

.DESCRIPTION
Show DNS datbase entries configured on the FortiGate

.EXAMPLE
Get-FGTSystemDnsDatabase

Display DNS configured on the FortiGate

.EXAMPLE
Get-FGTSystemDnsDatabase -filter_attribute primary -filter_value 192.0.2.1

Get System DNS datbase entries with primary (DNS) equal 192.0.2.1

.EXAMPLE
Get-FGTSystemDnsDatabase -filter_attribute domain -filter_value Fortinet -filter_type contains

Get System DNS database with domain contains Fortinet

.EXAMPLE
Get-FGTSystemDnsDatabase -skip

Display DNS configured on the FortiGate (but only relevant attributes)

.EXAMPLE
Get-FGTSystemDnsDatabase -vdom vdomX

Display DNS database entries configured on the FortiGate on vdomX
#>

[CmdletBinding(DefaultParameterSetName = "default")]
Param(
[Parameter(Mandatory = $false)]
[switch]$skip,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
[psobject]$connection = $DefaultFGTConnection
)

Begin {
}

Process {

$invokeParams = @{ }
if ( $PsBoundParameters.ContainsKey('skip') ) {
$invokeParams.add( 'skip', $skip )
}
if ( $PsBoundParameters.ContainsKey('vdom') ) {
$invokeParams.add( 'vdom', $vdom )
}

$response = Invoke-FGTRestMethod -uri 'api/v2/cmdb/system/dns-database' -method 'GET' -connection $connection @invokeParams
$response.results
}

End {
}
}

function Add-FGTSystemDnsZone {
[CmdletBinding(SupportsShouldProcess)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add .SYNOPSIS/.DESCRIPTION/.EXAMPLE,

Param(
[Parameter(Mandatory = $true)]
[ValidateLength(1, 35)]
[String]$name,
[Parameter(Mandatory = $false)]
[ValidateSet('enabled', 'disabled')]
[string]$status = "enabled",
[Parameter(Mandatory = $true)]
[ValidateLength(1, 255)]
[string]$domainname,
[Parameter(Mandatory = $false)]
[ValidateScript( { $_ -match [IPAddress]$_ })]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use type IPAddress ? (and after $allowtransfer.ToString() for get IPv4 display

[string[]]$allowtransfer,
[Parameter(Mandatory = $false)]
[ValidateSet('master', 'slave')]
[string]$type = "master",
[Parameter(Mandatory = $false)]
[ValidateSet('shadow', 'public')]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not case sensible ?

[string]$view,
[Parameter(Mandatory = $false)]
[ValidateScript( { $_ -match [IPAddress]$_ })]
[string]$ipmaster,
[Parameter(Mandatory = $false)]
[ValidateLength(1, 255)]
[string]$primaryname,
[Parameter(Mandatory = $false)]
[ValidateLength(1, 255)]
[string]$contact,
[Parameter(Mandatory = $false)]
[ValidateRange(0, 2147483647)]
[int]$ttl,
[Parameter(Mandatory = $false)]
[ValidateSet('enabled', 'disabled')]
[string]$authoritative,
[Parameter(Mandatory = $false)]
[ValidateScript( { $_ -match [IPAddress]$_ })]
[string[]]$forwarder,
[Parameter(Mandatory = $false)]
[ValidateScript( { $_ -match [IPAddress]$_ })]
[string]$sourceip,
[Parameter(Mandatory = $false)]
[psobject[]]$dnsentry,
[Parameter(Mandatory = $false)]
[String[]]$vdom,
[Parameter(Mandatory = $false)]
[psobject]$connection = $DefaultFGTConnection
)

Begin {
}

Process {
$invokeParams = @{ }
if ( $PsBoundParameters.ContainsKey('vdom') ) {
$invokeParams.add( 'vdom', $vdom )
}

$uri = "api/v2/cmdb/system/dns-database"
$dnszone = new-Object -TypeName PSObject

$dnszone | add-member -name "name" -membertype NoteProperty -Value $name
$dnszone | add-member -name "status" -membertype NoteProperty -Value $status
$dnszone | add-member -name "type" -membertype NoteProperty -Value $type
$dnszone | add-member -name "domainname" -membertype NoteProperty -Value $domainname

if ( $PsBoundParameters.ContainsKey('allowtransfer') ) {
$dnszone | add-member -name "allow-transfer" -membertype NoteProperty -Value ($allowtransfer -join " ")
}

if ( $PsBoundParameters.ContainsKey('view') ) {
$dnszone | add-member -name "view" -membertype NoteProperty -Value $view
}

if ( $PsBoundParameters.ContainsKey('ipmaster') ) {
$dnszone | add-member -name "ip-master" -membertype NoteProperty -Value $ipmaster
}

if ( $PsBoundParameters.ContainsKey('primaryname') ) {
$dnszone | add-member -name "primary-name" -membertype NoteProperty -Value $primaryname
}

if ( $PsBoundParameters.ContainsKey('contact') ) {
$dnszone | add-member -name "contact" -membertype NoteProperty -Value $contact
}

if ( $PsBoundParameters.ContainsKey('ttl') ) {
$dnszone | add-member -name "ttl" -membertype NoteProperty -Value $ttl
}

if ( $PsBoundParameters.ContainsKey('authoritative') ) {
$dnszone | add-member -name "authoritative" -membertype NoteProperty -Value $authoritative
}

if ( $PsBoundParameters.ContainsKey('forwarder') ) {
$dnszone | add-member -name "forwarder" -membertype NoteProperty -Value ($forwarder -join " ")
}

if ( $PsBoundParameters.ContainsKey('sourceip') ) {
$dnszone | add-member -name "source-ip" -membertype NoteProperty -Value $sourceip
}

$response = Invoke-FGTRestMethod -uri $uri -method 'POST' -body $dnszone -connection $connection @invokeParams
$response.results

}

End {
}
}