@@ -16,6 +16,7 @@ import (
1616 "os"
1717 "path"
1818 "path/filepath"
19+ "strconv"
1920 "strings"
2021 "time"
2122
@@ -24,6 +25,8 @@ import (
2425 "github.com/elazarl/goproxy"
2526)
2627
28+ const htmlContent = `<html><body>Intentionally Empty File</body></html>`
29+
2730type ServerSettings struct {
2831 RootPath string `json:"rootPath"`
2932 GameDataPath string `json:"gameDataPath"`
@@ -49,6 +52,7 @@ type ServerSettings struct {
4952 ExtIndexTypes []string `json:"extIndexTypes"`
5053 ExtGzippeddTypes []string `json:"extGzippedTypes"`
5154 ExtMimeTypes map [string ]string `json:"extMimeTypes"`
55+ EnableHtaccess bool `json:"enableHtaccess"`
5256}
5357
5458// ExtApplicationTypes is a map that holds the content types of different file extensions
@@ -96,6 +100,7 @@ func initServer() {
96100 allowCrossDomain := flag .Bool ("allowCrossDomain" , serverSettings .AllowCrossDomain , "Whether to allow cross-domain requests" )
97101 verboseLogging := flag .Bool ("verboseLogging" , serverSettings .VerboseLogging , "should every proxy request be logged to stdout" )
98102 apiPrefix := flag .String ("apiPrefix" , serverSettings .ApiPrefix , "apiPrefix is used to prefix any API call." )
103+ enableHtaccess := flag .Bool ("enableHtaccess" , serverSettings .EnableHtaccess , "Enables GameZIP games to follow basic htaccess rewrite files" )
99104
100105 flag .Parse ()
101106
@@ -141,6 +146,7 @@ func initServer() {
141146 serverSettings .AllowCrossDomain = * allowCrossDomain
142147 serverSettings .VerboseLogging = * verboseLogging
143148 serverSettings .ApiPrefix = * apiPrefix
149+ serverSettings .EnableHtaccess = * enableHtaccess
144150
145151 // Print out all path settings
146152 fmt .Println ("Root Path:" , serverSettings .RootPath )
@@ -149,6 +155,7 @@ func initServer() {
149155 fmt .Println ("Legacy CGI-BIN Path:" , serverSettings .LegacyCGIBINPath )
150156 fmt .Println ("Legacy HTDOCS Path:" , serverSettings .LegacyHTDOCSPath )
151157 fmt .Println ("PHP-CGI Path:" , serverSettings .PhpCgiPath )
158+ fmt .Println ("Htaccess Enabled:" , serverSettings .EnableHtaccess )
152159
153160 // Setup the proxy
154161 proxy = goproxy .NewProxyHttpServer ()
@@ -278,6 +285,18 @@ func getProxyResp(r *http.Request, contents []byte) (*http.Response, error) {
278285 return proxyResp , nil
279286 }
280287
288+ // Prevent htdocs loading
289+ // Intercept if we're serving /content/www.mochiads.com/static/lib/services/services.swf and it's smaller than 10kb (probably parked page)
290+ if r .URL .Host == "www.mochiads.com" && strings .HasPrefix (r .URL .Path , "/static/lib/services/services.swf" ) {
291+ resRecorder := httptest .NewRecorder ()
292+ resRecorder .Header ().Set ("Content-Type" , "text/html" )
293+ resRecorder .Header ().Set ("Content-Length" , strconv .Itoa (len (htmlContent )))
294+ resRecorder .Header ().Set ("ZIPSVR_FILENAME" , "/empty.html" )
295+ resRecorder .WriteHeader (http .StatusOK )
296+ resRecorder .Write ([]byte (htmlContent ))
297+ return resRecorder .Result (), nil
298+ }
299+
281300 // Check Legacy
282301 if proxyResp .StatusCode >= 400 {
283302 // Copy the original request
@@ -336,6 +355,7 @@ func handleRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http
336355 // Remove port from host if exists (old apps don't clean it before sending requests?)
337356 r .URL .Host = strings .Split (r .URL .Host , ":" )[0 ]
338357 r .Header .Del ("If-Modified-Since" )
358+
339359 // Clone the body into both requests by reading and making 2 new readers
340360 contents , _ := io .ReadAll (r .Body )
341361
@@ -504,6 +524,7 @@ XgVWIMrKj4T7p86bcxq4jdWDYUYpRd/2Og==
504524 serverSettings .ExtScriptTypes ,
505525 serverSettings .OverridePaths ,
506526 serverSettings .LegacyHTDOCSPath ,
527+ serverSettings .EnableHtaccess ,
507528 ),
508529 ))
509530 }()
0 commit comments