Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
95305e7e
Commit
95305e7e
authored
Jan 27, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed from goconfig to its new counter part go-ini
parent
951ce0a1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
64 deletions
+98
-64
conf/grafana.ini
+10
-7
pkg/api/api.go
+1
-1
pkg/api/login.go
+9
-0
pkg/services/sqlstore/sqlstore.go
+9
-7
pkg/setting/setting.go
+62
-43
pkg/social/social.go
+7
-6
No files found.
conf/grafana.ini
View file @
95305e7e
app_name
=
Grafana
app_mode
=
development
app_mode
=
production
[server]
protocol
=
http
...
...
@@ -35,19 +35,22 @@ session_id_hashfunc = sha1
; Session hash key, default is use random string
session_id_hashkey
=
[
admin
]
[
security
]
; default admin user, created on startup
user
=
admin
admin_
user
=
admin
; default admin password, can be changed before first start of grafana, or in profile settings
password
=
admin
admin_password
=
admin
; used for sig
secret_key
=
!#@FDEWREWR&*(
; Auto-login remember days
login_remember_days
=
7
cookie_username
=
grafana_user
cookie_remember_name
=
grafana_remember
[auth]
anonymous
=
false
anonymous_account_id
=
[auth.grafana]
enabled
=
true
[auth.github]
enabled
=
false
client_id
=
some_id
...
...
pkg/api/api.go
View file @
95305e7e
...
...
@@ -22,7 +22,7 @@ func Register(r *macaron.Macaron) {
r
.
Post
(
"/logout"
,
LogoutPost
)
r
.
Post
(
"/login"
,
bind
(
dtos
.
LoginCommand
{}),
LoginPost
)
r
.
Get
(
"/login/:name"
,
OAuthLogin
)
r
.
Get
(
"/login"
,
Index
)
r
.
Get
(
"/login"
,
LoginView
)
// authed views
r
.
Get
(
"/profile/"
,
reqSignedIn
,
Index
)
...
...
pkg/api/login.go
View file @
95305e7e
...
...
@@ -9,6 +9,15 @@ import (
"github.com/torkelo/grafana-pro/pkg/util"
)
func
LoginView
(
c
*
middleware
.
Context
)
{
if
err
:=
setIndexViewData
(
c
);
err
!=
nil
{
c
.
Handle
(
500
,
"Failed to get settings"
,
err
)
return
}
c
.
HTML
(
200
,
"index"
)
}
func
LoginPost
(
c
*
middleware
.
Context
,
cmd
dtos
.
LoginCommand
)
{
userQuery
:=
m
.
GetUserByLoginQuery
{
LoginOrEmail
:
cmd
.
User
}
...
...
pkg/services/sqlstore/sqlstore.go
View file @
95305e7e
...
...
@@ -136,18 +136,20 @@ func getEngine() (*xorm.Engine, error) {
}
func
LoadConfig
()
{
DbCfg
.
Type
=
setting
.
Cfg
.
MustValue
(
"database"
,
"type"
)
sec
:=
setting
.
Cfg
.
Section
(
"database"
)
DbCfg
.
Type
=
sec
.
Key
(
"type"
)
.
String
()
if
DbCfg
.
Type
==
"sqlite3"
{
UseSQLite3
=
true
}
DbCfg
.
Host
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"host"
)
DbCfg
.
Name
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"name"
)
DbCfg
.
User
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"user"
)
DbCfg
.
Host
=
se
c
.
Key
(
"host"
)
.
String
(
)
DbCfg
.
Name
=
se
c
.
Key
(
"name"
)
.
String
(
)
DbCfg
.
User
=
se
c
.
Key
(
"user"
)
.
String
(
)
if
len
(
DbCfg
.
Pwd
)
==
0
{
DbCfg
.
Pwd
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"password"
)
DbCfg
.
Pwd
=
se
c
.
Key
(
"password"
)
.
String
(
)
}
DbCfg
.
SslMode
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"ssl_mode"
)
DbCfg
.
Path
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"path"
,
"data/grafana.db"
)
DbCfg
.
SslMode
=
se
c
.
Key
(
"ssl_mode"
)
.
String
(
)
DbCfg
.
Path
=
se
c
.
Key
(
"path"
)
.
MustString
(
"data/grafana.db"
)
}
type
dbTransactionFunc
func
(
sess
*
xorm
.
Session
)
error
...
...
pkg/setting/setting.go
View file @
95305e7e
...
...
@@ -12,8 +12,8 @@ import (
"strings"
"github.com/Unknwon/com"
"github.com/Unknwon/goconfig"
"github.com/macaron-contrib/session"
"gopkg.in/ini.v1"
"github.com/torkelo/grafana-pro/pkg/log"
)
...
...
@@ -58,6 +58,12 @@ var (
StaticRootPath
string
EnableGzip
bool
// Security settings.
SecretKey
string
LogInRememberDays
int
CookieUserName
string
CookieRememberName
string
// Http auth
AdminUser
string
AdminPassword
string
...
...
@@ -69,7 +75,7 @@ var (
// Global setting objects.
WorkDir
string
Cfg
*
goconfig
.
Config
File
Cfg
*
ini
.
File
ConfRootPath
string
CustomPath
string
// Custom directory path.
ProdMode
bool
...
...
@@ -118,85 +124,98 @@ func findConfigFiles() []string {
return
filenames
}
func
parseAppUrlAndSubUrl
(
section
*
ini
.
Section
)
(
string
,
string
)
{
appUrl
:=
section
.
Key
(
"root_url"
)
.
MustString
(
"http://localhost:3000/"
)
if
appUrl
[
len
(
appUrl
)
-
1
]
!=
'/'
{
appUrl
+=
"/"
}
// Check if has app suburl.
url
,
err
:=
url
.
Parse
(
AppUrl
)
if
err
!=
nil
{
log
.
Fatal
(
4
,
"Invalid root_url(%s): %s"
,
appUrl
,
err
)
}
appSubUrl
:=
strings
.
TrimSuffix
(
url
.
Path
,
"/"
)
return
appUrl
,
appSubUrl
}
func
NewConfigContext
()
{
configFiles
:=
findConfigFiles
()
//log.Info("Loading config files: %v", configFiles)
var
err
error
Cfg
,
err
=
goconfig
.
LoadConfigFile
(
configFiles
[
0
])
if
err
!=
nil
{
log
.
Fatal
(
4
,
"Fail to parse config file, error: %v"
,
err
)
for
i
,
file
:=
range
configFiles
{
if
i
==
0
{
Cfg
,
err
=
ini
.
Load
(
configFiles
[
i
])
}
else
{
err
=
Cfg
.
Append
(
configFiles
[
i
])
}
if
len
(
configFiles
)
>
1
{
err
=
Cfg
.
AppendFiles
(
configFiles
[
1
:
]
...
)
if
err
!=
nil
{
log
.
Fatal
(
4
,
"Fail to parse config file, error: %v"
,
err
)
}
log
.
Fatal
(
4
,
"Fail to parse config file: %v, error: %v"
,
file
,
err
)
}
AppName
=
Cfg
.
MustValue
(
""
,
"app_name"
,
"Grafana"
)
AppUrl
=
Cfg
.
MustValue
(
"server"
,
"root_url"
,
"http://localhost:3000/"
)
if
AppUrl
[
len
(
AppUrl
)
-
1
]
!=
'/'
{
AppUrl
+=
"/"
}
// Check if has app suburl.
url
,
err
:=
url
.
Parse
(
AppUrl
)
if
err
!=
nil
{
log
.
Fatal
(
4
,
"Invalid root_url(%s): %s"
,
AppUrl
,
err
)
}
AppName
=
Cfg
.
Section
(
""
)
.
Key
(
"app_name"
)
.
MustString
(
"Grafana"
)
Env
=
Cfg
.
Section
(
""
)
.
Key
(
"app_mode"
)
.
MustString
(
"development"
)
AppSubUrl
=
strings
.
TrimSuffix
(
url
.
Path
,
"/"
)
server
:=
Cfg
.
Section
(
"server"
)
AppUrl
,
AppSubUrl
=
parseAppUrlAndSubUrl
(
server
)
Protocol
=
HTTP
if
Cfg
.
MustValue
(
"server"
,
"protocol
"
)
==
"https"
{
if
server
.
Key
(
"protocol"
)
.
MustString
(
"http
"
)
==
"https"
{
Protocol
=
HTTPS
CertFile
=
Cfg
.
MustValue
(
"server"
,
"cert_file"
)
KeyFile
=
Cfg
.
MustValue
(
"server"
,
"key_file"
)
CertFile
=
server
.
Key
(
"cert_file"
)
.
String
(
)
KeyFile
=
server
.
Key
(
"cert_file"
)
.
String
(
)
}
Domain
=
Cfg
.
MustValue
(
"server"
,
"domain"
,
"localhost"
)
HttpAddr
=
Cfg
.
MustValue
(
"server"
,
"http_addr"
,
"0.0.0.0"
)
HttpPort
=
Cfg
.
MustValue
(
"server"
,
"http_port"
,
"3000"
)
Domain
=
server
.
Key
(
"domain"
)
.
MustString
(
"localhost"
)
HttpAddr
=
server
.
Key
(
"http_addr"
)
.
MustString
(
"0.0.0.0"
)
HttpPort
=
server
.
Key
(
"http_port"
)
.
MustString
(
"3000"
)
port
:=
os
.
Getenv
(
"PORT"
)
if
port
!=
""
{
HttpPort
=
port
}
StaticRootPath
=
Cfg
.
MustValue
(
"server"
,
"static_root_path"
,
path
.
Join
(
WorkDir
,
"webapp"
))
RouterLogging
=
Cfg
.
MustBool
(
"server"
,
"router_logging"
,
false
)
EnableGzip
=
Cfg
.
MustBool
(
"server"
,
"enable_gzip"
)
StaticRootPath
=
server
.
Key
(
"static_root_path"
)
.
MustString
(
path
.
Join
(
WorkDir
,
"webapp"
))
RouterLogging
=
server
.
Key
(
"router_logging"
)
.
MustBool
(
false
)
EnableGzip
=
server
.
Key
(
"enable_gzip"
)
.
MustBool
(
false
)
security
:=
Cfg
.
Section
(
"security"
)
SecretKey
=
security
.
Key
(
"secret_key"
)
.
String
()
LogInRememberDays
=
security
.
Key
(
"login_remember_days"
)
.
MustInt
()
CookieUserName
=
security
.
Key
(
"cookie_username"
)
.
String
()
CookieRememberName
=
security
.
Key
(
"cookie_remember_name"
)
.
String
()
// Http auth
AdminUser
=
Cfg
.
MustValue
(
"admin"
,
"user"
,
"admin"
)
AdminPassword
=
Cfg
.
MustValue
(
"admin"
,
"password"
,
"admin"
)
Anonymous
=
Cfg
.
MustBool
(
"auth"
,
"anonymous"
,
false
)
AnonymousAccountId
=
Cfg
.
MustInt64
(
"auth"
,
"anonymous_account_id"
,
0
)
AdminUser
=
security
.
Key
(
"admin_user"
)
.
String
()
AdminPassword
=
security
.
Key
(
"admin_password"
)
.
String
()
if
Anonymous
&&
AnonymousAccountId
==
0
{
log
.
Fatal
(
3
,
"Must specify account id for anonymous access"
)
}
// Anonymous = Cfg.MustBool("auth", "anonymous", false)
// AnonymousAccountId = Cfg.MustInt64("auth", "anonymous_account_id", 0)
// PhantomJS rendering
ImagesDir
=
"data/png"
PhantomDir
=
"vendor/phantomjs"
LogRootPath
=
Cfg
.
MustValue
(
"log"
,
"root_path"
,
path
.
Join
(
WorkDir
,
"/data/log"
))
LogRootPath
=
Cfg
.
Section
(
"log"
)
.
Key
(
"root_path"
)
.
MustString
(
path
.
Join
(
WorkDir
,
"/data/log"
))
readSessionConfig
()
}
func
readSessionConfig
()
{
sec
:=
Cfg
.
Section
(
"session"
)
SessionOptions
=
session
.
Options
{}
SessionOptions
.
Provider
=
Cfg
.
MustValueRange
(
"session"
,
"provider"
,
"memory"
,
[]
string
{
"memory"
,
"file
"
})
SessionOptions
.
ProviderConfig
=
strings
.
Trim
(
Cfg
.
MustValue
(
"session"
,
"provider_config"
),
"
\"
"
)
SessionOptions
.
CookieName
=
Cfg
.
MustValue
(
"session"
,
"cookie_name"
,
"grafana_pro
_sess"
)
SessionOptions
.
Provider
=
sec
.
Key
(
"provider"
)
.
In
(
"memory"
,
[]
string
{
"memory"
,
"file"
,
"redis"
,
"mysql
"
})
SessionOptions
.
ProviderConfig
=
strings
.
Trim
(
sec
.
Key
(
"provider_config"
)
.
String
(
),
"
\"
"
)
SessionOptions
.
CookieName
=
sec
.
Key
(
"cookie_name"
)
.
MustString
(
"grafana
_sess"
)
SessionOptions
.
CookiePath
=
AppSubUrl
SessionOptions
.
Secure
=
Cfg
.
MustBool
(
"session"
,
"cookie_secure"
)
SessionOptions
.
Gclifetime
=
Cfg
.
MustInt64
(
"session"
,
"gc_interval_time"
,
86400
)
SessionOptions
.
Maxlifetime
=
Cfg
.
MustInt64
(
"session"
,
"session_life_time"
,
86400
)
SessionOptions
.
Secure
=
sec
.
Key
(
"cookie_secure"
)
.
MustBool
(
)
SessionOptions
.
Gclifetime
=
Cfg
.
Section
(
"session"
)
.
Key
(
"gc_interval_time"
)
.
MustInt64
(
86400
)
SessionOptions
.
Maxlifetime
=
Cfg
.
Section
(
"session"
)
.
Key
(
"session_life_time"
)
.
MustInt64
(
86400
)
if
SessionOptions
.
Provider
==
"file"
{
os
.
MkdirAll
(
path
.
Dir
(
SessionOptions
.
ProviderConfig
),
os
.
ModePerm
)
...
...
pkg/social/social.go
View file @
95305e7e
...
...
@@ -39,13 +39,14 @@ func NewOAuthService() {
allOauthes
:=
[]
string
{
"github"
,
"google"
}
for
_
,
name
:=
range
allOauthes
{
sec
:=
setting
.
Cfg
.
Section
(
"auth."
+
name
)
info
:=
&
setting
.
OAuthInfo
{
ClientId
:
se
tting
.
Cfg
.
MustValue
(
"auth."
+
name
,
"client_id"
),
ClientSecret
:
se
tting
.
Cfg
.
MustValue
(
"auth."
+
name
,
"client_secret"
),
Scopes
:
se
tting
.
Cfg
.
MustValueArray
(
"auth."
+
name
,
"scopes"
,
" "
),
AuthUrl
:
se
tting
.
Cfg
.
MustValue
(
"auth."
+
name
,
"auth_url"
),
TokenUrl
:
se
tting
.
Cfg
.
MustValue
(
"auth."
+
name
,
"token_url"
),
Enabled
:
se
tting
.
Cfg
.
MustBool
(
"auth."
+
name
,
"enabled"
),
ClientId
:
se
c
.
Key
(
"client_id"
)
.
String
(
),
ClientSecret
:
se
c
.
Key
(
"client_secret"
)
.
String
(
),
Scopes
:
se
c
.
Key
(
"scopes"
)
.
Strings
(
" "
),
AuthUrl
:
se
c
.
Key
(
"auth_url"
)
.
String
(
),
TokenUrl
:
se
c
.
Key
(
"token_url"
)
.
String
(
),
Enabled
:
se
c
.
Key
(
"enabled"
)
.
MustBool
(
),
}
if
!
info
.
Enabled
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment