Skip to content
Snippets Groups Projects
Commit 2002aea3 authored by mcmlxxix's avatar mcmlxxix
Browse files

display usage and errors the same as makeuser.js

parent 7182dbfd
No related branches found
No related tags found
No related merge requests found
/* writeln("\nALLUSERS - Bulk User Editor for Synchronet User Database\n");
* ALLUSERS - Bulk User Editor for Synchronet User Database
*
* usage: jsexec allusers.js [[ARS] [...]] [[/modify] [...]]
*
* where ARS is any valid ARS string
* (see http://www.synchro.net/docs/security.html)
*
* where modify is one of:
* L# change security level to #
* F#[+|-]<flags> add or remove flags from flag set #
* E[+|-]<flags> add or remove exemption flags
* R[+|-]<flags> add or remove restriction flags
*
* examples:
*
* jsexec allusers.js "L30" /FA add 'A' to flag set #1 for all level 30+ users
* jsexec allusers.js /F3-G remove 'G' from flag set #3 for all users
* jsexec allusers.js F2B /E-P remove 'P' exemption for all users with FLAG '2B'
* jsexec allusers.js "60$XA" /R+W add 'W' restriction for all level 60+ users
* with exemption 'A'
*
* NOTE: multi-word ARS strings or ARS strings with special characters
* must be enclosed in "quotes"
*/
(function() { (function() {
var error = false;
/* required values for user matching */ /* required values for user matching */
var match_rules = []; var match_rules = [];
...@@ -41,6 +18,32 @@ ...@@ -41,6 +18,32 @@
exemptions:undefined exemptions:undefined
} }
/* display command usage */
function usage() {
writeln('usage: jsexec allusers.js [[ARS] [...]] [[/modify] [...]]');
writeln();
writeln('where ARS is any valid ARS string');
writeln(' (see http://www.synchro.net/docs/security.html)');
writeln();
writeln('where modify is one of:');
writeln(' L# change security level to #');
writeln(' F#[+|-]<flags> add or remove flags from flag set #');
writeln(' E[+|-]<flags> add or remove exemption flags');
writeln(' R[+|-]<flags> add or remove restriction flags');
writeln();
writeln('examples: jsexec allusers.js ..');
writeln();
writeln(' "L30" /FA add "A" to flag set #1 for all level 30+ users');
writeln(' /F3-G remove "G" from flag set #3 for all users');
writeln(' F2B /E-P remove "P" exemption for all users with FLAG "2B"');
writeln(' "60$XA" /R+W add "W" restriction for all level 60+ users');
writeln(' with exemption "A"');
writeln();
writeln('NOTE: multi-word ARS strings or ARS strings with special characters');
writeln(' must be enclosed in "quotes"');
writeln();
}
/* apply argument to edit rule */ /* apply argument to edit rule */
function setEditRule(str) { function setEditRule(str) {
...@@ -71,14 +74,19 @@ ...@@ -71,14 +74,19 @@
restrictions = str.substr(1); restrictions = str.substr(1);
break; break;
default: default:
throw("invalid edit rule: " + str); writeln("* Invalid edit rule: " + str);
error = true;
break; break;
} }
if(level && level < 1 || level > 99) if(level && level < 1 || level > 99) {
throw("invalid security level: " + level); writeln("* Invalid security level: " + level);
if(flag_set < 1 || flag_set > 4) error = true;
throw("invalid flag set: " + flag_set); }
if(flag_set < 1 || flag_set > 4) {
writeln("* Invalid flag set: " + flag_set);
error = true;
}
if(level && !edit_rule.level) if(level && !edit_rule.level)
edit_rule.level = level; edit_rule.level = level;
...@@ -111,7 +119,7 @@ ...@@ -111,7 +119,7 @@
flags.unset |= flags_str(f); flags.unset |= flags_str(f);
} }
else { else {
throw("invalid flag: " + f); writeln("* Invalid flag: " + f);
} }
} }
...@@ -162,6 +170,12 @@ ...@@ -162,6 +170,12 @@
writeln("Modified " + matches.length + " record(s)"); writeln("Modified " + matches.length + " record(s)");
} }
/* if no arguments were passed, display command usage */
if(argc == 0) {
usage();
return;
}
/* parse command arguments */ /* parse command arguments */
while(argv.length > 0) { while(argv.length > 0) {
var arg = argv.shift(); var arg = argv.shift();
...@@ -171,12 +185,21 @@ ...@@ -171,12 +185,21 @@
match_rules.push(arg); match_rules.push(arg);
} }
/* if there was an error processing the request, exit */
if(error) {
writeln("\nError(s) processing request");
return false;
}
/* search user list and return matches */ /* search user list and return matches */
var matches = matchUsers(); var matches = matchUsers();
/* edit matched users */ /* edit matched users */
editUsers(matches, edit_rule); editUsers(matches, edit_rule);
return true;
})(); })();
writeln();
(function() { (function() {
writeln("\r\nSynchronet System/Node Statistics Log Viewer v1.02\n"); writeln("\r\nSynchronet System/Node Statistics Log Viewer\n");
var sfile = new File(system.ctrl_dir + "csts.dab"); var sfile = new File(system.ctrl_dir + "csts.dab");
var list = []; var list = [];
...@@ -29,10 +29,14 @@ ...@@ -29,10 +29,14 @@
} }
} }
if(!file_exists(sfile.name)) if(!file_exists(sfile.name)) {
throw(sfile.name + " does not exist"); writeln("* " + sfile.name + " does not exist");
if(!sfile.open('r+b')) return false;
throw("error opening " + sfile.name); }
if(!sfile.open('r+b')) {
writeln("* error opening " + sfile.name);
return false;
}
while(sfile.position <= file_size(sfile.name) - 40) { while(sfile.position <= file_size(sfile.name) - 40) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment