Add hostmask checking and options set command
This commit is contained in:
parent
6b43670b36
commit
d07923361a
23
bot.js
23
bot.js
@ -43,11 +43,25 @@ function consoleLog(log) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openPostWorker(chan, command, d1, d2, d3, d4, d5) {
|
var hostmask = null
|
||||||
|
|
||||||
|
function checkUserHostmask(user) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
setTimeout(() => {
|
||||||
|
bot.whois(user, function(callback) {
|
||||||
|
hostmask = callback.user+"@"+callback.host
|
||||||
|
consoleLog('[main.checkUserHostmask] User hostmask is '+hostmask)
|
||||||
|
resolve(hostmask)
|
||||||
|
})
|
||||||
|
}, 750)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPostWorker(chan, command, d1, d2, d3, d4, d5, d6) {
|
||||||
consoleLog(`[bot.openPostWorker] Opening ${command} worker`)
|
consoleLog(`[bot.openPostWorker] Opening ${command} worker`)
|
||||||
const worker = new Worker(`./commands/${command}.js`, {
|
const worker = new Worker(`./commands/${command}.js`, {
|
||||||
workerData: {
|
workerData: {
|
||||||
d1, d2, d3, d4, d5
|
d1, d2, d3, d4, d5, d6
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
worker.once('message', (string) => {
|
worker.once('message', (string) => {
|
||||||
@ -61,7 +75,10 @@ async function help(chan, sub) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function opt(chan, user, setting, setting2, value, value2) {
|
async function opt(chan, user, setting, setting2, value, value2) {
|
||||||
openPostWorker(chan, 'options', user, setting, setting2, value, value2)
|
if (setting == 'set' || setting == "get") {
|
||||||
|
await checkUserHostmask(user)
|
||||||
|
}
|
||||||
|
openPostWorker(chan, 'options', user, setting, setting2, value, value2, hostmask)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function feed(chan, nick, provfeed, n) {
|
async function feed(chan, nick, provfeed, n) {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
const config = require('../config/default.json')
|
const config = require('../config/default.json')
|
||||||
const uconfig = require('../config/usersettings.json')
|
const uconfig = require('../config/usersettings.json')
|
||||||
const { parentPort, workerData } = require('worker_threads');
|
const { parentPort, workerData } = require('worker_threads');
|
||||||
const { d1, d2, d3, d4, d5 } = workerData;
|
const { d1, d2, d3, d4, d5, d6 } = workerData;
|
||||||
var user = d1;
|
var user = d1;
|
||||||
var setting = d2;
|
var setting = d2;
|
||||||
var setting2 = d3;
|
var setting2 = d3;
|
||||||
var value = d4;
|
var value = d4;
|
||||||
var value2 = d5;
|
var value2 = d5;
|
||||||
|
var hostmask = d6
|
||||||
const fs = require('fs-extra')
|
const fs = require('fs-extra')
|
||||||
let Parser = require('rss-parser');
|
let Parser = require('rss-parser');
|
||||||
let parser = new Parser({
|
let parser = new Parser({
|
||||||
@ -131,11 +132,56 @@ async function alias(setting, value, url, nick) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function get(setting) {
|
async function get(setting, hostmask) {
|
||||||
|
if (setting == "hostmask") {
|
||||||
|
sendUpstream('Your hostmask ==> '+hostmask)
|
||||||
|
} else {
|
||||||
consoleLog('[options.get] Getting value of '+setting)
|
consoleLog('[options.get] Getting value of '+setting)
|
||||||
var file = editJsonFile('/home/node/app/config/default.json')
|
var file = editJsonFile('/home/node/app/config/default.json')
|
||||||
console.log(file.get(setting));
|
consoleLog(setting + ' ==> ' + file.get(setting));
|
||||||
sendUpstream(file.get(setting))
|
if ( file.get(setting) == undefined) {
|
||||||
|
sendUpstream(setting + 'is not a valid setting')
|
||||||
|
} else {
|
||||||
|
sendUpstream(setting + ' ==> ' + file.get(setting))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function set(setting, value, value2, hostmask) {
|
||||||
|
content = []
|
||||||
|
if (value2 == "-s" || value2 == '--spaces') {
|
||||||
|
consoleLog('[options.set] ' + value2+' called, replacing all dashes with spaces')
|
||||||
|
var value = value.replace(/-/g,' ')
|
||||||
|
}
|
||||||
|
var file = editJsonFile('/home/node/app/config/default.json')
|
||||||
|
var disallowedSettings = [
|
||||||
|
"irc",
|
||||||
|
"twitter",
|
||||||
|
"motd"
|
||||||
|
]
|
||||||
|
var disallowedCheck = setting.split(".")
|
||||||
|
var disallowedCheck = disallowedCheck[0]
|
||||||
|
if (config.irc.settings_auth_enable == 'true' ) {
|
||||||
|
if (hostmask != config.irc.settings_auth_hostmask) {
|
||||||
|
consoleLog('[options.set] Unauthorised user '+hostmask+' attempted to set '+setting+' to '+value)
|
||||||
|
sendUpstream(errorMsg+' You are not permitted to perform this action')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (file.get(setting) == undefined) {
|
||||||
|
consoleLog('[options.set] '+setting+' is not a valid setting')
|
||||||
|
sendUpstream(errorMsg+' '+setting+' is not a valid setting or has not been defined')
|
||||||
|
}
|
||||||
|
if (disallowedSettings.includes(disallowedCheck)) {
|
||||||
|
consoleLog('[options.set] '+hostmask+' attempted to edit disallowed setting category: '+disallowedCheck)
|
||||||
|
sendUpstream(errorMsg+" You may not modify this setting")
|
||||||
|
}
|
||||||
|
var oldvalue = file.get(setting)
|
||||||
|
file.set(setting, value);
|
||||||
|
file.save();
|
||||||
|
content.push(setting+' ==> ' +oldvalue+' (PREVIOUS)')
|
||||||
|
content.push(setting+ ' ==> '+file.get(setting)+' (UPDATED)')
|
||||||
|
var output = content.join("\n")
|
||||||
|
sendUpstream(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setting === 'feed') {
|
if (setting === 'feed') {
|
||||||
@ -143,9 +189,11 @@ if (setting === 'feed') {
|
|||||||
} else if (setting === 'list') {
|
} else if (setting === 'list') {
|
||||||
feed(user, setting2)
|
feed(user, setting2)
|
||||||
} else if (setting === 'get') {
|
} else if (setting === 'get') {
|
||||||
get(setting2);
|
get(setting2, hostmask);
|
||||||
} else if(setting === 'alias') {
|
} else if(setting === 'alias') {
|
||||||
alias(setting2, value, value2, user)
|
alias(setting2, value, value2, user)
|
||||||
|
} else if(setting === 'set') {
|
||||||
|
set(setting2, value, value2, hostmask)
|
||||||
} else {
|
} else {
|
||||||
sendUpstream(errorMsg+' '+setting+' is not a valid option')
|
sendUpstream(errorMsg+' '+setting+' is not a valid option')
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,9 @@
|
|||||||
"username": "mercury",
|
"username": "mercury",
|
||||||
"realname": "git.supernets.org/hgw/mercury",
|
"realname": "git.supernets.org/hgw/mercury",
|
||||||
"autorejoin": "true",
|
"autorejoin": "true",
|
||||||
"prefix": "m!"
|
"prefix": "m!",
|
||||||
|
"settings_auth_enable": "true",
|
||||||
|
"settings_auth_hostmask": "~user@supernets.org"
|
||||||
},
|
},
|
||||||
"floodprotect": {
|
"floodprotect": {
|
||||||
"flood_protection": "false",
|
"flood_protection": "false",
|
||||||
|
Loading…
Reference in New Issue
Block a user