mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
Use backend service to verify nodeID (fixes #418)
This commit is contained in:
parent
4fe2992924
commit
3388d5b49c
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/calmh/syncthing/events"
|
"github.com/calmh/syncthing/events"
|
||||||
"github.com/calmh/syncthing/logger"
|
"github.com/calmh/syncthing/logger"
|
||||||
"github.com/calmh/syncthing/model"
|
"github.com/calmh/syncthing/model"
|
||||||
|
"github.com/calmh/syncthing/protocol"
|
||||||
"github.com/vitrun/qart/qr"
|
"github.com/vitrun/qart/qr"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -103,6 +104,7 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro
|
|||||||
getRestMux.HandleFunc("/rest/report", withModel(m, restGetReport))
|
getRestMux.HandleFunc("/rest/report", withModel(m, restGetReport))
|
||||||
getRestMux.HandleFunc("/rest/events", restGetEvents)
|
getRestMux.HandleFunc("/rest/events", restGetEvents)
|
||||||
getRestMux.HandleFunc("/rest/upgrade", restGetUpgrade)
|
getRestMux.HandleFunc("/rest/upgrade", restGetUpgrade)
|
||||||
|
getRestMux.HandleFunc("/rest/nodeid", restGetNodeID)
|
||||||
|
|
||||||
// The POST handlers
|
// The POST handlers
|
||||||
postRestMux := http.NewServeMux()
|
postRestMux := http.NewServeMux()
|
||||||
@ -444,6 +446,22 @@ func restGetUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
json.NewEncoder(w).Encode(res)
|
json.NewEncoder(w).Encode(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func restGetNodeID(w http.ResponseWriter, r *http.Request) {
|
||||||
|
qs := r.URL.Query()
|
||||||
|
idStr := qs.Get("id")
|
||||||
|
id, err := protocol.NodeIDFromString(idStr)
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
if err == nil {
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
|
"id": id.String(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
|
"error": err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
|
func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
|
||||||
err := upgrade()
|
err := upgrade()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
15
gui/app.js
15
gui/app.js
@ -865,7 +865,7 @@ syncthing.directive('uniqueRepo', function() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
syncthing.directive('validNodeid', function() {
|
syncthing.directive('validNodeid', function($http) {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
@ -874,12 +874,13 @@ syncthing.directive('validNodeid', function() {
|
|||||||
// we shouldn't validate
|
// we shouldn't validate
|
||||||
ctrl.$setValidity('validNodeid', true);
|
ctrl.$setValidity('validNodeid', true);
|
||||||
} else {
|
} else {
|
||||||
var cleaned = viewValue.replace(/ /g, '').replace(/-/g, '').toLowerCase().trim();
|
$http.get(urlbase + '/nodeid?id='+viewValue).success(function (resp) {
|
||||||
if (cleaned.match(/^[a-z2-7]{52}$/)) {
|
if (resp.error) {
|
||||||
ctrl.$setValidity('validNodeid', true);
|
ctrl.$setValidity('validNodeid', false);
|
||||||
} else {
|
} else {
|
||||||
ctrl.$setValidity('validNodeid', false);
|
ctrl.$setValidity('validNodeid', true);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return viewValue;
|
return viewValue;
|
||||||
});
|
});
|
||||||
|
@ -398,7 +398,7 @@
|
|||||||
<span ng-show="!editingExisting">When adding a new node, keep in mind that <em>this node</em> must be added on the other side too.</span>
|
<span ng-show="!editingExisting">When adding a new node, keep in mind that <em>this node</em> must be added on the other side too.</span>
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="nodeEditor.nodeID.$error.required && nodeEditor.nodeID.$dirty">The node ID cannot be blank.</span>
|
<span ng-if="nodeEditor.nodeID.$error.required && nodeEditor.nodeID.$dirty">The node ID cannot be blank.</span>
|
||||||
<span ng-if="nodeEditor.nodeID.$error.validNodeid && nodeEditor.nodeID.$dirty">The entered node ID does not look valid. It should be a 52 character string consisting of letters and numbers, with spaces and dashes being optional.</span>
|
<span ng-if="nodeEditor.nodeID.$error.validNodeid && nodeEditor.nodeID.$dirty">The entered node ID does not look valid. It should be a 52 or 56 character string consisting of letters and numbers, with spaces and dashes being optional.</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -120,7 +119,6 @@ func unluhnify(s string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if g := fmt.Sprintf("%s%c", p, l); g != s[i*14:(i+1)*14] {
|
if g := fmt.Sprintf("%s%c", p, l); g != s[i*14:(i+1)*14] {
|
||||||
log.Printf("%q; %q", g, s[i*14:(i+1)*14])
|
|
||||||
return "", errors.New("check digit incorrect")
|
return "", errors.New("check digit incorrect")
|
||||||
}
|
}
|
||||||
res = append(res, p)
|
res = append(res, p)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user