-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver_pipe.go
More file actions
65 lines (56 loc) · 1.6 KB
/
server_pipe.go
File metadata and controls
65 lines (56 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func serverAddPipe(pipe *gin.RouterGroup) {
// Open a Rizin pipe for a page.
pipe.GET("/open/:unique", func(c *gin.Context) {
unique := c.Param("unique")
if !IsValidNonce(unique, PageNonceSize) {
c.HTML(http.StatusBadRequest, "error.tmpl", gin.H{
"root": webroot,
"error": "invalid page identifier",
})
return
}
page, err := catalog.GetPage(unique)
if err != nil || page == nil {
c.HTML(http.StatusNotFound, "error.tmpl", gin.H{
"root": webroot,
"error": "page not found",
})
return
}
if page.Binary == "" {
c.HTML(http.StatusBadRequest, "error.tmpl", gin.H{
"root": webroot,
"error": "This page has no binary attached yet. Attach one from the edit page before opening a Rizin pipe.",
"location": webroot + "edit/" + unique,
})
return
}
if notebook.open(unique, true) == nil {
c.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{
"root": webroot,
"error": "Failed to open Rizin pipe. Check that the binary file exists and rizin is installed.",
"location": webroot + "view/" + unique,
})
return
}
c.Redirect(http.StatusFound, webroot+"view/"+unique)
})
// Close a Rizin pipe for a page.
pipe.GET("/close/:unique", func(c *gin.Context) {
unique := c.Param("unique")
if !IsValidNonce(unique, PageNonceSize) {
c.HTML(http.StatusBadRequest, "error.tmpl", gin.H{
"root": webroot,
"error": "invalid page identifier",
})
return
}
notebook.closePipe(unique)
c.Redirect(http.StatusFound, webroot+"view/"+unique)
})
}