Skip to content

Commit

Permalink
Reverted unintentional merge
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoperini committed Dec 20, 2023
1 parent f4128a6 commit 2a5bb62
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 129 deletions.
78 changes: 2 additions & 76 deletions restapi/api/device_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package api

import (
"bytes"
"fmt"
"github.com/danielpaulus/go-ios/ios/imagemounter"
"github.com/danielpaulus/go-ios/ios/mobileactivation"
"io"
"net/http"
"os"
"sync"

"github.com/danielpaulus/go-ios/ios/mobileactivation"

"github.com/danielpaulus/go-ios/ios"
"github.com/danielpaulus/go-ios/ios/instruments"
"github.com/danielpaulus/go-ios/ios/mcinstall"
Expand Down Expand Up @@ -38,77 +35,6 @@ func Activate(c *gin.Context) {
c.IndentedJSON(http.StatusOK, GenericResponse{Message: "Activation successful"})
}

func GetImages(c *gin.Context) {
device := c.MustGet(IOS_KEY).(ios.DeviceEntry)
conn, err := imagemounter.New(device)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
signatures, err := conn.ListImages()
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}

res := make([]string, len(signatures))
for i, sig := range signatures {
res[i] = fmt.Sprintf("%x", sig)
}
c.JSON(http.StatusOK, res)

}
func InstallImage(c *gin.Context) {
device := c.MustGet(IOS_KEY).(ios.DeviceEntry)
auto := c.Query("auto")
if auto == "true" {
basedir := c.Query("basedir")
if basedir == "" {
basedir = "./devimages"
}

path, err := imagemounter.DownloadImageFor(device, basedir)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
err = imagemounter.MountImage(device, path)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
c.JSON(http.StatusOK, "ok")
return
}
body := c.Request.Body
defer body.Close()

tempfile, err := os.CreateTemp(os.TempDir(), "go-ios")
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
tempfilepath := tempfile.Name()
defer os.Remove(tempfilepath)
_, err = io.Copy(tempfile, body)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
err = tempfile.Close()
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
err = imagemounter.MountImage(device, tempfilepath)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
return
}
c.JSON(http.StatusOK, "ok")
return
}

// Info gets device info
// Info godoc
// @Summary Get lockdown info for a device by udid
Expand Down
20 changes: 6 additions & 14 deletions restapi/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,19 @@ func registerRoutes(router *gin.RouterGroup) {

func simpleDeviceRoutes(device *gin.RouterGroup) {
device.POST("/activate", Activate)

device.GET("/info", Info)
device.GET("/screenshot", Screenshot)
device.PUT("/setlocation", SetLocation)
device.POST("/resetlocation", ResetLocation)
device.GET("/conditions", GetSupportedConditions)
device.PUT("/enable-condition", EnableDeviceCondition)
device.POST("/disable-condition", DisableDeviceCondition)

device.GET("/image", GetImages)
device.PUT("/image", InstallImage)

device.GET("/notifications", streamingMiddleWare, Notifications)

device.GET("/info", Info)
device.GET("/listen", streamingMiddleWare, Listen)

device.POST("/pair", PairDevice)

device.GET("/profiles", GetProfiles)

device.POST("/resetlocation", ResetLocation)
device.GET("/screenshot", Screenshot)
device.PUT("/setlocation", SetLocation)
device.GET("/syslog", streamingMiddleWare, Syslog)

device.GET("/listen", streamingMiddleWare, Listen)
}

func appRoutes(group *gin.RouterGroup) {
Expand Down
42 changes: 3 additions & 39 deletions restapi/api/streaming_endpoints.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
package api

import (
"io"
"net/http"

"github.com/danielpaulus/go-ios/ios"
"github.com/danielpaulus/go-ios/ios/instruments"
"github.com/danielpaulus/go-ios/ios/syslog"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"io"
"net/http"
)

// Notifications uses instruments to get application state change events. It will stream the events as json objects separated by line breaks until it errors out.
// Listen godoc
// @Summary uses instruments to get application state change events
// @Description uses instruments to get application state change events
// @Tags general
// @Produce json
// @Success 200 {object} map[string]interface{}
// @Router /notifications [get]
func Notifications(c *gin.Context) {
device := c.MustGet(IOS_KEY).(ios.DeviceEntry)
listenerFunc, closeFunc, err := instruments.ListenAppStateNotifications(device)
if err != nil {
log.Fatal(err)
}
c.Stream(func(w io.Writer) bool {

notification, err := listenerFunc()
if err != nil {
c.JSON(http.StatusInternalServerError, err)
closeFunc()
return false
}

_, err = w.Write([]byte(MustMarshal(notification)))

if err != nil {
c.JSON(http.StatusInternalServerError, err)
closeFunc()
return false
}
w.Write([]byte("\n"))
return true
})

}

// Syslog
// Listen godoc
// @Summary Uses SSE to connect to the LISTEN command
Expand Down

0 comments on commit 2a5bb62

Please sign in to comment.