Skip to content

Commit ddedb00

Browse files
authored
Merge pull request #46 from RiV-chain/web_auth
Web auth module for NAS Synology RIVM-86
2 parents 1a52145 + eeb085f commit ddedb00

File tree

9 files changed

+185
-75
lines changed

9 files changed

+185
-75
lines changed

contrib/ui/mesh-ui/ui/assets/mesh-ui.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ function showInfo(text) {
153153
setTimeout(button.onclick, 2000);
154154
}
155155

156+
function showError(text) {
157+
var info = $("notification_error");
158+
var message = $("error_text");
159+
message.innerHTML = text;
160+
161+
info.className = "notification is-danger";
162+
var button = $("info_close");
163+
button.onclick = function () {
164+
message.value = "";
165+
info.className = "notification is-danger is-hidden";
166+
};
167+
}
168+
156169
function showWindow() {
157170
var info = $("notification_window");
158171
var message = $("info_window");
@@ -307,7 +320,16 @@ ui.updateConnectedPeers = () =>
307320

308321
ui.getSelfInfo = () =>
309322
fetch('api/self')
310-
.then((response) => response.json())
323+
.then((response) => {
324+
if (response.status === 401) {
325+
let status="st-error"
326+
Array.from($$("status")).forEach(node => node.classList.add("is-hidden"));
327+
$(status).classList.remove("is-hidden");
328+
response.text().then(text => {showError(text)});
329+
} else {
330+
return response.json()
331+
}
332+
});
311333

312334
ui.updateSelfInfo = () =>
313335
ui.getSelfInfo()
@@ -334,10 +356,10 @@ function main() {
334356
});
335357
});
336358

337-
ui.updateConnectedPeers();
338-
339359
ui.updateSelfInfo();
340360

361+
ui.updateConnectedPeers();
362+
341363
ui.sse = new EventSource('api/sse');
342364

343365
ui.sse.addEventListener("health", (e) => {

contrib/ui/mesh-ui/ui/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<link rel="stylesheet" href="assets/bulmaswatch.min.css" type="text/css">
1212
<link rel="stylesheet" href="assets/flag-icons.css" type="text/css">
1313
<link rel="stylesheet" href="assets/mesh-ui.css" type="text/css">
14-
<!--script type="application/javascript" src="assets/mesh-ui.js"></script-->
14+
<script type="module" type="application/javascript" src="assets/properties.js"></script>
15+
1516
<script>
1617
var script = document.createElement('script');
1718
//load polyfills + EC5 for IE or usual for rest
@@ -247,7 +248,7 @@
247248
class="button is-text">Terms and Conditions</a></strong>
248249
<br>
249250
<div style="margin-left: 20px; margin-right: 10px;">Copyright © <a class="target_new_window"
250-
href="https://rivchain.org/">RiV Chain </a>Ltd. and
251+
href="#https://rivchain.org/">RiV Chain </a>Ltd. and
251252
individual contributors. All rights reserved.</div>
252253
</div>
253254
</div>
@@ -275,6 +276,12 @@
275276
<p id="info_text"></p>
276277
</div>
277278
</div>
279+
<div style="margin-left: 100px; margin-right: 100px;">
280+
<div class="notification is-danger is-hidden" id="notification_error">
281+
<button class="delete" id="info_close"></button>
282+
<p id="error_text"></p>
283+
</div>
284+
</div>
278285

279286
</div>
280287
<footer>

contrib/ui/nas-synology-dsm6.0/package/var/lib/mesh/hooks/webauth

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ IFS=';'
66
for x in $HTTP_COOKIE
77
do
88
case $x in
9-
*EdSynoToken*)
9+
*RiVSynoToken*)
1010
eval $x
1111
;;
1212
esac
1313
done
14-
[ -z $QUERY_STRING ] && export QUERY_STRING=SynoToken=$EdSynoToken || export QUERY_STRING="$QUERY_STRING&SynoToken=$EdSynoToken"
14+
[ -z $QUERY_STRING ] && export QUERY_STRING=SynoToken=$RiVSynoToken || export QUERY_STRING="$QUERY_STRING&SynoToken=$RiVSynoToken"
1515

1616
[ ! -z $HTTP_X_REAL_IP ] && export REMOTE_ADDR=$HTTP_X_REAL_IP
1717
[ ! -z $HTTP_X_FORWARDED_FOR_ADDR ] && export SERVER_ADDR=$HTTP_X_FORWARDED_FOR_ADDR

contrib/ui/nas-synology-dsm6.0/package/www/assets/properties.js

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,63 @@ var ed = {
2323
document.cookie = key + "=" + value + expires + "; path=/";
2424
},
2525
getNasAuthUrl: function () {
26-
ed.setCookie('EdSynoToken', "");
26+
ed.setCookie('RiVSynoToken', "");
2727
var url = ed.getCookie('origin');
2828
if (url === undefined) {
2929
url = window.location.protocol + "//" + window.location.hostname + ":" + 5000;
3030
}
3131
return url;
3232
}
3333
};
34-
$(function () {
35-
function params(obj) {
36-
if (typeof obj === 'string') {
37-
if (obj[0] === '?') {
38-
obj = obj.substring(1);
39-
}
40-
var result = {};
41-
obj = obj.split("&");
42-
obj.forEach(function (pair) {
43-
pair = pair.split("=");
44-
var key = decodeURIComponent(pair[0]);
45-
var value = decodeURIComponent(pair[1]);
46-
// If first entry with this name
47-
if (typeof result[key] === "undefined") {
48-
result[key] = value;
49-
// If second entry with this name
50-
} else if (typeof result[key] === "string") {
51-
result[key] = [result[key], value];
52-
// If third or later entry with this name
53-
} else {
54-
result[key].push(value);
55-
}
56-
});
57-
return result;
58-
} else {
59-
return Object.keys(obj).map(function (key) {
60-
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]);
61-
}).join('&');
62-
}
63-
};
64-
//Hide URL parameters
65-
var query = params(window.location.search.substring(1));
66-
var refresh = false;
67-
for (var k in query) {
68-
if (k === 'SynoToken') {
69-
ed.setCookie('EdSynoToken', query[k]);
70-
refresh = true;
71-
delete query[k];
72-
} else if (k === 'origin') {
73-
ed.setCookie('origin', query[k]);
74-
refresh = true;
75-
delete query[k];
34+
35+
function params(obj) {
36+
if (typeof obj === 'string') {
37+
if (obj[0] === '?') {
38+
obj = obj.substring(1);
7639
}
40+
var result = {};
41+
obj = obj.split("&");
42+
obj.forEach(function (pair) {
43+
pair = pair.split("=");
44+
var key = decodeURIComponent(pair[0]);
45+
var value = decodeURIComponent(pair[1]);
46+
// If first entry with this name
47+
if (typeof result[key] === "undefined") {
48+
result[key] = value;
49+
// If second entry with this name
50+
} else if (typeof result[key] === "string") {
51+
result[key] = [result[key], value];
52+
// If third or later entry with this name
53+
} else {
54+
result[key].push(value);
55+
}
56+
});
57+
return result;
58+
} else {
59+
return Object.keys(obj).map(function (key) {
60+
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]);
61+
}).join('&');
62+
}
63+
};
64+
//Hide URL parameters
65+
var query = params(window.location.search.substring(1));
66+
var refresh = false;
67+
for (var k in query) {
68+
if (k === 'SynoToken') {
69+
ed.setCookie('RiVSynoToken', query[k]);
70+
refresh = true;
71+
delete query[k];
72+
} else if (k === 'origin') {
73+
ed.setCookie('origin', query[k]);
74+
refresh = true;
75+
delete query[k];
7776
}
78-
query = $.param(query);
79-
if (refresh)
80-
window.location.replace(window.location.origin + window.location.pathname + window.location.hash + ((query === "") ? "" : ("?" + query)));
81-
});
77+
}
78+
79+
query = Object.keys(query).map(function(k) {
80+
return encodeURIComponent(k) + '=' + encodeURIComponent(query[k])
81+
}).join('&');
82+
83+
if (refresh)
84+
window.location.replace(window.location.origin + window.location.pathname + window.location.hash + ((query === "") ? "" : ("?" + query)));
85+
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"port-config": {
33
"protocol-file": "mesh.sc"
4-
}
4+
},
5+
6+
"usr-local-linker": {
7+
"bin": ["mesh", "meshctl"]
8+
}
59
}
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
{
2-
"defaults":{
3-
"run-as": "package"
4-
},
5-
"ctrl-script":[{
6-
"action": "postinst",
7-
"run-as": "root"
8-
}, {
9-
"action": "postuninst",
10-
"run-as": "root"
11-
}, {
12-
"action": "preuninst",
13-
"run-as": "root"
14-
}, {
15-
"action": "start",
16-
"run-as": "root"
17-
}, {
18-
"action": "stop",
19-
"run-as": "root"
20-
}]
21-
}
2+
"defaults": {
3+
"run-as": "package"
4+
}
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
cat << EOF >> "$SYNOPKG_TEMP_LOGFILE"
4+
<big><strong style='color:blue'>RiV-mesh</strong></big><br>
5+
<br>
6+
<span>Please ensure that the RiV-mesh app is granted with root priviledges when it starts:<br>
7+
<br>
8+
<ol style="list-style-type:decimal; margin-left: 0; padding-left: 40px;">
9+
<li>Go to the SSH prompt as <strong>root</strong></li>
10+
<li>Run the following command to start the package: <strong>/var/packages/mesh/scripts/start</strong></li>
11+
<li>As result of success run you have to see the following output: <strong>RiV-mesh has been successfully started</strong></li>
12+
</ol>
13+
<br>
14+
For a detailed step-by-step guide, join our official channel in <a href="https://t.me/rivchain" target="_blank">Telegram</a>.
15+
EOF
16+
17+
exit 0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
if [ "$EUID" -ne 0 ]; then
4+
echo "This script must be run as root"
5+
exit 1
6+
fi
7+
8+
dir=`dirname $0`
9+
sed -i 's/package/root/' "$dir/../conf/privilege"
10+
11+
synopkg start mesh > /dev/null
12+
if [ "$?" -eq 0 ]; then
13+
echo "RiV-mesh has been successfully started"
14+
exit 0
15+
else
16+
echo "An error occurred during RiV-mesh startup" 1>&2
17+
exit 1
18+
fi

0 commit comments

Comments
 (0)