Example #1
0
package admin

import (
	"github.com/gorilla/mux"
	"k.prv/secproxy/config"
	"k.prv/secproxy/logging"
	"net/http"
)

var logUsers = logging.NewLogger("admin.users")

// Init - Initialize application
func InitUsersHandlers(globals *config.Globals, parentRotuer *mux.Route) {
	router := parentRotuer.Subrouter()
	router.HandleFunc("/{login}", SecurityContextHandler(userPageHandler, globals, "ADMIN"))
	router.HandleFunc("/", SecurityContextHandler(usersPageHandler, globals, "ADMIN"))
}

func usersPageHandler(w http.ResponseWriter, r *http.Request, bctx *BasePageContext) {
	ctx := &struct {
		*BasePageContext
		Users []*config.User
	}{bctx, bctx.Globals.GetUsers()}
	RenderTemplateStd(w, ctx, "users/index.tmpl")
}

type (
	userForm struct {
		*config.User
		NewPassword  string
		NewPasswordC string
Example #2
0
package admin

import (
	"github.com/gorilla/mux"
	"k.prv/secproxy/config"
	"k.prv/secproxy/logging"
	"k.prv/secproxy/proxy"
	"net/http"
	"strings"
)

var logEP = logging.NewLogger("admin.auth")

// Init - Initialize application
func InitEndpointsHandlers(globals *config.Globals, parentRotuer *mux.Route) {
	router := parentRotuer.Subrouter()
	router.HandleFunc("/", SecurityContextHandler(endpointsPageHandler, globals, "ADMIN"))
	router.HandleFunc("/{name}", SecurityContextHandler(endpointPageHandler, globals, "ADMIN"))
	router.HandleFunc("/{name}/{action}", SecurityContextHandler(endpointActionPageHandler, globals, "ADMIN"))
}

type endpoint struct {
	Name       string
	Running    bool
	Local      string
	LocalHttps string
	Remote     string
	Errors     string
}

func endpointsPageHandler(w http.ResponseWriter, r *http.Request, bctx *BasePageContext) {
Example #3
0
package admin

import (
	"github.com/gorilla/mux"
	"io"
	"k.prv/secproxy/config"
	"k.prv/secproxy/logging"
	"net/http"
	"os"
	"path"
	"path/filepath"
	"strings"
)

var logCerts = logging.NewLogger("admin.certs")

// Init - Initialize application
func InitCertsHandlers(globals *config.Globals, parentRotuer *mux.Route) {
	router := parentRotuer.Subrouter()
	router.HandleFunc("/", SecurityContextHandler(certsPageHandler, globals, "ADMIN"))
	router.HandleFunc("/upload", SecurityContextHandler(certUploadPageHandler, globals, "ADMIN")).Methods("POST")
	router.HandleFunc("/delete", SecurityContextHandler(certDeletePageHandler, globals, "ADMIN"))
}

func certsPageHandler(w http.ResponseWriter, r *http.Request, bctx *BasePageContext) {
	ctx := &struct {
		*BasePageContext
		Certs []string
	}{
		bctx,
		bctx.Globals.FindCerts(),
Example #4
0
// Sessions settings
const (
	sessionTimestampKey  = "timestamp"
	sessionLoggedUserKey = "USER"
	maxSessionAgeDays    = 31
	maxSessionAge        = time.Duration(24*maxSessionAgeDays) * time.Hour
)

type SessionUser struct {
	Login string
	Role  string
}

var store *sessions.CookieStore
var logSession = logging.NewLogger("admin.session")

func init() {
	gob.Register(&SessionUser{})
}

func NewSessionUser(login, role string) *SessionUser {
	return &SessionUser{
		Login: login,
		Role:  role,
	}
}

// InitSessionStore initialize sessions support
func InitSessionStore(conf *config.AppConfiguration) error {
	if len(conf.AdminPanel.CookieAuthKey) < 32 {
Example #5
0
package config

import (
	"github.com/naoina/toml"
	"io/ioutil"
	"k.prv/secproxy/common"
	"k.prv/secproxy/logging"
	"os"
)

var (
	AppVersion = "dev"
	log        = logging.NewLogger("config")
)

type (
	AdminPanelConf struct {
		HTTPAddress     string
		HTTPSAddress    string
		SslCert         string
		SslKey          string
		CookieAuthKey   string
		CookieEncKey    string
		SessionStoreDir string
		StaticDir       string
		TemplatesDir    string
	}

	// AppConfiguration Main app configuration.
	AppConfiguration struct {
		DBFilename string
Example #6
0
	varState string
)

func (v varState) String() string {
	return string(v)
}

var (
	states   map[string]*state = make(map[string]*state)
	counters                   = expvar.NewMap("counters")
	servStat                   = expvar.NewMap("states")
	errors                     = expvar.NewMap("errors")
	mu       sync.RWMutex

	log = logging.NewLogger("server")
)

func StartEndpoint(name string, globals *config.Globals) (errstr []string) {
	log.Info("server.StartEndpoint starting ", "endpoint", name)

	mu.Lock()
	defer mu.Unlock()

	var st *state
	var ok bool
	if st, ok = states[name]; ok && st != nil {
		if st.running || st.runningSSL {
			log.Warn("server.StartEndpoint already started ", "enpoint", name)
			return []string{"already running"}
		}
Example #7
0
package admin

import (
	"github.com/gorilla/mux"
	"github.com/gorilla/schema"
	"k.prv/secproxy/common"
	"k.prv/secproxy/config"
	"k.prv/secproxy/logging"
	"net/http"
)

var (
	appRouter = mux.NewRouter()
	decoder   = schema.NewDecoder()
	log       = logging.NewLogger("admin")
)

func StartAdmin(globals *config.Globals) {

	debug := logging.DebugLevel() > 0

	InitSessionStore(globals.Config)
	appRouter.HandleFunc("/", SecurityContextHandler(mainPageHandler, globals, ""))

	appRouter.HandleFunc("/login", ContextHandler(loginPageHandler, globals)).Name("auth-login")
	appRouter.HandleFunc("/logout", logoffHandler)
	appRouter.HandleFunc("/chpass", SecurityContextHandler(chpassPageHandler, globals, ""))

	appRouter.HandleFunc("/logs", SecurityContextHandler(logsPageHandler, globals, "ADMIN"))

	InitUsersHandlers(globals, appRouter.PathPrefix("/users"))