suthernfriend/mikrotik-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

suthernfriend/mikrotik-api

Composer 安装命令:

composer require suthernfriend/mikrotik-api

包简介

Comfortable Wrapper Around RouterOS Library for accessing MikroTik routers via their API

README 文档

README

A Comfortable Wrapper Around the RouterOS Library for accessing MikroTik routers via their API

Getting started

Install the package with composer

composer require suthernfriend/mikrotik-api

Create the ConnectionManager

<?php
use MikroTikApi\ConnectionManager;
use Psr\Log\LoggerInterface;

/** @var LoggerInterface $logger */
$logger = getPsrLoggerInterface();

/** @var array $config */
$config = [
    "router1" => [
        "host" => "10.1.1.1",
        "user" => "admin",
        "password" => "passwordForRouter1",
    ],
    "router2" => [
        "host" => "10.1.2.1",
        "user" => "admin",
        "password" => "passwordForRouter2",
    ]
];

$connectionManager = new ConnectionManager($logger, $config);
/* Or via Symfony Service */

services:
  MikroTikApi\ConnectionManager:
    arguments:
      $config:
        router1:
          host: 10.1.1.1
          user: admin
          password: passwordForRouter1
        router2:
          host: 10.1.2.1
          user: admin
          password: passwordForRouter2

Example use:

<?php

namespace App;

use MikroTikApi\ConnectionManager;
use MikroTikApi\DataObjectArray;
use MikroTikApi\DataObject;

/** @var ConnectionManager $connectionManager */
$connectionManager = new ConnectionManager($logger, $config);

// Read something
/** @var DataObjectArray $obj */
$obj = $connectionManager->createRequest("router1")->ip->address->print();

echo "$obj\n";
/**
 * Will print p.e. 
 * [
 *   { id: *27, address: 10.1.1.1/24, network: 10.1.1.0, interface: eth1, actualInterface: eth1, dynamic: false, invalid: false, disabled: false },
 *   { id: *2A, address: 192.168.1.1/24, network: 192.168.1.0, interface: trunk, actualInterface: trunk, dynamic: false, invalid: false, disabled: false }
 * ]
 */

// Add an object
$vlanInterface = DataObject::create([
	"name" => "myVlanInterface",
	"vlanId" => 50,
	"interface" => "trunk"
]);

$connectionManager->createRequest("router1")->interface->vlan->add($vlanInterface);

// Change an object
$query = DataObject::create([ "address" => "192.168.1.100" ]);

$lease = $connectionManager->createRequest("router1")->ip->dhcpServer->lease->print($query);
$lease->address = "192.168.1.101";

$connectionManager->createRequest("router1")->ip->dhcpServer->lease->set($lease);

// Use some other action
// without argument createRequest() will use the first ! router given by $config
$connectionManager->createRequest()->ip->dhcpServer->lease->makeStatic($lease);

General

You can use any MikroTik command by converting the command in the terminal interface to camelCase

All commands (and even new commands that may appear in a future version of RouterOS) are supported!

Examples:

  • /system reboot to $connectionManager->createRequest()->system->reboot();
  • /caps-man provisioning print to $connectionManager->createRequest()->capsMan->provisioning->print();
  • /routing ospf-v3 virtual-link remove to $connectionManager->createRequest()->routing->ospfV3->virtualLink->remove();

The same is valid for properties

<?php
$prov = $connectionManager->createRequest()->capsMan->provisioning->print(\MikroTikApi\DataObject::create(["comment" => "first-config"]))->getOne();
echo $prov->radioMac . "\n";
echo $prov->commonNameRegexp . "\n";

Values are not converted

<?php
$prov = $connectionManager->createRequest()->capsMan->provisioning->print(\MikroTikApi\DataObject::create(["comment" => "first-config"]))->getOne();
$prov->action = "create-dynamic-enabled";

Types

IP-Addresse, Mac addresses, Durations, Numbers and MikroTik Ids are converted to special instances of classes which have additional features. See the Types folder.

Bugs

I developed this for a project at work. So there is not much documentation. If there is a need feel free to ask me here or at my email and i will try my best to respond.

I'm expecting a lot of bugs in the code, since i haven't had the time to test everything. Feel free to report them or post pull-requests.

License

Apache License 2.0

suthernfriend/mikrotik-api 适用场景与选型建议

suthernfriend/mikrotik-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 suthernfriend/mikrotik-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 suthernfriend/mikrotik-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 suthernfriend/mikrotik-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 58
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2019-07-07