Selaa lähdekoodia

gui, lib/config: Add GUI user and password notification (fixes #4703) (#6536)

Jędrzej Kula 5 vuotta sitten
vanhempi
sitoutus
28d5c84599

+ 25 - 0
gui/default/syncthing/core/notifications.html

@@ -116,3 +116,28 @@
     </div>
   </div>
 </notification>
+
+<notification id="authenticationUserAndPassword">
+  <div class="panel panel-success">
+    <div class="panel-heading">
+      <h3 class="panel-title"><span class="fas fa-bolt"></span>&nbsp;<span translate>GUI Authentication: Set User and Password</span></h3>
+    </div>
+    <div class="panel-body">
+      <p>
+        <span translate>Username/Password has not been set for the GUI authentication. Please consider setting it up.</span>
+      </p>
+      <p>
+        <span translate>If you want to prevent other users on this computer to access Syncthing and through it your files, consider setting up authentication.</span>
+      </p>
+    </div>
+    <div class="panel-footer">
+      <button type="button" class="btn btn-sm btn-default pull-right" ng-click="showSettings()">
+        <span class="fas fa-cog"></span>&nbsp;<span translate>Settings</span>
+      </button>
+      <button type="button" class="btn btn-sm btn-default pull-left" ng-click="dismissNotification('authenticationUserAndPassword')">
+        <span class="fa fa-check-circle"></span>&nbsp;<span translate>OK</span>
+      </button>
+      <div class="clearfix"></div>
+    </div>
+  </div>
+</notification>

+ 4 - 0
gui/default/syncthing/core/syncthingController.js

@@ -448,6 +448,10 @@ angular.module('syncthing.core')
                 && (!guiCfg.user || !guiCfg.password)
                 && guiCfg.authMode !== 'ldap'
                 && !guiCfg.insecureAdminAccess;
+
+            if (guiCfg.user && guiCfg.password) {
+                dismissNotification('authenticationUserAndPassword');
+            }
         }
 
 

+ 10 - 1
lib/config/config.go

@@ -31,7 +31,7 @@ import (
 
 const (
 	OldestHandledVersion = 10
-	CurrentVersion       = 30
+	CurrentVersion       = 31
 	MaxRescanIntervalS   = 365 * 24 * 60 * 60
 )
 
@@ -103,6 +103,8 @@ func New(myID protocol.DeviceID) Configuration {
 	cfg.Version = CurrentVersion
 	cfg.OriginalVersion = CurrentVersion
 
+	cfg.Options.UnackedNotificationIDs = []string{"authenticationUserAndPassword"}
+
 	util.SetDefaults(&cfg)
 	util.SetDefaults(&cfg.Options)
 	util.SetDefaults(&cfg.GUI)
@@ -418,6 +420,13 @@ nextPendingDevice:
 	}
 	if cfg.Options.UnackedNotificationIDs == nil {
 		cfg.Options.UnackedNotificationIDs = []string{}
+	} else if cfg.GUI.User != "" && cfg.GUI.Password != "" {
+		for i, key := range cfg.Options.UnackedNotificationIDs {
+			if key == "authenticationUserAndPassword" {
+				cfg.Options.UnackedNotificationIDs = append(cfg.Options.UnackedNotificationIDs[:i], cfg.Options.UnackedNotificationIDs[i+1:]...)
+				break
+			}
+		}
 	}
 
 	return nil

+ 1 - 1
lib/config/config_test.go

@@ -67,7 +67,7 @@ func TestDefaultValues(t *testing.T) {
 		AlwaysLocalNets:         []string{},
 		OverwriteRemoteDevNames: false,
 		TempIndexMinBlocks:      10,
-		UnackedNotificationIDs:  []string{},
+		UnackedNotificationIDs:  []string{"authenticationUserAndPassword"},
 		DefaultFolderPath:       "~",
 		SetLowPriority:          true,
 		CRURL:                   "https://crash.syncthing.net/newcrash",

+ 6 - 0
lib/config/migrations.go

@@ -25,6 +25,7 @@ import (
 // update the config version. The order of migrations doesn't matter here,
 // put the newest on top for readability.
 var migrations = migrationSet{
+	{31, migrateToConfigV31},
 	{30, migrateToConfigV30},
 	{29, migrateToConfigV29},
 	{28, migrateToConfigV28},
@@ -85,6 +86,11 @@ func (m migration) apply(cfg *Configuration) {
 	cfg.Version = m.targetVersion
 }
 
+func migrateToConfigV31(cfg *Configuration) {
+	// Show a notification about setting User and Password
+	cfg.Options.UnackedNotificationIDs = append(cfg.Options.UnackedNotificationIDs, "authenticationUserAndPassword")
+}
+
 func migrateToConfigV30(cfg *Configuration) {
 	// The "max concurrent scans" option is now spelled "max folder concurrency"
 	// to be more general.

+ 1 - 1
lib/config/testdata/overridenvalues.xml

@@ -1,4 +1,4 @@
-<configuration version="29">
+<configuration version="31">
     <options>
         <listenAddress>tcp://:23000</listenAddress>
         <allowDelete>false</allowDelete>