2015-02-12 08:46:14 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2018-03-15 04:50:57 -05:00
|
|
|
"regexp"
|
2015-02-12 08:46:14 -06:00
|
|
|
"strings"
|
|
|
|
|
2016-01-24 23:18:17 -06:00
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
2015-02-12 08:46:14 -06:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
)
|
|
|
|
|
2018-03-07 10:54:50 -06:00
|
|
|
func AdminGetSettings(c *m.ReqContext) {
|
2015-02-12 08:46:14 -06:00
|
|
|
settings := make(map[string]interface{})
|
|
|
|
|
2018-04-30 09:21:04 -05:00
|
|
|
for _, section := range setting.Raw.Sections() {
|
2015-02-12 08:46:14 -06:00
|
|
|
jsonSec := make(map[string]interface{})
|
|
|
|
settings[section.Name()] = jsonSec
|
|
|
|
|
|
|
|
for _, key := range section.Keys() {
|
|
|
|
keyName := key.Name()
|
|
|
|
value := key.Value()
|
2015-11-18 08:55:45 -06:00
|
|
|
if strings.Contains(keyName, "secret") || strings.Contains(keyName, "password") || (strings.Contains(keyName, "provider_config")) {
|
2015-02-12 08:46:14 -06:00
|
|
|
value = "************"
|
|
|
|
}
|
2018-03-15 04:50:57 -05:00
|
|
|
if strings.Contains(keyName, "url") {
|
|
|
|
var rgx = regexp.MustCompile(`.*:\/\/([^:]*):([^@]*)@.*?$`)
|
|
|
|
var subs = rgx.FindAllSubmatch([]byte(value), -1)
|
|
|
|
if subs != nil && len(subs[0]) == 3 {
|
|
|
|
value = strings.Replace(value, string(subs[0][1]), "******", 1)
|
|
|
|
value = strings.Replace(value, string(subs[0][2]), "******", 1)
|
|
|
|
}
|
|
|
|
}
|
2015-02-13 01:47:44 -06:00
|
|
|
|
2015-02-12 08:46:14 -06:00
|
|
|
jsonSec[keyName] = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(200, settings)
|
|
|
|
}
|
2016-01-24 13:01:33 -06:00
|
|
|
|
2018-03-07 10:54:50 -06:00
|
|
|
func AdminGetStats(c *m.ReqContext) {
|
2016-01-24 13:01:33 -06:00
|
|
|
|
2016-01-24 23:18:17 -06:00
|
|
|
statsQuery := m.GetAdminStatsQuery{}
|
2016-01-24 13:01:33 -06:00
|
|
|
|
2016-01-24 23:18:17 -06:00
|
|
|
if err := bus.Dispatch(&statsQuery); err != nil {
|
|
|
|
c.JsonApiErr(500, "Failed to get admin stats from database", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(200, statsQuery.Result)
|
2016-01-24 13:01:33 -06:00
|
|
|
}
|