Skip to content

Commit

Permalink
Add variable session timeout (#14)
Browse files Browse the repository at this point in the history
* Added config setting for session timeout

* Bump to version 1.3.0
  • Loading branch information
zinen authored Aug 10, 2022
1 parent 07906b1 commit 15dbf9f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
52 changes: 30 additions & 22 deletions huawei-router/huawei-router.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script type="text/javascript">
RED.nodes.registerType('huawei-config',{
RED.nodes.registerType('huawei-config', {
category: 'config',
defaults: {
user: { value: "admin", required: true },
pass: { value: "", required: true },
url: { value: "192.168.1.1", required: true }
url: { value: "192.168.1.1", required: true },
sessionTimeout: { value: "" }
},
label: function() {
return this.user+"@"+this.url;
label: function () {
return this.user + "@" + this.url;
}
});
</script>
Expand All @@ -25,15 +26,22 @@
<label for="node-config-input-url"><i class="fa fa-globe"></i> URL of router</label>
<input type="text" id="node-config-input-url" placeholder="Eg. 192.168.0.45">
</div>
<div class="form-row">
<label for="node-config-input-sessionTimeout"><i class="fa fa-globe"></i> Optional: Session timeout</label>
<input type="number" id="node-config-input-sessionTimeout" placeholder="Defaults to 298 seconds">
</div>
<div class="form-tips">
Find the exact session timeout of your router by opening the webpage, login and time when the automatic logout happends if you dont click anything.
</div>
</script>

<script type="text/javascript">
RED.nodes.registerType('huawei-lanhosts', {
category: 'homesmart',
color: '#E5766A',
defaults: {
name: {value:""},
server: {type:"huawei-config", required:true}
name: { value: "" },
server: { type: "huawei-config", required: true }
},
inputs: 1,
outputs: 1,
Expand Down Expand Up @@ -79,9 +87,9 @@ <h3>Output</h3>
category: 'homesmart',
color: '#E5766A',
defaults: {
name: {value:""},
server: {type:"huawei-config", required:true},
mode: { value: "off-on"}
name: { value: "" },
server: { type: "huawei-config", required: true },
mode: { value: "off-on" }
},
inputs: 1,
outputs: 1,
Expand Down Expand Up @@ -156,8 +164,8 @@ <h3>Output</h3>
category: 'homesmart',
color: '#E5766A',
defaults: {
name: {value:""},
server: {type:"huawei-config", required:true}
name: { value: "" },
server: { type: "huawei-config", required: true }
},
inputs: 1,
outputs: 1,
Expand Down Expand Up @@ -202,8 +210,8 @@ <h3>Output</h3>
category: 'homesmart',
color: '#E5766A',
defaults: {
name: {value:""},
server: {type:"huawei-config", required:true}
name: { value: "" },
server: { type: "huawei-config", required: true }
},
inputs: 1,
outputs: 1,
Expand Down Expand Up @@ -248,8 +256,8 @@ <h3>Output</h3>
category: 'homesmart',
color: '#E5766A',
defaults: {
name: {value:""},
server: {type:"huawei-config", required:true}
name: { value: "" },
server: { type: "huawei-config", required: true }
},
inputs: 1,
outputs: 1,
Expand Down Expand Up @@ -290,10 +298,10 @@ <h3>Output</h3>
category: 'homesmart',
color: '#E5766A',
defaults: {
name: {value:""},
server: {type:"huawei-config", required:true},
phoneNumber: { value: ""},
message: {value:""}
name: { value: "" },
server: { type: "huawei-config", required: true },
phoneNumber: { value: "" },
message: { value: "" }
},
inputs: 1,
outputs: 1,
Expand Down Expand Up @@ -364,9 +372,9 @@ <h3>Output</h3>
category: 'homesmart',
color: '#E5766A',
defaults: {
name: {value:""},
server: {type:"huawei-config", required:true},
infoOption: {value:"Monitor-status"}
name: { value: "" },
server: { type: "huawei-config", required: true },
infoOption: { value: "Monitor-status" }
},
inputs: 1,
outputs: 1,
Expand Down
20 changes: 10 additions & 10 deletions huawei-router/huawei-router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (RED) {
'use strict'
const huaweiLteApi = require('huawei-lte-api')
function HuaweiConfig (n) {
function HuaweiConfig(n) {
RED.nodes.createNode(this, n)
const node = this
node.connect = async function () {
Expand All @@ -12,7 +12,7 @@ module.exports = function (RED) {
this.connection = null
}
// Add 298 seconds to current time as timeout
this.sessionTimeout = node.now + 298000
this.sessionTimeout = n.sessionTimeout ? node.now + n.sessionTimeout * 1000 : node.now + 298000
if (!this.connection) {
// Make new session
this.connection = new huaweiLteApi.Connection(`http://${n.user}:${n.pass}@${n.url}`)
Expand Down Expand Up @@ -44,7 +44,7 @@ module.exports = function (RED) {
}
RED.nodes.registerType('huawei-config', HuaweiConfig)

function HuaweiLanHosts (config) {
function HuaweiLanHosts(config) {
RED.nodes.createNode(this, config)
const node = this
node.on('input', async function (msg, send, done) {
Expand All @@ -69,7 +69,7 @@ module.exports = function (RED) {
}
RED.nodes.registerType('huawei-lanhosts', HuaweiLanHosts)

function HuaweiMobileData (config) {
function HuaweiMobileData(config) {
RED.nodes.createNode(this, config)
const node = this
node.mode = config.mode
Expand Down Expand Up @@ -124,7 +124,7 @@ module.exports = function (RED) {
}
RED.nodes.registerType('huawei-mobiledata', HuaweiMobileData)

function HuaweiSignal (config) {
function HuaweiSignal(config) {
RED.nodes.createNode(this, config)
const node = this
node.on('input', async function (msg, send, done) {
Expand All @@ -149,7 +149,7 @@ module.exports = function (RED) {
}
RED.nodes.registerType('huawei-signal', HuaweiSignal)

function HuaweiWlanHosts (config) {
function HuaweiWlanHosts(config) {
RED.nodes.createNode(this, config)
const node = this
node.on('input', async function (msg, send, done) {
Expand All @@ -174,7 +174,7 @@ module.exports = function (RED) {
}
RED.nodes.registerType('huawei-wlanhosts', HuaweiWlanHosts)

function HuaweiReboot (config) {
function HuaweiReboot(config) {
RED.nodes.createNode(this, config)
const node = this
node.on('input', async function (msg, send, done) {
Expand All @@ -198,12 +198,12 @@ module.exports = function (RED) {
})
}
RED.nodes.registerType('huawei-reboot', HuaweiReboot)
function HuaweiSMSSend (config) {
function HuaweiSMSSend(config) {
RED.nodes.createNode(this, config)
const node = this
node.phoneNumber = config.phoneNumber
node.on('input', async function (msg, send, done) {
function parseNumber (inputNumber) {
function parseNumber(inputNumber) {
if (typeof inputNumber === 'string') {
return [inputNumber]
} else if (typeof inputNumber === 'number') {
Expand Down Expand Up @@ -248,7 +248,7 @@ module.exports = function (RED) {
})
}
RED.nodes.registerType('huawei-sms-send', HuaweiSMSSend)
function HuaweiInfo (config) {
function HuaweiInfo(config) {
RED.nodes.createNode(this, config)
const node = this
node.infoOption = config.infoOption
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-huawei-router",
"version": "1.2.2",
"version": "1.3.0",
"description": "",
"scripts": {
"pretest": "npm install node-red-node-test-helper node-red mocha --no-save",
Expand Down Expand Up @@ -46,4 +46,4 @@
"engines": {
"node": ">=12.0.0"
}
}
}

0 comments on commit 15dbf9f

Please sign in to comment.