Git Product home page Git Product logo

phpipam-api-clients's Introduction

{php}IPAM

Website: https://phpipam.net/

Description

phpIPAM is an open-source web IP address management application. Its goal is to provide light and simple IP address management application. It is ajax-based using jQuery libraries, it uses php scripts and javascript and some HTML5/CSS3 features, so some modern browser is preferred to be able to display javascript quickly and correctly.

Links

Branches

  • MASTER: Current development release
  • 1.6: Productional branch for 1.6.x release
  • 1.5: Productional branch for 1.5.x release (obsolete)
  • 1.4: Productional branch for 1.4.x release (obsolete)
  • 1.3: Productional branch for 1.3.x release (obsolete)
  • 1.2: Productional branch for 1.2.x release (obsolete)
  • Other branches: Feature testing

Supported PHP versions

phpIPAM has been developed and tested on the following PHP versions.
The use of untested PHP versions is unsupported and may result in compatibility issues.

  • MASTER: PHP versions 7.2 to 8.3
  • 1.6.x: PHP versions 7.2 to 8.3
  • 1.5.x: PHP versions 5.4 to 7.4
  • 1.4.x: PHP versions 5.4 to 7.4
  • 1.3.x: PHP versions 5.4 to 7.1

Supported MySQL / MariaDB versions

As of v1.6.0 support for utf8mb4 is mandatory: MySQL 5.7.7+
For best performance, Common Table Expressions (CTE) query support: MySQL 8.0+ / MariaDB 10.2.1+

I forgot my Admin password!?

Just run php functions/scripts/reset-admin-password.php in the cli and enter your new password

What are the credentials for a fresh install?

The Default credentials for a new instance of phpIPAM are the same as the credentials for the demo page: Admin / ipamadmin

Docker

Community maintained docker images are available at https://hub.docker.com/u/phpipam

Changelog

See misc/CHANGELOG

Roadmap

See misc/Roadmap

Security

See SECURITY.md

Contact

[email protected]

Special thanks are going also to the Hosterdam team (http://www.hosterdam.com) for the VPS server that is used for development of phpIPAM and for demo site.

And also to all users that filed a bug report / feature report and helped with feature testing!

License

phpIPAM is released under the GPL v3 license, see misc/gpl-3.0.txt.

phpipam-api-clients's People

Contributors

cmeissner avatar josephtingiris avatar kompetenzbolzen avatar park0 avatar phpipam avatar rico29 avatar viniarck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar

phpipam-api-clients's Issues

Patch update

I try to do a Patch UPDATE of a Subnet description using CURL.
Please verify the syntax.

$API->execute ("PATCH", "subnets", array(26), array('description'=>'mytest'), $token_file);

$url = $this->api_url.$this->api_app_id.str_replace("//", "/", "/".$this->api_server_controller."/".$this->api_server_identifiers)."/"."?".http_build_query($params);

$url="https://phpipam-staging.gconnect.co.za/api/123456789/subnets/7/?description=mytest";

ERROR:
{"code":400,"success":false,"message":"Invalid parameters","time":0.005}

API: Filter do not work for filter_by subnet

ansible@server4:> curl --header 'token: FtUVhJ0XO9lFbgOYTzOaVieLMi1nor_d' -X GET "https://host/phpipam/api/api/subnets/?filter_value=10.15.0.0&filter_by=subnet" | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 81 100 81 0 0 1796 0 --:--:-- --:--:-- --:--:-- 1800
{
"code": 404,
"success": false,
"message": "No results (filter applied)",
"time": 0.014
}
ansible@server4:
>

ansible@server4:> curl --header 'token: FtUVhJ0XO9lFbgOYTzOaVieLMi1nor_d' -X GET "https://host/phpipam/api/api/subnets/?filter_value=24&filter_by=id" | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 871 100 871 0 0 18686 0 --:--:-- --:--:-- --:--:-- 18934
{
"code": 200,
"success": true,
"data": [
{
"id": "24",
"subnet": "10.15.0.0",
"mask": "19",
"sectionId": "3",
"description": "Virtuelle Maschinen",
"linked_subnet": null,
"firewallAddressObject": null,
"vrfId": null,
"masterSubnetId": "7",
"allowRequests": "0",
"vlanId": null,
"showName": "0",
"device": null,
"permissions": [
{
"group_id": 2,
"permission": "2",
"name": "Operators",
"desc": "default Operator group",
"members": false
},
{
"group_id": 3,
"permission": "1",
"name": "Guests",
"desc": "default Guest group (viewers)",
"members": false
}
],
"pingSubnet": "0",
"discoverSubnet": "0",
"resolveDNS": "0",
"DNSrecursive": "0",
"DNSrecords": "0",
"nameserverId": "0",
"scanAgent": "0",
"customer_id": null,
"isFolder": "0",
"isFull": "0",
"isPool": "0",
"tag": "2",
"threshold": "0",
"location": [],
"editDate": null,
"lastScan": null,
"lastDiscovery": null,
"links": [
{
"rel": "self",
"href": "/api/api/subnets/24/"
}
],
"custom_fields": null
}
],
"time": 0.015
}
ansible@server4:
>

Ability to get first free address based on tags

Hi,

first of all: Thanks for this awesome project! I absolutely love phpIPAM! It's a million times better than much enterprise solutions for IPAM!

I'm not sure if this is the right place to request enhancements. But I would love to be able to get the first free address from a subnet, based on a tag. The reason for this is, that you would usually categorize your subnet in different sections for different systems (i.e. .1-.10 network devices, .20-.30 printers, .50-.100 clients, etc.). The categorization may be done via tags, which are already there. Unfortunately I cannot decide from which range I would like to get the first free address. To have this ability would be awesome!
Instead of using tags, maybe it's easier to define the range of addresses, from which you want to get the first free address.

I don't know how much work this may be, but I'm sure it's worth it.

Thanks again for this cool solution!

Regards,
Sven

[Solved]Unauthorized Error

I'm tring to execute api-example.php, thi si error:
PHP Notice: Array to string conversion in /var/www/html/phpipam/functions/classes/class.phpipam-api.php on line 652
PHP Notice: Undefined variable: response_headers in /var/www/html/phpipam/functions/scripts/api-test.php on line 26
Array
(
[code] => 401
[success] =>
[message] => Unauthorized
[time] => 0.024
)

Can you help me?
Regards

[php-client/class.phpipam-api.php] can't handle exceptions

Hi

We use the php-client API , but struggling with the die() after a cURL exception:
https://github.com/phpipam/phpipam-api-clients/blob/74d67c44dd2221f880917678929c9e6b71b7c4a4/php-client/class.phpipam-api.php#LL266C15-L266C15

If the IPAM server is not reachable or other error occurs, we would like to handle the error and will react, but the script is stopping and we didn't have any option to catch the exception.

Is there a possibility to intercept this or why give the library not a result back to the main script.

ivo

return HTTP/1.1 400 Bad Request

I use curl exec is ok , but use api-clients call will return HTTP/1.1 400 Bad Request error...
who can help me....

[root@weather IPAM]# curl -X GET http://ipam.xxx.xxx.xxx/api/ipam/user/ --header 'token:h==kas7bR$eX__2TgHKyW0oO'

{"code":200,"success":true,"data":{"expires":"2018-04-14 20:24:39"},"time":0.043}

[root@IPAM]# php example.php 
* About to connect() to ipam.xxx.xxx.xxx port 80 (#0)
*   Trying 127.0.0.1...
* Connected to ipam.xxx.xxx.xxx (127.0.0.1) port 80 (#0)
> POST /api/ipam/user/ HTTP/1.1
User-Agent: phpipam-api php class
Host: ipam.xxx.xxx.xxx
Accept: */*
Authorization: Basic YXBpOm5jaHVjY25ldDIxNw==
Content-Length: -1
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

< HTTP/1.1 400 Bad Request
< Date: Sat, 14 Apr 2018 06:26:55 GMT
< Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 PHP/5.6.33
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
< 
* Closing connection 0
<?php
#api-config.php
# set error reporting
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);

# api params
$api_url    = "http://ipam.xxx.xxx.xxx/api/";     // server url
$api_app_id = "ipam";                     // application id
$api_key    = false;                       // api key - only for encrypted methods, otherwise must be false

# set username / password for authentication, not needed for encrypted communications
$api_username = "api";
$api_password = "testpassword";

# save token or not ?
#   false => dont save, check each time
#   filename => will save token to filename provided
$token_file = false;

# set result format json/object/array/xml
$result_format = "json";

?>
<?php
#example.php
# include config file and api client class file
require("api-config.php");
require("class.phpipam-api.php");
# init object with settings from
$API = new phpipam_api_client ($api_url, $api_app_id, $api_key, $api_username, $api_password, $result_format);

$API->set_debug (true);

$API->execute ("GET", "user", array(), array(), $token_file);

#  get result
$result = $API->get_result();

# print result
print_r($response_headers);
// print_r($result);
print_r(json_decode($result, true));
?>

Array marked public, listed as private

In file class.phpipam-api.php, on lines 191-201, the comment lists the access as private but the array itself is marked public. Is this an oversite or am I just missing the point of the access listing?

/**
 * To store result
 *
 * @var mixed
 * @access private
 */
public $result = array(
    "success" => true,
    "code"    => 204,
    "message" => ""
);

Assiging next free IP: Invalid request key id3

Hi,

I have just recently started using the php-api client and am trying to get upto speed with how to use it. I am having trouble assigning the next free IP address in a subnet along with properties and values, ie.. hostname, owner, tag, etc..

The call I am executing is as follows :
$API->execute ("POST", "addresses", array("first_free", 3), array("hostname"=>"api.client.hostname", "description"=>"created by API client" , "owner"=>"API_Client", "tag"=>3), $token_file);

From my understanding of the client, this is how it should be accomplished, however, I am returned the error which clearly indicates I am wrong 😆
Array ( [code] => 400 [success] => 0 [message] => Invalid request key id3 [time] => 0.025 )

Just looking for some help as to what I am doing wrong?
Any help would be appreciated.
Cheers!

New Terraform plugin (and Golang integration)

Hey @phpipam! And anyone else reading :)

Just wanted to pass along 2 new integrations that I created to help us at @paybyphone and how we work with PHPIPAM. I don't know if these are really good to submodule TBH, one of them definitely isn't and the other one is better fetched using any go package management tool or a simple go get -d.

Anyway, here we go:

Terraform Plugin

I created a Terraform plugin that you can find at https://github.com/paybyphone/terraform-provider-phpipam. There are both data sources and resources for sections, vlans, subnets, and addresses. The subnet and address data sources also have options for searching on description and hostname (and the subnet has a regex match feature as well). Detailed docs on installation and usage can be found there, in addition to downloads for both TF v0.9.x and v0.8.x for those that haven't updated yet.

Go SDK

To support the TF development efforts, and also to write a migration tool for our old pre-1.0 version, I wrote https://github.com/paybyphone/phpipam-sdk-go as well. Not everything in the API is implemented, but it's dead easy to extend to the point where writing the tests takes longer than writing the new implementations. The README is still sparse, but the godoc has tons of info on how to work with the SDK.

PHPIPAM 1.3 support?

I'll put this in phpipam/phpipam#1020 as well just for a quick update, but I have been developing against the PHPIPAM 1.2 release. Any info on when 1.3 will be out would be welcome and I'd be happy to update both the plugin and SDK to ensure that it works, if anything needed to be updated. I have tried as much as possible to follow the spec though, so if the docs on the website are up to date enough, hopefully there are no regressions.


Anyway, just wanted to pass these along! If there's anywhere I can put this info without adding a submodule, let me know and I'll do the needful! Cheers!

multiple parameters using crypt APIs

I think line 550 in class.phpipam-api.php should read
else { $this->api_server_identifiers['id'.($cnt+1)] = $i; }
instead of the current
else { $this->api_server_identifiers['id'.$i] = $i; }

Otherwise additional ids get messed up, unless I'm totally misunderstanding the way the id and parameter arrays passed to API->execute() are to be used.

The above change gives me the expected result for e.g.
$API->execute("GET", "subnets", [20,"first_free"], array(), $token_file);

Cheers.

Phpipam v 1.3 api crypt method

I have upgraded from 1.2 to 1.3 because the crypt method with multiple parameters wasn't working.
Now, in 1.3 I can't get a response from phpipam
The command is ----" curl -X GET -H "Content-Type: application/json, token: aa2ebe94307eb850a349109135b54045" -d '{"app_id":"xxx","enc_request":"ylQRQ8m4g%2BQYZKeMqwAGRKRoBatg0EI6L6tNZqkLY4Y%3D"}' teh "http://10.101.0.13/phpipam/api/"

The response is ----- {"code":400,"success":0,"message":"Invalid application id","time":0}

I have tried with the master php php-client as well, same result.
I have tried making the call from php
"$req['controller'] ="subnets"
$req['action'] = "read";
$req['format'] = "ip";
$req['id'] = "199";
$encrypted_request = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $api_key, json_encode($req), MCRYPT_MODE_ECB));
$par['enc_request'] = $encrypted_request;
$par['app_id'] = $api_app_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, count($par));
curl_setopt($ch, CURLOPT_POSTFIELDS, $par);
$result = json_decode(curl_exec($ch),true);
"

On version 1.2 was working with the url ".../phpipam/api/v1/"
Now on 1.3 the ul is url ".../phpipam/api/" .Should I do something else?

Thanks!

API cannot add nested Subnets in a existing Subnet

ansible@server4:> curl --header 'token: ...' -X POST "https://host/phpipam/api/api/subnets/?subnet=10.10.3.0&mask=24&sectionId=3&masterSubnetId=8&allowRequests=1&pingSubnet=1&discoverSubnet=1&description=10.10.3.0/24" | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 77 100 77 0 0 2054 0 --:--:-- --:--:-- --:--:-- 2081
{
"code": 400,
"success": false,
"message": "Invalid request key id2",
"time": 0.009
}
ansible@server4:
> curl --header 'token: ...' -X POST "https://host/phpipam/api/api/subnets/?subnet=10.10.3.0&mask=24&sectionId=3&masterSubnetId=0&allowRequests=1&pingSubnet=1&discoverSubnet=1&description=10.10.3.0/24" | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 140 100 140 0 0 3507 0 --:--:-- --:--:-- --:--:-- 3589
{
"code": 409,
"success": false,
"message": "Subnet 10.10.3.0/24 overlaps with 10.10.0.0/19 (Virtuelle Maschinen) in section IPv4",
"time": 0.008
}
ansible@server4:~>

The overlapping network is the MasterSubnetID 8.

Please correct it. Cannot import many nested subnets.

Can't get any subnet with php client

When I try:

$API->execute ("GET", "subnets", array("cidr", $full_subnet), array(), $token_file);

$full_subnet = '192.168.136.64/26'

here is the parameters of the api :

Array
(
[id] => cidr
[id2] => 192.168.136.64/26
[controller] => subnets
)

I get the following result :

(
[code] => 200
[success] => 0
[message] => No subnets found
[time] => 0.007
)

The subnet exist in php ipam

Auth with crypt and api key

Python API module

It would be nice to see a Python API module. Since it is greenfield, and Python 2.x is being deprecated, perhaps it could just start off with Python 3.x. being required.

Function mcrypt_encrypt() is deprecated

"php -v"
PHP 7.2.11-2+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Oct 15 2018 11:40:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.11-2+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

PHP Deprecated: Function mcrypt_encrypt() is deprecated in phpipam-api-clients/php-client/class.phpipam-api.php on line 698
Array
(
[code] => 503
[success] =>
[message] => Invalid enc_request
[time] => 0.001
)

Invalid request for subnet creation using Php Api clients

Hi,
I have a problem when i try to create a subnet after calling /api/my_app/sections/{id}/subnets/.
When i create the subnet alone without doing a get request to /api/my_app/sections/{id}/subnets/, it creates the subnet normally.
the code that is causing me a problem is this :
$this->execute('GET','sections',array("id"=>1,array('id2'=>'subnets',
//Ajout des filtres.
'filter_by'=>'description',
'filter_value'=>'subnet Infor'
),
$this->Token);
$this->execute('POST','subnets',array(),array("subnet"=>"172.13.0.32","sectionId"=>1,"mask"=>29,"masterSubnetId"=>$subnetId),
$this->Token);
my problem is when i delete the the call to return all subnets in section, it work prefectrly otherwise it gives this error :

array:4 [▼
  "code" => 400
  "success" => false
  "message" => """
    Invalid request key id2***stdClass Object


    (


        [app_id] => Wifup


        [controller] => sections


        [id] => 1


        [id2] => subnets


        [filter_by] => description


        [filter_value] => subnet Infor


        [subnet] => 172.13.0.32


        [sectionId] => 1


        [mask] => 29


        [masterSubnetId] => 31


    )


    """
  "time" => 0.023
]
I want to know why i get this error if i use the two calls and what im missing, because as i see phpipam remember the parameter sent in the first call so that is why i get the error.

Error after installation when I call the example

Hi,

I follow your recommandations but it doesn(t work for me.

Here is my output when I call the example.php after fill in the api-config.php with good informations :

php example.php

  • About to connect() to 10.10.6.1 port 80 (#0)
  • Trying 10.192.6.1…
  • Connected to 10.10.6.1 (10.192.6.1) port 80 (#0)

POST /api/myapp/user/ HTTP/1.1
User-Agent: phpipam-api php class
Host: 10.192.6.1
Accept: /
Authorization: Basic QWRtaW46YWRtaW5jbmFm
Content-Length: -1
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

  • Empty reply from server
  • Connection #0 to host 10.10.6.1 left intact
    {“code”:400,”success”:false,”message”:”Curl error: Empty reply from server”}

I don’t understand why in my output the Content-Type is not json/application !
Have you an idéa ?

I’m in master version of Ipam.
I installed the api-clients in the same server than Ipam.

I can call API with curl :
curl -X GET -H ‘token:H7Da9AAL6.dQMVHFpCKl$9QK’ ‘http://10.10.6.1/api/myapi/sections/’
{“code”:200,”success”:true,”data”:[{“id”:”5″,”name”:”Commun (N2)”,”description”:”Test \u00e0 chaque site”,”masterSection”:”0″,”permissions”:”{\”2\”:\”3\”,\”3\”:\”1\”}”,”strictMode”:”1″,”subnetOrdering”:”default”,”order”:”1″,”editDate”:”2016-09-26 13:53:41″,”showVLAN”:”1″,”showVRF”:”1″,”DNS”:null,”links”:[{“rel”:”self”,”href”:”/api/myapi/sections/5/”}]},{“id”:”3″,”name”:”Test section”,”description”:”Network Master”,”masterSection”:”0″,”permissions”:”{\”2\”:\”3\”,\”3\”:\”1\”}”,”strictMode”:”1″,”subnetOrdering”:”default”,”order”:”2″,”editDate”:”2016-09-13
…..
….

Sorry if I missed something.

No subnets found on Subnets controller

Hi,

I've been using php-client for a couple years now to sync the subnets in phpIPAM to some internal systems. Since update to phpIPAM 1.4, it started failing.

We've got this kind of structure in phpIPAM:

IPv4 (sectionId=1)
CUSTOMERS (subnetId=9)
CUST01
Subnets...
CUST02
Subnets...
...
IPv6
...

Before update, I called to something like:

    $api->execute ("GET", "subnets", [9, 'slaves'], [], $token_file);

And obtained the JSon list of cutomers from CUST01 to CUSTnn. But now I've just got: {"code":404,"success":false,"message":"No subnets found","time":0.009}

What have changed since last version? What/how I need to recode to get the "customers" list so I can grab each of it's subnets as I used to do?

Best regards!

Error after installation when I call the example

Hi,

I follow your recommandations but it doesn(t work for me.

Here is my output when I call the example.php after fill in the api-config.php with good informations :
php example.php

  • About to connect() to 10.10.6.1 port 80 (#0)
  • Trying 10.10.6.1…
  • Connected to 10.10.6.1 (10.10.6.1) port 80 (#0)

POST /api/myapp/user/ HTTP/1.1
User-Agent: phpipam-api php class
Host: 10.10.6.1
Accept: /
Authorization: Basic QWRtaW46YWRtaW5jbmFm
Content-Length: -1
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue

  • Empty reply from server
  • Connection #0 to host 10.10.6.1 left intact
    {“code”:400,”success”:false,”message”:”Curl error: Empty reply from server”}

I don’t understand why in my output the Content-Type is not json/application !
Have you an idea ?

I’m in master version of Ipam.
I installed the api-clients in the same server than Ipam.

I can call API with curl :
curl -X GET -H ‘token:H7Da9AAL6.dQMVHFpCKl$9QK’ ‘http://10.10.6.1/api/myapi/sections/’
{“code”:200,”success”:true,”data”:[{“id”:”5″,”name”:”Commun (N2)”,”description”:”Test \u00e0 chaque site”,”masterSection”:”0″,”permissions”:”{\”2\”:\”3\”,\”3\”:\”1\”}”,”strictMode”:”1″,”subnetOrdering”:”default”,”order”:”1″,”editDate”:”2016-09-26 13:53:41″,”showVLAN”:”1″,”showVRF”:”1″,”DNS”:null,”links”:[{“rel”:”self”,”href”:”/api/myapi/sections/5/”}]},{“id”:”3″,”name”:”Test section”,”description”:”Network Master”,”masterSection”:”0″,”permissions”:”{\”2\”:\”3\”,\”3\”:\”1\”}”,”strictMode”:”1″,”subnetOrdering”:”default”,”order”:”2″,”editDate”:”2016-09-13
…..
….

Sorry if I missed something.

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.