view pkg/controllers/system.go @ 804:21609ba97357

client: improve legendelements for layerselection * Add a special hint to the layer data, so that we can detect points and specify which resolution we want for the legend. * Improve LineString to have a bend. * Actually take styles of the layer into account. * Do not act on TILE layers.
author Bernhard Reiter <bernhard@intevation.de>
date Thu, 27 Sep 2018 15:00:52 +0200
parents 815f5e2ed974
children 0f61bfc21041
line wrap: on
line source

package controllers

import (
	"database/sql"
	"io/ioutil"
	"net/http"
	"strings"

	"github.com/gorilla/mux"
)

func showSystemLog(
	_ interface{}, req *http.Request,
	_ *sql.Conn,
) (jr JSONResult, err error) {

	serviceName := mux.Vars(req)["service"]
	fileName := mux.Vars(req)["file"]

	// The following check is currently most likely unnecessary as I wasn't
	// able to inject a verbatim '/' via the middleware, but better be on
	// the safe site...
	if strings.Contains(fileName, "/") {
		err = JSONError{http.StatusBadRequest,
			"error: no slashes allowed in file name"}
		return
	}

	var path string

	switch serviceName {
	case "apache2", "postgresql":
		path = "/var/log/" + serviceName + "/" + fileName
	default:
		err = JSONError{http.StatusBadRequest,
			"error: invalid service: " + serviceName}
		return
	}

	var txt []byte

	if txt, err = ioutil.ReadFile(path); err != nil {
		return
	}

	jr = JSONResult{
		Result: struct {
			Path    string `json:"path"`
			Content string `json:"content"`
		}{path, string(txt)},
	}
	return
}