Skip to content

Commit

Permalink
frontend change, oauth fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Sep 18, 2020
1 parent edeac80 commit 4fec05c
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 0.90.68 (09-15-2020)
# 0.90.68 (09-17-2020)
- Added DB_DSN env for mysql, postgres or sqlite DSN database connection string
- Added READ_ONLY env for a read only connection to the database
- Added Custom OAuth OpenID toggle switch in settings (appends 'openid' in scope)
Expand Down
18 changes: 13 additions & 5 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"time"
)

var (
importAll *bool
)

func assetsCli() error {
dir := utils.Directory
if err := utils.InitLogs(); err != nil {
Expand Down Expand Up @@ -254,6 +258,9 @@ func importCli(args []string) error {
if len(exportData.Messages) > 0 {
log.Printf("Messages: %d\n", len(exportData.Messages))
}
if len(exportData.Incidents) > 0 {
log.Printf("Incidents: %d\n", len(exportData.Incidents))
}
if len(exportData.Users) > 0 {
log.Printf("Users: %d\n", len(exportData.Users))
}
Expand Down Expand Up @@ -285,38 +292,38 @@ func importCli(args []string) error {
if ask("Import Core settings?") {
c := exportData.Core
if err := c.Update(); err != nil {
return err
log.Errorln(err)
}
}
for _, s := range exportData.Groups {
if ask(fmt.Sprintf("Import Group '%s'?", s.Name)) {
s.Id = 0
if err := s.Create(); err != nil {
return err
log.Errorln(err)
}
}
}
for _, s := range exportData.Services {
if ask(fmt.Sprintf("Import Service '%s'?", s.Name)) {
s.Id = 0
if err := s.Create(); err != nil {
return err
log.Errorln(err)
}
}
}
for _, s := range exportData.Checkins {
if ask(fmt.Sprintf("Import Checkin '%s'?", s.Name)) {
s.Id = 0
if err := s.Create(); err != nil {
return err
log.Errorln(err)
}
}
}
for _, s := range exportData.Messages {
if ask(fmt.Sprintf("Import Message '%s'?", s.Title)) {
s.Id = 0
if err := s.Create(); err != nil {
return err
log.Errorln(err)
}
}
}
Expand All @@ -333,6 +340,7 @@ func importCli(args []string) error {
}

func ask(format string) bool {

fmt.Printf(fmt.Sprintf(format + " [y/N]: "))
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ class Api {
return axios.get('api/settings/configs').then(response => (response.data)) || []
}

async configs_save(data) {
return axios.post('api/settings/configs', data).then(response => (response.data)) || []
}

token() {
return $cookies.get(tokenKey);
}
Expand Down
20 changes: 17 additions & 3 deletions frontend/src/components/Dashboard/Configs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<codemirror v-show="loaded" v-model="configs" ref="configs" :options="cmOptions" class="mt-4 codemirrorInput"/>

<button @click.prevent="save" class="btn col-12 btn-primary mt-3">Save</button>
</div>
</template>

Expand All @@ -23,7 +24,7 @@ name: "Configs",
data() {
return {
loaded: false,
configs: "okkoko: okokoko",
configs: null,
cmOptions: {
height: 700,
tabSize: 4,
Expand All @@ -35,14 +36,27 @@ name: "Configs",
}
},
mounted() {
this.loaded = false
this.update()
this.loaded = true
},
watch: {
"configs" () {
this.$refs.configs.codemirror.refresh()
}
},
methods: {
async update() {
this.loaded = false
this.configs = await Api.configs()
this.loaded = true
this.$refs.configs.codemirror.value = this.configs
this.$refs.configs.codemirror.refresh()
},
async save() {
try {
await Api.configs_save(this.configs)
} catch(e) {
window.console.error(e)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/chinese.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const chinese = {
logout: "注销",
online: "在线",
offline: "离线",
configs: "配置",
username: "用户名",
password: "密码",
email: "电子邮件",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/english.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const english = {
logout: "Logout",
online: "Online",
offline: "Offline",
configs: "Configuration",
username: "Username",
password: "Password",
email: "Email",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/french.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const french = {
logout: "Déconnexion",
online: "En ligne",
offline: "Offline",
configs: "Configuration",
username: "Nom d'utilisateur",
password: "mot de passe",
email: "Email",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/german.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const german = {
logout: "Abmelden",
online: "Online",
offline: "Offline",
configs: "Konfiguration",
username: "Benutzername",
password: "Kennwort",
email: "Mail",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/italian.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const italian = {
logout: "Disconnetti",
online: "Online",
offline: "Offline",
configs: "Configurazione",
username: "Nome utente",
password: "Password",
email: "E-mail",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/japanese.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const japanese = {
logout: "ログアウト",
online: "オンライン",
offline: "オフライン",
configs: "構成",
username: "ユーザ名",
password: "パスワード",
email: "Eメール",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/korean.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const korean = {
logout: "로그아웃",
online: "온라인",
offline: "오프라인",
configs: "구성",
username: "사용자 이름",
password: "비밀번호",
email: "이메일",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/russian.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const russian = {
logout: "Выход из системы",
online: "Онлайн",
offline: "Оффлайн",
configs: "Конфигурация",
username: "Имя пользователя",
password: "Пароль",
email: "Электронная почта",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/spanish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const spanish = {
logout: "Cerrar sesión",
online: "En línea",
offline: "Offline",
configs: "Configuración",
username: "Nombre de usuario",
password: "Contraseña",
email: "Correo",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<font-awesome-icon icon="cloud-download-alt" class="mr-2"/> {{ $t('import') }}
</a>
<a @click.prevent="changeTab" class="nav-link" v-bind:class="{active: liClass('v-pills-configs-tab')}" id="v-pills-configs-tab" data-toggle="pill" href="#v-pills-configs" role="tab" aria-controls="v-pills-configs" aria-selected="false">
<font-awesome-icon icon="cloud-download-alt" class="mr-2"/> {{ $t('configs') }}
<font-awesome-icon icon="cogs" class="mr-2"/> {{ $t('configs') }}
</a>

<h6 class="mt-4 text-muted">{{$t('notifiers')}}</h6>
Expand Down
47 changes: 38 additions & 9 deletions handlers/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"github.com/statping/statping/types/core"
"github.com/statping/statping/types/errors"
"github.com/statping/statping/types/groups"
"github.com/statping/statping/types/incidents"
"github.com/statping/statping/types/messages"
"github.com/statping/statping/types/notifications"
"github.com/statping/statping/types/services"
"github.com/statping/statping/types/users"
"github.com/statping/statping/utils"
"gopkg.in/yaml.v2"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -162,14 +164,16 @@ func apiThemeRemoveHandler(w http.ResponseWriter, r *http.Request) {
}

type ExportData struct {
Config *configs.DbConfig `json:"config,omitempty"`
Core *core.Core `json:"core"`
Services []services.Service `json:"services"`
Messages []*messages.Message `json:"messages"`
Checkins []*checkins.Checkin `json:"checkins"`
Users []*users.User `json:"users"`
Groups []*groups.Group `json:"groups"`
Notifiers []notifications.Notification `json:"notifiers"`
Config *configs.DbConfig `json:"config,omitempty"`
Core *core.Core `json:"core"`
Services []services.Service `json:"services"`
Messages []*messages.Message `json:"messages"`
Incidents []*incidents.Incident `json:"incidents"`
IncidentUpdates []*incidents.IncidentUpdate `json:"incident_updates"`
Checkins []*checkins.Checkin `json:"checkins"`
Users []*users.User `json:"users"`
Groups []*groups.Group `json:"groups"`
Notifiers []notifications.Notification `json:"notifiers"`
}

func (e *ExportData) JSON() []byte {
Expand Down Expand Up @@ -262,7 +266,32 @@ func settingsImportHandler(w http.ResponseWriter, r *http.Request) {
}

func configsSaveHandler(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadAll(r.Body)
if err != nil {
sendErrorJson(err, w, r)
return
}
defer r.Body.Close()

var cfg *configs.DbConfig
if err := yaml.Unmarshal(data, &cfg); err != nil {
sendErrorJson(err, w, r)
return
}

oldCfg, err := configs.LoadConfigs(utils.Directory + "/configs.yml")
if err != nil {
sendErrorJson(err, w, r)
return
}

newCfg := cfg.Merge(oldCfg)
if err := newCfg.Save(utils.Directory); err != nil {
sendErrorJson(err, w, r)
return
}

sendJsonAction(newCfg.Clean(), "updated", w, r)
}

func configsViewHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -271,7 +300,7 @@ func configsViewHandler(w http.ResponseWriter, r *http.Request) {
sendErrorJson(err, w, r)
return
}
w.Write(db.ToYAML())
w.Write(db.Clean().ToYAML())
}

func settingsExportHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
22 changes: 22 additions & 0 deletions types/configs/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ func (d *DbConfig) Save(directory string) error {
return nil
}

// Merge will merge the database connection info into the input
func (d *DbConfig) Merge(newCfg *DbConfig) *DbConfig {
d.DbConn = newCfg.DbConn
d.DbHost = newCfg.DbHost
d.DbPort = newCfg.DbPort
d.DbData = newCfg.DbData
d.DbUser = newCfg.DbUser
d.DbPass = newCfg.DbPass
return d
}

// Clean hides all sensitive database information for API requests
func (d *DbConfig) Clean() *DbConfig {
d.DbConn = ""
d.DbHost = ""
d.DbPort = 0
d.DbData = ""
d.DbUser = ""
d.DbPass = ""
return d
}

func (d *DbConfig) ToYAML() []byte {
c, err := yaml.Marshal(d)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions types/configs/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ const SqliteFilename = "statping.db"

// DbConfig struct is used for the Db connection and creates the 'config.yml' file
type DbConfig struct {
DbConn string `yaml:"connection" json:"connection"`
DbConn string `yaml:"connection,omitempty" json:"connection"`
DbHost string `yaml:"host,omitempty" json:"-"`
DbUser string `yaml:"user,omitempty" json:"-"`
DbPass string `yaml:"password,omitempty" json:"-"`
DbData string `yaml:"database,omitempty" json:"-"`
DbPort int `yaml:"port,omitempty" json:"-"`
ApiSecret string `yaml:"api_secret" json:"-"`
Language string `yaml:"language" json:"language"`
AllowReports bool `yaml:"allow_reports" json:"allow_reports"`
ApiSecret string `yaml:"api_secret,omitempty" json:"-"`
Language string `yaml:"language,omitempty" json:"language"`
AllowReports bool `yaml:"allow_reports,omitempty" json:"allow_reports"`
Project string `yaml:"-" json:"-"`
Description string `yaml:"-" json:"-"`
Domain string `yaml:"-" json:"-"`
Username string `yaml:"-" json:"-"`
Password string `yaml:"-" json:"-"`
Email string `yaml:"-" json:"-"`
Error error `yaml:"-" json:"-"`
Location string `yaml:"location" json:"-"`
Location string `yaml:"location,omitempty" json:"-"`
SqlFile string `yaml:"sqlfile,omitempty" json:"-"`
LetsEncryptHost string `yaml:"letsencrypt_host,omitempty" json:"letsencrypt_host"`
LetsEncryptEmail string `yaml:"letsencrypt_email,omitempty" json:"letsencrypt_email"`
Expand Down

0 comments on commit 4fec05c

Please sign in to comment.