prima versione qausi funzionante, non riconnette
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('mikrotik-device',{
|
RED.nodes.registerType('mikrotik-device-custom',{
|
||||||
category: 'config',
|
category: 'config',
|
||||||
defaults: {
|
defaults: {
|
||||||
host: { value: '192.168.0.1', required: true },
|
host: { value: '192.168.0.1', required: true },
|
||||||
@@ -12,11 +12,11 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.nodes.registerType('mikrotik',{
|
RED.nodes.registerType('mikrotik-custom',{
|
||||||
category: 'function',
|
category: 'function',
|
||||||
color: '#E9967A',
|
color: '#E9967A',
|
||||||
defaults: {
|
defaults: {
|
||||||
device: { value: '', type: "mikrotik-device" },
|
device: { value: '', type: "mikrotik-device-custom" },
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
action: {value:"0"}
|
action: {value:"0"}
|
||||||
},
|
},
|
||||||
@@ -24,13 +24,13 @@
|
|||||||
outputs:1,
|
outputs:1,
|
||||||
icon: "feed.png",
|
icon: "feed.png",
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.name||"mikrotik";
|
return this.name||"mikrotik-custom";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="mikrotik-device">
|
<script type="text/x-red" data-template-name="mikrotik-device-custom">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-host"><i class="fa fa-server"></i> Host</label>
|
<label for="node-config-input-host"><i class="fa fa-server"></i> Host</label>
|
||||||
<input type="text" id="node-config-input-host">
|
<input type="text" id="node-config-input-host">
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="mikrotik">
|
<script type="text/x-red" data-template-name="mikrotik-custom">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-device"><i class="fa fa-server"></i> Device</label>
|
<label for="node-input-device"><i class="fa fa-server"></i> Device</label>
|
||||||
<select id="node-input-device"></select>
|
<select id="node-input-device"></select>
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="mikrotik">
|
<script type="text/x-red" data-help-name="mikrotik-custom">
|
||||||
<p>A node that work with Mikrotik WiFi routers.</p>
|
<p>A node that work with Mikrotik WiFi routers.</p>
|
||||||
<p>Read more about RouterOs API here: <a href="http://wiki.mikrotik.com/wiki/API_command_notes" target="_blank">http://wiki.mikrotik.com/wiki/API_command_notes</a>.</p>
|
<p>Read more about RouterOs API here: <a href="http://wiki.mikrotik.com/wiki/API_command_notes" target="_blank">http://wiki.mikrotik.com/wiki/API_command_notes</a>.</p>
|
||||||
</script>
|
</script>
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
/**
|
var mikrotik = require('mikronode-ng2');
|
||||||
* Created by Bladerunner on 11/03/16.
|
|
||||||
*/
|
|
||||||
var mikrotik = require('mikronode-ng');
|
|
||||||
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
function NodeMikrotikDevice(n) {
|
function NodeMikrotikDevice(n) {
|
||||||
@@ -11,7 +8,7 @@ module.exports = function(RED) {
|
|||||||
this.username = n.username;
|
this.username = n.username;
|
||||||
this.password = n.password;
|
this.password = n.password;
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("mikrotik-device", NodeMikrotikDevice);
|
RED.nodes.registerType("mikrotik-device-custom", NodeMikrotikDevice);
|
||||||
|
|
||||||
|
|
||||||
function NodeMikrotik(config) {
|
function NodeMikrotik(config) {
|
||||||
@@ -25,7 +22,6 @@ module.exports = function(RED) {
|
|||||||
var port = this.device.port;
|
var port = this.device.port;
|
||||||
var username = this.device.username;
|
var username = this.device.username;
|
||||||
var password = this.device.password;
|
var password = this.device.password;
|
||||||
|
|
||||||
var command;
|
var command;
|
||||||
|
|
||||||
switch (parseInt(node.action)) {
|
switch (parseInt(node.action)) {
|
||||||
@@ -46,28 +42,30 @@ module.exports = function(RED) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var connection = null;
|
var connection = mikrotik.getConnection(host, username, password, {closeOnDone : false, port: port});
|
||||||
connection = mikrotik.getConnection(host, username, password, {closeOnDone : false, port: port});
|
var conn = null;
|
||||||
|
try {
|
||||||
|
conn = connection.connect();
|
||||||
|
} catch (error) {
|
||||||
|
node.error(error);
|
||||||
|
}
|
||||||
|
|
||||||
this.on('input', function(msg) {
|
this.on('input', function(msg) {
|
||||||
if (command == '') command = msg.payload;
|
if (command == '') command = msg.payload;
|
||||||
if (command == '') return false;
|
if (command == '') return false;
|
||||||
connection.getConnectPromise().then(function resolve(conn) {
|
|
||||||
conn.getCommandPromise(command).then(function resolved(values) {
|
|
||||||
var parsed = mikrotik.parseItems(values);
|
|
||||||
var pl = [];
|
|
||||||
parsed.forEach(function(item) {
|
|
||||||
pl.push(item);
|
|
||||||
});
|
|
||||||
msg.payload = values;
|
|
||||||
node.send(msg);
|
|
||||||
}, function rejected(reason) {
|
|
||||||
node.error('Error executing cmd['+command+']: ' + JSON.stringify(reason));
|
|
||||||
|
|
||||||
|
conn.getCommandPromise(command).then(
|
||||||
|
function resolved(values) { //promise resolved
|
||||||
|
var parsed = mikrotik.parseItems(values);
|
||||||
|
var pl = [];
|
||||||
|
parsed.forEach(function(item) {
|
||||||
|
pl.push(item);
|
||||||
});
|
});
|
||||||
|
msg.payload = values;
|
||||||
|
node.send(msg);
|
||||||
},
|
},
|
||||||
function(err) {
|
function notresolved(reason) { //promise rejected
|
||||||
node.error("Connection error: " + err);
|
node.error('Error executing cmd['+command+']: ' + JSON.stringify(reason));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -77,7 +75,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("mikrotik", NodeMikrotik);
|
RED.nodes.registerType("mikrotik-custom", NodeMikrotik);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-mikrotik3",
|
"name": "node-red-contrib-mikrotik-custom",
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
"description": "Node based on nodered-contrib-mikrotik to work with Mikrotik devices",
|
"description": "Node based on nodered-contrib-mikrotik to work with Mikrotik devices",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
],
|
],
|
||||||
"node-red": {
|
"node-red": {
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"mikrotik": "mikrotik.js"
|
"mikrotik": "mikrotik-custom.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -22,9 +22,9 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mikronode-ng": "^1.0.5"
|
"mikronode-ng2": "^1.0.12"
|
||||||
},
|
},
|
||||||
"main": "mikrotik.js",
|
"main": "mikrotik-custom.js",
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user