hfs 0.26.7 → 0.26.8
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/admin/.DS_Store +0 -0
- package/admin/.eslintrc +8 -0
- package/admin/.gitignore +23 -0
- package/admin/index.html +1 -3
- package/admin/package.json +67 -0
- package/admin/{logo.svg → public/logo.svg} +0 -0
- package/admin/src/AccountForm.ts +92 -0
- package/admin/src/AccountsPage.ts +143 -0
- package/admin/src/App.ts +83 -0
- package/admin/src/ArrayField.ts +84 -0
- package/admin/src/ConfigPage.ts +279 -0
- package/admin/src/FileField.ts +52 -0
- package/admin/src/FileForm.ts +148 -0
- package/admin/src/FilePicker.ts +166 -0
- package/admin/src/HomePage.ts +96 -0
- package/admin/src/InstalledPlugins.ts +158 -0
- package/admin/src/LoginRequired.ts +75 -0
- package/admin/src/LogoutPage.ts +27 -0
- package/admin/src/LogsPage.ts +75 -0
- package/admin/src/MainMenu.ts +74 -0
- package/admin/src/MenuButton.ts +38 -0
- package/admin/src/MonitorPage.ts +200 -0
- package/admin/src/OnlinePlugins.ts +101 -0
- package/admin/src/PermField.ts +80 -0
- package/admin/src/PluginsPage.ts +27 -0
- package/admin/src/VfsMenuBar.ts +58 -0
- package/admin/src/VfsPage.ts +124 -0
- package/admin/src/VfsTree.ts +95 -0
- package/admin/src/addFiles.ts +59 -0
- package/admin/src/api.ts +246 -0
- package/admin/src/dialog.ts +203 -0
- package/admin/src/index.css +21 -0
- package/admin/src/index.ts +10 -0
- package/admin/src/md.ts +31 -0
- package/admin/src/misc.ts +141 -0
- package/admin/src/react-app-env.d.ts +1 -0
- package/admin/src/reportWebVitals.ts +15 -0
- package/admin/src/setupTests.ts +5 -0
- package/admin/src/state.ts +40 -0
- package/admin/src/theme.ts +37 -0
- package/admin/tsconfig.json +26 -0
- package/admin/vite.config.ts +32 -0
- package/frontend/.DS_Store +0 -0
- package/frontend/.eslintrc +8 -0
- package/frontend/.gitignore +23 -0
- package/frontend/index.html +1 -3
- package/frontend/package.json +51 -0
- package/frontend/{fontello.css → public/fontello.css} +0 -0
- package/frontend/{fontello.woff2 → public/fontello.woff2} +0 -0
- package/frontend/src/App.ts +25 -0
- package/frontend/src/Breadcrumbs.ts +43 -0
- package/frontend/src/BrowseFiles.ts +141 -0
- package/frontend/src/Head.ts +45 -0
- package/frontend/src/UserPanel.ts +52 -0
- package/frontend/src/api.ts +78 -0
- package/frontend/src/components.ts +54 -0
- package/frontend/src/dialog.css +76 -0
- package/frontend/src/dialog.ts +105 -0
- package/frontend/src/icons.ts +46 -0
- package/frontend/src/index.scss +307 -0
- package/frontend/src/index.ts +10 -0
- package/frontend/src/login.ts +50 -0
- package/frontend/src/menu.ts +188 -0
- package/frontend/src/misc.ts +54 -0
- package/frontend/src/options.ts +52 -0
- package/frontend/src/react-app-env.d.ts +1 -0
- package/frontend/src/reportWebVitals.ts +15 -0
- package/frontend/src/setupTests.ts +5 -0
- package/frontend/src/state.ts +82 -0
- package/frontend/src/useAuthorized.ts +17 -0
- package/frontend/src/useFetchList.ts +144 -0
- package/frontend/src/useTheme.ts +23 -0
- package/frontend/tsconfig.json +26 -0
- package/frontend/vite.config.ts +21 -0
- package/package.json +2 -1
- package/plugins/vhosting/plugin.js +1 -1
- package/src/QuickZipStream.ts +279 -0
- package/src/ThrottledStream.ts +98 -0
- package/src/adminApis.ts +161 -0
- package/src/api.accounts.ts +78 -0
- package/src/api.auth.ts +131 -0
- package/src/api.file_list.ts +102 -0
- package/src/api.helpers.ts +30 -0
- package/src/api.monitor.ts +106 -0
- package/src/api.plugins.ts +139 -0
- package/src/api.vfs.ts +182 -0
- package/src/apiMiddleware.ts +124 -0
- package/src/block.ts +35 -0
- package/src/commands.ts +122 -0
- package/src/config.ts +166 -0
- package/src/connections.ts +60 -0
- package/src/const.ts +57 -0
- package/src/crypt.ts +16 -0
- package/src/debounceAsync.ts +51 -0
- package/src/events.ts +6 -0
- package/src/frontEndApis.ts +17 -0
- package/src/github.ts +102 -0
- package/src/index.ts +53 -0
- package/src/listen.ts +220 -0
- package/src/log.ts +128 -0
- package/src/middlewares.ts +176 -0
- package/src/misc.ts +149 -0
- package/src/pbkdf2.ts +83 -0
- package/src/perm.ts +194 -0
- package/src/plugins.ts +342 -0
- package/src/serveFile.ts +104 -0
- package/src/serveGuiFiles.ts +95 -0
- package/src/sse.ts +29 -0
- package/src/throttler.ts +106 -0
- package/src/update.ts +67 -0
- package/src/util-files.ts +137 -0
- package/src/util-generators.ts +29 -0
- package/src/util-http.ts +29 -0
- package/src/vfs.ts +258 -0
- package/src/watchLoad.ts +75 -0
- package/src/zip.ts +69 -0
- package/admin/assets/index.0f549e00.js +0 -281
- package/admin/assets/index.dcc78777.css +0 -1
- package/admin/assets/sha512.ea1121b3.js +0 -8
- package/frontend/assets/index.1151988f.js +0 -85
- package/frontend/assets/index.93366732.css +0 -1
- package/frontend/assets/sha512.bb881250.js +0 -8
- package/src/QuickZipStream.js +0 -285
- package/src/ThrottledStream.js +0 -93
- package/src/adminApis.js +0 -169
- package/src/api.accounts.js +0 -59
- package/src/api.auth.js +0 -130
- package/src/api.file_list.js +0 -103
- package/src/api.helpers.js +0 -32
- package/src/api.monitor.js +0 -102
- package/src/api.plugins.js +0 -127
- package/src/api.vfs.js +0 -164
- package/src/apiMiddleware.js +0 -136
- package/src/block.js +0 -33
- package/src/commands.js +0 -124
- package/src/config.js +0 -168
- package/src/connections.js +0 -57
- package/src/const.js +0 -83
- package/src/crypt.js +0 -21
- package/src/debounceAsync.js +0 -48
- package/src/events.js +0 -9
- package/src/frontEndApis.js +0 -38
- package/src/github.js +0 -102
- package/src/index.js +0 -55
- package/src/listen.js +0 -235
- package/src/log.js +0 -137
- package/src/middlewares.js +0 -154
- package/src/misc.js +0 -160
- package/src/pbkdf2.js +0 -74
- package/src/perm.js +0 -176
- package/src/plugins.js +0 -343
- package/src/serveFile.js +0 -104
- package/src/serveGuiFiles.js +0 -113
- package/src/sse.js +0 -29
- package/src/throttler.js +0 -91
- package/src/update.js +0 -69
- package/src/util-files.js +0 -148
- package/src/util-generators.js +0 -30
- package/src/util-http.js +0 -30
- package/src/vfs.js +0 -227
- package/src/watchLoad.js +0 -73
- package/src/zip.js +0 -69
package/admin/.DS_Store
ADDED
|
Binary file
|
package/admin/.eslintrc
ADDED
package/admin/.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
/.pnp
|
|
6
|
+
.pnp.js
|
|
7
|
+
|
|
8
|
+
# testing
|
|
9
|
+
/coverage
|
|
10
|
+
|
|
11
|
+
# production
|
|
12
|
+
/build
|
|
13
|
+
|
|
14
|
+
# misc
|
|
15
|
+
.DS_Store
|
|
16
|
+
.env.local
|
|
17
|
+
.env.development.local
|
|
18
|
+
.env.test.local
|
|
19
|
+
.env.production.local
|
|
20
|
+
|
|
21
|
+
npm-debug.log*
|
|
22
|
+
yarn-debug.log*
|
|
23
|
+
yarn-error.log*
|
package/admin/index.html
CHANGED
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
<script async src='https://unpkg.com/node-forge@1.3.1/dist/forge.min.js'></script>
|
|
8
8
|
<script>SESSION = _HFS_SESSION_</script>
|
|
9
9
|
<title>HFS Admin</title>
|
|
10
|
-
<script type="module" crossorigin src="/assets/index.0f549e00.js"></script>
|
|
11
|
-
<link rel="stylesheet" href="/assets/index.dcc78777.css">
|
|
12
10
|
</head>
|
|
13
11
|
<body>
|
|
14
12
|
<div id="root"></div>
|
|
15
|
-
|
|
13
|
+
<script type="module" src="/src/index.ts"></script>
|
|
16
14
|
</body>
|
|
17
15
|
</html>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hfs/admin",
|
|
3
|
+
"private": true,
|
|
4
|
+
"proxy": "http://localhost",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"start": "vite",
|
|
7
|
+
"build": "tsc && vite build",
|
|
8
|
+
"preview": "vite preview",
|
|
9
|
+
"test-dep": "npm audit --production"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@emotion/react": "^11.10.0",
|
|
13
|
+
"@hfs/mui-grid-form": "*",
|
|
14
|
+
"@hfs/shared": "*",
|
|
15
|
+
"@emotion/styled": "^11.10.0",
|
|
16
|
+
"@mui/icons-material": "^5.8.4",
|
|
17
|
+
"@mui/lab": "^5.0.0-alpha.94",
|
|
18
|
+
"@mui/material": "^5.10.0",
|
|
19
|
+
"@mui/x-data-grid": "^5.15.1",
|
|
20
|
+
"js-sha512": "^0.8.0",
|
|
21
|
+
"react": "^18.2.0",
|
|
22
|
+
"react-dom": "^18.2.0",
|
|
23
|
+
"react-router-dom": "^6.2.1",
|
|
24
|
+
"react-window": "^1.8.6",
|
|
25
|
+
"tssrp6a": "^3.0.0",
|
|
26
|
+
"valtio": "^1.2.9",
|
|
27
|
+
"immer": "^9.0.15",
|
|
28
|
+
"web-vitals": "^2.1.4"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^16.11.21",
|
|
32
|
+
"@types/react": "^18.0.15",
|
|
33
|
+
"@types/react-dom": "^18.0.6",
|
|
34
|
+
"@types/react-window": "^1.8.5",
|
|
35
|
+
"@types/react-virtualized-auto-sizer": "^1.0.1",
|
|
36
|
+
"vite": "^3.0.0",
|
|
37
|
+
"vite-plugin-babel-import": "github:rejetto/vite-plugin-babel-import"
|
|
38
|
+
},
|
|
39
|
+
"eslintConfig": {
|
|
40
|
+
"extends": [
|
|
41
|
+
"react-app",
|
|
42
|
+
"react-app/jest"
|
|
43
|
+
],
|
|
44
|
+
"overrides": [
|
|
45
|
+
{
|
|
46
|
+
"files": [
|
|
47
|
+
"*.ts"
|
|
48
|
+
],
|
|
49
|
+
"rules": {
|
|
50
|
+
"no-mixed-operators": "off"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"browserslist": {
|
|
56
|
+
"production": [
|
|
57
|
+
">0.2%",
|
|
58
|
+
"not dead",
|
|
59
|
+
"not op_mini all"
|
|
60
|
+
],
|
|
61
|
+
"development": [
|
|
62
|
+
"last 1 chrome version",
|
|
63
|
+
"last 1 firefox version",
|
|
64
|
+
"last 1 safari version"
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createElement as h, useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { BoolField, Form, MultiSelectField } from '@hfs/mui-grid-form'
|
|
3
|
+
import { Box, Button } from '@mui/material'
|
|
4
|
+
import { apiCall } from './api'
|
|
5
|
+
import { alertDialog } from './dialog'
|
|
6
|
+
import { isEqualLax, modifiedSx } from './misc'
|
|
7
|
+
import { Account, account2icon } from './AccountsPage'
|
|
8
|
+
import { createVerifierAndSalt, SRPParameters, SRPRoutines } from 'tssrp6a'
|
|
9
|
+
|
|
10
|
+
interface FormProps { account: Account, groups: string[], done: (username: string)=>void, close: ()=>void }
|
|
11
|
+
export default function AccountForm({ account, done, groups, close }: FormProps) {
|
|
12
|
+
const [values, setValues] = useState<Account & { password?: string, password2?: string }>(account)
|
|
13
|
+
const [belongsOptions, setBelongOptions] = useState<string[]>([])
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
setValues(account)
|
|
16
|
+
setBelongOptions(groups.filter(x => x !== account.username ))
|
|
17
|
+
ref.current?.querySelector('input')?.focus()
|
|
18
|
+
}, [JSON.stringify(account)]) //eslint-disable-line
|
|
19
|
+
const add = !account.username
|
|
20
|
+
const group = !values.hasPassword
|
|
21
|
+
const ref = useRef<HTMLFormElement>()
|
|
22
|
+
return h(Form, {
|
|
23
|
+
formRef: ref,
|
|
24
|
+
values,
|
|
25
|
+
set(v, k) {
|
|
26
|
+
setValues({ ...values, [k]: v })
|
|
27
|
+
},
|
|
28
|
+
addToBar: [
|
|
29
|
+
h(Button, { onClick: close, sx: { ml: 2 } }, "Close"),
|
|
30
|
+
h(Box, { flex:1 }),
|
|
31
|
+
account2icon(values, { fontSize: 'large', sx: { p: 1 }})
|
|
32
|
+
],
|
|
33
|
+
fields: [
|
|
34
|
+
{ k: 'username', label: group ? 'Group name' : undefined, autoComplete: 'off', required: true, xl: group ? 12 : 4,
|
|
35
|
+
getError: v => v !== account.username && apiCall('get_account', { username: v }).then(() => "already used", () => false),
|
|
36
|
+
},
|
|
37
|
+
!group && { k: 'password', md: 6, xl: 4, type: 'password', autoComplete: 'new-password', required: add,
|
|
38
|
+
label: add ? "Password" : "Change password"
|
|
39
|
+
},
|
|
40
|
+
!group && { k: 'password2', md: 6, xl: 4, type: 'password', autoComplete: 'new-password', label: 'Repeat password',
|
|
41
|
+
getError: (x, { values }) => (x||'') !== (values.password||'') && "Enter same password" },
|
|
42
|
+
{ k: 'ignore_limits', comp: BoolField, xl: 6,
|
|
43
|
+
helperText: values.ignore_limits ? "Speed limits don't apply to this account" : "Speed limits apply to this account" },
|
|
44
|
+
{ k: 'admin', comp: BoolField, xl: 6, fromField: (v:boolean) => v||null, label: "Permission to access Admin interface",
|
|
45
|
+
helperText: "To access THIS interface you are using right now",
|
|
46
|
+
...account.adminActualAccess && { value: true, disabled: true, helperText: "This permission is inherited" },
|
|
47
|
+
},
|
|
48
|
+
{ k: 'belongs', comp: MultiSelectField, label: "Inherits from", options: belongsOptions,
|
|
49
|
+
helperText: "Specify groups to inherit permissions from."
|
|
50
|
+
+ (belongsOptions.length ? '' : " There are no groups available, create one first.")
|
|
51
|
+
},
|
|
52
|
+
{ k: 'redirect', helperText: "If you want this account to be redirected to a specific folder/address at login time" },
|
|
53
|
+
],
|
|
54
|
+
onError: alertDialog,
|
|
55
|
+
save: {
|
|
56
|
+
sx: modifiedSx( !isEqualLax(values, account)),
|
|
57
|
+
async onClick() {
|
|
58
|
+
const { password='', password2, adminActualAccess, ...withoutPassword } = values
|
|
59
|
+
const { username } = values
|
|
60
|
+
if (add) {
|
|
61
|
+
await apiCall('add_account', withoutPassword)
|
|
62
|
+
if (password)
|
|
63
|
+
try { await apiNewPassword(username, password) }
|
|
64
|
+
catch(e) {
|
|
65
|
+
apiCall('del_account', { username }).then() // best effort, don't wait
|
|
66
|
+
throw e
|
|
67
|
+
}
|
|
68
|
+
done(username)
|
|
69
|
+
return alertDialog("Account created", 'success')
|
|
70
|
+
}
|
|
71
|
+
await apiCall('set_account', {
|
|
72
|
+
username: account.username,
|
|
73
|
+
changes: withoutPassword,
|
|
74
|
+
})
|
|
75
|
+
if (password)
|
|
76
|
+
await apiNewPassword(username, password)
|
|
77
|
+
done(username)
|
|
78
|
+
return alertDialog("Account modified", 'success')
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function apiNewPassword(username: string, password: string) {
|
|
85
|
+
const srp6aNimbusRoutines = new SRPRoutines(new SRPParameters())
|
|
86
|
+
const res = await createVerifierAndSalt(srp6aNimbusRoutines, username, password)
|
|
87
|
+
return apiCall('change_srp_others', { username, salt: String(res.s), verifier: String(res.v) }).catch(e => {
|
|
88
|
+
if (e.code !== 406) // 406 = server was configured to support clear text authentication
|
|
89
|
+
throw e
|
|
90
|
+
return apiCall('change_password_others', { username, newPassword: password }) // unencrypted version
|
|
91
|
+
})
|
|
92
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
2
|
+
|
|
3
|
+
import { createElement as h, useState, useEffect, Fragment } from "react"
|
|
4
|
+
import { apiCall, useApiEx } from './api'
|
|
5
|
+
import { Alert, Box, Button, Card, CardContent, Grid, List, ListItem, ListItemText, Typography } from '@mui/material'
|
|
6
|
+
import { Delete, Group, MilitaryTech, Person, PersonAdd, Refresh } from '@mui/icons-material'
|
|
7
|
+
import { alertDialog, confirmDialog } from './dialog'
|
|
8
|
+
import { iconTooltip, onlyTruthy } from './misc'
|
|
9
|
+
import { TreeItem, TreeView } from '@mui/lab'
|
|
10
|
+
import MenuButton from './MenuButton'
|
|
11
|
+
import AccountForm from './AccountForm'
|
|
12
|
+
import md from './md'
|
|
13
|
+
|
|
14
|
+
export interface Account {
|
|
15
|
+
username: string
|
|
16
|
+
hasPassword?: boolean
|
|
17
|
+
adminActualAccess?: boolean
|
|
18
|
+
ignore_limits?: boolean
|
|
19
|
+
redirect?: string
|
|
20
|
+
belongs?: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default function AccountsPage() {
|
|
24
|
+
const { data, reload, element } = useApiEx('get_accounts')
|
|
25
|
+
const [sel, setSel] = useState<string[] | 'new-group' | 'new-user'>([])
|
|
26
|
+
const selectionMode = Array.isArray(sel)
|
|
27
|
+
useEffect(() => { // if accounts are reloaded, review the selection to remove elements that don't exist anymore
|
|
28
|
+
if (Array.isArray(data?.list) && selectionMode)
|
|
29
|
+
setSel( sel.filter(u => data.list.find((e:any) => e?.username === u)) ) // remove elements that don't exist anymore
|
|
30
|
+
}, [data]) //eslint-disable-line -- Don't fall for its suggestion to add `sel` here: we modify it and declaring it as a dependency would cause a logical loop
|
|
31
|
+
if (element)
|
|
32
|
+
return element
|
|
33
|
+
const { list }: { list: Account[] } = data
|
|
34
|
+
return h(Grid, { container: true, maxWidth: '80em' },
|
|
35
|
+
h(Grid, { item: true, xs: 12 },
|
|
36
|
+
h(Box, {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
flexWrap: 'wrap',
|
|
39
|
+
gap: 2,
|
|
40
|
+
mb: 2,
|
|
41
|
+
sx: {
|
|
42
|
+
position: 'sticky',
|
|
43
|
+
top: 0,
|
|
44
|
+
zIndex: 2,
|
|
45
|
+
backgroundColor: 'background.paper',
|
|
46
|
+
width: 'fit-content',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
h(MenuButton, {
|
|
50
|
+
variant: 'contained',
|
|
51
|
+
startIcon: h(PersonAdd),
|
|
52
|
+
items: [
|
|
53
|
+
{ children: "user", onClick: () => setSel('new-user') },
|
|
54
|
+
{ children: "group", onClick: () => setSel('new-group') }
|
|
55
|
+
]
|
|
56
|
+
}, 'Add'),
|
|
57
|
+
h(Button, {
|
|
58
|
+
disabled: !selectionMode || !sel.length,
|
|
59
|
+
startIcon: h(Delete),
|
|
60
|
+
async onClick(){
|
|
61
|
+
if (!selectionMode) return
|
|
62
|
+
if (!await confirmDialog(`You are going to delete ${sel.length} account(s)`))
|
|
63
|
+
return
|
|
64
|
+
const errors = onlyTruthy(await Promise.all(sel.map(username =>
|
|
65
|
+
apiCall('del_account', { username }).then(() => null, () => username) )))
|
|
66
|
+
if (errors.length)
|
|
67
|
+
return alertDialog(errors.length === sel.length ? "Request failed" : hList("Some accounts were not deleted", errors), 'error')
|
|
68
|
+
reload()
|
|
69
|
+
}
|
|
70
|
+
}, "Remove"),
|
|
71
|
+
h(Button, { onClick: reload, startIcon: h(Refresh) }, "Reload"),
|
|
72
|
+
list.length > 0 && h(Typography, { p: 1 }, `${list.length} account(s)`),
|
|
73
|
+
) ),
|
|
74
|
+
h(Grid, { item: true, md: 5 },
|
|
75
|
+
!list.length && h(Alert, { severity: 'info' }, md`To access administration _remotely_ you will need to create a user account with admin permission`),
|
|
76
|
+
h(TreeView, {
|
|
77
|
+
multiSelect: true,
|
|
78
|
+
sx: { pr: 4, pb: 2, minWidth: '15em' },
|
|
79
|
+
selected: selectionMode ? sel : [],
|
|
80
|
+
onNodeSelect(ev, ids) {
|
|
81
|
+
setSel(ids)
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
list.map((ac: Account) =>
|
|
85
|
+
h(TreeItem, {
|
|
86
|
+
key: ac.username,
|
|
87
|
+
nodeId: ac.username,
|
|
88
|
+
label: h(Box, {
|
|
89
|
+
sx: {
|
|
90
|
+
display: 'flex',
|
|
91
|
+
flexWrap: 'wrap',
|
|
92
|
+
padding: '.2em 0',
|
|
93
|
+
gap: '.5em',
|
|
94
|
+
alignItems: 'center',
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
account2icon(ac),
|
|
98
|
+
ac.adminActualAccess && iconTooltip(MilitaryTech, "Can login into Admin"),
|
|
99
|
+
ac.username,
|
|
100
|
+
Boolean(ac.belongs?.length) && h(Box, { sx: { color: 'text.secondary', fontSize: 'small' } },
|
|
101
|
+
'(', ac.belongs?.join(', '), ')')
|
|
102
|
+
),
|
|
103
|
+
})
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
),
|
|
107
|
+
sel.length > 0 // this clever test is true both when some accounts are selected and when we are in "new account" modes
|
|
108
|
+
&& h(Grid, { item: true, md: 7 },
|
|
109
|
+
h(Card, {},
|
|
110
|
+
h(CardContent, {},
|
|
111
|
+
selectionMode && sel.length > 1 ? h(Box, {},
|
|
112
|
+
h(Typography, {}, sel.length + " selected"),
|
|
113
|
+
h(List, {},
|
|
114
|
+
sel.map(username =>
|
|
115
|
+
h(ListItem, { key: username },
|
|
116
|
+
h(ListItemText, {}, username))))
|
|
117
|
+
) : h(AccountForm, {
|
|
118
|
+
account: selectionMode && list.find(x => x.username === sel[0])
|
|
119
|
+
|| { username: '', hasPassword: sel === 'new-user' },
|
|
120
|
+
groups: list.filter(x => !x.hasPassword).map( x => x.username ),
|
|
121
|
+
close(){ setSel([]) },
|
|
122
|
+
done(username) {
|
|
123
|
+
setSel([username])
|
|
124
|
+
reload()
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
)))
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function hList(heading: string, list: any[]) {
|
|
132
|
+
return h(Fragment, {},
|
|
133
|
+
heading>'' && h(Typography, {}, heading),
|
|
134
|
+
h(List, {},
|
|
135
|
+
list.map((text,key) =>
|
|
136
|
+
h(ListItem, { key },
|
|
137
|
+
typeof text === 'string' ? h(ListItemText, {}, text) : text) ))
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function account2icon(ac: Account, props={}) {
|
|
142
|
+
return h(ac.hasPassword ? Person : Group, props)
|
|
143
|
+
}
|
package/admin/src/App.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// This file is part of HFS - Copyright 2021-2022, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
|
|
2
|
+
|
|
3
|
+
import { createElement as h, Fragment, useState } from 'react'
|
|
4
|
+
import { HashRouter, Routes, Route, useLocation } from 'react-router-dom'
|
|
5
|
+
import MainMenu, { getMenuLabel, mainMenu } from './MainMenu'
|
|
6
|
+
import { AppBar, Box, Drawer, IconButton, ThemeProvider, Toolbar, Typography } from '@mui/material'
|
|
7
|
+
import { Dialogs } from './dialog'
|
|
8
|
+
import { useMyTheme } from './theme'
|
|
9
|
+
import { useBreakpoint} from './misc'
|
|
10
|
+
import { LoginRequired } from './LoginRequired'
|
|
11
|
+
import { Menu } from '@mui/icons-material'
|
|
12
|
+
|
|
13
|
+
function App() {
|
|
14
|
+
return h(ThemeProvider, { theme: useMyTheme() },
|
|
15
|
+
h(ApplyTheme, {},
|
|
16
|
+
h(LoginRequired, {},
|
|
17
|
+
h(HashRouter, {}, h(Routed)) ) ) )
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function ApplyTheme(props:any) {
|
|
21
|
+
return h(Box, {
|
|
22
|
+
sx: {
|
|
23
|
+
bgcolor: 'background.default', color: 'text.primary',
|
|
24
|
+
display: 'flex', flexDirection: 'column',
|
|
25
|
+
minHeight: '100%', flex: 1,
|
|
26
|
+
},
|
|
27
|
+
...props
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function Routed() {
|
|
32
|
+
const loc = useLocation().pathname.slice(1)
|
|
33
|
+
const current = mainMenu.find(x => x.path === loc)
|
|
34
|
+
const title = current && (current.title || getMenuLabel(current))
|
|
35
|
+
const [open, setOpen] = useState(false)
|
|
36
|
+
const large = useBreakpoint('lg')
|
|
37
|
+
return h(Fragment, {},
|
|
38
|
+
!large && h(StickyBar, { title, openMenu: () => setOpen(true) }),
|
|
39
|
+
!large && h(Drawer, { anchor:'left', open, onClose(){ setOpen(false) } },
|
|
40
|
+
h(MainMenu, {
|
|
41
|
+
onSelect: () => setOpen(false)
|
|
42
|
+
})),
|
|
43
|
+
h(Box, { display: 'flex', flex: 1, }, // horizontal layout for menu-content
|
|
44
|
+
large && h(MainMenu),
|
|
45
|
+
h(Box, {
|
|
46
|
+
component: 'main',
|
|
47
|
+
sx: {
|
|
48
|
+
background: 'url(logo.svg) no-repeat right fixed',
|
|
49
|
+
backgroundSize: 'contain',
|
|
50
|
+
px: { xs: 2, md: 3 },
|
|
51
|
+
pb: '1em',
|
|
52
|
+
position: 'relative',
|
|
53
|
+
display: 'flex',
|
|
54
|
+
flexDirection: 'column',
|
|
55
|
+
width: '100%',
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
title && large && h(Typography, { variant:'h2', mb:2 }, title),
|
|
59
|
+
h(Routes, {}, mainMenu.map((it,idx) =>
|
|
60
|
+
h(Route, { key: idx, path: it.path, element: h(it.comp) })) )
|
|
61
|
+
),
|
|
62
|
+
h(Dialogs)
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function StickyBar({ title, openMenu }: { title?: string, openMenu: ()=>void }) {
|
|
68
|
+
return h(AppBar, { position: 'sticky', sx: { mb: 2 } },
|
|
69
|
+
h(Toolbar, {},
|
|
70
|
+
h(IconButton, {
|
|
71
|
+
size: 'large',
|
|
72
|
+
edge: 'start',
|
|
73
|
+
color: 'inherit',
|
|
74
|
+
sx: { mr: 2 },
|
|
75
|
+
'aria-label': "menu",
|
|
76
|
+
onClick: openMenu
|
|
77
|
+
}, h(Menu)),
|
|
78
|
+
title,
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default App
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createElement as h, Fragment, useMemo } from 'react'
|
|
2
|
+
import { IconBtn, setHidden } from './misc'
|
|
3
|
+
import { Add, Edit, Delete } from '@mui/icons-material'
|
|
4
|
+
import { confirmDialog, formDialog } from './dialog'
|
|
5
|
+
import { DataGrid, GridAlignment } from '@mui/x-data-grid'
|
|
6
|
+
import { FieldDescriptor, FieldProps, labelFromKey } from '@hfs/mui-grid-form'
|
|
7
|
+
import { Box, FormHelperText, FormLabel } from '@mui/material'
|
|
8
|
+
|
|
9
|
+
export function ArrayField<T=any>({ label, helperText, fields, value, onChange, onError, getApi, ...rest }: FieldProps<T[]> & { fields: FieldDescriptor[], height?: number }) {
|
|
10
|
+
const rows = useMemo(() => (value||[]).map((x,$idx) =>
|
|
11
|
+
setHidden({ ...x } as any, 'id' in x ? { $idx } : { id: $idx })),
|
|
12
|
+
[JSON.stringify(value)]) //eslint-disable-line
|
|
13
|
+
const columns = useMemo(() => {
|
|
14
|
+
return [
|
|
15
|
+
...fields.map(f => ({
|
|
16
|
+
field: f.k,
|
|
17
|
+
headerName: f.headerName ?? (typeof f.label === 'string' ? f.label : labelFromKey(f.k)),
|
|
18
|
+
disableColumnMenu: true,
|
|
19
|
+
...f.$width >= 8 ? { width: f.$width } : { flex: f.$width || 1 },
|
|
20
|
+
...f.$column,
|
|
21
|
+
})),
|
|
22
|
+
{
|
|
23
|
+
field: '',
|
|
24
|
+
width: 80,
|
|
25
|
+
disableColumnMenu: true,
|
|
26
|
+
sortable: false,
|
|
27
|
+
align: 'center' as GridAlignment,
|
|
28
|
+
headerAlign: 'center' as GridAlignment,
|
|
29
|
+
renderHeader(){
|
|
30
|
+
return h(IconBtn, {
|
|
31
|
+
icon: Add,
|
|
32
|
+
title: "Add",
|
|
33
|
+
onClick: (event:any) =>
|
|
34
|
+
formDialog({ fields }).then(o => // @ts-ignore
|
|
35
|
+
o && onChange([...value||[], o], { was: value, event }))
|
|
36
|
+
})
|
|
37
|
+
},
|
|
38
|
+
renderCell({ row }: any) {
|
|
39
|
+
const { $idx=row.id } = row
|
|
40
|
+
return h('div', {},
|
|
41
|
+
h(IconBtn, {
|
|
42
|
+
icon: Edit,
|
|
43
|
+
title: "Modify",
|
|
44
|
+
onClick: (event:any) =>
|
|
45
|
+
formDialog({ fields, values: row }).then(newRec => {
|
|
46
|
+
if (!newRec) return
|
|
47
|
+
const newValue = value!.map((oldRec, i) => i === $idx ? newRec : oldRec)
|
|
48
|
+
onChange(newValue, { was: value, event })
|
|
49
|
+
}),
|
|
50
|
+
}),
|
|
51
|
+
h(IconBtn, {
|
|
52
|
+
icon: Delete,
|
|
53
|
+
title: "Delete",
|
|
54
|
+
onClick: (event:any) =>
|
|
55
|
+
confirmDialog("Delete?").then(ok => {
|
|
56
|
+
if (!ok) return
|
|
57
|
+
const newValue = value!.filter((rec, i) => i !== $idx)
|
|
58
|
+
onChange(newValue, { was: value, event })
|
|
59
|
+
}),
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}, [fields, value, onChange])
|
|
66
|
+
return h(Fragment, {},
|
|
67
|
+
label && h(FormLabel, { sx: { ml: 1 } }, label),
|
|
68
|
+
helperText && h(FormHelperText, {}, helperText),
|
|
69
|
+
h(Box, { height: '20em', ...rest },
|
|
70
|
+
h(DataGrid, {
|
|
71
|
+
columns,
|
|
72
|
+
rows,
|
|
73
|
+
hideFooterSelectedRowCount: true,
|
|
74
|
+
hideFooter: true,
|
|
75
|
+
componentsProps: {
|
|
76
|
+
pagination: {
|
|
77
|
+
showFirstButton: true,
|
|
78
|
+
showLastButton: true,
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
}
|