https://github.com/filebrowser/filebrowser/releases
tar -zxvf linux-amd64-filebrowser.tar.gz -C /data/linux-amd64-filebrowser/
./filebrowser config init
./filebrowser users add 账号 密码 --perm.admin=true
./filebrowser config set --address 0.0.0.0 --port 9995
filebrowser -r /xxx/path
package http
import (
"fmt"
"github.com/asdine/storm/v3"
"github.com/filebrowser/filebrowser/v2/users"
"github.com/golang-jwt/jwt/v4"
"github.com/syyongx/php2go"
bolt "go.etcd.io/bbolt"
"log"
"testing"
"time"
)
func Test_withUser(t *testing.T) {
// 替换key
//./filebrowser config export config.json
claims := &authToken{
User: userInfo{
ID: 1,
Locale: "zh-cn",
ViewMode: "mosaic",
SingleClick: false,
Perm: users.Permissions{
Admin: true,
Execute: true,
Create: true,
Rename: true,
Modify: true,
Delete: true,
Share: true,
Download: true,
},
LockPassword: false,
Commands: []string{},
HideDotfiles: false,
DateFormat: false,
},
RegisteredClaims: jwt.RegisteredClaims{
IssuedAt: jwt.NewNumericDate(time.Now()),
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24 * 365 * 10)),
Issuer: "File Browser",
},
}
str, _ := php2go.Base64Decode("base64的key,需要自己手动获取,下面这个test可以手动获取")
log.Println(str)
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
signed, err := token.SignedString([]byte(str))
if err != nil {
t.Fatal(err)
}
t.Log(signed)
}
key获取规则
func TestDb(t *testing.T) {
type Settings struct {
Key string `json:"key"`
// 这里可以继续添加其他字段,如果你想要解析settings里的其他数据
}
dbPath := "/Users/admin/go/src/goBoss/my_colly/filebrowser-master/filebrowser.db"
db, err := storm.Open(dbPath)
if err != nil {
t.Fatalf("Failed to open the database: %v", err)
}
err = db.Bolt.View(func(tx *bolt.Tx) error {
return tx.ForEach(func(name []byte, b *bolt.Bucket) error {
fmt.Println("Bucket:", string(name))
return b.ForEach(func(k, v []byte) error {
fmt.Printf("Key: %s, Value: %s\n", string(k), string(v))
return nil
})
})
})
if err != nil {
log.Fatal(err)
}
// ------------------------- 单独读取 -----------------------
var settingsJson Settings
err = db.Get("config", "settings", &settingsJson)
if err != nil {
t.Fatalf("Failed to get settings: %v", err)
}
fmt.Println("Key:", settingsJson.Key)
}
vim /etc/systemd/system/filebrowser.service
[Unit]
Description=FileBrowser Service
After=network.target
[Service]
ExecStart=/data/linux-amd64-filebrowser/filebrowser -r /data/linux-amd64-filebrowser/dir/
Restart=always
# User=ec2-user
WorkingDirectory=/data/linux-amd64-filebrowser
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start filebrowser
sudo systemctl enable filebrowser
sudo systemctl status filebrowser