Просмотр исходного кода

up web client can get pwd if exist

ljw 1 год назад
Родитель
Сommit
62a22c697d
2 измененных файлов с 25 добавлено и 1 удалено
  1. 23 1
      http/controller/web/index.go
  2. 2 0
      http/response/api/webClient.go

+ 23 - 1
http/controller/web/index.go

@@ -12,6 +12,15 @@ func (i *Index) ConfigJs(c *gin.Context) {
12
 	apiServer := global.Config.Rustdesk.ApiServer
12
 	apiServer := global.Config.Rustdesk.ApiServer
13
 
13
 
14
 	tmp := `
14
 	tmp := `
15
+      function stringToUint8Array(str){
16
+		  var arr = [];
17
+		  for (var i = 0, j = str.length; i < j; ++i) {
18
+			arr.push(str.charCodeAt(i));
19
+		  }
20
+		 
21
+		  var tmpUint8Array = new Uint8Array(arr);
22
+		  return tmpUint8Array
23
+	 }
15
  	  window._gwen = {}
24
  	  window._gwen = {}
16
       window._gwen.kv = {}
25
       window._gwen.kv = {}
17
       function getQueryVariable() {
26
       function getQueryVariable() {
@@ -53,13 +62,26 @@ const autoWriteServer = () => {
53
 							}	
62
 							}	
54
                          
63
                          
55
 						  if (res.data.peers) {
64
 						  if (res.data.peers) {
56
-								oldPeers = JSON.parse(localStorage.getItem('peers')) || {}
65
+                              oldPeers = JSON.parse(localStorage.getItem('peers')) || {}
66
+							  let needUpdate = false	
57
 							  Object.keys(res.data.peers).forEach(k => {
67
 							  Object.keys(res.data.peers).forEach(k => {
58
 								if(!oldPeers[k]) {
68
 								if(!oldPeers[k]) {
59
 									oldPeers[k] = res.data.peers[k]
69
 									oldPeers[k] = res.data.peers[k]
70
+									needUpdate = true
71
+								}else{
72
+									oldPeers[k].info = res.data.peers[k].info
60
 								}
73
 								}
74
+								if (oldPeers[k].info && oldPeers[k].info.hash&&!oldPeers[k].password ) {
75
+									let p1 = window.atob(oldPeers[k].info.hash)
76
+									const pwd = stringToUint8Array(p1)
77
+									oldPeers[k].password = pwd.toString()
78
+                                    oldPeers[k].remember = true
79
+								}							
61
                               })
80
                               })
62
 							  localStorage.setItem('peers', JSON.stringify(oldPeers))
81
 							  localStorage.setItem('peers', JSON.stringify(oldPeers))
82
+							  if(needUpdate) {
83
+								  window.location.reload()
84
+                              }
63
 					      }
85
 					      }
64
                       }
86
                       }
65
                   })
87
                   })

+ 2 - 0
http/response/api/webClient.go

@@ -15,6 +15,7 @@ type WebClientPeerInfoPayload struct {
15
 	Username string `json:"username"`
15
 	Username string `json:"username"`
16
 	Hostname string `json:"hostname"`
16
 	Hostname string `json:"hostname"`
17
 	Platform string `json:"platform"`
17
 	Platform string `json:"platform"`
18
+	Hash     string `json:"hash"`
18
 }
19
 }
19
 
20
 
20
 func (wcpp *WebClientPeerPayload) FromAddressBook(a *model.AddressBook) {
21
 func (wcpp *WebClientPeerPayload) FromAddressBook(a *model.AddressBook) {
@@ -25,5 +26,6 @@ func (wcpp *WebClientPeerPayload) FromAddressBook(a *model.AddressBook) {
25
 		Username: a.Username,
26
 		Username: a.Username,
26
 		Hostname: a.Hostname,
27
 		Hostname: a.Hostname,
27
 		Platform: a.Platform,
28
 		Platform: a.Platform,
29
+		Hash:     a.Hash,
28
 	}
30
 	}
29
 }
31
 }