Fixed subcontrollers
This commit is contained in:
@@ -14,10 +14,10 @@ public class Domain {
|
|||||||
string description,
|
string description,
|
||||||
string sections
|
string sections
|
||||||
) {
|
) {
|
||||||
this.Id = id;
|
this.Id = id;
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.Description = description;
|
this.Description = description;
|
||||||
this.Sections = sections;
|
this.Sections = sections;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|||||||
25
classlib/class/nameserver.cs
Normal file
25
classlib/class/nameserver.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
namespace PS.IPAM;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class Nameserver {
|
||||||
|
public int Id { get; }
|
||||||
|
public string Name { get; }
|
||||||
|
public string[] NameSevers { get; }
|
||||||
|
public string Permissions { get; }
|
||||||
|
public DateTime? EditDate { get; }
|
||||||
|
|
||||||
|
public Nameserver(
|
||||||
|
int id,
|
||||||
|
string name,
|
||||||
|
string nameServers,
|
||||||
|
string permissions,
|
||||||
|
DateTime? editDate
|
||||||
|
) {
|
||||||
|
this.Id = id;
|
||||||
|
this.Name = name;
|
||||||
|
this.NameSevers = nameServers.Split(';');
|
||||||
|
this.Permissions = permissions;
|
||||||
|
this.EditDate = editDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,20 +34,20 @@ public class Section {
|
|||||||
bool showSupernetOnly,
|
bool showSupernetOnly,
|
||||||
int dnsId
|
int dnsId
|
||||||
) {
|
) {
|
||||||
this.Id = id;
|
this.Id = id;
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.Description = description;
|
this.Description = description;
|
||||||
this.MasterSectionId = masterSectionId;
|
this.MasterSectionId = masterSectionId;
|
||||||
this.Permissions = permissions;
|
this.Permissions = permissions;
|
||||||
this.StrictMode = strictMode;
|
this.StrictMode = strictMode;
|
||||||
this.SubnetOrdering = subnetOrdering;
|
this.SubnetOrdering = subnetOrdering;
|
||||||
this.Order = order;
|
this.Order = order;
|
||||||
this.EditDate = editDate;
|
this.EditDate = editDate;
|
||||||
this.ShowSubnet = showSubnet;
|
this.ShowSubnet = showSubnet;
|
||||||
this.ShowVlan = showVlan;
|
this.ShowVlan = showVlan;
|
||||||
this.ShowVRF = showVRF;
|
this.ShowVRF = showVRF;
|
||||||
this.ShowSupernetOnly = showSupernetOnly;
|
this.ShowSupernetOnly = showSupernetOnly;
|
||||||
this.DNSId = dnsId;
|
this.DNSId = dnsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ public class Session {
|
|||||||
DateTime? expires,
|
DateTime? expires,
|
||||||
Object? credentials
|
Object? credentials
|
||||||
) {
|
) {
|
||||||
AuthType = authType;
|
AuthType = authType;
|
||||||
Token = token;
|
Token = token;
|
||||||
AppID = appId;
|
AppID = appId;
|
||||||
URL = url;
|
URL = url;
|
||||||
Expires = expires;
|
Expires = expires;
|
||||||
Credentials = credentials;
|
Credentials = credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,38 +69,38 @@ public class Subnetwork {
|
|||||||
Object calculation,
|
Object calculation,
|
||||||
Object? custom_fields
|
Object? custom_fields
|
||||||
) {
|
) {
|
||||||
this.Id = id;
|
this.Id = id;
|
||||||
this.Subnet = subnet;
|
this.Subnet = subnet;
|
||||||
this.Mask = mask;
|
this.Mask = mask;
|
||||||
this.SectionId = sectionId;
|
this.SectionId = sectionId;
|
||||||
this.Description = description;
|
this.Description = description;
|
||||||
this.LinkedSubnet = linkedSubnet;
|
this.LinkedSubnet = linkedSubnet;
|
||||||
this.FirewallAddressObject = firewallAddressObject;
|
this.FirewallAddressObject = firewallAddressObject;
|
||||||
this.VrfId = vrfId;
|
this.VrfId = vrfId;
|
||||||
this.MasterSubnetId = masterSubnetId;
|
this.MasterSubnetId = masterSubnetId;
|
||||||
this.AllowRequests = allowRequests;
|
this.AllowRequests = allowRequests;
|
||||||
this.VlanId = vlanId;
|
this.VlanId = vlanId;
|
||||||
this.ShowName = showName;
|
this.ShowName = showName;
|
||||||
this.DeviceId = deviceId;
|
this.DeviceId = deviceId;
|
||||||
this.Permissions = permissions;
|
this.Permissions = permissions;
|
||||||
this.PingSubnet = pingSubnet;
|
this.PingSubnet = pingSubnet;
|
||||||
this.DiscoverSubnet = discoverSubnet;
|
this.DiscoverSubnet = discoverSubnet;
|
||||||
this.ResolveDNS = resolveDNS;
|
this.ResolveDNS = resolveDNS;
|
||||||
this.DNSRecursive = dnsRecursive;
|
this.DNSRecursive = dnsRecursive;
|
||||||
this.DNSRecords = dnsRecords;
|
this.DNSRecords = dnsRecords;
|
||||||
this.NameserverId = nameserverId;
|
this.NameserverId = nameserverId;
|
||||||
this.ScanAgent = scanAgent;
|
this.ScanAgent = scanAgent;
|
||||||
this.IsFolder = isFolder;
|
this.IsFolder = isFolder;
|
||||||
this.IsFull = isFull;
|
this.IsFull = isFull;
|
||||||
this.IsPool = isPool;
|
this.IsPool = isPool;
|
||||||
this.TagId = tagId;
|
this.TagId = tagId;
|
||||||
this.Threshold = threshold;
|
this.Threshold = threshold;
|
||||||
this.LocationId = locationId;
|
this.LocationId = locationId;
|
||||||
this.EditDate = editDate;
|
this.EditDate = editDate;
|
||||||
this.LastScan = lastScan;
|
this.LastScan = lastScan;
|
||||||
this.LastDiscovery = lastDiscovery;
|
this.LastDiscovery = lastDiscovery;
|
||||||
this.Calculation = calculation;
|
this.Calculation = calculation;
|
||||||
this.ExtendedData = custom_fields;
|
this.ExtendedData = custom_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetCIDR() {
|
public string GetCIDR() {
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ public class Vlan : DynamicObject {
|
|||||||
int customer_id,
|
int customer_id,
|
||||||
Object? custom_fields
|
Object? custom_fields
|
||||||
) {
|
) {
|
||||||
this.Id = vlanId;
|
this.Id = vlanId;
|
||||||
this.DomainId = domainId;
|
this.DomainId = domainId;
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.Number = number;
|
this.Number = number;
|
||||||
this.Description = description;
|
this.Description = description;
|
||||||
this.EditDate = editDate;
|
this.EditDate = editDate;
|
||||||
this.CustomerId = customer_id;
|
this.CustomerId = customer_id;
|
||||||
this.ExtendedData = custom_fields;
|
this.ExtendedData = custom_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ public class Vrf {
|
|||||||
DateTime? editDate,
|
DateTime? editDate,
|
||||||
Object? custom_fields
|
Object? custom_fields
|
||||||
) {
|
) {
|
||||||
this.Id = id;
|
this.Id = id;
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.RouteDistinguisher = rd;
|
this.RouteDistinguisher = rd;
|
||||||
this.Description = description;
|
this.Description = description;
|
||||||
this.Sections = sections;
|
this.Sections = sections;
|
||||||
this.EditDate = editDate;
|
this.EditDate = editDate;
|
||||||
this.ExtendedData = custom_fields;
|
this.ExtendedData = custom_fields;
|
||||||
}
|
}
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,11 +26,9 @@ function Invoke-Request {
|
|||||||
if ($_tokenStatus -eq "NoToken") { throw "No session available!" }
|
if ($_tokenStatus -eq "NoToken") { throw "No session available!" }
|
||||||
if ($_tokenStatus -eq "Expired") { Update-Session }
|
if ($_tokenStatus -eq "Expired") { Update-Session }
|
||||||
|
|
||||||
$Controller = $Controller
|
|
||||||
|
|
||||||
$_uri = "$($script:psipamSession.URL)/api/$($script:psipamSession.AppID)/$Controller"
|
$_uri = "$($script:psipamSession.URL)/api/$($script:psipamSession.AppID)/$Controller"
|
||||||
if ($SubController) { $_uri += "/$SubController" }
|
if ($SubController -ne $null) { $SubController;$_uri += "/$SubController" }
|
||||||
if ($Identifiers) { $_uri += "/$($Identifiers -join '/')/" }
|
if ($Identifiers -ne $null) { $_uri += "/$($Identifiers -join '/')/" }
|
||||||
|
|
||||||
$_headers = @{
|
$_headers = @{
|
||||||
"Accept" = "application/json"
|
"Accept" = "application/json"
|
||||||
@@ -60,42 +58,48 @@ function Invoke-Request {
|
|||||||
|
|
||||||
Write-Verbose -Message "Invoking web request to $($_uri), with method $($_arguments.Method), headers: $($_arguments.Headers)"
|
Write-Verbose -Message "Invoking web request to $($_uri), with method $($_arguments.Method), headers: $($_arguments.Headers)"
|
||||||
|
|
||||||
$_response = Invoke-RestMethod @_arguments
|
try {
|
||||||
|
$_response = Invoke-RestMethod @_arguments
|
||||||
if ($_response.code -match "20\d") {
|
}
|
||||||
if ($Type -is [PS.IPAM.types]) {
|
catch [System.Net.WebException] {
|
||||||
switch ($Type) {
|
switch ($_.Exception.Message) {
|
||||||
"address" {
|
"The remote server returned an error: (404) Not Found." { Write-Verbose -Message "Not found." }
|
||||||
$_paramList = @("id","subnetId","ip","is_gateway","description","hostname","mac","owner","tag","deviceId","location","port","note","lastSeen","excludePing","PTRignore","PTR","firewallAddressObject","editDate","customer_id")
|
"The remote server returned an error: (400) Bad Request." { Write-Warning -Message "Bad Request." }
|
||||||
|
Default { Write-Verbose -Message "Error occured while requesting api" }
|
||||||
$_response.data | ForEach-Object {
|
|
||||||
New-Object -TypeName ([PS.IPAM.Address]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
|
||||||
}; break
|
|
||||||
}
|
|
||||||
"vlan" {
|
|
||||||
$_paramList = @("vlanId","domainId","name","number","description","editDate","customer_id","custom_fields")
|
|
||||||
|
|
||||||
$_response.data | ForEach-Object {
|
|
||||||
New-Object -TypeName ([PS.IPAM.Vlan]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
|
||||||
}; break
|
|
||||||
}
|
|
||||||
"subnetwork" {
|
|
||||||
$_response.data | ForEach-Object {
|
|
||||||
New-Object -TypeName ([PS.IPAM.Subnetwork]) -ArgumentList (@($_.psobject.properties.value[0..30]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
|
||||||
}; break
|
|
||||||
}
|
|
||||||
"vrf" {
|
|
||||||
$_response.data | ForEach-Object {
|
|
||||||
New-Object -TypeName ([PS.IPAM.Vrf]) -ArgumentList (@($_.psobject.properties.value[0..5]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
|
||||||
}; break
|
|
||||||
}
|
|
||||||
Default { $_response.data | ForEach-Object { New-Object -TypeName ("PS.IPAM.$Type") -ArgumentList $_.psobject.properties.value } }
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return $_response.data
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!$_response) { return $null }
|
||||||
|
|
||||||
|
if ($Type -is [PS.IPAM.types]) {
|
||||||
|
switch ($Type) {
|
||||||
|
"address" {
|
||||||
|
$_paramList = @("id","subnetId","ip","is_gateway","description","hostname","mac","owner","tag","deviceId","location","port","note","lastSeen","excludePing","PTRignore","PTR","firewallAddressObject","editDate","customer_id")
|
||||||
|
|
||||||
|
$_response.data | ForEach-Object {
|
||||||
|
New-Object -TypeName ([PS.IPAM.Address]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"vlan" {
|
||||||
|
$_paramList = @("vlanId","domainId","name","number","description","editDate","customer_id","custom_fields")
|
||||||
|
|
||||||
|
$_response.data | ForEach-Object {
|
||||||
|
New-Object -TypeName ([PS.IPAM.Vlan]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"subnetwork" {
|
||||||
|
$_response.data | ForEach-Object {
|
||||||
|
New-Object -TypeName ([PS.IPAM.Subnetwork]) -ArgumentList (@($_.psobject.properties.value[0..30]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"vrf" {
|
||||||
|
$_response.data | ForEach-Object {
|
||||||
|
New-Object -TypeName ([PS.IPAM.Vrf]) -ArgumentList (@($_.psobject.properties.value[0..5]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Default { $_response.data | ForEach-Object { New-Object -TypeName ("PS.IPAM.$Type") -ArgumentList $_.psobject.properties.value } }
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw ("Error - $($_response.code)")
|
$_response.data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,16 @@ function Get-Address {
|
|||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]
|
[string]
|
||||||
$HostName,
|
$HostName,
|
||||||
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByHostBase"
|
||||||
|
)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[string]
|
||||||
|
$HostBase,
|
||||||
[parameter(
|
[parameter(
|
||||||
Mandatory=$true,
|
Mandatory=$true,
|
||||||
ValueFromPipeline=$true,
|
ValueFromPipeline=$true,
|
||||||
@@ -81,6 +91,7 @@ function Get-Address {
|
|||||||
"ByID" { $_identifiers = @($id); break }
|
"ByID" { $_identifiers = @($id); break }
|
||||||
"ByIP" { $_identifiers = ("search",$IP); break }
|
"ByIP" { $_identifiers = ("search",$IP); break }
|
||||||
"ByHostName" { $_identifiers = ("search_hostname",$HostName); break }
|
"ByHostName" { $_identifiers = ("search_hostname",$HostName); break }
|
||||||
|
"ByHostBase" { $_identifiers = ("search_hostbase",$HostBase); break }
|
||||||
"ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses); break }
|
"ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses); break }
|
||||||
"BySubnetId" {
|
"BySubnetId" {
|
||||||
if ($IP) {
|
if ($IP) {
|
||||||
|
|||||||
@@ -1,16 +1,34 @@
|
|||||||
function Get-FirstFreeIP {
|
function Get-FirstFreeIP {
|
||||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||||
param (
|
param (
|
||||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")]
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByCIDR"
|
||||||
|
)]
|
||||||
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
|
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]
|
[string]
|
||||||
$CIDR,
|
$CIDR,
|
||||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByID"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$Id,
|
$Id,
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="BySubnetObject"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[PS.IPAM.Subnetwork]
|
[PS.IPAM.Subnetwork]
|
||||||
$SubnetObject
|
$SubnetObject
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ function Get-L2Domain {
|
|||||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||||
[OutputType([PS.IPAM.Domain])]
|
[OutputType([PS.IPAM.Domain])]
|
||||||
param (
|
param (
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByID"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$Id
|
$Id
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
function Get-Nameserver {
|
function Get-Nameserver {
|
||||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||||
param (
|
param (
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByID"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$Id
|
$Id
|
||||||
|
|||||||
@@ -2,11 +2,21 @@ function Get-Section {
|
|||||||
[CmdletBinding(DefaultParameterSetName="NoParams")]
|
[CmdletBinding(DefaultParameterSetName="NoParams")]
|
||||||
[OutputType([PS.IPAM.Section])]
|
[OutputType([PS.IPAM.Section])]
|
||||||
param (
|
param (
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByID"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$Id,
|
$Id,
|
||||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByName")]
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByName"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]
|
[string]
|
||||||
$Name
|
$Name
|
||||||
|
|||||||
Reference in New Issue
Block a user