Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
* master:
  chore: clean the code
  chore: add scripts to build and release
  feat: add configs for the email smtp
  chore: update the Makefile
  • Loading branch information
saltbo committed Oct 27, 2019
2 parents 742bfec + 5fbf586 commit 87a81f2
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

# Test binary, build with `go test -c`
*.test
bin
build
coverage.txt
config.yaml
roles.json

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install: true
script:
- make
- make test
- make pack
- make release

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.1.1] - 2017-06-20
### Added
- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8).
- Version navigation.

### Changed
- Start using "changelog" over "change log" since it's the common usage.

### Removed
- Section about "changelog" vs "CHANGELOG".

## [1.0.5] - 2019-10-16
### Added
- RU translation from [@aishek](https://github.com/aishek).
- pt-BR translation from [@tallesl](https://github.com/tallesl).
- es-ES translation from [@ZeliosAriex](https://github.com/ZeliosAriex).

分享链接匿名用户无法访问
37 changes: 11 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
.PHONY: default install build fmt test vet docker clean

BINARY=zpan
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(dir $(MKFILE_PATH))
default: build

TARGET_DIR=${MKFILE_DIR}build
TARGET_PATH=${TARGET_DIR}/${BINARY}

LDFLAGS="-s -w -X ${BINARY}/version.release=${RELEASE} -X ${BINARY}/version.commit=${COMMIT} -X ${BINARY}/version.repo=${GITREPO}"

# git info
COMMIT := git-$(shell git rev-parse --short HEAD)
GITREPO := $(shell git config --get remote.origin.url)
RELEASE := $(shell git describe --tags | awk -F '-' '{print $$1}')
build:
GO_BUILD_FLAGS="-v" ./scripts/build.sh
./bin/zpan --version

default: install build
run:
./bin/zpan

install:
go mod download
./scripts/install.sh

build:
GOOS=linux GOARCH=386 go build -ldflags ${LDFLAGS} -o ${TARGET_PATH}-linux-386/${BINARY} cmd/server.go
GOOS=linux GOARCH=amd64 go build -ldflags ${LDFLAGS} -o ${TARGET_PATH}-linux-amd64/${BINARY} cmd/server.go
GOOS=darwin GOARCH=386 go build -ldflags ${LDFLAGS} -o ${TARGET_PATH}-darwin-386/${BINARY} cmd/server.go
GOOS=darwin GOARCH=amd64 go build -ldflags ${LDFLAGS} -o ${TARGET_PATH}-darwin-amd64/${BINARY} cmd/server.go
release:
./scripts/release.sh

test:
go test -coverprofile=coverage.txt -covermode=atomic ./...
Expand All @@ -32,11 +22,6 @@ test:
covhtml:
go tool cover -html=coverage.txt

pack:
tar -C ${TARGET_DIR} -zvcf ${TARGET_PATH}-linux-386.tar.gz ${BINARY}-linux-386/${BINARY}
tar -C ${TARGET_DIR} -zvcf ${TARGET_PATH}-linux-amd64.tar.gz ${BINARY}-linux-amd64/${BINARY}
tar -C ${TARGET_DIR} -zvcf ${TARGET_PATH}-darwin-386.tar.gz ${BINARY}-darwin-386/${BINARY}
tar -C ${TARGET_DIR} -zvcf ${TARGET_PATH}-darwin-amd64.tar.gz ${BINARY}-darwin-amd64/${BINARY}

clean:
rm -rf ${TARGET_DIR}
rm -rf bin
rm -rf build
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ZPan - Your Last disk on the cloud.
- [x] File Manage
- [x] Folder Manage
- [x] File & Folder Share
- [x] Picture library
- [x] Storage Capacity Control
- [ ] RecycleBin
- [x] Support AliOSS
Expand All @@ -33,20 +34,25 @@ ZPan - Your Last disk on the cloud.
### Binary
Download the appropriate binary for your platform from the [Releases](https://github.com/saltbo/zpan/releases) page

```bash
cp config.yaml.tpl config.yaml
vi config.yaml #setup your configs
./zpan
```

### Source

> depend on [Golang](https://golang.org/dl/) compiler environment
```bash
git clone https://github.com/saltbo/zpan.git
cd zpan && make
```
or
```bash
go get github.com/saltbo/zpan
cd zpan && make && make install
```

## Usage
```bash
make run
```


## Contact us
Expand Down
2 changes: 1 addition & 1 deletion api/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewRest(conf *config.Config) (*RestServer, error) {
func (rs *RestServer) SetupProvider(provider disk.Provider) {
rs.provider = provider
rs.resources = []Resource{
NewUserResource(),
NewUserResource(rs),
NewURLResource(rs),
NewFileResource(rs),
NewShareResource(),
Expand Down
35 changes: 20 additions & 15 deletions api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ type RoleClaims struct {

type UserResource struct {
jwtSecret []byte
siteHost string
mailHost string
mailUser string
mailPwd string
}

func NewUserResource() Resource {
func NewUserResource(rs *RestServer) Resource {
return &UserResource{
jwtSecret: []byte(JWT_SECRET),
siteHost: rs.conf.SiteHost,
mailHost: rs.conf.Email.Host,
mailUser: rs.conf.Email.User,
mailPwd: rs.conf.Email.Password,
}
}

Expand Down Expand Up @@ -111,11 +119,11 @@ func (rs *UserResource) signUp(c *gin.Context) error {

body := `
<h3>账户激活链接</h3>
<p><a href="http://localhost:8080/login?email=%s&atoken=%s">点击此处重置密码</a></p>
<p><a href="%s/login?email=%s&atoken=%s">点击此处重置密码</a></p>
<p>如果您没有进行账号注册请忽略!</p>
`
body = fmt.Sprintf(body, p.Email, m.ActiveToken)
if err := SendToMail("账号注册成功,请激活您的账户", body, p.Email); err != nil {
body = fmt.Sprintf(body, rs.siteHost, p.Email, m.ActiveToken)
if err := rs.sendMail("账号注册成功,请激活您的账户", body, p.Email); err != nil {
return ginx.Failed(err)
}

Expand Down Expand Up @@ -280,11 +288,11 @@ func (rs *UserResource) sendRecoverMail(c *gin.Context) error {

body := `
<h3>密码重置链接</h3>
<p><a href="http://localhost:8080/login/resetpwd?email=%s&rtoken=%s">点击此处重置密码</a></p>
<p><a href="%s/login/resetpwd?email=%s&rtoken=%s">点击此处重置密码</a></p>
<p>如果您没有申请重置密码请忽略!</p>
`
body = fmt.Sprintf(body, p.Email, u.RecoverToken)
if err := SendToMail("密码重置申请", body, p.Email); err != nil {
body = fmt.Sprintf(body, rs.siteHost, p.Email, u.RecoverToken)
if err := rs.sendMail("密码重置申请", body, p.Email); err != nil {
return ginx.Failed(err)
}

Expand Down Expand Up @@ -314,17 +322,14 @@ func (rs *UserResource) resetPassword(c *gin.Context) error {
return nil
}

func SendToMail(subject, body, to string) error {
hostPort := "smtpdm.aliyun.com:25"
host, _, err := net.SplitHostPort(hostPort)
func (rs *UserResource) sendMail(subject, body, to string) error {
host, _, err := net.SplitHostPort(rs.mailHost)
if err != nil {
return err
}

user := "zpan@mail.saltbo.cn"
password := "SvNKDti9033wBJZB"
auth := smtp.PlainAuth("", user, password, host)
auth := smtp.PlainAuth("", rs.mailUser, rs.mailPwd, host)
contentType := "Content-Type: text/html; charset=UTF-8"
msg := []byte("To: " + to + "\r\nFrom: " + user + "\r\nSubject: " + subject + "\r\n" + contentType + "\r\n\r\n" + body)
return smtp.SendMail(hostPort, auth, user, []string{to}, msg)
msg := []byte("To: " + to + "\r\nFrom: " + rs.mailUser + "\r\nSubject: " + subject + "\r\n" + contentType + "\r\n\r\n" + body)
return smtp.SendMail(rs.mailHost, auth, rs.mailUser, []string{to}, msg)
}
31 changes: 30 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,50 @@ package main
import (
"log"
"math/rand"
"os"
"time"

"github.com/urfave/cli"

"zpan/api"
"zpan/config"
"zpan/dao"
"zpan/disk"
"zpan/version"
)

const (
// uploader configs
UPTOC_UPLOADER_OSS = "alioss"
)

var (
appFlags = []cli.Flag{
cli.StringFlag{
Name: "config,c",
Usage: "specify path of the config file. default: config.yaml",
Value: "config.yaml",
},
}
)

func main() {
app := cli.NewApp()
app.Name = "zpan"
app.Usage = "A cloud disk base on the cloud storage."
app.Copyright = "(c) 2019 zpan.saltbo.cn"
app.Compiled = time.Now()
app.Version = version.Short
app.Flags = appFlags
app.Action = serve
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}

func serve(c *cli.Context) {
rand.Seed(time.Now().UnixNano())
conf := config.Parse("config.yaml")
conf := config.Parse(c.String("config"))
dao.Init(conf.MySqlDSN)

// select provider
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ type Provider struct {
AccessSecret string `yaml:"access_secret"`
}

// system send email
type Email struct {
Host string `yaml:"host"`
User string `yaml:"user"`
Password string `yaml:"password"`
}

type Config struct {
SiteHost string `yaml:"site_host"`
StoreHost string `yaml:"store_host"`
MySqlDSN string `yaml:"mysqldsn"`
Provider *Provider `yaml:"provider"`
Email *Email `yaml:"email"`
}

func Parse(filename string) *Config {
Expand Down
8 changes: 7 additions & 1 deletion config.yaml.tpl → developments/config.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
host: http://local.frpx.saltbo.cn:1080
mysqldsn: root:root@tcp(127.0.0.1:3306)/zpan?charset=utf8&interpolateParams=true

provider:
name: alioss
bucket: saltbo-zpan-test
endpoint: https://oss-cn-zhangjiakou.aliyuncs.com
access_key: LTAI4FxxxxxxxxxxxxBXmS3
access_secret: Vt1FZgXxxxxxxxxxxxxxxx380AI
access_secret: Vt1FZgXxxxxxxxxxxxxxxx380AI

email:
host: smtpdm.aliyun.com:25
user: zpan@mail.saltbo.cn
password: SvNxxxxxxxxJZB
File renamed without changes.
15 changes: 15 additions & 0 deletions developments/zpan.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=zpan - A cloud disk base on the cloud storage.
Documentation=https://github.com/saltbo/zpan
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/zpan.pid
ExecStart=/usr/local/bin/zpan -c /etc/zpan/config.yaml
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require (
github.com/rakyll/statik v0.1.6
github.com/satori/go.uuid v1.2.0
github.com/storyicon/grbac v0.0.0-20190801030200-88ce5668903d
golang.org/x/exp v0.0.0-20190121172915-509febef88a4
github.com/urfave/cli v1.22.1
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 // indirect
golang.org/x/tools v0.0.0-20191010201905-e5ffc44a6fee // indirect
gopkg.in/yaml.v2 v2.2.2
)
Loading

0 comments on commit 87a81f2

Please sign in to comment.