mirror of
https://github.com/tinode/chat.git
synced 2025-03-14 10:05:07 +00:00
fix for #157
This commit is contained in:
@ -51,14 +51,13 @@ All images are available at https://hub.docker.com/r/tinode/
|
||||
|
||||
### Resetting the database
|
||||
|
||||
The data in the database is reset when either one of the following conditions is true:
|
||||
The database is initialized or re-initialized when either one of the following conditions is true:
|
||||
|
||||
* File `/botdata/.tn-cookie` is missing.
|
||||
* Database is missing.
|
||||
* Database has a wrong schema version.
|
||||
* `RESET_DB` environment variable is true.
|
||||
|
||||
If you want to keep the data in the database between image upgrades, make sure the `/botdata` is a mounted volume (i.e. you launch the container with `--volume botdata:/botdata` option).
|
||||
|
||||
If you want to reset the data in the database regardless of `/botdata/.tn-cookie` presence, shut down the Tinode container and remove it:
|
||||
If you want to reset the data in the database, shut down the Tinode container and remove it:
|
||||
```
|
||||
$ docker stop tinode-srv && docker rm tinode-srv
|
||||
```
|
||||
@ -66,21 +65,24 @@ then repeat step 4 adding `--env RESET_DB=true`.
|
||||
|
||||
### Enable push notifications
|
||||
|
||||
Download and save the file with [FCM service account credentials](https://cloud.google.com/docs/authentication/production).
|
||||
Assuming your Firebase credentials file is named `myproject-1234-firebase-adminsdk-abc12-abcdef012345.json` and it's saved at `/Users/jdoe/`, sender ID is `114121611234`, and VAPID key (a.k.a. "Web Push certificates") is `83OrSoRandomLookingCharacters`, start the container with the following parameters (using MySQL container as an example):
|
||||
Download and save the file with the [FCM service account credentials](https://cloud.google.com/docs/authentication/production).
|
||||
Assuming your Firebase credentials file is named `myproject-1234-firebase-adminsdk-abc12-abcdef012345.json` and it's saved at `/Users/jdoe/`, sender ID is `141421356237`, and VAPID key (a.k.a. "Web Push certificates") is `83_OrSoRandomLookingCharacters`, start the container with the following parameters (using MySQL container as an example):
|
||||
|
||||
```
|
||||
$ docker run -p 6060:18080 -d --name tinode-srv --network tinode-net \
|
||||
-v /Users/jdoe:/fcm \
|
||||
--env FCM_CRED_FILE=/fcm/myproject-1234-firebase-adminsdk-abc12-abcdef012345.json \
|
||||
--env FCM_SENDER_ID=114121611234 \
|
||||
--env FCM_VAPID_KEY=83OrSoRandomLookingCharacters \
|
||||
--env FCM_SENDER_ID=141421356237 \
|
||||
--env FCM_VAPID_KEY=83_OrSoRandomLookingCharacters \
|
||||
tinode/tinode-mysql:latest
|
||||
```
|
||||
|
||||
### Run the chatbot
|
||||
|
||||
See [instructions](../chatbot/).
|
||||
See [instructions](../chatbot/python/).
|
||||
|
||||
The chatbot password is generated only when the database is initialized or reset. It's saved to `/botdata` directory in the container. If you want to keep the data available between container changes, such as image upgrades, make sure the `/botdata` is a mounted volume (i.e. you always launch the container with `--volume botdata:/botdata` option).
|
||||
|
||||
|
||||
## Supported environment variables
|
||||
|
||||
|
@ -37,13 +37,15 @@ done < config.template
|
||||
|
||||
|
||||
# Initialize the database if it has not been initialized yet or if data reset has been requested.
|
||||
if [ ! -f /botdata/.tn-cookie ] || [ "$RESET_DB" = true ] ; then
|
||||
# Run the generator. Save stdout to to a file to extract Tino's password for possible later use.
|
||||
./init-db --reset --config=working.config --data=data.json | grep "usr;tino;" > /botdata/tino-password
|
||||
./init-db --reset=${RESET_DB} --config=working.config --data=data.json | grep "usr;tino;" > /botdata/tino-password
|
||||
|
||||
if [ -s /botdata/tino-password ] ; then
|
||||
# Convert Tino's authentication credentials into a cookie file.
|
||||
# The cookie file is also used to check if database has been initialized.
|
||||
./credentials.sh < /botdata/tino-password > /botdata/.tn-cookie
|
||||
|
||||
# /botdata/tino-password could be empty if DB was not updated. In such a case the
|
||||
# /botdata/.tn-cookie will not be modified.
|
||||
./credentials.sh /botdata/.tn-cookie < /botdata/tino-password
|
||||
fi
|
||||
|
||||
# Run the tinode server.
|
||||
|
@ -1,12 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Credential extractor. Tino the Chatbot is created with a random password. The password is written
|
||||
# Credential extractor. Tino the Chatbot is created with a random password. The password is written
|
||||
# to stdout by tinode-db. The script converts it to chatbot's authentication cookie.
|
||||
|
||||
# The script takes a string like 'usr;tino;usrImlot_X9vAc;cOuTvzVa' (ignored;login;user_id;password)
|
||||
# and formats it into a json chatbot's authentication cookie like
|
||||
# '{"schema": "basic", "secret": "username:password", "user": "user_id"}'.
|
||||
# and formats it into a json chatbot's authentication cookie like
|
||||
# '{"schema": "basic", "secret": "username:password", "user": "user_id"}'.
|
||||
|
||||
COOKIE_FILE=$@
|
||||
|
||||
while read line; do
|
||||
IFS=';' read -r -a parts <<< "$line"
|
||||
echo "{\"schema\": \"basic\", \"secret\": \"${parts[1]}:${parts[3]}\", \"user\": \"${parts[2]}\"}"
|
||||
if [ ${#parts[@]} -eq 0 ] ; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# If the name of the cookie file is given, write to file
|
||||
# Otherwise write to stdout
|
||||
if [ "$COOKIE_FILE" ]; then
|
||||
exec 3>"$COOKIE_FILE"
|
||||
else
|
||||
exec 3>&1
|
||||
fi
|
||||
|
||||
echo "{\"schema\": \"basic\", \"secret\": \"${parts[1]}:${parts[3]}\", \"user\": \"${parts[2]}\"}" 1>&3
|
||||
break
|
||||
done < /dev/stdin
|
||||
|
Reference in New Issue
Block a user