Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

init core files, base deployment and command line management.

Jack068fc6c9f5ed
diff --git a/.gitignore b/.gitignore
index 2000043e..51fe7531 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,4 +7,13 @@ test/*
config/*
data/*
temp/
-ssl/*
\ No newline at end of file
+ssl/*
+.env
+billionmail.conf
+logs/
+backup/
+vmail-data/
+postfix-data/
+rspamd-data/
+postgresql-data/
+redis-data/
diff --git a/core/.gitattributes b/core/.gitattributes
new file mode 100644
index 00000000..1fbf887f
--- /dev/null
+++ b/core/.gitattributes
@@ -0,0 +1 @@
+* linguist-language=GO
\ No newline at end of file
diff --git a/core/.gitignore b/core/.gitignore
new file mode 100644
index 00000000..18646b63
--- /dev/null
+++ b/core/.gitignore
@@ -0,0 +1,19 @@
+.buildpath
+.hgignore.swp
+.project
+.orig
+.swp
+.idea/
+.settings/
+.vscode/
+bin/
+**/.DS_Store
+gf
+main
+main.exe
+output/
+manifest/output/
+temp/
+temp.yaml
+bin
+**/config/config.yaml
\ No newline at end of file
diff --git a/core/Makefile b/core/Makefile
new file mode 100644
index 00000000..2a6e6e96
--- /dev/null
+++ b/core/Makefile
@@ -0,0 +1,7 @@
+ROOT_DIR = $(shell pwd)
+NAMESPACE = "default"
+DEPLOY_NAME = "template-single"
+DOCKER_NAME = "template-single"
+
+include ./hack/hack-cli.mk
+include ./hack/hack.mk
\ No newline at end of file
diff --git a/core/README.MD b/core/README.MD
new file mode 100644
index 00000000..d36ceddf
--- /dev/null
+++ b/core/README.MD
@@ -0,0 +1,4 @@
+# GoFrame Template For SingleRepo
+
+Quick Start:
+- https://goframe.org/quick
\ No newline at end of file
diff --git a/core/api/hello/hello.go b/core/api/hello/hello.go
new file mode 100644
index 00000000..3ff7ea24
--- /dev/null
+++ b/core/api/hello/hello.go
@@ -0,0 +1,15 @@
+// =================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// =================================================================================
+
+package hello
+
+import (
+ "context"
+
+ "billionmail-core/api/hello/v1"
+)
+
+type IHelloV1 interface {
+ Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error)
+}
diff --git a/core/api/hello/v1/hello.go b/core/api/hello/v1/hello.go
new file mode 100644
index 00000000..b4dd233a
--- /dev/null
+++ b/core/api/hello/v1/hello.go
@@ -0,0 +1,12 @@
+package v1
+
+import (
+ "github.com/gogf/gf/v2/frame/g"
+)
+
+type HelloReq struct {
+ g.Meta `path:"/hello" tags:"Hello" method:"get" summary:"You first hello api"`
+}
+type HelloRes struct {
+ g.Meta `mime:"text/html" example:"string"`
+}
diff --git a/core/go.mod b/core/go.mod
new file mode 100644
index 00000000..2f4d7992
--- /dev/null
+++ b/core/go.mod
@@ -0,0 +1,35 @@
+module billionmail-core
+
+go 1.22
+
+toolchain go1.23.2
+
+require github.com/gogf/gf/v2 v2.9.0
+
+require (
+ github.com/BurntSushi/toml v1.4.0 // indirect
+ github.com/clbanning/mxj/v2 v2.7.0 // indirect
+ github.com/emirpasic/gods v1.18.1 // indirect
+ github.com/fatih/color v1.18.0 // indirect
+ github.com/fsnotify/fsnotify v1.7.0 // indirect
+ github.com/go-logr/logr v1.4.2 // indirect
+ github.com/go-logr/stdr v1.2.2 // indirect
+ github.com/google/uuid v1.6.0 // indirect
+ github.com/gorilla/websocket v1.5.3 // indirect
+ github.com/grokify/html-strip-tags-go v0.1.0 // indirect
+ github.com/kr/text v0.2.0 // indirect
+ github.com/magiconair/properties v1.8.9 // indirect
+ github.com/mattn/go-colorable v0.1.13 // indirect
+ github.com/mattn/go-isatty v0.0.20 // indirect
+ github.com/mattn/go-runewidth v0.0.16 // indirect
+ github.com/olekukonko/tablewriter v0.0.5 // indirect
+ github.com/rivo/uniseg v0.4.7 // indirect
+ go.opentelemetry.io/otel v1.32.0 // indirect
+ go.opentelemetry.io/otel/metric v1.32.0 // indirect
+ go.opentelemetry.io/otel/sdk v1.32.0 // indirect
+ go.opentelemetry.io/otel/trace v1.32.0 // indirect
+ golang.org/x/net v0.32.0 // indirect
+ golang.org/x/sys v0.28.0 // indirect
+ golang.org/x/text v0.21.0 // indirect
+ gopkg.in/yaml.v3 v3.0.1 // indirect
+)
diff --git a/core/go.sum b/core/go.sum
new file mode 100644
index 00000000..76f7aa27
--- /dev/null
+++ b/core/go.sum
@@ -0,0 +1,74 @@
+github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
+github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
+github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
+github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
+github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
+github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
+github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
+github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
+github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
+github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
+github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
+github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
+github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
+github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
+github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
+github.com/gogf/gf/v2 v2.9.0 h1:semN5Q5qGjDQEv4620VzxcJzJlSD07gmyJ9Sy9zfbHk=
+github.com/gogf/gf/v2 v2.9.0/go.mod h1:sWGQw+pLILtuHmbOxoe0D+0DdaXxbleT57axOLH2vKI=
+github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
+github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
+github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
+github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
+github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
+github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
+github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
+github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
+github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
+github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
+github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
+github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
+github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
+github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
+github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
+github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
+github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
+github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
+github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
+github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
+github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
+github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
+github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
+github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
+go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
+go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
+go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
+go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
+go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
+go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
+go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
+golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
+golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
+golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
+golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
+golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/core/hack/config.yaml b/core/hack/config.yaml
new file mode 100644
index 00000000..83c7dc6c
--- /dev/null
+++ b/core/hack/config.yaml
@@ -0,0 +1,13 @@
+
+# CLI tool, only in development environment.
+# https://goframe.org/docs/cli
+gfcli:
+ gen:
+ dao:
+ - link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
+ descriptionTag: true
+
+ docker:
+ build: "-a amd64 -s linux -p temp -ew"
+ tagPrefixes:
+ - my.image.pub/my-app
\ No newline at end of file
diff --git a/core/hack/hack-cli.mk b/core/hack/hack-cli.mk
new file mode 100644
index 00000000..f4e2ad28
--- /dev/null
+++ b/core/hack/hack-cli.mk
@@ -0,0 +1,20 @@
+
+# Install/Update to the latest CLI tool.
+.PHONY: cli
+cli:
+ @set -e; \
+ wget -O gf \
+ https://github.com/gogf/gf/releases/latest/download/gf_$(shell go env GOOS)_$(shell go env GOARCH) && \
+ chmod +x gf && \
+ ./gf install -y && \
+ rm ./gf
+
+
+# Check and install CLI tool.
+.PHONY: cli.install
+cli.install:
+ @set -e; \
+ gf -v > /dev/null 2>&1 || if [[ "$?" -ne "0" ]]; then \
+ echo "GoFame CLI is not installed, start proceeding auto installation..."; \
+ make cli; \
+ fi;
\ No newline at end of file
diff --git a/core/hack/hack.mk b/core/hack/hack.mk
new file mode 100644
index 00000000..2f68179d
--- /dev/null
+++ b/core/hack/hack.mk
@@ -0,0 +1,75 @@
+.DEFAULT_GOAL := build
+
+# Update GoFrame and its CLI to latest stable version.
+.PHONY: up
+up: cli.install
+ @gf up -a
+
+# Build binary using configuration from hack/config.yaml.
+.PHONY: build
+build: cli.install
+ @gf build -ew
+
+# Parse api and generate controller/sdk.
+.PHONY: ctrl
+ctrl: cli.install
+ @gf gen ctrl
+
+# Generate Go files for DAO/DO/Entity.
+.PHONY: dao
+dao: cli.install
+ @gf gen dao
+
+# Parse current project go files and generate enums go file.
+.PHONY: enums
+enums: cli.install
+ @gf gen enums
+
+# Generate Go files for Service.
+.PHONY: service
+service: cli.install
+ @gf gen service
+
+
+# Build docker image.
+.PHONY: image
+image: cli.install
+ $(eval _TAG = $(shell git rev-parse --short HEAD))
+ifneq (, $(shell git status --porcelain 2>/dev/null))
+ $(eval _TAG = $(_TAG).dirty)
+endif
+ $(eval _TAG = $(if ${TAG}, ${TAG}, $(_TAG)))
+ $(eval _PUSH = $(if ${PUSH}, ${PUSH}, ))
+ @gf docker ${_PUSH} -tn $(DOCKER_NAME):${_TAG};
+
+
+# Build docker image and automatically push to docker repo.
+.PHONY: image.push
+image.push: cli.install
+ @make image PUSH=-p;
+
+
+# Deploy image and yaml to current kubectl environment.
+.PHONY: deploy
+deploy: cli.install
+ $(eval _TAG = $(if ${TAG}, ${TAG}, develop))
+
+ @set -e; \
+ mkdir -p $(ROOT_DIR)/temp/kustomize;\
+ cd $(ROOT_DIR)/manifest/deploy/kustomize/overlays/${_ENV};\
+ kustomize build > $(ROOT_DIR)/temp/kustomize.yaml;\
+ kubectl apply -f $(ROOT_DIR)/temp/kustomize.yaml; \
+ if [ $(DEPLOY_NAME) != "" ]; then \
+ kubectl patch -n $(NAMESPACE) deployment/$(DEPLOY_NAME) -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"; \
+ fi;
+
+
+# Parsing protobuf files and generating go files.
+.PHONY: pb
+pb: cli.install
+ @gf gen pb
+
+# Generate protobuf files for database tables.
+.PHONY: pbentity
+pbentity: cli.install
+ @gf gen pbentity
\ No newline at end of file
diff --git a/core/internal/cmd/cmd.go b/core/internal/cmd/cmd.go
new file mode 100644
index 00000000..3f6670ea
--- /dev/null
+++ b/core/internal/cmd/cmd.go
@@ -0,0 +1,30 @@
+package cmd
+
+import (
+ "context"
+
+ "github.com/gogf/gf/v2/frame/g"
+ "github.com/gogf/gf/v2/net/ghttp"
+ "github.com/gogf/gf/v2/os/gcmd"
+
+ "billionmail-core/internal/controller/hello"
+)
+
+var (
+ Main = gcmd.Command{
+ Name: "main",
+ Usage: "main",
+ Brief: "start http server",
+ Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
+ s := g.Server()
+ s.Group("/", func(group *ghttp.RouterGroup) {
+ group.Middleware(ghttp.MiddlewareHandlerResponse)
+ group.Bind(
+ hello.NewV1(),
+ )
+ })
+ s.Run()
+ return nil
+ },
+ }
+)
diff --git a/core/internal/consts/consts.go b/core/internal/consts/consts.go
new file mode 100644
index 00000000..d709a2be
--- /dev/null
+++ b/core/internal/consts/consts.go
@@ -0,0 +1 @@
+package consts
diff --git a/core/internal/controller/hello/hello.go b/core/internal/controller/hello/hello.go
new file mode 100644
index 00000000..f72082fb
--- /dev/null
+++ b/core/internal/controller/hello/hello.go
@@ -0,0 +1,5 @@
+// =================================================================================
+// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
+// =================================================================================
+
+package hello
diff --git a/core/internal/controller/hello/hello_new.go b/core/internal/controller/hello/hello_new.go
new file mode 100644
index 00000000..0e3003e8
--- /dev/null
+++ b/core/internal/controller/hello/hello_new.go
@@ -0,0 +1,15 @@
+// =================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// =================================================================================
+
+package hello
+
+import (
+ "billionmail-core/api/hello"
+)
+
+type ControllerV1 struct{}
+
+func NewV1() hello.IHelloV1 {
+ return &ControllerV1{}
+}
diff --git a/core/internal/controller/hello/hello_v1_hello.go b/core/internal/controller/hello/hello_v1_hello.go
new file mode 100644
index 00000000..bc0646c3
--- /dev/null
+++ b/core/internal/controller/hello/hello_v1_hello.go
@@ -0,0 +1,13 @@
+package hello
+
+import (
+ "context"
+ "github.com/gogf/gf/v2/frame/g"
+
+ "billionmail-core/api/hello/v1"
+)
+
+func (c *ControllerV1) Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error) {
+ g.RequestFromCtx(ctx).Response.Writeln("Hello World!")
+ return
+}
diff --git a/core/internal/dao/.gitkeep b/core/internal/dao/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/internal/logic/.gitkeep b/core/internal/logic/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/internal/model/.gitkeep b/core/internal/model/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/internal/model/do/.gitkeep b/core/internal/model/do/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/internal/model/entity/.gitkeep b/core/internal/model/entity/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/internal/packed/packed.go b/core/internal/packed/packed.go
new file mode 100644
index 00000000..e20ab1e9
--- /dev/null
+++ b/core/internal/packed/packed.go
@@ -0,0 +1 @@
+package packed
diff --git a/core/internal/service/.gitkeep b/core/internal/service/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/main.go b/core/main.go
new file mode 100644
index 00000000..c565104e
--- /dev/null
+++ b/core/main.go
@@ -0,0 +1,13 @@
+package main
+
+import (
+ _ "billionmail-core/internal/packed"
+
+ "github.com/gogf/gf/v2/os/gctx"
+
+ "billionmail-core/internal/cmd"
+)
+
+func main() {
+ cmd.Main.Run(gctx.GetInitCtx())
+}
diff --git a/core/manifest/deploy/kustomize/base/deployment.yaml b/core/manifest/deploy/kustomize/base/deployment.yaml
new file mode 100644
index 00000000..28f1d694
--- /dev/null
+++ b/core/manifest/deploy/kustomize/base/deployment.yaml
@@ -0,0 +1,21 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: template-single
+ labels:
+ app: template-single
+spec:
+ replicas: 1
+ selector:
+ matchLabels:
+ app: template-single
+ template:
+ metadata:
+ labels:
+ app: template-single
+ spec:
+ containers:
+ - name : main
+ image: template-single
+ imagePullPolicy: Always
+
diff --git a/core/manifest/deploy/kustomize/base/kustomization.yaml b/core/manifest/deploy/kustomize/base/kustomization.yaml
new file mode 100644
index 00000000..302d92d6
--- /dev/null
+++ b/core/manifest/deploy/kustomize/base/kustomization.yaml
@@ -0,0 +1,8 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+resources:
+- deployment.yaml
+- service.yaml
+
+
+
diff --git a/core/manifest/deploy/kustomize/base/service.yaml b/core/manifest/deploy/kustomize/base/service.yaml
new file mode 100644
index 00000000..608771cc
--- /dev/null
+++ b/core/manifest/deploy/kustomize/base/service.yaml
@@ -0,0 +1,12 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: template-single
+spec:
+ ports:
+ - port: 80
+ protocol: TCP
+ targetPort: 8000
+ selector:
+ app: template-single
+
diff --git a/core/manifest/deploy/kustomize/overlays/develop/configmap.yaml b/core/manifest/deploy/kustomize/overlays/develop/configmap.yaml
new file mode 100644
index 00000000..3b1d0afe
--- /dev/null
+++ b/core/manifest/deploy/kustomize/overlays/develop/configmap.yaml
@@ -0,0 +1,14 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: template-single-configmap
+data:
+ config.yaml: |
+ server:
+ address: ":8000"
+ openapiPath: "/api.json"
+ swaggerPath: "/swagger"
+
+ logger:
+ level : "all"
+ stdout: true
diff --git a/core/manifest/deploy/kustomize/overlays/develop/deployment.yaml b/core/manifest/deploy/kustomize/overlays/develop/deployment.yaml
new file mode 100644
index 00000000..04e48519
--- /dev/null
+++ b/core/manifest/deploy/kustomize/overlays/develop/deployment.yaml
@@ -0,0 +1,10 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+ name: template-single
+spec:
+ template:
+ spec:
+ containers:
+ - name : main
+ image: template-single:develop
\ No newline at end of file
diff --git a/core/manifest/deploy/kustomize/overlays/develop/kustomization.yaml b/core/manifest/deploy/kustomize/overlays/develop/kustomization.yaml
new file mode 100644
index 00000000..4731c47f
--- /dev/null
+++ b/core/manifest/deploy/kustomize/overlays/develop/kustomization.yaml
@@ -0,0 +1,14 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+
+resources:
+- ../../base
+- configmap.yaml
+
+patchesStrategicMerge:
+- deployment.yaml
+
+namespace: default
+
+
+
diff --git a/core/manifest/docker/Dockerfile b/core/manifest/docker/Dockerfile
new file mode 100644
index 00000000..d3abe8f5
--- /dev/null
+++ b/core/manifest/docker/Dockerfile
@@ -0,0 +1,16 @@
+FROM loads/alpine:3.8
+
+###############################################################################
+# INSTALLATION
+###############################################################################
+
+ENV WORKDIR /app
+ADD resource $WORKDIR/
+ADD ./temp/linux_amd64/main $WORKDIR/main
+RUN chmod +x $WORKDIR/main
+
+###############################################################################
+# START
+###############################################################################
+WORKDIR $WORKDIR
+CMD ./main
diff --git a/core/manifest/docker/docker.sh b/core/manifest/docker/docker.sh
new file mode 100644
index 00000000..ff393f9c
--- /dev/null
+++ b/core/manifest/docker/docker.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# This shell is executed before docker build.
+
+
+
+
+
diff --git a/core/manifest/i18n/.gitkeep b/core/manifest/i18n/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/manifest/protobuf/.keep-if-necessary b/core/manifest/protobuf/.keep-if-necessary
new file mode 100644
index 00000000..e69de29b
diff --git a/core/resource/public/html/.gitkeep b/core/resource/public/html/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/resource/public/plugin/.gitkeep b/core/resource/public/plugin/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/resource/public/resource/css/.gitkeep b/core/resource/public/resource/css/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/resource/public/resource/image/.gitkeep b/core/resource/public/resource/image/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/resource/public/resource/js/.gitkeep b/core/resource/public/resource/js/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/resource/template/.gitkeep b/core/resource/template/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/core/utility/.gitkeep b/core/utility/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/init.sql b/init.sql
new file mode 100644
index 00000000..84309c38
--- /dev/null
+++ b/init.sql
@@ -0,0 +1,51 @@
+
+-- domain
+CREATE TABLE IF NOT EXISTS domain (
+ domain varchar(255) NOT NULL,
+ a_record varchar(255) NOT NULL DEFAULT '',
+ mailboxes int NOT NULL DEFAULT 50, -- Number of emails created
+ mailbox_quota BIGINT NOT NULL DEFAULT 5368709120, -- Default space size of mailbox
+ quota BIGINT NOT NULL DEFAULT 10737418240, -- Domain name quota
+ rate_limit INT DEFAULT 12, -- How many emails per second
+ create_time INT NOT NULL default 0,
+ active SMALLINT NOT NULL DEFAULT 1,
+ PRIMARY KEY (domain)
+);
+
+-- mailbox
+CREATE TABLE IF NOT EXISTS mailbox (
+ username varchar(255) NOT NULL,
+ password varchar(255) NOT NULL,
+ password_encode varchar(255) NOT NULL,
+ full_name varchar(255) NOT NULL,
+ is_admin smallint NOT NULL DEFAULT 0,
+ maildir varchar(255) NOT NULL,
+ quota bigint NOT NULL DEFAULT 0,
+ local_part varchar(255) NOT NULL,
+ domain varchar(255) NOT NULL,
+ create_time int NOT NULL default 0,
+ update_time int NOT NULL default 0,
+ active SMALLINT NOT NULL DEFAULT 1,
+ PRIMARY KEY (username)
+);
+
+-- alias
+CREATE TABLE IF NOT EXISTS alias (
+ address varchar(255) NOT NULL,
+ goto text NOT NULL,
+ domain varchar(255) NOT NULL,
+ create_time int NOT NULL default 0,
+ update_time int NOT NULL default 0,
+ active smallint NOT NULL DEFAULT 1,
+ PRIMARY KEY (address)
+);
+
+-- alias_domain
+CREATE TABLE IF NOT EXISTS alias_domain (
+ alias_domain varchar(255) NOT NULL,
+ target_domain varchar(255) NOT NULL,
+ create_time int NOT NULL default 0,
+ update_time int NOT NULL default 0,
+ active smallint NOT NULL DEFAULT 1,
+ PRIMARY KEY (alias_domain)
+);
diff --git a/install.sh b/install.sh
new file mode 100644
index 00000000..958e79a4
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,1253 @@
+#!/bin/bash
+PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
+export PATH
+
+CONTAINER_PROJECT_NAME=billionmail
+PGSQL_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-pgsql-billionmail-1"
+DOVECOT_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-dovecot-billionmail-1"
+POSTFIX_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-postfix-billionmail-1"
+create_time=$(date +%s)
+DBNAME=billionmail
+DBUSER=billionmail
+SMTP_PORT=25
+SMTPS_PORT=465
+SUBMISSION_PORT=587
+IMAP_PORT=143
+IMAPS_PORT=993
+POP_PORT=110
+POPS_PORT=995
+REDIS_PORT=127.0.0.1:26379
+SQL_PORT=127.0.0.1:25432
+REDISPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 32)
+time=$(date +%Y_%m_%d_%H_%M_%S)
+
+PWD_d=`pwd`
+download_Url=https://node.aapanel.com
+mirror=''
+Default_Download_Url=""
+
+CPU_architecture=$(uname -m)
+if [ "${CPU_architecture}" == "s390x" ];then
+ echo -e "\033[31mSorry, not support the s390x architecture for install. \nPlease use the x86_64 server architecture. \033[0m"
+ exit 1
+elif [ "${CPU_architecture}" == "aarch64" ];then
+ #CPU_architecture="-aarch64"
+ echo " ${CPU_architecture} architecture is not currently supported."
+ uname -a
+ exit 1
+elif [ "${CPU_architecture}" == "x86_64" ];then
+ # x86_64 is empty by default
+ CPU_architecture=""
+else
+ echo " ${CPU_architecture} architecture is not currently supported."
+ uname -a
+ exit 1
+fi
+
+is64bit=$(getconf LONG_BIT)
+if [ "${is64bit}" != '64' ];then
+ echo -e "\033[31m Sorry, BillionMail does not support 32-bit systems \033[0m"
+ exit 1
+fi
+
+
+if [ $(whoami) != "root" ];then
+ echo -e "Non-root install, please try the following solutions: \n 1.Please switch to root user install \n 2.Try executing the following install commands: \n sudo bash $0 $@"
+ exit 1
+fi
+
+while [ ${#} -gt 0 ]; do
+ case $1 in
+ -h|--help)
+ echo "Usage: [options]"
+ echo "Options:"
+ echo " -d, --domain Set Mail Server domain. eg: example.com"
+ echo " -t, --TZ Set Time Zone. eg: CST"
+ echo " Time Zone See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of timezones"
+ echo " Use a column named "TZ identifier" + note the column named "Notes""
+ echo "eg: bash install.sh --domain example.com --TZ CST"
+ exit 0
+ ;;
+ -d|--domain)
+ BILLIONMAIL_HOSTNAME=$2
+ shift 1
+ ;;
+ -t|--TZ)
+ BILLIONMAIL_TIME_ZONE=$2
+ shift 1
+ ;;
+ esac
+ shift 1
+done
+
+if [ -f "billionmail.conf" ]; then
+read -r -p "Check that the configuration file exists, will you continue to overwrite the file?? [y/N] " gogo
+case $gogo in
+ [Yy][eE][sS]|[Yy])
+ if [ ! -d "./backup/" ]; then
+ mkdir ./backup
+ fi
+ mv billionmail.conf ./backup/billionmail.conf_${time}
+ echo "Backup: billionmail.conf --> ./backup/billionmail.conf_${time}"
+ if [ -f ".env" ]; then
+ mv .env env_${time}
+ echo "Backup: .env --> ./backup/env_${time}"
+ fi
+ ;;
+ *)
+ exit 1
+ ;;
+esac
+fi
+
+while [ -z "${BILLIONMAIL_HOSTNAME}" ]; do
+echo "Press Enter to confirm the detected value '[value]', or enter a custom value."
+echo -e ""
+ echo -e "Mail Server hostname (FQDN), As: example.com"
+ echo -e ""
+ read -p "Please enter the Mail Server hostname (FQDN): " -e BILLIONMAIL_HOSTNAME
+ if [[ ! "${BILLIONMAIL_HOSTNAME}" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9](\.[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])*$ ]]; then
+ echo -e "\e[31m(${BILLIONMAIL_HOSTNAME}) is not a FQDN!\e[0m"
+ echo "Please change it to a FQDN"
+ exit 1
+ elif [[ "${BILLIONMAIL_HOSTNAME: -1}" == "." ]]; then
+ echo "(${BILLIONMAIL_HOSTNAME}) is ending with a dot. This is not a valid FQDN!"
+ exit 1
+
+ fi
+done
+
+if [ -a /etc/timezone ]; then
+ SYSTEM_TIME_ZONE=$(cat /etc/timezone)
+elif [ -a /etc/localtime ]; then
+ SYSTEM_TIME_ZONE=$(readlink /etc/localtime|sed -n 's|^.*zoneinfo/||p')
+fi
+
+while [ -z "${BILLIONMAIL_TIME_ZONE}" ]; do
+ echo -e ""
+ echo -e "See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of timezones"
+ echo -e "Use a column named "TZ identifier" + note the column named "Notes""
+ echo -e "Please enter your time zone"
+ echo -e ""
+ if [ -z "${SYSTEM_TIME_ZONE}" ]; then
+ read -p "Timezone: " -e BILLIONMAIL_TIME_ZONE
+ else
+ read -p "Timezone [${SYSTEM_TIME_ZONE}]: " -e BILLIONMAIL_TIME_ZONE
+ [ -z "${BILLIONMAIL_TIME_ZONE}" ] && BILLIONMAIL_TIME_ZONE=${SYSTEM_TIME_ZONE}
+ fi
+done
+
+DBPASS_file=DBPASS_file.pl
+if [ ! -s "${DBPASS_file}" ]; then
+ DBPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 32)
+ echo "${DBPASS}" > ${DBPASS_file}
+ chmod 600 ${DBPASS_file}
+else
+ DBPASS=$(cat ${DBPASS_file})
+fi
+
+
+GetSysInfo(){
+ if [ -s "/etc/redhat-release" ];then
+ SYS_VERSION=$(cat /etc/redhat-release)
+ elif [ -s "/etc/issue" ]; then
+ SYS_VERSION=$(cat /etc/issue)
+ fi
+ SYS_INFO=$(uname -a)
+ SYS_BIT=$(getconf LONG_BIT)
+ MEM_TOTAL=$(free -m|grep Mem|awk '{print $2}')
+ CPU_INFO=$(getconf _NPROCESSORS_ONLN)
+
+ echo -e ${SYS_VERSION}
+ echo -e Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO}
+ echo -e ${SYS_INFO}
+ echo -e "Please screenshot the above error message and post to the forum forum.aapanel.com for help"
+
+}
+
+
+Red_Error(){
+ echo '=================================================';
+ printf '\033[1;31;40m%b\033[0m\n' "$@";
+ GetSysInfo
+ exit 1;
+}
+
+
+
+PORT(){
+
+ if Command_Exists ss ; then
+ command_port="ss"
+
+ elif Command_Exists netstat ; then
+ command_port="netstat"
+ else
+ echo -e "Command does not exist and cannot check whether the port is used"
+ command_port=""
+ fi
+
+ if [[ ! -z $command_port ]]; then
+ echo "Checking if the port is used"
+ check_command=$($command_port -ltnp | grep -E ':(25|465|587|110|143|993|995)\s')
+
+ if [[ ! -z "$check_command" ]]; then
+ echo "$check_command"
+ echo -e "\033[31m Mail Server need use port 25 465 587 110 143 993 995. There are already services ports in the system, cannot be installed. \nRecommended use a new system. \033[0m"
+ exit 1
+ fi
+ fi
+}
+
+Check_Port(){
+ if ! Command_Exists docker; then
+ PORT
+ else
+ check=$(docker ps |grep -wE "${POSTFIX_CONTAINER_NAME}|${DOVECOT_CONTAINER_NAME}")
+ if [[ -z "$check" ]]; then
+ PORT
+ fi
+ fi
+}
+
+
+LXC_install_tips (){
+ # Check if it is in the lxc container
+ System_Info=$(hostnamectl)
+ check_container=$(echo "$System_Info" |grep "Chassis"|awk -F":" '{print $2}')
+ #echo $check_container
+ if [[ "$check_container" =~ "container" ]];then
+ echo -e "\033[33mInstalling in an LXC container,May not install properly. \nDocker may not be able to correctly obtain the number of CPU cores, \nwhich may cause the system to crash and cause high load when nginx is running. \nRecommended use VPS or physical machine for install.\033[0m"
+ echo -e ""
+ echo -e "\033[33mMust be turned on \"Unprivileged container\", \"nesting\". Otherwise the container cannot be started.\033[0m"
+ echo "Please confirm whether continue install?"
+ while [ "$lxc" != 'y' ] && [ "$lxc" != 'n' ]; do
+ read -p "Please confirm whether in LXC container continue install? (y/n): " lxc;
+ done
+
+ if [ "$lxc" == 'n' ];then
+ echo "Install canceled."
+ exit;
+ fi
+
+ LXC_install="yes"
+ fi
+}
+
+
+Get_Pack_Manager(){
+ if [ -f "/usr/bin/yum" ] && [ -d "/etc/yum.repos.d" ]; then
+ PM="yum"
+ elif [ -f "/usr/bin/apt-get" ] && [ -f "/usr/bin/dpkg" ]; then
+ PM="apt-get"
+ fi
+}
+
+
+Install_RPM_Pack(){
+ yumPacks="wget curl tar gzip git firewalld ca-certificates";
+ yum install -y ${yumPacks}
+
+ for yumPack in ${yumPacks}
+ do
+ rpmPack=$(rpm -q ${yumPack})
+ packCheck=$(echo ${rpmPack}|grep not)
+ if [ "${packCheck}" ]; then
+ yum install ${yumPack} -y
+ fi
+ done
+
+ setenforce 0
+ sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
+}
+
+Install_Deb_Pack(){
+ debPacks="wget curl tar gzip git lsb-release ufw ca-certificates";
+ apt-get update -y
+ DEBIAN_FRONTEND=noninteractive apt-get install -y $debPacks --allow-downgrades --allow-remove-essential --allow-change-held-packages
+
+ for debPack in ${debPacks}
+ do
+ packCheck=$(dpkg -l ${debPack})
+ if [ "$?" -ne "0" ] ;then
+ apt-get install -y $debPack
+ fi
+ done
+}
+
+Command_Exists() {
+ command -v "$@" >/dev/null 2>&1
+}
+
+Docker_Download_Url_Check() {
+ echo -e "Selecting download docker address source, please wait..."
+ ser_names=(download.docker.com mirrors.ustc.edu.cn/docker-ce mirrors.tuna.tsinghua.edu.cn/docker-ce mirrors.aliyun.com/docker-ce mirror.azure.cn/docker-ce)
+ tmp_file1=/dev/shm/net_test1.pl
+ tmp_file2=/dev/shm/net_test2.pl
+ [ -f "${tmp_file1}" ] && rm -f ${tmp_file1}
+ [ -f "${tmp_file2}" ] && rm -f ${tmp_file2}
+ touch $tmp_file1
+ touch $tmp_file2
+
+ for ser_name in ${ser_names[@]};
+ do
+ NODE_CHECK=$(curl -k -s 2>/dev/null --connect-timeout 5 -w "%{http_code} %{time_total}" https://${ser_name} -o c${ser_name}.txt|xargs)
+ rm -rf c${ser_name}.txt
+ NODE_STATUS=$(echo ${NODE_CHECK}|awk '{print $1}')
+ TIME_TOTAL=$(echo ${NODE_CHECK}|awk '{print $2 * 1000 - 500 }'|cut -d '.' -f 1)
+ if [ "${NODE_STATUS}" == "200" ] || [ "${NODE_STATUS}" == "301" ] || [ "${NODE_STATUS}" == "403" ];then
+ if [ $TIME_TOTAL -lt 100 ]; then
+ echo "$ser_name" >> $tmp_file1
+ elif [ $TIME_TOTAL -gt 1500 ] && [ $TIME_TOTAL -lt 2500 ]; then
+ echo "$ser_name" >> $tmp_file2
+ fi
+ fi
+ done
+ Docker_NODE_URL=$(cat $tmp_file1|head -n 1|awk '{print $1}')
+ if [ -z "$Docker_NODE_URL" ];then
+ Docker_NODE_URL=$(cat $tmp_file2|head -n 1|awk '{print $1}')
+ fi
+
+ rm -f $tmp_file1
+ rm -f $tmp_file2
+ mirror="$Docker_NODE_URL"
+ echo $mirror
+ case "$mirror" in
+ mirrors.aliyun.com/docker-ce)
+ Default_Download_Url="https://mirrors.aliyun.com/docker-ce"
+ mirror="Aliyun"
+ ;;
+ mirror.azure.cn/docker-ce)
+ Default_Download_Url="https://mirror.azure.cn/docker-ce"
+ mirror="AzureChinaCloud"
+ ;;
+ mirrors.ustc.edu.cn/docker-ce)
+ Default_Download_Url="https://mirrors.ustc.edu.cn/docker-ce"
+ mirror="USTC"
+ ;;
+ mirrors.tuna.tsinghua.edu.cn/docker-ce)
+ Default_Download_Url="https://mirrors.tuna.tsinghua.edu.cn/docker-ce"
+ mirror="tsinghua"
+ ;;
+ *)
+ Default_Download_Url="https://download.docker.com"
+ mirror=""
+ ;;
+ esac
+
+ DEFAULT_REPO_FILE="docker-ce.repo"
+
+ if [ -z "$REPO_FILE" ]; then
+ REPO_FILE="$DEFAULT_REPO_FILE"
+ fi
+}
+
+Get_Distribution() {
+ lsb_dist=""
+ lsb_name=""
+
+ if [ -r /etc/os-release ]; then
+ lsb_dist="$(. /etc/os-release && echo "$ID")"
+ lsb_name="$(. /etc/os-release && echo "$NAME")"
+ fi
+ echo "$lsb_dist $lsb_name"
+}
+
+
+Bored_waiting(){
+ w_time="$wait_time"
+ msg="$wait_msg"
+ progress="."
+ for ((i=0; i<${w_time}; i++))
+ do
+ printf "$msg %-10s %d\r" "$progress" "$((i+1))"
+ sleep 1
+
+ if [ "$progress" == ".........." ]; then
+ progress="."
+ else
+ progress+="."
+ fi
+ done
+ printf "$msg %-10s %d\r" ".........." "$w_time"
+ #echo ""
+}
+
+Docker_Start() {
+ if Command_Exists docker || [ -f /lib/systemd/system/docker.service ]; then
+ if Command_Exists systemctl; then
+ # systemctl mask [email protected]
+ systemctl enable docker
+ systemctl reset-failed docker.service
+ systemctl start docker.service
+ if [ "$?" != "0" ];then
+ systemctl reset-failed docker.service
+ systemctl restart docker.service
+ if [ "$?" != "0" ];then
+ docker_status=$(systemctl status docker.service)
+ echo "$docker_status"
+ if [ -f /etc/docker/daemon.json ]; then
+ echo "/etc/docker/daemon.json file content:"
+ cat /etc/docker/daemon.json
+ echo -e "\033[33mRecommended check the above /etc/docker/daemon.json Are the file contents correct?\033[0m"
+ fi
+ # Wait for 100 seconds of animation
+ echo -e "\033[31m start docker service failed, maybe too fast to start\033[0m"
+ wait_msg="waiting 100 seconds to start docker service"
+ wait_time="100"
+ Bored_waiting
+ systemctl reset-failed docker.service
+ systemctl restart docker.service
+ if [ "$?" != "0" ];then
+ docker_status=$(systemctl status docker.service)
+ echo "$docker_status"
+ Red_Error "docker start failed" "Please try again later execute the restart docker command: systemctl restart docker.service (no content returns normal)" "Finally, re-execute install BillionMail"
+ fi
+ fi
+ fi
+ else
+ chkconfig --add docker
+ chkconfig --level 2345 docker on
+ service docker start
+ if [ "$?" != "0" ];then
+ service docker.service status
+ cat /etc/docker/daemon.json
+ Red_Error "docker start failed"
+ fi
+ fi
+ else
+
+ Red_Error "Docker is not installed"
+
+
+
+ fi
+}
+
+
+Is_Darwin() {
+ case "$(uname -s)" in
+ *darwin*) true ;;
+ *Darwin*) true ;;
+ *) false ;;
+ esac
+}
+
+Check_Forked() {
+ if Command_Exists lsb_release; then
+ set +e
+ lsb_release -a -u >/dev/null 2>&1
+ lsb_release_exit_code=$?
+
+ if [ "$lsb_release_exit_code" = "0" ]; then
+ cat <<-EOF
+You're using '$lsb_dist' version '$dist_version'.
+EOF
+ lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')
+ dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')
+ cat <<-EOF
+Upstream release is '$lsb_dist' version '$dist_version'.
+EOF
+ else
+ if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then
+ if [ "$lsb_dist" = "osmc" ]; then
+ lsb_dist=raspbian
+ else
+ lsb_dist=debian
+ fi
+ dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
+ case "$dist_version" in
+ 12)
+ dist_version="bookworm"
+ ;;
+ 11)
+ dist_version="bullseye"
+ ;;
+ 10)
+ dist_version="buster"
+ ;;
+ 9)
+ dist_version="stretch"
+ ;;
+ 8)
+ dist_version="jessie"
+ ;;
+ esac
+ fi
+ fi
+ fi
+}
+
+
+Docker_Check(){
+
+ # Default value is: 0 Not installed
+ is_docker="0"
+ docker_version="docker version"
+ if Command_Exists $docker_version ; then
+ is_docker="1"
+ fi
+ echo "docker command: $is_docker"
+
+}
+
+create_docker_yum_repo() {
+ cat <<EOF >/etc/yum.repos.d/docker-ce.repo
+[docker-ce-stable]
+name=Docker CE Stable - \$basearch
+baseurl=https://download.docker.com/linux/centos/\$releasever/\$basearch/stable
+enabled=1
+gpgcheck=1
+gpgkey=https://download.docker.com/linux/centos/gpg
+
+EOF
+}
+
+
+Docker_Install() {
+ lsb_dist=$(Get_Distribution|awk -F " " '{print $1}')
+ lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
+
+ case "$lsb_dist" in
+ ubuntu)
+ if Command_Exists lsb_release; then
+ dist_version="$(lsb_release --codename | cut -f2)"
+ fi
+ if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
+ dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
+ fi
+ ;;
+ debian | raspbian)
+ dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
+ case "$dist_version" in
+ 12)
+ dist_version="bookworm"
+ ;;
+ 11)
+ dist_version="bullseye"
+ ;;
+ 10)
+ dist_version="buster"
+ ;;
+ 9)
+ dist_version="stretch"
+ ;;
+ 8)
+ dist_version="jessie"
+ ;;
+ esac
+ ;;
+ centos | rhel | sles | ol | tencentos | alinux | anolis | rocky | euleros | almalinux | opencloudos |openeuler |hce | kylin |uos | kylinsecos |amzn )
+ if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
+ dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
+ fi
+ ;;
+ *)
+ if Command_Exists lsb_release; then
+ dist_version="$(lsb_release --release | cut -f2)"
+ fi
+ if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
+ dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
+ fi
+ ;;
+ esac
+
+ Check_Forked
+
+ case "$lsb_dist" in
+ ubuntu | debian | raspbian)
+ docker_gpg="/usr/share/keyrings/docker-archive-keyring.gpg"
+ apt_repo_file="/etc/apt/sources.list.d/docker.list"
+ pre_reqs="apt-transport-https ca-certificates curl wget"
+
+ if ! command -v gpg >/dev/null; then
+ pre_reqs="$pre_reqs gnupg"
+ fi
+
+ apt_repo="deb [arch=$(dpkg --print-architecture) signed-by=$docker_gpg] $Default_Download_Url/linux/$lsb_dist $dist_version stable"
+ (
+ DEBIAN_FRONTEND=noninteractive apt-get install -y $pre_reqs
+ if [ -f $docker_gpg ] && [ -f $apt_repo_file ]; then
+ rm -rf $docker_gpg
+ rm -rf $apt_repo_file
+ fi
+
+ #curl -fsSL --connect-time 10 --retry 5 $Default_Download_Url/linux/$lsb_dist/gpg | gpg --dearmor --yes -o $docker_gpg
+ #wget --no-check-certificate -qO - -t 5 -T 20 $Default_Download_Url/linux/$lsb_dist/gpg | gpg --dearmor --yes -o $docker_gpg
+ wget -qO - -t 5 -T 10 $Default_Download_Url/linux/$lsb_dist/gpg | gpg --dearmor --yes -o $docker_gpg
+ chmod a+r $docker_gpg
+
+ echo "$apt_repo" > $apt_repo_file
+ apt-get update -y
+ )
+ pkg_version=""
+
+ #First check whether apt-get is used. It cannot be put into the subshell, that is, () to execute, otherwise it will not exit.
+ # Check_apt_status
+
+ (
+ pkgs="$pkgs docker-ce${pkg_version%=}"
+ DEBIAN_FRONTEND=noninteractive apt-get install -y $pkgs docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
+ )
+ ;;
+ centos | fedora | rhel | ol | tencentos | alinux | anolis | rocky | almalinux | opencloudos |openeuler |hce |uos |amzn )
+ pkg_version=""
+
+ yum_repo="$Default_Download_Url/linux/$lsb_dist/$REPO_FILE"
+ if [ "$lsb_dist" == "ol" ] || [ "$lsb_dist" == "tencentos" ] || [ "$lsb_dist" == "alinux" ] || [ "$lsb_dist" == "anolis" ] || [ "$lsb_dist" == "opencloudos" ] || [ "$lsb_dist" == "openeuler" ] || [ "$lsb_dist" == "hce" ] || [ "$lsb_dist" == "uos" ] || [ "$lsb_dist" == "amzn" ] ; then
+ yum_repo="$Default_Download_Url/linux/centos/$REPO_FILE"
+ fi
+ if [ "$lsb_dist" == "rocky" ] || [ "$lsb_dist" == "almalinux" ]; then
+ yum_repo="$Default_Download_Url/linux/centos/$REPO_FILE"
+ fi
+ if [ "$lsb_dist" = "fedora" ]; then
+ pkg_manager="dnf"
+ config_manager="dnf config-manager"
+ enable_channel_flag="--set-enabled"
+ disable_channel_flag="--set-disabled"
+ pre_reqs="dnf-plugins-core"
+ pkg_suffix="fc$dist_version"
+ else
+ pkg_manager="yum"
+ config_manager="yum-config-manager"
+ enable_channel_flag="--enable"
+ disable_channel_flag="--disable"
+ pre_reqs="yum-utils"
+ pkg_suffix="el"
+ fi
+
+ #wget --no-check-certificate -O /etc/yum.repos.d/docker-ce.repo $yum_repo -t 5 -T 10
+ wget -O /etc/yum.repos.d/docker-ce.repo $yum_repo -t 5 -T 10
+ if [ $? -ne "0" ]; then
+ create_docker_yum_repo
+ fi
+
+ if ! grep -q "docker" /etc/yum.repos.d/docker-ce.repo; then
+ create_docker_yum_repo
+ fi
+
+ sed -i "s|https://download.docker.com|$Default_Download_Url|g" /etc/yum.repos.d/docker-ce.repo
+ # cat /etc/yum.repos.d/docker-ce.repo
+
+ lsb_name=$(Get_Distribution|awk -F " " '{print $3}')
+ echo $lsb_name
+ echo $lsb_dist
+ #if [ "$lsb_name" = "Stream" ] || [ "$lsb_dist" = "alinux" ] || [ "$lsb_dist" = "anolis" ];then
+ #if [ "$lsb_name" = "Stream" ] || [ "$lsb_dist" = "anolis" ];then
+ if [ "$lsb_name" = "Stream" ]; then
+ conflicting="--allowerasing"
+ fi
+ if [ "$lsb_name" = "rocky" ] || [ "$lsb_dist" = "euleros" ] || [ "$lsb_dist" = "almalinux" ];then
+ conflicting="--allowerasing"
+ fi
+
+ if [ "$lsb_dist" = "openeuler" ];then
+ openeuler_v=$(cat /etc/os-release |grep "VERSION=")
+ if [[ $openeuler_v =~ "23.0" ]]; then
+
+ sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
+ $pkg_manager makecache
+
+ elif [[ $openeuler_v =~ "22.0" ]]; then
+ sed -i "s|\$releasever|7|g" /etc/yum.repos.d/docker-ce.repo
+ $pkg_manager makecache
+ else
+ if [ -f "/etc/os-release" ]; then
+ cat /etc/os-release
+ fi
+ echo "ERROR: not support this system yum auto install docker"
+ fi
+ fi
+
+ # Amazon Linux
+ if [ "$lsb_dist" = "amzn" ];then
+ #amzn_v=$(. /etc/os-release && echo "$VERSION_ID")
+
+ sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
+ $pkg_manager makecache
+ fi
+
+ # Huawei Cloud EulerOS
+ if [ "$lsb_dist" = "hce" ];then
+ hce_v=$(. /etc/os-release && echo "$VERSION_ID")
+ if [[ $hce_v =~ "2.0" ]]; then
+ sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
+ $pkg_manager makecache
+ else
+ if [ -f "/etc/os-release" ]; then
+ cat /etc/os-release
+ fi
+ echo "ERROR: not support this system yum auto install docker"
+ fi
+ fi
+
+ # OpenCloudOS 9.0
+ if [ "$lsb_dist" = "opencloudos" ];then
+ pkg_manager="yum"
+ opencloudos_v=$(. /etc/os-release && echo "$VERSION_ID")
+ if [[ $opencloudos_v =~ "9.0" ]]; then
+
+ sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
+ # centos 8
+ download_container_selinux="$download_Url/cloudwaf/package/container-selinux-2.224.0-1.module_el8+712+4cd1bd69.noarch.rpm"
+ wget --no-check-certificate -O container-selinux-2.224.0-1.module_el8+712+4cd1bd69.noarch.rpm ${download_container_selinux} -t 5 -T 10
+
+ install_docker="1"
+ $pkg_manager makecache
+
+ $pkg_manager install -y docker-ce$pkg_version docker-ce-cli docker-buildx-plugin docker-compose-plugin container-selinux-2.224.0-1.module_el8+712+4cd1bd69.noarch.rpm
+
+ rm -f container-selinux-2.224.0-1.module_el8+712+4cd1bd69.noarch.rpm
+
+ fi
+ fi
+
+ if [ "$lsb_dist" = "uos" ];then
+ pkg_manager="yum"
+ uos_v=$(. /etc/os-release && echo "$VERSION_ID")
+ uos_NAME=$(. /etc/os-release && echo "$NAME")
+ if [[ $uos_v =~ "20" ]] && [[ "$uos_NAME" == "UOS Server Euler" ]]; then
+ # UOS Server Euler 20 Install using the default source
+ if [ -f /etc/yum.repos.d/docker-ce.repo ]; then
+ rm -f /etc/yum.repos.d/docker-ce.repo
+ fi
+ # Define to install docker using other commands
+ install_docker="1"
+ $pkg_manager makecache
+
+ $pkg_manager install -y docker* --skip-broken
+
+ elif [[ $uos_v =~ "20" ]]; then
+ sed -i "s|\$releasever|8|g" /etc/yum.repos.d/docker-ce.repo
+
+ # Define to install docker using other commands
+ install_docker="1"
+
+ $pkg_manager makecache
+
+ $pkg_manager install -y docker-ce$pkg_version docker-ce-cli docker-buildx-plugin docker-compose-plugin
+
+
+ else
+ if [ -f "/etc/os-release" ]; then
+ cat /etc/os-release
+ fi
+ echo "ERROR: not support this system yum auto install docker"
+ fi
+ fi
+
+ if [[ "$install_docker" != "1" ]]; then
+ # 1 When docker is installed using other commands
+ $pkg_manager makecache
+
+ $pkg_manager install -y docker-ce$pkg_version docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin $conflicting
+
+ fi
+ ;;
+
+ *)
+ if [ -z "$lsb_dist" ]; then
+ if Is_Darwin; then
+ echo
+ echo "ERROR: Unsupported operating system 'macOS'"
+ echo
+ exit 1
+ fi
+ fi
+ echo
+ Red_Error "ERROR: not support '$lsb_dist' this system auto install docker"
+ ;;
+ esac
+
+ if ! Command_Exists docker && [ ! -f /usr/bin/docker ]; then
+ echo "Trying to install docker using binary package method."
+
+ Binary_package_install_docker
+
+ fi
+
+ if ! Command_Exists docker ; then
+ Red_Error "docker command not exists,install docker failed,please check the reason."
+ fi
+}
+
+
+Binary_package_install_docker(){
+# Install docker in binary package
+ DOCKER_VERSION="27.3.1"
+ SYS_TYPE=$(uname -m)
+
+ echo "Create docker group"
+ groupadd docker
+
+ echo "Downloading docker ${DOCKER_VERSION}.tgz file, please wait..."
+ wget --no-check-certificate -O docker-${DOCKER_VERSION}.tgz ${download_Url}/src/docker-${DOCKER_VERSION}-${SYS_TYPE}.tgz -t 5 -T 10
+
+ tmp_size=$(du -b docker-${DOCKER_VERSION}.tgz |awk '{print $1}')
+ if [ $tmp_size -lt 60831072 ];then
+ ls -l docker-${DOCKER_VERSION}.tgz
+ Red_Error "ERROR: Failed to download, please try install again!"
+ fi
+
+ echo "Unzip the docker ${DOCKER_VERSION}.tgz file, please wait..."
+ tar -xvf docker-${DOCKER_VERSION}.tgz
+ \cp docker/* /usr/bin/
+
+ # rm -rf docker
+ rm -f docker-${DOCKER_VERSION}.tgz
+
+ wget --no-check-certificate -O /usr/bin/docker-compose ${download_Url}/src/docker-compose-linux-${SYS_TYPE} -t 5 -T 20
+ chmod +x /usr/bin/docker-compose
+
+ wget --no-check-certificate -O /usr/lib/systemd/system/docker.service ${download_Url}/init/systemd/docker.service -t 5 -T 20
+ wget --no-check-certificate -O /usr/lib/systemd/system/docker.socket ${download_Url}/init/systemd/docker.socket -t 5 -T 20
+ wget --no-check-certificate -O /usr/lib/systemd/system/containerd.service ${download_Url}/init/systemd/containerd.service -t 5 -T 20
+
+ systemctl enable docker.service
+ systemctl enable docker.socket
+ systemctl enable containerd.service
+
+ systemctl start containerd.service
+ systemctl start docker.socket
+ systemctl start docker.service
+
+}
+
+Docker_Compose_Check(){
+
+ is_docker_compose="0"
+ if Command_Exists docker-compose; then
+ is_docker_compose="1"
+ DOCKER_COMPOSE="docker-compose"
+ else
+ if Command_Exists docker; then
+ Docker_compose="docker compose version"
+ if $Docker_compose; then
+ is_docker_compose="1"
+ DOCKER_COMPOSE="docker compose"
+ fi
+ else
+ is_docker_compose="0"
+ fi
+
+ fi
+}
+
+Docker_Compose_Install() {
+
+ if [ $is_docker_compose == "0" ]; then
+ Docker_Install
+ fi
+
+ Compose_Download_Url="$download_Url/install/src/docker-compose-$(uname -s)-$(uname -m)"
+ Compose_Path="/usr/local/bin/docker-compose"
+ New_Compose_Path="/usr/libexec/docker/cli-plugins/docker-compose"
+ Compose_lin="/usr/bin/docker-compose"
+
+ if [ ! -f $New_Compose_Path ]; then
+ wget --no-check-certificate -t 5 -T 20 -O $New_Compose_Path $Compose_Download_Url
+ chmod +x $New_Compose_Path
+ rm -rf $Compose_lin
+ fi
+
+ if [ ! -f ${Compose_lin} ];then
+ ln -s $New_Compose_Path $Compose_lin
+ fi
+}
+
+
+Set_Firewall() {
+ sshPort=$(cat /etc/ssh/sshd_config | grep 'Port ' | awk '{print $2}')
+ if [ "${PM}" = "apt-get" ]; then
+ if [ ! -f "/usr/bin/ufw" ] && [ ! -f "/bin/ufw" ] && ! Command_Exists "ufw"; then
+ apt-get install -y ufw
+ fi
+ if [ -f "/usr/sbin/ufw" ]; then
+ ufw allow 20/tcp >/dev/null 2>&1
+ ufw allow 21/tcp >/dev/null 2>&1
+ ufw allow 22/tcp >/dev/null 2>&1
+ ufw allow 80/tcp >/dev/null 2>&1
+ ufw allow 443/tcp >/dev/null 2>&1
+ ufw allow 888/tcp >/dev/null 2>&1
+ ufw allow 39000:40000/tcp >/dev/null 2>&1
+ ufw allow ${SMTP_PORT}/tcp >/dev/null 2>&1
+ ufw allow ${SMTPS_PORT}/tcp >/dev/null 2>&1
+ ufw allow ${SUBMISSION_PORT}/tcp >/dev/null 2>&1
+ ufw allow ${IMAP_PORT}/tcp >/dev/null 2>&1
+ ufw allow ${IMAPS_PORT}/tcp >/dev/null 2>&1
+ ufw allow ${POP_PORT}/tcp >/dev/null 2>&1
+ ufw allow ${POPS_PORT}/tcp >/dev/null 2>&1
+ ufw allow ${sshPort}/tcp >/dev/null 2>&1
+ ufw_status=$(ufw status)
+ echo y | ufw enable
+ ufw default deny
+ ufw reload
+ fi
+ else
+ if [ -f "/etc/init.d/iptables" ]; then
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${SMTP_PORT} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${SMTPS_PORT} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${SUBMISSION_PORT} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${IMAP_PORT} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${IMAPS_PORT} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${POP_PORT} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${POPS_PORT} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${sshPort} -j ACCEPT
+ iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
+ #iptables -I INPUT -p tcp -m state --state NEW -m udp --dport 39000:40000 -j ACCEPT
+ iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
+ iptables -A INPUT -s localhost -d localhost -j ACCEPT
+ iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
+ iptables -P INPUT DROP
+ service iptables save
+ sed -i "s#IPTABLES_MODULES=\"\"#IPTABLES_MODULES=\"ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp\"#" /etc/sysconfig/iptables-config
+ iptables_status=$(service iptables status | grep 'not running')
+ if [ "${iptables_status}" == '' ]; then
+ service iptables restart
+ fi
+ else
+ AliyunCheck=$(cat /etc/redhat-release | grep "Aliyun Linux")
+ [ "${AliyunCheck}" ] && return
+ if [ ! -f "/usr/bin/firewall-cmd" ] && [ ! -f "/bin/firewall-cmd" ] && ! Command_Exists "firewall-cmd"; then
+ yum install firewalld -y
+ fi
+ [ "${Centos8Check}" ] && yum reinstall python3-six -y
+ systemctl enable firewalld
+ systemctl start firewalld
+ firewall-cmd --set-default-zone=public >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=20/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=21/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=22/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=80/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=443/tcp > /dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${SMTP_PORT}/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${SMTPS_PORT}/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${SUBMISSION_PORT}/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${IMAP_PORT}/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${IMAPS_PORT}/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${POP_PORT}/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${POPS_PORT}/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=${sshPort}/tcp >/dev/null 2>&1
+ firewall-cmd --permanent --zone=public --add-port=39000-40000/tcp >/dev/null 2>&1
+ #firewall-cmd --permanent --zone=public --add-port=39000-40000/udp > /dev/null 2>&1
+ firewall-cmd --reload
+ fi
+ fi
+}
+
+
+Check_apt_status(){
+
+ MAX_RETRIES=30
+ retries=0
+
+ while [ $retries -lt $MAX_RETRIES ]; do
+ output=$(ps aux| grep -E '(apt|apt-get)\s' 2>&1)
+ check_output=$(echo "$output" | grep -E '(apt|apt-get)\s')
+
+ # If check_output is empty, terminate the loop
+ if [ -z "$check_output" ]; then
+ break
+ fi
+
+ retries=$((retries + 1))
+
+ echo "apt-get is in use, it will automatically exit after ${retries}/${MAX_RETRIES} times, try again after 10 seconds..."
+ echo "$check_output"
+ wait_msg="Please wait "
+ wait_time="10"
+ Bored_waiting
+
+ done
+
+ if [ $retries -ge $MAX_RETRIES ]; then
+ echo "$output" > /tmp/waf_install_log.txt
+ Red_Error "ERROR: apt-get command exceeds the maximum wait times: ${MAX_RETRIES}. Do not use the apt/apt-get command or install software during installation, please try to reinstall!"
+ fi
+
+}
+
+
+Check_Connect_PgSql(){
+
+ MAX_RETRIES=10
+ retries=0
+
+ while [ $retries -lt $MAX_RETRIES ]; do
+ output=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT 1;" 2>&1)
+ if [ $? -eq 0 ]; then
+ PgSql_run="1"
+ break
+ # When equal to 0, exit the loop
+ fi
+
+ retries=$((retries + 1))
+
+ echo "PgSql failed to connect, try again after 10 seconds, ${retries}/${MAX_RETRIES}..."
+
+ if [[ "${retries}" == "1" ]] || [[ "${retries}" == "${MAX_RETRIES}" ]]; then
+ # Only the first and last print information
+ echo "$connect_PgSql"
+ fi
+ wait_msg="Please wait.."
+ wait_time="10"
+ Bored_waiting
+
+ done
+
+ if [ $retries -ge $MAX_RETRIES ]; then
+ Red_Error "ERROR: The maximum number of retrys exceeded, and the connection to PgSql cannot be connected. Please try reinstalling!"
+ fi
+
+}
+
+Init_Billionmail()
+{
+ # SQL file path
+ SQL_FILE="./init.sql"
+ if [ ! -f "${SQL_FILE}" ]; then
+ Red_Error "SQL The file does not exist: ${SQL_FILE}"
+ fi
+
+ if docker ps --format '{{.Names}}' | grep -q "^${PGSQL_CONTAINER_NAME}$"; then
+
+ # Test whether it is possible to connect
+ Check_Connect_PgSql
+
+ echo "Importing database..."
+ docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} < ${SQL_FILE}
+ if [ $? -eq 0 ]; then
+ echo "Database import was successful!"
+ else
+ Red_Error "Database import failed!"
+ fi
+ echo "Creating domain..."
+ BILLIONMAIL_HOSTNAME=$(echo "${BILLIONMAIL_HOSTNAME}" | tr '[:upper:]' '[:lower:]')
+ Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
+ if [ -z "${Check_domain}" ]; then
+ # Create a domain
+ docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "INSERT INTO domain (domain, a_record, mailboxes, mailbox_quota, quota, rate_limit, create_time, active)
+ VALUES ('${BILLIONMAIL_HOSTNAME}', 'mail.${BILLIONMAIL_HOSTNAME}', 500, 5368709120, 5368709120, 12, ${create_time}, 1);"
+ if [ $? -eq 0 ]; then
+ echo "Domain creation was successful!"
+ else
+ Red_Error "Domain creation failed!"
+ fi
+ else
+ echo ""${Check_domain}" Domain already exists!"
+ fi
+
+ # Create a mailbox
+ if [ -z "${mailbox}" ]; then
+ mailbox=$(LC_ALL=C </dev/urandom tr -dc a-z0-9 2> /dev/null | head -c 6)
+ echo "Generate mailbox: ${mailbox}"
+ else
+ mailbox=$(echo "${mailbox}" | tr '[:upper:]' '[:lower:]')
+ fi
+ Generate_mailbox_password=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 16)
+ #echo "Generate_mailbox_password: ${Generate_mailbox_password}"
+ Encrypt_mailbox_password=$(docker exec -i ${DOVECOT_CONTAINER_NAME} doveadm pw -s MD5-CRYPT -p "${Generate_mailbox_password}" | sed 's/{MD5-CRYPT}//')
+ if [ $? -eq 0 ]; then
+ echo "Generate_mailbox_password: ${Generate_mailbox_password}"
+ echo "mailbox_password: ${Encrypt_mailbox_password}"
+ else
+ # Generate the default password after failure: BILLIONMAIL
+ Generate_mailbox_password="BILLIONMAIL"
+ Encrypt_mailbox_password='$1$ELBUCcYE$TbdGKBvLkFbjQguDbi3s01'
+ echo "Generate_mailbox_password--default: ${Generate_mailbox_password}"
+ Default_password=1
+ fi
+
+ if [ "${Default_password}" != 1 ]; then
+ # password_encode
+ # Base64 encoding of strings
+ b64_data=$(echo -n "${Generate_mailbox_password}" | base64)
+ # Convert characters to hexadecimal
+ password_encode=$(echo -n "${b64_data}" | while IFS= read -r -n1 char; do printf "%02x" "'$char"; done)
+ echo "password_encode: ${password_encode}"
+ if [ -z ${password_encode} ]; then
+ b64_data=$(echo -n "${Generate_mailbox_password}" | base64)
+ password_encode=$(echo -n "${b64_data}" | od -A n -t x1 | tr -d ' \n')
+ echo "password_encode: ${password_encode}"
+ fi
+ else
+ password_encode="516b6c4d54456c50546b31425355773d"
+ fi
+
+ Check_mailbox=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';" | grep -w "${mailbox}@${BILLIONMAIL_HOSTNAME}")
+ if [ -z "${Check_mailbox}" ]; then
+ INSERT_mailbox='INSERT INTO mailbox (username, password, password_encode, full_name, is_admin, maildir, quota, local_part, domain, create_time, update_time, active)
+ VALUES (
+ '\'${mailbox}@${BILLIONMAIL_HOSTNAME}\'',
+ '\'${Encrypt_mailbox_password}\'',
+ '\'${password_encode}\'',
+ '\'${mailbox}\'',
+ 0,
+ '\'${mailbox}@${BILLIONMAIL_HOSTNAME}/\'',
+ 5368709120,
+ '\'${mailbox}\'',
+ '\'${BILLIONMAIL_HOSTNAME}\'',
+ '${create_time}',
+ '${create_time}',
+ 1
+ );'
+ echo "$INSERT_mailbox"
+ docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "$INSERT_mailbox"
+ if [ $? -eq 0 ]; then
+ echo "Mailbox creation was successful!"
+ else
+ Red_Error "Mailbox creation failed!"
+ fi
+ #docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';"
+ else
+ echo ""${Check_mailbox}" Mailbox already exists!"
+ fi
+
+ else
+ Red_Error "PgSql container does not exist!"
+ fi
+
+}
+
+Billionmail(){
+ cat << EOF > billionmail.conf
+
+# BILLIONMAIL_HOSTNAME configuration
+BILLIONMAIL_HOSTNAME=${BILLIONMAIL_HOSTNAME}
+
+# SQL NAME and USER and PASSWORD configuration
+
+DBNAME=${DBNAME}
+DBUSER=${DBUSER}
+
+# Generate random passwords
+DBPASS=${DBPASS}
+
+# REDIS PASSWORD configuration
+
+REDISPASS=${REDISPASS}
+
+
+## MAIL Ports
+SMTP_PORT=${SMTP_PORT}
+SMTPS_PORT=${SMTPS_PORT}
+SUBMISSION_PORT=${SUBMISSION_PORT}
+IMAP_PORT=${IMAP_PORT}
+IMAPS_PORT=${IMAPS_PORT}
+POP_PORT=${POP_PORT}
+POPS_PORT=${POPS_PORT}
+REDIS_PORT=${SMTP_REDIS_PORTPORT}
+SQL_PORT=${SQL_PORT}
+
+
+# You can use this script to set the time zone for your container.
+# See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of timezones"
+# echo -e "Use a column named "TZ identifier" + note the column named "Notes""
+
+TZ=${BILLIONMAIL_TIME_ZONE}
+
+
+EOF
+ \cp -rf billionmail.conf .env
+ if [ ! -f ".env" ]; then
+ echo -e "Error: Failed to create .env file"
+ exit 1
+ fi
+
+ SSL_path=ssl-self-signed
+ if [ ! -d "ssl-self-signed" ]; then
+ mkdir ssl-self-signed
+ fi
+ openssl genrsa -out ${SSL_path}/key.pem 2048
+ openssl req -x509 -new -nodes -key ${SSL_path}/key.pem -sha256 -days 3650 -out ${SSL_path}/cert.pem \
+ -subj "/C=US/ST=State/L=City/O=${BILLIONMAIL_HOSTNAME}/OU=${BILLIONMAIL_HOSTNAME}/CN=*.${BILLIONMAIL_HOSTNAME}" -nodes
+ cp -d -n ${SSL_path}/* ssl/
+
+ echo -e "Execute ${DOCKER_COMPOSE} up -d"
+ if [ ! -s "docker-compose.yml" ]; then
+ ls -al
+ Red_Error "docker-compose.yml not found."
+ fi
+ ${DOCKER_COMPOSE} up -d
+ if [ $? -eq 0 ]; then
+ echo -e "Billionmail installation completed successfully!"
+ else
+ Red_Error "Billionmail installation failed, please try reinstalling!"
+ fi
+
+ echo -e "Initialize the data..."
+ sleep 5
+ Init_Billionmail
+
+}
+
+
+Install_Main(){
+ Check_Port
+ LXC_install_tips
+
+ Get_Pack_Manager
+ if [ "$PM" == "yum" ]; then
+ Install_RPM_Pack
+ else
+ Install_Deb_Pack
+ fi
+
+ set +e
+ Docker_Check
+ Docker_Compose_Check
+
+ if [ "$is_docker" != "1" ]; then
+ Docker_Download_Url_Check
+ Docker_Install
+ Docker_Compose_Check
+ fi
+
+ if [ "$is_docker_compose" != "1" ]; then
+ Docker_Compose_Install
+ Docker_Compose_Check
+ if [ "$is_docker_compose" != "1" ]; then
+ Red_Error "ERROR: Docker Compose installation failed, Please reinstall Docker Compose!"
+ fi
+ fi
+
+ Docker_Start
+
+ Billionmail
+
+ Set_Firewall
+
+}
+
+
+Install_Main
+
+IPV4_ADDRESS=$(curl -sS -4 --connect-timeout 10 -m 20 https://ifconfig.me)
+if [ -z "${IPV4_ADDRESS}" ]; then
+ IPV4_ADDRESS=$(curl -sSk --connect-timeout 10 -m 20 https://www.aapanel.com/api/common/getClientIP)
+fi
+ipv4_regex="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
+if [[ ${IPV4_ADDRESS} =~ ${ipv4_regex} ]]; then
+ echo "${IPV4_ADDRESS}" >/dev/null 2>&1
+elif [ -z "${IPV4_ADDRESS}" ]; then
+ IPV4_ADDRESS="YOUR_SERVER_IPV4_ADDRESS"
+fi
+echo -e ""
+echo -e "\e[31mPlease add the following record to your domain name\e[0m"
+echo -e "==========================================================="
+echo -e " Type | Host record | IPv4 address |"
+echo -e " A | mail.${BILLIONMAIL_HOSTNAME} | ${IPV4_ADDRESS} |"
+echo -e "==========================================================="
+echo -e " Type | Host record | Record value | MX priority"
+echo -e " MX | @ | mail.${BILLIONMAIL_HOSTNAME} | 10"
+echo -e "==========================================================="
+
+echo -e "\e[31mPlease save the following information:\e[0m"
+echo -e "Mailbox (e-mail): \e[33m${mailbox}@${BILLIONMAIL_HOSTNAME}\e[0m \nPassword: \e[33m${Generate_mailbox_password}\e[0m"
+
+echo -e "Tip: Use \e[33mbash mail_users.sh\e[0m to add and delete Domain and Mailboxes"
diff --git a/mail_users.sh b/mail_users.sh
new file mode 100644
index 00000000..facf1482
--- /dev/null
+++ b/mail_users.sh
@@ -0,0 +1,278 @@
+#!/bin/bash
+PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
+export PATH
+
+# Add domain name and email
+
+CONTAINER_PROJECT_NAME=billionmail
+PGSQL_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-pgsql-billionmail-1"
+DOVECOT_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-dovecot-billionmail-1"
+create_time=$(date +%s)
+time=$(date +%Y_%m_%d_%H_%M_%S)
+
+
+if [ $(whoami) != "root" ];then
+ echo -e "Non-root install, please try the following solutions: \n 1.Please switch to root user install \n 2.Try executing the following install commands: \n sudo bash $0 $@"
+ exit 1
+fi
+
+if [ ! -s ".env" ]; then
+ ls -al
+ echo " The .env file does not exist. Cannot continue operation, please operate in the project directory"
+ exit 1
+fi
+. .env
+if [ -z "${DBUSER}" ] || [ -z "${DBNAME}" ] || [ -z "${DBPASS}" ]; then
+ echo "The obtained .env configuration exception is empty."
+ exit 1
+fi
+
+Red_Error(){
+ echo '=================================================';
+ printf '\033[1;31;40m%b\033[0m\n' "$@";
+ # GetSysInfo
+ exit 1;
+}
+
+Init_Email() {
+ input="$2"
+
+ # Regular expression verification email address format
+ if [[ "$input" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]]; then
+ mailbox=$(echo "$input" | cut -d '@' -f 1 | tr '[:upper:]' '[:lower:]')
+ BILLIONMAIL_HOSTNAME=$(echo "$input" | cut -d '@' -f 2 | tr '[:upper:]' '[:lower:]')
+
+ else
+ echo "Enter an email address that is not a legal one: $input"
+ echo "Example: [email protected]"
+ exit 1
+ fi
+}
+
+
+Init_Domain() {
+ BILLIONMAIL_HOSTNAME="$2"
+
+ # Regular expression check domain name format
+ if [[ ! "${BILLIONMAIL_HOSTNAME}" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9](\.[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])*$ ]]; then
+ echo -e "\e[31m(${BILLIONMAIL_HOSTNAME}) is not a FQDN!\e[0m"
+ echo "Please change it to a FQDN"
+ exit 1
+ elif [[ "${BILLIONMAIL_HOSTNAME: -1}" == "." ]]; then
+ echo "(${BILLIONMAIL_HOSTNAME}) is ending with a dot. This is not a valid FQDN!"
+ exit 1
+
+ fi
+
+ # Convert to lowercase
+ BILLIONMAIL_HOSTNAME=$(echo "${BILLIONMAIL_HOSTNAME}" | tr '[:upper:]' '[:lower:]')
+
+}
+
+Select_Domain_data(){
+
+ # Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain;")
+ # echo "${Check_domain}"
+ Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT domain FROM domain;")
+ echo "${Check_domain}"
+}
+
+Select_Email_data(){
+
+ Check_mailbox=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT username FROM mailbox;")
+ echo "${Check_mailbox}"
+}
+
+Add_Domain() {
+
+ echo "Creating domain..."
+
+ Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
+ if [ -z ${Check_domain} ]; then
+ # Create a domain
+
+ docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "INSERT INTO domain (domain, a_record, mailboxes, mailbox_quota, quota, rate_limit, create_time, active)
+ VALUES ('${BILLIONMAIL_HOSTNAME}', 'mail.${BILLIONMAIL_HOSTNAME}', 500, 5368709120, 5368709120, 12, ${create_time}, 1);"
+ if [ $? -eq 0 ]; then
+ echo "${BILLIONMAIL_HOSTNAME} Domain creation was successful!"
+ else
+ Red_Error "Domain creation failed!"
+ fi
+ else
+ echo ""${Check_domain}" Domain already exists!"
+ fi
+
+ IPV4_ADDRESS=$(curl -sS -4 --connect-timeout 10 -m 20 https://ifconfig.me)
+ if [ -z "${IPV4_ADDRESS}" ]; then
+ IPV4_ADDRESS=$(curl -sSk --connect-timeout 10 -m 20 https://www.aapanel.com/api/common/getClientIP)
+ fi
+ ipv4_regex="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
+ if [[ ${IPV4_ADDRESS} =~ ${ipv4_regex} ]]; then
+ echo "${IPV4_ADDRESS}" >/dev/null 2>&1
+ elif [ -z "${IPV4_ADDRESS}" ]; then
+ IPV4_ADDRESS="YOUR_SERVER_IPV4_ADDRESS"
+ fi
+ echo -e "Please add the following record to your domain name"
+ echo -e "======================================================="
+ echo -e " Type | Host record | IPv4 address |"
+ echo -e " A | mail.${BILLIONMAIL_HOSTNAME} | ${IPV4_ADDRESS} |"
+ echo -e "======================================================="
+ echo -e " Type | Host record | Record value | MX priority"
+ echo -e " MX | @ | mail.${BILLIONMAIL_HOSTNAME} | 10"
+ echo -e "======================================================="
+
+}
+
+Del_Domain() {
+ echo "Deleting domain..."
+
+ Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
+
+ if [ -z "${Check_domain}" ]; then
+ echo "Domain '${BILLIONMAIL_HOSTNAME}' does not exist!"
+ else
+ # Delete the domain
+ docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "DELETE FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';"
+ if [ $? -eq 0 ]; then
+ echo "Domain '${BILLIONMAIL_HOSTNAME}' deleted successfully!"
+ else
+ Red_Error "Failed to delete domain '${BILLIONMAIL_HOSTNAME}'!"
+ fi
+ fi
+}
+
+
+Add_Email() {
+ echo "Creating mailbox..."
+
+ Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
+ if [ -z "${Check_domain}" ]; then
+ Red_Error "Domain '${BILLIONMAIL_HOSTNAME}' does not exist, please create it first!"
+ fi
+
+ # Create a mailbox
+ if [ -z "${mailbox}" ]; then
+ mailbox=$(LC_ALL=C </dev/urandom tr -dc a-z0-9 2> /dev/null | head -c 6)
+ echo "Generate mailbox: ${mailbox}"
+ else
+ mailbox=$(echo "${mailbox}" | tr '[:upper:]' '[:lower:]')
+ fi
+ Generate_mailbox_password=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 16)
+ #echo "Generate_mailbox_password: ${Generate_mailbox_password}"
+ Encrypt_mailbox_password=$(docker exec -i ${DOVECOT_CONTAINER_NAME} doveadm pw -s MD5-CRYPT -p "${Generate_mailbox_password}" | sed 's/{MD5-CRYPT}//')
+ if [ $? -eq 0 ]; then
+ echo "Generate_mailbox_password: ${Generate_mailbox_password}"
+ echo "mailbox_password: ${Encrypt_mailbox_password}"
+ else
+ # Generate the default password after failure: BILLIONMAIL
+ Generate_mailbox_password="BILLIONMAIL"
+ Encrypt_mailbox_password='$1$ELBUCcYE$TbdGKBvLkFbjQguDbi3s01'
+ echo "Generate_mailbox_password--default: ${Generate_mailbox_password}"
+ Default_password=1
+ fi
+
+ if [ "${Default_password}" != 1 ]; then
+ # password_encode
+ # Base64 encoding of strings
+ b64_data=$(echo -n "${Generate_mailbox_password}" | base64)
+ # Convert characters to hexadecimal
+ password_encode=$(echo -n "${b64_data}" | while IFS= read -r -n1 char; do printf "%02x" "'$char"; done)
+ echo "password_encode: ${password_encode}"
+ if [ -z ${password_encode} ]; then
+ b64_data=$(echo -n "${Generate_mailbox_password}" | base64)
+ password_encode=$(echo -n "${b64_data}" | od -A n -t x1 | tr -d ' \n')
+ echo "password_encode: ${password_encode}"
+ fi
+ else
+ password_encode="516b6c4d54456c50546b31425355773d"
+ fi
+
+ Check_mailbox=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';" | grep -w "${mailbox}@${BILLIONMAIL_HOSTNAME}")
+ if [ -z "${Check_mailbox}" ]; then
+ INSERT_mailbox='INSERT INTO mailbox (username, password, password_encode, full_name, is_admin, maildir, quota, local_part, domain, create_time, update_time, active)
+ VALUES (
+ '\'${mailbox}@${BILLIONMAIL_HOSTNAME}\'',
+ '\'${Encrypt_mailbox_password}\'',
+ '\'${password_encode}\'',
+ '\'${mailbox}\'',
+ 0,
+ '\'${mailbox}@${BILLIONMAIL_HOSTNAME}/\'',
+ 5368709120,
+ '\'${mailbox}\'',
+ '\'${BILLIONMAIL_HOSTNAME}\'',
+ '${create_time}',
+ '${create_time}',
+ 1
+ );'
+ echo "$INSERT_mailbox"
+ docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "$INSERT_mailbox"
+ if [ $? -eq 0 ]; then
+ echo "Mailbox creation was successful!"
+ else
+ Red_Error "Mailbox creation failed!"
+ fi
+ #docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';"
+ else
+ echo ""${Check_mailbox}" Mailbox already exists!"
+ fi
+
+ echo -e "\e[31mPlease save the following information:\e[0m"
+ echo -e "Mailbox (e-mail): \e[33m${mailbox}@${BILLIONMAIL_HOSTNAME}\e[0m \nPassword: \e[33m${Generate_mailbox_password}\e[0m"
+}
+
+
+Del_Email() {
+
+ echo "Deleting mailbox..."
+
+ Check_mailbox=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';" | grep -w "${mailbox}@${BILLIONMAIL_HOSTNAME}")
+
+ if [ -z "${Check_mailbox}" ]; then
+ echo "Mailbox '${mailbox}@${BILLIONMAIL_HOSTNAME}' does not exist!"
+ else
+ docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "DELETE FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';"
+ if [ $? -eq 0 ]; then
+ echo "Mailbox '${mailbox}@${BILLIONMAIL_HOSTNAME}' deleted successfully!"
+ else
+ Red_Error "Failed to delete mailbox '${mailbox}@${BILLIONMAIL_HOSTNAME}'!"
+ fi
+ fi
+}
+
+case "$1" in
+ h | -h | help | --help | -help)
+ echo "Help Information:"
+ echo " add-domain <domain> - Add domain. Example: $0 add-domain example.com"
+ echo " del-domain <domain> - Delete domain. Example: $0 del-domain example.com"
+ echo " add-email <email> - Add email. Example: $0 add-email [email protected]"
+ echo " del-email <email> - Delete email. Example: $0 del-email [email protected]"
+ echo " show-domain - Show domain data."
+ echo " show-email - Show email data."
+ ;;
+ add-domain)
+ Init_Domain "$@"
+ Add_Domain
+ ;;
+ del-domain)
+ Init_Domain "$@"
+ Del_Domain
+ ;;
+ add-email)
+ Init_Email "$@"
+ Add_Email
+ ;;
+ del-email)
+ Init_Email "$@"
+ Del_Email
+ ;;
+ show-domain)
+ Select_Domain_data
+ ;;
+ show-email)
+ Select_Email_data
+ ;;
+ *)
+ echo "Usage: $0 {add-domain|del-domain|add-email|del-email|show-domain|show-email|help}"
+ exit 1
+ ;;
+esac
\ No newline at end of file