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
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
65 deletions
+99
-65
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
+63
-44
pkg/social/social.go
+7
-6
No files found.
conf/grafana.ini
View file @
95305e7e
app_name
=
Grafana
app_name
=
Grafana
app_mode
=
development
app_mode
=
production
[server]
[server]
protocol
=
http
protocol
=
http
...
@@ -35,19 +35,22 @@ session_id_hashfunc = sha1
...
@@ -35,19 +35,22 @@ session_id_hashfunc = sha1
; Session hash key, default is use random string
; Session hash key, default is use random string
session_id_hashkey
=
session_id_hashkey
=
[
admin
]
[
security
]
; default admin user, created on startup
; 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
; 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]
[auth]
anonymous
=
false
anonymous
=
false
anonymous_account_id
=
anonymous_account_id
=
[auth.grafana]
enabled
=
true
[auth.github]
[auth.github]
enabled
=
false
enabled
=
false
client_id
=
some_id
client_id
=
some_id
...
...
pkg/api/api.go
View file @
95305e7e
...
@@ -22,7 +22,7 @@ func Register(r *macaron.Macaron) {
...
@@ -22,7 +22,7 @@ func Register(r *macaron.Macaron) {
r
.
Post
(
"/logout"
,
LogoutPost
)
r
.
Post
(
"/logout"
,
LogoutPost
)
r
.
Post
(
"/login"
,
bind
(
dtos
.
LoginCommand
{}),
LoginPost
)
r
.
Post
(
"/login"
,
bind
(
dtos
.
LoginCommand
{}),
LoginPost
)
r
.
Get
(
"/login/:name"
,
OAuthLogin
)
r
.
Get
(
"/login/:name"
,
OAuthLogin
)
r
.
Get
(
"/login"
,
Index
)
r
.
Get
(
"/login"
,
LoginView
)
// authed views
// authed views
r
.
Get
(
"/profile/"
,
reqSignedIn
,
Index
)
r
.
Get
(
"/profile/"
,
reqSignedIn
,
Index
)
...
...
pkg/api/login.go
View file @
95305e7e
...
@@ -9,6 +9,15 @@ import (
...
@@ -9,6 +9,15 @@ import (
"github.com/torkelo/grafana-pro/pkg/util"
"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
)
{
func
LoginPost
(
c
*
middleware
.
Context
,
cmd
dtos
.
LoginCommand
)
{
userQuery
:=
m
.
GetUserByLoginQuery
{
LoginOrEmail
:
cmd
.
User
}
userQuery
:=
m
.
GetUserByLoginQuery
{
LoginOrEmail
:
cmd
.
User
}
...
...
pkg/services/sqlstore/sqlstore.go
View file @
95305e7e
...
@@ -136,18 +136,20 @@ func getEngine() (*xorm.Engine, error) {
...
@@ -136,18 +136,20 @@ func getEngine() (*xorm.Engine, error) {
}
}
func
LoadConfig
()
{
func
LoadConfig
()
{
DbCfg
.
Type
=
setting
.
Cfg
.
MustValue
(
"database"
,
"type"
)
sec
:=
setting
.
Cfg
.
Section
(
"database"
)
DbCfg
.
Type
=
sec
.
Key
(
"type"
)
.
String
()
if
DbCfg
.
Type
==
"sqlite3"
{
if
DbCfg
.
Type
==
"sqlite3"
{
UseSQLite3
=
true
UseSQLite3
=
true
}
}
DbCfg
.
Host
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"host"
)
DbCfg
.
Host
=
se
c
.
Key
(
"host"
)
.
String
(
)
DbCfg
.
Name
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"name"
)
DbCfg
.
Name
=
se
c
.
Key
(
"name"
)
.
String
(
)
DbCfg
.
User
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"user"
)
DbCfg
.
User
=
se
c
.
Key
(
"user"
)
.
String
(
)
if
len
(
DbCfg
.
Pwd
)
==
0
{
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
.
SslMode
=
se
c
.
Key
(
"ssl_mode"
)
.
String
(
)
DbCfg
.
Path
=
se
tting
.
Cfg
.
MustValue
(
"database"
,
"path"
,
"data/grafana.db"
)
DbCfg
.
Path
=
se
c
.
Key
(
"path"
)
.
MustString
(
"data/grafana.db"
)
}
}
type
dbTransactionFunc
func
(
sess
*
xorm
.
Session
)
error
type
dbTransactionFunc
func
(
sess
*
xorm
.
Session
)
error
...
...
pkg/setting/setting.go
View file @
95305e7e
...
@@ -12,8 +12,8 @@ import (
...
@@ -12,8 +12,8 @@ import (
"strings"
"strings"
"github.com/Unknwon/com"
"github.com/Unknwon/com"
"github.com/Unknwon/goconfig"
"github.com/macaron-contrib/session"
"github.com/macaron-contrib/session"
"gopkg.in/ini.v1"
"github.com/torkelo/grafana-pro/pkg/log"
"github.com/torkelo/grafana-pro/pkg/log"
)
)
...
@@ -58,6 +58,12 @@ var (
...
@@ -58,6 +58,12 @@ var (
StaticRootPath
string
StaticRootPath
string
EnableGzip
bool
EnableGzip
bool
// Security settings.
SecretKey
string
LogInRememberDays
int
CookieUserName
string
CookieRememberName
string
// Http auth
// Http auth
AdminUser
string
AdminUser
string
AdminPassword
string
AdminPassword
string
...
@@ -69,7 +75,7 @@ var (
...
@@ -69,7 +75,7 @@ var (
// Global setting objects.
// Global setting objects.
WorkDir
string
WorkDir
string
Cfg
*
goconfig
.
Config
File
Cfg
*
ini
.
File
ConfRootPath
string
ConfRootPath
string
CustomPath
string
// Custom directory path.
CustomPath
string
// Custom directory path.
ProdMode
bool
ProdMode
bool
...
@@ -118,85 +124,98 @@ func findConfigFiles() []string {
...
@@ -118,85 +124,98 @@ func findConfigFiles() []string {
return
filenames
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
()
{
func
NewConfigContext
()
{
configFiles
:=
findConfigFiles
()
configFiles
:=
findConfigFiles
()
//log.Info("Loading config files: %v", configFiles)
//log.Info("Loading config files: %v", configFiles)
var
err
error
var
err
error
Cfg
,
err
=
goconfig
.
LoadConfigFile
(
configFiles
[
0
])
for
i
,
file
:=
range
configFiles
{
if
err
!=
nil
{
if
i
==
0
{
log
.
Fatal
(
4
,
"Fail to parse config file, error: %v"
,
err
)
Cfg
,
err
=
ini
.
Load
(
configFiles
[
i
])
}
}
else
{
err
=
Cfg
.
Append
(
configFiles
[
i
])
}
if
len
(
configFiles
)
>
1
{
err
=
Cfg
.
AppendFiles
(
configFiles
[
1
:
]
...
)
if
err
!=
nil
{
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"
)
AppName
=
Cfg
.
Section
(
""
)
.
Key
(
"app_name"
)
.
MustString
(
"Grafana"
)
AppUrl
=
Cfg
.
MustValue
(
"server"
,
"root_url"
,
"http://localhost:3000/"
)
Env
=
Cfg
.
Section
(
""
)
.
Key
(
"app_mode"
)
.
MustString
(
"development"
)
if
AppUrl
[
len
(
AppUrl
)
-
1
]
!=
'/'
{
AppUrl
+=
"/"
}
// Check if has app suburl.
server
:=
Cfg
.
Section
(
"server"
)
url
,
err
:=
url
.
Parse
(
AppUrl
)
AppUrl
,
AppSubUrl
=
parseAppUrlAndSubUrl
(
server
)
if
err
!=
nil
{
log
.
Fatal
(
4
,
"Invalid root_url(%s): %s"
,
AppUrl
,
err
)
}
AppSubUrl
=
strings
.
TrimSuffix
(
url
.
Path
,
"/"
)
Protocol
=
HTTP
Protocol
=
HTTP
if
Cfg
.
MustValue
(
"server"
,
"protocol
"
)
==
"https"
{
if
server
.
Key
(
"protocol"
)
.
MustString
(
"http
"
)
==
"https"
{
Protocol
=
HTTPS
Protocol
=
HTTPS
CertFile
=
Cfg
.
MustValue
(
"server"
,
"cert_file"
)
CertFile
=
server
.
Key
(
"cert_file"
)
.
String
(
)
KeyFile
=
Cfg
.
MustValue
(
"server"
,
"key_file"
)
KeyFile
=
server
.
Key
(
"cert_file"
)
.
String
(
)
}
}
Domain
=
Cfg
.
MustValue
(
"server"
,
"domain"
,
"localhost"
)
HttpAddr
=
Cfg
.
MustValue
(
"server"
,
"http_addr"
,
"0.0.0.0"
)
Domain
=
server
.
Key
(
"domain"
)
.
MustString
(
"localhost"
)
HttpPort
=
Cfg
.
MustValue
(
"server"
,
"http_port"
,
"3000"
)
HttpAddr
=
server
.
Key
(
"http_addr"
)
.
MustString
(
"0.0.0.0"
)
HttpPort
=
server
.
Key
(
"http_port"
)
.
MustString
(
"3000"
)
port
:=
os
.
Getenv
(
"PORT"
)
port
:=
os
.
Getenv
(
"PORT"
)
if
port
!=
""
{
if
port
!=
""
{
HttpPort
=
port
HttpPort
=
port
}
}
StaticRootPath
=
Cfg
.
MustValue
(
"server"
,
"static_root_path"
,
path
.
Join
(
WorkDir
,
"webapp"
))
StaticRootPath
=
server
.
Key
(
"static_root_path"
)
.
MustString
(
path
.
Join
(
WorkDir
,
"webapp"
))
RouterLogging
=
Cfg
.
MustBool
(
"server"
,
"router_logging"
,
false
)
RouterLogging
=
server
.
Key
(
"router_logging"
)
.
MustBool
(
false
)
EnableGzip
=
Cfg
.
MustBool
(
"server"
,
"enable_gzip"
)
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
// Http auth
AdminUser
=
Cfg
.
MustValue
(
"admin"
,
"user"
,
"admin"
)
AdminUser
=
security
.
Key
(
"admin_user"
)
.
String
()
AdminPassword
=
Cfg
.
MustValue
(
"admin"
,
"password"
,
"admin"
)
AdminPassword
=
security
.
Key
(
"admin_password"
)
.
String
()
Anonymous
=
Cfg
.
MustBool
(
"auth"
,
"anonymous"
,
false
)
AnonymousAccountId
=
Cfg
.
MustInt64
(
"auth"
,
"anonymous_account_id"
,
0
)
if
Anonymous
&&
AnonymousAccountId
==
0
{
// Anonymous = Cfg.MustBool("auth", "anonymous", false)
log
.
Fatal
(
3
,
"Must specify account id for anonymous access"
)
// AnonymousAccountId = Cfg.MustInt64("auth", "anonymous_account_id", 0)
}
// PhantomJS rendering
// PhantomJS rendering
ImagesDir
=
"data/png"
ImagesDir
=
"data/png"
PhantomDir
=
"vendor/phantomjs"
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
()
readSessionConfig
()
}
}
func
readSessionConfig
()
{
func
readSessionConfig
()
{
sec
:=
Cfg
.
Section
(
"session"
)
SessionOptions
=
session
.
Options
{}
SessionOptions
=
session
.
Options
{}
SessionOptions
.
Provider
=
Cfg
.
MustValueRange
(
"session"
,
"provider"
,
"memory"
,
[]
string
{
"memory"
,
"file
"
})
SessionOptions
.
Provider
=
sec
.
Key
(
"provider"
)
.
In
(
"memory"
,
[]
string
{
"memory"
,
"file"
,
"redis"
,
"mysql
"
})
SessionOptions
.
ProviderConfig
=
strings
.
Trim
(
Cfg
.
MustValue
(
"session"
,
"provider_config"
),
"
\"
"
)
SessionOptions
.
ProviderConfig
=
strings
.
Trim
(
sec
.
Key
(
"provider_config"
)
.
String
(
),
"
\"
"
)
SessionOptions
.
CookieName
=
Cfg
.
MustValue
(
"session"
,
"cookie_name"
,
"grafana_pro
_sess"
)
SessionOptions
.
CookieName
=
sec
.
Key
(
"cookie_name"
)
.
MustString
(
"grafana
_sess"
)
SessionOptions
.
CookiePath
=
AppSubUrl
SessionOptions
.
CookiePath
=
AppSubUrl
SessionOptions
.
Secure
=
Cfg
.
MustBool
(
"session"
,
"cookie_secure"
)
SessionOptions
.
Secure
=
sec
.
Key
(
"cookie_secure"
)
.
MustBool
(
)
SessionOptions
.
Gclifetime
=
Cfg
.
MustInt64
(
"session"
,
"gc_interval_time"
,
86400
)
SessionOptions
.
Gclifetime
=
Cfg
.
Section
(
"session"
)
.
Key
(
"gc_interval_time"
)
.
MustInt64
(
86400
)
SessionOptions
.
Maxlifetime
=
Cfg
.
MustInt64
(
"session"
,
"session_life_time"
,
86400
)
SessionOptions
.
Maxlifetime
=
Cfg
.
Section
(
"session"
)
.
Key
(
"session_life_time"
)
.
MustInt64
(
86400
)
if
SessionOptions
.
Provider
==
"file"
{
if
SessionOptions
.
Provider
==
"file"
{
os
.
MkdirAll
(
path
.
Dir
(
SessionOptions
.
ProviderConfig
),
os
.
ModePerm
)
os
.
MkdirAll
(
path
.
Dir
(
SessionOptions
.
ProviderConfig
),
os
.
ModePerm
)
...
...
pkg/social/social.go
View file @
95305e7e
...
@@ -39,13 +39,14 @@ func NewOAuthService() {
...
@@ -39,13 +39,14 @@ func NewOAuthService() {
allOauthes
:=
[]
string
{
"github"
,
"google"
}
allOauthes
:=
[]
string
{
"github"
,
"google"
}
for
_
,
name
:=
range
allOauthes
{
for
_
,
name
:=
range
allOauthes
{
sec
:=
setting
.
Cfg
.
Section
(
"auth."
+
name
)
info
:=
&
setting
.
OAuthInfo
{
info
:=
&
setting
.
OAuthInfo
{
ClientId
:
se
tting
.
Cfg
.
MustValue
(
"auth."
+
name
,
"client_id"
),
ClientId
:
se
c
.
Key
(
"client_id"
)
.
String
(
),
ClientSecret
:
se
tting
.
Cfg
.
MustValue
(
"auth."
+
name
,
"client_secret"
),
ClientSecret
:
se
c
.
Key
(
"client_secret"
)
.
String
(
),
Scopes
:
se
tting
.
Cfg
.
MustValueArray
(
"auth."
+
name
,
"scopes"
,
" "
),
Scopes
:
se
c
.
Key
(
"scopes"
)
.
Strings
(
" "
),
AuthUrl
:
se
tting
.
Cfg
.
MustValue
(
"auth."
+
name
,
"auth_url"
),
AuthUrl
:
se
c
.
Key
(
"auth_url"
)
.
String
(
),
TokenUrl
:
se
tting
.
Cfg
.
MustValue
(
"auth."
+
name
,
"token_url"
),
TokenUrl
:
se
c
.
Key
(
"token_url"
)
.
String
(
),
Enabled
:
se
tting
.
Cfg
.
MustBool
(
"auth."
+
name
,
"enabled"
),
Enabled
:
se
c
.
Key
(
"enabled"
)
.
MustBool
(
),
}
}
if
!
info
.
Enabled
{
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