mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 04:45:00 +00:00
multibot wrapper example
This commit is contained in:
parent
2344f3237d
commit
c61dbbe105
@ -56,11 +56,12 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
|
||||
## Security Considerations
|
||||
Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot.
|
||||
|
||||
Bash scripts in general are not designed to be bullet proof, so consider this Bot as a proof of concept. More concret examples of security problems are: bash's 'quoting hell' and globbing. [Implications of wrong quoting](https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells)
|
||||
Bash scripts in general are not designed to be bullet proof, so consider this Bot as a proof of concept. Bash programmers often struggle with 'quoting hell' and globbing, see [Implications of wrong quoting](https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells)
|
||||
|
||||
Whenever you are processing input from from untrusted sources (messages, files, network) you must be as carefull as possible, e.g. set IFS appropriate, disable globbing (set -f) and quote everthing. In addition disable not used Bot commands and delete unused scripts from your Bot, e.g. example scripts 'notify', 'calc', 'question',
|
||||
Whenever you are processing input from from untrusted sources (messages, files, network) you must be as carefull as possible, e.g. set IFS appropriate, disable globbing (set -f) and quote everthing. In addition delete unused scripts and examples from your Bot, e.g. scripts 'notify', 'calc', 'question', and disable all not used commands.
|
||||
|
||||
A powerful tool to improve your scripts robustness is ```shellcheck```. You can [use it online](https://www.shellcheck.net/) or [install shellcheck locally](https://github.com/koalaman/shellcheck#installing). All bashbot scripts are checked by shellcheck.
|
||||
A powerful tool to improve your scripts is ```shellcheck```. You can [use it online](https://www.shellcheck.net/) or [install shellcheck locally](https://github.com/koalaman/shellcheck#installing). Shellcheck is used extensive in bashbot development to enshure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests.
|
||||
In addition bashbot has a [test suite](doc/7_develop.md) to check if important functionality is working as expected.
|
||||
|
||||
### Run your Bot as a restricted user
|
||||
**I recommend to run your bot as a user, with almost no access rights.**
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
## Bashbot examples
|
||||
|
||||
### bashbot multi
|
||||
An example wrapper to run multiple instances of bashbot, use ```./bashbot-multi.sh botname command```
|
||||
|
||||
### bashbot.cron
|
||||
An example crontab is provided in ```examples/bashbot.cron```, see [Expert use](../doc/4_expert.md#Scedule-bashbot-from-Cron)
|
||||
|
||||
|
44
examples/bashbot-multi.sh
Executable file
44
examples/bashbot-multi.sh
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
# file. multibot.sh
|
||||
# description: run multiple telegram bots from one installation
|
||||
#
|
||||
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
|
||||
|
||||
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
||||
echo "Usage: $0 botname command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BOT="${1}"
|
||||
[ "${#BOT}" -lt 5 ] && echo "Botname must have a minumum lenth of 5 characters" && exit 1
|
||||
|
||||
# where should the bots live?
|
||||
# true in one dir, false in seperate dirs
|
||||
if true; then
|
||||
# example for all in one bashbot dir
|
||||
BINDIR="/usr/local/telegram-bot-bash"
|
||||
ETC="${BINDIR}"
|
||||
VAR="${BINDIR}"
|
||||
|
||||
else
|
||||
# alternative linux like localtions
|
||||
BINDIR="/usr/local/bin"
|
||||
ETC="/etc/bahsbot"
|
||||
VAR="/var/bahsbot"
|
||||
export BASHBOT_JSONSH="/usr/local/bin/JSON.sh"
|
||||
|
||||
fi
|
||||
|
||||
# set final ENV
|
||||
export BASHBOT_ETC="${ETC}/${BOT}"
|
||||
export BASHBOT_VAR="${VAR}/${BOT}"
|
||||
|
||||
# some checks
|
||||
[ ! -d "${BINDIR}" ] && echo "Dir ${BINDIR} does not exist" && exit 1
|
||||
[ ! -d "${BASHBOT_ETC}" ] && echo "Dir ${BASHBOT_ETC} does not exist" && exit 1
|
||||
[ ! -d "${BASHBOT_VAR}" ] && echo "Dir ${BASHBOT_VAR} does not exist" && exit 1
|
||||
[ ! -x "${BINDIR}/bashbot.sh" ] && echo "${BINDIR}/bashbot.sh not executeable or does not exist" && exit 1
|
||||
[ ! -r "${BASHBOT_ETC}/commands.sh" ] && echo "${BASHBOT_ETC}/commands.sh not readable or does not exist" && exit 1
|
||||
[ ! -r "${BASHBOT_ETC}/mycommands.sh" ] && echo "${BASHBOT_ETC}/mycommands.sh not readable or does not exist" && exit 1
|
||||
|
||||
"${BINDIR}/bashbot.sh" $2
|
44
examples/multibot.sh
Executable file
44
examples/multibot.sh
Executable file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
# file. multibot.sh
|
||||
# description: run multiple telegram bots from one installation
|
||||
#
|
||||
#### $$VERSION$$ v0.70-rc1-0-g8883cc9
|
||||
|
||||
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
||||
echo "Usage: $0 botname command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BOT="${1}"
|
||||
[ "${#BOT}" -lt 5 ] && echo "Botname must have a minumum lenth of 5 characters" && exit 1
|
||||
|
||||
# where should the bots live?
|
||||
# true in one dir, false in seperate dirs
|
||||
if true; then
|
||||
# example for all in one bashbot dir
|
||||
BINDIR="/usr/local/telegram-bot-bash"
|
||||
ETC="${BINDIR}"
|
||||
VAR="${BINDIR}"
|
||||
|
||||
else
|
||||
# alternative linux like localtions
|
||||
BINDIR="/usr/local/bin"
|
||||
ETC="/etc/bahsbot"
|
||||
VAR="/var/bahsbot"
|
||||
export BASHBOT_JSONSH="/usr/local/bin/JSON.sh"
|
||||
|
||||
fi
|
||||
|
||||
# set final ENV
|
||||
export BASHBOT_ETC="${ETC}/${BOT}"
|
||||
export BASHBOT_VAR="${VAR}/${BOT}"
|
||||
|
||||
# some checks
|
||||
[ ! -d "${BINDIR}" ] && echo "Dir ${BINDIR} does not exist" && exit 1
|
||||
[ ! -d "${BASHBOT_ETC}" ] && echo "Dir ${BASHBOT_ETC} does not exist" && exit 1
|
||||
[ ! -d "${BASHBOT_VAR}" ] && echo "Dir ${BASHBOT_VAR} does not exist" && exit 1
|
||||
[ ! -x "${BINDIR}/bashbot.sh" ] && echo "${BINDIR}/bashbot.sh not executeable or does not exist" && exit 1
|
||||
[ ! -r "${BASHBOT_ETC}/commands.sh" ] && echo "${BASHBOT_ETC}/commands.sh not readable or does not exist" && exit 1
|
||||
[ ! -r "${BASHBOT_ETC}/mycommands.sh" ] && echo "${BASHBOT_ETC}/mycommands.sh not readable or does not exist" && exit 1
|
||||
|
||||
"${BINDIR}/bashbot.sh" $2
|
@ -10,7 +10,7 @@ if [ -f "${TESTDIR}/bashbot.sh" ]; then
|
||||
echo "${SUCCESS} bashbot.sh exist!"
|
||||
exit 0
|
||||
else
|
||||
echo "${NOSUCCESS} ${TESTDIR}bashbot.sh missing!"
|
||||
echo "${NOSUCCESS} ${TESTDIR}/bashbot.sh missing!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user