Git Product home page Git Product logo

psphpipam's Introduction

Powershell REST Client Module For PHPIPAM

Build status

this powershell module using PHPIPAM rest api to operate PHPIPAM tasks ,powershell version suggest 3.0 or above.

this module works on powershell core 6.0 and above now ,and the test environment is mainly on linux and powershell core

# if you just want to use it , install PSPHPIPAM module

Install-Module -Name PSPHPIPAM

# list command this module provide 

get-command -module PSPHPIPAM

# get help for a command

get-help Get-PhpIpamSubnet -full

# just get example of a command

get-help Get-PhpIpamSubnet -examples

# if you want to extend the module functions, read Docs\* and Tests\* under this project to gain idears.

Alerts

No support and test with PHPIPAM 'encryped' Application security mode.

用于PHPIPAM 的Powershell REST API 客户端

该powershell 模组使用PHPIPAM REST API来操作PHPIPAM的一些任务。建议powershell 3.0 或者更高版本,目前已经支持powershell core 6.0,最新的测试环境已经移到linux 环境,并且主要使用powershell core 6.x 进行测试.

该模块的主要结构和文件说明

  • Docs 目录放置说明还有截图,而且模块的每个内置的函数也尽量包含了example 和说明,你可以使用get-help command 来获取帮助

  • Tests 目录放置pester 测试文件,该测试文件针对vagrant 搭建的phpipam 开发环境进行测试.

  • PSPHPIPAM 目录放置该模块的主要的函数\包括基础模块函数还有其他扩展的函数.如果你要扩充模块,请添加命令到Functions\Public ,参考其他的函数命令,比如Functions\Public|TestIdears

  • Nginx 是PhpIpam 测试开发环境使用的nginx 配置文件及证书,我会使用vagrant 来创建一个PHPipam 的环境,其使用docker 搭建了一个可用的Phpipam环境

- buildenv.* 可以用来创建PHPIPAM 开发测试环境,需要安装vagrant,virtualbox 参考 也可以直接使用docker-compose

Examples

Read the docs:

How to Debug

The functions in this module mainly used powershell advanced function feature (the function which contains [cmdletbinding()], so when you encounter errors ,you can add the -debug switch to see what's goging on there,you can add your write-debug expression to the function to see more information if you want.

Debug like this

New-PhpIpamSession -useCredAuth -PhpIpamApiUrl http://127.0.0.1/api -AppID script2 -userName admin -password password -debug

if you want to see raw network requests ,you can use below hacks to capture api request and response using a proxy

  1. for example you have a proxy listening at http://127.0.0.1:8088
   import-module PSPHPIPAM
   $module=Get-Module PSPHPIPAM
   # execute custom hack code in the module env
   # hack the default proxy value of invoke-restmethod command
   $module.Invoke({$PSDefaultParameterValues['invoke-restmethod:proxy']='http://127.0.0.1:8088'})
   # display $PSDefaultParameterValues in the module env
   $module.Invoke({$PSDefaultParameterValues})
   # test your code here
   Update-PhpIpamAddress -params @{id=279;description="test3";ip="127.0.0.254"}
   # the above code has not return and no error ,even using -debug param like below
   Update-PhpIpamAddress -params @{id=279;description="test3";ip="127.0.0.254"} -debug
   
   # but the log in proxy can see the detail 
   # {"code":400,"success":false,"message":"IP address cannot be changed","time":0.002}
   
   # we can see invoke-webrequest and invoke-restmethod will report simple 400 error and we can not see the error detail
   
   # the root cause of 400 return code is because. ip property is not use when patch address object 
   
   # the phpipam API doc will prove this 
   

psphpipam's People

Contributors

danubie avatar evkogan1 avatar galipolix avatar mrieder avatar shiso89 avatar yoke88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

psphpipam's Issues

Invalid enc_request

Hi,

I tried your PS library for phpIpam and I get the following error:

New-PhpIpamSession : {"code":503,"success":0,"message":"Invalid enc_request","time":0.001}
In C:\Users\foo\Desktop\ipam\test.ps1:4 Zeichen:1
+ New-PhpIpamSession -useAppKeyAuth -PhpIpamApiUrl 'https://ipam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-PhpIpamSession

The full url is https://ipam/api/?app_id=43543&enc_request=zLXkPGhy9VpOI2HpkZ8dpoZXDXtd60fbLRKk1z10R7c%3d

get data from Changelog

Hi.
Is it posible to get data from Changelog?
I need take a username who add data to IP-address

Just getting generic error when trying to start phpIpam session

`Import-Module PSPHPIPAM

new-PhpIpamSession -useAppkeyAuth -phpIpamApiURL 'https://ipam.woodmen.net/phpipam/api/' -AppID powershell -AppKey
`

All I get is the following error... doesn't give a clue where to start troubleshooting...

`new-PhpIpamSession : Exception of type 'Microsoft.PowerShell.Commands.WriteErrorException' was thrown.
At H:\windows_scripts\phpipam\phpipam-cheat.ps1:19 char:1

  • new-PhpIpamSession -useAppkeyAuth -phpIpamApiURL 'https://ipam.woodme ...
  •   + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-PhpIpamSession`
    

Get next available IP CLI

I have the PowerShell Module installed, but dont know how to use it.

How would a powershell command looks like? If I want to create a invoke restmethod?

do you have an example? and what is the api url?

thanks

Devices?

I'm working on a Powershell script that utilizes "PSDiscoveryProtocol" Module to determine the Switch that a Computer is connected to... But We don't have the Powershell CmdLet to interface the PHPIPAM Devices API..

Example:
TimeToLive : 120
Model : WS-C2960X-48FPS-L
VLAN : 1
SystemDescription : Cisco IOS Software, C2960X Software (C2960X-UNIVERSALK9-M), Version 15.2(4)E7, RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2018 by Cisco Systems, Inc.
Compiled Tue 18-Sep-18 13:07 by prod_rel_team
Port : Gi3/0/20
Device : Switch1.example.com
PortDescription : GigabitEthernet3/0/20
IPAddress : {192.168.1.3}
ChassisId : 50451370C680
Computer : GX5421.example.com
Connection : Ethernet
Interface : Realtek USB GbE Family Controller #3
Type : LLDP

So I'd like to be able to create/update the Device in IPAM

and then set the Port on the "Address"

problem using crypto

Hi i am running this :
New-PhpIpamSession -useAppKeyAuth -PhpIpamApiUrl http://192.168.1.23/api/myapp/user -appid script -appkey '76c9b896c4b48f12b51824952****'

And get this error:
New-PhpIpamSession : Cannot validate argument on parameter 'AppKey'. The argument "76c9b896c4b48f12b51824952****" does not match the "^[0-9a-fA-f]{32}$"

How to handle IP addresses entered as RANGE

image

So issue is.. When using Get-PHPIpamAddress there is no attribute to tell me that it's a range? so I that if I want via API to now break that down into individual addresses I need to remove the entry not just update..

Any thoughts?

Params format for new-phpipamAddress

I'm not having any luck with new-phpipamAddress.

`new-phpipamAddress -params @("subnetid=277";"ipaddress=172.16.12.40";"hostname=test";"MAC Address=02-00-00-00-00-01")
{"code":400,"success":0,"message":"Subnet Id must be numeric","time":0.009}
At PSPHPIPAM-master\Functions\PhpIpamBaseFunctions.ps1:257 char:13

  •         throw $_.ErrorDetails.message
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : OperationStopped: ({"code":400,"su...","time":0.009}:String) [], RuntimeException
    • FullyQualifiedErrorId : {"code":400,"success":0,"message":"Subnet Id must be numeric","time":0.009}`

Id of Folder

Hi,

I able to create a folder with:
New-PhpIpamSubnet -Params @{ description = "Test"; sectionId = 1; isFolder = 1 }

Now I´m struggling with how I can create a subnet within that folder that I´m just ceated as I´m not able to get the Id of this folder.

When I go back to the GUI and get the Id of that folder from the URL and type 'Get-PhpIPamSubnet -Id xxx' nothing is returned. When using the Id of a subnet the subnet is returned.

In addition Get-PhpIpamAllSubnets does not return any subnets/folders.

Am I´m doing anything wrong here?

Thanks
Martin

Question - First available subnet within selected for mask

Hello guys,

We used to be able to get the next free subnet and then use that to create a new one by using the command

Get-PhpIpamSubnetfirst_subnetByID

I got my laptop rebuild and after reinstalling everything including this module again I noticed this is no longer a function

I have recreated the function but is there a reason it was removed?

`
$cred = Get-Credential

$PhpIpamApiUrl = "https://<IPAM_Server>/api"
$AppID = ""

$headers = @{
    Authorization = "Basic {0}" -f $base64Token
}
$uri = "{0}/{1}/user/" -f $PhpIpamApiUrl, $AppID

$token = Invoke-RestMethod -Method post -Uri $uri -SkipCertificateCheck -Credential $cred -SkipHeaderValidation -Authentication Basic

$headers = @{
token = $token.data.token
}

Invoke-RestMethod -Method get -Uri "https://{IPAM_Server}/api/{AppID}/subnets/{ID}/first_subnet/{mask}/" -Headers $headers -SkipCertificateCheck
`

phpipam supporting Rijndael128 algorithm (AES)

Hi. I don't think you need to chase Rijndael256 for support in dotnet core. It will probably never be supported.

Additionally someone has tried to introduce the option for crypt mode to use Rijndael128 algorithm (AES) while preserving backward compatibility in phpipam/phpipam#1516. However it's not seems to have been lost in porting that stuff into a crypt class on phppiam.

Lastly phpipam has added SSL with App Token as well, meaning no need for crypt to handle the scenario of not using a user/password in scripts.

FYI Only...

Example for new-phpipamAddress

Hi,
i am having trouble understanding what params to pass to the "new-phpipamAddress" function.
Could you please give an example for this ?

Also, how am i supposed to get the SubnetID for the ip address to register ?
I only have "Get-PhpIpamSubnetByID". A function "Get-PhpIpamSubnetByIP" would be really helpful.

Thanks
Best regards!

Getting full subnet hierarchy, including folders from Get-PhpIpamSubnets

Is it possible to get the full subnet hierarchy, including folders from Get-PhpIpamSubnets?

Looking in the phpIPAM web UI, each subnet view has a "Hierarchy" display like:
Hierarchy | Section / Folder / Folder / Supernet (CIDR) / Subnet (CIDR)

Get-PhpIpamSubnets seems to return a sectionId and masterSubnetId which gets me some info, and I can construct fields like, say:

Get-PhpIpamSubnets |
Select-Object `
    @{Name = 'Subnet'; Expression = {$_.subnet+"/"+$_.mask}},
    @{Name = 'Section'; Expression = {(get-PhpIpamSection -id ([int]($_.sectionId))).name}},
    @{Name = 'Supernet_Description'; Expression = {if($_.masterSubnetId -and $_.masterSubnetId -ne 0 ){(Get-PhpIpamSubnet ([int]$_.masterSubnetId)).description}}},
    @{Name = 'Supernet'; Expression = {if($_.mastersubnetid -and $_.masterSubnetId -ne 0){(Get-PhpIpamSubnet ([int]$_.masterSubnetId)).subnet +"/"+ (Get-PhpIpamSubnet ([int]$_.masterSubnetId)).mask}}}

However, it doesn't seem like masterSubnetId registers folders, just supernets above the subnet, nor do I see any other properties returned related to folders.

Is that data just not returned by the API? If so, is there any other approaches possible to get the full hierarchy output for a subnet.

Thanks!

Adding a new Subnet

Hi there i'm trying to add a new subnet but getting an error. I used Get-PhpIpamSubnetByID to copy the object but no luck. Any help would be great:

Create the new object:

$newsubnet =@()
$object = New-Object –TypeName PSObject
$object | Add-Member –MemberType NoteProperty –Name subnet –Value '10.10.10.0'
$object | Add-Member –MemberType NoteProperty –Name mask –Value '24'
$object | Add-Member –MemberType NoteProperty –Name description –Value 'bbbb'
$object | Add-Member –MemberType NoteProperty –Name sectionId –Value '1'
#$object | Add-Member –MemberType NoteProperty –Name linked_subnet –Value '0'
$object | Add-Member –MemberType NoteProperty –Name vlanId –Value '0'
$object | Add-Member –MemberType NoteProperty –Name vrfId –Value '0'
$object | Add-Member –MemberType NoteProperty –Name masterSubnetId –Value '170'
$object | Add-Member –MemberType NoteProperty –Name nameserverId –Value '0'
$object | Add-Member –MemberType NoteProperty –Name showName –Value '0'
#$object | Add-Member –MemberType NoteProperty –Name permissions –Value
$object | Add-Member –MemberType NoteProperty –Name DNSrecursive –Value '0'
$object | Add-Member –MemberType NoteProperty –Name DNSrecords –Value '0'
$object | Add-Member –MemberType NoteProperty –Name allowRequests –Value '0'
$object | Add-Member –MemberType NoteProperty –Name scanAgent –Value '0'
$object | Add-Member –MemberType NoteProperty –Name pingSubnet –Value '0'
$object | Add-Member –MemberType NoteProperty –Name discoverSubnet –Value '0'
$object | Add-Member –MemberType NoteProperty –Name isFolder –Value '0'
$object | Add-Member –MemberType NoteProperty –Name isFull –Value '0'
$object | Add-Member –MemberType NoteProperty –Name state –Value '0'
$object | Add-Member –MemberType NoteProperty –Name threshold –Value '0'
#$object | Add-Member –MemberType NoteProperty –Name firewallAddressObject –Value '0'
$object | Add-Member –MemberType NoteProperty –Name location –Value '4'
$object | Add-Member –MemberType NoteProperty –Name device –Value '0'
$object | Add-Member –MemberType NoteProperty –Name tag –Value '0'
$object | Add-Member –MemberType NoteProperty –Name resolveDNS –Value '0'
$newsubnet += $object

Try to use the object:
New-PhpIpamSubnet -Params $newsubnet

Error:

image

New-PhpIpamSubnet : Cannot validate argument on parameter 'Params'. The "$_ -is [system.collections.hashtable]" validation script for the argument with value "@{subnet=10.10.10.0; mask=24;
description=bbbb; sectionId=1; vlanId=0; vrfId=0; masterSubnetId=170; nameserverId=0; showName=0; DNSrecursive=0; DNSrecords=0; allowRequests=0; scanAgent=0; pingSubnet=0; discoverSubnet=0;
isFolder=0; isFull=0; state=0; threshold=0; location=4; device=0; tag=0; resolveDNS=0}" did not return a result of True. Determine why the validation script failed, and then try the command
again.
At line:1 char:27

  • New-PhpIpamSubnet -Params $newsubnet
  •                       ~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [New-PhpIpamSubnet], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,New-PhpIpamSubnet

Invalid authentication with New-PhpIpamSession -useAppKeyAuth

hi, I've read several times now the documentation on https://phpipam.net/api/api_documentation/ and unfortunately I miss an example script for creating the session and a post / get call.
The docu page probably refers to an outdated Github page "To simplify deployment you can use API classes for different languages ​​available on Github - Collection of API clients for phpipam API." -> https://github.com/yoke88/PSPHPIPAM/tree/4a62b9e7018ca0bf12f3d554e1884ae3eb611440

There are newer versions on the main page: https://github.com/yoke88/PSPHPIPAM. But this brings me the same error message after a small bugfix.

Bugfix on File "New-PhpIpamSession.ps1" in line 57
[ValidateScript ({if ($ PSVersionTable.PSEdition -eq 'Core') {throw (" CrptoAuth need Rijndael256, it's not implemented in powershell core ")})]
missing the positive condition so an else {$ true} :
[ValidateScript ({if ($ PSVersionTable.PSEdition -eq 'Core') {throw ("CrptoAuth need Rijndael256, it's not implemented in powershell core")} else {$ true}})]

My call:

Import-Module PSPHPIPAM
New-PhpIpamSession -useAppKeyAuth -PhpIpamApiUrl http://server.domain.de/api -appid LocalAPI -appkey 'vidivBkZd5RsEa3VnhlkeVoV7IXDmcdq' -Debug

and my error message about that

New-PhpIpamSession : {"code":401,"success":false,"message":"Unauthorized","time":0.001}
In C:\Users\xxx\Desktop\phpIPam.ps1:3 Zeichen:1
+ New-PhpIpamSession -useAppKeyAuth -PhpIpamApiUrl http://sys-test14.hr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,New-PhpIpamSession

I use the following Powershell version

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
PSVersion                      5.1.17134.858                                                                                                                                                                                                                     
PSEdition                      Desktop                                                                                                                                                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                           
BuildVersion                   10.0.17134.858                                                                                                                                                                                                                    
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                   
WSManStackVersion              3.0                                                                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                               
SerializationVersion           1.1.0.1  

Can someone tell me if I control the module incorrectly or if there is an error here?

Additional check in Disable-CertsCheck.ps1 ('TrustAllCertsPolicy' already exists)

Hello,

My script already disables cert check at the beginning in the same way.
Later, in the middle of the script, I try to import the PSPHPIPAM module and receive the error below:

add-type : Cannot add type. The type name 'TrustAllCertsPolicy' already exists.
At C:\Program 
Files\WindowsPowerShell\Modules\PSPHPIPAM\1.3.2\Functions\Private\Disable-CertsCheck.ps1:14 char:9

Is it possible to add one additional check for this type? Something like this:

if (-not ("TrustAllCertsPolicy" -as [type])) {
        Add-Type ...
        [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.