-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpro.go
More file actions
95 lines (79 loc) · 1.98 KB
/
Copy pathpro.go
File metadata and controls
95 lines (79 loc) · 1.98 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
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
// Copyright 2021 Alexey Krivonogov. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.
package main
import (
"eonza/users"
"fmt"
"net/http"
"time"
"github.com/labstack/echo/v4"
)
type ProOptions struct {
Active bool `json:"active"`
Settings users.ProSettings `json:"settings"`
Storage StorageResponse `json:"storage"`
}
const (
Pro = true
)
func IsProActive() bool {
return true
}
func CheckAdmin(c echo.Context) error {
return AdminAccess(c.(*Auth).User.ID)
}
func GetUserRole(id, idrole uint32) (uname string, rname string) {
if idrole >= users.ResRoleID {
uname, rname = GetSchedulerName(id, idrole)
} else {
uname, rname = ProGetUserRole(id)
}
if len(uname) == 0 {
uname = fmt.Sprintf("%x", id)
}
if len(rname) == 0 {
rname = fmt.Sprintf("%x", idrole)
}
return
}
func GetTitle() string {
ret := storage.Settings.Title
if len(ret) == 0 {
ret = appInfo.Title
} else {
ret += `/eonza`
}
return ret
}
func GetTrialMode() int {
return storage.Trial.Mode
}
func TaskCheck(taskID uint32, userID uint32) (bool, error) {
var status int
if v, ok := tasks[taskID]; ok && v.UserID == userID {
status = v.Status
if v.Status == TaskActive || v.Status == TaskWaiting ||
(v.Status == TaskFinished && time.Now().Unix() <= v.FinishTime+1) {
return v.Status < TaskFinished, nil
}
}
return status < TaskFinished, fmt.Errorf(`access denied task %d / user %d`, taskID, userID)
}
func ProInit(psw []byte, counter uint32) {
CallbackPassCounter = StoragePassCounter
CallbackTitle = GetTitle
CallbackTrial = GetTrialMode
CallbackTaskCheck = TaskCheck
LoadPro(psw, counter, cfg.path, cfg.Users.Dir)
}
func proSettingsHandle(c echo.Context) error {
var response ProOptions
if err := CheckAdmin(c); err != nil {
return jsonError(c, err)
}
response.Active = IsProActive()
response.Settings = ProSettings()
response.Storage = PassStorage()
return c.JSON(http.StatusOK, &response)
}