@@ -22,34 +22,42 @@ import { rerouteLog, browser } from './globals.js';
2222
2323userale . addCallbacks ( { reroute : rerouteLog } ) ;
2424
25- function setConfig ( e ) {
26- browser . storage . local . set (
27- { useraleConfig : {
28- url : document . getElementById ( "url" ) . value ,
29- userId : document . getElementById ( "user" ) . value ,
30- toolName : document . getElementById ( "tool" ) . value ,
31- version : document . getElementById ( "version" ) . value
32- } } ,
33- ( ) => { getConfig ( ) }
34- ) ;
25+ // TODO: Warn users when setting credentials with unsecured connection.
26+ const mitmWarning = "Setting credentials with http will expose you to a MITM attack. Are you sure you want to continue?" ;
27+
28+ function setConfig ( ) {
29+ let config = {
30+ url : document . getElementById ( "url" ) . value ,
31+ userId : document . getElementById ( "user" ) . value ,
32+ toolName : document . getElementById ( "tool" ) . value ,
33+ version : document . getElementById ( "version" ) . value
34+ } ;
35+
36+ // Set a basic auth header if given credentials.
37+ const password = document . getElementById ( "password" ) . value ;
38+ if ( config . userId && password ) {
39+ config . authHeader = "Basic " + btoa ( `${ config . userId } :${ password } ` ) ;
40+ }
41+
42+ browser . storage . local . set ( { useraleConfig : config } , ( ) => {
43+ userale . options ( config ) ;
44+ browser . runtime . sendMessage ( { type : MessageTypes . CONFIG_CHANGE , payload : config } ) ;
45+ } ) ;
3546}
3647
3748function getConfig ( ) {
3849 browser . storage . local . get ( "useraleConfig" , ( res ) => {
3950 let config = res . useraleConfig ;
4051
52+ userale . options ( config ) ;
4153 document . getElementById ( "url" ) . value = config . url ;
4254 document . getElementById ( "user" ) . value = config . userId ;
4355 document . getElementById ( "tool" ) . value = config . toolName ;
4456 document . getElementById ( "version" ) . value = config . version ;
45-
46- userale . options ( config ) ;
47- browser . runtime . sendMessage ( { type : MessageTypes . CONFIG_CHANGE , payload : config } ) ;
48-
4957 } ) ;
5058}
5159
52- document . addEventListener ( ' DOMContentLoaded' , getConfig ) ;
60+ document . addEventListener ( " DOMContentLoaded" , getConfig ) ;
5361document . addEventListener ( "submit" , setConfig ) ;
5462
5563/* eslint-enable */
0 commit comments