@underpostnet/underpost 2.99.7 → 3.0.0
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/.env.development +2 -1
- package/.env.production +1 -0
- package/.env.test +2 -1
- package/.github/workflows/npmpkg.ci.yml +2 -1
- package/.github/workflows/publish.ci.yml +18 -34
- package/.vscode/extensions.json +8 -50
- package/.vscode/settings.json +0 -77
- package/CHANGELOG.md +91 -1
- package/{cli.md → CLI-HELP.md} +48 -41
- package/Dockerfile +15 -15
- package/README.md +8 -15
- package/bin/build.js +1 -15
- package/bin/deploy.js +4 -133
- package/bin/file.js +5 -24
- package/bin/zed.js +63 -2
- package/examples/static-page/ssr-components/CustomPage.js +1 -1
- package/jsdoc.json +1 -2
- package/manifests/cronjobs/dd-cron/dd-cron-backup.yaml +1 -1
- package/manifests/cronjobs/dd-cron/dd-cron-dns.yaml +1 -1
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
- package/manifests/deployment/dd-test-development/deployment.yaml +2 -2
- package/manifests/deployment/fastapi/initial_data.sh +4 -52
- package/manifests/ipfs/configmap.yaml +57 -0
- package/manifests/ipfs/headless-service.yaml +35 -0
- package/manifests/ipfs/kustomization.yaml +8 -0
- package/manifests/ipfs/statefulset.yaml +149 -0
- package/manifests/ipfs/storage-class.yaml +9 -0
- package/package.json +5 -5
- package/scripts/k3s-node-setup.sh +89 -0
- package/scripts/lxd-vm-setup.sh +23 -0
- package/scripts/rocky-setup.sh +1 -13
- package/src/cli/baremetal.js +7 -9
- package/src/cli/cluster.js +72 -121
- package/src/cli/deploy.js +8 -5
- package/src/cli/index.js +31 -30
- package/src/cli/ipfs.js +184 -0
- package/src/cli/lxd.js +191 -236
- package/src/cli/repository.js +4 -1
- package/src/client/components/core/VanillaJs.js +0 -25
- package/src/client/services/user/user.management.js +0 -5
- package/src/client/services/user/user.service.js +1 -1
- package/src/db/mariadb/MariaDB.js +2 -2
- package/src/index.js +12 -1
- package/src/runtime/express/Dockerfile +15 -15
- package/src/runtime/lampp/Dockerfile +15 -15
- package/src/server/client-build-docs.js +26 -7
- package/src/server/conf.js +3 -20
- package/src/server/logger.js +22 -10
- package/.vscode/zed.keymap.json +0 -39
- package/.vscode/zed.settings.json +0 -20
- package/bin/cron.js +0 -47
- package/bin/db.js +0 -199
- package/bin/hwt.js +0 -49
- package/bin/util.js +0 -63
- package/manifests/lxd/underpost-setup.sh +0 -163
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createPool } from 'mariadb';
|
|
2
2
|
|
|
3
3
|
import { loggerFactory } from '../../server/logger.js';
|
|
4
4
|
|
|
@@ -32,7 +32,7 @@ class MariaDBService {
|
|
|
32
32
|
*/
|
|
33
33
|
async query(options) {
|
|
34
34
|
const { host, port, user, password, query } = options;
|
|
35
|
-
const pool =
|
|
35
|
+
const pool = createPool({
|
|
36
36
|
host: 'host' in options ? host : '127.0.0.1',
|
|
37
37
|
port: 'port' in options ? port : 3306,
|
|
38
38
|
user: 'user' in options ? user : 'root',
|
package/src/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import UnderpostDB from './cli/db.js';
|
|
|
12
12
|
import UnderpostDeploy from './cli/deploy.js';
|
|
13
13
|
import UnderpostRootEnv from './cli/env.js';
|
|
14
14
|
import UnderpostFileStorage from './cli/fs.js';
|
|
15
|
+
import UnderpostIPFS from './cli/ipfs.js';
|
|
15
16
|
import UnderpostImage from './cli/image.js';
|
|
16
17
|
import UnderpostLxd from './cli/lxd.js';
|
|
17
18
|
import UnderpostMonitor from './cli/monitor.js';
|
|
@@ -41,7 +42,7 @@ class Underpost {
|
|
|
41
42
|
* @type {String}
|
|
42
43
|
* @memberof Underpost
|
|
43
44
|
*/
|
|
44
|
-
static version = '
|
|
45
|
+
static version = 'v3.0.0';
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* Required Node.js major version
|
|
@@ -143,6 +144,15 @@ class Underpost {
|
|
|
143
144
|
static get fs() {
|
|
144
145
|
return UnderpostFileStorage.API;
|
|
145
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* IPFS cli API
|
|
149
|
+
* @static
|
|
150
|
+
* @type {UnderpostIPFS.API}
|
|
151
|
+
* @memberof Underpost
|
|
152
|
+
*/
|
|
153
|
+
static get ipfs() {
|
|
154
|
+
return UnderpostIPFS.API;
|
|
155
|
+
}
|
|
146
156
|
/**
|
|
147
157
|
* Monitor cli API
|
|
148
158
|
* @static
|
|
@@ -296,6 +306,7 @@ export {
|
|
|
296
306
|
UnderpostStatic,
|
|
297
307
|
UnderpostLxd,
|
|
298
308
|
UnderpostKickStart,
|
|
309
|
+
UnderpostIPFS,
|
|
299
310
|
UnderpostMonitor,
|
|
300
311
|
UnderpostRepository,
|
|
301
312
|
UnderpostRun,
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
FROM rockylinux:9
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Update and install required packages
|
|
4
4
|
RUN dnf -y update && \
|
|
5
5
|
dnf -y install epel-release && \
|
|
6
6
|
dnf -y install --allowerasing \
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
bzip2 \
|
|
8
|
+
sudo \
|
|
9
|
+
curl \
|
|
10
|
+
net-tools \
|
|
11
|
+
openssh-server \
|
|
12
|
+
nano \
|
|
13
|
+
vim-enhanced \
|
|
14
|
+
less \
|
|
15
|
+
openssl-devel \
|
|
16
|
+
wget \
|
|
17
|
+
git \
|
|
18
|
+
gnupg2 \
|
|
19
|
+
libnsl \
|
|
20
|
+
perl && \
|
|
21
21
|
dnf clean all
|
|
22
22
|
|
|
23
23
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
FROM rockylinux:9
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# Update and install required packages
|
|
4
4
|
RUN dnf -y update && \
|
|
5
5
|
dnf -y install epel-release && \
|
|
6
6
|
dnf -y install --allowerasing \
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
bzip2 \
|
|
8
|
+
sudo \
|
|
9
|
+
curl \
|
|
10
|
+
net-tools \
|
|
11
|
+
openssh-server \
|
|
12
|
+
nano \
|
|
13
|
+
vim-enhanced \
|
|
14
|
+
less \
|
|
15
|
+
openssl-devel \
|
|
16
|
+
wget \
|
|
17
|
+
git \
|
|
18
|
+
gnupg2 \
|
|
19
|
+
libnsl \
|
|
20
|
+
perl && \
|
|
21
21
|
dnf clean all
|
|
22
22
|
|
|
23
23
|
# --- Download and install XAMPP
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
|
-
import swaggerAutoGen from 'swagger-autogen';
|
|
11
10
|
import { shellExec } from './process.js';
|
|
12
11
|
import { loggerFactory } from './logger.js';
|
|
13
12
|
import { JSONweb } from './client-formatted.js';
|
|
@@ -123,13 +122,33 @@ const buildApiDocs = async ({
|
|
|
123
122
|
|
|
124
123
|
logger.warn('build swagger api docs', doc.info);
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
// swagger-autogen@2.9.2 bug: getProducesTag, getConsumesTag, getResponsesTag missing __¬¬¬__ decode before eval
|
|
126
|
+
fs.writeFileSync(
|
|
127
|
+
`node_modules/swagger-autogen/src/swagger-tags.js`,
|
|
128
|
+
fs
|
|
129
|
+
.readFileSync(`node_modules/swagger-autogen/src/swagger-tags.js`, 'utf8')
|
|
130
|
+
// getProducesTag and getConsumesTag: already decode " but not __¬¬¬__
|
|
131
|
+
.replaceAll(
|
|
132
|
+
`data.replaceAll('\\n', ' ').replaceAll('\u201c', '\u201d')`,
|
|
133
|
+
`data.replaceAll('\\n', ' ').replaceAll('\u201c', '\u201d').replaceAll('__\u00ac\u00ac\u00ac__', '"')`,
|
|
134
|
+
)
|
|
135
|
+
// getResponsesTag: decodes neither " nor __¬¬¬__
|
|
136
|
+
.replaceAll(
|
|
137
|
+
`data.replaceAll('\\n', ' ');`,
|
|
138
|
+
`data.replaceAll('\\n', ' ').replaceAll('__\u00ac\u00ac\u00ac__', '"');`,
|
|
139
|
+
),
|
|
140
|
+
'utf8',
|
|
141
|
+
);
|
|
142
|
+
setTimeout(async () => {
|
|
143
|
+
const { default: swaggerAutoGen } = await import('swagger-autogen');
|
|
144
|
+
const outputFile = `./public/${host}${path === '/' ? path : `${path}/`}swagger-output.json`;
|
|
145
|
+
const routes = [];
|
|
146
|
+
for (const api of apis) {
|
|
147
|
+
if (['user'].includes(api)) routes.push(`./src/api/${api}/${api}.router.js`);
|
|
148
|
+
}
|
|
131
149
|
|
|
132
|
-
|
|
150
|
+
await swaggerAutoGen({ openapi: '3.0.0' })(outputFile, routes, doc);
|
|
151
|
+
});
|
|
133
152
|
};
|
|
134
153
|
|
|
135
154
|
/**
|
package/src/server/conf.js
CHANGED
|
@@ -1335,26 +1335,9 @@ const buildCliDoc = (program, oldVersion, newVersion) => {
|
|
|
1335
1335
|
});
|
|
1336
1336
|
md = md.replaceAll(oldVersion, newVersion);
|
|
1337
1337
|
fs.writeFileSync(`./src/client/public/nexodev/docs/references/Command Line Interface.md`, md, 'utf8');
|
|
1338
|
-
fs.writeFileSync(`./
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
fs.writeFileSync(
|
|
1342
|
-
'./README.md',
|
|
1343
|
-
(
|
|
1344
|
-
readme[0] +
|
|
1345
|
-
readmeSplit +
|
|
1346
|
-
`
|
|
1347
|
-
|
|
1348
|
-
` +
|
|
1349
|
-
baseOptions +
|
|
1350
|
-
`
|
|
1351
|
-
|
|
1352
|
-
<a target="_top" href="https://github.com/${process.env.GITHUB_USERNAME}/pwa-microservices-template/blob/master/cli.md">See complete CLI Docs here.</a>
|
|
1353
|
-
|
|
1354
|
-
`
|
|
1355
|
-
).replaceAll(oldVersion, newVersion),
|
|
1356
|
-
'utf8',
|
|
1357
|
-
);
|
|
1338
|
+
fs.writeFileSync(`./CLI-HELP.md`, md, 'utf8');
|
|
1339
|
+
const readme = fs.readFileSync(`./README.md`, 'utf8');
|
|
1340
|
+
fs.writeFileSync('./README.md', readme.replaceAll(oldVersion, newVersion), 'utf8');
|
|
1358
1341
|
};
|
|
1359
1342
|
|
|
1360
1343
|
/**
|
package/src/server/logger.js
CHANGED
|
@@ -101,27 +101,37 @@ const setUpInfo = async (logger = new winston.Logger()) => {
|
|
|
101
101
|
* @param meta - The `meta` parameter in the `loggerFactory` function is used to extract the last part
|
|
102
102
|
* of a URL and use it to create log files in a specific directory.
|
|
103
103
|
* @param logLevel - Specify the logging level for the logger instance. e.g., 'error', 'warn', 'info', 'debug'.
|
|
104
|
+
* @param enableFileLogs - Whether to write logs to files. Defaults to the value of the `ENABLE_FILE_LOGS` environment variable.
|
|
104
105
|
* @returns {underpostLogger} The `loggerFactory` function returns a logger instance created using Winston logger
|
|
105
106
|
* library. The logger instance is configured with various transports for printing out messages to
|
|
106
107
|
* different destinations such as the terminal, error.log file, and all.log file. The logger instance
|
|
107
108
|
* also has a method `setUpInfo` attached to it for setting up additional information.
|
|
108
109
|
* @memberof Logger
|
|
109
110
|
*/
|
|
110
|
-
const loggerFactory = (
|
|
111
|
+
const loggerFactory = (
|
|
112
|
+
meta = { url: '' },
|
|
113
|
+
logLevel = '',
|
|
114
|
+
enableFileLogs = process.env.ENABLE_FILE_LOGS === 'true' || process.env.ENABLE_FILE_LOGS === true,
|
|
115
|
+
) => {
|
|
111
116
|
meta = meta.url.split('/').pop();
|
|
112
117
|
// Define which transports the logger must use to print out messages.
|
|
113
118
|
// In this example, we are using three different transports
|
|
114
119
|
const transports = [
|
|
115
120
|
// Allow the use the terminal to print the messages
|
|
116
121
|
new winston.transports.Console(),
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
// Optionally write log files when enableFileLogs is true
|
|
123
|
+
...(enableFileLogs
|
|
124
|
+
? [
|
|
125
|
+
// Allow to print all the error level messages inside the error.log file
|
|
126
|
+
new winston.transports.File({
|
|
127
|
+
filename: `logs/${meta}/error.log`,
|
|
128
|
+
level: 'error',
|
|
129
|
+
}),
|
|
130
|
+
// Allow to print all the error messages inside the all.log file
|
|
131
|
+
// (also includes error logs that are also printed inside error.log)
|
|
132
|
+
new winston.transports.File({ filename: `logs/${meta}/all.log` }),
|
|
133
|
+
]
|
|
134
|
+
: []),
|
|
125
135
|
];
|
|
126
136
|
|
|
127
137
|
// Create the logger instance that has to be exported
|
|
@@ -154,6 +164,7 @@ const loggerFactory = (meta = { url: '' }, logLevel = '') => {
|
|
|
154
164
|
* @param {Object} meta - An object containing metadata, such as the URL, to be used in the logger.
|
|
155
165
|
* @param {string} logLevel - The logging level to be used for the logger (e.g., 'error', 'warn', 'info', 'debug').
|
|
156
166
|
* @param {Function} skip - A function to determine whether to skip logging for a particular request.
|
|
167
|
+
* @param {boolean} enableFileLogs - Whether to write logs to files. Defaults to false.
|
|
157
168
|
* @returns {Function} A middleware function that can be used in an Express application to log HTTP requests.
|
|
158
169
|
* @memberof Logger
|
|
159
170
|
*/
|
|
@@ -161,10 +172,11 @@ const loggerMiddleware = (
|
|
|
161
172
|
meta = { url: '' },
|
|
162
173
|
logLevel = 'info',
|
|
163
174
|
skip = (req, res) => process.env.NODE_ENV === 'production',
|
|
175
|
+
enableFileLogs = process.env.ENABLE_FILE_LOGS === 'true' || process.env.ENABLE_FILE_LOGS === true,
|
|
164
176
|
) => {
|
|
165
177
|
const stream = {
|
|
166
178
|
// Use the http severity
|
|
167
|
-
write: (message) => loggerFactory(meta, logLevel).http(message),
|
|
179
|
+
write: (message) => loggerFactory(meta, logLevel, enableFileLogs).http(message),
|
|
168
180
|
};
|
|
169
181
|
|
|
170
182
|
morgan.token('host', function (req, res) {
|
package/.vscode/zed.keymap.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"context": "Editor",
|
|
4
|
-
"bindings": {
|
|
5
|
-
"ctrl-c": "editor::Copy",
|
|
6
|
-
"ctrl-x": "editor::Cut",
|
|
7
|
-
"ctrl-v": "editor::Paste",
|
|
8
|
-
"ctrl-shift-c": "editor::CopyAndTrim",
|
|
9
|
-
"ctrl-shift-v": "editor::Paste",
|
|
10
|
-
"cmd-c": "editor::Copy",
|
|
11
|
-
"cmd-x": "editor::Cut",
|
|
12
|
-
"cmd-v": "editor::Paste"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"context": "Terminal",
|
|
17
|
-
"bindings": {
|
|
18
|
-
"ctrl-shift-c": "terminal::Copy",
|
|
19
|
-
"ctrl-shift-v": "terminal::Paste",
|
|
20
|
-
"cmd-shift-c": "terminal::Copy",
|
|
21
|
-
"cmd-shift-v": "terminal::Paste"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"context": "Editor && edit_prediction",
|
|
26
|
-
"bindings": {
|
|
27
|
-
"tab": "editor::AcceptEditPrediction",
|
|
28
|
-
"alt-tab": "editor::AcceptEditPrediction",
|
|
29
|
-
"alt-l": null
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"context": "Editor && edit_prediction_conflict",
|
|
34
|
-
"bindings": {
|
|
35
|
-
"alt-l": "editor::AcceptEditPrediction",
|
|
36
|
-
"tab": "editor::ComposeCompletion"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
]
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ui_font_size": 16,
|
|
3
|
-
"buffer_font_size": 15,
|
|
4
|
-
"theme": {
|
|
5
|
-
"mode": "system",
|
|
6
|
-
"light": "One Dark",
|
|
7
|
-
"dark": "One Dark"
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
"features": {
|
|
11
|
-
"edit_prediction_provider": "copilot",
|
|
12
|
-
"copilot": true // https://github.com/login/device
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
"show_edit_predictions": true,
|
|
16
|
-
|
|
17
|
-
"edit_predictions": {
|
|
18
|
-
"mode": "eager"
|
|
19
|
-
}
|
|
20
|
-
}
|
package/bin/cron.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { BackUpManagement } from '../src/server/backup.js';
|
|
2
|
-
import { Cmd } from '../src/server/conf.js';
|
|
3
|
-
import { Dns } from '../src/server/dns.js';
|
|
4
|
-
import { loggerFactory } from '../src/server/logger.js';
|
|
5
|
-
import { netWorkCron, saveRuntimeCron } from '../src/server/network.js';
|
|
6
|
-
import { shellExec } from '../src/server/process.js';
|
|
7
|
-
import fs from 'fs-extra';
|
|
8
|
-
|
|
9
|
-
const logger = loggerFactory(import.meta);
|
|
10
|
-
|
|
11
|
-
await logger.setUpInfo();
|
|
12
|
-
|
|
13
|
-
switch (process.argv[2]) {
|
|
14
|
-
case 'backups':
|
|
15
|
-
{
|
|
16
|
-
await BackUpManagement.Init({ deployId: process.argv[3] });
|
|
17
|
-
}
|
|
18
|
-
break;
|
|
19
|
-
case 'dns':
|
|
20
|
-
{
|
|
21
|
-
await Dns.InitIpDaemon({ deployId: process.argv[3] });
|
|
22
|
-
}
|
|
23
|
-
break;
|
|
24
|
-
|
|
25
|
-
case 'run': {
|
|
26
|
-
const confCronConfig = JSON.parse(fs.readFileSync(`./engine-private/conf/${process.argv[3]}/conf.cron.json`));
|
|
27
|
-
if (confCronConfig.jobs && Object.keys(confCronConfig.jobs).length > 0) {
|
|
28
|
-
shellExec(`node bin/deploy conf ${process.argv[3]} production`);
|
|
29
|
-
for (const job of Object.keys(confCronConfig.jobs)) {
|
|
30
|
-
if (confCronConfig.jobs[job].enabled) {
|
|
31
|
-
shellExec(Cmd.cron(process.argv[3], job, confCronConfig.jobs[job].expression));
|
|
32
|
-
netWorkCron.push({
|
|
33
|
-
deployId: process.argv[3],
|
|
34
|
-
jobId: job,
|
|
35
|
-
expression: confCronConfig.jobs[job].expression,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
await saveRuntimeCron();
|
|
41
|
-
if (fs.existsSync(`./tmp/await-deploy`)) fs.remove(`./tmp/await-deploy`);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
default:
|
|
46
|
-
break;
|
|
47
|
-
}
|
package/bin/db.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import { shellExec } from '../src/server/process.js';
|
|
3
|
-
import { loggerFactory } from '../src/server/logger.js';
|
|
4
|
-
import { MariaDB } from '../src/db/mariadb/MariaDB.js';
|
|
5
|
-
import { Lampp } from '../src/runtime/lampp/Lampp.js';
|
|
6
|
-
import { getCapVariableName, loadConf, splitFileFactory } from '../src/server/conf.js';
|
|
7
|
-
import { DataBaseProvider } from '../src/db/DataBaseProvider.js';
|
|
8
|
-
import { hashPassword } from '../src/server/auth.js';
|
|
9
|
-
|
|
10
|
-
const logger = loggerFactory(import.meta);
|
|
11
|
-
|
|
12
|
-
logger.info('argv', process.argv);
|
|
13
|
-
|
|
14
|
-
const [exe, dir, hostPath = '', operator, deployId, arg0, arg1, arg2] = process.argv;
|
|
15
|
-
const [host, _path = ''] = hostPath.split('/');
|
|
16
|
-
const path = `/${_path}`;
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
let cmd;
|
|
20
|
-
if (deployId) loadConf(deployId);
|
|
21
|
-
const confServer = JSON.parse(fs.readFileSync(`./conf/conf.server.json`, 'utf8'));
|
|
22
|
-
const { runtime, db, git, client, directory } = confServer[host][path];
|
|
23
|
-
const { provider, name, user, password = '', backupPath = '' } = db;
|
|
24
|
-
// logger.info('database', confServer[host][`/${path}`].db);
|
|
25
|
-
switch (provider) {
|
|
26
|
-
case 'mariadb':
|
|
27
|
-
// Login:
|
|
28
|
-
// mysql -u root -h localhost -p
|
|
29
|
-
|
|
30
|
-
// Get Users:
|
|
31
|
-
// SELECT user,authentication_string,plugin,host FROM mysql.user;
|
|
32
|
-
|
|
33
|
-
// Get DB User:
|
|
34
|
-
// SELECT User, Db, Host from mysql.db;
|
|
35
|
-
|
|
36
|
-
// Change password:
|
|
37
|
-
// ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY 'NEW_PASSWORD';
|
|
38
|
-
// ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_PASSWORD';
|
|
39
|
-
// ALTER USER 'root'@'::1' IDENTIFIED BY 'NEW_PASSWORD';
|
|
40
|
-
|
|
41
|
-
// Get all user privileges:
|
|
42
|
-
// select * from information_schema.user_privileges;
|
|
43
|
-
|
|
44
|
-
// Expose public server:
|
|
45
|
-
// '/etc/mysql/my.cnf' Change lines:
|
|
46
|
-
// bind-address = 127.0.0.1 -> bind-address = 0.0.0.0
|
|
47
|
-
// skip-networking -> #skip-networking
|
|
48
|
-
|
|
49
|
-
// Create user:
|
|
50
|
-
// DROP USER 'username'@'%';
|
|
51
|
-
// CREATE USER 'username'@'%' IDENTIFIED BY 'password';
|
|
52
|
-
|
|
53
|
-
// Set DB user:
|
|
54
|
-
// FLUSH PRIVILEGES;
|
|
55
|
-
// ON databasename.*
|
|
56
|
-
// TO 'username'@'%'
|
|
57
|
-
// IDENTIFIED BY 'newpassword';
|
|
58
|
-
// FLUSH PRIVILEGES;
|
|
59
|
-
|
|
60
|
-
// Set admin:
|
|
61
|
-
// FLUSH PRIVILEGES;
|
|
62
|
-
// GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
|
|
63
|
-
// FLUSH PRIVILEGES;
|
|
64
|
-
|
|
65
|
-
switch (operator) {
|
|
66
|
-
case 'show-all':
|
|
67
|
-
await MariaDB.query({ user, password, query: `SHOW DATABASES` });
|
|
68
|
-
break;
|
|
69
|
-
case 'show':
|
|
70
|
-
await MariaDB.query({ user, password, query: `SHOW TABLES FROM ${name}` });
|
|
71
|
-
break;
|
|
72
|
-
case 'create':
|
|
73
|
-
await MariaDB.query({ user, password, query: `CREATE DATABASE ${name}` });
|
|
74
|
-
break;
|
|
75
|
-
case 'delete':
|
|
76
|
-
await MariaDB.query({ user, password, query: `DROP DATABASE IF EXISTS ${name}` });
|
|
77
|
-
break;
|
|
78
|
-
case 'select':
|
|
79
|
-
{
|
|
80
|
-
const pageSize = 10;
|
|
81
|
-
const pageNumber = 1;
|
|
82
|
-
await MariaDB.query({
|
|
83
|
-
user,
|
|
84
|
-
password,
|
|
85
|
-
query: `SELECT ${arg0} FROM ${name}.${arg1} LIMIT ${pageSize} OFFSET ${(pageNumber - 1) * pageSize}`,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
case 'count': {
|
|
90
|
-
await MariaDB.query({
|
|
91
|
-
user,
|
|
92
|
-
password,
|
|
93
|
-
query: `SELECT COUNT(*) AS total FROM ${name}.${arg0}`,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
case 'export':
|
|
97
|
-
{
|
|
98
|
-
const cmdBackupPath = `${arg0 ? `${arg0}/${name}.sql` : backupPath}`;
|
|
99
|
-
|
|
100
|
-
cmd = `mysqldump -u ${user} -p${password} ${name} > ${cmdBackupPath}`;
|
|
101
|
-
shellExec(cmd);
|
|
102
|
-
await splitFileFactory(name, cmdBackupPath);
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
case 'import':
|
|
106
|
-
break;
|
|
107
|
-
|
|
108
|
-
case 'init-lampp-service':
|
|
109
|
-
await Lampp.initService();
|
|
110
|
-
break;
|
|
111
|
-
case 'remote-client-access':
|
|
112
|
-
{
|
|
113
|
-
// https://docs.anaconda.com/miniconda/install/#quick-command-line-install
|
|
114
|
-
// https://mariadb.com/kb/en/configuring-mariadb-for-remote-client-access/
|
|
115
|
-
// conf: /opt/lampp/etc
|
|
116
|
-
// conf: /etc/mysql/my.cnf
|
|
117
|
-
// conf: /etc/mysql/mariadb.conf.d/50-server.cnf
|
|
118
|
-
// cli: /opt/lampp/bin/mysql
|
|
119
|
-
// cli: mysql -h 127.0.0.1
|
|
120
|
-
// select db: use db0;
|
|
121
|
-
}
|
|
122
|
-
break;
|
|
123
|
-
default:
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
break;
|
|
128
|
-
|
|
129
|
-
case 'mongoose':
|
|
130
|
-
// MongoDB App Services CLI
|
|
131
|
-
switch (operator) {
|
|
132
|
-
case 'update':
|
|
133
|
-
{
|
|
134
|
-
await DataBaseProvider.load({ apis: [arg0], host, path, db });
|
|
135
|
-
const models = DataBaseProvider.instance[`${host}${path}`].mongoose.models[getCapVariableName(arg0)];
|
|
136
|
-
|
|
137
|
-
const select = JSON.parse(arg1.replaceAll("'", `"`));
|
|
138
|
-
const update = JSON.parse(arg2.replaceAll("'", `"`));
|
|
139
|
-
|
|
140
|
-
console.log({ models, select, update });
|
|
141
|
-
|
|
142
|
-
switch (arg0) {
|
|
143
|
-
case 'user':
|
|
144
|
-
if (update.password) update.password = hashPassword(update.password);
|
|
145
|
-
|
|
146
|
-
default:
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
let doc = await models.findOne(select);
|
|
150
|
-
if (doc) {
|
|
151
|
-
doc = await models.findByIdAndUpdate(doc._id, update, {
|
|
152
|
-
runValidators: true,
|
|
153
|
-
});
|
|
154
|
-
logger.info(`successfully updated doc`, doc._doc);
|
|
155
|
-
await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
|
|
156
|
-
} else throw new Error(`no doc found`);
|
|
157
|
-
}
|
|
158
|
-
break;
|
|
159
|
-
case 'show-all':
|
|
160
|
-
// show dbs
|
|
161
|
-
break;
|
|
162
|
-
case 'show':
|
|
163
|
-
break;
|
|
164
|
-
case 'create':
|
|
165
|
-
break;
|
|
166
|
-
case 'delete':
|
|
167
|
-
{
|
|
168
|
-
await DataBaseProvider.load({ apis: [arg0], host, path, db });
|
|
169
|
-
const models = DataBaseProvider.instance[`${host}${path}`].mongoose.models[getCapVariableName(arg0)];
|
|
170
|
-
await models.collection.drop();
|
|
171
|
-
logger.info(`successfully drop collection`, arg0);
|
|
172
|
-
await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
|
|
173
|
-
}
|
|
174
|
-
break;
|
|
175
|
-
case 'export':
|
|
176
|
-
// mongodump -d <database_name> -o <directory_backup>
|
|
177
|
-
shellExec(`mongodump -d ${name} -o ${arg0 ? arg0 : `./engine-private/mongodb-backup/`}`);
|
|
178
|
-
break;
|
|
179
|
-
case 'import':
|
|
180
|
-
// mongorestore -d <database_name> <directory_backup>
|
|
181
|
-
break;
|
|
182
|
-
case 'init-service':
|
|
183
|
-
break;
|
|
184
|
-
default:
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
break;
|
|
188
|
-
|
|
189
|
-
default:
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// logger.info(`Run the following command`, cmd);
|
|
194
|
-
// await ncp.copy(cmd);
|
|
195
|
-
// await read({ prompt: 'Command copy to clipboard, press enter to continue.\n' });
|
|
196
|
-
// throw new Error(``);
|
|
197
|
-
} catch (error) {
|
|
198
|
-
logger.error(error, error.stack);
|
|
199
|
-
}
|
package/bin/hwt.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
|
|
3
|
-
import { loggerFactory } from '../src/server/logger.js';
|
|
4
|
-
|
|
5
|
-
const logger = loggerFactory(import.meta);
|
|
6
|
-
|
|
7
|
-
logger.info('argv', process.argv);
|
|
8
|
-
|
|
9
|
-
const [exe, dir, operator, templateId, publicPath] = process.argv;
|
|
10
|
-
|
|
11
|
-
// engine for 'html-website-templates'
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
switch (operator) {
|
|
15
|
-
case 'set-base':
|
|
16
|
-
{
|
|
17
|
-
switch (parseInt(templateId)) {
|
|
18
|
-
// Horizontal Scroll One Page Template Website
|
|
19
|
-
case 0:
|
|
20
|
-
{
|
|
21
|
-
fs.writeFile(
|
|
22
|
-
`${publicPath}/index.html`,
|
|
23
|
-
fs
|
|
24
|
-
.readFileSync(`${publicPath}/index.html`, 'utf8')
|
|
25
|
-
.replace(`<ul class="menu">`, `<ul class="menu hidden">`)
|
|
26
|
-
.replaceAll(`<section class="slide fade-6 kenBurns">`, `<section class="fade-6 kenBurns hidden">`)
|
|
27
|
-
.replace(`<section class="fade-6 kenBurns hidden">`, `<section class="slide fade-6 kenBurns">`)
|
|
28
|
-
.replaceAll(
|
|
29
|
-
`<nav class="panel bottom forceMobileView">`,
|
|
30
|
-
`<nav class="panel bottom forceMobileView hidden">`,
|
|
31
|
-
),
|
|
32
|
-
|
|
33
|
-
'utf8',
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
break;
|
|
37
|
-
|
|
38
|
-
default:
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
43
|
-
|
|
44
|
-
default:
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
} catch (error) {
|
|
48
|
-
logger.error(error, error.stack);
|
|
49
|
-
}
|