node-red-contrib-padavan 2.0.2 → 2.1.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/dist/nodes/locales/en-US/system.html +12 -5
- package/dist/nodes/locales/ru/system.html +13 -5
- package/dist/nodes/params.html +1 -1
- package/dist/nodes/params.js +1 -1
- package/dist/nodes/system.html +1 -1
- package/dist/nodes/system.js +1 -1
- package/dist/nodes/upgrade.js +1 -1
- package/package.json +2 -2
|
@@ -4,7 +4,7 @@ Performs system diagnostics and control operations.
|
|
|
4
4
|
### Inputs
|
|
5
5
|
|
|
6
6
|
- **Action** (`msg.topic`):
|
|
7
|
-
- `status`: Get system status
|
|
7
|
+
- `status`: Get system status.
|
|
8
8
|
- `log`: Get the system log.
|
|
9
9
|
- `reboot`: Reboot the router.
|
|
10
10
|
- `scan`: Scan for Wi-Fi networks (Site Survey).
|
|
@@ -15,11 +15,18 @@ Performs system diagnostics and control operations.
|
|
|
15
15
|
|
|
16
16
|
### Outputs
|
|
17
17
|
|
|
18
|
-
- `msg.payload`: The result
|
|
19
|
-
|
|
18
|
+
- `msg.payload`: The raw result object from the library.
|
|
19
|
+
- For `status`: A JSON object with raw system data.
|
|
20
|
+
- For `scan`: An array of networks.
|
|
21
|
+
- For `doctor`: An analysis object.
|
|
22
|
+
- For `log`: A string.
|
|
23
|
+
- For the `status` action, the message is also enriched with properties:
|
|
24
|
+
- `msg.uptimeStr` (`string`): A formatted uptime string (e.g., "5d 12h 30m").
|
|
25
|
+
- `msg.cpuPercent` (`number` | `null`): Calculated CPU usage.
|
|
26
|
+
- `msg.ramPercent` (`number`): Calculated RAM usage.
|
|
20
27
|
|
|
21
28
|
### Details
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
For an accurate `cpuPercent`, the `status` action should be triggered
|
|
31
|
+
regularly (e.g., every 5-10 seconds).
|
|
25
32
|
</script>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
### Входы
|
|
5
5
|
|
|
6
6
|
- **Действие** (`msg.topic`):
|
|
7
|
-
- `status`: Получить статус
|
|
7
|
+
- `status`: Получить статус системы.
|
|
8
8
|
- `log`: Получить системный журнал.
|
|
9
9
|
- `reboot`: Перезагрузить роутер.
|
|
10
10
|
- `scan`: Сканировать эфир Wi-Fi (Site Survey).
|
|
@@ -15,11 +15,19 @@
|
|
|
15
15
|
|
|
16
16
|
### Выходы
|
|
17
17
|
|
|
18
|
-
- `msg.payload`:
|
|
19
|
-
|
|
18
|
+
- `msg.payload`: "Сырой" объект с результатом от библиотеки.
|
|
19
|
+
- Для `status`: JSON-объект с системными данными.
|
|
20
|
+
- Для `scan`: Массив сетей.
|
|
21
|
+
- Для `doctor`: Объект с анализом.
|
|
22
|
+
- Для `log`: Строка.
|
|
23
|
+
- Для действия `status`, сообщение также дополняется свойствами:
|
|
24
|
+
- `msg.uptimeStr` (`string`): Отформатированная строка времени работы
|
|
25
|
+
(например, "5d 12h 30m").
|
|
26
|
+
- `msg.cpuPercent` (`number` | `null`): Рассчитанная загрузка CPU.
|
|
27
|
+
- `msg.ramPercent` (`number`): Рассчитанное использование RAM.
|
|
20
28
|
|
|
21
29
|
### Детали
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
Для корректного расчета `cpuPercent` действие `status` необходимо
|
|
32
|
+
вызывать регулярно (например, каждые 5-10 секунд).
|
|
25
33
|
</script>
|
package/dist/nodes/params.html
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
|
-
var ACTION_MODE=[" Apply "," Restart "," Reboot "," Shutdown "," Add "," Del "," ClearLog "," SystemCmd "," CommitFlash "," RestoreNVRAM "," RestoreStorage "," FreeMemory "," NTPSyncNow "," CreateCertHTTPS "," CheckCertHTTPS "," CreateCertOVPNS "," ExportConfOVPNC "," ExportWGConf "," wg_action ","Update"],SERVICE_ID=["General","LANHostConfig","IPConnection","PPPConnection","FirewallConfig","RouterConfig","WLANConfig11a","WLANConfig11b","WLANAuthentication11a","WLANAuthentication11b","Storage","IP6Connection","Layer3Forwarding"],GROUP_ID=["ManualDHCPList","VSList","GWStatic","UrlList","MFList","ACLList","rt_ACLList","RBRList","rt_RBRList","LWFilterList","VPNSACLList"];
|
|
2
|
+
var ACTION_MODE=[" Apply "," Restart "," Reboot "," Shutdown "," Add "," Del "," ClearLog "," SystemCmd "," CommitFlash "," RestoreNVRAM "," RestoreStorage "," FreeMemory "," NTPSyncNow "," CreateCertHTTPS "," CheckCertHTTPS "," CreateCertOVPNS "," ExportConfOVPNC "," ExportWGConf "," wg_action ","Update"],SERVICE_ID=["General","LANHostConfig","IPConnection","PPPConnection","FirewallConfig","RouterConfig","WLANConfig11a","WLANConfig11b","WLANAuthentication11a","WLANAuthentication11b","Storage","IP6Connection","Layer3Forwarding"],GROUP_ID=["ManualDHCPList","VSList","GWStatic","UrlList","MFList","ACLList","rt_ACLList","RBRList","rt_RBRList","LWFilterList","VPNSACLList"];function createTypedInputOptions(list){return list.map((value)=>({value,label:value.trim()}))}var RED=window.RED;RED.nodes.registerType("padavan-params",{category:"Padavan",defaults:{settings:{value:"",type:"padavan-config",required:!0},name:{value:""},topic:{value:"topic"},topicType:{value:"msg"},payload:{value:"payload"},payloadType:{value:"msg"},page:{value:""},pageType:{value:"str"},sid:{value:""},sidType:{value:"str"},group:{value:""},groupType:{value:"str"},script:{value:""},scriptType:{value:"str"},action:{value:" Apply "},actionType:{value:"str"}},icon:"font-awesome/fa-cogs",inputs:1,outputs:1,color:"#49AFCD",paletteLabel:"Params",label:function(){return this.name||"Params"},oneditprepare:function(){$("#node-input-topic").typedInput({types:["msg",{value:"action",options:[{value:"list",label:this._("params.action.list")},{value:"get",label:this._("params.action.get")},{value:"set",label:this._("params.action.set")}]}],typeField:"#node-input-topicType"}),$("#node-input-payload").typedInput({types:["msg","json","str","jsonata"],typeField:"#node-input-payloadType"}),$("#node-input-page").typedInput({types:["str","msg"],typeField:"#node-input-pageType"}),$("#node-input-sid").typedInput({types:["str","json","msg",{value:"sid",options:createTypedInputOptions(SERVICE_ID)}],typeField:"#node-input-sidType"}),$("#node-input-group").typedInput({types:["str","msg",{value:"group",options:createTypedInputOptions(GROUP_ID)}],typeField:"#node-input-groupType"}),$("#node-input-script").typedInput({types:["str","msg"],typeField:"#node-input-scriptType"}),$("#node-input-action").typedInput({types:[{value:"mode",options:createTypedInputOptions(ACTION_MODE)},"str","msg"],typeField:"#node-input-actionType"}),$("#node-input-topic").on("change",function(){let type=$("#node-input-topicType").val(),value=$("#node-input-topic").val(),isSet=type==="action"&&value==="set"||type==="msg",isList=type==="action"&&value==="list";$("#node-row-payload").toggle(!isList),$("#node-row-page").toggle(!isList),$("#node-row-sid").toggle(isSet),$("#node-row-group").toggle(isSet),$("#node-row-script").toggle(isSet),$("#node-row-action").toggle(isSet)})}});
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
<script type="text/html" data-template-name="padavan-params">
|
package/dist/nodes/params.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function L(b,q,h,k,w){return new Promise((z,B)=>{if(h==="jsonata")b.util.evaluateNodeProperty(q,h,k,w,(x,G)=>{if(x)B(x);else z(G)});else try{let x=b.util.evaluateNodeProperty(q,h,k,w);z(x)}catch(x){B(x)}})}async function J(b,q,h,k){let w=k.map(({value:z,type:B})=>L(b,z,B,q,h));return Promise.all(w)}class K{#q;#h;#b;#k;constructor(b,q,h){this.#h=b,this.#b=q,this.#q=h;let k=h.nodes.getNode(q.settings);if(k)this.#k=k.instance;else this.#h.warn("Config node not found or configured.");this.#h.on("input",this.#w.bind(this))}get client(){if(!this.#k)throw Error("Client is not initialized. Check configuration.");return this.#k.client}async#w(b,q,h){try{let[k,w,z,B,x,G,H]=await J(this.#q,this.#h,b,[{value:this.#b.topic,type:this.#b.topicType},{value:this.#b.payload,type:this.#b.payloadType},{value:this.#b.action,type:this.#b.actionType},{value:this.#b.script,type:this.#b.scriptType},{value:this.#b.sid,type:this.#b.sidType},{value:this.#b.group,type:this.#b.groupType},{value:this.#b.page,type:this.#b.pageType}]);this.#h.status({fill:"blue",shape:"dot",text:"Processing..."});let F;switch(k){case"list":{F=await this.client.getParams();break}case"get":{F=await this.client.getParams(w,H);break}case"set":{if(!w||typeof w!=="object")throw Error("Input payload missing or not an object");await this.client.setParams(w,{action_mode:z,action_script:B,sid_list:x,group_id:G,current_page:H}),F=w;break}default:throw Error(`Invalid topic: "${k}". Must be 'list', 'get', or 'set'.`)}if(F){if(!b.topic)b.topic=k;b.payload=F,q(b)}this.#h.status({}),h()}catch(k){this.#h.status({fill:"red",shape:"ring",text:"Error"}),h(k)}}}function O(b){b.nodes.registerType("padavan-params",function(q){b.nodes.createNode(this,q);let h=this;h.instance=new K(h,q,b)})}export{O as default,K as ParamsNode};
|
package/dist/nodes/system.html
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
|
-
var RED=window.RED;RED.nodes.registerType("padavan-system",{category:"Padavan",defaults:{settings:{value:"",type:"padavan-config",required:!0},name:{value:""},topic:{value:"topic"},topicType:{value:"msg"},band:{value:"2.4"},bandType:{value:"
|
|
2
|
+
var RED=window.RED;RED.nodes.registerType("padavan-system",{category:"Padavan",defaults:{settings:{value:"",type:"padavan-config",required:!0},name:{value:""},topic:{value:"topic"},topicType:{value:"msg"},band:{value:"2.4"},bandType:{value:"band"}},icon:"font-awesome/fa-server",inputs:1,outputs:1,color:"#49AFCD",paletteLabel:"System",label:function(){return this.name||"System"},oneditprepare:function(){$("#node-input-topic").typedInput({types:["msg",{value:"action",options:[{value:"status",label:this._("system.action.status")},{value:"log",label:this._("system.action.log")},{value:"reboot",label:this._("system.action.reboot")},{value:"scan",label:this._("system.action.scan")},{value:"doctor",label:this._("system.action.doctor")}]}],typeField:"#node-input-topicType"}).on("change",function(){let type=$("#node-input-topicType").val(),value=$("#node-input-topic").val(),showBand=type==="action"&&(value==="scan"||value==="doctor")||type==="msg";$("#node-input-band-row").toggle(showBand)}),$("#node-input-band").typedInput({types:[{value:"band",options:[{value:"2.4",label:"2.4 GHz"},{value:"5",label:"5 GHz"}]},"msg"],typeField:"#node-input-bandType"})}});
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
<script type="text/html" data-template-name="padavan-system">
|
package/dist/nodes/system.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{formatUptime as O}from"padavan/utils/formatting.js";function L(k,z,q,x,F){return new Promise((h,G)=>{if(q==="jsonata")k.util.evaluateNodeProperty(z,q,x,F,(B,H)=>{if(B)G(B);else h(H)});else try{let B=k.util.evaluateNodeProperty(z,q,x,F);h(B)}catch(B){G(B)}})}async function J(k,z,q,x){let F=x.map(({value:h,type:G})=>L(k,h,G,z,q));return Promise.all(F)}class K{#z;#h;#q;#x;#k=null;constructor(k,z,q){this.#h=k,this.#q=z,this.#z=q;let x=q.nodes.getNode(z.settings);if(x)this.#x=x.instance;else this.#h.warn("Config node not found or configured.");this.#h.on("input",this.#B.bind(this)),this.#h.on("close",()=>{this.#k=null})}get client(){if(!this.#x)throw Error("Client is not initialized. Check configuration.");return this.#x.client}async#B(k,z,q){try{let[x,F]=await J(this.#z,this.#h,k,[{value:this.#q.topic,type:this.#q.topicType},{value:this.#q.band,type:this.#q.bandType}]);this.#h.status({fill:"blue",shape:"dot",text:`Running ${x}...`});let h;switch(x){case"status":{if(h=await this.client.getStatus(),h.uptime)k.uptimeStr=O(h.uptime);if(h.ram?.total>0)k.ramPercent=Math.round(h.ram.used/h.ram.total*100);if(h.cpu){k.cpuPercent=null;let G=Date.now();if(this.#k&&G-this.#k.timestamp<30000){let B=h.cpu.busy-this.#k.state.busy,H=h.cpu.total-this.#k.state.total;if(H>0&&B>=0)k.cpuPercent=Math.round(B/H*100)}this.#k={state:h.cpu,timestamp:G}}break}case"log":{h=await this.client.getLog();break}case"reboot":{h=await this.client.startReboot();break}case"scan":{h=await this.client.startScan(F);break}case"doctor":{h=await this.client.getBestChannel(F);break}default:throw Error(`Invalid topic: "${x}".`)}if(h!==void 0){if(!k.topic)k.topic=x;k.payload=h,z(k)}this.#h.status({}),q()}catch(x){this.#h.status({fill:"red",shape:"ring",text:"Error"}),q(x)}}}function Q(k){k.nodes.registerType("padavan-system",function(z){k.nodes.createNode(this,z);let q=this;q.instance=new K(q,z,k)})}export{Q as default,K as SystemNode};
|
package/dist/nodes/upgrade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function F(b,w,h,k,q){return new Promise((z,B)=>{if(h==="jsonata")b.util.evaluateNodeProperty(w,h,k,q,(x,H)=>{if(x)B(x);else z(H)});else try{let x=b.util.evaluateNodeProperty(w,h,k,q);z(x)}catch(x){B(x)}})}class G{#q;#b;#h;#k;constructor(b,w,h){this.#b=b,this.#h=w,this.#q=h;let k=h.nodes.getNode(w.settings);if(k)this.#k=k.instance;else this.#b.warn("Config node not found or configured.");this.#b.on("input",this.#w.bind(this))}get client(){if(!this.#k)throw Error("Client is not initialized. Check configuration.");return this.#k.client}async#w(b,w,h){try{let k=await F(this.#q,this.#h.topic,this.#h.topicType,this.#b,b);this.#b.status({fill:"blue",shape:"dot",text:"Processing..."});let q;switch(k){case"changelog":{if(this.#b.status({fill:"blue",shape:"dot",text:"Checking updates..."}),q=await this.client.getChangelog(),q.messages&&q.messages.length>0)this.#b.status({fill:"green",shape:"dot",text:`New updates: ${q.messages.length}`});else this.#b.status({fill:"green",shape:"ring",text:"Up to date"});break}case"build":{this.#b.status({fill:"blue",shape:"dot",text:"Triggering build..."}),await this.client.startBuild(),q={status:"success",message:"Build triggered"},this.#b.status({fill:"green",shape:"dot",text:"Build started"}),setTimeout(()=>this.#b.status({}),5000);break}case"upgrade":{this.#b.status({fill:"blue",shape:"dot",text:"Downloading & Flashing..."}),await this.client.startUpgrade(),q={status:"success",message:"Firmware uploaded, router is rebooting"},this.#b.status({fill:"green",shape:"dot",text:"Rebooting..."}),setTimeout(()=>this.#b.status({}),1e4);break}default:throw Error(`Invalid topic: "${k}". Must be 'changelog', 'build', or 'upgrade'.`)}if(q){if(!b.topic)b.topic=k;b.payload=q,w(b)}h()}catch(k){this.#b.status({fill:"red",shape:"ring",text:"Error"}),h(k)}}}function J(b){b.nodes.registerType("padavan-upgrade",function(w){b.nodes.createNode(this,w);let h=this;h.instance=new G(h,w,b)})}export{J as default,G as UpgradeNode};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-padavan",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Node-RED nodes for managing routers with Padavan firmware.",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"padavan": "2.
|
|
30
|
+
"padavan": "2.1.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/bun": "^1.2.17",
|