Skip to content

Commit 85422c0

Browse files
authored
Merge pull request #439 from tobychui/v3.1.5
Fixed hostname case sensitive bug Fixed ACME table too wide css bug Fixed HSTS toggle button bug Fixed slow GeoIP resolve mode concurrent r/w bug Added close connection as default site option Added experimental authelia support Added custom header support to websocket Added levelDB as database implementation (not currently used) Added external GeoIP db loading support Restructured a lot of modules
2 parents 2fca458 + 73999c1 commit 85422c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+27823
-22996
lines changed

docker/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ENV ZEROTIER="false"
4444

4545
ENV AUTORENEW="86400"
4646
ENV CFGUPGRADE="true"
47+
ENV DB="auto"
4748
ENV DOCKER="true"
4849
ENV EARLYRENEW="30"
4950
ENV FASTGEOIP="false"
@@ -52,6 +53,7 @@ ENV MDNSNAME="''"
5253
ENV NOAUTH="false"
5354
ENV PORT="8000"
5455
ENV SSHLB="false"
56+
ENV UPDATE_GEOIP="false"
5557
ENV VERSION="false"
5658
ENV WEBFM="true"
5759
ENV WEBROOT="./www"

docker/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Variables are the same as those in [Start Parameters](https://github.com/tobychu
7373
|:-|:-|:-|
7474
| `AUTORENEW` | `86400` (Integer) | ACME auto TLS/SSL certificate renew check interval. |
7575
| `CFGUPGRADE` | `true` (Boolean) | Enable auto config upgrade if breaking change is detected. |
76+
| `DB` | `auto` (String) | Database backend to use (leveldb, boltdb, auto) Note that fsdb will be used on unsupported platforms like RISCV (default "auto"). |
7677
| `DOCKER` | `true` (Boolean) | Run Zoraxy in docker compatibility mode. |
7778
| `EARLYRENEW` | `30` (Integer) | Number of days to early renew a soon expiring certificate. |
7879
| `FASTGEOIP` | `false` (Boolean) | Enable high speed geoip lookup, require 1GB extra memory (Not recommend for low end devices). |
@@ -81,6 +82,7 @@ Variables are the same as those in [Start Parameters](https://github.com/tobychu
8182
| `NOAUTH` | `false` (Boolean) | Disable authentication for management interface. |
8283
| `PORT` | `8000` (Integer) | Management web interface listening port |
8384
| `SSHLB` | `false` (Boolean) | Allow loopback web ssh connection (DANGER). |
85+
| `UPDATE_GEOIP` | `false` (Boolean) | Download the latest GeoIP data and exit. |
8486
| `VERSION` | `false` (Boolean) | Show version of this server. |
8587
| `WEBFM` | `true` (Boolean) | Enable web file manager for static web server root folder. |
8688
| `WEBROOT` | `./www` (String) | Static web server root folder. Only allow change in start parameters. |

docker/entrypoint.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
#!/usr/bin/env bash
22

33
update-ca-certificates
4-
echo "CA certificates updated"
4+
echo "CA certificates updated."
5+
6+
zoraxy -update_geoip=true
7+
echo "Updated GeoIP data."
58

69
if [ "$ZEROTIER" = "true" ]; then
710
if [ ! -d "/opt/zoraxy/config/zerotier/" ]; then
811
mkdir -p /opt/zoraxy/config/zerotier/
912
fi
1013
ln -s /opt/zoraxy/config/zerotier/ /var/lib/zerotier-one
1114
zerotier-one -d
12-
echo "ZeroTier daemon started"
15+
echo "ZeroTier daemon started."
1316
fi
1417

1518
echo "Starting Zoraxy..."
1619
exec zoraxy \
1720
-autorenew="$AUTORENEW" \
1821
-cfgupgrade="$CFGUPGRADE" \
22+
-db="$DB" \
1923
-docker="$DOCKER" \
2024
-earlyrenew="$EARLYRENEW" \
2125
-fastgeoip="$FASTGEOIP" \
@@ -24,6 +28,7 @@ exec zoraxy \
2428
-noauth="$NOAUTH" \
2529
-port=:"$PORT" \
2630
-sshlb="$SSHLB" \
31+
-update_geoip="$UPDATE_GEOIP" \
2732
-version="$VERSION" \
2833
-webfm="$WEBFM" \
2934
-webroot="$WEBROOT" \

src/api.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,9 @@ func RegisterTLSAPIs(authRouter *auth.RouterDef) {
7777
authRouter.HandleFunc("/api/cert/delete", handleCertRemove)
7878
}
7979

80-
// Register the APIs for SSO and Oauth functions, WIP
81-
func RegisterSSOAPIs(authRouter *auth.RouterDef) {
82-
authRouter.HandleFunc("/api/sso/status", ssoHandler.HandleSSOStatus)
83-
authRouter.HandleFunc("/api/sso/enable", ssoHandler.HandleSSOEnable)
84-
authRouter.HandleFunc("/api/sso/setPort", ssoHandler.HandlePortChange)
85-
authRouter.HandleFunc("/api/sso/setAuthURL", ssoHandler.HandleSetAuthURL)
86-
87-
authRouter.HandleFunc("/api/sso/app/register", ssoHandler.HandleRegisterApp)
88-
//authRouter.HandleFunc("/api/sso/app/list", ssoHandler.HandleListApp)
89-
//authRouter.HandleFunc("/api/sso/app/remove", ssoHandler.HandleRemoveApp)
90-
91-
authRouter.HandleFunc("/api/sso/user/list", ssoHandler.HandleListUser)
92-
authRouter.HandleFunc("/api/sso/user/add", ssoHandler.HandleAddUser)
93-
authRouter.HandleFunc("/api/sso/user/edit", ssoHandler.HandleEditUser)
94-
authRouter.HandleFunc("/api/sso/user/remove", ssoHandler.HandleRemoveUser)
80+
// Register the APIs for Authentication handlers like Authelia and OAUTH2
81+
func RegisterAuthenticationHandlerAPIs(authRouter *auth.RouterDef) {
82+
authRouter.HandleFunc("/api/sso/Authelia", autheliaRouter.HandleSetAutheliaURLAndHTTPS)
9583
}
9684

9785
// Register the APIs for redirection rules management functions
@@ -339,7 +327,7 @@ func initAPIs(targetMux *http.ServeMux) {
339327
RegisterAuthAPIs(requireAuth, targetMux)
340328
RegisterHTTPProxyAPIs(authRouter)
341329
RegisterTLSAPIs(authRouter)
342-
//RegisterSSOAPIs(authRouter)
330+
RegisterAuthenticationHandlerAPIs(authRouter)
343331
RegisterRedirectionAPIs(authRouter)
344332
RegisterAccessRuleAPIs(authRouter)
345333
RegisterPathRuleAPIs(authRouter)

src/config.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func LoadReverseProxyConfig(configFilepath string) error {
5959
thisConfigEndpoint.RootOrMatchingDomain = "/"
6060
}
6161

62-
if thisConfigEndpoint.ProxyType == dynamicproxy.ProxyType_Root {
62+
if thisConfigEndpoint.ProxyType == dynamicproxy.ProxyTypeRoot {
6363
//This is a root config file
6464
rootProxyEndpoint, err := dynamicProxyRouter.PrepareProxyRoute(&thisConfigEndpoint)
6565
if err != nil {
@@ -68,7 +68,7 @@ func LoadReverseProxyConfig(configFilepath string) error {
6868

6969
dynamicProxyRouter.SetProxyRouteAsRoot(rootProxyEndpoint)
7070

71-
} else if thisConfigEndpoint.ProxyType == dynamicproxy.ProxyType_Host {
71+
} else if thisConfigEndpoint.ProxyType == dynamicproxy.ProxyTypeHost {
7272
//This is a host config file
7373
readyProxyEndpoint, err := dynamicProxyRouter.PrepareProxyRoute(&thisConfigEndpoint)
7474
if err != nil {
@@ -97,7 +97,7 @@ func filterProxyConfigFilename(filename string) string {
9797
func SaveReverseProxyConfig(endpoint *dynamicproxy.ProxyEndpoint) error {
9898
//Get filename for saving
9999
filename := filepath.Join("./conf/proxy/", endpoint.RootOrMatchingDomain+".config")
100-
if endpoint.ProxyType == dynamicproxy.ProxyType_Root {
100+
if endpoint.ProxyType == dynamicproxy.ProxyTypeRoot {
101101
filename = "./conf/proxy/root.config"
102102
}
103103

@@ -129,9 +129,15 @@ func RemoveReverseProxyConfig(endpoint string) error {
129129
// Get the default root config that point to the internal static web server
130130
// this will be used if root config is not found (new deployment / missing root.config file)
131131
func GetDefaultRootConfig() (*dynamicproxy.ProxyEndpoint, error) {
132+
//Default Authentication Provider
133+
defaultAuth := &dynamicproxy.AuthenticationProvider{
134+
AuthMethod: dynamicproxy.AuthMethodNone,
135+
BasicAuthCredentials: []*dynamicproxy.BasicAuthCredentials{},
136+
BasicAuthExceptionRules: []*dynamicproxy.BasicAuthExceptionRule{},
137+
}
132138
//Default settings
133139
rootProxyEndpoint, err := dynamicProxyRouter.PrepareProxyRoute(&dynamicproxy.ProxyEndpoint{
134-
ProxyType: dynamicproxy.ProxyType_Root,
140+
ProxyType: dynamicproxy.ProxyTypeRoot,
135141
RootOrMatchingDomain: "/",
136142
ActiveOrigins: []*loadbalance.Upstream{
137143
{
@@ -141,14 +147,12 @@ func GetDefaultRootConfig() (*dynamicproxy.ProxyEndpoint, error) {
141147
Weight: 0,
142148
},
143149
},
144-
InactiveOrigins: []*loadbalance.Upstream{},
145-
BypassGlobalTLS: false,
146-
VirtualDirectories: []*dynamicproxy.VirtualDirectoryEndpoint{},
147-
RequireBasicAuth: false,
148-
BasicAuthCredentials: []*dynamicproxy.BasicAuthCredentials{},
149-
BasicAuthExceptionRules: []*dynamicproxy.BasicAuthExceptionRule{},
150-
DefaultSiteOption: dynamicproxy.DefaultSite_InternalStaticWebServer,
151-
DefaultSiteValue: "",
150+
InactiveOrigins: []*loadbalance.Upstream{},
151+
BypassGlobalTLS: false,
152+
VirtualDirectories: []*dynamicproxy.VirtualDirectoryEndpoint{},
153+
AuthenticationProvider: defaultAuth,
154+
DefaultSiteOption: dynamicproxy.DefaultSite_InternalStaticWebServer,
155+
DefaultSiteValue: "",
152156
})
153157
if err != nil {
154158
return nil, err
@@ -167,7 +171,6 @@ func ExportConfigAsZip(w http.ResponseWriter, r *http.Request) {
167171
if includeSysDBRaw == "true" {
168172
//Include the system database in backup snapshot
169173
//Temporary set it to read only
170-
sysdb.ReadOnly = true
171174
includeSysDB = true
172175
}
173176

@@ -241,8 +244,6 @@ func ExportConfigAsZip(w http.ResponseWriter, r *http.Request) {
241244
return
242245
}
243246

244-
//Restore sysdb state
245-
sysdb.ReadOnly = false
246247
}
247248

248249
if err != nil {

src/def.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"imuslab.com/zoraxy/mod/access"
1717
"imuslab.com/zoraxy/mod/acme"
1818
"imuslab.com/zoraxy/mod/auth"
19-
"imuslab.com/zoraxy/mod/auth/sso"
19+
"imuslab.com/zoraxy/mod/auth/sso/authelia"
2020
"imuslab.com/zoraxy/mod/database"
2121
"imuslab.com/zoraxy/mod/dockerux"
2222
"imuslab.com/zoraxy/mod/dynamicproxy/loadbalance"
@@ -42,7 +42,7 @@ import (
4242
const (
4343
/* Build Constants */
4444
SYSTEM_NAME = "Zoraxy"
45-
SYSTEM_VERSION = "3.1.4"
45+
SYSTEM_VERSION = "3.1.5"
4646
DEVELOPMENT_BUILD = false /* Development: Set to false to use embedded web fs */
4747

4848
/* System Constants */
@@ -74,6 +74,7 @@ const (
7474
/* System Startup Flags */
7575
var (
7676
webUIPort = flag.String("port", ":8000", "Management web interface listening port")
77+
databaseBackend = flag.String("db", "auto", "Database backend to use (leveldb, boltdb, auto) Note that fsdb will be used on unsupported platforms like RISCV")
7778
noauth = flag.Bool("noauth", false, "Disable authentication for management interface")
7879
showver = flag.Bool("version", false, "Show version of this server")
7980
allowSshLoopback = flag.Bool("sshlb", false, "Allow loopback web ssh connection (DANGER)")
@@ -88,6 +89,9 @@ var (
8889
staticWebServerRoot = flag.String("webroot", "./www", "Static web server root folder. Only allow chnage in start paramters")
8990
allowWebFileManager = flag.Bool("webfm", true, "Enable web file manager for static web server root folder")
9091
enableAutoUpdate = flag.Bool("cfgupgrade", true, "Enable auto config upgrade if breaking change is detected")
92+
93+
/* Maintaince Function Flags */
94+
geoDbUpdate = flag.Bool("update_geoip", false, "Download the latest GeoIP data and exit")
9195
)
9296

9397
/* Global Variables and Handlers */
@@ -127,7 +131,9 @@ var (
127131
staticWebServer *webserv.WebServer //Static web server for hosting simple stuffs
128132
forwardProxy *forwardproxy.Handler //HTTP Forward proxy, basically VPN for web browser
129133
loadBalancer *loadbalance.RouteManager //Global scope loadbalancer, store the state of the lb routing
130-
ssoHandler *sso.SSOHandler //Single Sign On handler
134+
135+
//Authentication Provider
136+
autheliaRouter *authelia.AutheliaRouter //Authelia router for Authelia authentication
131137

132138
//Helper modules
133139
EmailSender *email.Sender //Email sender that handle email sending

src/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ require (
2828
github.com/benbjohnson/clock v1.3.0 // indirect
2929
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
3030
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
31+
github.com/golang/snappy v0.0.1 // indirect
3132
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.114 // indirect
3233
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
3334
github.com/shopspring/decimal v1.3.1 // indirect
35+
github.com/syndtr/goleveldb v1.0.0 // indirect
3436
github.com/tidwall/btree v0.0.0-20191029221954-400434d76274 // indirect
3537
github.com/tidwall/buntdb v1.1.2 // indirect
3638
github.com/tidwall/gjson v1.12.1 // indirect

src/go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
277277
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
278278
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
279279
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
280+
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
281+
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
280282
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
281283
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
282284
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -528,6 +530,7 @@ github.com/nzdjb/go-metaname v1.0.0 h1:sNASlZC1RM3nSudtBTE1a3ZVTDyTpjqI5WXRPrdZ9
528530
github.com/nzdjb/go-metaname v1.0.0/go.mod h1:0GR0LshZax1Lz4VrOrfNSE4dGvTp7HGjiemdczXT2H4=
529531
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
530532
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
533+
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
531534
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
532535
github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0=
533536
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
@@ -536,6 +539,7 @@ github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3
536539
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
537540
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
538541
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
542+
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
539543
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
540544
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
541545
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
@@ -660,6 +664,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
660664
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
661665
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
662666
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
667+
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
668+
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
663669
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1002 h1:RE84sHFFx6t24DJvSnF9fS1DzBNv9OpctzHK3t7AY+I=
664670
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1002/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
665671
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.1002 h1:QwE0dRkAAbdf+eACnkNULgDn9ZKUJpPWRyXdqJolP5E=

src/main.go

+9-31
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ import (
4242

4343
"github.com/google/uuid"
4444
"github.com/gorilla/csrf"
45+
"imuslab.com/zoraxy/mod/geodb"
4546
"imuslab.com/zoraxy/mod/update"
4647
"imuslab.com/zoraxy/mod/utils"
4748
)
4849

49-
5050
/* SIGTERM handler, do shutdown sequences before closing */
5151
func SetupCloseHandler() {
5252
c := make(chan os.Signal, 2)
@@ -58,43 +58,21 @@ func SetupCloseHandler() {
5858
}()
5959
}
6060

61-
func ShutdownSeq() {
62-
SystemWideLogger.Println("Shutting down " + SYSTEM_NAME)
63-
SystemWideLogger.Println("Closing Netstats Listener")
64-
netstatBuffers.Close()
65-
SystemWideLogger.Println("Closing Statistic Collector")
66-
statisticCollector.Close()
67-
if mdnsTickerStop != nil {
68-
SystemWideLogger.Println("Stopping mDNS Discoverer (might take a few minutes)")
69-
// Stop the mdns service
70-
mdnsTickerStop <- true
71-
}
72-
mdnsScanner.Close()
73-
SystemWideLogger.Println("Shutting down load balancer")
74-
loadBalancer.Close()
75-
SystemWideLogger.Println("Closing Certificates Auto Renewer")
76-
acmeAutoRenewer.Close()
77-
//Remove the tmp folder
78-
SystemWideLogger.Println("Cleaning up tmp files")
79-
os.RemoveAll("./tmp")
80-
81-
//Close database
82-
SystemWideLogger.Println("Stopping system database")
83-
sysdb.Close()
84-
85-
//Close logger
86-
SystemWideLogger.Println("Closing system wide logger")
87-
SystemWideLogger.Close()
88-
}
89-
9061
func main() {
9162
//Parse startup flags
9263
flag.Parse()
64+
65+
/* Maintaince Function Modes */
9366
if *showver {
9467
fmt.Println(SYSTEM_NAME + " - Version " + SYSTEM_VERSION)
9568
os.Exit(0)
9669
}
70+
if *geoDbUpdate {
71+
geodb.DownloadGeoDBUpdate("./conf/geodb")
72+
os.Exit(0)
73+
}
9774

75+
/* Main Zoraxy Routines */
9876
if !utils.ValidateListeningAddress(*webUIPort) {
9977
fmt.Println("Malformed -port (listening address) paramter. Do you mean -port=:" + *webUIPort + "?")
10078
os.Exit(0)
@@ -130,7 +108,7 @@ func main() {
130108
csrf.SameSite(csrf.SameSiteLaxMode),
131109
)
132110

133-
//Startup all modules
111+
//Startup all modules, see start.go
134112
startupSequence()
135113

136114
//Initiate management interface APIs

src/mod/auth/sso/app.go

-34
This file was deleted.

0 commit comments

Comments
 (0)