diff --git a/restapi/api/device_endpoints.go b/restapi/api/device_endpoints.go index fa06e61e..c2d4f275 100644 --- a/restapi/api/device_endpoints.go +++ b/restapi/api/device_endpoints.go @@ -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" @@ -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 diff --git a/restapi/api/routes.go b/restapi/api/routes.go index 5c6d7a38..ea983735 100644 --- a/restapi/api/routes.go +++ b/restapi/api/routes.go @@ -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) { diff --git a/restapi/api/streaming_endpoints.go b/restapi/api/streaming_endpoints.go index c9213532..775d2fa1 100644 --- a/restapi/api/streaming_endpoints.go +++ b/restapi/api/streaming_endpoints.go @@ -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