-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnotpro.go
138 lines (111 loc) · 2.23 KB
/
notpro.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
// 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.
//go:build !pro
package main
import (
"eonza/users"
"fmt"
"sync"
"github.com/labstack/echo/v4"
)
const Pro = false
var (
Users map[uint32]users.User
Roles map[uint32]users.Role
proMutex = &sync.Mutex{}
)
func Licensed() bool {
return false
}
func IsProActive() bool {
return false
}
func ProInit(psw []byte, counter uint32) {
Roles, Users = users.InitUsers(psw, counter)
}
func GetRole(id uint32) (role users.Role, ok bool) {
role, ok = Roles[id]
return
}
func GetUser(id uint32) (user users.User, ok bool) {
user, ok = Users[id]
return
}
func GetUserRole(id, idrole uint32) (uname string, rname string) {
if idrole >= users.ResRoleID {
uname, rname = GetSchedulerName(id, idrole)
} else {
if user, ok := Users[id]; ok {
uname = user.Nickname
if role, ok := Roles[user.RoleID]; ok {
rname = role.Name
}
}
}
if len(uname) == 0 {
uname = fmt.Sprintf("%x", id)
}
if len(rname) == 0 {
rname = fmt.Sprintf("%x", idrole)
}
return
}
func GetUsers() []users.User {
user := Users[users.XRootID]
return []users.User{
user,
}
}
func CheckAdmin(c echo.Context) error {
return nil
}
func ScriptAccess(name, ipath string, roleid uint32) error {
return nil
}
func SetActive() {
}
func SetUserPassword(id uint32, hash []byte) error {
proMutex.Lock()
defer proMutex.Unlock()
if user, ok := GetUser(id); ok {
user.PassCounter++
user.PasswordHash = hash
Users[id] = user
}
return nil
}
func IncPassCounter(id uint32) error {
proMutex.Lock()
defer proMutex.Unlock()
if user, ok := GetUser(id); ok {
user.PassCounter++
Users[id] = user
}
return nil
}
func VerifyKey() {
}
func proSettingsHandle(c echo.Context) error {
return jsonError(c, fmt.Errorf(`Unsupported`))
}
func IsTwofa() bool {
return false
}
func IsDecrypted() bool {
return true
}
func TwofaQR(id uint32) (string, error) {
return ``, fmt.Errorf(`Unsupported`)
}
func ValidateOTP(user users.User, otp string) error {
return fmt.Errorf(`Unsupported`)
}
func SecureConstants() map[string]string {
return nil
}
func IsAutoFill() bool {
return false
}
func ProApi(e *echo.Echo) {
}