mirror of
https://wiilab.wiimart.org/wiimart/WiiSOAP
synced 2025-09-05 21:11:02 +02:00
Graft WiiSOAP to EC's expected request behaviour (#12)
* Update module repo path * Use SOAPAction for request interpretation
This commit is contained in:
parent
f0c243bc9c
commit
0e3490357d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.idea
|
||||
config.xml
|
7
go.mod
7
go.mod
@ -1,8 +1,5 @@
|
||||
module github.com/Apfel/WiiSOAP
|
||||
module github.com/morenatsu-net/WiiSOAP
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.4.1
|
||||
google.golang.org/appengine v1.6.5 // indirect
|
||||
)
|
||||
require github.com/go-sql-driver/mysql v1.5.0
|
||||
|
13
go.sum
13
go.sum
@ -1,11 +1,2 @@
|
||||
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
|
||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
|
38
main.go
38
main.go
@ -24,8 +24,8 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
@ -50,14 +50,10 @@ func main() {
|
||||
fmt.Println("WiiSOAP 0.2.6 Kawauso\n[i] Reading the Config...")
|
||||
|
||||
// Check the Config.
|
||||
configfile, err := os.Open("./config.xml")
|
||||
checkError(err)
|
||||
ioconfig, err := ioutil.ReadAll(configfile)
|
||||
ioconfig, err := ioutil.ReadFile("./config.xml")
|
||||
checkError(err)
|
||||
CON := Config{}
|
||||
err = xml.Unmarshal([]byte(ioconfig), &CON)
|
||||
//fmt.Println(CON)
|
||||
// ^ Printing this shows the password in the commandline, which may be insecure. ^
|
||||
err = xml.Unmarshal(ioconfig, &CON)
|
||||
checkError(err)
|
||||
|
||||
fmt.Println("[i] Initializing core...")
|
||||
@ -73,13 +69,17 @@ func main() {
|
||||
|
||||
// Start the HTTP server.
|
||||
fmt.Printf("Starting HTTP connection (%s)...\nNot using the usual port for HTTP?\nBe sure to use a proxy, otherwise the Wii can't connect!\n", CON.Address)
|
||||
http.HandleFunc("/", handler) // each request calls handler
|
||||
http.HandleFunc("/ecs/services/ECommerceSOAP", handler) // each request calls handler
|
||||
log.Fatal(http.ListenAndServe(CON.Address, nil))
|
||||
|
||||
// From here on out, all special cool things should go into the handler function.
|
||||
}
|
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) {
|
||||
// Figure out the action to handle via header.
|
||||
action := r.Header.Get("SOAPAction")
|
||||
action = parseAction(action, "ecs")
|
||||
|
||||
// Get a sexy new timestamp to use.
|
||||
timestampnano := strconv.FormatInt(time.Now().UTC().Unix(), 10)
|
||||
timestamp := timestampnano + "000"
|
||||
@ -87,14 +87,13 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("[!] Incoming request.")
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
http.Error(w, "[x] Error reading request body...", http.StatusInternalServerError)
|
||||
http.Error(w, "Error reading request body...", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// The switch converts the HTTP Body of the request into a string. There is no need to convert the cases to byte format.
|
||||
switch string(body) {
|
||||
switch action {
|
||||
// TODO: Make the case functions cleaner. (e.g. Should the response be a variable?)
|
||||
// TODO: Update the responses so that they query the SQL Database for the proper information (e.g. Device Code, Token, etc).
|
||||
// TODO: Use Strings.Contains otherwise the program assumes that the whole request MUST only be the keyword.
|
||||
|
||||
case "CheckDeviceStatus":
|
||||
fmt.Println("CDS.")
|
||||
@ -363,3 +362,20 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: Add NUS and CAS SOAP to the case list.
|
||||
fmt.Println("[!] End of Request." + "\n")
|
||||
}
|
||||
|
||||
func namespaceForType(service string) string {
|
||||
return "urn:" + service + ".wsapi.broadon.com"
|
||||
}
|
||||
|
||||
// Expected contents are along the lines of "urn:ecs.wsapi.broadon.com/CheckDeviceStatus"
|
||||
func parseAction(original string, service string) string {
|
||||
prefix := namespaceForType(service) + "/"
|
||||
stripped := strings.Replace(original, prefix, "", 1)
|
||||
|
||||
if stripped == original {
|
||||
// This doesn't appear valid.
|
||||
return ""
|
||||
} else {
|
||||
return stripped
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user