Fixing some API issues, adding a few API responses
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio
|
SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio
|
||||||
|
|
||||||
#Relative or absolute path accepted, the server will convert any relative path to an absolute path.
|
#Relative or absolute path accepted, the server will convert any relative path to an absolute path.
|
||||||
DefaultMoveFolder = 'Z:\downloads' #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
|
DefaultMoveFolder = 'downloads' #default path that a finished torrent is symlinked to after completion. Torrents added via RSS will default here
|
||||||
TorrentWatchFolder = 'torrentUpload' #folder path that is watched for .torrent files and adds them automatically every 5 minutes
|
TorrentWatchFolder = 'torrentUpload' #folder path that is watched for .torrent files and adds them automatically every 5 minutes
|
||||||
|
|
||||||
#Limits your upload and download speed globally, all are averages and not burst protected (usually burst on start).
|
#Limits your upload and download speed globally, all are averages and not burst protected (usually burst on start).
|
||||||
@@ -25,13 +25,13 @@
|
|||||||
|
|
||||||
[notifications]
|
[notifications]
|
||||||
|
|
||||||
PushBulletToken = "o.8sUHemPkTCaty3u7KnyvEBN19EkeT63g" #add your pushbullet api token here to notify of torrent completion to pushbullet
|
PushBulletToken = "" #add your pushbullet api token here to notify of torrent completion to pushbullet
|
||||||
|
|
||||||
[reverseProxy]
|
[reverseProxy]
|
||||||
#This is for setting up goTorrent behind a reverse Proxy (with SSL, reverse proxy with no SSL will require editing the WSS connection to a WS connection manually)
|
#This is for setting up goTorrent behind a reverse Proxy (with SSL, reverse proxy with no SSL will require editing the WSS connection to a WS connection manually)
|
||||||
ProxyEnabled = true #bool, either false or true
|
ProxyEnabled = false #bool, either false or true
|
||||||
#URL is CASE SENSITIVE
|
#URL is CASE SENSITIVE
|
||||||
BaseURL = "derajnet.duckdns.org/gopher/" # MUST be in the format (if you have a subdomain, and must have trailing slash) "yoursubdomain.domain.org/subroute/"
|
BaseURL = "domain.com/subroute/" # MUST be in the format (if you have a subdomain, and must have trailing slash) "yoursubdomain.domain.org/subroute/"
|
||||||
|
|
||||||
[EncryptionPolicy]
|
[EncryptionPolicy]
|
||||||
|
|
||||||
|
@@ -19,6 +19,12 @@ type Message struct {
|
|||||||
|
|
||||||
//Next are the messages the server sends to the client
|
//Next are the messages the server sends to the client
|
||||||
|
|
||||||
|
//AuthResponse is sent when the client fails to perform authentication correctly
|
||||||
|
type AuthResponse struct {
|
||||||
|
MessageType string
|
||||||
|
Payload string
|
||||||
|
}
|
||||||
|
|
||||||
//ServerPushMessage is information (usually logs and status messages) that the server pushes to the client
|
//ServerPushMessage is information (usually logs and status messages) that the server pushes to the client
|
||||||
type ServerPushMessage struct {
|
type ServerPushMessage struct {
|
||||||
MessageType string
|
MessageType string
|
||||||
|
28
main.go
28
main.go
@@ -38,6 +38,9 @@ var (
|
|||||||
var upgrader = websocket.Upgrader{
|
var upgrader = websocket.Upgrader{
|
||||||
ReadBufferSize: 1024,
|
ReadBufferSize: 1024,
|
||||||
WriteBufferSize: 1024,
|
WriteBufferSize: 1024,
|
||||||
|
CheckOrigin: func(r *http.Request) bool {
|
||||||
|
return true
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveHome(w http.ResponseWriter, r *http.Request) {
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -48,8 +51,16 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
|
|||||||
func handleAuthentication(conn *websocket.Conn, db *storm.DB) {
|
func handleAuthentication(conn *websocket.Conn, db *storm.DB) {
|
||||||
msg := Engine.Message{}
|
msg := Engine.Message{}
|
||||||
err := conn.ReadJSON(&msg)
|
err := conn.ReadJSON(&msg)
|
||||||
payloadData := msg.Payload.(map[string]interface{})
|
conn.WriteJSON(msg) //TODO just for testing, remove
|
||||||
clientAuthToken := payloadData["ClientAuthString"].(string)
|
payloadData, ok := msg.Payload.(map[string]interface{})
|
||||||
|
clientAuthToken, tokenOk := payloadData["ClientAuthString"].(string)
|
||||||
|
fmt.Println("ClientAuthToken:", clientAuthToken, "TokenOkay", tokenOk, "PayloadData", payloadData, "PayloadData Okay?", ok)
|
||||||
|
if ok == false || tokenOk == false {
|
||||||
|
authFail := Engine.AuthResponse{MessageType: "authResponse", Payload: "Message Payload in AuthRequest was malformed, closing connection"}
|
||||||
|
conn.WriteJSON(authFail)
|
||||||
|
conn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.WithFields(logrus.Fields{"error": err, "SuppliedToken": clientAuthToken}).Error("Unable to read authentication message")
|
Logger.WithFields(logrus.Fields{"error": err, "SuppliedToken": clientAuthToken}).Error("Unable to read authentication message")
|
||||||
}
|
}
|
||||||
@@ -63,10 +74,15 @@ func handleAuthentication(conn *websocket.Conn, db *storm.DB) {
|
|||||||
return singingKey, nil
|
return singingKey, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
authFail := Engine.AuthResponse{MessageType: "authResponse", Payload: "Parsing of Token failed, ensure you have the correct token! Closing Connection"}
|
||||||
|
conn.WriteJSON(authFail)
|
||||||
Logger.WithFields(logrus.Fields{"error": err, "SuppliedToken": token}).Error("Unable to parse token!")
|
Logger.WithFields(logrus.Fields{"error": err, "SuppliedToken": token}).Error("Unable to parse token!")
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
||||||
|
authTrue := Engine.AuthResponse{MessageType: "authResponse", Payload: "Authentication Verified, proceed with commands."}
|
||||||
|
conn.WriteJSON(authTrue)
|
||||||
fmt.Println("Claims", claims["ClientName"], claims["Issuer"])
|
fmt.Println("Claims", claims["ClientName"], claims["Issuer"])
|
||||||
Authenticated = true
|
Authenticated = true
|
||||||
} else {
|
} else {
|
||||||
@@ -197,7 +213,9 @@ func main() {
|
|||||||
|
|
||||||
router.HandleFunc("/websocket", func(w http.ResponseWriter, r *http.Request) { //websocket is the main data pipe to the frontend
|
router.HandleFunc("/websocket", func(w http.ResponseWriter, r *http.Request) { //websocket is the main data pipe to the frontend
|
||||||
conn, err := upgrader.Upgrade(w, r, nil)
|
conn, err := upgrader.Upgrade(w, r, nil)
|
||||||
fmt.Println("Websocket connection here")
|
fmt.Println("Websocket connection established, awaiting authentication")
|
||||||
|
connResponse := Engine.ServerPushMessage{MessageType: "connectResponse", MessageLevel: "Message", Payload: "Websocket Connection Established, awaiting Authentication"}
|
||||||
|
conn.WriteJSON(&connResponse)
|
||||||
defer conn.Close() //defer closing the websocket until done.
|
defer conn.Close() //defer closing the websocket until done.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.WithFields(logrus.Fields{"error": err}).Fatal("Unable to create websocket!")
|
Logger.WithFields(logrus.Fields{"error": err}).Fatal("Unable to create websocket!")
|
||||||
@@ -206,6 +224,8 @@ func main() {
|
|||||||
if Authenticated != true {
|
if Authenticated != true {
|
||||||
handleAuthentication(conn, db)
|
handleAuthentication(conn, db)
|
||||||
} else { //If we are authenticated inject the connection into the other packages
|
} else { //If we are authenticated inject the connection into the other packages
|
||||||
|
connResponse := Engine.ServerPushMessage{MessageType: "authResponse", MessageLevel: "Message", Payload: "Already Authenticated... Awaiting Commands"}
|
||||||
|
conn.WriteJSON(&connResponse)
|
||||||
Logger.Info("Authenticated, websocket connection available!")
|
Logger.Info("Authenticated, websocket connection available!")
|
||||||
}
|
}
|
||||||
Engine.Conn = conn
|
Engine.Conn = conn
|
||||||
@@ -222,7 +242,7 @@ func main() {
|
|||||||
break MessageLoop
|
break MessageLoop
|
||||||
}
|
}
|
||||||
var payloadData map[string]interface{}
|
var payloadData map[string]interface{}
|
||||||
if msg.Payload != nil {
|
if msg.Payload != nil && msg.Payload != "" {
|
||||||
payloadData = msg.Payload.(map[string]interface{})
|
payloadData = msg.Payload.(map[string]interface{})
|
||||||
}
|
}
|
||||||
Logger.WithFields(logrus.Fields{"message": msg}).Debug("Message From Client")
|
Logger.WithFields(logrus.Fields{"message": msg}).Debug("Message From Client")
|
||||||
|
Reference in New Issue
Block a user