rosinterface 1.3.7 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +207 -171
- package/dist/client/CommandBuilder.js +0 -5
- package/dist/client/CommandBuilder.js.map +1 -1
- package/dist/client/MikrotikClient.d.ts +18 -0
- package/dist/client/MikrotikClient.js +12 -11
- package/dist/client/MikrotikClient.js.map +1 -1
- package/dist/client/MikrotikSwarm.d.ts +16 -7
- package/dist/client/MikrotikSwarm.js +16 -7
- package/dist/client/MikrotikSwarm.js.map +1 -1
- package/dist/features/DiagnosticWrapper.d.ts +58 -0
- package/dist/features/DiagnosticWrapper.js +95 -0
- package/dist/features/DiagnosticWrapper.js.map +1 -0
- package/dist/features/FirewallWrapper.d.ts +209 -0
- package/dist/features/FirewallWrapper.js +272 -0
- package/dist/features/FirewallWrapper.js.map +1 -0
- package/dist/features/IpWrapper.d.ts +140 -0
- package/dist/features/IpWrapper.js +184 -0
- package/dist/features/IpWrapper.js.map +1 -0
- package/dist/features/PPPoEWrapper.d.ts +217 -0
- package/dist/features/PPPoEWrapper.js +293 -0
- package/dist/features/PPPoEWrapper.js.map +1 -0
- package/dist/features/QueueWrapper.d.ts +118 -0
- package/dist/features/QueueWrapper.js +157 -0
- package/dist/features/QueueWrapper.js.map +1 -0
- package/dist/features/SystemWrapper.d.ts +94 -0
- package/dist/features/SystemWrapper.js +145 -0
- package/dist/features/SystemWrapper.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueueWrapper = void 0;
|
|
4
|
+
class QueueWrapper {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* **Retrieve: Simple Queues (PRINT)**
|
|
10
|
+
*
|
|
11
|
+
* Sends a `/queue/simple/print` command to list bandwidth queues.
|
|
12
|
+
*
|
|
13
|
+
* **Feature: Filtered Search**
|
|
14
|
+
* You can pass a dictionary of parameters to filter the results directly on the router,
|
|
15
|
+
* reducing network overhead and processing time.
|
|
16
|
+
*
|
|
17
|
+
* @param filter Optional dictionary to filter results (e.g., `{"?target": "192.168.10.50/32"}`).
|
|
18
|
+
* @param options Advanced write options (idempotency, forced protocol).
|
|
19
|
+
* @returns A promise resolving to an array of queue objects.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Get all configured queues
|
|
24
|
+
* const allQueues = await mk.queue.getQueues();
|
|
25
|
+
* * // Find a specific queue by its target IP
|
|
26
|
+
* const clientQueue = await mk.queue.getQueues({ "?target": "192.168.10.50/32" });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
async getQueues(filter, options) {
|
|
30
|
+
return this.client.write('/queue/simple/print', filter || {}, options);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* **Resource Creation: Simple Queue (ADD)**
|
|
34
|
+
*
|
|
35
|
+
* Sends a `/queue/simple/add` command to limit bandwidth for a specific target.
|
|
36
|
+
*
|
|
37
|
+
* **Feature: Bandwidth Allocation (QoS)**
|
|
38
|
+
* Creates basic rules to limit upload and download speeds. You can also pass
|
|
39
|
+
* additional parameters to build hierarchical QoS trees.
|
|
40
|
+
*
|
|
41
|
+
* @param name The identifier name for the queue (e.g., 'Client_John').
|
|
42
|
+
* @param target The target IP address or subnet (e.g., '192.168.10.50/32').
|
|
43
|
+
* @param maxLimit The maximum bandwidth allowed format (Upload/Download) e.g., '10M/20M'.
|
|
44
|
+
* @param additionalParams Optional dictionary for extra parameters like priority, parent queue, etc.
|
|
45
|
+
* @param options Advanced write options.
|
|
46
|
+
* @returns A promise resolving to the API response.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Create a 20 Megabit download / 10 Megabit upload limit for a single IP
|
|
51
|
+
* await mk.queue.addQueue('Client_John', '192.168.10.50/32', '10M/20M');
|
|
52
|
+
* * // Create a queue with a specific parent for hierarchical QoS
|
|
53
|
+
* await mk.queue.addQueue('Client_Jane', '192.168.10.51/32', '5M/10M', { parent: 'Main_Node' });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async addQueue(name, target, maxLimit, additionalParams, options) {
|
|
57
|
+
return this.client.write('/queue/simple/add', {
|
|
58
|
+
name,
|
|
59
|
+
target,
|
|
60
|
+
"max-limit": maxLimit,
|
|
61
|
+
...additionalParams // Spread any extra config like parent, priority, limit-at
|
|
62
|
+
}, options);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* **Resource Modification: Update Queue (SET)**
|
|
66
|
+
*
|
|
67
|
+
* Sends a `/queue/simple/set` command to modify an existing Simple Queue.
|
|
68
|
+
*
|
|
69
|
+
* **Feature: Dynamic Speed Adjustment**
|
|
70
|
+
* Automatically resolves the internal `.id` based on the target IP and applies
|
|
71
|
+
* the new parameters, allowing for on-the-fly plan upgrades/downgrades.
|
|
72
|
+
*
|
|
73
|
+
* @param target The exact target IP or subnet of the queue to modify.
|
|
74
|
+
* @param paramsToUpdate Dictionary containing the fields to update (e.g., `{"max-limit": "50M/100M"}`).
|
|
75
|
+
* @param options Advanced write options.
|
|
76
|
+
* @returns A promise resolving to the API response.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Upgrade a user's bandwidth on the fly
|
|
81
|
+
* await mk.queue.setQueueLimit('192.168.10.50/32', { "max-limit": "20M/50M" });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async setQueueLimit(target, paramsToUpdate, options) {
|
|
85
|
+
const result = await this.getQueues({ "?target": target }, options);
|
|
86
|
+
if (result.length > 0 && result[0]['.id']) {
|
|
87
|
+
return this.client.write('/queue/simple/set', {
|
|
88
|
+
".id": result[0]['.id'],
|
|
89
|
+
...paramsToUpdate // Inject new values
|
|
90
|
+
}, options);
|
|
91
|
+
}
|
|
92
|
+
throw new Error(`Queue with target '${target}' not found.`);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* **Execution Terminator: Delete Queue (REMOVE)**
|
|
96
|
+
*
|
|
97
|
+
* Sends a `/queue/simple/remove` command to permanently delete a Simple Queue.
|
|
98
|
+
*
|
|
99
|
+
* **Feature: Safe Deletion**
|
|
100
|
+
* Searches for the exact dynamic ID before attempting removal, preventing errors
|
|
101
|
+
* if the queue does not exist.
|
|
102
|
+
*
|
|
103
|
+
* @param target The exact target IP or subnet of the queue to delete.
|
|
104
|
+
* @param options Advanced write options.
|
|
105
|
+
* @returns A promise resolving to the API response.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // Remove bandwidth limits for a specific IP
|
|
110
|
+
* try {
|
|
111
|
+
* await mk.queue.removeQueue('192.168.10.50/32');
|
|
112
|
+
* console.log('Queue removed successfully');
|
|
113
|
+
* } catch (error) {
|
|
114
|
+
* console.error(error.message);
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
async removeQueue(target, options) {
|
|
119
|
+
const result = await this.getQueues({ "?target": target }, options);
|
|
120
|
+
if (result.length > 0 && result[0]['.id']) {
|
|
121
|
+
return this.client.write('/queue/simple/remove', {
|
|
122
|
+
".id": result[0]['.id']
|
|
123
|
+
}, options);
|
|
124
|
+
}
|
|
125
|
+
throw new Error(`Queue with target '${target}' not found.`);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* **Execution: Reset Statistics (RESET-COUNTERS)**
|
|
129
|
+
*
|
|
130
|
+
* Sends a `/queue/simple/reset-counters` command to clear traffic data.
|
|
131
|
+
*
|
|
132
|
+
* **Feature: Traffic Monitoring Reset**
|
|
133
|
+
* Useful for billing cycles or data cap management when you need to reset
|
|
134
|
+
* the bytes/packets counted by the router for a specific target.
|
|
135
|
+
*
|
|
136
|
+
* @param target The exact target IP or subnet of the queue to reset.
|
|
137
|
+
* @param options Advanced write options.
|
|
138
|
+
* @returns A promise resolving to the API response.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // Reset traffic statistics at the beginning of a billing cycle
|
|
143
|
+
* await mk.queue.resetCounters('192.168.10.50/32');
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
async resetCounters(target, options) {
|
|
147
|
+
const result = await this.getQueues({ "?target": target }, options);
|
|
148
|
+
if (result.length > 0 && result[0]['.id']) {
|
|
149
|
+
return this.client.write('/queue/simple/reset-counters', {
|
|
150
|
+
".id": result[0]['.id']
|
|
151
|
+
}, options);
|
|
152
|
+
}
|
|
153
|
+
throw new Error(`Queue with target '${target}' not found.`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.QueueWrapper = QueueWrapper;
|
|
157
|
+
//# sourceMappingURL=QueueWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueueWrapper.js","sourceRoot":"","sources":["../../src/features/QueueWrapper.ts"],"names":[],"mappings":";;;AAEA,MAAa,YAAY;IAGrB,YAAY,MAAsB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,SAAS,CAAC,MAA+B,EAAE,OAAuB;QACpE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,MAAM,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IAC3E,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,QAAQ,CACV,IAAY,EACZ,MAAc,EACd,QAAgB,EAChB,gBAA4D,EAC5D,OAAuB;QAEvB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE;YAC1C,IAAI;YACJ,MAAM;YACN,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;;;;;;;;OAkBG;IACH,KAAK,CAAC,aAAa,CAAC,MAAc,EAAE,OAAuB;QACvD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;QAEpE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE;gBACrD,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;aAC1B,EAAE,OAAO,CAAC,CAAC;QAChB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,MAAM,cAAc,CAAC,CAAC;IAChE,CAAC;CACJ;AA3KD,oCA2KC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { MikrotikClient, IWriteOptions } from "../client/MikrotikClient";
|
|
2
|
+
export declare class SystemWrapper {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(client: MikrotikClient);
|
|
5
|
+
/**
|
|
6
|
+
* **Retrieve: External Public IP (PRINT)**
|
|
7
|
+
*
|
|
8
|
+
* Queries the router's Cloud/DDNS service or specific interfaces to find the true external IP.
|
|
9
|
+
*
|
|
10
|
+
* **Feature: Dynamic IP Discovery & CGNAT Bypass**
|
|
11
|
+
* Inspired by `nat-api`, this method retrieves the public IP. By utilizing RouterOS's
|
|
12
|
+
* built-in `/ip/cloud`, it can often discover the true public IP even if the router
|
|
13
|
+
* is behind an ISP's NAT (CGNAT).
|
|
14
|
+
*
|
|
15
|
+
* @param forceCloud If true, forces the use of MikroTik's Cloud service to detect the IP.
|
|
16
|
+
* @param options Advanced write options (Highly recommended to use Sockets for speed here).
|
|
17
|
+
* @returns A promise resolving to the public IP address as a string.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Get the true external IP (useful for dynamic DNS updates in your app)
|
|
22
|
+
* const myPublicIp = await mk.system.getExternalIp(true);
|
|
23
|
+
* console.log(`Router is reachable at: ${myPublicIp}`);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
getExternalIp(forceCloud?: boolean, options?: IWriteOptions): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* **Retrieve: System Resources (PRINT)**
|
|
29
|
+
*
|
|
30
|
+
* Sends a `/system/resource/print` command to fetch hardware health metrics.
|
|
31
|
+
*
|
|
32
|
+
* **Feature: Real-time Telemetry**
|
|
33
|
+
* Perfect for dashboards. Returns CPU load, free memory, disk space, and total uptime.
|
|
34
|
+
*
|
|
35
|
+
* @param options Advanced write options.
|
|
36
|
+
* @returns A promise resolving to an object containing vital system metrics.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Fetch and log CPU load and uptime
|
|
41
|
+
* const resources = await mk.system.getResources();
|
|
42
|
+
* console.log(`CPU Load: ${resources[0]['cpu-load']}%`);
|
|
43
|
+
* console.log(`Uptime: ${resources[0]['uptime']}`);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
getResources(options?: IWriteOptions): Promise<any[]>;
|
|
47
|
+
/**
|
|
48
|
+
* **Execution: Generate Configuration Backup (SAVE)**
|
|
49
|
+
*
|
|
50
|
+
* Sends a `/system/backup/save` command to generate an encrypted `.backup` file.
|
|
51
|
+
*
|
|
52
|
+
* **Feature: Hybrid Protocol Advantage (REST vs Sockets)**
|
|
53
|
+
* You can force this command via REST using your `IWriteOptions`. REST is much
|
|
54
|
+
* more stable for operations that write large files to the router's NAND flash.
|
|
55
|
+
*
|
|
56
|
+
* @param name The desired name for the backup file (e.g., 'weekly-backup').
|
|
57
|
+
* @param password Optional password to encrypt the backup.
|
|
58
|
+
* @param options Advanced write options (Tip: `{ forceProtocol: 'rest' }`).
|
|
59
|
+
* @returns A promise resolving when the backup is complete.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // Generate a secure backup forcing the REST API to avoid socket timeouts
|
|
64
|
+
* await mk.system.createBackup('Example_Core_Backup', 'superSecret123', {
|
|
65
|
+
* forceProtocol: 'rest'
|
|
66
|
+
* });
|
|
67
|
+
* console.log('Backup file saved in router storage.');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
createBackup(name: string, password?: string, options?: IWriteOptions): Promise<any[]>;
|
|
71
|
+
/**
|
|
72
|
+
* **Execution Terminator: Reboot Router (REBOOT)**
|
|
73
|
+
*
|
|
74
|
+
* Sends a `/system/reboot` command.
|
|
75
|
+
*
|
|
76
|
+
* **Feature: Emergency Recovery**
|
|
77
|
+
* Restarts the operating system. The connection will be dropped immediately
|
|
78
|
+
* after executing this command.
|
|
79
|
+
*
|
|
80
|
+
* @param options Advanced write options.
|
|
81
|
+
* @returns A promise that resolves before the connection drops.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // Reboot the router at 3:00 AM for maintenance
|
|
86
|
+
* try {
|
|
87
|
+
* await mk.system.reboot();
|
|
88
|
+
* } catch (e) {
|
|
89
|
+
* console.log('Connection closed expectedly during reboot.');
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
reboot(options?: IWriteOptions): Promise<true | any[]>;
|
|
94
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SystemWrapper = void 0;
|
|
4
|
+
class SystemWrapper {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
// ==========================================
|
|
9
|
+
// NETWORK DISCOVERY (Inspired by nat-api)
|
|
10
|
+
// ==========================================
|
|
11
|
+
/**
|
|
12
|
+
* **Retrieve: External Public IP (PRINT)**
|
|
13
|
+
*
|
|
14
|
+
* Queries the router's Cloud/DDNS service or specific interfaces to find the true external IP.
|
|
15
|
+
*
|
|
16
|
+
* **Feature: Dynamic IP Discovery & CGNAT Bypass**
|
|
17
|
+
* Inspired by `nat-api`, this method retrieves the public IP. By utilizing RouterOS's
|
|
18
|
+
* built-in `/ip/cloud`, it can often discover the true public IP even if the router
|
|
19
|
+
* is behind an ISP's NAT (CGNAT).
|
|
20
|
+
*
|
|
21
|
+
* @param forceCloud If true, forces the use of MikroTik's Cloud service to detect the IP.
|
|
22
|
+
* @param options Advanced write options (Highly recommended to use Sockets for speed here).
|
|
23
|
+
* @returns A promise resolving to the public IP address as a string.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Get the true external IP (useful for dynamic DNS updates in your app)
|
|
28
|
+
* const myPublicIp = await mk.system.getExternalIp(true);
|
|
29
|
+
* console.log(`Router is reachable at: ${myPublicIp}`);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
async getExternalIp(forceCloud = true, options) {
|
|
33
|
+
if (forceCloud) {
|
|
34
|
+
// Force an update to ensure we have the latest IP from MikroTik servers
|
|
35
|
+
await this.client.write('/ip/cloud/force-update', {}, options);
|
|
36
|
+
const cloudResult = await this.client.write('/ip/cloud/print', {}, options);
|
|
37
|
+
if (cloudResult.length > 0 && cloudResult[0]['public-address']) {
|
|
38
|
+
return cloudResult[0]['public-address'].toString();
|
|
39
|
+
}
|
|
40
|
+
throw new Error('Could not retrieve public IP from MikroTik Cloud. Ensure Cloud is enabled.');
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// Fallback: Just grab the first IP that isn't a local subnet (Simplified logic)
|
|
44
|
+
const result = await this.client.write('/ip/address/print', {}, options);
|
|
45
|
+
const externalObj = result.find(r => r.address && !r.address.startsWith('192.168.') && !r.address.startsWith('10.'));
|
|
46
|
+
if (externalObj)
|
|
47
|
+
return externalObj.address.toString().split('/')[0];
|
|
48
|
+
throw new Error('No external IP found on any interface.');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// ==========================================
|
|
52
|
+
// HARDWARE & HEALTH MONITORING
|
|
53
|
+
// ==========================================
|
|
54
|
+
/**
|
|
55
|
+
* **Retrieve: System Resources (PRINT)**
|
|
56
|
+
*
|
|
57
|
+
* Sends a `/system/resource/print` command to fetch hardware health metrics.
|
|
58
|
+
*
|
|
59
|
+
* **Feature: Real-time Telemetry**
|
|
60
|
+
* Perfect for dashboards. Returns CPU load, free memory, disk space, and total uptime.
|
|
61
|
+
*
|
|
62
|
+
* @param options Advanced write options.
|
|
63
|
+
* @returns A promise resolving to an object containing vital system metrics.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Fetch and log CPU load and uptime
|
|
68
|
+
* const resources = await mk.system.getResources();
|
|
69
|
+
* console.log(`CPU Load: ${resources[0]['cpu-load']}%`);
|
|
70
|
+
* console.log(`Uptime: ${resources[0]['uptime']}`);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
async getResources(options) {
|
|
74
|
+
return this.client.write('/system/resource/print', {}, options);
|
|
75
|
+
}
|
|
76
|
+
// ==========================================
|
|
77
|
+
// MAINTENANCE & BACKUPS
|
|
78
|
+
// ==========================================
|
|
79
|
+
/**
|
|
80
|
+
* **Execution: Generate Configuration Backup (SAVE)**
|
|
81
|
+
*
|
|
82
|
+
* Sends a `/system/backup/save` command to generate an encrypted `.backup` file.
|
|
83
|
+
*
|
|
84
|
+
* **Feature: Hybrid Protocol Advantage (REST vs Sockets)**
|
|
85
|
+
* You can force this command via REST using your `IWriteOptions`. REST is much
|
|
86
|
+
* more stable for operations that write large files to the router's NAND flash.
|
|
87
|
+
*
|
|
88
|
+
* @param name The desired name for the backup file (e.g., 'weekly-backup').
|
|
89
|
+
* @param password Optional password to encrypt the backup.
|
|
90
|
+
* @param options Advanced write options (Tip: `{ forceProtocol: 'rest' }`).
|
|
91
|
+
* @returns A promise resolving when the backup is complete.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Generate a secure backup forcing the REST API to avoid socket timeouts
|
|
96
|
+
* await mk.system.createBackup('Example_Core_Backup', 'superSecret123', {
|
|
97
|
+
* forceProtocol: 'rest'
|
|
98
|
+
* });
|
|
99
|
+
* console.log('Backup file saved in router storage.');
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
async createBackup(name, password, options) {
|
|
103
|
+
const params = { name };
|
|
104
|
+
if (password)
|
|
105
|
+
params.password = password;
|
|
106
|
+
return this.client.write('/system/backup/save', params, options);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* **Execution Terminator: Reboot Router (REBOOT)**
|
|
110
|
+
*
|
|
111
|
+
* Sends a `/system/reboot` command.
|
|
112
|
+
*
|
|
113
|
+
* **Feature: Emergency Recovery**
|
|
114
|
+
* Restarts the operating system. The connection will be dropped immediately
|
|
115
|
+
* after executing this command.
|
|
116
|
+
*
|
|
117
|
+
* @param options Advanced write options.
|
|
118
|
+
* @returns A promise that resolves before the connection drops.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // Reboot the router at 3:00 AM for maintenance
|
|
123
|
+
* try {
|
|
124
|
+
* await mk.system.reboot();
|
|
125
|
+
* } catch (e) {
|
|
126
|
+
* console.log('Connection closed expectedly during reboot.');
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
async reboot(options) {
|
|
131
|
+
// We catch the error internally because MikroTik will immediately sever
|
|
132
|
+
// the TCP socket, which often throws an EOF error in Node.js.
|
|
133
|
+
try {
|
|
134
|
+
return await this.client.write('/system/reboot', {}, options);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (error.message.includes('socket hang up') || error.message.includes('closed')) {
|
|
138
|
+
return true; // Expected behavior
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.SystemWrapper = SystemWrapper;
|
|
145
|
+
//# sourceMappingURL=SystemWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemWrapper.js","sourceRoot":"","sources":["../../src/features/SystemWrapper.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IAGtB,YAAY,MAAsB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,6CAA6C;IAC7C,0CAA0C;IAC1C,6CAA6C;IAE7C;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,aAAa,CAAC,aAAsB,IAAI,EAAE,OAAuB;QACnE,IAAI,UAAU,EAAE,CAAC;YACb,wEAAwE;YACxE,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;YAC/D,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;YAE5E,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBAC7D,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE,CAAC;YACvD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;QAClG,CAAC;aAAM,CAAC;YACJ,gFAAgF;YAChF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;YACzE,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,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AAK,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC/E,OAAO,IAAI,CAAC,CAAC,oBAAoB;YACrC,CAAC;YACD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AAnJD,sCAmJC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rosinterface",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "High-performance, Offline-First Mikrotik RouterOS API Client for Enterprise.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"codegen": "ts-node src/cli/Generate.ts"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
50
51
|
"chalk": "^5.6.2",
|
|
51
52
|
"commander": "^14.0.2",
|
|
52
53
|
"dotenv": "^16.6.1",
|