You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB
JavaScript

const express = require('express')
const { Routeros } = require("routeros-node");
const app = express()
app.get('/', function (req, res) {
res.send('Hello World')
})
async function run() {
const routeros = new Routeros({
host: "203.83.6.82",
port: 8728,
user: "admin",
password: "HYPerLINk6",
});
try {
// connect to RouterOS
const conn = await routeros.connect();
// if connected successfully will return the connected instance/socket,
console.log("conn===>", conn);
// after that we can write the query
const usersHotspot = await conn.write([
"/user-manager/user/add",
"=name=aaron",
"=password=Falz1982",
"=group=vpn"]);
console.log(usersHotspot);
} catch (error) {
// if it fails will return an error here
console.log("error===>", error);
} finally {
// dont forget to close connection
routeros.destroy();
console.log(routeros)
}
}
run();
function generateTOTPKey(length) {
const base32Characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
let key = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * base32Characters.length);
key += base32Characters.charAt(randomIndex);
}
return key;
}
console.log(generateTOTPKey(32))
app.listen(3000)