-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_HTTP_Handlers.go
128 lines (104 loc) · 2.76 KB
/
mod_HTTP_Handlers.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"fmt"
"image/png"
"log"
"net/http"
"strings"
"github.com/casbin/casbin"
"github.com/gin-gonic/gin"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
"github.com/fogleman/gg"
)
func indexHandler(ctx *gin.Context) {
var ipas []Ipa
ipas, _ = SQLiteGetIpas()
for id, ipa := range ipas {
ipas[id].URL = fmt.Sprintf("%s/ipa/%s/%s", cfg.Service.Url, ipa.SHA256, ipa.FileName)
}
e := casbin.NewEnforcer("./model.conf", "./policy.csv")
//log.Println(ctx.Value("user"))
// Admin rights
if user := ctx.Value("user"); user != nil {
if e.Enforce(user, "index", "write") {
ctx.HTML(http.StatusOK, "index", gin.H{
"title": "IPA Manager",
"version": version,
"ipas": ipas,
"admin": 1,
"service_url": cfg.Service.Url,
},
)
return
}
}
// Guest rights
ctx.HTML(http.StatusOK, "index", gin.H{
"title": "IPA Manager",
"version": version,
"ipas": ipas,
"admin": 0,
"service_url": cfg.Service.Url,
},
)
}
func removeHandler(ctx *gin.Context) {
var ipa Ipa
var id = ctx.PostForm("id")
ipa, _ = SQLiteGetIpa(id)
RemoveDir(fmt.Sprintf(".\\ipa\\%s", ipa.SHA256))
SQLiteDelIpa(ipa)
ctx.Redirect(http.StatusMovedPermanently, cfg.Service.Url)
log.Println("Ipa delete has completed")
}
func versionHandler(ctx *gin.Context) {
var ipa Ipa
var sha256 = ctx.Param("sha256")
ipa, _ = SQLiteFindIpa(sha256)
ipa.URL = fmt.Sprintf("%s/ipa/%s/%s", cfg.Service.Url, ipa.SHA256, ipa.FileName)
ctx.HTML(http.StatusOK, "version/index", gin.H{
"title": "IPA Manager",
"ipa": ipa,
"service_url": cfg.Service.Url,
},
)
}
func qrHandler(ctx *gin.Context) {
dataString := ctx.PostForm("url")
CFBundleIdentifier := ctx.PostForm("CFBundleIdentifier")
version := CFBundleIdentifier + " - " + ctx.PostForm("version")
qrCode, _ := qr.Encode(dataString, qr.L, qr.Auto)
qrCode, _ = barcode.Scale(qrCode, 600, 600)
im := qrCode
dc := gg.NewContext(600, 626)
dc.SetRGB(1, 1, 1)
dc.Clear()
dc.SetRGB(0, 0, 0)
if err := dc.LoadFontFace("arial.ttf", 16); err != nil {
panic(err)
}
dc.DrawRoundedRectangle(0, 0, 600, 626, 0)
dc.DrawImage(im, 0, 0)
dc.DrawStringAnchored(version, 300, 615, 0.5, 0)
dc.Clip()
png.Encode(ctx.Writer, dc.Image())
ctx.String(http.StatusOK, "Done")
}
func postIpaHandler(ctx *gin.Context) {
file, err := ctx.FormFile("file")
if err != nil {
log.Fatal(err)
}
if !strings.HasSuffix(file.Filename, ".ipa") {
ctx.JSON(http.StatusBadRequest, gin.H{"responce": "Invalid file extension"})
return
}
//log.Println(file.Filename)
err = ctx.SaveUploadedFile(file, "./temp/"+file.Filename)
if err != nil {
log.Fatal(err)
}
ipaProcessor("./temp", file.Filename)
ctx.JSON(http.StatusOK, gin.H{"responce": "File processed"})
}