Giter Club home page Giter Club logo

phpipamsync's Introduction

phpipamsync

Small script synchronizes phpipam hosts with pi-hole resolvers.

Requirement

phpipam v1.6 and above

Use case

Phpipam considered to be a source of truth for DNS resolution.

  • Network admins create hostnames in phpipam.
  • Pihole used as a DNS-server.
  • (optional) Cisco router acts as a DHCP-server

To synchronize phpipam hostanmes with pihole DNS-resolver

phpipamsync get pi-hole

phpipamsync config

Location ~/.phpipamsync/config

ipam_site_url: https://192.168.169.170:8670/                    # IP and port where phpipam exposes API endpoints
ipam_app_id: phpipamsync                                        # phpipam app id
ipam_app_code: AVyzJl7ceWJ5WrbKZ1QjAIgNdMSggw12                 # phpipam app code
ipam_subnets:                                                   # ipam subnets to synchronize
- 192.168.250.0/24
- 192.168.251.0/24

domain: home                                                    # domain to add to hostnames. For example (home will add .home to all hostnames)
pi_hole: /home/ikuchin/docker/pi.hole/etc-pihole/custom.list    # full path to pi-hole custom.list file 

ATTENTION pi-hole custom file will be rewritten, not appended.

phpipam API token

To generate API topken, in phpipam go to Administration -> API -> Create API token.

  • Type - SSL with App code token
  • App permission - Read

Important: HTTPS access should be enabled to phpipam

Cisco DHCP config

To generate DHCP config snippet for Cisco router configuration

phpipamsync get cisco-dhpc

Once snippet generated it can be copy/paste-ed to the actual router configuration. There is no integration between phpipamsync and router.

Examples

DNS resolution

e:\docs\src\go\phpipamsync>nslookup fridge.home
...
Non-authoritative answer:
Name:    fridge.home
Address:  192.168.251.13

e:\docs\src\go\phpipamsync>nslookup 192.168.251.13
...
Name:    fridge.home
Address:  192.168.251.13

Cisco IOS DHCP config

ClientID generated from either of options below:

  • MAC address (by adding prefix 01.....)
  • Custom field named ClientID ( Administration -> Custom fields -> Custom IP addresses fields )
$ phpipamsync get cisco-dhcp

ip dhcp pool fridge
 host 192.168.251.13 255.255.255.0
 client-identifier 0170.2c1f.3ed2.cb
 default-router 192.168.251.1
!
ip dhcp pool tesla
 host 192.168.251.49 255.255.255.0
 client-identifier 014c.fcaa.8ec6.62
 default-router 192.168.251.1
!

phpipamsync's People

Contributors

ivankuchin avatar

Watchers

 avatar

phpipamsync's Issues

Multiple subnets

Hi @IvanKuchin,

thanks for this program, I got it working. Does it support multiple subnets? If yes, how do you specify them in the config file?
I tried various ways but couldn't get it to work.

Thanks.

Json unmarshal error

Hi,

thanks for adding #9 so quickly. While testing, I ran into this error:

2024/01/29 14:58:26.941661 get.go:28: Error unmarshalling json: json: cannot unmarshal number into Go struct field Ipam_subnet_data.data.id of type string
Error: json: cannot unmarshal number into Go struct field Ipam_subnet_data.data.id of type string
Usage:
phpipamsync get pi-hole [flags]

Flags:
-h, --help help for pi-hole

Error: json: cannot unmarshal number into Go struct field Ipam_subnet_data.data.id of type string

I then tried it again with version 0.1.2 but got the same error. So I suspect it has to do with the update of phpipam that I did meanwhile. My phpipam version is: v1.6.0 git 97bc4d97

I have no experience with go, but I played around a little and found that I probably could get rid of the errors by setting the datatype to int for the respective variables in internal/cli/get_types.go

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.