Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (69 loc) · 2.54 KB
/
Copy pathindex.js
File metadata and controls
79 lines (69 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const Client = require('./lib/client');
const StatusApi = require('./api/status');
const UserApi = require('./api/user');
const GroupApi = require('./api/group');
const PolicyApi = require('./api/policy');
const BindInfoApi = require('./api/bindinfo');
const OnlineUsersApi = require('./api/online-users');
/**
* 深信服 AC API SDK — 统一入口
* @class SangforAC
* @description 封装深信服 AC 设备开放接口,提供状态监控、用户管理、组管理、
* 策略查询、绑定关系、在线用户六大模块的完整能力。
*
* 认证方式:MD5 签名(共享密钥 + random),每次请求自动生成。
* 协议:HTTP RESTful,端口 9999。
*
* @example
* // 自定义配置
* const ac = new SangforAC({
* host: '10.0.0.1',
* port: 9999,
* sharedKey: 'your-shared-key',
* timeout: 5000
* });
*
* @example
* // 获取设备版本
* const ver = await ac.status.version();
* console.log(ver.data); // 'AC12.0.40.002 Build20191102'
*
* @example
* // 添加用户并绑定策略
* await ac.user.add({ name: 'test', father_path: '/' });
* await ac.user.setNetPolicy('add', 'test', ['默认策略']);
*/
class SangforAC {
/**
* 创建 SangforAC SDK 实例
* @param {Object} cfg - 配置对象
* @param {string} cfg.host - AC 设备 IP
* @param {number} cfg.port - RESTful 端口
* @param {string} cfg.sharedKey - 共享密钥
* @param {number} [cfg.timeout=10000] - 请求超时(毫秒)
* @param {string} [cfg.language='zh-CN'] - 响应语言
*/
constructor(cfg) {
if (!cfg || !cfg.host || !cfg.port || !cfg.sharedKey) {
throw new Error('SangforAC 构造函数必须提供 host、port、sharedKey');
}
/** @type {Object} 当前生效的配置 */
this.config = { timeout: 10000, language: 'zh-CN', ...cfg };
/** @type {Client} HTTP 客户端实例 */
this.client = new Client(this.config);
// 初始化各模块
/** @type {StatusApi} 设备状态监控接口 */
this.status = new StatusApi(this.client);
/** @type {UserApi} 用户管理接口 */
this.user = new UserApi(this.client);
/** @type {GroupApi} 组管理接口 */
this.group = new GroupApi(this.client);
/** @type {PolicyApi} 策略查询接口(只读) */
this.policy = new PolicyApi(this.client);
/** @type {BindInfoApi} IP/MAC 绑定关系接口 */
this.bindInfo = new BindInfoApi(this.client);
/** @type {OnlineUsersApi} 在线用户接口 */
this.onlineUsers = new OnlineUsersApi(this.client);
}
}
module.exports = SangforAC;