Skip to content

Commit 6d2ca73

Browse files
committed
luci: Add Base64 decode for node links
1 parent fc17f19 commit 6d2ca73

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

luci-app-passwall/luasrc/view/passwall/node_list/link_add_node.htm

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@
4040
sendNextChunk();
4141
}
4242

43+
function decodeIfBase64(str) {
44+
try {
45+
let s = str.replace(/-/g, '+').replace(/_/g, '/');
46+
while (s.length % 4) s += '=';
47+
const decoded = decodeURIComponent(
48+
atob(s).split('').map(c =>
49+
'%' + c.charCodeAt(0).toString(16).padStart(2, '0')
50+
).join('')
51+
);
52+
if (btoa(unescape(encodeURIComponent(decoded))).replace(/=+$/, '') === s.replace(/=+$/, '')) {
53+
return decoded;
54+
}
55+
} catch (e) {}
56+
return str;
57+
}
58+
4359
function getBg(el) {
4460
if (!el) return null;
4561
const style = getComputedStyle(el);
@@ -74,15 +90,14 @@
7490
const group = (document.querySelector('#addlink_group_custom input[type="hidden"]')?.value || "default");
7591
nodes_link = nodes_link.replace(/\t/g, "").replace(/\r\n|\r/g, "\n").replace(/<[^>]*>/g, '').trim();
7692
if (nodes_link != "") {
93+
nodes_link = decodeIfBase64(nodes_link);
7794
let s = nodes_link.split('://');
7895
if (s.length > 1) {
7996
ajax_add_node(nodes_link, group);
80-
}
81-
else {
97+
} else {
8298
alert("<%:Please enter the correct link.%>");
8399
}
84-
}
85-
else {
100+
} else {
86101
document.getElementById("nodes_link").focus();
87102
}
88103
}
@@ -93,8 +108,7 @@
93108
function(x, data) {
94109
if(x && x.status == 200) {
95110
window.location.href = '<%=api.url("node_list")%>';
96-
}
97-
else {
111+
} else {
98112
alert("<%:Error%>");
99113
}
100114
});
@@ -154,8 +168,7 @@
154168
function(x, data) {
155169
if (x && x.status == 200) {
156170
window.location.href = '<%=api.url("node_list")%>';
157-
}
158-
else {
171+
} else {
159172
alert("<%:Error%>");
160173
}
161174
});

0 commit comments

Comments
 (0)