Browse Source

Forced ws upgrader to accept cors request

Toby Chui 3 years ago
parent
commit
58dc07aa01

+ 3 - 0
file_system.go

@@ -421,6 +421,7 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 
 	//Start websocket connection
 	var upgrader = websocket.Upgrader{}
+	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
 	c, err := upgrader.Upgrade(w, r, nil)
 	if err != nil {
 		log.Println("Failed to upgrade websocket connection: ", err.Error())
@@ -801,6 +802,7 @@ func system_fs_WebSocketScanTrashBin(w http.ResponseWriter, r *http.Request) {
 
 	//Upgrade to websocket
 	var upgrader = websocket.Upgrader{}
+	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
 	c, err := upgrader.Upgrade(w, r, nil)
 	if err != nil {
 		w.WriteHeader(http.StatusInternalServerError)
@@ -1256,6 +1258,7 @@ func system_fs_handleWebSocketOpr(w http.ResponseWriter, r *http.Request) {
 
 	//Upgrade to websocket
 	var upgrader = websocket.Upgrader{}
+	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
 	c, err := upgrader.Upgrade(w, r, nil)
 	if err != nil {
 		w.WriteHeader(http.StatusInternalServerError)

+ 1 - 0
mod/filesystem/metadata/metadata.go

@@ -217,6 +217,7 @@ func (rh *RenderHandler) HandleLoadCache(w http.ResponseWriter, r *http.Request,
 
 	//Upgrade the connection to websocket
 	var upgrader = websocket.Upgrader{}
+	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
 	c, err := upgrader.Upgrade(w, r, nil)
 	if err != nil {
 		log.Print("upgrade:", err)

+ 1 - 0
mod/network/websocketproxy/websocketproxy.go

@@ -168,6 +168,7 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
 
 	// Now upgrade the existing incoming request to a WebSocket connection.
 	// Also pass the header that we gathered from the Dial handshake.
+	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
 	connPub, err := upgrader.Upgrade(rw, req, upgradeHeader)
 	if err != nil {
 		log.Printf("websocketproxy: couldn't upgrade %s", err)

+ 2 - 1
mod/network/websocketproxy/websocketproxy_test.go

@@ -46,11 +46,12 @@ func TestProxy(t *testing.T) {
 		mux2 := http.NewServeMux()
 		mux2.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 			// Don't upgrade if original host header isn't preserved
-			if r.Host !=  "127.0.0.1:7777" {
+			if r.Host != "127.0.0.1:7777" {
 				log.Printf("Host header set incorrectly.  Expecting 127.0.0.1:7777 got %s", r.Host)
 				return
 			}
 
+			upgrader.CheckOrigin = func(r *http.Request) bool { return true }
 			conn, err := upgrader.Upgrade(w, r, nil)
 			if err != nil {
 				log.Println(err)

+ 2 - 1
mod/wsshell/wsshell.go

@@ -35,6 +35,7 @@ type Terminal struct {
 
 func NewWebSocketShellTerminal() *Terminal {
 	baseCWD, _ := filepath.Abs("./")
+	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
 	return &Terminal{
 		cwd: baseCWD,
 	}
@@ -58,7 +59,7 @@ func (t *Terminal) HandleOpen(w http.ResponseWriter, r *http.Request) {
 		cmd = exec.Command("/bin/bash")
 	} else {
 		//Currently not supported.
-		c.WriteMessage(1, []byte("[ERROR] Host Platform not supported: " + runtime.GOOS))
+		c.WriteMessage(1, []byte("[ERROR] Host Platform not supported: "+runtime.GOOS))
 		w.WriteHeader(http.StatusInternalServerError)
 		w.Write([]byte("500 - Host OS Not supported"))
 		return

+ 2 - 1
subservice/WsTTY/mod/wsshell/wsshell.go

@@ -34,6 +34,7 @@ type Terminal struct {
 }
 
 func NewWebSocketShellTerminal() *Terminal {
+	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
 	baseCWD, _ := filepath.Abs("./")
 	return &Terminal{
 		cwd: baseCWD,
@@ -58,7 +59,7 @@ func (t *Terminal) HandleOpen(w http.ResponseWriter, r *http.Request) {
 		cmd = exec.Command("/bin/bash")
 	} else {
 		//Currently not supported.
-		c.WriteMessage(1, []byte("[ERROR] Host Platform not supported: " + runtime.GOOS))
+		c.WriteMessage(1, []byte("[ERROR] Host Platform not supported: "+runtime.GOOS))
 		w.WriteHeader(http.StatusInternalServerError)
 		w.Write([]byte("500 - Host OS Not supported"))
 		return

+ 4 - 2
web/Manga Cafe/viewComic.html

@@ -73,7 +73,8 @@
     filter: alpha(opacity = 0);
     position:fixed;
     top:25%; bottom:25%; left:0; right:0;
-	width:100%;height:50%
+	width:100%;
+	height:50%;
     display:block;
     z-index:998;
     background:transparent;" onClick="">
@@ -83,7 +84,8 @@
 <div id="SettingInterface" style="
     position:fixed;
     top:0; bottom:0; left:0; right:0;
-	width:100%;height:100%
+	width:100%;
+	height:100%;
     display:block;
     z-index:1501;
 	display:none;" onClick="">