Inital commit

This commit is contained in:
bladerunner2020
2016-03-25 00:08:18 +03:00
commit 26e60f4598
6 changed files with 316 additions and 0 deletions

122
.gitignore vendored Normal file
View File

@@ -0,0 +1,122 @@
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml
## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:
# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## File-based project format:
*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
### Windows template
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
### OSX template
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

12
LICENSE Normal file
View File

@@ -0,0 +1,12 @@
Copyright (c) 2016, Alexander Pivovarov
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

56
mikrotik.html Normal file
View File

@@ -0,0 +1,56 @@
<script type="text/javascript">
RED.nodes.registerType('mikrotik',{
category: 'function',
color: '#E9967A',
defaults: {
name: {value:""},
ip : {value: ""},
action: {value:"0"}
},
credentials: {
login: {type:"text"},
pass: {type:"password"}
},
inputs:1,
outputs:1,
icon: "feed.png",
label: function() {
return this.name||"mikrotik";
}
});
</script>
<script type="text/x-red" data-template-name="mikrotik">
<div class="form-row">
<label for="node-input-ip"><i class="icon-globe"></i> IP</label>
<input type="text" id="node-input-ip" placeholder="xxx.xxx.xxx.xxx">
</div>
<div class="form-row">
<label for="node-input-login"><i class="icon-user"></i> Login</label>
<input type="text" id="node-input-login" placeholder="login">
</div>
<div class="form-row">
<label for="node-input-pass"><i class="icon-tag"></i> Pass</label>
<input type="password" id="node-input-pass" placeholder="password">
</div>
<div class="form-row">
<label for="node-input-action"><i class="icon-tasks"></i> Action</label>
<select id="node-input-action" placeholder="action">
<option value="0">Log</option>
<option value="1">System resources</option>
<option value="2">Connected WiFi</option>
<option value="3">Reboot</option>
<option value="9">Raw (use msg.payload)</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" class="paletteLabel" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="mikrotik">
<p>A node that work with Mikrotik WiFi routers.</p>
</script>

80
mikrotik.js Normal file
View File

@@ -0,0 +1,80 @@
/**
* Created by Bladerunner on 11/03/16.
*/
var mikrotik = require('mikronode');
module.exports = function(RED) {
function NodeMikrotik(config) {
RED.nodes.createNode(this,config);
this.action = config.action;
this.ip = config.ip;
this.action = config.action;
var node = this;
var ip = node.ip;
var login = node.credentials.login;
var pass = node.credentials.pass;
var action = '';
switch (parseInt(node.action)) {
case 0:
action = '/log/print';
break;
case 1:
action = '/system/resource/print';
break;
case 2:
action = '/interface/wireless/registration-table/print';
break;
case 3:
action = '/system/reboot';
break;
case 9:
action = msg.payload;
break;
}
this.on('input', function(msg) {
var connection = new mikrotik(ip, login, pass);
connection.connect(function(conn) {
var chan = conn.openChannel();
chan.write(action, function() {
chan.on('done',function(data) {
var parsed = mikrotik.parseItems(data);
var pl = [];
parsed.forEach(function(item) {
pl.push(item);
});
msg.payload = pl;
node.send(msg);
chan.close();
conn.close();
});
});
});
});
}
RED.nodes.registerType("mikrotik", NodeMikrotik, {
credentials: {
login: {type:"text"},
pass: {type:"password"}
}
});
};

31
package.json Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "node-red-contrib-mikrotik",
"version": "0.0.1",
"description": "Node to work with Mikrotik WiFi router",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Alexander Pivovarov <pivovarov@gmail.com>",
"node-red": {
"nodes": {
"mikrotik": "mikrotik.js"
}
},
"keywords": [
"node-red"
],
"license": "ISC",
"dependencies": {
"mikronode": "^0.3.3"
},
"main": "mikrotik.js",
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/bladerunner2020/node-red-contrib-mikrotik.git"
},
"bugs": {
"url": "https://github.com/bladerunner2020/node-red-contrib-mikrotik/issues"
},
"homepage": "https://github.com/bladerunner2020/node-red-contrib-mikrotik#readme"
}

15
readme.md Normal file
View File

@@ -0,0 +1,15 @@
node-red-contrib-mikrotik
========================
Install
-------
Run command on Node-RED installation directory
npm install node-red-contrib-mikrotik
Config
-------
<p>A <a href="http://nodered.org" target="_new">Node-RED</a> node that provides API for Mikrotik WiFi routers.</p>
This is an alfa verion. Available actions: log, resources, wifi, connections, reboot, raw.