1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- /**
- ArOZ Online WebSocket Reflector
- DO NOT SEND CONFIDENTIAL INFORMATION TO WSR IN PLAIN TEXT!
- Designed to be used with ArOZ Online System for cross module communication purposes
- Developed (Glue together) by Toby Chui feat. ArOZ Online Project
- **/
- // Websocket Related Functions:
- // Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSE file.
- package main
- import (
- "flag"
- "log"
- "net/http"
- "fmt"
- "os"
- "io/ioutil"
- "runtime"
- )
- var addr = flag.String("addr", ":65530", "http service address")
- func check(e error) {
- if e != nil {
- panic(e)
- }
- }
- func serveHome(w http.ResponseWriter, r *http.Request) {
- log.Println("[request]",r.URL)
- //For HDS protocol compatibility, these two standard functions are included in the system
- if r.URL.Path == "/status"{
- //Response will only be given when the websocket server is on, so the return result of status must be ON
- fmt.Fprintf(w, "ON")
- return
- }
- if r.URL.Path == "/info"{
- //Show standard information for HDS scanner, make sure that they don't try to connect to this instance
- fmt.Fprintf(w, "ArOZ Online Websocket Reflector_ref.ao.com.imuslab")
- return
- }
- if r.URL.Path == "/uuid"{
- //Read the devices uuid from the dedicated path and return it to the browser
- var uuidPath = "/etc/AOB/device_identity.config"
- if runtime.GOOS == "windows" {
- uuidPath = "C:\\AOB\\device_identity.config"
- }
- if _, err := os.Stat(uuidPath); err == nil {
- //Check if the ArOZ Online UUID file exists or not. If Yes, read uuid from file.
- dat, err := ioutil.ReadFile(uuidPath)
- check(err)
- fmt.Fprintf(w,string(dat))
- }else{
- //The file not found. Just send an error message.
- fmt.Fprintf(w,"ERROR. ArOZ Online device_identify.config file not found.")
- }
- return
- }
- if r.URL.Path != "/" {
- http.Error(w, "Not found", http.StatusNotFound)
- return
- }
- if r.Method != "GET" {
- http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
- return
- }
- http.ServeFile(w, r, "info.html")
- }
- func main() {
- fmt.Println("[ArOZ Online WebSocket Server]")
- fmt.Println("[info] init in progress...")
- flag.Parse()
- hub := newHub()
- go hub.run()
- fmt.Println("[info] Ready!")
- http.HandleFunc("/", serveHome)
- http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
- serveWs(hub, w, r)
- })
- err := http.ListenAndServe(*addr, nil)
- if err != nil {
- log.Fatal("ListenAndServe: ", err)
- }
- }
|