up web client can get pwd if exist

This commit is contained in:
ljw
2024-09-24 10:15:04 +08:00
parent 5b5943b287
commit a161e3ba10
2 changed files with 25 additions and 1 deletions

View File

@@ -12,6 +12,15 @@ func (i *Index) ConfigJs(c *gin.Context) {
apiServer := global.Config.Rustdesk.ApiServer
tmp := `
function stringToUint8Array(str){
var arr = [];
for (var i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i));
}
var tmpUint8Array = new Uint8Array(arr);
return tmpUint8Array
}
window._gwen = {}
window._gwen.kv = {}
function getQueryVariable() {
@@ -53,13 +62,26 @@ const autoWriteServer = () => {
}
if (res.data.peers) {
oldPeers = JSON.parse(localStorage.getItem('peers')) || {}
oldPeers = JSON.parse(localStorage.getItem('peers')) || {}
let needUpdate = false
Object.keys(res.data.peers).forEach(k => {
if(!oldPeers[k]) {
oldPeers[k] = res.data.peers[k]
needUpdate = true
}else{
oldPeers[k].info = res.data.peers[k].info
}
if (oldPeers[k].info && oldPeers[k].info.hash&&!oldPeers[k].password ) {
let p1 = window.atob(oldPeers[k].info.hash)
const pwd = stringToUint8Array(p1)
oldPeers[k].password = pwd.toString()
oldPeers[k].remember = true
}
})
localStorage.setItem('peers', JSON.stringify(oldPeers))
if(needUpdate) {
window.location.reload()
}
}
}
})

View File

@@ -15,6 +15,7 @@ type WebClientPeerInfoPayload struct {
Username string `json:"username"`
Hostname string `json:"hostname"`
Platform string `json:"platform"`
Hash string `json:"hash"`
}
func (wcpp *WebClientPeerPayload) FromAddressBook(a *model.AddressBook) {
@@ -25,5 +26,6 @@ func (wcpp *WebClientPeerPayload) FromAddressBook(a *model.AddressBook) {
Username: a.Username,
Hostname: a.Hostname,
Platform: a.Platform,
Hash: a.Hash,
}
}