config

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DavLogger func(r *http.Request, err error)

Functions

func GenShareHash added in v0.8.3

func GenShareHash(userName, itmPath string) string

Types

type AllowedShare

type AllowedShare struct {
	*UserConfig
	*ShareItem
}

type Auth

type Auth struct {
	Header string `json:"header"`
	Key    string `json:"key"`
}

Auth settings.

type CaptchaConfig

type CaptchaConfig struct {
	Host   string `json:"host"`
	Key    string `json:"key"`
	Secret string `json:"secret"`
}

type GlobalConfig

type GlobalConfig struct {
	Users   []*UserConfig `json:"users"`
	Http    *ListenConf   `json:"http"`
	Tls     *ListenConf   `json:"https"`
	Log     string        `json:"log"`
	TLSKey  string        `json:"tlsKey"`
	TLSCert string        `json:"tlsCert"`
	// Scope is the Path the user has access to.
	FilesPath      string `json:"filesPath"`
	*CaptchaConfig `json:"captchaConfig"`
	*Auth          `json:"auth"`
	*PreviewConf   `json:"preview"`
	//http://host:port that used behind DMZ
	ExternalShareHost string `json:"externalShareHost"`

	//Path to config file
	Path string `json:"-"`
}

Single config for everything. update automatically

func (*GlobalConfig) AddUser added in v0.8.6

func (cfg *GlobalConfig) AddUser(u *UserConfig) error

func (*GlobalConfig) CopyConfig

func (cfg *GlobalConfig) CopyConfig() *GlobalConfig

clone config

func (*GlobalConfig) DeleteUser added in v0.8.6

func (cfg *GlobalConfig) DeleteUser(username string) error

delete user by username

func (*GlobalConfig) GetAdmin

func (cfg *GlobalConfig) GetAdmin() *UserConfig

func (*GlobalConfig) GetDavPath added in v0.8.3

func (cfg *GlobalConfig) GetDavPath(userName string) string

~/<<cfg_PATH>>/<<username>>/

func (*GlobalConfig) GetExternal added in v0.8.3

func (cfg *GlobalConfig) GetExternal(hash string) (res *ShareItem, usr *UserConfig)

since we sure that this method will not modify, just return original

func (*GlobalConfig) GetKeyBytes

func (cfg *GlobalConfig) GetKeyBytes() ([]byte, error)

returns salt key in bytes, err in case key missed

func (*GlobalConfig) GetSharePreviewPath added in v0.8.3

func (cfg *GlobalConfig) GetSharePreviewPath(url string) (res string)

take the user from url, find it, after return user preview

func (*GlobalConfig) GetUserByIp added in v0.8.6

func (cfg *GlobalConfig) GetUserByIp(ip string) (*UserConfig, bool)

func (*GlobalConfig) GetUserByUsername added in v0.8.6

func (cfg *GlobalConfig) GetUserByUsername(username string) (*UserConfig, bool)

func (*GlobalConfig) GetUserHomePath added in v0.1.8

func (cfg *GlobalConfig) GetUserHomePath(userName string) string

~/<<cfg_PATH>>/<<username>>/files

func (*GlobalConfig) GetUserPreviewPath added in v0.1.8

func (cfg *GlobalConfig) GetUserPreviewPath(userName string) string

~/<<cfg_PATH>>/<<username>>/preview

func (*GlobalConfig) GetUserSharesPath added in v0.8.3

func (cfg *GlobalConfig) GetUserSharesPath(userName string) string

~/<<cfg_PATH>>/<<username>>/shares

func (*GlobalConfig) GetUserSharexPath added in v0.8.7

func (cfg *GlobalConfig) GetUserSharexPath(userName string) string

~/<<cfg_PATH>>/<<username>>/sharex

func (*GlobalConfig) GetUsers

func (cfg *GlobalConfig) GetUsers() (res []*UserConfig)

func (*GlobalConfig) ReadConfigFile

func (cfg *GlobalConfig) ReadConfigFile()

read and initiate global config, if file missed, one will be created with default settings.

func (*GlobalConfig) RefreshUserRam added in v0.8.3

func (cfg *GlobalConfig) RefreshUserRam()

should not be called directly

func (*GlobalConfig) SetKey

func (cfg *GlobalConfig) SetKey(k []byte)

update salt key

func (*GlobalConfig) Update

func (cfg *GlobalConfig) Update(u *UserConfig) error

func (*GlobalConfig) UpdateConfig

func (cfg *GlobalConfig) UpdateConfig(u *GlobalConfig)

deep update config

func (*GlobalConfig) UpdatePassword added in v0.8.3

func (cfg *GlobalConfig) UpdatePassword(u *UserConfig) error

func (*GlobalConfig) Verify

func (cfg *GlobalConfig) Verify()

func (*GlobalConfig) WriteConfig added in v0.1.8

func (cfg *GlobalConfig) WriteConfig()

type ListenConf added in v0.8.3

type ListenConf struct {
	Port int    `json:"port"`
	IP   string `json:"ip"`
	// Define if which of the following authentication mechansims should be used:
	// - 'default', which requires a user and a password.
	// - 'proxy', which requires a valid user and the user name has to be provided through an
	//   web header.
	// - 'none', which allows anyone to access the filebrowser instance.
	// If 'Method' is set to 'proxy' the header configured below is used to identify the user.
	AuthMethod string `json:"authMethod"`
}

type PreviewConf

type PreviewConf struct {
	//enable preview generating by call .sh
	ScriptPath string `json:"scriptPath"`
	Threads    int    `json:"threads"`
	FirstRun   bool   `json:"previewOnFirstRun"`
}

Auth settings.

type ShareItem

type ShareItem struct {
	Path string `json:"path"`
	//allow all not registered
	AllowExternal bool `json:"allowExternal"`
	//allow all registered users
	AllowLocal bool `json:"allowLocal"`
	//allowed by only specific users
	AllowUsers []string `json:"allowedUsers"`
	//uses for external DMZ share request
	Hash string `json:"-"`
}

presents 1 share Path in filesystem, and access rules

func (*ShareItem) IsAllowed

func (shr *ShareItem) IsAllowed(user string) (res bool)

allow access to the specific share link

func (*ShareItem) ResolveSymlinkName added in v0.8.6

func (shr *ShareItem) ResolveSymlinkName() string

will create correct symlink name, err in case hash empty

type TContext added in v0.8.6

type TContext struct {
	SharePathDeep  string
	SharePathUp    string
	ConfigPath     string
	Usr1           *UserConfig
	Usr2           *UserConfig
	Guest          *UserConfig
	User1FS        utils.Dir
	User1FSPreview utils.Dir
	User2FS        utils.Dir
	User2FSShare   utils.Dir
	AdminFSShare   utils.Dir
	AdminFS        utils.Dir
	*GlobalConfig
	Srv   *httptest.Server
	Tr    *http.Transport
	Token string
}

helper struct for testing only

func (*TContext) Clean added in v0.8.6

func (tc *TContext) Clean(t *testing.T)

func (*TContext) Init added in v0.8.6

func (tc *TContext) Init()

func (*TContext) InitWithUsers added in v0.8.6

func (tc *TContext) InitWithUsers(t *testing.T)

setup filesystem in ram for users, will create empty test files

func (*TContext) MakeUser added in v0.8.6

func (tc *TContext) MakeUser(name string) *UserConfig

type UserConfig

type UserConfig struct {
	FirstRun bool `json:"hashPasswordFirstRun"`
	// Tells if this user is an admin.
	Admin bool `json:"admin"`
	// These indicate if the user can perform certain actions.
	AllowEdit bool `json:"allowEdit"` // Edit/rename files
	AllowNew  bool `json:"allowNew"`  // Create files and folders

	// Prevents the user to change its password.
	LockPassword bool `json:"lockPassword"`

	// Locale is the language of the user.
	Locale string `json:"locale"`

	// The hashed password. This never reaches the front-end because it's temporarily
	// emptied during JSON marshall.
	Password string `json:"password"`

	// Username is the user username used to login.
	Username string `json:"username"`

	// User view mode for files and folders.
	ViewMode string `json:"viewMode"`

	Shares []*ShareItem `json:"shares"`
	//authenticate by IP, need to change auth.method
	IpAuth     []string        `json:"ipAuth"`
	DavHandler *webdav.Handler `json:"-"`

	//create files/folders according this ownership
	UID int `json:"uid"`
	GID int `json:"gid"`
}

User contains the configuration for each user.

func (*UserConfig) AddShare

func (u *UserConfig) AddShare(shr *ShareItem) (res bool)

true in case share added

func (*UserConfig) DeleteShare

func (u *UserConfig) DeleteShare(relPath string) (res bool)

true in case share deleted

func (*UserConfig) GetShares added in v0.8.3

func (u *UserConfig) GetShares(relPath string, del bool) (res []*ShareItem)

func (*UserConfig) IsGuest added in v0.8.3

func (u *UserConfig) IsGuest() bool

Jump to

Keyboard shortcuts

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