Working prototype and clear and easy to understand logic.
Daan committed
Mar 22, 2025 at 03:21 UTC
660312eff37fc8d7c28f905264c3aa25f08151d9
4 files changed
+170
-82
docker/Dockerfile
+1
-1
@@ -93,7 +93,7 @@ WORKDIR /opt/meshcentral
93
94
RUN apk update \
95
&& apk add --no-cache --update \
96
- bash gcc g++ jq make nodejs npm postgresql-client python3 tzdata \
96
+ bash gcc g++ jq make nodejs npm python3 tzdata \
97
&& rm -rf /var/cache/* \
98
/tmp/* \
99
/usr/share/man/ \
docker/README.md
+46
-37
@@ -18,47 +18,57 @@
18
You can place the `config.json` file directly under `./meshcentral/data/`, or use the following `.env` file instead.
19
20
```ini
21
-NODE_ENV=production
22
-
23
-USE_MONGODB=false
24
-# set already exist mongo connection string url here
25
-MONGO_URL=
26
-# or set following init params for new mongodb, use it with docker-compose file with mongodb version
27
-MONGO_INITDB_ROOT_USERNAME=mongodbadmin
28
-MONGO_INITDB_ROOT_PASSWORD=mongodbpasswd
29
-
30
-# initial meshcentral-variables
31
-# the following options are only used if no config.json exists in the data-folder
32
-
33
-# your hostname
34
-HOSTNAME=my.domain.com
35
-# set to your reverse proxy IP if you want to put meshcentral behind a reverse proxy
36
-REVERSE_PROXY=false
37
-REVERSE_PROXY_TLS_PORT=
38
-# set to true if you wish to enable iframe support
39
-IFRAME=false
40
-# set to false if you want disable self-service creation of new accounts besides the first (admin)
41
-ALLOW_NEW_ACCOUNTS=true
42
-# set to true to enable WebRTC - per documentation it is not officially released with meshcentral and currently experimental. Use with caution
43
-WEBRTC=false
44
-# set to true to allow plugins
45
-ALLOWPLUGINS=false
46
-# set to true to allow session recording
47
-LOCALSESSIONRECORDING=false
48
-# set to enable or disable minification of json, reduces traffic
49
-MINIFY=true
50
-# set this value to add extra arguments to meshcentral on startup (e.g --debug ldap)
51
-ARGS=
52
-# set to the hostname(s) meshcentral will be reachable on, or true to disable origin checking
53
-# forms allowed "hostname" or "hostname1,hostname2" or ["hostname1","hostname2"]
54
-ALLOWED_ORIGIN=false
21
+NODE_ENV = "production"
22
+# Leave CONFIG_FILE as per default by using this, or removing it completely from the list. Otherwise if you know what you are doing, you can use this.
23
+CONFIG_FILE = "/opt/meshcentral/meshcentral-data/config.json"
24
+# DYNAMIC_CONFIG enables the config to be rechecked on every restart. If disabled then the container runtime will not change the config.json.
25
+DYNAMIC_CONFIG = "true"
26
+
27
+# Environment variables for the MeshCentral Config.json
28
+ALLOWPLUGINS = "false"
29
+ALLOW_NEW_ACCOUNTS = "false"
30
+ALLOWED_ORIGIN = "false"
31
+ARGS = ""
32
+HOSTNAME = "localhost"
33
+IFRAME = "false"
34
+LOCALSESSIONRECORDING = "true"
35
+MINIFY = "true"
36
+REGENSESSIONKEY = "false"
37
+REVERSE_PROXY = ""
38
+REVERSE_PROXY_TLS_PORT = ""
39
+WEBRTC = "false"
40
+
41
+# MongoDB Variables
42
+INCLUDE_MONGODB_TOOLS = "false"
43
+USE_MONGODB = "false"
44
+MONGO_HOST = ""
45
+MONGO_PORT = "27017"
46
+MONGO_USERNAME = ""
47
+MONGO_PASS = ""
48
+MONGO_URL = ""
49
+
50
+# PostgreSQL Variables
51
+INCLUDE_POSTGRESQL_TOOLS = "false"
52
+USE_POSTGRESQL = "false"
53
+PSQL_HOST = ""
54
+PSQL_PORT = "5432"
55
+PSQL_USER = ""
56
+PSQL_PASS = ""
57
+PSQL_DATABASE = ""
58
+
59
+# MariaDB/MySQL Variables (Alpine Linux only provides MariaDB binaries)
60
+INCLUDE_MARIADB_TOOLS = "false"
61
+USE_MARIADB = "false"
62
+MARIADB_HOST = ""
63
+MARIADB_PORT = "3306"
64
+MARIADB_USER = ""
65
+MARIADB_PASS = ""
66
+MARIADB_DATABASE = ""
67
```
68
69
## docker-compose.yml
70
71
```yaml
60
-version: '3'
61
-
72
services:
73
meshcentral:
74
restart: always
@@ -66,7 +76,6 @@ services:
76
# use the official meshcentral container
77
image: ghcr.io/ylianst/meshcentral:latest
78
ports:
69
- # MeshCentral will moan and try everything not to use port 80, but you can also use it if you so desire, just change the config.json according to your needs
79
- 8086:443
80
env_file:
81
- .env
docker/config.json.template
+10
-1
@@ -1,7 +1,9 @@
1
{
2
"$schema": "https://raw.githubusercontent.com/Ylianst/MeshCentral/master/meshcentral-config-schema.json",
3
"settings": {
4
- "plugins":{"enabled": false},
4
+ "plugins":{
5
+ "enabled": false
6
+ },
7
"cert": "myserver.mydomain.com",
8
"_WANonly": true,
9
"_LANonly": true,
@@ -22,6 +24,13 @@
24
"user": "",
25
"password": "",
26
"database": ""
27
+ },
28
+ "_mariaDB": {
29
+ "host": "",
30
+ "port": "",
31
+ "user": "",
32
+ "password": "",
33
+ "database": ""
34
}
35
},
36
"domains": {
docker/entrypoint.sh
+113
-43
@@ -3,9 +3,11 @@
3
graceful_shutdown() {
4
echo "Received SIGTERM. Cleaning up..."
5
node /opt/meshcentral/meshcentral/meshcentral --stop
6
+
7
+ echo "MeshCentral process stopped. Exiting..."
8
exit 0
9
}
8
-trap cleanup SIGTERM
10
+trap graceful_shutdown SIGTERM
11
12
### Start MeshCentral Docker Container.
13
@@ -20,8 +22,13 @@ else
22
fi
23
24
if [[ "$DYNAMIC_CONFIG" =~ ^(true|yes)$ ]]; then
25
+ cat $CONFIG_FILE
26
+ echo "Using Dynamic Configuration values..."
27
28
+ # BEGIN DATABASE CONFIGURATION FIELDS
29
if [[ "$USE_MONGODB" =~ ^(true|yes)$ ]]; then
30
+ echo "Enabling MongoDB-connector..."
31
+
32
if [[ -n "$MONGO_URL" ]]; then
33
echo "MONGO_URL is set, using that..."
34
else
@@ -32,20 +39,49 @@ if [[ "$DYNAMIC_CONFIG" =~ ^(true|yes)$ ]]; then
39
sed -i 's/"_mongoDb"/"mongoDb"/' "$CONFIG_FILE"
40
sed -i "s/\"mongoDb\": *\"[^\"]*\"/\"mongoDb\": \"$ESCAPED_MONGO_URL\"/" "$CONFIG_FILE"
41
else
42
+ echo "Disabling MongoDB-connector..."
43
sed -i 's/"mongoDb"/"_mongoDb"/' "$CONFIG_FILE"
44
fi
45
46
if [[ "$USE_POSTGRESQL" =~ ^(true|yes)$ ]]; then
39
- echo "So you wanna postgres"
47
+ echo "Enabling PostgreSQL-connector..."
48
+
49
+ sed -i 's/"_postgres"/"postgres"/' "$CONFIG_FILE"
50
+ jq --arg psql_host "$PSQL_HOST" \
51
+ --arg psql_port "$PSQL_PORT" \
52
+ --arg psql_user "$PSQL_USER" \
53
+ --arg psql_pass "$PSQL_PASS" \
54
+ --arg psql_db "$PSQL_DATABASE" \
55
+ '.settings.postgres.host = $psql_host |
56
+ .settings.postgres.port = $psql_port |
57
+ .settings.postgres.user = $psql_user |
58
+ .settings.postgres.password = $psql_pass |
59
+ .settings.postgres.database = $psql_db' \
60
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
61
else
41
- echo "No Postgres"
62
+ echo "Disabling PostgreSQL-connector..."
63
+ sed -i 's/"postgres"/"_postgres"/' "$CONFIG_FILE"
64
fi
65
66
if [[ "$USE_MARIADB" =~ ^(true|yes)$ ]]; then
45
- echo "So you wanna MariaDB"
67
+ echo "Enabling MariaDB-connector..."
68
+ sed -i 's/"_mariaDB"/"mariaDB"/' "$CONFIG_FILE"
69
+ jq --arg mariadb_host "$MARIADB_HOST" \
70
+ --arg mariadb_port "$MARIADB_PORT" \
71
+ --arg mariadb_user "$MARIADB_USER" \
72
+ --arg mariadb_pass "$MARIADB_PASS" \
73
+ --arg mariadb_db "$MARIADB_DATABASE" \
74
+ '.settings.mariaDB.host = $mariadb_host |
75
+ .settings.mariaDB.port = $mariadb_port |
76
+ .settings.mariaDB.user = $mariadb_user |
77
+ .settings.mariaDB.password = $mariadb_pass |
78
+ .settings.mariaDB.database = $mariadb_db' \
79
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
80
else
47
- echo "No MariaDB"
81
+ echo "Disabling MariaDB-connector..."
82
+ sed -i 's/"mariaDB"/"_mariaDB"/' "$CONFIG_FILE"
83
fi
84
+ # END DATABASE CONFIGURATION FIELDS
85
86
# Doing the bulk with JQ utility. Given the remaining variables an opportunity with Sed.
87
# The way this works is if the environment variable is empty, it will add a _ in front of the variable, commenting it.
@@ -60,102 +96,136 @@ if [[ "$DYNAMIC_CONFIG" =~ ^(true|yes)$ ]]; then
96
SESSION_KEY=$(tr -dc 'A-Z0-9' < /dev/urandom | fold -w 96 | head -n 1)
97
98
sed -i 's/"_sessionKey"/"sessionKey"/' "$CONFIG_FILE"
63
- sed -i "s/\"sessionKey\": *\"[^\"]*\"/\"sessionKey\": \"$SESSION_KEY\"/" "$CONFIG_FILE"
99
+ jq --arg session_key "$SESSION_KEY" \
100
+ '.settings.sessionKey = $session_key' \
101
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
102
else
103
echo "REGENSESSIONKEY is not 'true' or 'yes', therefore it's being kept as is."
104
fi
105
106
# HOSTNAME
69
- if [[ -n $HOSTNAME ]] && [[ $HOSTNAME =~ ^([a-zA-Z0-9-]+\.)+[a-zA-Z0-9-]+$ ]]; then
70
- echo "Setting hostname (cert)... - $HOSTNAME"
71
- sed -i 's/"_cert"/"cert"/' "$CONFIG_FILE"
72
- sed -i "s/\"cert\": *\"[^\"]*\"/\"cert\": \"$HOSTNAME\"/" "$CONFIG_FILE"
107
+ if [[ -n $HOSTNAME ]] && [[ $HOSTNAME =~ ^[a-zA-Z0-9-]+$ ]]; then
108
+ echo "Setting hostname (cert)... $HOSTNAME"
109
+
110
+ jq --arg hostname "$HOSTNAME" \
111
+ '.settings.cert = $hostname' \
112
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
113
else
74
- echo "Invalid hostname, commenting it out..."
75
- sed -i "s/\"cert\": *\"[^\"]*\"/\"cert\": \"localhost\"/" "$CONFIG_FILE"
114
+ echo "Invalid or no hostname, defaulting to 'localhost', value given: $HOSTNAME"
115
+ jq --arg hostname "localhost" \
116
+ '.settings.cert = $hostname' \
117
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
118
fi
119
120
# ALLOW_NEW_ACCOUNTS
121
if [[ -n $ALLOW_NEW_ACCOUNTS ]] && [[ $ALLOW_NEW_ACCOUNTS =~ ^(true|false)$ ]]; then
80
- echo "Setting NewAccounts... - $ALLOW_NEW_ACCOUNTS"
122
+ echo "Setting NewAccounts... $ALLOW_NEW_ACCOUNTS"
123
+
124
sed -i 's/"_NewAccounts"/"NewAccounts"/' "$CONFIG_FILE"
82
- sed -i "s/\"NewAccounts\": *[a-z]*/\"NewAccounts\": $ALLOW_NEW_ACCOUNTS/" "$CONFIG_FILE"
125
+ jq --argjson new_accounts "$ALLOW_NEW_ACCOUNTS" \
126
+ '.domains[""].NewAccounts = $new_accounts' \
127
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
128
else
84
- echo "Invalid ALLOW_NEW_ACCOUNTS value given, commenting out so default applies..."
129
+ echo "Invalid or no ALLOW_NEW_ACCOUNTS value given, commenting out so default applies... Value given: $ALLOW_NEW_ACCOUNTS"
130
sed -i 's/"NewAccounts":/"_NewAccounts":/g' "$CONFIG_FILE"
131
fi
132
133
# ALLOWPLUGINS
134
if [[ -n $ALLOWPLUGINS ]] && [[ $ALLOWPLUGINS =~ ^(true|false)$ ]]; then
90
- echo "Setting plugins... - $ALLOWPLUGINS"
135
+ echo "Setting plugins... $ALLOWPLUGINS"
136
+
137
sed -i 's/"_plugins"/"plugins"/' "$CONFIG_FILE"
92
- sed -i "s/\"plugins\": *{[^}]*}/\"plugins\": {\"enabled\": $ALLOWPLUGINS}/" "$CONFIG_FILE"
138
+ jq --argjson allow_plugins "$ALLOWPLUGINS" \
139
+ '.settings.plugins.enabled = $allow_plugins' \
140
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
141
else
94
- echo "Invalid ALLOWPLUGINS value given, commenting out so default applies..."
142
+ echo "Invalid or no ALLOWPLUGINS value given, commenting out so default applies... Value given: $ALLOWPLUGINS"
143
sed -i 's/"plugins":/"_plugins":/g' "$CONFIG_FILE"
144
fi
145
146
# LOCALSESSIONRECORDING
147
if [[ -n $LOCALSESSIONRECORDING ]] && [[ $LOCALSESSIONRECORDING =~ ^(true|false)$ ]]; then
100
- echo "Setting localSessionRecording... - $LOCALSESSIONRECORDING"
148
+ echo "Setting localSessionRecording... $LOCALSESSIONRECORDING"
149
+
150
sed -i 's/"_localSessionRecording"/"localSessionRecording"/' "$CONFIG_FILE"
102
- sed -i "s/\"localSessionRecording\": *[a-z]*/\"localSessionRecording\": $LOCALSESSIONRECORDING/" "$CONFIG_FILE"
151
+ jq --argjson session_recording "$LOCALSESSIONRECORDING" \
152
+ '.domains[""].localSessionRecording = $session_recording' \
153
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
154
else
104
- echo "Invalid LOCALSESSIONRECORDING value given, commenting out so default applies..."
155
+ echo "Invalid or no LOCALSESSIONRECORDING value given, commenting out so default applies... Value given: $LOCALSESSIONRECORDING"
156
sed -i 's/"localSessionRecording":/"_localSessionRecording":/g' "$CONFIG_FILE"
157
fi
158
159
# MINIFY
160
if [[ -n $MINIFY ]] && [[ $MINIFY =~ ^(true|false)$ ]]; then
110
- echo "Setting minify... - $MINIFY"
161
+ echo "Setting minify... $MINIFY"
162
+
163
sed -i 's/"_minify"/"minify"/' "$CONFIG_FILE"
112
- sed -i "s/\"minify\": *[a-z]*/\"minify\": $MINIFY/" "$CONFIG_FILE"
164
+ jq --arg minify "$MINIFY" \
165
+ '.domains[""].minify = $minify' \
166
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
167
+ #sed -i "s/\"minify\": *[a-z]*/\"minify\": $MINIFY/" "$CONFIG_FILE"
168
else
114
- echo "Invalid MINIFY value given, commenting out so default applies..."
169
+ echo "Invalid or no MINIFY value given, commenting out so default applies... Value given: $MINIFY"
170
sed -i 's/"minify":/"_minify":/g' "$CONFIG_FILE"
171
fi
172
173
# WEBRTC
174
if [[ -n $WEBRTC ]] && [[ $WEBRTC =~ ^(true|false)$ ]]; then
120
- echo "Setting WebRTC... - $WEBRTC"
175
+ echo "Setting WebRTC... $WEBRTC"
176
+
177
sed -i 's/"_WebRTC"/"WebRTC"/' "$CONFIG_FILE"
122
- sed -i "s/\"WebRTC\": *[a-z]*/\"WebRTC\": $WEBRTC/" "$CONFIG_FILE"
178
+ jq --argjson webrtc "$WEBRTC" \
179
+ '.settings.WebRTC = $webrtc' \
180
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
181
+ #sed -i "s/\"WebRTC\": *[a-z]*/\"WebRTC\": $WEBRTC/" "$CONFIG_FILE"
182
else
124
- echo "Invalid WEBRTC value given, commenting out so default applies..."
183
+ echo "Invalid or no WEBRTC value given, commenting out so default applies... Value given: $WEBRTC"
184
sed -i 's/"WebRTC":/"_WebRTC":/g' "$CONFIG_FILE"
185
fi
186
187
# IFRAME
188
if [[ -n $IFRAME ]] && [[ $IFRAME =~ ^(true|false)$ ]]; then
130
- echo "Setting AllowFraming... - $IFRAME"
189
+ echo "Setting AllowFraming... $IFRAME"
190
+
191
sed -i 's/"_AllowFraming"/"AllowFraming"/' "$CONFIG_FILE"
132
- sed -i "s/\"AllowFraming\": *[a-z]*/\"AllowFraming\": $IFRAME/" "$CONFIG_FILE"
192
+ jq --argjson allow_framing "$IFRAME" \
193
+ '.settings.AllowFraming = $allow_framing' \
194
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
195
else
134
- echo "Invalid IFRAME value given, commenting out so default applies..."
196
+ echo "Invalid or no IFRAME value given, commenting out so default applies... Value given: $IFRAME"
197
sed -i 's/"AllowFraming":/"_AllowFraming":/g' "$CONFIG_FILE"
198
fi
199
200
# ALLOWED_ORIGIN
201
if [[ -n $ALLOWED_ORIGIN ]] && [[ $ALLOWED_ORIGIN =~ ^(true|false)$ ]]; then
140
- echo "Setting allowedOrigin... - $ALLOWED_ORIGIN"
202
+ echo "Setting allowedOrigin... $ALLOWED_ORIGIN"
203
+
204
sed -i 's/"_allowedOrigin"/"allowedOrigin"/' "$CONFIG_FILE"
142
- sed -i "s/\"allowedOrigin\": *[a-z]*/\"allowedOrigin\": $ALLOWED_ORIGIN/" "$CONFIG_FILE"
205
+ jq --arg allowed_origin "$ALLOWED_ORIGIN" \
206
+ '.domains[""].allowedOrigin = $allowed_origin' \
207
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
208
else
144
- echo "Invalid ALLOWED_ORIGIN value given, commenting out so default applies..."
209
+ echo "Invalid or no ALLOWED_ORIGIN value given, commenting out so default applies... Value given: $ALLOWED_ORIGIN"
210
sed -i 's/"allowedOrigin":/"_allowedOrigin":/g' "$CONFIG_FILE"
211
fi
212
148
- echo -e "\n$(cat "$CONFIG_FILE")"
149
-
150
- # TO DO CERTURL - POSTGRESQL - MONGO_INITDB_ROOT_PASSWORD="pass"
213
+ # certUrl
214
+ if [[ -n $REVERSE_PROXY ]] && [[ -n $REVERSE_PROXY_TLS_PORT ]]; then
215
+ REVERSE_PROXY_STRING="${REVERSE_PROXY}:${REVERSE_PROXY_TLS_PORT}"
216
+
217
+ echo "Setting certUrl... - $REVERSE_PROXY_STRING"
218
+ sed -i 's/"_certUrl"/"certUrl"/' "$CONFIG_FILE"
219
+ jq --arg cert_url "$REVERSE_PROXY_STRING" \
220
+ '.domains[""].certUrl = $cert_url' \
221
+ "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
222
+ #sed -i "s/\"certUrl\": *[a-z]*/\"certUrl\": $REVERSE_PROXY_STRING/" "$CONFIG_FILE"
223
+ else
224
+ echo "Invalid or no REVERSE_PROXY and/or REVERSE_PROXY_TLS_PORT value given, commenting out so default applies... Value(s) given: $REVERSE_PROXY_STRING"
225
+ sed -i 's/"certUrl":/"_certUrl":/g' "$CONFIG_FILE"
226
+ fi
227
152
- #if [[ "$ALLOWED_ORIGIN" =~ ^\[.*\]|^true|^false ]]; then
153
- # sed -i "s/\"allowedOrigin\": false/\"allowedOrigin\": $ALLOWED_ORIGIN/" meshcentral-data/"${CONFIG_FILE}"
154
- #else
155
- # sed -i "s/\"allowedOrigin\": false/\"allowedOrigin\": \"$ALLOWED_ORIGIN\"/" meshcentral-data/"${CONFIG_FILE}"
156
- #fi
157
- #SESSION_KEY= # Session key should be random. Not passed in through arguments.
158
- #sed -i "s/\"_sessionKey\": \"MyReallySecretPassword1\"/\"sessionKey\": \"$SESSION_KEY\"/" meshcentral-data/"${CONFIG_FILE}"
228
+ echo -e "\n$(cat "$CONFIG_FILE")"
229
else
230
echo "Leaving config as-is."
231
fi