Use secure protocols if page was loaded securely

pull/1/head
cpsdqs 7 years ago
parent cf29deaa0c
commit 0794030210
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 5
      js/term/connection.js
  2. 4
      js/wifi.js

@ -5,6 +5,7 @@ try { demo = require('./demo') } catch (err) {}
const RECONN_DELAY = 2000 const RECONN_DELAY = 2000
const HEARTBEAT_TIME = 3000 const HEARTBEAT_TIME = 3000
const HTTPS = window.location.protocol.match(/s:/)
/** Handle connections */ /** Handle connections */
module.exports = class TermConnection extends EventEmitter { module.exports = class TermConnection extends EventEmitter {
@ -192,7 +193,7 @@ module.exports = class TermConnection extends EventEmitter {
this.closeSocket() this.closeSocket()
this.ws = new window.WebSocket('ws://' + window._root + '/term/update.ws') this.ws = new window.WebSocket(`${HTTPS ? 'wss' : 'ws'}://${window._root}/term/update.ws`)
this.ws.addEventListener('open', (...args) => this.onWSOpen(...args)) this.ws.addEventListener('open', (...args) => this.onWSOpen(...args))
this.ws.addEventListener('close', (...args) => this.onWSClose(...args)) this.ws.addEventListener('close', (...args) => this.onWSClose(...args))
this.ws.addEventListener('message', (...args) => this.onWSMessage(...args)) this.ws.addEventListener('message', (...args) => this.onWSMessage(...args))
@ -211,7 +212,7 @@ module.exports = class TermConnection extends EventEmitter {
sendPing () { sendPing () {
console.log('> ping') console.log('> ping')
this.emit('ping') this.emit('ping')
$.get('http://' + window._root + '/api/v1/ping', (resp, status) => { $.get(`${HTTPS ? 'https' : 'http'}://${window._root}/api/v1/ping`, (resp, status) => {
if (status === 200) { if (status === 200) {
clearInterval(this.pingInterval) clearInterval(this.pingInterval)
console.info('Server ready, opening socket…') console.info('Server ready, opening socket…')

@ -2,6 +2,8 @@ const $ = require('./lib/chibi')
const { mk } = require('./utils') const { mk } = require('./utils')
const tr = require('./lang') const tr = require('./lang')
const HTTPS = window.location.protocol.match(/s:/)
{ {
const w = window.WiFi = {} const w = window.WiFi = {}
@ -131,7 +133,7 @@ const tr = require('./lang')
if (window._demo) { if (window._demo) {
onScan(window._demo_aps, 200) onScan(window._demo_aps, 200)
} else { } else {
$.get('http://' + window._root + '/cfg/wifi/scan', onScan) $.get(`${HTTPS ? 'https' : 'http'}://${window._root}/cfg/wifi/scan`, onScan)
} }
} }

Loading…
Cancel
Save