瞎逛的时候,发现了一个IP地址管理工具,phpIPAM。看名字就知道是一个基于PHP开发的。PHP是世界上最好的@#$%^&!
先看一下官方给出的要求:

1.) Requirements before you start installing phpipam, please make sure you meet following requirements: Apache2 webserver with php support or
Nginx with php-fpm Mysql server (5.1+) PHP: version 5.3 supported to
phpipam version 1.3.1 version 5.4 version 7.2 and higher supported
from phpipam release 1.3.2 PHP modules: pdo, pdo_mysql : Adds support
for mysql connections session : Adds persistent session support
sockets : Adds sockets support openssl : Adds openSSL support gmp :
Adds support for dev-libs/gmp (GNU MP library) -> to calculate IPv6
networks ldap : Adds LDAP support (Lightweight Directory Access
Protocol – for AD also) crypt : Add support for password encryption
SimpleXML: Support for SimpleXML (optional, for RIPE queries and if
required for API) json: Enable JSON support gettext: Enables
translation filter : Adds filtering support pcntl : Add support for
process creation functions (optional, required for scanning) cli :
Enable CLI (optional, required for scanning and status checks)
mbstring : Enable mbstring support php PEAR support Usually most php
modules all are built into default php installation. If some required
modules are missing phpipam will fail with warning and notify you
about them.

You can check which php modules are enabled by issuing php -m in
command line.

直接从GitHub clone
git clone https://github.com/phpipam/phpipam.git /wwwroot/ipam
切换版本
git checkout -b 1.3 origin/1.3

配置nginx和PHP7.2
官方给出了nginx的参考配置

1.) phpIPAM version 1.3.2 and higher If you are using phpIPAM version 1.3.2 or higher please use below snippet to configure your nginx server. We assume phpipam will be on separate subfolder on webserver,
e.g. http://hostname/phpipam/, if not adjust settings accordingly.

  server {
    # root directory
    root   /var/www/;

    # phpipam
    location /phpipam/ {
        try_files $uri $uri/ /phpipam/index.php;
        index index.php;
    }
    # phpipam - api
    location /phpipam/api/ {
        try_files $uri $uri/ /phpipam/api/index.php;
    }

    # php-fpm
    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php-fpm.socket;
        fastcgi_index  index.php;
        try_files      $uri $uri/ index.php = 404;
        include        fastcgi_params;
    }  }

2.) phpIPAM up to version 1.3.1 For older phpIPAM versions please use below snippet. Again we assume phpipam will be on separate subfolder
on webserver.

server {
    # root directory
    root   /var/www/;

    # phpipam
    location /phpipam/ {
        try_files $uri $uri/ =404;
        index index.php;

        error_page 500 /app/error/index.php;
        error_page 404 /app/error/index.php;
        error_page 403 /app/error/index.php;

        rewrite ^/phpipam/login/dashboard/?$ /phpipam/dashboard/ redirect;
        rewrite ^/phpipam/logout/dashboard/?$ /phpipam/dashboard/ redirect;
        rewrite ^/phpipam/tools/search/(.*)/(.*)/(.*)/(.*)/([^/]+)$ /phpipam/index.php?page=tools§ion=search&addresses=$1&subnets=$2&vlans=$3&vrf=$4&ip=$5
last;
        rewrite ^/phpipam/tools/search/(.*) /phpipam/index.php?page=tools§ion=search&ip=$1 last;
        rewrite ^/phpipam/(.*)/(.*)/(.*)/(.*)/(.*)/([^/]+)/? /phpipam/index.php?page=$1§ion=$2&subnetId=$3&sPage=$4&ipaddrid=$5&tab=$6
last;
        rewrite ^/phpipam/(.*)/(.*)/(.*)/(.*)/([^/]+)/? /phpipam/index.php?page=$1§ion=$2&subnetId=$3&sPage=$4&ipaddrid=$5
last;
        rewrite ^/phpipam/(.*)/(.*)/(.*)/([^/]+)/? /phpipam/index.php?page=$1§ion=$2&subnetId=$3&sPage=$4 last;
        rewrite ^/phpipam/(.*)/(.*)/([^/]+)/? /phpipam/index.php?page=$1§ion=$2&subnetId=$3 last;
        rewrite ^/phpipam/(.*)/([^/]+)/? /phpipam/index.php?page=$1§ion=$2 last;
        rewrite ^/phpipam/([^/]+)/? /phpipam/index.php?page=$1 last;
    }
    # phpipam - api
    location /phpipam/api {
        rewrite ^/phpipam/api/(.*)/(.*)/(.*)/(.*)/(.*) /phpipam/api/index.php?app_id=$1&controller=$2&id=$3&id2=$4&id3=$5
last;
        rewrite ^/phpipam/api/(.*)/(.*)/(.*)/(.*) /phpipam/api/index.php?app_id=$1&controller=$2&id=$3&id2=$4 last;
        rewrite ^/phpipam/api/(.*)/(.*)/(.*) /phpipam/api/index.php?app_id=$1&controller=$2&id=$3 last;
        rewrite ^/phpipam/api/(.*)/(.*) /phpipam/api/index.php?app_id=$1&controller=$2 last;
        rewrite ^/phpipam/api/(.*) /phpipam/api/index.php?app_id=$1 last;
    }
    location /phpipam/css {
        try_files $uri $uri/ =404;
    }
    location /phpipam/js {
        try_files $uri $uri/ =404;
    }

    # php-fpm
    location ~ \.php$ {
        fastcgi_pass   unix:/var/run/php-fpm.socket;
        fastcgi_index  index.php;
        try_files      $uri $uri/ index.php = 404;
        include        fastcgi_params;
    }  }

PHP安装扩展
aptitude install php7.2-gd php-pear php7.2-pdo-mysql php7.2-mbstring php7.2-json php7.2-xml php7.2-gmp ,对LDAP有需求的可以安装php7.2-ldap

手动安装:
复制示例的config.php

3.) Initial configuration Before you start installing database files, you need to enter database details, that you will use for phpipam
connecting to database. First copy config.dist.php to config.php and
enter required details. For automatic installation phpipam will
configure database with settings you enter in config.php file, for
manual installation you will have to do it yourself.

$db['host'] = "localhost";
$db['user'] = "phpipam";
$db['pass'] = "phpipamadmin";
$db['name'] = "phpipam";

also, if you extracted
phpipam directory in any other directory than web server root folder,
you need to set that as well (BASE directive) in config.php:

define('BASE', "/");

For example, if you will have phpipam
installed in http://myserver/phpipam/ directory than set BASE as /phpipam/.

导入数据库

You can manually import sql SCHEMA file via mysql’s cli, but first you
need to create database and grant user permission (replace user/pass
with one you set in config.php):

# mysql -u root -p Enter
password:
mysql> create database phpipam;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL on phpipam.* to phpipam@localhost identified by ‘phpipamadmin’;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye

Once this is in place, you can import SCHEMA.sql file with following command:
mysql -u root -p phpipam < db/SCHEMA.sql

标签: IPAM

添加新评论