commit 26e60f4598df220b5d665c2b3ea8156d218495d5 Author: bladerunner2020 Date: Fri Mar 25 00:08:18 2016 +0300 Inital commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fe8bbd --- /dev/null +++ b/.gitignore @@ -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 + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5fa140f --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/mikrotik.html b/mikrotik.html new file mode 100644 index 0000000..74baee9 --- /dev/null +++ b/mikrotik.html @@ -0,0 +1,56 @@ + + + + + \ No newline at end of file diff --git a/mikrotik.js b/mikrotik.js new file mode 100644 index 0000000..0eef131 --- /dev/null +++ b/mikrotik.js @@ -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"} + } + }); +}; + + + + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..a91d84c --- /dev/null +++ b/package.json @@ -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 ", + "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" +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..7ea5fed --- /dev/null +++ b/readme.md @@ -0,0 +1,15 @@ +node-red-contrib-mikrotik +======================== + +Install +------- +Run command on Node-RED installation directory + + npm install node-red-contrib-mikrotik + +Config +------- + +

A Node-RED node that provides API for Mikrotik WiFi routers.

+This is an alfa verion. Available actions: log, resources, wifi, connections, reboot, raw. +