Added recurring guest device sharing support to meshctrl.js

Ylian Saint-Hilaire committed Jan 17, 2022 at 11:38 UTC 0290ba7f8bf9681c16ad9e14a40a5e182e68dad4
1 file changed +25 -5
meshctrl.js
+25 -5
@@ -227,6 +227,7 @@ if (args['_'].length == 0) {
227 }
228 case 'devicesharing': {
229 if (args.id == null) { console.log(winRemoveSingleQuotes("Missing device id, use --id '[deviceid]'")); }
230 + else if ((args.daily != null) && (args.weekly != null)) { console.log(winRemoveSingleQuotes("Can't specify both --daily and --weekly at the same time.")); }
231 else { ok = true; }
232 break;
233 }
@@ -839,6 +840,7 @@ if (args['_'].length == 0) {
840 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid'"));
841 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid' --remove abcdef"));
842 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid' --add Guest --start " + localISOTime + " --duration 30"));
843 + console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid' --add Guest --start " + localISOTime + " --duration 30 --daily"));
844 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceSharing --id 'deviceid' --add Guest --type desktop,terminal --consent prompt"));
845 console.log("\r\nRequired arguments:\r\n");
846 if (process.platform == 'win32') {
@@ -855,6 +857,8 @@ if (args['_'].length == 0) {
857 console.log(" --start [yyyy-mm-ddThh:mm:ss] - Start time, default is now.");
858 console.log(" --end [yyyy-mm-ddThh:mm:ss] - End time.");
859 console.log(" --duration [minutes] - Duration of the share, default is 60 minutes.");
860 + console.log(" --daily - Add recurring daily device share.");
861 + console.log(" --weekly - Add recurring weekly device share.");
862 break;
863 }
864 case 'agentdownload': {
@@ -1608,12 +1612,25 @@ function serverConnect() {
1612 if (args.end) { if (start == null) { start = Math.floor(Date.now() / 1000) } end = Math.floor(Date.parse(args.end) / 1000); if (end <= start) { console.log("End time must be ahead of start time."); process.exit(1); return; } }
1613 if (args.duration) { if (start == null) { start = Math.floor(Date.now() / 1000) } end = start + parseInt(args.duration * 60); }
1614
1611 - if ((start == null) && (end == null)) {
1612 - // Unlimited sharing
1613 - ws.send(JSON.stringify({ action: 'createDeviceShareLink', nodeid: args.id, guestname: args.add, p: p, consent: consent, expire: 0, viewOnly: viewOnly, responseid: 'meshctrl' }));
1615 + // Recurring
1616 + var recurring = 0;
1617 + if (args.daily) { recurring = 1; } else if (args.weekly) { recurring = 2; }
1618 + if (recurring > 0) {
1619 + if (args.end != null) { console.log("End time can't be specified for recurring shares, use --duration only."); process.exit(1); return; }
1620 + if (args.duration == null) { args.duration = 60; } else { args.duration = parseInt(args.duration); }
1621 + if (start == null) { start = Math.floor(Date.now() / 1000) }
1622 + if ((typeof args.duration != 'number') || (args.duration < 1)) { console.log("Invalid duration value."); process.exit(1); return; }
1623 +
1624 + // Recurring sharing
1625 + ws.send(JSON.stringify({ action: 'createDeviceShareLink', nodeid: args.id, guestname: args.add, p: p, consent: consent, start: start, expire: args.duration, recurring: recurring, viewOnly: viewOnly, responseid: 'meshctrl' }));
1626 } else {
1615 - // Time limited sharing
1616 - ws.send(JSON.stringify({ action: 'createDeviceShareLink', nodeid: args.id, guestname: args.add, p: p, consent: consent, start: start, end: end, viewOnly: viewOnly, responseid: 'meshctrl' }));
1627 + if ((start == null) && (end == null)) {
1628 + // Unlimited sharing
1629 + ws.send(JSON.stringify({ action: 'createDeviceShareLink', nodeid: args.id, guestname: args.add, p: p, consent: consent, expire: 0, viewOnly: viewOnly, responseid: 'meshctrl' }));
1630 + } else {
1631 + // Time limited sharing
1632 + ws.send(JSON.stringify({ action: 'createDeviceShareLink', nodeid: args.id, guestname: args.add, p: p, consent: consent, start: start, end: end, viewOnly: viewOnly, responseid: 'meshctrl' }));
1633 + }
1634 }
1635 } else if (args.remove) {
1636 ws.send(JSON.stringify({ action: 'removeDeviceShare', nodeid: args.id, publicid: args.remove, responseid: 'meshctrl' }));
@@ -1807,6 +1824,9 @@ function serverConnect() {
1824 console.log('User Consent: ' + consent.join(', '));
1825 if (share.startTime) { console.log('Start Time: ' + new Date(share.startTime).toLocaleString()); }
1826 if (share.expireTime) { console.log('Expire Time: ' + new Date(share.expireTime).toLocaleString()); }
1827 + if (share.duration) { console.log('Duration: ' + share.duration + ' minute' + ((share.duration > 1) ? 's' : '')); }
1828 + if (share.recurring == 1) { console.log('Recurring: ' + 'Daily'); }
1829 + if (share.recurring == 2) { console.log('Recurring: ' + 'Weekly'); }
1830 console.log('URL: ' + share.url);
1831 }
1832 }