lupine.api 1.1.57 → 1.1.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/admin/admin-about.tsx +12 -16
- package/admin/admin-config.tsx +47 -44
- package/admin/admin-css.tsx +3 -3
- package/admin/admin-db.tsx +75 -75
- package/admin/admin-frame-helper.tsx +364 -364
- package/admin/admin-frame.tsx +164 -164
- package/admin/admin-index.tsx +65 -65
- package/admin/admin-login.tsx +111 -111
- package/admin/admin-menu-edit.tsx +637 -637
- package/admin/admin-menu-list.tsx +87 -87
- package/admin/admin-page-edit.tsx +564 -564
- package/admin/admin-page-list.tsx +83 -83
- package/admin/admin-performance.tsx +28 -28
- package/admin/admin-release.tsx +427 -404
- package/admin/admin-resources.tsx +382 -382
- package/admin/admin-shell.tsx +89 -89
- package/admin/admin-table-data.tsx +146 -146
- package/admin/admin-table-list.tsx +230 -230
- package/admin/admin-test-animations.tsx +395 -395
- package/admin/admin-test-component.tsx +823 -808
- package/admin/admin-test-edit.tsx +319 -319
- package/admin/admin-test-themes.tsx +56 -56
- package/admin/admin-tokens.tsx +338 -338
- package/admin/design/admin-design.tsx +174 -174
- package/admin/design/block-grid.tsx +36 -36
- package/admin/design/block-grid1.tsx +21 -21
- package/admin/design/block-paragraph.tsx +19 -19
- package/admin/design/block-title.tsx +19 -19
- package/admin/design/design-block-box.tsx +140 -140
- package/admin/design/drag-data.tsx +24 -24
- package/admin/index.ts +9 -9
- package/admin/package.json +15 -15
- package/admin/tsconfig.json +127 -127
- package/dev/copy-folder.js +32 -32
- package/dev/cp-index-html.js +69 -69
- package/dev/file-utils.js +12 -12
- package/dev/index.js +18 -19
- package/dev/package.json +12 -12
- package/dev/plugin-ifelse.js +168 -168
- package/dev/plugin-ifelse.test.js +37 -37
- package/dev/run-cmd.js +14 -14
- package/dev/send-request.js +12 -12
- package/package.json +55 -55
- package/src/admin-api/admin-api-helper.ts +210 -205
- package/src/admin-api/admin-api.ts +65 -65
- package/src/admin-api/admin-auth.ts +152 -146
- package/src/admin-api/admin-config.ts +94 -84
- package/src/admin-api/admin-csv.ts +94 -94
- package/src/admin-api/admin-db.ts +269 -269
- package/src/admin-api/admin-menu.ts +135 -135
- package/src/admin-api/admin-page.ts +135 -135
- package/src/admin-api/admin-performance.ts +128 -128
- package/src/admin-api/admin-release.ts +703 -700
- package/src/admin-api/admin-resources.ts +318 -318
- package/src/admin-api/admin-token-helper.ts +82 -79
- package/src/admin-api/admin-tokens.ts +90 -90
- package/src/admin-api/index.ts +2 -2
- package/src/admin-api/web-config-api.ts +19 -19
- package/src/api/api-cache.ts +103 -103
- package/src/api/api-helper.ts +44 -44
- package/src/api/api-module.ts +67 -60
- package/src/api/api-router.ts +177 -177
- package/src/api/api-shared-storage.ts +64 -64
- package/src/api/async-storage.ts +5 -5
- package/src/api/debug-service.ts +56 -56
- package/src/api/encode-html.ts +27 -27
- package/src/api/handle-status.ts +75 -75
- package/src/api/index.ts +15 -16
- package/src/api/mini-web-socket.ts +270 -270
- package/src/api/server-content-type.ts +82 -82
- package/src/api/server-render.ts +235 -215
- package/src/api/shell-service.ts +74 -74
- package/src/api/simple-storage.ts +80 -80
- package/src/api/static-server.ts +128 -125
- package/src/api/to-client-delivery.ts +26 -26
- package/src/app/app-cache.ts +55 -55
- package/src/app/app-helper.ts +62 -62
- package/src/app/app-message.ts +109 -109
- package/src/app/app-shared-storage.ts +363 -363
- package/src/app/app-start.ts +136 -136
- package/src/app/cleanup-exit.ts +16 -16
- package/src/app/host-to-path.ts +38 -38
- package/src/app/index.ts +11 -11
- package/src/app/process-dev-requests.ts +130 -130
- package/src/app/web-listener.ts +294 -294
- package/src/app/web-processor.ts +47 -42
- package/src/app/web-server.ts +100 -100
- package/src/common-js/web-env.js +104 -104
- package/src/index.ts +7 -7
- package/src/lang/api-lang-en.ts +26 -26
- package/src/lang/api-lang-zh-cn.ts +27 -27
- package/src/lang/index.ts +2 -2
- package/src/lang/lang-helper.ts +76 -76
- package/src/lang/lang-props.ts +6 -6
- package/src/lib/db/db-helper.ts +23 -23
- package/src/lib/db/db-mysql.ts +249 -250
- package/src/lib/db/db-sqlite.ts +101 -101
- package/src/lib/db/db.spec.ts +28 -28
- package/src/lib/db/db.ts +325 -325
- package/src/lib/db/index.ts +5 -5
- package/src/lib/index.ts +3 -3
- package/src/lib/logger.spec.ts +214 -214
- package/src/lib/logger.ts +281 -281
- package/src/lib/runtime-require.ts +37 -37
- package/src/lib/utils/cookie-util.ts +34 -34
- package/src/lib/utils/crypto.ts +58 -58
- package/src/lib/utils/date-utils.ts +317 -317
- package/src/lib/utils/deep-merge.ts +37 -37
- package/src/lib/utils/delay.ts +12 -12
- package/src/lib/utils/file-setting.ts +55 -55
- package/src/lib/utils/format-bytes.ts +11 -11
- package/src/lib/utils/fs-utils.ts +158 -158
- package/src/lib/utils/get-env.ts +27 -27
- package/src/lib/utils/index.ts +12 -12
- package/src/lib/utils/is-type.ts +48 -48
- package/src/lib/utils/load-env.ts +14 -14
- package/src/lib/utils/pad.ts +6 -6
- package/src/models/api-base.ts +5 -5
- package/src/models/api-module-props.ts +10 -11
- package/src/models/api-router-props.ts +26 -26
- package/src/models/app-cache-props.ts +33 -33
- package/src/models/app-data-props.ts +10 -10
- package/src/models/app-helper-props.ts +6 -6
- package/src/models/app-shared-storage-props.ts +38 -38
- package/src/models/app-start-props.ts +18 -18
- package/src/models/async-storage-props.ts +13 -13
- package/src/models/db-config.ts +30 -30
- package/src/models/host-to-path-props.ts +12 -12
- package/src/models/index.ts +16 -16
- package/src/models/json-object.ts +8 -8
- package/src/models/locals-props.ts +36 -36
- package/src/models/logger-props.ts +84 -84
- package/src/models/simple-storage-props.ts +13 -14
- package/src/models/to-client-delivery-props.ts +6 -6
- package/tsconfig.json +115 -115
- package/dev/plugin-gen-versions.js +0 -20
|
@@ -1,205 +1,210 @@
|
|
|
1
|
-
import { ServerResponse } from 'http';
|
|
2
|
-
import { ApiHelper } from '../api';
|
|
3
|
-
import { CryptoUtils, Logger } from '../lib';
|
|
4
|
-
import { ServerRequest } from '../models';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
dev-admin uses different authentication method from frontend.
|
|
8
|
-
dev-admin only provides fixed username and password authentication, no user maintenance.
|
|
9
|
-
saved cookie name: _token_dev
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
// DEFAULT_ADMIN_PASS is DEFAULT_ADMIN_NAME + ':' + login password hash.
|
|
13
|
-
// Use below command to generate hash:
|
|
14
|
-
// node -e "console.log(require('crypto').createHash('md5').update('admin:F4AZ5O@2fPUjw%f$LmhZpJTQ^DoXnWPkH#hqE', 'utf8').digest('hex'))"
|
|
15
|
-
export type DevAdminSessionProps = {
|
|
16
|
-
u: string; // username
|
|
17
|
-
t: string; // type: admin, user
|
|
18
|
-
ip: string;
|
|
19
|
-
h: string; // md5 of name+pass
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
dev admin has more permissions than app admin, and the dashboard also supports for app admin only users.
|
|
24
|
-
app admin is supposed to manage the application, not the site, and may have different fields in cookie.
|
|
25
|
-
This is a sample how to set login process for app admin.
|
|
26
|
-
|
|
27
|
-
export const appAdminHookSetCookie: AppAdminHookSetCookieProps = async (
|
|
28
|
-
req: ServerRequest,
|
|
29
|
-
res: ServerResponse,
|
|
30
|
-
username: string
|
|
31
|
-
) => {
|
|
32
|
-
const cryptoKey = process.env['CRYPTO_KEY'];
|
|
33
|
-
const u = process.env['ADMIN_USER'];
|
|
34
|
-
const p = process.env['ADMIN_PASS'];
|
|
35
|
-
if (!cryptoKey || !u || !p) {
|
|
36
|
-
return {};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const specialToken = CryptoUtils.hash((u + ':' + p) as string);
|
|
40
|
-
const loginJson: LoginJsonProps = {
|
|
41
|
-
ip: '',
|
|
42
|
-
id: 0,
|
|
43
|
-
u: u,
|
|
44
|
-
t: 'admin',
|
|
45
|
-
h: specialToken,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const token = JSON.stringify(loginJson);
|
|
49
|
-
const tokenCookie = CryptoUtils.encrypt(token, cryptoKey);
|
|
50
|
-
const response = {
|
|
51
|
-
status: 'ok',
|
|
52
|
-
message: langHelper.getLang('shared:login_success'),
|
|
53
|
-
result: tokenCookie,
|
|
54
|
-
user: {
|
|
55
|
-
u: loginJson.u,
|
|
56
|
-
t: loginJson.t,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// sameSite: 'none' needs secure=true
|
|
61
|
-
req.locals.setCookie('_token', tokenCookie, {
|
|
62
|
-
expireDays: 360,
|
|
63
|
-
path: '/',
|
|
64
|
-
httpOnly: false,
|
|
65
|
-
secure: true,
|
|
66
|
-
sameSite: 'none',
|
|
67
|
-
});
|
|
68
|
-
return response;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export const appAdminHookCheckLogin: AppAdminHookCheckLoginProps = async (
|
|
72
|
-
req: ServerRequest,
|
|
73
|
-
res: ServerResponse,
|
|
74
|
-
username: string,
|
|
75
|
-
password: string
|
|
76
|
-
) => {
|
|
77
|
-
if (process.env['ADMIN_PASS'] && username === process.env['ADMIN_USER'] && password === process.env['ADMIN_PASS']) {
|
|
78
|
-
const appAdminResponse = await appAdminHookSetCookie(req, res, username);
|
|
79
|
-
ApiHelper.sendJson(req, res, appAdminResponse);
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
adminHelper.setAppAdminHookSetCookie(appAdminHookSetCookie);
|
|
86
|
-
adminHelper.setAppAdminHookCheckLogin(appAdminHookCheckLogin);
|
|
87
|
-
*/
|
|
88
|
-
export type AppAdminHookSetCookieProps = (req: ServerRequest, res: ServerResponse, username: string) => Promise<any>;
|
|
89
|
-
export type AppAdminHookCheckLoginProps = (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
export
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.
|
|
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
|
-
|
|
1
|
+
import { ServerResponse } from 'http';
|
|
2
|
+
import { ApiHelper } from '../api';
|
|
3
|
+
import { CryptoUtils, Logger } from '../lib';
|
|
4
|
+
import { ServerRequest } from '../models';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
dev-admin uses different authentication method from frontend.
|
|
8
|
+
dev-admin only provides fixed username and password authentication, no user maintenance.
|
|
9
|
+
saved cookie name: _token_dev
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// DEFAULT_ADMIN_PASS is DEFAULT_ADMIN_NAME + ':' + login password hash.
|
|
13
|
+
// Use below command to generate hash:
|
|
14
|
+
// node -e "console.log(require('crypto').createHash('md5').update('admin:F4AZ5O@2fPUjw%f$LmhZpJTQ^DoXnWPkH#hqE', 'utf8').digest('hex'))"
|
|
15
|
+
export type DevAdminSessionProps = {
|
|
16
|
+
u: string; // username
|
|
17
|
+
t: string; // type: admin, user
|
|
18
|
+
ip: string;
|
|
19
|
+
h: string; // md5 of name+pass
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
dev admin has more permissions than app admin, and the dashboard also supports for app admin only users.
|
|
24
|
+
app admin is supposed to manage the application, not the site, and may have different fields in cookie.
|
|
25
|
+
This is a sample how to set login process for app admin.
|
|
26
|
+
|
|
27
|
+
export const appAdminHookSetCookie: AppAdminHookSetCookieProps = async (
|
|
28
|
+
req: ServerRequest,
|
|
29
|
+
res: ServerResponse,
|
|
30
|
+
username: string
|
|
31
|
+
) => {
|
|
32
|
+
const cryptoKey = process.env['CRYPTO_KEY'];
|
|
33
|
+
const u = process.env['ADMIN_USER'];
|
|
34
|
+
const p = process.env['ADMIN_PASS'];
|
|
35
|
+
if (!cryptoKey || !u || !p) {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const specialToken = CryptoUtils.hash((u + ':' + p) as string);
|
|
40
|
+
const loginJson: LoginJsonProps = {
|
|
41
|
+
ip: '',
|
|
42
|
+
id: 0,
|
|
43
|
+
u: u,
|
|
44
|
+
t: 'admin',
|
|
45
|
+
h: specialToken,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const token = JSON.stringify(loginJson);
|
|
49
|
+
const tokenCookie = CryptoUtils.encrypt(token, cryptoKey);
|
|
50
|
+
const response = {
|
|
51
|
+
status: 'ok',
|
|
52
|
+
message: langHelper.getLang('shared:login_success'),
|
|
53
|
+
result: tokenCookie,
|
|
54
|
+
user: {
|
|
55
|
+
u: loginJson.u,
|
|
56
|
+
t: loginJson.t,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// sameSite: 'none' needs secure=true
|
|
61
|
+
req.locals.setCookie('_token', tokenCookie, {
|
|
62
|
+
expireDays: 360,
|
|
63
|
+
path: '/',
|
|
64
|
+
httpOnly: false,
|
|
65
|
+
secure: true,
|
|
66
|
+
sameSite: 'none',
|
|
67
|
+
});
|
|
68
|
+
return response;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const appAdminHookCheckLogin: AppAdminHookCheckLoginProps = async (
|
|
72
|
+
req: ServerRequest,
|
|
73
|
+
res: ServerResponse,
|
|
74
|
+
username: string,
|
|
75
|
+
password: string
|
|
76
|
+
) => {
|
|
77
|
+
if (process.env['ADMIN_PASS'] && username === process.env['ADMIN_USER'] && password === process.env['ADMIN_PASS']) {
|
|
78
|
+
const appAdminResponse = await appAdminHookSetCookie(req, res, username);
|
|
79
|
+
ApiHelper.sendJson(req, res, appAdminResponse);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
adminHelper.setAppAdminHookSetCookie(appAdminHookSetCookie);
|
|
86
|
+
adminHelper.setAppAdminHookCheckLogin(appAdminHookCheckLogin);
|
|
87
|
+
*/
|
|
88
|
+
export type AppAdminHookSetCookieProps = (req: ServerRequest, res: ServerResponse, username: string) => Promise<any>;
|
|
89
|
+
export type AppAdminHookCheckLoginProps = (
|
|
90
|
+
req: ServerRequest,
|
|
91
|
+
res: ServerResponse,
|
|
92
|
+
username: string,
|
|
93
|
+
password: string
|
|
94
|
+
) => Promise<boolean>;
|
|
95
|
+
export type AppAdminHookLogoutProps = (req: ServerRequest, res: ServerResponse) => Promise<void>;
|
|
96
|
+
|
|
97
|
+
export const DEV_ADMIN_TYPE = 'dev-admin';
|
|
98
|
+
export const DEV_ADMIN_CRYPTO_KEY_NAME = 'DEV_CRYPTO_KEY';
|
|
99
|
+
export const DEV_ADMIN_SESSION_NAME = '_token_dev';
|
|
100
|
+
export class AdminApiHelper {
|
|
101
|
+
private static instance: AdminApiHelper;
|
|
102
|
+
private logger = new Logger('admin-api');
|
|
103
|
+
|
|
104
|
+
private constructor() {}
|
|
105
|
+
|
|
106
|
+
public static getInstance(): AdminApiHelper {
|
|
107
|
+
if (!AdminApiHelper.instance) {
|
|
108
|
+
AdminApiHelper.instance = new AdminApiHelper();
|
|
109
|
+
}
|
|
110
|
+
return AdminApiHelper.instance;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private AppAdminHookSetCookie?: AppAdminHookSetCookieProps;
|
|
114
|
+
setAppAdminHookSetCookie(hook: AppAdminHookSetCookieProps) {
|
|
115
|
+
this.AppAdminHookSetCookie = hook;
|
|
116
|
+
}
|
|
117
|
+
getAppAdminHookSetCookie() {
|
|
118
|
+
return this.AppAdminHookSetCookie;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private AppAdminHookCheckLogin?: AppAdminHookCheckLoginProps;
|
|
122
|
+
setAppAdminHookCheckLogin(hook: AppAdminHookCheckLoginProps) {
|
|
123
|
+
this.AppAdminHookCheckLogin = hook;
|
|
124
|
+
}
|
|
125
|
+
getAppAdminHookCheckLogin() {
|
|
126
|
+
return this.AppAdminHookCheckLogin;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private AppAdminHookLogout?: AppAdminHookLogoutProps;
|
|
130
|
+
setAppAdminHookLogout(hook: AppAdminHookLogoutProps) {
|
|
131
|
+
this.AppAdminHookLogout = hook;
|
|
132
|
+
}
|
|
133
|
+
getAppAdminHookLogout() {
|
|
134
|
+
return this.AppAdminHookLogout;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
decryptJson(text: string) {
|
|
138
|
+
const cryptoKey = process.env[DEV_ADMIN_CRYPTO_KEY_NAME];
|
|
139
|
+
if (cryptoKey && text) {
|
|
140
|
+
try {
|
|
141
|
+
const deCrypto = CryptoUtils.decrypt(text, cryptoKey);
|
|
142
|
+
const json = JSON.parse(deCrypto);
|
|
143
|
+
return json;
|
|
144
|
+
} catch (error: any) {
|
|
145
|
+
this.logger.error(error.message);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
encryptJson(jsonOrText: string | object) {
|
|
152
|
+
const cryptoKey = process.env[DEV_ADMIN_CRYPTO_KEY_NAME];
|
|
153
|
+
if (cryptoKey && jsonOrText) {
|
|
154
|
+
try {
|
|
155
|
+
const text = typeof jsonOrText === 'string' ? jsonOrText : JSON.stringify(jsonOrText);
|
|
156
|
+
const encryptText = CryptoUtils.encrypt(text, cryptoKey);
|
|
157
|
+
return encryptText;
|
|
158
|
+
} catch (error: any) {
|
|
159
|
+
this.logger.error(error.message);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async getDevAdminFromCookie(
|
|
166
|
+
req: ServerRequest,
|
|
167
|
+
res: ServerResponse,
|
|
168
|
+
sendResponseWhenError = true
|
|
169
|
+
): Promise<DevAdminSessionProps | false> {
|
|
170
|
+
try {
|
|
171
|
+
const cookies = req.locals.cookies();
|
|
172
|
+
const token = cookies.get(DEV_ADMIN_SESSION_NAME, '');
|
|
173
|
+
if (token) {
|
|
174
|
+
const json = this.decryptJson(token) as DevAdminSessionProps;
|
|
175
|
+
if (!json || json.t !== DEV_ADMIN_TYPE) {
|
|
176
|
+
if (sendResponseWhenError) {
|
|
177
|
+
const response = {
|
|
178
|
+
status: 'error',
|
|
179
|
+
message: 'Wrong session data, contact site admin please.',
|
|
180
|
+
};
|
|
181
|
+
ApiHelper.sendJson(req, res, response);
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// if it's special admin
|
|
187
|
+
if (json.h && json.u === process.env['DEV_ADMIN_USER']) {
|
|
188
|
+
const hash = CryptoUtils.hash(process.env['DEV_ADMIN_USER'] + ':' + process.env['DEV_ADMIN_PASS']);
|
|
189
|
+
if (json.h === hash) {
|
|
190
|
+
return json;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
} catch (error: any) {
|
|
196
|
+
this.logger.error(error.message);
|
|
197
|
+
}
|
|
198
|
+
if (sendResponseWhenError) {
|
|
199
|
+
const response = {
|
|
200
|
+
status: 'error',
|
|
201
|
+
message: 'Please login to use this system.',
|
|
202
|
+
};
|
|
203
|
+
ApiHelper.sendJson(req, res, response);
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// add comment for tree shaking
|
|
210
|
+
export const adminApiHelper = /* @__PURE__ */ AdminApiHelper.getInstance();
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { ServerResponse } from 'http';
|
|
2
|
-
// import { AdminUser } from './admin-user';
|
|
3
|
-
import { AdminDb } from './admin-db';
|
|
4
|
-
import { AdminMenu } from './admin-menu';
|
|
5
|
-
import { devAdminAuth, devAdminLogout, needDevAdminSession } from './admin-auth';
|
|
6
|
-
import { AdminPerformance } from './admin-performance';
|
|
7
|
-
import { AdminRelease } from './admin-release';
|
|
8
|
-
import { AdminResources } from './admin-resources';
|
|
9
|
-
import { AdminTokens } from './admin-tokens';
|
|
10
|
-
import { AdminConfig } from './admin-config';
|
|
11
|
-
import { Logger } from '../lib';
|
|
12
|
-
import { IApiBase, ServerRequest } from '../models';
|
|
13
|
-
import { ApiRouter } from '../api';
|
|
14
|
-
import { readWebConfig } from './web-config-api';
|
|
15
|
-
|
|
16
|
-
const logger = new Logger('admin-api');
|
|
17
|
-
|
|
18
|
-
export class AdminApi implements IApiBase {
|
|
19
|
-
protected router = new ApiRouter();
|
|
20
|
-
adminUser: any;
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
this.mountDashboard();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public getRouter(): ApiRouter {
|
|
27
|
-
return this.router;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected mountDashboard() {
|
|
31
|
-
this.router.use('/web-config', readWebConfig);
|
|
32
|
-
|
|
33
|
-
const adminDb = new AdminDb();
|
|
34
|
-
this.router.use('/db', needDevAdminSession, adminDb.getRouter());
|
|
35
|
-
|
|
36
|
-
// const adminUsers = new AdminUser();
|
|
37
|
-
// this.router.use('/user', needDevAdminSession, adminUsers.getRouter());
|
|
38
|
-
|
|
39
|
-
const adminMenus = new AdminMenu();
|
|
40
|
-
this.router.use('/menu', needDevAdminSession, adminMenus.getRouter());
|
|
41
|
-
|
|
42
|
-
const adminPerformance = new AdminPerformance();
|
|
43
|
-
this.router.use('/performance', needDevAdminSession, adminPerformance.getRouter());
|
|
44
|
-
|
|
45
|
-
const adminRelease = new AdminRelease();
|
|
46
|
-
// as some endpoints check the token, so add needDevAdminSession inside
|
|
47
|
-
this.router.use('/release', adminRelease.getRouter());
|
|
48
|
-
|
|
49
|
-
const adminResources = new AdminResources();
|
|
50
|
-
this.router.use('/resources', needDevAdminSession, adminResources.getRouter());
|
|
51
|
-
|
|
52
|
-
const adminConfig = new AdminConfig();
|
|
53
|
-
this.router.use('/config', needDevAdminSession, adminConfig.getRouter());
|
|
54
|
-
|
|
55
|
-
const adminTokens = new AdminTokens();
|
|
56
|
-
this.router.use('/tokens', needDevAdminSession, adminTokens.getRouter());
|
|
57
|
-
|
|
58
|
-
this.router.use('/auth', async (req: ServerRequest, res: ServerResponse) => {
|
|
59
|
-
return devAdminAuth(req, res);
|
|
60
|
-
});
|
|
61
|
-
this.router.use('/logout', async (req: ServerRequest, res: ServerResponse) => {
|
|
62
|
-
return devAdminLogout(req, res);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
import { ServerResponse } from 'http';
|
|
2
|
+
// import { AdminUser } from './admin-user';
|
|
3
|
+
import { AdminDb } from './admin-db';
|
|
4
|
+
import { AdminMenu } from './admin-menu';
|
|
5
|
+
import { devAdminAuth, devAdminLogout, needDevAdminSession } from './admin-auth';
|
|
6
|
+
import { AdminPerformance } from './admin-performance';
|
|
7
|
+
import { AdminRelease } from './admin-release';
|
|
8
|
+
import { AdminResources } from './admin-resources';
|
|
9
|
+
import { AdminTokens } from './admin-tokens';
|
|
10
|
+
import { AdminConfig } from './admin-config';
|
|
11
|
+
import { Logger } from '../lib';
|
|
12
|
+
import { IApiBase, ServerRequest } from '../models';
|
|
13
|
+
import { ApiRouter } from '../api';
|
|
14
|
+
import { readWebConfig } from './web-config-api';
|
|
15
|
+
|
|
16
|
+
const logger = new Logger('admin-api');
|
|
17
|
+
|
|
18
|
+
export class AdminApi implements IApiBase {
|
|
19
|
+
protected router = new ApiRouter();
|
|
20
|
+
adminUser: any;
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
this.mountDashboard();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getRouter(): ApiRouter {
|
|
27
|
+
return this.router;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected mountDashboard() {
|
|
31
|
+
this.router.use('/web-config', readWebConfig);
|
|
32
|
+
|
|
33
|
+
const adminDb = new AdminDb();
|
|
34
|
+
this.router.use('/db', needDevAdminSession, adminDb.getRouter());
|
|
35
|
+
|
|
36
|
+
// const adminUsers = new AdminUser();
|
|
37
|
+
// this.router.use('/user', needDevAdminSession, adminUsers.getRouter());
|
|
38
|
+
|
|
39
|
+
const adminMenus = new AdminMenu();
|
|
40
|
+
this.router.use('/menu', needDevAdminSession, adminMenus.getRouter());
|
|
41
|
+
|
|
42
|
+
const adminPerformance = new AdminPerformance();
|
|
43
|
+
this.router.use('/performance', needDevAdminSession, adminPerformance.getRouter());
|
|
44
|
+
|
|
45
|
+
const adminRelease = new AdminRelease();
|
|
46
|
+
// as some endpoints check the token, so add needDevAdminSession inside
|
|
47
|
+
this.router.use('/release', adminRelease.getRouter());
|
|
48
|
+
|
|
49
|
+
const adminResources = new AdminResources();
|
|
50
|
+
this.router.use('/resources', needDevAdminSession, adminResources.getRouter());
|
|
51
|
+
|
|
52
|
+
const adminConfig = new AdminConfig();
|
|
53
|
+
this.router.use('/config', needDevAdminSession, adminConfig.getRouter());
|
|
54
|
+
|
|
55
|
+
const adminTokens = new AdminTokens();
|
|
56
|
+
this.router.use('/tokens', needDevAdminSession, adminTokens.getRouter());
|
|
57
|
+
|
|
58
|
+
this.router.use('/auth', async (req: ServerRequest, res: ServerResponse) => {
|
|
59
|
+
return devAdminAuth(req, res);
|
|
60
|
+
});
|
|
61
|
+
this.router.use('/logout', async (req: ServerRequest, res: ServerResponse) => {
|
|
62
|
+
return devAdminLogout(req, res);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|