2014-10-05 22:50:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// Copyright 2014 Unknwon
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Copyright 2014 Torkel Ödegaard
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								package  setting  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  (  
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"bytes" 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"errors" 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-12 20:31:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"fmt" 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-01 18:47:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"net/http" 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"net/url" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"os" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"path" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"path/filepath" 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"regexp" 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									"runtime" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									"strings" 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-02 19:33:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"time" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-29 20:27:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/go-macaron/session" 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ini  "gopkg.in/ini.v1" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-13 14:45:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/infra/log" 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-19 15:14:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									"github.com/grafana/grafana/pkg/util" 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								type  Scheme  string  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  (  
						 
					
						
							
								
									
										
										
										
											2016-11-23 22:35:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									HTTP               Scheme  =  "http" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									HTTPS              Scheme  =  "https" 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-16 23:06:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									HTTP2              Scheme  =  "h2" 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-27 14:54:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SOCKET             Scheme  =  "socket" 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-23 22:35:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DEFAULT_HTTP_ADDR  string  =  "0.0.0.0" 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 22:33:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									REDACTED_PASSWORD  string  =  "*********" 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-12-16 19:04:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  (  
						 
					
						
							
								
									
										
										
										
											2020-01-27 16:24:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DEV       =  "development" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PROD      =  "production" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									TEST      =  "test" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									APP_NAME  =  "Grafana" 
							 
						 
					
						
							
								
									
										
										
										
											2014-12-16 19:04:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-02 17:49:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ERR_TEMPLATE_NAME  =  "error" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 17:51:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// This constant corresponds to the default value for ldap_sync_ttl in .ini files
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// it is used for comparision and has to be kept in sync
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AUTH_PROXY_SYNC_TTL  =  60 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								var  (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// App settings.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-27 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Env               =  DEV 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AppUrl            string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AppSubUrl         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ServeFromSubPath  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									InstanceName      string 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-01-05 17:46:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// build
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-27 19:41:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									BuildVersion     string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									BuildCommit      string 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-29 20:27:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									BuildBranch      string 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-27 19:41:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									BuildStamp       int64 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-02 19:33:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									IsEnterprise     bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-27 19:41:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ApplicationName  string 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-05 17:46:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-15 21:42:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// packaging
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Packaging  =  "unknown" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Paths
 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-01 21:51:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									HomePath        string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PluginsPath     string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									CustomInitPath  =  "conf/custom.ini" 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									// Log settings.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-19 15:29:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									LogConfigs  [ ] util . DynMap 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Http server options
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Protocol            Scheme 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Domain              string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									HttpAddr ,  HttpPort  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									SshPort             int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									CertFile ,  KeyFile   string 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-27 14:54:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SocketPath          string 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-05 22:50:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									RouterLogging       bool 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-11 23:51:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DataProxyLogging    bool 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-25 03:04:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DataProxyTimeout    int 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-05 22:50:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									StaticRootPath      string 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-14 17:34:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									EnableGzip          bool 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-05 17:21:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									EnforceDomain       bool 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-05 22:50:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Security settings.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-12 19:15:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SecretKey                          string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DisableGravatar                    bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									EmailCodeValidMinutes              int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DataProxyWhiteList                 map [ string ] bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DisableBruteForceLoginProtection   bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									CookieSecure                       bool 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-15 00:41:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CookieSameSiteDisabled             bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									CookieSameSiteMode                 http . SameSite 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-12 19:15:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AllowEmbedding                     bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XSSProtectionHeader                bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ContentTypeProtectionHeader        bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StrictTransportSecurity            bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StrictTransportSecurityMaxAge      int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StrictTransportSecurityPreload     bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StrictTransportSecuritySubDomains  bool 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 22:39:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Snapshots
 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 22:56:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExternalSnapshotUrl    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExternalSnapshotName   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExternalEnabled        bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									SnapShotRemoveExpired  bool 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-02 21:15:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SnapshotPublicMode     bool 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 22:39:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-14 18:34:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Dashboard history
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DashboardVersionsToKeep  int 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-28 21:32:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									MinRefreshInterval       string 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-14 18:34:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-11 23:19:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// User settings
 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-31 20:39:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AllowUserSignUp          bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AllowUserOrgCreate       bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AutoAssignOrg            bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-14 03:14:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AutoAssignOrgId          int 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-31 20:39:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AutoAssignOrgRole        string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									VerifyEmailEnabled       bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LoginHint                string 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-08 06:00:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									PasswordHint             string 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-31 20:39:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DefaultTheme             string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DisableLoginForm         bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DisableSignoutMenu       bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-27 20:52:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SignoutRedirectUrl       string 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-31 20:39:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExternalUserMngLinkUrl   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExternalUserMngLinkName  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExternalUserMngInfo      string 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-28 22:16:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OAuthAutoLogin           bool 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-14 01:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ViewersCanEdit           bool 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 22:14:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-01-07 23:37:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Http auth
 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AdminUser             string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AdminPassword         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LoginCookieName       string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LoginMaxLifetimeDays  int 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 22:45:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-02-24 03:07:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AnonymousEnabled  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AnonymousOrgName  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AnonymousOrgRole  string 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-07 23:37:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-01 17:55:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Auth proxy settings
 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 00:48:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AuthProxyEnabled           bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AuthProxyHeaderName        string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AuthProxyHeaderProperty    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AuthProxyAutoSignUp        bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AuthProxyEnableLoginToken  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AuthProxySyncTtl           int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AuthProxyWhitelist         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AuthProxyHeaders           map [ string ] string 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-01 17:55:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-06-30 15:37:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Basic Auth
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									BasicAuthEnabled  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-10-05 22:50:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Session settings.
 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-16 04:23:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SessionOptions          session . Options 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									SessionConnMaxLifetime  int64 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Global setting objects.
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Raw           * ini . File 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									ConfRootPath  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									IsWindows     bool 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-07 03:31:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// for logging purposes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									configFiles                   [ ] string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									appliedCommandLineProperties  [ ] string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									appliedEnvOverrides           [ ] string 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-23 03:14:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-21 15:30:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ReportingEnabled    bool 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-12 00:21:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CheckForUpdates     bool 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-21 15:30:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GoogleAnalyticsId   string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									GoogleTagManagerId  string 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-04 15:34:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// LDAP
 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-22 20:30:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									LDAPEnabled            bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LDAPConfigFile         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LDAPSyncCron           string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LDAPAllowSignup        bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LDAPActiveSyncEnabled  bool 
							 
						 
					
						
							
								
									
										
										
										
											2015-07-10 17:10:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-11 01:47:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// QUOTA
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Quota  QuotaSettings 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-29 20:35:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Alerting
 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 17:20:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingEnabled             bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExecuteAlerts               bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-25 18:17:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingRenderLimit         int 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-06 17:20:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingErrorOrTimeout      string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AlertingNoDataOrNullValues  string 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-07 19:31:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-29 13:58:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingEvaluationTimeout    time . Duration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AlertingNotificationTimeout  time . Duration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AlertingMaxAttempts          int 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-14 17:13:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingMinInterval          int64 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-29 13:58:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-27 17:39:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Explore UI
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExploreEnabled  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-05-27 19:52:19 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Grafana.NET URL
 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-22 20:56:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GrafanaComUrl  string 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-30 19:36:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// S3 temp image store
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									S3TempImageStoreBucketUrl  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									S3TempImageStoreAccessKey  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									S3TempImageStoreSecretKey  string 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-10 23:27:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ImageUploadProvider  string 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-24 23:15:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									FeatureToggles       map [ string ] bool 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// TODO move all global vars to this struct
  
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  Cfg  struct  {  
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Raw     * ini . File 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Logger  log . Logger 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// HTTP Server Settings
 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-27 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AppUrl            string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AppSubUrl         string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ServeFromSubPath  bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-05-01 21:51:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Paths
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ProvisioningPath  string 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DataPath          string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LogsPath          string 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-01 21:51:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// SMTP email settings
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Smtp  SmtpSettings 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-05-24 21:26:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Rendering
 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-24 21:58:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ImagesDir              string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PhantomDir             string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									RendererUrl            string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									RendererCallbackUrl    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									RendererLimit          int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									RendererLimitAlerting  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Security
 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 18:11:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DisableInitAdminCreation          bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DisableBruteForceLoginProtection  bool 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CookieSecure                      bool 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-15 00:41:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CookieSameSiteDisabled            bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									CookieSameSiteMode                http . SameSite 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-01 19:07:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									TempDataLifetime                  time . Duration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									MetricsEndpointEnabled            bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-15 04:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									MetricsEndpointBasicAuthUsername  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									MetricsEndpointBasicAuthPassword  string 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-17 15:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									MetricsEndpointDisableTotalStats  bool 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-12 19:46:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									PluginsEnableAlpha                bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PluginsAppsSkipVerifyTLS          bool 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-22 18:56:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DisableSanitizeHtml               bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-01 19:07:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									EnterpriseLicensePath             string 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-22 21:06:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Auth
 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 17:51:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									LoginCookieName               string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LoginMaxInactiveLifetimeDays  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LoginMaxLifetimeDays          int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									TokenRotationIntervalMinutes  int 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-22 19:11:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-30 22:44:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// OAuth
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OAuthCookieMaxAge  int 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-05 22:39:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// SAML Auth
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									SAMLEnabled  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-14 20:04:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Dataproxy
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									SendUserHeader  bool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-04 04:48:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// DistributedCache
 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-09 03:49:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									RemoteCacheOptions  * RemoteCacheOptions 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-12 14:32:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									EditorsCanAdmin  bool 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ApiKeyMaxSecondsToLive  int64 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-09 14:58:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-25 19:25:39 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Use to enable new features which may still be in alpha/beta stage.
 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-09 14:58:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									FeatureToggles  map [ string ] bool 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-08 20:10:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  CommandLineArgs  struct  {  
						 
					
						
							
								
									
										
										
										
											2015-04-12 15:15:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Config    string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									HomePath  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Args      [ ] string 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-08 20:10:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								func  init ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									IsWindows  =  runtime . GOOS  ==  "windows" 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-01 22:29:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  parseAppUrlAndSubUrl ( section  * ini . Section )  ( string ,  string ,  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									appUrl ,  err  :=  valueAsString ( section ,  "root_url" ,  "http://localhost:3000/" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  "" ,  "" ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  appUrl [ len ( appUrl ) - 1 ]  !=  '/'  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										appUrl  +=  "/" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Check if has app suburl.
 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-30 21:21:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									url ,  err  :=  url . Parse ( appUrl ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										log . Fatal ( 4 ,  "Invalid root_url(%s): %s" ,  appUrl ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									appSubUrl  :=  strings . TrimSuffix ( url . Path ,  "/" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  appUrl ,  appSubUrl ,  nil 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-02-06 21:17:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ToAbsUrl ( relativeUrl  string )  string  {  
						 
					
						
							
								
									
										
										
										
											2015-02-04 18:35:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  AppUrl  +  relativeUrl 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-02 02:50:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  shouldRedactKey ( s  string )  bool  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									uppercased  :=  strings . ToUpper ( s ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-27 15:50:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  strings . Contains ( uppercased ,  "PASSWORD" )  ||  strings . Contains ( uppercased ,  "SECRET" )  ||  strings . Contains ( uppercased ,  "PROVIDER_CONFIG" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-02 02:50:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 00:37:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  shouldRedactURLKey ( s  string )  bool  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									uppercased  :=  strings . ToUpper ( s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  strings . Contains ( uppercased ,  "DATABASE_URL" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  applyEnvVariableOverrides ( file  * ini . File )  error  {  
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									appliedEnvOverrides  =  make ( [ ] string ,  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  section  :=  range  file . Sections ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-12 20:31:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  key  :=  range  section . Keys ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 22:33:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											envKey  :=  envKey ( section . Name ( ) ,  key . Name ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-12 20:31:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											envValue  :=  os . Getenv ( envKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  len ( envValue )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												key . SetValue ( envValue ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-02 02:50:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  shouldRedactKey ( envKey )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 22:33:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													envValue  =  REDACTED_PASSWORD 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-04 17:38:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 00:37:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  shouldRedactURLKey ( envKey )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-29 00:03:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													u ,  err  :=  url . Parse ( envValue ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														return  fmt . Errorf ( "could not parse environment variable. key: %s, value: %s. error: %v" ,  envKey ,  envValue ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-29 00:37:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													ui  :=  u . User 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ui  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														_ ,  exists  :=  ui . Password ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  exists  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															u . User  =  url . UserPassword ( ui . Username ( ) ,  "-redacted-" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															envValue  =  u . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												appliedEnvOverrides  =  append ( appliedEnvOverrides ,  fmt . Sprintf ( "%s=%s" ,  envKey ,  envValue ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-12 20:31:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-29 00:03:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2015-02-12 18:55:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 22:33:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  envKey ( sectionName  string ,  keyName  string )  string  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									sN  :=  strings . ToUpper ( strings . Replace ( sectionName ,  "." ,  "_" ,  - 1 ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									kN  :=  strings . ToUpper ( strings . Replace ( keyName ,  "." ,  "_" ,  - 1 ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									envKey  :=  fmt . Sprintf ( "GF_%s_%s" ,  sN ,  kN ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  envKey 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  applyCommandLineDefaultProperties ( props  map [ string ] string ,  file  * ini . File )  {  
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									appliedCommandLineProperties  =  make ( [ ] string ,  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  section  :=  range  file . Sections ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  key  :=  range  section . Keys ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											keyString  :=  fmt . Sprintf ( "default.%s.%s" ,  section . Name ( ) ,  key . Name ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											value ,  exists  :=  props [ keyString ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  exists  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												key . SetValue ( value ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-03-02 02:50:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  shouldRedactKey ( keyString )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 22:33:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													value  =  REDACTED_PASSWORD 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-04 17:38:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												appliedCommandLineProperties  =  append ( appliedCommandLineProperties ,  fmt . Sprintf ( "%s=%s" ,  keyString ,  value ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 02:31:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  applyCommandLineProperties ( props  map [ string ] string ,  file  * ini . File )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  section  :=  range  file . Sections ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 02:02:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										sectionName  :=  section . Name ( )  +  "." 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-30 21:16:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  section . Name ( )  ==  ini . DefaultSection  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 02:02:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											sectionName  =  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  key  :=  range  section . Keys ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 02:02:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											keyString  :=  sectionName  +  key . Name ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											value ,  exists  :=  props [ keyString ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  exists  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												appliedCommandLineProperties  =  append ( appliedCommandLineProperties ,  fmt . Sprintf ( "%s=%s" ,  keyString ,  value ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 02:02:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												key . SetValue ( value ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-02-16 05:57:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  getCommandLineProperties ( args  [ ] string )  map [ string ] string  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									props  :=  make ( map [ string ] string ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  arg  :=  range  args  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ! strings . HasPrefix ( arg ,  "cfg:" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										trimmed  :=  strings . TrimPrefix ( arg ,  "cfg:" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										parts  :=  strings . Split ( trimmed ,  "=" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( parts )  !=  2  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-08-29 04:26:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											log . Fatal ( 3 ,  "Invalid command line argument. argument: %v" ,  arg ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-05 14:59:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										props [ parts [ 0 ] ]  =  parts [ 1 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  props 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  makeAbsolute ( path  string ,  root  string )  string  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  filepath . IsAbs ( path )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  path 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  filepath . Join ( root ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 04:41:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  EvalEnvVarExpression ( value  string )  string  {  
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									regex  :=  regexp . MustCompile ( ` \$ { (\w+)} ` ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  regex . ReplaceAllStringFunc ( value ,  func ( envVar  string )  string  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										envVar  =  strings . TrimPrefix ( envVar ,  "${" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										envVar  =  strings . TrimSuffix ( envVar ,  "}" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										envValue  :=  os . Getenv ( envVar ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-02 20:32:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-05 20:20:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// if env variable is hostname and it is empty use os.Hostname as default
 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-02 20:32:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  envVar  ==  "HOSTNAME"  &&  envValue  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											envValue ,  _  =  os . Hostname ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  envValue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  evalConfigValues ( file  * ini . File )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  section  :=  range  file . Sections ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  key  :=  range  section . Keys ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 04:41:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											key . SetValue ( EvalEnvVarExpression ( key . Value ( ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-12-02 22:40:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  loadSpecifiedConfigFile ( configFile  string ,  masterFile  * ini . File )  error  {  
						 
					
						
							
								
									
										
										
										
											2015-04-12 15:15:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  configFile  ==  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-08 19:22:30 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										configFile  =  filepath . Join ( HomePath ,  CustomInitPath ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 15:15:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// return without error if custom file does not exist
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ! pathExists ( configFile )  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 07:37:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 15:15:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-10 16:58:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userConfig ,  err  :=  ini . Load ( configFile ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 07:37:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  fmt . Errorf ( "Failed to parse %v, %v" ,  configFile ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-10 16:58:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-11-29 00:55:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									userConfig . BlockMode  =  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-10 16:58:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  section  :=  range  userConfig . Sections ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  _ ,  key  :=  range  section . Keys ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  key . Value ( )  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											defaultSec ,  err  :=  masterFile . GetSection ( section . Name ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-10 16:58:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												defaultSec ,  _  =  masterFile . NewSection ( section . Name ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-10 16:58:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											defaultKey ,  err  :=  defaultSec . GetKey ( key . Name ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-19 23:50:17 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												defaultKey ,  _  =  defaultSec . NewKey ( key . Name ( ) ,  key . Value ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-10 16:58:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											defaultKey . SetValue ( key . Value ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									configFiles  =  append ( configFiles ,  configFile ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 07:37:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-10 16:58:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( cfg  * Cfg )  loadConfiguration ( args  * CommandLineArgs )  ( * ini . File ,  error )  {  
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  err  error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// load config defaults
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									defaultConfigFile  :=  path . Join ( HomePath ,  "conf/defaults.ini" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									configFiles  =  append ( configFiles ,  defaultConfigFile ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-12-06 14:36:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// check if config file exists
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  _ ,  err  :=  os . Stat ( defaultConfigFile ) ;  os . IsNotExist ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fmt . Println ( "Grafana-server Init Failed: Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										os . Exit ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// load defaults
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									parsedFile ,  err  :=  ini . Load ( defaultConfigFile ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-23 20:37:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										fmt . Printf ( "Failed to parse defaults.ini, %v\n" ,  err ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-06 14:36:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										os . Exit ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  nil ,  err 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									parsedFile . BlockMode  =  false 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-18 23:43:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// command line props
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									commandLineProps  :=  getCommandLineProperties ( args . Args ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// load default overrides
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									applyCommandLineDefaultProperties ( commandLineProps ,  parsedFile ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// load specified config file
 
							 
						 
					
						
							
								
									
										
										
										
											2019-12-02 22:40:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  =  loadSpecifiedConfigFile ( args . Config ,  parsedFile ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 07:37:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-05 04:00:05 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										err2  :=  cfg . initLogging ( parsedFile ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err2  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  nil ,  err2 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 07:37:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										log . Fatal ( 3 ,  err . Error ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// apply environment overrides
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									err  =  applyEnvVariableOverrides ( parsedFile ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-29 00:03:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  nil ,  err 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-29 00:03:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// apply command line overrides
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									applyCommandLineProperties ( commandLineProps ,  parsedFile ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-08 20:10:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// evaluate config values containing environment variables
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									evalConfigValues ( parsedFile ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-14 16:15:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// update data path and logging config
 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dataPath ,  err  :=  valueAsString ( parsedFile . Section ( "paths" ) ,  "data" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . DataPath  =  makeAbsolute ( dataPath ,  HomePath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									err  =  cfg . initLogging ( parsedFile ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil ,  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-29 00:03:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  parsedFile ,  err 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-12 15:15:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  pathExists ( path  string )  bool  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									_ ,  err  :=  os . Stat ( path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  ==  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  os . IsNotExist ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  setHomePath ( args  * CommandLineArgs )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  args . HomePath  !=  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										HomePath  =  args . HomePath 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									HomePath ,  _  =  filepath . Abs ( "." ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// check if homepath is correct
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  pathExists ( filepath . Join ( HomePath ,  "conf/defaults.ini" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// try down one path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  pathExists ( filepath . Join ( HomePath ,  "../conf/defaults.ini" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										HomePath  =  filepath . Join ( HomePath ,  "../" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-28 04:14:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  skipStaticRootValidation  =  false  
						 
					
						
							
								
									
										
										
										
											2015-09-11 14:58:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  NewCfg ( )  * Cfg  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  & Cfg { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Logger :  log . New ( "settings" ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Raw :     ini . Empty ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( cfg  * Cfg )  validateStaticRootPath ( )  error  {  
						 
					
						
							
								
									
										
										
										
											2015-09-11 14:58:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  skipStaticRootValidation  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-10 19:34:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 02:02:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  _ ,  err  :=  os . Stat ( path . Join ( StaticRootPath ,  "build" ) ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										cfg . Logger . Error ( "Failed to detect generated javascript files in public/build" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-10 19:34:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 02:02:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-10 19:34:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( cfg  * Cfg )  Load ( args  * CommandLineArgs )  error  {  
						 
					
						
							
								
									
										
										
										
											2015-04-12 15:15:49 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									setHomePath ( args ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									iniFile ,  err  :=  cfg . loadConfiguration ( args ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-29 00:03:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . Raw  =  iniFile 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// Temporary keep global, to make refactor in steps
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Raw  =  cfg . Raw 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-01 04:40:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ApplicationName  =  APP_NAME 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-27 19:41:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Env ,  err  =  valueAsString ( iniFile . Section ( "" ) ,  "app_mode" ,  "development" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									InstanceName ,  err  =  valueAsString ( iniFile . Section ( "" ) ,  "instance_name" ,  "unknown_instance_name" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									plugins ,  err  :=  valueAsString ( iniFile . Section ( "paths" ) ,  "plugins" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PluginsPath  =  makeAbsolute ( plugins ,  HomePath ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-20 16:40:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									provisioning ,  err  :=  valueAsString ( iniFile . Section ( "paths" ) ,  "provisioning" ,  "" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-20 16:40:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . ProvisioningPath  =  makeAbsolute ( provisioning ,  HomePath ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									server  :=  iniFile . Section ( "server" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AppUrl ,  AppSubUrl ,  err  =  parseAppUrlAndSubUrl ( server ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-27 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ServeFromSubPath  =  server . Key ( "serve_from_sub_path" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . AppUrl  =  AppUrl 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . AppSubUrl  =  AppSubUrl 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-27 23:47:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . ServeFromSubPath  =  ServeFromSubPath 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Protocol  =  HTTP 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									protocolStr ,  err  :=  valueAsString ( server ,  "protocol" ,  "http" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  protocolStr  ==  "https"  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										Protocol  =  HTTPS 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										CertFile  =  server . Key ( "cert_file" ) . String ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-12 02:44:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										KeyFile  =  server . Key ( "cert_key" ) . String ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-04 19:33:20 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-16 23:06:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  protocolStr  ==  "h2"  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Protocol  =  HTTP2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										CertFile  =  server . Key ( "cert_file" ) . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										KeyFile  =  server . Key ( "cert_key" ) . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  protocolStr  ==  "socket"  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-27 14:54:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Protocol  =  SOCKET 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										SocketPath  =  server . Key ( "socket" ) . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Domain ,  err  =  valueAsString ( server ,  "domain" ,  "localhost" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									HttpAddr ,  err  =  valueAsString ( server ,  "http_addr" ,  DEFAULT_HTTP_ADDR ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									HttpPort ,  err  =  valueAsString ( server ,  "http_port" ,  "3000" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									RouterLogging  =  server . Key ( "router_logging" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-16 19:43:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									EnableGzip  =  server . Key ( "enable_gzip" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-05 17:21:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									EnforceDomain  =  server . Key ( "enforce_domain" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									staticRoot ,  err  :=  valueAsString ( server ,  "static_root_path" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StaticRootPath  =  makeAbsolute ( staticRoot ,  HomePath ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-11 14:58:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  :=  cfg . validateStaticRootPath ( ) ;  err  !=  nil  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-11 14:58:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 17:09:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-16 19:43:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// read data proxy settings
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dataproxy  :=  iniFile . Section ( "dataproxy" ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-16 19:43:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DataProxyLogging  =  dataproxy . Key ( "logging" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-25 03:04:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DataProxyTimeout  =  dataproxy . Key ( "timeout" ) . MustInt ( 30 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-14 20:04:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . SendUserHeader  =  dataproxy . Key ( "send_user_header" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-16 19:43:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-09 23:21:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// read security settings
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									security  :=  iniFile . Section ( "security" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SecretKey ,  err  =  valueAsString ( security ,  "secret_key" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-01 14:40:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DisableGravatar  =  security . Key ( "disable_gravatar" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . DisableBruteForceLoginProtection  =  security . Key ( "disable_brute_force_login_protection" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DisableBruteForceLoginProtection  =  cfg . DisableBruteForceLoginProtection 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-01 14:40:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CookieSecure  =  security . Key ( "cookie_secure" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . CookieSecure  =  CookieSecure 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									samesiteString ,  err  :=  valueAsString ( security ,  "cookie_samesite" ,  "lax" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-15 00:41:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  samesiteString  ==  "disabled"  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										CookieSameSiteDisabled  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cfg . CookieSameSiteDisabled  =  CookieSameSiteDisabled 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-15 00:41:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										validSameSiteValues  :=  map [ string ] http . SameSite { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"lax" :     http . SameSiteLaxMode , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"strict" :  http . SameSiteStrictMode , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"none" :    http . SameSiteNoneMode , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  samesite ,  ok  :=  validSameSiteValues [ samesiteString ] ;  ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											CookieSameSiteMode  =  samesite 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											cfg . CookieSameSiteMode  =  CookieSameSiteMode 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											CookieSameSiteMode  =  http . SameSiteLaxMode 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											cfg . CookieSameSiteMode  =  CookieSameSiteMode 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-05-06 15:56:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AllowEmbedding  =  security . Key ( "allow_embedding" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-12 19:15:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ContentTypeProtectionHeader  =  security . Key ( "x_content_type_options" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									XSSProtectionHeader  =  security . Key ( "x_xss_protection" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StrictTransportSecurity  =  security . Key ( "strict_transport_security" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StrictTransportSecurityMaxAge  =  security . Key ( "strict_transport_security_max_age_seconds" ) . MustInt ( 86400 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StrictTransportSecurityPreload  =  security . Key ( "strict_transport_security_preload" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									StrictTransportSecuritySubDomains  =  security . Key ( "strict_transport_security_subdomains" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 22:39:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// read snapshots settings
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									snapshots  :=  iniFile . Section ( "snapshots" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExternalSnapshotUrl ,  err  =  valueAsString ( snapshots ,  "external_snapshot_url" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExternalSnapshotName ,  err  =  valueAsString ( snapshots ,  "external_snapshot_name" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 22:39:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExternalEnabled  =  snapshots . Key ( "external_enabled" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 22:56:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SnapShotRemoveExpired  =  snapshots . Key ( "snapshot_remove_expired" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-02 21:15:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SnapshotPublicMode  =  snapshots . Key ( "public_mode" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-14 22:39:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-14 18:34:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// read dashboard settings
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dashboards  :=  iniFile . Section ( "dashboards" ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-15 18:36:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DashboardVersionsToKeep  =  dashboards . Key ( "versions_to_keep" ) . MustInt ( 20 ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-28 21:32:01 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									MinRefreshInterval ,  err  =  valueAsString ( dashboards ,  "min_refresh_interval" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-14 18:34:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-09 23:21:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									//  read data source proxy white list
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DataProxyWhiteList  =  make ( map [ string ] bool ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									securityStr ,  err  :=  valueAsString ( security ,  "data_source_proxy_whitelist" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  hostAndIp  :=  range  util . SplitString ( securityStr )  { 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-09 23:21:25 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										DataProxyWhiteList [ hostAndIp ]  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 22:45:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// admin
 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 18:11:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . DisableInitAdminCreation  =  security . Key ( "disable_initial_admin_creation" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AdminUser ,  err  =  valueAsString ( security ,  "admin_user" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AdminPassword ,  err  =  valueAsString ( security ,  "admin_password" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 22:45:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-02-22 19:11:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// users
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									users  :=  iniFile . Section ( "users" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-11 23:19:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AllowUserSignUp  =  users . Key ( "allow_sign_up" ) . MustBool ( true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AllowUserOrgCreate  =  users . Key ( "allow_org_create" ) . MustBool ( true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AutoAssignOrg  =  users . Key ( "auto_assign_org" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-07-14 03:14:40 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AutoAssignOrgId  =  users . Key ( "auto_assign_org_id" ) . MustInt ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-14 01:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AutoAssignOrgRole  =  users . Key ( "auto_assign_org_role" ) . In ( "Editor" ,  [ ] string { "Editor" ,  "Admin" ,  "Viewer" } ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-31 17:35:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									VerifyEmailEnabled  =  users . Key ( "verify_email_enabled" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									LoginHint ,  err  =  valueAsString ( users ,  "login_hint" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									PasswordHint ,  err  =  valueAsString ( users ,  "password_hint" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									DefaultTheme ,  err  =  valueAsString ( users ,  "default_theme" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExternalUserMngLinkUrl ,  err  =  valueAsString ( users ,  "external_manage_link_url" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExternalUserMngLinkName ,  err  =  valueAsString ( users ,  "external_manage_link_name" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ExternalUserMngInfo ,  err  =  valueAsString ( users ,  "external_manage_info" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-14 01:53:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ViewersCanEdit  =  users . Key ( "viewers_can_edit" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-12 14:32:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . EditorsCanAdmin  =  users . Key ( "editors_can_admin" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-28 21:27:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// auth
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									auth  :=  iniFile . Section ( "auth" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									LoginCookieName ,  err  =  valueAsString ( auth ,  "login_cookie_name" ,  "grafana_session" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . LoginCookieName  =  LoginCookieName 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . LoginMaxInactiveLifetimeDays  =  auth . Key ( "login_maximum_inactive_lifetime_days" ) . MustInt ( 7 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LoginMaxLifetimeDays  =  auth . Key ( "login_maximum_lifetime_days" ) . MustInt ( 30 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . LoginMaxLifetimeDays  =  LoginMaxLifetimeDays 
							 
						 
					
						
							
								
									
										
										
										
											2019-06-26 14:47:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . ApiKeyMaxSecondsToLive  =  auth . Key ( "api_key_max_seconds_to_live" ) . MustInt64 ( - 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-06 04:09:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . TokenRotationIntervalMinutes  =  auth . Key ( "token_rotation_interval_minutes" ) . MustInt ( 10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  cfg . TokenRotationIntervalMinutes  <  2  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cfg . TokenRotationIntervalMinutes  =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-28 21:27:08 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DisableLoginForm  =  auth . Key ( "disable_login_form" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-29 17:33:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									DisableSignoutMenu  =  auth . Key ( "disable_signout_menu" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-28 22:16:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									OAuthAutoLogin  =  auth . Key ( "oauth_auto_login" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-30 22:44:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . OAuthCookieMaxAge  =  auth . Key ( "oauth_state_cookie_max_age" ) . MustInt ( 60 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									SignoutRedirectUrl ,  err  =  valueAsString ( auth ,  "signout_redirect_url" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 22:14:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-05 22:39:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// SAML auth
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . SAMLEnabled  =  iniFile . Section ( "auth.saml" ) . Key ( "enabled" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-01-27 22:45:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// anonymous access
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AnonymousEnabled  =  iniFile . Section ( "auth.anonymous" ) . Key ( "enabled" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AnonymousOrgName ,  err  =  valueAsString ( iniFile . Section ( "auth.anonymous" ) ,  "org_name" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AnonymousOrgRole ,  err  =  valueAsString ( iniFile . Section ( "auth.anonymous" ) ,  "org_role" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-07 23:37:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-05-01 17:55:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// auth proxy
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									authProxy  :=  iniFile . Section ( "auth.proxy" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-01 17:55:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AuthProxyEnabled  =  authProxy . Key ( "enabled" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-17 19:57:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AuthProxyHeaderName ,  err  =  valueAsString ( authProxy ,  "header_name" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AuthProxyHeaderProperty ,  err  =  valueAsString ( authProxy ,  "header_property" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-01 17:55:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AuthProxyAutoSignUp  =  authProxy . Key ( "auto_sign_up" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 00:48:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AuthProxyEnableLoginToken  =  authProxy . Key ( "enable_login_token" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 18:24:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ldapSyncVal  :=  authProxy . Key ( "ldap_sync_ttl" ) . MustInt ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									syncVal  :=  authProxy . Key ( "sync_ttl" ) . MustInt ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-08 17:51:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ldapSyncVal  !=  AUTH_PROXY_SYNC_TTL  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-11-07 18:24:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AuthProxySyncTtl  =  ldapSyncVal 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cfg . Logger . Warn ( "[Deprecated] the configuration setting 'ldap_sync_ttl' is deprecated, please use 'sync_ttl' instead" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										AuthProxySyncTtl  =  syncVal 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AuthProxyWhitelist ,  err  =  valueAsString ( authProxy ,  "whitelist" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-05-01 17:55:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-05-07 16:39:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AuthProxyHeaders  =  make ( map [ string ] string ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									headers ,  err  :=  valueAsString ( authProxy ,  "headers" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  propertyAndHeader  :=  range  util . SplitString ( headers )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-07 16:39:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										split  :=  strings . SplitN ( propertyAndHeader ,  ":" ,  2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  len ( split )  ==  2  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											AuthProxyHeaders [ split [ 0 ] ]  =  split [ 1 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-23 21:22:28 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// basic auth
 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									authBasic  :=  iniFile . Section ( "auth.basic" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-30 18:14:13 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									BasicAuthEnabled  =  authBasic . Key ( "enabled" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-06-30 15:37:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-05-24 21:26:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Rendering
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									renderSec  :=  iniFile . Section ( "rendering" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . RendererUrl ,  err  =  valueAsString ( renderSec ,  "server_url" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . RendererCallbackUrl ,  err  =  valueAsString ( renderSec ,  "callback_url" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-04 19:42:55 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  cfg . RendererCallbackUrl  ==  ""  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cfg . RendererCallbackUrl  =  AppUrl 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  cfg . RendererCallbackUrl [ len ( cfg . RendererCallbackUrl ) - 1 ]  !=  '/'  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											cfg . RendererCallbackUrl  +=  "/" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										_ ,  err  :=  url . Parse ( cfg . RendererCallbackUrl ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											log . Fatal ( 4 ,  "Invalid callback_url(%s): %s" ,  cfg . RendererCallbackUrl ,  err ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . ImagesDir  =  filepath . Join ( cfg . DataPath ,  "png" ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-24 21:26:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . PhantomDir  =  filepath . Join ( HomePath ,  "tools/phantomjs" ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-06-14 15:50:18 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . TempDataLifetime  =  iniFile . Section ( "paths" ) . Key ( "temp_data_lifetime" ) . MustDuration ( time . Second  *  3600  *  24 ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-13 20:36:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . MetricsEndpointEnabled  =  iniFile . Section ( "metrics" ) . Key ( "enabled" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . MetricsEndpointBasicAuthUsername ,  err  =  valueAsString ( iniFile . Section ( "metrics" ) ,  "basic_auth_username" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . MetricsEndpointBasicAuthPassword ,  err  =  valueAsString ( iniFile . Section ( "metrics" ) ,  "basic_auth_password" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-17 15:32:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . MetricsEndpointDisableTotalStats  =  iniFile . Section ( "metrics" ) . Key ( "disable_total_stats" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-11-15 00:13:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									analytics  :=  iniFile . Section ( "analytics" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-28 00:13:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ReportingEnabled  =  analytics . Key ( "reporting_enabled" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-12 00:21:48 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									CheckForUpdates  =  analytics . Key ( "check_for_updates" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-26 20:47:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GoogleAnalyticsId  =  analytics . Key ( "google_analytics_ua_id" ) . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									GoogleTagManagerId  =  analytics . Key ( "google_tag_manager_id" ) . String ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-23 03:14:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									alerting  :=  iniFile . Section ( "alerting" ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-25 20:32:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingEnabled  =  alerting . Key ( "enabled" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-10 19:09:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExecuteAlerts  =  alerting . Key ( "execute_alerts" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-25 18:17:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingRenderLimit  =  alerting . Key ( "concurrent_render_limit" ) . MustInt ( 5 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingErrorOrTimeout ,  err  =  valueAsString ( alerting ,  "error_or_timeout" ,  "alerting" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AlertingNoDataOrNullValues ,  err  =  valueAsString ( alerting ,  "nodata_or_nullvalues" ,  "no_data" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-29 20:35:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-30 18:05:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									evaluationTimeoutSeconds  :=  alerting . Key ( "evaluation_timeout_seconds" ) . MustInt64 ( 30 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AlertingEvaluationTimeout  =  time . Second  *  time . Duration ( evaluationTimeoutSeconds ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									notificationTimeoutSeconds  :=  alerting . Key ( "notification_timeout_seconds" ) . MustInt64 ( 30 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AlertingNotificationTimeout  =  time . Second  *  time . Duration ( notificationTimeoutSeconds ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-29 13:58:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingMaxAttempts  =  alerting . Key ( "max_attempts" ) . MustInt ( 3 ) 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-14 17:13:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AlertingMinInterval  =  alerting . Key ( "min_interval_seconds" ) . MustInt64 ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-29 13:58:37 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									explore  :=  iniFile . Section ( "explore" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-01-28 20:02:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ExploreEnabled  =  explore . Key ( "enabled" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-27 17:39:14 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-12 19:46:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									panelsSection  :=  iniFile . Section ( "panels" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . DisableSanitizeHtml  =  panelsSection . Key ( "disable_sanitize_html" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pluginsSection  :=  iniFile . Section ( "plugins" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . PluginsEnableAlpha  =  pluginsSection . Key ( "enable_alpha" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-23 18:34:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . PluginsAppsSkipVerifyTLS  =  pluginsSection . Key ( "app_tls_skip_verify_insecure" ) . MustBool ( false ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-12 19:46:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-09-09 14:58:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Read and populate feature toggles list
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									featureTogglesSection  :=  iniFile . Section ( "feature_toggles" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . FeatureToggles  =  make ( map [ string ] bool ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									featuresTogglesStr ,  err  :=  valueAsString ( featureTogglesSection ,  "enable" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  _ ,  feature  :=  range  util . SplitString ( featuresTogglesStr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cfg . FeatureToggles [ feature ]  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-24 23:15:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									FeatureToggles  =  cfg . FeatureToggles 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-09 14:58:57 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-12 19:46:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// check old location for this option
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  panelsSection . Key ( "enable_alpha" ) . MustBool ( false )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cfg . PluginsEnableAlpha  =  true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-09 23:47:43 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 22:12:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . readLDAPConfig ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . readSessionConfig ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . readSmtpSettings ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . readQuotaSettings ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-31 17:35:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  VerifyEmailEnabled  &&  ! cfg . Smtp . Enabled  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-12-28 22:51:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										log . Warn ( "require_email_validation is enabled but smtp is disabled" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-31 17:35:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-11 14:58:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-05-22 20:56:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// check old key  name
 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									GrafanaComUrl ,  err  =  valueAsString ( iniFile . Section ( "grafana_net" ) ,  "url" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-22 20:56:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  GrafanaComUrl  ==  ""  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										GrafanaComUrl ,  err  =  valueAsString ( iniFile . Section ( "grafana_com" ) ,  "url" ,  "https://grafana.com" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-22 20:56:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-05-27 19:52:19 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									imageUploadingSection  :=  iniFile . Section ( "external_image_storage" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ImageUploadProvider ,  err  =  valueAsString ( imageUploadingSection ,  "provider" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-01 19:07:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									enterprise  :=  iniFile . Section ( "enterprise" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . EnterpriseLicensePath ,  err  =  valueAsString ( enterprise ,  "license_path" ,  filepath . Join ( cfg . DataPath ,  "license.jwt" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-01 19:07:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-09 03:49:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cacheServer  :=  iniFile . Section ( "remote_cache" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									dbName ,  err  :=  valueAsString ( cacheServer ,  "type" ,  "database" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									connStr ,  err  :=  valueAsString ( cacheServer ,  "connstr" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-09 03:49:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . RemoteCacheOptions  =  & RemoteCacheOptions { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Name :     dbName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ConnStr :  connStr , 
							 
						 
					
						
							
								
									
										
										
										
											2019-03-04 04:48:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-09-11 14:58:45 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  nil 
							 
						 
					
						
							
								
									
										
										
										
											2015-01-15 21:44:15 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2014-12-30 17:28:27 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  valueAsString ( section  * ini . Section ,  keyName  string ,  defaultValue  string )  ( value  string ,  err  error )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									defer  func ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  err_  :=  recover ( ) ;  err_  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											err  =  errors . New ( "Invalid value for key '"  +  keyName  +  "' in configuration file" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  section . Key ( keyName ) . MustString ( defaultValue ) ,  nil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-03-09 03:49:16 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  RemoteCacheOptions  struct  {  
						 
					
						
							
								
									
										
										
										
											2019-03-04 04:48:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Name     string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ConnStr  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 22:12:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( cfg  * Cfg )  readLDAPConfig ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ldapSec  :=  cfg . Raw . Section ( "auth.ldap" ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-22 20:30:03 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									LDAPConfigFile  =  ldapSec . Key ( "config_file" ) . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LDAPSyncCron  =  ldapSec . Key ( "sync_cron" ) . String ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LDAPEnabled  =  ldapSec . Key ( "enabled" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LDAPActiveSyncEnabled  =  ldapSec . Key ( "active_sync_enabled" ) . MustBool ( false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									LDAPAllowSignup  =  ldapSec . Key ( "allow_sign_up" ) . MustBool ( true ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 22:12:56 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( cfg  * Cfg )  readSessionConfig ( )  {  
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									sec ,  _  :=  cfg . Raw . GetSection ( "session" ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-08 14:59:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  sec  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cfg . Logger . Warn ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"[Removed] Session setting was removed in v6.2, use remote_cache option instead" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-08 14:59:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2014-10-05 22:50:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-03-03 17:18:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( cfg  * Cfg )  initLogging ( file  * ini . File )  error  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									logModeStr ,  err  :=  valueAsString ( file . Section ( "log" ) ,  "mode" ,  "console" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-07 18:11:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// split on comma
 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									logModes  :=  strings . Split ( logModeStr ,  "," ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-07 18:11:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// also try space
 
							 
						 
					
						
							
								
									
										
										
										
											2018-10-12 13:55:36 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  len ( logModes )  ==  1  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										logModes  =  strings . Split ( logModeStr ,  " " ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-03 17:18:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-25 14:29:07 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									logsPath ,  err  :=  valueAsString ( file . Section ( "paths" ) ,  "logs" ,  "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  err  !=  nil  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  err 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . LogsPath  =  makeAbsolute ( logsPath ,  HomePath ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-12-02 22:40:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  log . ReadLoggingConfig ( logModes ,  cfg . LogsPath ,  file ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-03 17:18:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-30 22:21:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  ( cfg  * Cfg )  LogConfigSources ( )  {  
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									var  text  bytes . Buffer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-06-07 15:29:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  _ ,  file  :=  range  configFiles  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										cfg . Logger . Info ( "Config loaded from" ,  "file" ,  file ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-03 17:18:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( appliedCommandLineProperties )  >  0  { 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-07 15:29:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  prop  :=  range  appliedCommandLineProperties  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											cfg . Logger . Info ( "Config overridden from command line" ,  "arg" ,  prop ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( appliedEnvOverrides )  >  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										text . WriteString ( "\tEnvironment variables used:\n" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-06-07 15:29:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  _ ,  prop  :=  range  appliedEnvOverrides  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											cfg . Logger . Info ( "Config overridden from Environment variable" ,  "var" ,  prop ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-04-09 18:16:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-22 23:58:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									cfg . Logger . Info ( "Path Home" ,  "path" ,  HomePath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . Logger . Info ( "Path Data" ,  "path" ,  cfg . DataPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . Logger . Info ( "Path Logs" ,  "path" ,  cfg . LogsPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . Logger . Info ( "Path Plugins" ,  "path" ,  PluginsPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . Logger . Info ( "Path Provisioning" ,  "path" ,  cfg . ProvisioningPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cfg . Logger . Info ( "App mode "  +  Env ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-03-03 17:18:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2019-10-25 21:28:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-10 22:33:54 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								type  DynamicSection  struct  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									section  * ini . Section 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Logger   log . Logger 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Key dynamically overrides keys with environment variables.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// As a side effect, the value of the setting key will be updated if an environment variable is present.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( s  * DynamicSection )  Key ( k  string )  * ini . Key  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									envKey  :=  envKey ( s . section . Name ( ) ,  k ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									envValue  :=  os . Getenv ( envKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									key  :=  s . section . Key ( k ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  len ( envValue )  ==  0  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  key 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									key . SetValue ( envValue ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  shouldRedactKey ( envKey )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										envValue  =  REDACTED_PASSWORD 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									s . Logger . Info ( "Config overridden from Environment variable" ,  "var" ,  fmt . Sprintf ( "%s=%s" ,  envKey ,  envValue ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  key 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// SectionWithEnvOverrides dynamically overrides keys with environment variables.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// As a side effect, the value of the setting key will be updated if an environment variable is present.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								func  ( cfg  * Cfg )  SectionWithEnvOverrides ( s  string )  * DynamicSection  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  & DynamicSection { cfg . Raw . Section ( s ) ,  cfg . Logger } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-25 21:28:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								func  IsExpressionsEnabled ( )  bool  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									v ,  ok  :=  FeatureToggles [ "expressions" ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ! ok  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  v 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}