This commit is contained in:
2022-12-05 08:48:37 +03:00
parent 800d788838
commit 09cd00dc66
35 changed files with 642 additions and 142 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.dll
bin
obj

View File

@@ -27,6 +27,7 @@
[![License](https://img.shields.io/badge/license-GPL2+-blue.svg)](https://git.arnike.ru/Arnike/ps.ipam/src/branch/main/LICENSE) [![License](https://img.shields.io/badge/license-GPL2+-blue.svg)](https://git.arnike.ru/Arnike/ps.ipam/src/branch/main/LICENSE)
![Powershell](https://img.shields.io/badge/powershell-v5.1+-blue.svg) ![Powershell](https://img.shields.io/badge/powershell-v5.1+-blue.svg)
![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/ps.ipam)
<h3 align="center">PS.IPAM</h3> <h3 align="center">PS.IPAM</h3>

73
classlib/address.cs Normal file
View File

@@ -0,0 +1,73 @@
namespace PS.IPAM;
using System;
public class Address {
public int Id { get; }
public int SubnetId { get; }
public string Ip { get; }
public bool IsGateway { get; }
public string Description { get; }
public string Hostname { get; }
public string MAC { get; }
public string Owner { get; }
public int TagId { get; }
public int DeviceId { get; }
public string Location { get; }
public int Port { get; }
public string Note { get; }
public DateTime? LastSeen { get; }
public bool ExcludePing { get; }
public int PTRignore { get; }
public int PTR { get; }
public string FirewallAddressObject { get; }
public DateTime? EditDate { get; }
public int CustomerId { get; }
public Address(
int id,
int subnetId,
string ip,
bool is_gateway,
string description,
string hostname,
string mac,
string owner,
int tag,
int deviceId,
string location,
int port,
string note,
DateTime? lastSeen,
bool excludePing,
int PTRignore,
int PTR,
string firewallAddressObject,
DateTime? editDate,
int customer_id
) {
this.Id = id;
this.SubnetId = subnetId;
this.Ip = ip;
this.IsGateway = is_gateway;
this.Description = description;
this.Hostname = hostname;
this.MAC = mac;
this.Owner = owner;
this.TagId = tag;
this.DeviceId = deviceId;
this.Location = location;
this.Port = port;
this.Note = note;
this.EditDate = lastSeen;
this.ExcludePing = excludePing;
this.PTRignore = PTRignore;
this.PTR = PTR;
this.FirewallAddressObject = firewallAddressObject;
this.EditDate = editDate;
this.CustomerId = customer_id;
}
public override string ToString() {
return this.Ip;
}
}

9
classlib/classlib.csproj Normal file
View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

6
classlib/enum.cs Normal file
View File

@@ -0,0 +1,6 @@
namespace PS.IPAM;
using System;
enum Parameters {
IsGateway = "is_gateway";
}

95
classlib/subnet.cs Normal file
View File

@@ -0,0 +1,95 @@
namespace PS.IPAM;
using System;
public class Subnetwork {
public int Id { get; }
public string Subnet { get; }
public int Mask { get; }
public int SectionId { get; }
public string Description { get; }
public string LinkedSubnet { get; }
public int FirewallAddressObject { get; }
public int VrfId { get; }
public int MasterSubnetId { get; }
public bool AllowRequests { get; }
public int VlanId { get; }
public bool ShowName { get; }
public int Device { get; }
public bool PingSubnet { get; }
public bool DiscoverSubnet { get; }
public bool ResolveDNS { get; }
public Subnetwork(
int id,
string subnet,
int mask,
int sectionId,
string description,
string linkedSubnet,
int firewallAddressObject,
int vrfId,
int masterSubnetId,
string permissions,
bool allowRequests,
int vlanId,
bool showName,
int device,
bool pingSubnet,
bool discoverSubnet,
bool resolveDNS
) {
this.Id = id;
this.Subnet = subnet;
this.Mask = mask;
this.SectionId = sectionId;
this.Description = description;
this.LinkedSubnet = linkedSubnet;
this.FirewallAddressObject = firewallAddressObject;
this.VrfId = vrfId;
this.MasterSubnetId = masterSubnetId;
this.AllowRequests = allowRequests;
this.VlanId = vlanId;
this.ShowName = showName;
this.Device = device;
this.PingSubnet = pingSubnet;
this.DiscoverSubnet = discoverSubnet;
this.ResolveDNS = resolveDNS;
}
public override string ToString()
{
return $"{this.Subnet}/{this.Mask}";
}
}
id : 1
subnet : fd13:6d20:29dc:cf27::
mask : 64
sectionId : 2
description : Private subnet 1
linked_subnet :
firewallAddressObject :
vrfId : 0
masterSubnetId : 0
allowRequests : 1
vlanId : 1
showName : 1
device : 0
permissions : {"3":"1","2":"2"}
pingSubnet : 0
discoverSubnet : 0
resolveDNS : 0
DNSrecursive : 0
DNSrecords : 0
nameserverId : 0
scanAgent :
customer_id :
isFolder : 0
isFull : 0
isPool : 0
tag : 2
threshold : 0
location :
editDate :
lastScan :
lastDiscovery :
calculation : @{Type=IPv6; Host address=/; Host address (uncompressed)=/; Subnet prefix=fd13:6d20:29dc:cf27::/64; Prefix length=64; Subnet Reverse DNS=7.2.f.c.c.d.9.2.0.2.d.6.3.1.d.f.ip6.arpa; Min host IP=fd13:6d20:29dc:cf27::; Max host IP=fd13:6d20:29dc:cf27:ffff:ffff:ffff:ffff; Number of hosts=18446744073709551616; Address type=NET_IPV6}

43
classlib/tag.cs Normal file
View File

@@ -0,0 +1,43 @@
namespace PS.IPAM;
public class Tag {
public int Id { get; }
public string Type { get; }
public bool ShowTag { get; }
public string BGColor { get; }
public string FGColor { get; }
public bool Compress { get; }
public bool Locked { get; }
public bool UpdateTag { get; }
public Tag(
int id,
string type,
bool showTag,
string BGColor,
string FGColor,
string compress,
string locked,
bool updateTag
) {
this.Id = id;
this.Type = type;
this.ShowTag = showTag;
this.BGColor = BGColor;
this.FGColor = FGColor;
this.Compress = this.StringToBool(compress);
this.Locked = this.StringToBool(locked);
this.UpdateTag = updateTag;
}
public override string ToString() {
return this.Type;
}
private bool StringToBool(string str) {
if (str == "Yes") {
return true;
}
return false;
}
}

View File

@@ -1,4 +1,4 @@
function Invoke-PSIPAMRequest { function Invoke-Request {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[parameter(Mandatory=$true)] [parameter(Mandatory=$true)]
@@ -10,6 +10,10 @@ function Invoke-PSIPAMRequest {
[string] [string]
$Controller, $Controller,
[parameter(Mandatory=$false)] [parameter(Mandatory=$false)]
[ValidateSet("address","tag","subnet")]
[string]
$Type,
[parameter(Mandatory=$false)]
[ValidateSet("nameservers")] [ValidateSet("nameservers")]
[string] [string]
$SubController, $SubController,
@@ -20,10 +24,10 @@ function Invoke-PSIPAMRequest {
[array] [array]
$Identifiers $Identifiers
) )
$_tokenStatus = Test-PSIPAMSession $_tokenStatus = Test-Session
if ($_tokenStatus -eq "NoToken") { throw "No session available!" } if ($_tokenStatus -eq "NoToken") { throw "No session available!" }
if ($_tokenStatus -eq "Expired") { Update-PSIPAMSession } if ($_tokenStatus -eq "Expired") { Update-Session }
$Controller = $Controller.ToLower() $Controller = $Controller.ToLower()
@@ -34,7 +38,10 @@ function Invoke-PSIPAMRequest {
$_headers = @{ $_headers = @{
"Accept" = "application/json" "Accept" = "application/json"
"Content-Type" = "application/json" "Content-Type" = "application/json"
"token" = $script:ipamToken }
switch ($script:ipamAuthType) {
"Credentials" { $_headers.Add("token", $script:ipamToken) }
"Token" { $_headers.Add("phpipam-token", $script:ipamToken) }
} }
$_arguments = @{ $_arguments = @{
@@ -57,7 +64,12 @@ function Invoke-PSIPAMRequest {
$_response = Invoke-RestMethod @_arguments $_response = Invoke-RestMethod @_arguments
if ($_response.code -match "20\d") { if ($_response.code -match "20\d") {
return $_response.data switch ($Type) {
"address" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Address" -ArgumentList $_.psobject.properties.value } }
"subnet" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Subnetwork" -ArgumentList $_.psobject.properties.value } }
"tag" { $_response.data | ForEach-Object { New-Object -TypeName "PS.IPAM.Tag" -ArgumentList $_.psobject.properties.value } }
Default { $_response.data }
}
} else { } else {
throw ("Error - $($_response.code)") throw ("Error - $($_response.code)")
} }

View File

@@ -1,15 +0,0 @@
function Test-PSIPAMSession {
[CmdletBinding()]
param (
)
if ($script:ipamToken) {
if ($script:ipamExpires -lt (Get-Date)) {
return "Expired"
} else {
return "Valid"
}
} else {
return "NoToken"
}
}

View File

@@ -0,0 +1,19 @@
function Test-Session {
[CmdletBinding()]
param (
)
if ($script:ipamToken) {
if ($script:ipamExpires -eq "Never") {
return "Valid"
} else {
if ($script:ipamExpires -lt (Get-Date)) {
return "Expired"
} else {
return "Valid"
}
}
} else {
return "NoToken"
}
}

View File

@@ -1,18 +1,18 @@
function Update-PSIPAMSession { function Update-Session {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[switch] [switch]
$Force $Force
) )
$_tokenStatus = Test-PSIPAMSession $_tokenStatus = Test-Session
if ($_tokenStatus -eq "NoToken") { if ($_tokenStatus -eq "NoToken") {
throw "No session available!" throw "No session available!"
} }
if ($_tokenStatus -eq "Valid") { if ($_tokenStatus -eq "Valid") {
return (Invoke-PSIPAMRequest -Method PATCH -Controller user).expires return (Invoke-Request -Method PATCH -Controller user).expires
} }
if ($_tokenStatus -eq "Expired" -or $Force) { if ($_tokenStatus -eq "Expired" -or $Force) {
New-PSIPAMSession -URL $script:ipamURL -AppID $script:ipamAppID -Credentials $script:ipamCredentials New-Session -URL $script:ipamURL -AppID $script:ipamAppID -Credentials $script:ipamCredentials
return $script:ipamExpires return $script:ipamExpires
} }
} }

View File

@@ -0,0 +1,68 @@
function Get-Address {
[CmdletBinding(DefaultParameterSetName="ByID")]
[OutputType('address')]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByIP")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="BySubnetId")]
[ValidateScript({[ipaddress] $_})]
[ValidateNotNullOrEmpty()]
[string]
$IP,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByHostName")]
[ValidateNotNullOrEmpty()]
[string]
$HostName,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByTag")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$TagId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetId")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SubnetId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetCIDR")]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$SubnetCIDR
)
process {
$_params = @{
Controller = "addresses"
Method = "GET"
Type = "address"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($id) }
"ByIP" { $_identifiers = ("search",$IP) }
"ByHostName" { $_identifiers = ("search_hostname",$HostName) }
"ByTag" { $_identifiers = ("tags",$TagId,"addresses") }
"BySubnetId" {
if ($IP) {
$_identifiers = ($IP,$SubnetId)
} else {
$_params.Item("Controller") = "subnets"
$_identifiers = ($SubnetId,"addresses")
}
}
"BySubnetCIDR" {
$_params.Item("Controller") = "subnets"
$_subnetId = (Get-Subnet -CIDR $SubnetCIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" }
$_identifiers = ($_subnetId,"addresses")
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember -Function Get-Address

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMFirstFreeIP { 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")]
@@ -20,14 +20,14 @@ function Get-PSIPAMFirstFreeIP {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_subnetId = $Id } "ByID" { $_subnetId = $Id }
"ByCIDR" { "ByCIDR" {
$_subnetId = (Get-PSIPAMSubnet -CIDR $CIDR).id $_subnetId = (Get-Subnet -CIDR $CIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" } if (!$_subnetId) { throw "Cannot find subnet!" }
} }
} }
$_identifiers = @($_subnetId,"first_free") $_identifiers = @($_subnetId,"first_free")
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
return Invoke-PSIPAMRequest @_params | Select-Object @{n="Ip";e={$_}} return Invoke-Request @_params | Select-Object @{n="Ip";e={$_}}
} }
} }
Export-ModuleMember -Function Get-PSIPAMFirstFreeIP Export-ModuleMember -Function Get-FirstFreeIP

View File

@@ -1,4 +1,4 @@
function Get-PSIPAML2Domain { function Get-L2Domain {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding(DefaultParameterSetName="ByID")]
param ( param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
@@ -19,8 +19,8 @@ function Get-PSIPAML2Domain {
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | ` Invoke-Request @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember -Function Get-PSIPAML2Domain Export-ModuleMember -Function Get-L2Domain

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMNameserver { 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")]
@@ -22,8 +22,8 @@ function Get-PSIPAMNameserver {
$_identifiers = @($_nameserverId) $_identifiers = @($_nameserverId)
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="address";e={$_.namesrv1}},* | Select-Object -ExcludeProperty namesrv1 | ` Invoke-Request @_params | Select-Object @{n="address";e={$_.namesrv1}},* | Select-Object -ExcludeProperty namesrv1 | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember -Function Get-PSIPAMNameserver Export-ModuleMember -Function Get-Nameserver

View File

@@ -1,26 +0,0 @@
function Get-PSIPAMTags {
[CmdletBinding()]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
[string[]]$visiblePropertiesList = @('Id','Name')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "addresses"
Method = "GET"
}
$_identifiers = @("tags")
if ($Id) { $_identifiers += $Id }
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMTags

View File

@@ -1,5 +1,5 @@
function Get-PSIPAMAddress { function Get-Permissions {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding()]
param ( param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })] [ValidateScript({ $_ -match "^\d+$" })]
@@ -55,7 +55,7 @@ function Get-PSIPAMAddress {
} }
"BySubnetCIDR" { "BySubnetCIDR" {
$_params.Item("Controller") = "subnets" $_params.Item("Controller") = "subnets"
$_subnetId = (Get-PSIPAMSubnet -CIDR $SubnetCIDR).id $_subnetId = (Get-Subnet -CIDR $SubnetCIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" } if (!$_subnetId) { throw "Cannot find subnet!" }
$_identifiers = ($_subnetId,"addresses") $_identifiers = ($_subnetId,"addresses")
@@ -63,8 +63,8 @@ function Get-PSIPAMAddress {
} }
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | ` Invoke-Request @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember -Function Get-PSIPAMAddress Export-ModuleMember -Function Get-Permissions

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMSection { function Get-Section {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding(DefaultParameterSetName="ByID")]
param ( param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")] [parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
@@ -25,8 +25,8 @@ function Get-PSIPAMSection {
} }
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | ` Invoke-Request @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember Get-PSIPAMSection Export-ModuleMember Get-Section

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMSubnet { function Get-Subnet {
[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")]
@@ -58,6 +58,7 @@ function Get-PSIPAMSubnet {
$_params = @{ $_params = @{
Controller = "subnets" Controller = "subnets"
Method = "GET" Method = "GET"
Type = "subnet"
} }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"ByCIDR" { "ByCIDR" {
@@ -82,7 +83,7 @@ function Get-PSIPAMSubnet {
} }
"BySectionName" { "BySectionName" {
$_params.Item("Controller") = "sections" $_params.Item("Controller") = "sections"
$_sectionId = (Get-PSIPAMSection -Name $SectionName).id $_sectionId = (Get-Section -Name $SectionName).id
if (!$_sectionId) { throw "Cannot find section!" } if (!$_sectionId) { throw "Cannot find section!" }
$_identifiers = @($_sectionId,"subnets") $_identifiers = @($_sectionId,"subnets")
@@ -97,7 +98,7 @@ function Get-PSIPAMSubnet {
$_params.Item("Controller") = "vlan" $_params.Item("Controller") = "vlan"
$_vlanId = $VlanId $_vlanId = $VlanId
if ($SectionId) { $_sectionId = $SectionId } if ($SectionId) { $_sectionId = $SectionId }
if ($SectionName){ $_sectionId = (Get-PSIPAMSection -Name $SectionName).id } if ($SectionName){ $_sectionId = (Get-Section -Name $SectionName).id }
$_identifiers = @($_vlanId,"subnets") $_identifiers = @($_vlanId,"subnets")
@@ -105,10 +106,10 @@ function Get-PSIPAMSubnet {
} }
"ByVlanNumber" { "ByVlanNumber" {
$_params.Item("Controller") = "vlan" $_params.Item("Controller") = "vlan"
$_vlans = Get-PSIPAMVlan -Number $VlanNumber $_vlans = Get-Vlan -Number $VlanNumber
if ($VlanDomain) { $_vlans = $_vlans | Where-Object {$_.domainId -eq $VlanDomain} } if ($VlanDomain) { $_vlans = $_vlans | Where-Object {$_.domainId -eq $VlanDomain} }
if ($SectionId) { $_sectionId = $SectionId } if ($SectionId) { $_sectionId = $SectionId }
if ($SectionName){ $_sectionId = (Get-PSIPAMSection -Name $SectionName).id } if ($SectionName){ $_sectionId = (Get-Section -Name $SectionName).id }
$_vlanId = $_vlans.vlanId $_vlanId = $_vlans.vlanId
@@ -122,8 +123,7 @@ function Get-PSIPAMSubnet {
} }
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | ` Invoke-Request @_params
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember Get-PSIPAMSubnet Export-ModuleMember Get-Subnet

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMSubnetUsage { function Get-SubnetUsage {
[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")]
@@ -19,7 +19,7 @@ function Get-PSIPAMSubnetUsage {
} }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"ByCIDR" { "ByCIDR" {
$_subnetId = (Get-PSIPAMSubnet -CIDR $CIDR).id $_subnetId = (Get-Subnet -CIDR $CIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" } if (!$_subnetId) { throw "Cannot find subnet!" }
} }
"ByID" { $_subnetId = $Id } "ByID" { $_subnetId = $Id }
@@ -27,7 +27,7 @@ function Get-PSIPAMSubnetUsage {
$_identifiers = @($_subnetId,"usage") $_identifiers = @($_subnetId,"usage")
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
return Invoke-PSIPAMRequest @_params return Invoke-Request @_params
} }
} }
Export-ModuleMember -Function Get-PSIPAMSubnetUsage Export-ModuleMember -Function Get-SubnetUsage

View File

@@ -0,0 +1,37 @@
function Get-Tag {
[CmdletBinding(DefaultParameterSetName="NoParams")]
[OutputType('tag')]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")]
[ValidateNotNullOrEmpty()]
[ps.ipam.address]
$InputObject
)
process {
$_params = @{
Controller = "addresses"
Method = "GET"
Type = "tag"
}
$_identifiers = @("tags")
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers += $Id }
"ByAddressObject" {
if ($InputObject.TagId) {
$_identifiers += $InputObject.TagId
} else {
return $null
}
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember -Function Get-Tag

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMVlan { function Get-Vlan {
[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")]
@@ -38,8 +38,8 @@ function Get-PSIPAMVlan {
} }
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="id";e={$_.vlanId}},* | Select-Object -ExcludeProperty vlanId | ` Invoke-Request @_params | Select-Object @{n="id";e={$_.vlanId}},* | Select-Object -ExcludeProperty vlanId | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember -Function Get-PSIPAMVlan Export-ModuleMember -Function Get-Vlan

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMVrf { function Get-Vrf {
[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")]
@@ -19,8 +19,8 @@ function Get-PSIPAMVrf {
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="id";e={$_.vrfId}},* | Select-Object -ExcludeProperty vrfId | ` Invoke-Request @_params | Select-Object @{n="id";e={$_.vrfId}},* | Select-Object -ExcludeProperty vrfId | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember -Function Get-PSIPAMVrf Export-ModuleMember -Function Get-Vrf

View File

@@ -1,4 +1,4 @@
function New-PSIPAMAddress { function New-Address {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[parameter( [parameter(
@@ -172,11 +172,11 @@ function New-PSIPAMAddress {
$_params.Add("Params",$_body) $_params.Add("Params",$_body)
try { try {
Invoke-PSIPAMRequest @_params Invoke-Request @_params
} }
finally { finally {
Get-PSIPAMAddress -SubnetId $SubnetId -Ip $Ip Get-Address -SubnetId $SubnetId -Ip $Ip
} }
} }
} }
Export-ModuleMember -Function New-PSIPAMAddress Export-ModuleMember -Function New-Address

View File

@@ -1,4 +1,4 @@
function New-PSIPAMFirstFreeIP { function New-FirstFreeIP {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[parameter( [parameter(
@@ -163,10 +163,10 @@ function New-PSIPAMFirstFreeIP {
$_params.Add("Params",$_body) $_params.Add("Params",$_body)
$_result = Invoke-PSIPAMRequest @_params $_result = Invoke-Request @_params
if ($_result) { if ($_result) {
Get-PSIPAMAddress -SubnetId $SubnetId -IP $_result Get-Address -SubnetId $SubnetId -IP $_result
} }
} }
} }
Export-ModuleMember -Function New-PSIPAMFirstFreeIP Export-ModuleMember -Function New-FirstFreeIP

View File

@@ -1,37 +0,0 @@
function New-PSIPAMSession {
[CmdletBinding()]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateNotNullOrEmpty()]
[string]$URL,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[string]$AppID,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2)]
[ValidateNotNullOrEmpty()]
[pscredential]$Credentials
)
$_bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credentials.Password)
$_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($_bstr)
$_uri = "$URL/api/$AppID/user"
$_auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($Credentials.UserName):$_password"))
$_headers = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
"Authorization" = "Basic $_auth"
}
$_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue
if ($_response.success -eq $true) {
$script:ipamAuth = $true
$script:ipamToken = $_response.data.token
$script:ipamAppID = $AppID
$script:ipamURL = $URL
$script:ipamCredentials = $Credentials
$script:ipamExpires = Get-Date $_response.data.expires
} else {
$_response.error
}
}
Export-ModuleMember -Function New-PSIPAMSession

View File

@@ -0,0 +1,53 @@
function New-Session {
[CmdletBinding(DefaultParameterSetName="Credentials")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateNotNullOrEmpty()]
[string]$URL,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[string]$AppID,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="Credentials")]
[ValidateNotNullOrEmpty()]
[pscredential]$Credentials,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="Token")]
[ValidateNotNullOrEmpty()]
[string]$Token,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=3)]
[switch]$IgnoreSSL = $false
)
switch ($PSCmdlet.ParameterSetName) {
"Credentials" {
$_bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credentials.Password)
$_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($_bstr)
$_uri = "$URL/api/$AppID/user"
$_auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($Credentials.UserName):$_password"))
$_headers = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
"Authorization" = "Basic $_auth"
}
$_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue
if ($_response.success -ne $true) { return $_response.error }
$script:ipamAuthType = "Credentials"
$script:ipamAuth = $true
$script:ipamToken = $_response.data.token
$script:ipamAppID = $AppID
$script:ipamURL = $URL
$script:ipamCredentials = $Credentials
$script:ipamExpires = Get-Date $_response.data.expires
}
"Token" {
$script:ipamAuthType = "Token"
$script:ipamAuth = $true
$script:ipamToken = $Token
$script:ipamAppID = $AppID
$script:ipamURL = $URL
$script:ipamExpires = "Never"
}
}
}
Export-ModuleMember -Function New-Session

View File

@@ -1,4 +1,4 @@
function New-PSIPAMSubnet { function New-Subnet {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[parameter( [parameter(
@@ -193,10 +193,10 @@ function New-PSIPAMSubnet {
$_params.Add("Params",$_body) $_params.Add("Params",$_body)
$_result = Invoke-PSIPAMRequest @_params $_result = Invoke-Request @_params
if ($_result) { if ($_result) {
return Get-PSIPAMSubnet -CIDR $_result return Get-Subnet -CIDR $_result
} }
} }
} }
Export-ModuleMember -Function New-PSIPAMSubnet Export-ModuleMember -Function New-Subnet

View File

@@ -1,4 +1,4 @@
function Remove-PSIPAMAddress { function Remove-Address {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding(DefaultParameterSetName="ByID")]
param ( param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")] [parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
@@ -29,7 +29,7 @@ function Remove-PSIPAMAddress {
} }
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params Invoke-Request @_params
} }
} }
Export-ModuleMember Remove-PSIPAMAddress Export-ModuleMember Remove-Address

View File

@@ -1,4 +1,4 @@
function Set-PSIPAMAddress { function Set-Address {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[parameter( [parameter(
@@ -162,11 +162,11 @@ function Set-PSIPAMAddress {
$_params.Add("Params",$_body) $_params.Add("Params",$_body)
try { try {
Invoke-PSIPAMRequest @_params Invoke-Request @_params
} }
finally { finally {
Get-PSIPAMAddress -Id $Id Get-Address -Id $Id
} }
} }
} }
Export-ModuleMember -Function Set-PSIPAMAddress Export-ModuleMember -Function Set-Address

75
old/address.ps1 Normal file
View File

@@ -0,0 +1,75 @@
Add-Type @'
using System;
namespace ps.ipam {
public class address {
public int Id { get; set; }
public int SubnetId { get; set; }
public string Ip { get; set; }
public bool IsGateway { get; set; }
public string Description { get; set; }
public string Hostname { get; set; }
public string MAC { get; set; }
public string Owner { get; set; }
public int TagId { get; set; }
public int DeviceId { get; set; }
public string Location { get; set; }
public int Port { get; set; }
public string Note { get; set; }
public DateTime? LastSeen { get; set; }
public bool ExcludePing { get; set; }
public int PTRignore { get; set; }
public int PTR { get; set; }
public string FirewallAddressObject { get; set; }
public DateTime? EditDate { get; set; }
public int CustomerId { get; set; }
public address(
int id,
int subnetId,
string ip,
bool is_gateway,
string description,
string hostname,
string mac,
string owner,
int tag,
int deviceId,
string location,
int port,
string note,
DateTime? lastSeen,
bool excludePing,
int PTRignore,
int PTR,
string firewallAddressObject,
DateTime? editDate,
int customer_id
) {
this.Id = id;
this.SubnetId = subnetId;
this.Ip = ip;
this.IsGateway = is_gateway;
this.Description = description;
this.Hostname = hostname;
this.MAC = mac;
this.Owner = owner;
this.TagId = tag;
this.DeviceId = deviceId;
this.Location = location;
this.Port = port;
this.Note = note;
this.EditDate = lastSeen;
this.ExcludePing = excludePing;
this.PTRignore = PTRignore;
this.PTR = PTR;
this.FirewallAddressObject = firewallAddressObject;
this.EditDate = editDate;
this.CustomerId = customer_id;
}
public override string ToString() {
return this.Ip;
}
}
}
'@

33
old/tag.ps1 Normal file
View File

@@ -0,0 +1,33 @@
class tag {
[int]$id
[string]$Type
[bool]$ShowTag
[System.Drawing.Color]$BGColor
[System.Drawing.Color]$FGColor
[bool]$Compress
[bool]$Locked
[bool]$UpdateTag
tag ([int]$id,[string]$type,[bool]$showTag,[string]$BGColor,[string]$FGColor,[string]$compress,[string]$locked,[bool]$updateTag) {
$this.id = $id
$this.Type = $type
$this.ShowTag = $showTag
$this.BGColor = $BGColor
$this.FGColor = $FGColor
$this.Compress = $this.ToBool($compress)
$this.Locked = $this.ToBool($locked)
$this.UpdateTag = $updateTag
}
[string] ToString() {
return $this.Type
}
hidden [bool]ToBool([string]$str) {
if ($str -eq "Yes") {
return $true
} else {
return $false
}
}
}

Binary file not shown.

51
types/types.ps1xml Normal file
View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>ps.ipam.address</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Ip</Name>
<Name>Hostname</Name>
<Name>Description</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
<Type>
<Name>ps.ipam.tag</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Type</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
</Types>