@@ -20,13 +20,14 @@ var (
20
20
jsdelivr = 0
21
21
// whiteList = []string{}
22
22
// blackList = []string{}
23
- passList = []string {}
24
- exp1 = regexp .MustCompile (`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:releases|archive)/.*$` )
25
- exp2 = regexp .MustCompile (`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:blob|raw)/.*$` )
26
- exp3 = regexp .MustCompile (`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:info|git-).*$` )
27
- exp4 = regexp .MustCompile (`^(?:https?://)?raw\.(?:githubusercontent|github)\.com/(?P<author>.+?)/(?P<repo>.+?)/.+?/.+$` )
28
- exp5 = regexp .MustCompile (`^(?:https?://)?gist\.(?:githubusercontent|github)\.com/(?P<author>.+?)/.+?/.+$` )
29
- exp6 = regexp .MustCompile (`(\.com/.*?/.+?)/(.+?/)` )
23
+ passList = []string {}
24
+ exp1 = regexp .MustCompile (`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:releases|archive)/.*$` )
25
+ exp2 = regexp .MustCompile (`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:blob|raw)/.*$` )
26
+ exp3 = regexp .MustCompile (`^(?:https?://)?github\.com/(?P<author>.+?)/(?P<repo>.+?)/(?:info|git-).*$` )
27
+ exp4 = regexp .MustCompile (`^(?:https?://)?raw\.(?:githubusercontent|github)\.com/(?P<author>.+?)/(?P<repo>.+?)/.+?/.+$` )
28
+ exp5 = regexp .MustCompile (`^(?:https?://)?gist\.(?:githubusercontent|github)\.com/(?P<author>.+?)/.+?/.+$` )
29
+ exp6 = regexp .MustCompile (`(\.com/.*?/.+?)/(.+?/)` )
30
+ allowAnyUrl bool
30
31
)
31
32
32
33
func main () {
@@ -35,6 +36,7 @@ func main() {
35
36
36
37
flag .StringVar (& host , "host" , "0.0.0.0" , "Host address" )
37
38
flag .StringVar (& port , "port" , "80" , "Port number" )
39
+ flag .BoolVar (& allowAnyUrl , "allow-any-url" , false , "Do not check if the URL is a GitHub URL" )
38
40
flag .Parse ()
39
41
40
42
hostRegExp := regexp .MustCompile (`^\d+\.\d+\.\d+\.\d+$` )
@@ -80,6 +82,11 @@ func main() {
80
82
handler (c , path )
81
83
})
82
84
85
+ if allowAnyUrl {
86
+ log .Println ("Mode: Allow any URL" )
87
+ } else {
88
+ log .Println ("Mode: GitHub URL only" )
89
+ }
83
90
log .Println ("Starting server at " + host + ":" + port )
84
91
85
92
err := router .Run (host + ":" + port )
@@ -107,7 +114,7 @@ func handler(c *gin.Context, u string) {
107
114
break
108
115
}
109
116
}
110
- } else {
117
+ } else if ! allowAnyUrl {
111
118
c .String (http .StatusForbidden , "Invalid input." )
112
119
return
113
120
}
0 commit comments