update readme
parent
c4a4d1a6e3
commit
465b10a02a
|
@ -8,7 +8,7 @@ Note that if you are handling large files you might run into troubles due to the
|
||||||
|
|
||||||
To start using this plugin you just need to go to the [download Caddy page](https://caddyserver.com/download) and choose `filemanager` in the directives section. For further information on how Caddy works refer to [its documentation](https://caddyserver.com/docs).
|
To start using this plugin you just need to go to the [download Caddy page](https://caddyserver.com/download) and choose `filemanager` in the directives section. For further information on how Caddy works refer to [its documentation](https://caddyserver.com/docs).
|
||||||
|
|
||||||
The default credentials are `admin` for the user and the password. It is highy recommended to change this after logging in for the first time and to use HTTPS. In the web interface, you can create more users and define their own permissions.
|
The default credentials are `admin` for both the user and the password. It is highy recommended to change them after logging in for the first time and to use HTTPS. You can create more users and define their own permissions using the web interface.
|
||||||
|
|
||||||
## Syntax
|
## Syntax
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@ filemanager [baseurl] [scope] {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
All of the options above are optional.
|
`baseurl` is the URL path where you will access File Manager. Defaults to `/`.
|
||||||
|
|
||||||
+ **baseurl** is the URL where you will access the File Manager interface. Defaults to `/`.
|
`scope` is the path, relative or absolute, to the directory you want to browse in. This value will be used for the creation of the first user. Defaults to `./`.
|
||||||
+ **scope** is the path, relative or absolute, to the directory you want to browse in. Defaults to `./`.
|
|
||||||
+ **path** is the database path where the settings that aren't included in the Caddyfile will be stored. By default, the database will be stored on `.caddy` folder and its name will be an hashed combination of the host and the `baseurl`. It is **highly** recommended to set this option. Otherwise, whenever you change the host or the `baseurl`, your settings will be lost or you will need to point to the previous database.
|
`path` is the database path where the settings will be stored. By default, the database will be stored on `.caddy/filemanager` folder and its name will be an hashed combination of the host and the `baseurl`. If you use a relative path it will be relative to `.caddy/filemanager`. Despite being optional, it is **highly** recommended to set this option in order to keep the settings when you change the `baseurl` and/or the hostname.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
package filemanager
|
package filemanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -97,22 +98,31 @@ func parse(c *caddy.Controller) ([]*config, error) {
|
||||||
|
|
||||||
caddyConf := httpserver.GetConfig(c)
|
caddyConf := httpserver.GetConfig(c)
|
||||||
|
|
||||||
// If there is no database path on the settings,
|
|
||||||
// store one in .caddy/filemanager/name.db.
|
|
||||||
if database == "" {
|
|
||||||
path := filepath.Join(caddy.AssetsPath(), "filemanager")
|
path := filepath.Join(caddy.AssetsPath(), "filemanager")
|
||||||
err := os.MkdirAll(path, 0700)
|
err := os.MkdirAll(path, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if there is a database path and it is not absolute,
|
||||||
|
// it will be relative to Caddy folder.
|
||||||
|
if !filepath.IsAbs(database) && database != "" {
|
||||||
|
database = filepath.Join(path, database)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is no database path on the settings,
|
||||||
|
// store one in .caddy/filemanager/name.db.
|
||||||
|
if database == "" {
|
||||||
// The name of the database is the hashed value of a string composed
|
// The name of the database is the hashed value of a string composed
|
||||||
// by the host, address path and the baseurl of this File Manager
|
// by the host, address path and the baseurl of this File Manager
|
||||||
// instance.
|
// instance.
|
||||||
hasher := sha256.New()
|
hasher := md5.New()
|
||||||
hasher.Write([]byte(caddyConf.Addr.Host + caddyConf.Addr.Path + baseURL))
|
hasher.Write([]byte(caddyConf.Addr.Host + caddyConf.Addr.Path + baseURL))
|
||||||
sha := hex.EncodeToString(hasher.Sum(nil))
|
sha := hex.EncodeToString(hasher.Sum(nil))
|
||||||
database = filepath.Join(path, sha+".db")
|
database = filepath.Join(path, sha+".db")
|
||||||
|
|
||||||
|
fmt.Println("[WARNING] A database is going to be created for your File Manager instace at " + database +
|
||||||
|
". It is highly recommended that you set the 'database' option to '" + sha + ".db'\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
fm, err := New(database, User{
|
fm, err := New(database, User{
|
||||||
|
|
Loading…
Reference in New Issue