forked from bitcoinmoneydigital/WebBitcoinEscrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
667 lines (609 loc) · 19.5 KB
/
main.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"html/template"
"io"
"io/ioutil"
"net/http"
"regexp"
"strconv"
"strings"
"time"
"github.com/didip/tollbooth"
"github.com/didip/tollbooth/limiter"
"github.com/didip/tollbooth_echo"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/rs/xid"
"golang.org/x/crypto/bcrypt"
"github.com/tidwall/gjson"
)
//To make global db access possible
//Could be implemented with closures
var db2 *gorm.DB
var db4 *gorm.DB
type Product struct {
gorm.Model
UID string
NameA string
NameB string
Comment string
BtcBetrag string
BtcAdressA string
BtcAdressAausgezahlt bool `gorm:"default:false"`
BtcAdressEscrow string
BtcAdressEscrowFunded bool `gorm:"default:false"`
URLPanel string
URLB string
URLBFrei string
URLBFreiGenerated bool `gorm:"default:false"`
TradeReleasedB bool `gorm:"default:false"`
TradeEscaledB bool `gorm:"default:false"`
}
//Todo is astruct to hold data
type Todo struct {
UserPanel string
UserPanels string
Tradestatus string
TradeStatusColor string
Empfname string
Empfadresse string
Zahlpf string
Ubfrei string
Ubfrei2 string
}
//TodoPageData is a struc that helps
type TodoPageData struct {
Todos []Todo
Empty string
}
type Template struct {
templates *template.Template
}
type Settings struct {
gorm.Model
AdminPass string
AdminUser string
BlockchainUser string
BlockchainPassword string
Multi float64
}
func HashPassword(password string) string {
bytes, _ := bcrypt.GenerateFromPassword([]byte(password), 4)
return string(bytes)
}
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}
//validates btc adress
func validateBTCa(tx string) bool {
url := "http://codacoin.com/api/public.php?request=validate&address=" + tx
response, _ := http.Get(url)
defer response.Body.Close()
c, _ := ioutil.ReadAll(response.Body)
t := strings.TrimSpace(string(c))
if t == "Valid" {
return true
}
return false
}
//hashthis reuturns hash as string
func hashthis(password string) string {
h := sha256.New()
h.Write([]byte(password))
b := h.Sum(nil)
return hex.EncodeToString(b)
}
//returns new generated BTC adress
func getNewAdressBTC(label string, UID string, pwd string) string {
response, err := http.Get("http://localhost:3000/merchant/" + UID +
"/new_address?password=" + pwd + "&label=" + label)
if err != nil {
return "False"
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return "False"
}
value := gjson.Get(string(contents), "address")
return value.String()
}
//returns converted satoshi to btc of adress
func getBalanceBTC(adress string, UID string, pwd string) string {
response, err := http.Get("http://localhost:3000/merchant/" + UID +
"/address_balance?password=" + pwd + "&address=" + adress)
if err != nil {
return "False"
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return "False"
}
value := gjson.Get(string(contents), "balance")
bf, _ := strconv.ParseFloat(value.String(), 64)
bff := 0.00000001 * bf
bfff := strconv.FormatFloat(bff, 'f', 8, 64)
return bfff
}
//sends satoshi to btc adress
func payAdressBTC(UID string, pwd string, outAdr string, amount string) string {
bf, _ := strconv.ParseFloat(amount, 64)
bff := int(bf * 100000000)
bfff := strconv.Itoa(bff)
url := "http://localhost:3000/merchant/" + UID + "/payment?password=" + pwd + "&to=" + outAdr + "&amount=" + bfff
response, err := http.Get(url)
if err != nil {
return "False"
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return "False"
}
suc := gjson.Get(string(contents), "success").Bool()
if suc == true {
return "True"
}
return "False"
}
//Render executes the template and returns it
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}
func InDex(c echo.Context) error {
return c.Render(http.StatusOK, "forms.html", map[string]interface{}{})
}
func GenIndex(c echo.Context) error {
//map to render
fview := map[string]interface{}{}
withouterror := true
//parsing of betrag
formValueBetrag := c.FormValue("betrag")
if formValueBetrag == "" || len(formValueBetrag) > 50 {
fview["FORM1_WARN"] = "This field must be filled in."
fview["FORM1_WARN_d"] = "is-danger"
fview["FORM1_WARN_ca"] = "fas fa-exclamation-triangle"
withouterror = false
}
betrag, err := strconv.ParseFloat(formValueBetrag, 64)
if err != nil || betrag < 0.00001 {
fview["FORM1_WARN"] = "Incorrect amount!"
fview["FORM1_WARN_d"] = "is-danger"
fview["FORM1_WARN_ca"] = "fas fa-exclamation-triangle"
withouterror = false
} else {
fview["FORM1_WARN_ca"] = "fas fa-check"
fview["FORM1_WARN_d"] = "is-success"
fview["FORM1_WARN_d_v"] = formValueBetrag
}
//parsing of address
formValueAdress := c.FormValue("adress")
if formValueAdress == "" || len(formValueAdress) > 40 {
fview["FORM2_WARN"] = "Please enter a Bitcoin address!"
fview["FORM2_WARN_d"] = "is-danger"
fview["FORM2_WARN_ca"] = "fas fa-exclamation-triangle"
withouterror = false
}
if m, _ := regexp.MatchString("^([13][a-km-zA-HJ-NP-Z1-9]{25,34})", formValueAdress); !m {
fview["FORM2_WARN"] = "Not a valid address!"
fview["FORM2_WARN_d"] = "is-danger"
fview["FORM2_WARN_ca"] = "fas fa-exclamation-triangle"
withouterror = false
} else {
if validateBTCa(formValueAdress) != true {
fview["FORM2_WARN"] = "Not a valid address!"
fview["FORM2_WARN_d"] = "is-danger"
fview["FORM2_WARN_ca"] = "fas fa-exclamation-triangle"
withouterror = false
} else {
fview["FORM2_WARN_ca"] = "fas fa-check"
fview["FORM2_WARN_d"] = "is-success"
fview["FORM2_WARN_d_v"] = formValueAdress
}
}
//parsing of empf
formValueEmpf := c.FormValue("empf")
if formValueEmpf == "" || len(formValueEmpf) > 100 || formValueEmpf == "Diddy" {
fview["FORM3_WARN"] = "Creditor is missing!"
fview["FORM3_WARN_d"] = "is-danger"
fview["FORM3_WARN_ca"] = "fas fa-exclamation-triangle"
withouterror = false
} else {
fview["FORM3_WARN_ca"] = "fas fa-check"
fview["FORM3_WARN_d"] = "is-success"
fview["FORM3_WARN_d_v"] = formValueEmpf
}
//parsing of zahl
formValueZahl := c.FormValue("zahl")
if formValueZahl == "" || len(formValueZahl) > 100 || formValueZahl == "Diddy" {
fview["FORM4_WARN"] = "Debtor missing!"
fview["FORM4_WARN_d"] = "is-danger"
fview["FORM4_WARN_ca"] = "fas fa-exclamation-triangle"
withouterror = false
} else {
fview["FORM4_WARN_ca"] = "fas fa-check"
fview["FORM4_WARN_d"] = "is-success"
fview["FORM4_WARN_d_v"] = formValueZahl
}
//parsing of com
formValueCom := c.FormValue("comment")
if formValueCom == "" || len(formValueCom) > 1000 || len(formValueCom) < 10 {
fview["FORM5_WARN"] = "Please revise conditions!"
fview["FORM5_WARN_d]"] = "is-danger"
withouterror = false
} else {
fview["FORM5_WARN_d"] = "is-success"
fview["FORM5_WARN_d_v"] = formValueCom
}
if withouterror == false {
return c.Render(http.StatusOK, "forms.html", fview)
}
fview2 := map[string]interface{}{}
fview2["BETRAG"] = formValueBetrag
fview2["ADRESS"] = formValueAdress
fview2["EMPF"] = formValueEmpf
fview2["ZAHL"] = formValueZahl
fview2["CO"] = formValueCom
return c.Render(http.StatusOK, "sum.html", fview2)
}
func GenFinal(c echo.Context) error {
b := c.FormValue("betrag")
a := c.FormValue("adress")
e := c.FormValue("empf")
z := c.FormValue("zahl")
co := c.FormValue("co")
//this should make it faster
c1 := make(chan string, 1)
c3 := make(chan string, 1)
go func() {
unid := xid.New().String()
c1 <- unid
c1 <- hashthis(unid)
}()
go func() {
c3 <- hashthis(xid.New().String())
}()
unid2 := <-c1
panelid := <-c1
u2 := <-c3
bf, _ := strconv.ParseFloat(b, 64)
user := Settings{}
db4.First(&user)
bff := bf * user.Multi
bfff := strconv.FormatFloat(bff, 'f', 8, 64)
thbtcad := getNewAdressBTC(unid2, user.BlockchainUser, user.BlockchainPassword)
if thbtcad == "False" {
return c.String(http.StatusOK, "Error: Could not generate address.")
}
db2.Create(&Product{UID: unid2, NameA: e, NameB: z, Comment: co,
BtcBetrag: bfff, BtcAdressA: a, URLPanel: panelid, URLB: u2, BtcAdressEscrow: thbtcad})
r := c.Request()
currentURL := c.Scheme() + "://" + r.Host
fview := map[string]interface{}{}
fview["TRANSURL"] = currentURL + "/trans/" + panelid
fview["ZAHLURL"] = currentURL + "/ub/" + u2
return c.Render(http.StatusOK, "final.html", fview)
}
func transPanel(c echo.Context) error {
fview := map[string]interface{}{}
// User ID from path `users/:id`
id := c.Param("id")
// Read
var product Product
db2.Where("url_panel = ?", id).First(&product)
if len(product.URLPanel) < 10 {
fview["MESS"] = "URL not found!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if product.TradeReleasedB == true && product.BtcAdressEscrowFunded == true {
fview["MESS"] = "The escrow has already been finalised!"
return c.Render(http.StatusOK, "mess.html", fview)
}
fview["BETRAG"] = product.BtcBetrag
fview["TREUAD"] = product.BtcAdressEscrow
if product.BtcAdressEscrowFunded == false {
user := Settings{}
db4.First(&user)
//ba := getBalanceBTC(string(product.BtcAdressEscrow), user.AdminUser, user.BlockchainPassword)
ba := getBalanceBTC(product.BtcAdressEscrow, user.BlockchainUser, user.BlockchainPassword)
if ba != "False" {
fmt.Println(product.BtcAdressEscrow, ba)
if ba >= product.BtcBetrag {
db2.Model(&product).Update("BtcAdressEscrowFunded", true)
}
}
}
if product.BtcAdressEscrowFunded == true {
fview["TREUADSTAT"] = "Funded"
fview["TREUADSTAT_f"] = "green"
} else {
fview["TREUADSTAT"] = "Unfunded"
fview["TREUADSTAT_f"] = "red"
}
fview["STATTRANS"] = "Open"
fview["STATTRANS_f"] = "yellow"
if product.TradeReleasedB == true {
fview["STATTRANS"] = "Released"
fview["STATTRANS_f"] = "green"
}
if product.TradeEscaledB == true {
fview["STATTRANS"] = "Escalated"
fview["STATTRANS_f"] = "red"
}
if product.URLBFreiGenerated == true {
fview["ZAHLGEN"] = "Yes"
fview["ZAHLGEN_f"] = "green"
} else {
fview["ZAHLGEN"] = "No"
fview["ZAHLGEN_f"] = "red"
}
fview["EMPF"] = product.NameA
fview["ZAHL"] = product.NameB
fview["CO"] = product.Comment
return c.Render(http.StatusOK, "trans.html", fview)
}
func userbPanel(c echo.Context) error {
fview := map[string]interface{}{}
// User ID from path `users/:id`
id := c.Param("id")
// Read
var product Product
db2.Where("url_b = ?", id).First(&product)
if len(product.URLB) < 10 {
fview["MESS"] = "URL not found!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if product.URLBFreiGenerated == true {
fview["MESS"] = "URL has already been used!"
return c.Render(http.StatusOK, "mess.html", fview)
}
fview["CURL"] = id
return c.Render(http.StatusOK, "userb.html", fview)
}
func userbPanelGen(c echo.Context) error {
fview := map[string]interface{}{}
b := c.FormValue("curl")
var product Product
db2.Where("url_b = ?", b).First(&product)
if len(product.URLB) < 10 {
fview["MESS"] = "URL not found!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if product.URLBFreiGenerated == true {
fview["MESS"] = "URL has already been used!"
return c.Render(http.StatusOK, "mess.html", fview)
}
flink := hashthis(xid.New().String())
r := c.Request()
currentURL := c.Scheme() + "://" + r.Host // r.URL.pathy
fview["TRANSURL"] = currentURL + "/ub/release/" + flink
db2.Model(&product).Update("URLBFrei", flink)
db2.Model(&product).Update("URLBFreiGenerated", true)
return c.Render(http.StatusOK, "userbf.html", fview)
}
func userbPanelRelease(c echo.Context) error {
fview := map[string]interface{}{}
// User ID from path `users/:id`
id := c.Param("id")
// Read
var product Product
db2.Where("url_b_frei = ?", id).First(&product)
if len(product.URLBFrei) < 10 {
fview["MESS"] = "URL not found!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if product.TradeReleasedB == true {
fview["MESS"] = "Escrow has already been released!"
return c.Render(http.StatusOK, "mess.html", fview)
}
fview["CURL"] = id
return c.Render(http.StatusOK, "ff.html", fview)
}
func userbPanelReleaseFinal(c echo.Context) error {
fview := map[string]interface{}{}
id := c.FormValue("curl")
fmt.Println("dsfdf")
var product Product
db2.Where("url_b_frei = ?", id).First(&product)
if len(product.URLBFrei) < 10 {
fview["MESS"] = "URL not found!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if product.TradeReleasedB == true {
fview["MESS"] = "Escrow has already been released!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if product.BtcAdressEscrowFunded == false && c.FormValue("es") == "false" {
fview["MESS"] = "Escrow cannot be released if no money has been deposited yet!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if product.BtcAdressEscrowFunded == false && c.FormValue("es") == "true" {
fview["MESS"] = "Escrow cannot be escalated if no money has been deposited yet!"
return c.Render(http.StatusOK, "mess.html", fview)
}
be := c.FormValue("be")
if be == "true" {
user := Settings{}
db4.First(&user)
//b := payAdressBTC(user.BlockchainUser, user.BlockchainPassword, product.BtcAdressA, product.BtcBetrag)
fmt.Println(user.BlockchainUser, user.BlockchainPassword, product.BtcAdressA, product.BtcBetrag)
b := "True"
if b == "True" {
db2.Model(&product).Update("BtcAdressAausgezahlt", true)
fview["MESS"] = "Thank you very much, the escrow has been released."
db2.Model(&product).Update("TradeReleasedB", true)
return c.Render(http.StatusOK, "mess.html", fview)
}
fview["MESS"] = "Can not be paid out please contact the admin or try again!"
return c.Render(http.StatusOK, "mess.html", fview)
}
es := c.FormValue("es")
if es == "true" {
db2.Model(&product).Update("TradeEscaledB", true)
fview["MESS"] = "The Escrow has been escalated!"
return c.Render(http.StatusOK, "mess.html", fview)
}
fview["MESS"] = "Error"
return c.Render(http.StatusOK, "mess.html", fview)
}
func adminuserbPanelReleaseFinal(c echo.Context) error {
fview := map[string]interface{}{}
id := c.Param("id")
var product Product
db2.Where("url_b_frei = ?", id).First(&product)
if len(product.URLBFrei) < 10 {
fview["MESS"] = "URL not found!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if product.TradeReleasedB == true {
fview["MESS"] = "Escrow has already been released!"
return c.Render(http.StatusOK, "mess.html", fview)
}
fview["MESS"] = "The escrow has been terminated."
db2.Model(&product).Update("TradeReleasedB", true)
db2.Model(&product).Update("BtcAdressEscrowFunded", true)
return c.Render(http.StatusOK, "mess.html", fview)
}
func adminPanel(c echo.Context) error {
r := c.Request()
currentURL := c.Scheme() + "://" + r.Host // r.URL.pathy
p := []Product{}
db2.Where("trade_escaled_b = ?", true).Find(&p)
s := []Todo{}
for _, v := range p {
if v.TradeReleasedB == false {
tro := "Escalated"
trof := "red"
item1 := Todo{UserPanel: currentURL + "/trans/" + v.URLPanel, UserPanels: v.URLPanel[:15], Tradestatus: tro, TradeStatusColor: trof,
Empfname: v.NameA, Empfadresse: v.BtcAdressA, Ubfrei2: currentURL + "/admin/tb/" + v.URLBFrei,
Zahlpf: v.NameB, Ubfrei: currentURL + "/ub/release/" + v.URLBFrei}
s = append(s, item1)
}
}
var m string
if len(s) < 1 {
m = "No escalated escrow pending."
}
data := TodoPageData{
Empty: m,
Todos: s,
}
fmt.Println(data)
return c.Render(http.StatusOK, "admin.html", data)
}
func adminPanelSettings(c echo.Context) error {
fview := map[string]interface{}{}
user := Settings{}
db4.First(&user)
fview["BlockchainUser"] = user.BlockchainUser
fview["BlockchainPassword"] = user.BlockchainPassword
fview["Multi"] = user.Multi
return c.Render(http.StatusOK, "settings.html", fview)
}
func adminPanelSettingsChange(c echo.Context) error {
fview := map[string]interface{}{}
u := c.FormValue("uname")
p := c.FormValue("pwd")
bu := c.FormValue("buname")
bp := c.FormValue("bpwd")
mul := c.FormValue("multi")
if len(u) > 0 && len(p) > 0 {
user := Settings{}
db4.First(&user)
user.AdminUser = HashPassword(u)
user.AdminPass = HashPassword(p)
db4.Save(&user)
fview["MESS"] = "The data has been updated!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if len(bu) > 0 && len(bp) > 0 {
user := Settings{}
db4.First(&user)
user.BlockchainUser = bu
user.BlockchainPassword = bp
db4.Save(&user)
fview["MESS"] = "The data has been updated!"
return c.Render(http.StatusOK, "mess.html", fview)
}
if len(mul) > 0 {
user := Settings{}
db4.First(&user)
mul2, _ := strconv.ParseFloat(mul, 64)
user.Multi = mul2
db4.Save(&user)
fview["MESS"] = "The data has been updated!"
return c.Render(http.StatusOK, "mess.html", fview)
}
return c.Render(http.StatusOK, "settings.html", fview)
}
func main() {
db, err := gorm.Open("sqlite3", "escrow.db")
db2 = db
if err != nil {
panic("failed to connect database")
}
// Migrate the schema
db2.AutoMigrate(&Product{})
defer db.Close()
db3, err := gorm.Open("sqlite3", "settings.db")
db4 = db3
if err != nil {
panic("failed to connect database")
}
// Migrate the schema
db3.AutoMigrate(&Settings{})
ss := Settings{AdminUser: HashPassword("Admin"), AdminPass: HashPassword("Admin"),
BlockchainUser: "Please enter UID",
BlockchainPassword: "Please enter your password", Multi: 0.5}
db3.Create(&ss)
defer db3.Close()
t := &Template{
templates: template.Must(template.ParseGlob("static/*.html")),
}
// Create a request limitier to prevent flooding.
lmt := tollbooth.NewLimiter(3, &limiter.ExpirableOptions{DefaultExpirationTTL: time.Hour})
lmtAdmin := tollbooth.NewLimiter(2, &limiter.ExpirableOptions{DefaultExpirationTTL: time.Hour})
// Set a custom message.
lmt.SetMessage("You have reached maximum request limit.")
lmtAdmin.SetMessage("You have reached maximum request limit.")
e := echo.New()
e.Pre(middleware.RemoveTrailingSlash())
e.Use(middleware.Recover())
e.Use(middleware.Logger())
e.Use(middleware.BodyLimit("1M"))
e.Use(middleware.Secure())
e.Use(middleware.Gzip())
e.Static("/", "assets")
e.Renderer = t //register templates t
e.GET("/", InDex, tollbooth_echo.LimitHandler(lmt))
e.POST("/gen", GenIndex, tollbooth_echo.LimitHandler(lmt))
e.POST("/gen/final", GenFinal, tollbooth_echo.LimitHandler(lmt))
e.GET("/trans/:id", transPanel, tollbooth_echo.LimitHandler(lmt))
e.GET("/ub/:id", userbPanel, tollbooth_echo.LimitHandler(lmt))
e.POST("/ub/gen", userbPanelGen, tollbooth_echo.LimitHandler(lmt))
e.GET("/ub/release/:id", userbPanelRelease, tollbooth_echo.LimitHandler(lmt))
e.POST("/ub/release/final", userbPanelReleaseFinal, tollbooth_echo.LimitHandler(lmt))
// Group level middleware for Admin Panel
g := e.Group("/admin", tollbooth_echo.LimitHandler(lmtAdmin))
g.Use(middleware.RemoveTrailingSlash())
g.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
user := Settings{}
db4.First(&user)
if CheckPasswordHash(username, user.AdminUser) && CheckPasswordHash(password, user.AdminPass) {
return true, nil
}
return false, nil
}))
g.GET("", adminPanel)
g.GET("/settings", adminPanelSettings)
g.POST("/settings/change", adminPanelSettingsChange)
g.GET("/tb/:id", adminuserbPanelReleaseFinal)
e.Start(":80") //Change here the port of the webapp
}