commit 33d072a98276e3bf385d7bbd17675cbf1a0994f1 Author: Adrien Bourmault Date: Fri Feb 4 12:55:28 2022 +0100 Commit initial diff --git a/.bash_history b/.bash_history new file mode 100644 index 0000000..9df79b2 --- /dev/null +++ b/.bash_history @@ -0,0 +1,30 @@ +cd +nano bot_main.py +chmod +x bot_main.py +./bot_main.py +python3 bot_main.py +nano bot_main.py +python3 bot_main.py +python3 bot_main.py --jid isengard@a-lec.org --nick Isengard --password 7M457M8RApgQdeR59HK --room cominfra@salons.a-lec.org +nano bot_main.py +python3 bot_main.py --jid isengard@a-lec.org --nick Isengard --password 7M457M8RApgQdeR59HK --room cominfra@salons.a-lec.org +nano bot_main.py +python3 bot_main.py --jid isengard@a-lec.org --nick Isengard --password 7M457M8RApgQdeR59HK --room cominfra@salons.a-lec.org +nano bot_main.py +python3 bot_main.py --jid isengard@a-lec.org --nick Isengard --password 7M457M8RApgQdeR59HK --room cominfra@salons.a-lec.org +nano bot_main.py +python3 bot_main.py --jid isengard@a-lec.org --nick Isengard --password 7M457M8RApgQdeR59HK --room cominfra@salons.a-lec.org +nano bot_main.py +python3 bot_main.py --jid isengard@a-lec.org --nick Isengard --password 7M457M8RApgQdeR59HK --room cominfra@salons.a-lec.org +nano bot_main.py +nano bot_service.conf +sudo cp bot_service.conf /usr/lib/systemd/system/xmpp_bot.service +cd +nano bot_service.conf +mv bot_service.conf xmpp_bot.service +cd +./bot_main.py +nano bot_main.py +cd +ll +nano bot_main.py diff --git a/.bash_logout b/.bash_logout new file mode 100644 index 0000000..de4f5f7 --- /dev/null +++ b/.bash_logout @@ -0,0 +1,7 @@ +# ~/.bash_logout: executed by bash(1) when login shell exits. + +# when leaving the console clear the screen to increase privacy + +if [ "$SHLVL" = 1 ]; then + [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q +fi diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..89f7ef6 --- /dev/null +++ b/.bashrc @@ -0,0 +1,113 @@ +# ~/.bashrc: executed by bash(1) for non-login shells. +# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) +# for examples + +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + +# don't put duplicate lines or lines starting with space in the history. +# See bash(1) for more options +HISTCONTROL=ignoreboth + +# append to the history file, don't overwrite it +shopt -s histappend + +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=1000 +HISTFILESIZE=2000 + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# If set, the pattern "**" used in a pathname expansion context will +# match all files and zero or more directories and subdirectories. +#shopt -s globstar + +# make less more friendly for non-text input files, see lesspipe(1) +#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" + +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +# set a fancy prompt (non-color, unless we know we "want" color) +case "$TERM" in + xterm-color|*-256color) color_prompt=yes;; +esac + +# uncomment for a colored prompt, if the terminal has the capability; turned +# off by default to not distract the user: the focus in a terminal window +# should be on the output of commands, not on the prompt +#force_color_prompt=yes + +if [ -n "$force_color_prompt" ]; then + if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then + # We have color support; assume it's compliant with Ecma-48 + # (ISO/IEC-6429). (Lack of such support is extremely rare, and such + # a case would tend to support setf rather than setaf.) + color_prompt=yes + else + color_prompt= + fi +fi + +if [ "$color_prompt" = yes ]; then + PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\H\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' +else + PS1='${debian_chroot:+($debian_chroot)}\u@\H:\w\$ ' +fi +unset color_prompt force_color_prompt + +# If this is an xterm set the title to user@host:dir +case "$TERM" in +xterm*|rxvt*) + PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\H: \w\a\]$PS1" + ;; +*) + ;; +esac + +# enable color support of ls and also add handy aliases +if [ -x /usr/bin/dircolors ]; then + test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" + alias ls='ls --color=auto' + alias dir='dir --color=auto' + alias vdir='vdir --color=auto' + + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' +fi + +# colored GCC warnings and errors +#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' + +# some more ls aliases +alias ll='ls -l' +alias la='ls -A' +#alias l='ls -CF' + +# Alias definitions. +# You may want to put all your additions into a separate file like +# ~/.bash_aliases, instead of adding them here directly. +# See /usr/share/doc/bash-doc/examples in the bash-doc package. + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi + +# enable programmable completion features (you don't need to enable +# this, if it's already enabled in /etc/bash.bashrc and /etc/profile +# sources /etc/bash.bashrc). +if ! shopt -oq posix; then +if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion +elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion +fi +fi diff --git a/.profile b/.profile new file mode 100644 index 0000000..d89ea5a --- /dev/null +++ b/.profile @@ -0,0 +1,27 @@ +# ~/.profile: executed by the command interpreter for login shells. +# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login +# exists. +# see /usr/share/doc/bash/examples/startup-files for examples. +# the files are located in the bash-doc package. + +# the default umask is set in /etc/profile; for setting the umask +# for ssh logins, install and configure the libpam-umask package. +#umask 022 + +# if running bash +if [ -n "$BASH_VERSION" ]; then + # include .bashrc if it exists + if [ -f "$HOME/.bashrc" ]; then + . "$HOME/.bashrc" + fi +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/bin" ] ; then + PATH="$HOME/bin:$PATH" +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/.local/bin" ] ; then + PATH="$HOME/.local/bin:$PATH" +fi diff --git a/.ssh/id_rsa b/.ssh/id_rsa new file mode 100644 index 0000000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muq87AqypAGvkzKF66X3Ly3lBANHWB9kYf/B/Qt3zzLzcuvcSCZ64P/XA9liLQCsHM+ +6XTber2vulscAgWj37wUyd90w1sDrkIUKbyu6RHE0z5s6n541ytX4tlJefaca67iwKKBZp +orpoVtiU9Xqz2Kn/sw01w6OAnbSn4tAAAAwQDMgY5lP+P9X9GSoHc6DeukUXt5Mpscoqpw +6FbGrxc9WK2mNuHYaanqLWAENWoIkJ+1QAoSUcYqSRInCSeh3X5isBR/zw8a+LmsCBMM32 +6k0YdhOhloxIJhjhgJ2Ub038/NIhIPNRupyKocQd+ZOI5VKHuthCxKGB3uolo5FYciJLz7 +B+HcABLAkHtTfT3mdCUzVGr++kVMofuvnC4f1gkg2a9GkfI1JT3D/r+0cT4bTKT3YgS3ZJ +dXD/31EoCIMcsAAAAraXNlbmdhcmRfeG1wcEBpc2VuZ2FyZC5saWJyZS1lbi1jb21tdW5z +Lm9yZw== +-----END OPENSSH PRIVATE KEY----- diff --git a/.ssh/id_rsa.pub b/.ssh/id_rsa.pub new file mode 100644 index 0000000..520c104 --- /dev/null +++ b/.ssh/id_rsa.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDAGsRE+xFF1waq8Dx7A2k2Uxdm9SC1E/HQRlGJIbIx57vj0AfgrrrJeGd1oSnRfiiZP4MN5R7uDETwsmzpHAeEhGm052htTBPBCgevpYKHQd+HeFeXufH0DhH0YaCPy/pgoZqtKq/LPNw/Gg99mWlIp7MZItFZlqpLjl57whfxKLq6MJ++DPFZpcCZHxvFkLQkrIw1Vga7yoPQTs2LKHhBIu3fYgpjn8OHMQBqrXfa1mng+CABI+DxGwu8pnyHdtAeIeoHhQIZUur1qkDJdCFKq2b/S2AJhw+TF4S6QmcTgWsZDTRuy/8MEulyZdRqvKBqyq0DxCCBHd4efqer4Ix1KHdRee6WwtZ2X71ISduA9ZW8++Ey8z1TBLEKp9Buc1j1wcO+9RHP9lEaTR884uOa11bhWoWixVi9zLPyFlu+qgUsM3N84jB05aEBGTeYFu/jlAkmKGAb/NMOPSDi4zPEp79jFPa+1OGpoA1cj8UlmLc2KAujkCkSBT0Bna4gqq8= isengard_xmpp@isengard.libre-en-communs.org diff --git a/.ssh/known_hosts b/.ssh/known_hosts new file mode 100644 index 0000000..9bb2430 --- /dev/null +++ b/.ssh/known_hosts @@ -0,0 +1,2 @@ +|1|YsPM9bo+wHZbzMaqYDUx61uCepc=|qSWaJ1CNo0oLNdP/IpCIa246PlI= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDv3H1JlE7Elm6zxa5sSu63H/V33gWm5b0klR8WEi7j9MnFMirE2NRkYTD21SPQy0fGWuyn3IOq2oZ9jEcEChX4= +|1|HmPlyVmhWK6XSBkw4UIDkkR89Xs=|LpPJ41Glo+04gRSpKCXpYbpCjUQ= ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDv3H1JlE7Elm6zxa5sSu63H/V33gWm5b0klR8WEi7j9MnFMirE2NRkYTD21SPQy0fGWuyn3IOq2oZ9jEcEChX4= diff --git a/bot_main.py b/bot_main.py new file mode 100755 index 0000000..1a0b868 --- /dev/null +++ b/bot_main.py @@ -0,0 +1,154 @@ +#!/usr/bin/env python3 + +import logging +from getpass import getpass +from argparse import ArgumentParser + +import slixmpp + + +class MUCBot(slixmpp.ClientXMPP): + + """ + A simple Slixmpp bot that will greets those + who enter the room, and acknowledge any messages + that mentions the bot's nickname. + """ + + def __init__(self, jid, password, room, nick): + slixmpp.ClientXMPP.__init__(self, jid, password) + + self.room = room + self.nick = nick + + # The session_start event will be triggered when + # the bot establishes its connection with the server + # and the XML streams are ready for use. We want to + # listen for this event so that we we can initialize + # our roster. + self.add_event_handler("session_start", self.start) + + # The groupchat_message event is triggered whenever a message + # stanza is received from any chat room. If you also also + # register a handler for the 'message' event, MUC messages + # will be processed by both handlers. + self.add_event_handler("groupchat_message", self.muc_message) + + # The groupchat_presence event is triggered whenever a + # presence stanza is received from any chat room, including + # any presences you send yourself. To limit event handling + # to a single room, use the events muc::room@server::presence, + # muc::room@server::got_online, or muc::room@server::got_offline. + self.add_event_handler("muc::%s::got_online" % self.room, + self.muc_online) + + + async def start(self, event): + """ + Process the session_start event. + + Typical actions for the session_start event are + requesting the roster and broadcasting an initial + presence stanza. + + Arguments: + event -- An empty dictionary. The session_start + event does not provide any additional + data. + """ + await self.get_roster() + self.send_presence() + self.plugin['xep_0045'].join_muc(self.room, + self.nick, + # If a room password is needed, use: + # password=the_room_password, + ) + + def muc_message(self, msg): + """ + Process incoming message stanzas from any chat room. Be aware + that if you also have any handlers for the 'message' event, + message stanzas may be processed by both handlers, so check + the 'type' attribute when using a 'message' event handler. + + Whenever the bot's nickname is mentioned, respond to + the message. + + IMPORTANT: Always check that a message is not from yourself, + otherwise you will create an infinite loop responding + to your own messages. + + This handler will reply to messages that mention + the bot's nickname. + + Arguments: + msg -- The received message stanza. See the documentation + for stanza objects and the Message stanza to see + how it may be used. + """ + if msg['mucnick'] != self.nick and self.nick in msg['body']: + self.send_message(mto=msg['from'].bare, + mbody="%s, je n'ai pas compris (je suis un peu bête) mais j'ai bien lu!" % msg['mucnick'], + mtype='groupchat') + if msg['body'][0] == "!": + self.send_message(mto=msg['from'].bare, + mbody="%s, ça a l'air d'être une commande... mais je ne l'ai pas saisie." % msg['mucnick'], + mtype='groupchat') + + def muc_online(self, presence): + """ + Process a presence stanza from a chat room. In this case, + presences from users that have just come online are + handled by sending a welcome message that includes + the user's nickname and role in the room. + + Arguments: + presence -- The received presence stanza. See the + documentation for the Presence stanza + to see how else it may be used. + """ + if presence['muc']['nick'] != self.nick: + self.send_message(mto=presence['from'].bare, + mbody="Salut %s !" % (presence['muc']['nick']), + mtype='groupchat') + + +if __name__ == '__main__': + # Setup the command line arguments. + parser = ArgumentParser() + + # Output verbosity options. + parser.add_argument("-q", "--quiet", help="set logging to ERROR", + action="store_const", dest="loglevel", + const=logging.ERROR, default=logging.INFO) + parser.add_argument("-d", "--debug", help="set logging to DEBUG", + action="store_const", dest="loglevel", + const=logging.DEBUG, default=logging.INFO) + + # JID and password options. + parser.add_argument("-j", "--jid", dest="jid", + help="JID to use") + parser.add_argument("-p", "--password", dest="password", + help="password to use") + parser.add_argument("-r", "--room", dest="room", + help="MUC room to join") + parser.add_argument("-n", "--nick", dest="nick", + help="MUC nickname") + + args = parser.parse_args() + + # Setup logging. + logging.basicConfig(level=args.loglevel, + format='%(levelname)-8s %(message)s') + + # Setup the MUCBot and register plugins. Note that while plugins may + # have interdependencies, the order in which you register them does + # not matter. + xmpp = MUCBot(args.jid, args.password, args.room, args.nick) + xmpp.register_plugin('xep_0030') # Service Discovery + xmpp.register_plugin('xep_0045') # Multi-User Chat + xmpp.register_plugin('xep_0199') # XMPP Ping + + # Connect to the XMPP server and start processing XMPP stanzas. + xmpp.connect() + xmpp.process() diff --git a/xmpp_bot.service b/xmpp_bot.service new file mode 100644 index 0000000..ddbcc5a --- /dev/null +++ b/xmpp_bot.service @@ -0,0 +1,13 @@ +[Unit] +Description=SlixXMPP service bot +After=network.target ejabberd.service + +[Service] +Type=simple +ExecStart=/usr/bin/python3 /home/isengard_xmpp/bot_main.py --jid isengard@a-lec.org --nick Isengard --password 7M457M8RApgQdeR59HK --room cominfra@salons.a-lec.org +Restart=on-failure +RestartSec=60s +User=isengard_xmpp + +[Install] +WantedBy=multi-user.target