该工具允许您浏览通过 UniFi 控制器 API 公开的数据,这些数据是使用 PHP、JavaScript 和 Bootstrap CSS 框架开发的。它与用于访问 UniFi 控制器 API 的 PHP 类捆绑在一起,该类比 UniFi API 浏览器工具支持更多的 API 端点。
如果您打算创建自己的 PHP 代码来与 UniFi 控制器 API 交互,建议使用独立版本的 API 客户端类,可以在 https://github.com/Art-of-WiFi/ 找到该类UniFi-API-客户端。在那里,您还可以找到有关如何使用它的示例和详细说明。
使用 UniFi API 浏览器时请记住以下几点:
由于配置文件的结构已更改,因此我们建议从 1.x 升级到 2.x 时创建全新安装。
UniFi API 浏览器工具提供以下功能:
$debug
设置为true
以启用调试模式)请注意,捆绑的 API 客户端支持更多 API 端点,但并非所有端点都适合添加到 API 浏览器。
该工具的安装非常简单。最简单的方法是使用git clone
,它也可以轻松更新:
cd
到 Web 服务器的根文件夹(在 Ubuntu 上为/var/www/html
),然后从命令提示符执行以下命令: git clone https://github.com/Art-of-WiFi/UniFi-API-browser.git
或者,您可以选择下载 zip 文件并将其解压缩到您选择的目录中,然后按照以下配置步骤进行操作。
@scyto 维护 Docker 容器,以便快速轻松地部署 UniFi API 浏览器工具。请参阅存储库中的此 Wiki 页面以获取更多详细信息。请注意,我们不提供与基于 Docker 的安装相关的支持。
config/config-template.php
的文件中配置,应将其复制/重命名为config/config.php
config/config.php
文件内的数组中config/config-template.php
文件以获取更多配置说明config/users-template.php
文件中的说明以获取更多详细信息http(s)://<server IP address>/UniFi-API-browser/
版本 2.0.7 添加了对基于 UniFi OS 的控制器(例如 UniFi Dream Machine Pro)的支持。将 UniFi OS 设备的详细信息添加到config/config.php
文件时,请确保不要在 URL 中添加端口后缀或尾部斜杠。
当使用 UniFi API 浏览器通过 WAN 接口连接到基于 UniFi 操作系统的网关上的网络应用程序时,需要创建特定的防火墙规则以允许外部访问网关本地接口上的端口 443。有关更多信息,请参阅以下博客文章了解更多详细信息:https://artofwifi.net/2022/04/07/how-to-access-the-unifi-controller-by-wan-ip-or-hostname -on-a-udm-pro/
从版本 2.0.0 开始,您可以通过将集合下拉菜单添加到config.php
文件中来使用您自己的选项来扩展集合下拉菜单。
这是一个例子:
/**
* adding a custom sub-menu example
*/
$ collections = array_merge ( $ collections , [
[
' label ' => ' Custom Menu ' , // length of this string is limited due to dropdown menu width
' options ' => [
[
' type ' => ' collection ' , // either 'collection' or 'divider'
' label ' => ' hourly site stats past 24 hours ' , // string that is displayed in the dropdown menu
' method ' => ' stat_hourly_site ' , // name of the method/function in the API client class that is called
' params ' => [( time () - ( 24 * 60 * 60 )) * 1000 , time () * 1000 ], // an array containing the parameters as they are passed to the method/function
],
[
' type ' => ' collection ' ,
' label ' => ' daily site stats past 31 days ' ,
' method ' => ' stat_daily_site ' ,
' params ' => [( time () - ( 31 * 24 * 60 * 60 )) * 1000 , time () * 1000 ],
],
[
' type ' => ' divider ' , // dividers have no other properties
],
[
' type ' => ' collection ' ,
' label ' => ' enable the site LEDs ' ,
' method ' => ' site_leds ' , // don't go too wild when adding such calls, this example is simply to show the flexibility
' params ' => [ true ]
],
[
' type ' => ' collection ' ,
' label ' => ' disable the site LEDs ' ,
' method ' => ' site_leds ' , // don't go too wild when adding such calls, this example is simply to show the flexibility
' params ' => [ false ]
],
],
],
]);
注意:对于collection
类型菜单选项, type
、 label
、 method
和params
“properties” 是必需的。
上面示例的结果如下所示:
如果您使用git clone
命令安装了该工具,则可以通过进入该工具的安装目录并从那里运行git pull
命令来应用更新。
否则,您只需将最新 zip 文件中的内容复制到该工具的安装目录即可。
与此工具捆绑在一起的 PHP API 客户端基于以下开发人员的工作:
以及 Ubiquiti 发布的 API:
其他包含的库:
警告
值得注意的是,UniFi API 浏览器工具是一个功能强大的工具,允许访问 UniFi 控制器上的敏感数据和配置选项。因此,采取适当的安全措施非常重要,例如限制受信任的个人访问该工具。此外,您应该了解与在服务器上运行 PHP 代码相关的安全风险。
我们强烈建议通过基于包含的config/users-template.php
文件创建config/users.php
来启用用户名/密码身份验证功能。在为config/users.php
文件中的条目创建密码及其 SHA512 哈希值时,请确保使用强随机密码。请参阅config/users-template.php
文件中的说明以获取更多详细信息
该项目正在积极维护,随时欢迎反馈和建议。如果您遇到任何问题或有任何改进建议,请使用 GitHub 问题列表或 Ubiquiti 社区论坛 (https://community.ubnt.com/t5/UniFi-Wireless/UniFi-API-browser-tool-released/ mp/1392651)分享您的想法和问题。
以下是该工具正在运行的几个屏幕截图。
启用用户身份验证时的登录表单:
控制器选择下拉菜单:
站点选择下拉菜单:
集合下拉菜单:
以 JSON 格式显示站点设置集合:
以交互式 PHP 格式显示站点设置集合:
“关于”模式: