Removed password from firmware updates
This commit is contained in:
205
src/js/app.js
205
src/js/app.js
@@ -32,23 +32,23 @@ var cookie = require('./cookie')('bbctrl-');
|
|||||||
var Sock = require('./sock');
|
var Sock = require('./sock');
|
||||||
|
|
||||||
function is_newer_version(current, latest) {
|
function is_newer_version(current, latest) {
|
||||||
const pattern = /(\d+)\.(\d+)\.(\d+)(.*)/;
|
const pattern = /(\d+)\.(\d+)\.(\d+)(.*)/;
|
||||||
const currentParts = current.match(pattern);
|
const currentParts = current.match(pattern);
|
||||||
const latestParts = latest.match(pattern);
|
const latestParts = latest.match(pattern);
|
||||||
|
|
||||||
if (!currentParts || !latestParts) {
|
if (!currentParts || !latestParts) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal version comparisons
|
// Normal version comparisons
|
||||||
const major = latestParts[1] - currentParts[1];
|
const major = latestParts[1] - currentParts[1];
|
||||||
const minor = latestParts[2] - currentParts[2];
|
const minor = latestParts[2] - currentParts[2];
|
||||||
const patch = latestParts[3] - currentParts[3];
|
const patch = latestParts[3] - currentParts[3];
|
||||||
|
|
||||||
// If current is a pre-release, and latest is a release
|
// If current is a pre-release, and latest is a release
|
||||||
const betaToRelease = latestParts[4].length === 0 && currentParts[4].length > 0;
|
const betaToRelease = latestParts[4].length === 0 && currentParts[4].length > 0;
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case major > 0:
|
case major > 0:
|
||||||
case major === 0 && minor > 0:
|
case major === 0 && minor > 0:
|
||||||
case major === 0 && minor === 0 && patch > 0:
|
case major === 0 && minor === 0 && patch > 0:
|
||||||
@@ -60,8 +60,8 @@ function is_newer_version(current, latest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_object(o) {return o !== null && typeof o == 'object'}
|
function is_object(o) { return o !== null && typeof o == 'object' }
|
||||||
function is_array(o) {return Array.isArray(o)}
|
function is_array(o) { return Array.isArray(o) }
|
||||||
|
|
||||||
function update_array(dst, src) {
|
function update_array(dst, src) {
|
||||||
while (dst.length) dst.pop()
|
while (dst.length) dst.pop()
|
||||||
@@ -110,7 +110,7 @@ module.exports = new Vue({
|
|||||||
modified: false,
|
modified: false,
|
||||||
template: require('../resources/config-template.json'),
|
template: require('../resources/config-template.json'),
|
||||||
config: {
|
config: {
|
||||||
settings: {units: 'METRIC'},
|
settings: { units: 'METRIC' },
|
||||||
motors: [{}, {}, {}, {}],
|
motors: [{}, {}, {}, {}],
|
||||||
version: '<loading>',
|
version: '<loading>',
|
||||||
full_version: '<loading>'
|
full_version: '<loading>'
|
||||||
@@ -132,7 +132,6 @@ module.exports = new Vue({
|
|||||||
checkedUpgrade: false,
|
checkedUpgrade: false,
|
||||||
firmwareName: '',
|
firmwareName: '',
|
||||||
latestVersion: '',
|
latestVersion: '',
|
||||||
password: '',
|
|
||||||
ipAddress: '0.0.0.0',
|
ipAddress: '0.0.0.0',
|
||||||
wifiSSID: '',
|
wifiSSID: '',
|
||||||
confirmShutdown: false,
|
confirmShutdown: false,
|
||||||
@@ -140,10 +139,9 @@ module.exports = new Vue({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
'estop': {template: '#estop-template'},
|
'estop': { template: '#estop-template' },
|
||||||
'loading-view': {template: '<h1>Loading...</h1>'},
|
'loading-view': { template: '<h1>Loading...</h1>' },
|
||||||
'control-view': require('./control-view'),
|
'control-view': require('./control-view'),
|
||||||
'settings-view': require('./settings-view'),
|
'settings-view': require('./settings-view'),
|
||||||
'motor-view': require('./motor-view'),
|
'motor-view': require('./motor-view'),
|
||||||
@@ -151,18 +149,21 @@ module.exports = new Vue({
|
|||||||
'io-view': require('./io-view'),
|
'io-view': require('./io-view'),
|
||||||
'admin-general-view': require('./admin-general-view'),
|
'admin-general-view': require('./admin-general-view'),
|
||||||
'admin-network-view': require('./admin-network-view'),
|
'admin-network-view': require('./admin-network-view'),
|
||||||
'help-view': {template: '#help-view-template'},
|
'help-view': { template: '#help-view-template' },
|
||||||
'cheat-sheet-view': {
|
'cheat-sheet-view': {
|
||||||
template: '#cheat-sheet-view-template',
|
template: '#cheat-sheet-view-template',
|
||||||
data: function () {return {showUnimplemented: false}}
|
data: function () { return { showUnimplemented: false } }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'config-changed': function () {this.modified = true;},
|
'config-changed': function () {
|
||||||
'hostname-changed': function (hostname) {this.hostname = hostname},
|
this.modified = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
'hostname-changed': function (hostname) {
|
||||||
|
this.hostname = hostname
|
||||||
|
},
|
||||||
|
|
||||||
send: function (msg) {
|
send: function (msg) {
|
||||||
if (this.status == 'connected') {
|
if (this.status == 'connected') {
|
||||||
@@ -171,10 +172,13 @@ module.exports = new Vue({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
connected: function () {
|
||||||
|
this.update()
|
||||||
|
},
|
||||||
|
|
||||||
connected: function () {this.update()},
|
update: function () {
|
||||||
update: function () {this.update()},
|
this.update()
|
||||||
|
},
|
||||||
|
|
||||||
check: function () {
|
check: function () {
|
||||||
this.latestVersion = '';
|
this.latestVersion = '';
|
||||||
@@ -182,7 +186,7 @@ module.exports = new Vue({
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: 'https://raw.githubusercontent.com/OneFinityCNC/onefinity-release/master/latest.txt',
|
url: 'https://raw.githubusercontent.com/OneFinityCNC/onefinity-release/master/latest.txt',
|
||||||
data: {hid: this.state.hid},
|
data: { hid: this.state.hid },
|
||||||
cache: false
|
cache: false
|
||||||
|
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
@@ -191,28 +195,25 @@ module.exports = new Vue({
|
|||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
upgrade: function () {
|
upgrade: function () {
|
||||||
this.password = '';
|
|
||||||
this.confirmUpgrade = true;
|
this.confirmUpgrade = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
upload: function (firmware) {
|
upload: function (firmware) {
|
||||||
this.firmware = firmware;
|
this.firmware = firmware;
|
||||||
this.firmwareName = firmware.name;
|
this.firmwareName = firmware.name;
|
||||||
this.password = '';
|
|
||||||
this.confirmUpload = true;
|
this.confirmUpload = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
error: function (msg) {
|
error: function (msg) {
|
||||||
// Honor user error blocking
|
// Honor user error blocking
|
||||||
if (Date.now() - this.errorTimeoutStart < this.errorTimeout * 1000)
|
if (Date.now() - this.errorTimeoutStart < this.errorTimeout * 1000)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Wait at least 1 sec to pop up repeated errors
|
// Wait at least 1 sec to pop up repeated errors
|
||||||
if (1 < msg.repeat && Date.now() - msg.ts < 1000) return;
|
if (1 < msg.repeat && Date.now() - msg.ts < 1000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Popup error dialog
|
// Popup error dialog
|
||||||
this.errorShow = true;
|
this.errorShow = true;
|
||||||
@@ -220,75 +221,70 @@ module.exports = new Vue({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
popupMessages: function () {
|
popupMessages: function () {
|
||||||
var msgs = [];
|
const msgs = [];
|
||||||
|
|
||||||
for (var i = 0; i < this.state.messages.length; i++) {
|
for (let i = 0; i < this.state.messages.length; i++) {
|
||||||
var text = this.state.messages[i].text;
|
const text = this.state.messages[i].text;
|
||||||
if (!/^#/.test(text)) msgs.push(text);
|
if (!/^#/.test(text)) {
|
||||||
|
msgs.push(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
ready: function () {
|
ready: function () {
|
||||||
$(window).on('hashchange', this.parse_hash);
|
$(window).on('hashchange', this.parse_hash);
|
||||||
this.connect();
|
this.connect();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
metric: function () {return this.config.settings.units != 'IMPERIAL'},
|
metric: function () {
|
||||||
|
return this.config.settings.units != 'IMPERIAL'
|
||||||
|
},
|
||||||
|
|
||||||
block_error_dialog: function () {
|
block_error_dialog: function () {
|
||||||
this.errorTimeoutStart = Date.now();
|
this.errorTimeoutStart = Date.now();
|
||||||
this.errorShow = false;
|
this.errorShow = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
toggle_video: function (e) {
|
toggle_video: function (e) {
|
||||||
if (this.video_size == 'small') this.video_size = 'large';
|
if (this.video_size == 'small') this.video_size = 'large';
|
||||||
else if (this.video_size == 'large') this.video_size = 'small';
|
else if (this.video_size == 'large') this.video_size = 'small';
|
||||||
cookie.set('video-size', this.video_size);
|
cookie.set('video-size', this.video_size);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
toggle_crosshair: function (e) {
|
toggle_crosshair: function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.crosshair = !this.crosshair;
|
this.crosshair = !this.crosshair;
|
||||||
cookie.set('crosshair', this.crosshair);
|
cookie.set('crosshair', this.crosshair);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
estop: function () {
|
estop: function () {
|
||||||
if (this.state.xx == 'ESTOPPED') api.put('clear');
|
if (this.state.xx == 'ESTOPPED') api.put('clear');
|
||||||
else api.put('estop');
|
else api.put('estop');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
upgrade_confirmed: async function () {
|
||||||
upgrade_confirmed: function () {
|
|
||||||
this.confirmUpgrade = false;
|
this.confirmUpgrade = false;
|
||||||
|
|
||||||
api.put('upgrade', {password: this.password}).done(function () {
|
try {
|
||||||
|
await api.put('upgrade');
|
||||||
this.firmwareUpgrading = true;
|
this.firmwareUpgrading = true;
|
||||||
|
} catch (err) {
|
||||||
}.bind(this)).fail(function () {
|
api.alert('Error during upgrade.');
|
||||||
api.alert('Invalid password');
|
console.error("Error during upgrade", err);
|
||||||
}.bind(this))
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
upload_confirmed: function () {
|
upload_confirmed: function () {
|
||||||
this.confirmUpload = false;
|
this.confirmUpload = false;
|
||||||
|
|
||||||
var form = new FormData();
|
const form = new FormData();
|
||||||
form.append('firmware', this.firmware);
|
form.append('firmware', this.firmware);
|
||||||
if (this.password) form.append('password', this.password);
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/firmware/update',
|
url: '/api/firmware/update',
|
||||||
@@ -300,13 +296,12 @@ module.exports = new Vue({
|
|||||||
|
|
||||||
}).success(function () {
|
}).success(function () {
|
||||||
this.firmwareUpgrading = true;
|
this.firmwareUpgrading = true;
|
||||||
|
}.bind(this)).error(function (err) {
|
||||||
}.bind(this)).error(function () {
|
api.alert('Firmware update failed');
|
||||||
api.alert('Invalid password or bad firmware');
|
console.error('Firmware update failed', err);
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
show_upgrade: function () {
|
show_upgrade: function () {
|
||||||
if (!this.latestVersion) return false;
|
if (!this.latestVersion) return false;
|
||||||
return is_newer_version(this.config.version, this.latestVersion);
|
return is_newer_version(this.config.version, this.latestVersion);
|
||||||
@@ -325,80 +320,61 @@ module.exports = new Vue({
|
|||||||
this.$emit('check');
|
this.$emit('check');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.check_ip_address();
|
this.check_ip_address();
|
||||||
this.check_ssid();
|
this.check_ssid();
|
||||||
//.check_disk_space();
|
//.check_disk_space();
|
||||||
|
|
||||||
|
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
|
|
||||||
check_ip_address : function() {
|
check_ip_address: function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: 'hostinfo.txt',
|
url: 'hostinfo.txt',
|
||||||
data: {hid: this.state.hid},
|
data: { hid: this.state.hid },
|
||||||
cache: false
|
cache: false
|
||||||
|
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
console.debug('>', data);
|
console.debug('>', data);
|
||||||
this.ipAddress = 'IP:' + data;
|
this.ipAddress = 'IP:' + data;
|
||||||
this.$broadcast('ipAddress', data);
|
this.$broadcast('ipAddress', data);
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
|
|
||||||
check_ssid : function() {
|
check_ssid: function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: 'ssidinfo.txt',
|
url: 'ssidinfo.txt',
|
||||||
data: {hid: this.state.hid},
|
data: { hid: this.state.hid },
|
||||||
cache: false
|
cache: false
|
||||||
|
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
console.debug('>', data);
|
console.debug('>', data);
|
||||||
this.wifiSSID = 'SSID:' + data;
|
this.wifiSSID = 'SSID:' + data;
|
||||||
this.$broadcast('wifiSSID', data);
|
this.$broadcast('wifiSSID', data);
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
|
||||||
|
|
||||||
// check_disk_space : function() {
|
|
||||||
// $.ajax({
|
|
||||||
// type: 'GET',
|
|
||||||
// url: 'diskinfo.txt',
|
|
||||||
// data: {hid: this.state.hid},
|
|
||||||
// cache: false
|
|
||||||
//
|
|
||||||
// }).done(function (data) {
|
|
||||||
// console.debug('>', data);
|
|
||||||
// this.diskSpace = data;
|
|
||||||
// this.$broadcast('diskSpace', data);
|
|
||||||
// }.bind(this))
|
|
||||||
// },
|
|
||||||
|
|
||||||
get_ip_address : function() {
|
|
||||||
console.debug('get_ip>', this.ipAddress);
|
|
||||||
return this.ipAddress;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get_ssid : function() {
|
get_ip_address: function () {
|
||||||
console.debug('get_ssid>', this.wifiSSID);
|
console.debug('get_ip>', this.ipAddress);
|
||||||
return this.wifiSSID;
|
return this.ipAddress;
|
||||||
},
|
},
|
||||||
|
|
||||||
// get_disk_space : function() {
|
get_ssid: function () {
|
||||||
// console.debug('get_disk>', this.diskSpace);
|
console.debug('get_ssid>', this.wifiSSID);
|
||||||
// return this.diskSpace;
|
return this.wifiSSID;
|
||||||
// },
|
},
|
||||||
|
|
||||||
shutdown : function() {
|
shutdown: function () {
|
||||||
this.confirmShutdown = false;
|
this.confirmShutdown = false;
|
||||||
api.put('shutdown');
|
api.put('shutdown');
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
reboot : function() {
|
reboot: function () {
|
||||||
this.confirmShutdown = false;
|
this.confirmShutdown = false;
|
||||||
api.put('reboot');
|
api.put('reboot');
|
||||||
},
|
},
|
||||||
|
|
||||||
connect: function () {
|
connect: function () {
|
||||||
@@ -456,7 +432,6 @@ module.exports = new Vue({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
parse_hash: function () {
|
parse_hash: function () {
|
||||||
var hash = location.hash.substr(1);
|
var hash = location.hash.substr(1);
|
||||||
|
|
||||||
@@ -472,7 +447,6 @@ module.exports = new Vue({
|
|||||||
this.currentView = parts[0];
|
this.currentView = parts[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
save: function () {
|
save: function () {
|
||||||
api.put('config/save', this.config).done(function (data) {
|
api.put('config/save', this.config).done(function (data) {
|
||||||
this.modified = false;
|
this.modified = false;
|
||||||
@@ -481,7 +455,6 @@ module.exports = new Vue({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
close_messages: function (action) {
|
close_messages: function (action) {
|
||||||
if (action == 'stop') api.put('stop');
|
if (action == 'stop') api.put('stop');
|
||||||
if (action == 'continue') api.put('unpause');
|
if (action == 'continue') api.put('unpause');
|
||||||
|
|||||||
@@ -160,11 +160,6 @@ html(lang="en")
|
|||||||
| Are you sure you want to upgrade the firmware to version
|
| Are you sure you want to upgrade the firmware to version
|
||||||
| {{latestVersion}}?
|
| {{latestVersion}}?
|
||||||
|
|
||||||
p.pure-control-group
|
|
||||||
label(for="pass") Password
|
|
||||||
input(name="pass", v-model="password", type="password",
|
|
||||||
@keyup.enter="upgrade_confirmed")
|
|
||||||
|
|
||||||
div(slot="footer")
|
div(slot="footer")
|
||||||
button.pure-button(@click="confirmUpgrade=false") Cancel
|
button.pure-button(@click="confirmUpgrade=false") Cancel
|
||||||
button.pure-button.pure-button-primary(@click="upgrade_confirmed")
|
button.pure-button.pure-button-primary(@click="upgrade_confirmed")
|
||||||
@@ -175,11 +170,6 @@ html(lang="en")
|
|||||||
div(slot="body")
|
div(slot="body")
|
||||||
p Are you sure you want to upload firmware #[em {{firmwareName}}]?
|
p Are you sure you want to upload firmware #[em {{firmwareName}}]?
|
||||||
|
|
||||||
p.pure-control-group
|
|
||||||
label(for="pass") Password
|
|
||||||
input(name="pass", v-model="password", type="password",
|
|
||||||
@keyup.enter="upload_confirmed")
|
|
||||||
|
|
||||||
div(slot="footer")
|
div(slot="footer")
|
||||||
button.pure-button(@click="confirmUpload=false") Cancel
|
button.pure-button(@click="confirmUpload=false") Cancel
|
||||||
button.pure-button.pure-button-primary(@click="upload_confirmed")
|
button.pure-button.pure-button-primary(@click="upload_confirmed")
|
||||||
|
|||||||
@@ -257,14 +257,9 @@ class FirmwareUpdateHandler(bbctrl.APIHandler):
|
|||||||
|
|
||||||
|
|
||||||
def put_ok(self):
|
def put_ok(self):
|
||||||
if not 'password' in self.request.arguments:
|
|
||||||
raise HTTPError(401, 'Missing "password"')
|
|
||||||
|
|
||||||
if not 'firmware' in self.request.files:
|
if not 'firmware' in self.request.files:
|
||||||
raise HTTPError(401, 'Missing "firmware"')
|
raise HTTPError(401, 'Missing "firmware"')
|
||||||
|
|
||||||
check_password(self.request.arguments['password'][0])
|
|
||||||
|
|
||||||
firmware = self.request.files['firmware'][0]
|
firmware = self.request.files['firmware'][0]
|
||||||
|
|
||||||
if not os.path.exists('firmware'): os.mkdir('firmware')
|
if not os.path.exists('firmware'): os.mkdir('firmware')
|
||||||
@@ -278,7 +273,6 @@ class FirmwareUpdateHandler(bbctrl.APIHandler):
|
|||||||
|
|
||||||
class UpgradeHandler(bbctrl.APIHandler):
|
class UpgradeHandler(bbctrl.APIHandler):
|
||||||
def put_ok(self):
|
def put_ok(self):
|
||||||
check_password(self.json['password'])
|
|
||||||
self.get_ctrl().lcd.goodbye('Upgrading firmware')
|
self.get_ctrl().lcd.goodbye('Upgrading firmware')
|
||||||
subprocess.Popen(['/usr/local/bin/upgrade-bbctrl'])
|
subprocess.Popen(['/usr/local/bin/upgrade-bbctrl'])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user