-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacc.js
More file actions
181 lines (157 loc) · 4.21 KB
/
Copy pathacc.js
File metadata and controls
181 lines (157 loc) · 4.21 KB
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
function accListUpd(j, id) {
var o;
try {
for(var i = 0; i < j.Accounts.length; i++) {
o = document.createElement("option");
o.value = j.Accounts[i].Id;
o.text = j.Accounts[i].Name;
eGetById("accList").add(o, null);
}
} catch(e) {
console.log(e);
}
}
function accGetUpd(j) {
try {
hS("accN", j.Name);
if (j.Access & accEn)
cS("accREn", true);
if (j.Access & accFtpRw)
cS("accRFtp", true);
if (j.Access & accIo)
cS("accRIo", true);
if (j.Access & accIoCfg)
cS("accRIoCfg", true);
if (j.Access & accAdmin)
cS("accRAdmin", true);
} catch (e) {
console.log(e);
}
}
async function accGet() {
var e = eGetById("accList");
var rq = {Cmd:"AccGet", SessionId:sIdG()};
rq["Name"] = e.options[e.selectedIndex].text;
try {
hS("accN", "");
vS("accP", "");
vS("accCP", "");
cS("accREn", false);
cS("accRFtp", false);
cS("accRIo", false);
cS("accRIoCfg", false);
cS("accRAdmin", false);
} catch (e) {
console.log(e);
}
return await rqp(rq, accGetUpd);
}
async function accSet() {
var e = eGetById("accList")
var acc;
var rq = {Cmd:"AccSet", SessionId:sIdG()};
rq["Name"] = e.options[e.selectedIndex].text;
if (cG("accREn"))
acc |= accEn;
if (cG("accRFtp"))
acc |= accFtpRw;
if (cG("accRIo"))
acc |= accIo;
if (cG("accRIoCfg"))
acc |= accIoCfg;
if (cG("accRAdmin"))
acc |= accAdmin;
rq["Access"] = acc;
if (vG("accP").length)
rq["Pass"] = vG("accP");
if ((e.selectedIndex === 0) && (vG("accCP").length))
rq["CopyPass"] = vG("accCP");
return await rqp(rq, null);
}
async function accListGet(){
let rq = {Cmd:"AccListGet", SessionId:sIdG()};
return new Promise(async(res,rej) => {
try {
l = eGetById("accList").options.length - 1;
for (i = l; i >= 0; i--) {
eGetById("accList").remove(i);
}
} catch(e) {
console.log(e);
}
await rqp(rq, accListUpd).then(() => {
eGetById("accList").selectedIndex = 0;
res();
}).catch((m) => {
rej(m);
})
});
}
async function accCreate() {
return new Promise(async(res,rej) => {
let rq = {Cmd:"AccCreate", SessionId:sIdG()};
rq["Name"] = vG("accCN");
await rqp(rq, null).then(async () => {
await accListGet().then(() => {
res();
}).catch((m) => {
rej(m);
})
}).catch((m) => {
rej(m);
})
});
}
async function accDel() {
var e = eGetById("accList")
return new Promise(async(res,rej) => {
let rq = {Cmd:"AccDelete", SessionId:sIdG()};
rq["Name"] = e.options[e.selectedIndex].text;
await rqp(rq, null).then(async() => {
await accListGet().then(() => {
}).catch((m) => {
rej(m);
})
}).catch((m) => {
rej(mExcept(rq, m));
})
});
}
async function accInit() {
return new Promise(async(res, rej) => {
btnEvAdd("accBtDel", async() => {
await accDel().then(() => {
}).catch((m) => {
alert(m);
})
});
btnEvAdd("accBtCreate", async() => {
await accCreate().then(() => {
}).catch((m) => {
alert(m);
})
});
btnEvAdd("accBtUpd", async() => {
await accSet().then(() => {
}).catch((m) => {
alert(m);
})
});
eGetById("accList").addEventListener("change", async() => {
await accGet().then(() => {
}).catch((m) => {
alert(m);
})
});
await accListGet()
.then(async() => {
await accGet().then(() => {
res();
}).catch((m) => {
rej(m);
})
}).catch((m) => {
rej(m);
})
});
}