manageusers

package module
v0.0.0-...-49f9c84 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

caddy-manageusers

Caddy plugin designed to work with http.login (loginsrv) plugin. Allow creation, update, deletion of users in .htpasswd file and user-file. Based on https://github.com/foomo/htpasswd for htpasswd management.

Setup

Add a directive in your Caddyfile : manageusers /[route to access API] [.htpasswd file name] [optional : users.json file]

Example : manageusers /manageusers .htpasswd users.json

Usage

Retrieve user list
GET http://[hostname:port]/manageusers  HTTP/1.1
Add or alter an user
POST http://[hostname:port]/manageusers HTTP/1.1
content-type: application/json

{
    "username": "user",
    "password": "pwd",
    "origin": "htpasswd",
    "role": "user",
    "name": "Us",
    "surname": "ER"
}
Delete an user
DELETE http://[hostname:port]/manageusers/[username] HTTP/1.1

NB

The user-file is not dynamically reloaded when an user is added or deleted on windows systems, it is ok with linux systems. The loginsrv (http.login) plugin is supposed to work with a yaml file, but since json is valid yaml, it works flawlessly. The user management route must be protected by jwt to disable unwanted users creation (which is a major security flaw).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteUserInfoFile

func WriteUserInfoFile(file string, users *[]UserInfos) error

WriteUserInfoFile write user infos into file

Types

type Claims

type Claims struct {
	Role    string `json:"role"`
	Name    string `json:"name"`
	Surname string `json:"surname"`
}

Claims struct

type Config

type Config struct {
	Route        string
	HtPasswdFile string
	UserInfoFile string
}

Config type for the handler

type PwdHandler

type PwdHandler struct {
	Next   httpserver.Handler
	Config Config
}

PwdHandler type

func (PwdHandler) ServeHTTP

func (h PwdHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

type User

type User struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Origin   string `json:"origin"`
	Role     string `json:"role"`
	Name     string `json:"name"`
	Surname  string `json:"surname"`
}

User type

type UserInfos

type UserInfos struct {
	Sub    string `json:"sub"`
	Origin string `json:"origin"`
	Claims Claims `json:"claims"`
}

UserInfos type

func ParseUserInfoFile

func ParseUserInfoFile(file string) (users []UserInfos, err error)

ParseUserInfoFile load a json user file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址