33 category : 'config' ,
44 defaults : {
55 subject : { value : "" , required : true } ,
6- // The below 3 key fields are not used anymore (i.e. replaced by credentials) but we cannot
7- // remove them here, otherwise the keys of old existing nodes would be lost ...
8- publicKey : { value : "" } ,
9- privateKey : { value : "" } ,
6+ publicKey : { value : "" , required : true } ,
7+ privateKey : { value : "" , required : true } ,
108 gcmApiKey : { value : "" } ,
119 name : { value : "" }
1210 } ,
13- credentials : {
14- // TODO how make credentials required??
15- publicKey2 : { type :"password" } ,
16- privateKey2 : { type : "password" } ,
17- gcmApiKey2 : { type :"password" }
18- } ,
1911 label : function ( ) {
2012 return this . name || this . subject ;
21- } ,
22- oneditprepare : function ( ) {
23- var node = this ;
24-
25- // For old nodes (without credentials), the (unsecure) keys should be converted to credentials. Some remarks:
26- // - The old html screen elements should remain available, in order to keep the old node values.
27- // - The new keys have postfix '2', otherwise Node-RED binds the html screen element to both old and new node fields.
28- // - We will manipulate the html screen element values, so Node-RED will automatically sync the node values (at 'Done' or 'Cancel').
29- if ( node . publicKey ) {
30- $ ( '#node-config-input-publicKey' ) . val ( "" ) ;
31- $ ( '#node-config-input-publicKey2' ) . val ( node . publicKey ) ;
32- }
33- if ( node . privateKey ) {
34- $ ( '#node-config-input-privateKey' ) . val ( "" ) ;
35- $ ( '#node-config-input-privateKey2' ) . val ( node . privateKey ) ;
36- }
37- if ( node . gcmApiKey ) {
38- $ ( '#node-config-input-gcmApiKey' ) . val ( "" ) ;
39- $ ( '#node-config-input-gcmApiKey2' ) . val ( node . gcmApiKey ) ;
40- }
41-
42- $ ( "#node-input-generateKeyPair" ) . click ( function ( ) {
43- if ( $ ( "#node-config-input-publicKey2" ) . val ( ) || $ ( "#node-config-input-privateKey2" ) . val ( ) ) {
44- if ( ! confirm ( "The current keypair will be overwritten! Are you sure to continue?" ) ) {
45- // The user has clicked the 'Cancel' button
46- return ;
47- }
48- }
49-
50- // Ask the server side flow to generate a new key pair
51- $ . getJSON ( 'vapid_configuration/generate_key_pair' , function ( jsonData ) {
52- // Show the new keys on the config screen
53- $ ( "#node-config-input-publicKey2" ) . val ( jsonData . publicKey ) ;
54- $ ( "#node-config-input-privateKey2" ) . val ( jsonData . privateKey ) ;
55-
56- // Make sure the validators are being triggerd, otherwise the red border will remain around the input fields
57- $ ( "#node-config-input-publicKey2" ) . change ( ) ;
58- $ ( "#node-config-input-privateKey2" ) . change ( ) ;
59- } ) . error ( function ( ) {
60- RED . notify ( "Cannot create VAPID key pair. See Node-RED log for more details..." , "error" ) ;
61- } ) ;
62- } ) ;
6313 }
6414 } ) ;
6515
7121 < input type = "text" id = "node-config-input-subject" placeholder = "This must be either a URL or a 'mailto:' address." >
7222 </ div >
7323 < div class = "form-row" >
74- < label > </ label >
75- < button id = "node-input-generateKeyPair" > < i class = "fa fa-exchange" > </ i > Generate VAPID keypair</ button >
76- </ div >
77- < div class = "form-row" hidden >
78- <!-- Unused hidden fields to bind the old (unsecure) keys in the node instance -->
79- < input type = "text" id = "node-config-input-publicKey" >
80- < input type = "text" id = "node-config-input-privateKey" >
81- < input type = "text" id = "node-config-input-gcmApiKey" >
82- </ div >
83- < div class = "form-row" >
84- < label for = "node-config-input-publicKey2" > < i class = "icon-tag" > </ i > Public Key</ label >
85- < input type = "password" id = "node-config-input-publicKey2" >
24+ < label for = "node-config-input-publicKey" > < i class = "icon-tag" > </ i > Public Key</ label >
25+ < input type = "text" id = "node-config-input-publicKey" placeholder = "The public VAPID key" >
8626 </ div >
8727 < div class = "form-row" >
88- < label for = "node-config-input-privateKey2 " > < i class = "icon-tag" > </ i > Private Key</ label >
89- < input type = "password " id = "node-config-input-privateKey2 " >
28+ < label for = "node-config-input-privateKey " > < i class = "icon-tag" > </ i > Private Key</ label >
29+ < input type = "text " id = "node-config-input-privateKey" placeholder = "The public VAPID key ">
9030 </ div >
9131 < div class = "form-row" >
92- < label for = "node-config-input-gcmApiKey2 " > < i class = "icon-tag" > </ i > GCM API Key (for older browsers)</ label >
93- < input type = "password " id = "node-config-input-gcmApiKey2 " >
32+ < label for = "node-config-input-gcmApiKey " > < i class = "icon-tag" > </ i > GCM API Key (for older browsers)</ label >
33+ < input type = "text " id = "node-config-input-gcmApiKey" placeholder = "The API key to send with the GCM request ">
9434 </ div >
9535 < div class = "form-row" >
9636 < label for = "node-config-input-name" > < i class = "icon-tag" > </ i > Name</ label >
10141< script type ="text/x-red " data-help-name ="vapid-configuration ">
10242 < p > Configuration for VAPID. You can generate the key pair using < code > generateVAPIDKeys()</ code > method of < a href = "https://www.npmjs.com/package/web-push" target = "_blank" > web-push</ a > library or online here: < a href = "https://web-push-codelab.glitch.me/" target = "_blank" > https://web-push-codelab.glitch.me</ a > .</ p >
10343 < p > For Chrome prior to version 52 and some old browsers , you 're also still required to include a <code>gcm_sender_id</code> in your web app' s manifest . json . < / p >
104- </ script >
44+ </ script >
0 commit comments