-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallusers.js
205 lines (178 loc) · 6.21 KB
/
allusers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
writeln("\nALLUSERS - Bulk User Editor for Synchronet User Database\n");
(function() {
var error = false;
/* required values for user matching */
var match_rules = [];
/* items to edit in matched users */
var edit_rule = {
flags:{
1:undefined,
2:undefined,
3:undefined,
4:undefined},
level:undefined,
restrictions: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 */
function setEditRule(str) {
str = str.substr(1);
var level = undefined;
var flag_set = 1;
var flags = undefined;
var exemptions = undefined;
var restrictions = undefined;
switch(str[0].toUpperCase()) {
case "L":
level = str.substr(1);
break;
case "F":
if(isNaN(str[1])) {
flags = str;
}
else {
flag_set = str[1];
flags = str.substr(2);
}
break;
case "E":
exemptions = str.substr(1);
break;
case "R":
restrictions = str.substr(1);
break;
default:
writeln("* Invalid edit rule: " + str);
error = true;
break;
}
if(level && level < 1 || level > 99) {
writeln("* Invalid security level: " + level);
error = true;
}
if(flag_set < 1 || flag_set > 4) {
writeln("* Invalid flag set: " + flag_set);
error = true;
}
if(level && !edit_rule.level)
edit_rule.level = level;
if(flags && !edit_rule.flags[flag_set])
edit_rule.flags[flag_set] = parseFlags(flags);
if(restrictions && !edit_rule.restrictions)
edit_rule.restrictions = parseFlags(restrictions);
if(exemptions && !edit_rule.exemptions)
edit_rule.exemptions = parseFlags(exemptions);
}
/* parse a +/- flag string and return a flag set/unset object */
function parseFlags(str) {
var flags = {
set:undefined,
unset:undefined
};
var set = true;
str = str.split("");
for each(var f in str) {
if(f == "+")
set = true;
else if(f == "-")
set = false;
else if(flags_str(f) > 0) {
if(set)
flags.set |= flags_str(f);
else
flags.unset |= flags_str(f);
}
else {
writeln("* Invalid flag: " + f);
}
}
return flags;
}
/* return a list of users that fit the match rule */
function matchUsers() {
var matches = [];
user_loop:
for(var u = 1; u < system.lastuser; u++) {
var usr = new User(u);
for each(var m in match_rules) {
if(!usr.compare_ars(m))
continue user_loop;
}
matches.push(usr);
}
return matches;
}
/* edit them bitches */
function editUsers(matches, rule) {
for each(var m in matches) {
if(rule.level)
m.security.level = Number(rule.level);
flag_loop:
for(var s in rule.flags) {
if(!rule.flags[s])
continue flag_loop;
m.security["flags" + s] |= rule.flags[s].set;
m.security["flags" + s] &= ~rule.flags[s].unset;
}
if(rule.exemptions) {
m.security.exemptions |= rule.exemptions.set;
m.security.exemptions &= ~rule.exemptions.unset;
}
if(rule.restrictions) {
m.security.restrictions |= rule.restrictions.set;
m.security.restrictions &= ~rule.restrictions.unset;
}
writeln("Modified user record #" + m.number);
}
writeln("Modified " + matches.length + " record(s)");
}
/* if no arguments were passed, display command usage */
if(argc == 0) {
usage();
return;
}
/* parse command arguments */
while(argv.length > 0) {
var arg = argv.shift();
if(arg[0] == "/")
setEditRule(arg);
else
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 */
var matches = matchUsers();
/* edit matched users */
editUsers(matches, edit_rule);
return true;
})();
writeln();