Compare commits
	
		
			10 Commits
		
	
	
		
			464d721af6
			...
			20d4998c63
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					20d4998c63 | ||
| 
						 | 
					36f4e9b324 | ||
| 
						 | 
					f8bf2c62b0 | ||
| 
						 | 
					405e7c21c3 | ||
| 
						 | 
					6e40fba236 | ||
| 
						 | 
					414174985b | ||
| 
						 | 
					77abee6c5a | ||
| 
						 | 
					9aa08adef8 | ||
| 
						 | 
					22c80eaf54 | ||
| 
						 | 
					19aa4e12d5 | 
@@ -4,3 +4,5 @@ PASSWORD = bottestpassword
 | 
			
		||||
NICK = xmppbot
 | 
			
		||||
ROOM1 = testroom1@conference.localhost
 | 
			
		||||
ROOM2 = testroom2@conference.localhost
 | 
			
		||||
HOST = 127.0.0.1
 | 
			
		||||
PORT = 25222
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										37
									
								
								test/test.sh
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								test/test.sh
									
									
									
									
									
								
							@@ -1,5 +1,16 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
# Check if docker is installed
 | 
			
		||||
if ! command -v docker run &> /dev/null
 | 
			
		||||
then
 | 
			
		||||
    echo "No docker detected. If you are running debian based system, you can install docker with"
 | 
			
		||||
    echo "sudo apt install docker.io"
 | 
			
		||||
    exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
echo "Docker detected"
 | 
			
		||||
 | 
			
		||||
# Run ejabberd docker as a daemon
 | 
			
		||||
echo "Starting ejabberd docker container"
 | 
			
		||||
docker run --name xmppbot-test -d -p 25222:5222 ejabberd/ecs
 | 
			
		||||
 | 
			
		||||
# Wait few seconds for ejabberd to boot
 | 
			
		||||
@@ -15,12 +26,34 @@ docker exec -it xmppbot-test bin/ejabberdctl create_room testroom1 conference.lo
 | 
			
		||||
docker exec -it xmppbot-test bin/ejabberdctl create_room testroom2 conference.localhost localhost
 | 
			
		||||
 | 
			
		||||
# Run xmpp mirror bot
 | 
			
		||||
python3 ../xmppmirror &
 | 
			
		||||
echo "Running xmpp mirror bot"
 | 
			
		||||
python3 ../xmppmirror & XMPPMIRRORPID=$!
 | 
			
		||||
 | 
			
		||||
# Run xmpp test bot
 | 
			
		||||
python3 testbot
 | 
			
		||||
echo "Running test bot"
 | 
			
		||||
python3 testbot & TESTBOTPID=$!
 | 
			
		||||
 | 
			
		||||
# Wait for bots to connect
 | 
			
		||||
sleep 10
 | 
			
		||||
 | 
			
		||||
# Wait certain amount of time for every test message in the file
 | 
			
		||||
for i in $(cat testmsgs.txt); do sleep 5; done
 | 
			
		||||
 | 
			
		||||
# Kill bots
 | 
			
		||||
if ps -p $XMPPMIRRORPID > /dev/null
 | 
			
		||||
then
 | 
			
		||||
    echo "Killing xmpp mirror bot"
 | 
			
		||||
    kill $XMPPMIRRORPID
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if ps -p $TESTBOTPID > /dev/null
 | 
			
		||||
then
 | 
			
		||||
    echo "Killing test bot"
 | 
			
		||||
    kill $TESTBOTPID
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Stop and remove containter
 | 
			
		||||
echo "Stopping and removing docker container"
 | 
			
		||||
docker stop xmppbot-test
 | 
			
		||||
docker rm xmppbot-test
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										41
									
								
								test/testbot
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								test/testbot
									
									
									
									
									
								
							@@ -3,6 +3,7 @@
 | 
			
		||||
import argparse
 | 
			
		||||
import slixmpp
 | 
			
		||||
import configparser
 | 
			
		||||
import time
 | 
			
		||||
 | 
			
		||||
CONFIG_PATH = "./testconfig.ini"
 | 
			
		||||
 | 
			
		||||
@@ -31,14 +32,23 @@ def allmsgsrecv():
 | 
			
		||||
    for i in results2:
 | 
			
		||||
        if i[2] == 0:
 | 
			
		||||
            return False
 | 
			
		||||
    return ret
 | 
			
		||||
 | 
			
		||||
# Print results and exit
 | 
			
		||||
def printandexit():
 | 
			
		||||
    print("Results of test:")
 | 
			
		||||
    print("Room1 -> Room2:")
 | 
			
		||||
    for i in results1:
 | 
			
		||||
        print(i[0].rstrip + " : " + str(round(i[2]-i[1],2)) + " secounds")
 | 
			
		||||
        if i[2] == 0:
 | 
			
		||||
            print(i[0] + " : Not recieved")
 | 
			
		||||
        else:
 | 
			
		||||
            print(i[0].rstrip() + " : " + str(round(i[2]-i[1],2)) + " secounds")
 | 
			
		||||
    print("Room2 -> Room1:")
 | 
			
		||||
    for i in results2:
 | 
			
		||||
        print(i[0].rstrip + " : " + str(round(i[2]-i[1],2)) + " secounds")
 | 
			
		||||
        if i[2] == 0:
 | 
			
		||||
            print(i[0] + " : Not recieved")
 | 
			
		||||
        else:
 | 
			
		||||
            print(i[0].rstrip() + " : " + str(round(i[2]-i[1],2)) + " secounds")
 | 
			
		||||
    exit()
 | 
			
		||||
 | 
			
		||||
def show_version():
 | 
			
		||||
@@ -81,19 +91,26 @@ class MUCBot(slixmpp.ClientXMPP):
 | 
			
		||||
 | 
			
		||||
    def muc_message(self, msg):
 | 
			
		||||
        rtime=time.time()
 | 
			
		||||
        rcpt=msg['from'].bare
 | 
			
		||||
        if msg['mucnick'] == self.nick:
 | 
			
		||||
            return
 | 
			
		||||
        body="%(body)s" % msg
 | 
			
		||||
        unknownmsg = True
 | 
			
		||||
        if self.room1 in str(msg['from']):
 | 
			
		||||
            for i in results2:
 | 
			
		||||
                if i[0] == body:
 | 
			
		||||
                if "admin: " + i[0] == body:
 | 
			
		||||
                    i[2] = rtime
 | 
			
		||||
                    unknownmsg = False
 | 
			
		||||
 | 
			
		||||
        if self.room2 in str(msg['from']):
 | 
			
		||||
            for i in results1:
 | 
			
		||||
                if i[0] == body:
 | 
			
		||||
                if "admin: " + i[0] == body:
 | 
			
		||||
                    i[2] = rtime
 | 
			
		||||
                    unknownmsg = False
 | 
			
		||||
 | 
			
		||||
        if allmsgsrecv:
 | 
			
		||||
        if unknownmsg:
 | 
			
		||||
            print("Unknown message recieved: " + body)
 | 
			
		||||
 | 
			
		||||
        if allmsgsrecv() is True:
 | 
			
		||||
            printandexit()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -114,6 +131,13 @@ if __name__ == '__main__':
 | 
			
		||||
    NICK = config.get('credentials', 'NICK')
 | 
			
		||||
    ROOM1 = config.get('credentials', 'ROOM1')
 | 
			
		||||
    ROOM2 = config.get('credentials', 'ROOM2')
 | 
			
		||||
    HOST = None
 | 
			
		||||
    PORT = 5222
 | 
			
		||||
    if "host" in config.options('credentials'):
 | 
			
		||||
        HOST = config.get('credentials', 'HOST')
 | 
			
		||||
    if "port" in config.options('credentials'):
 | 
			
		||||
        PORT = config.get('credentials', 'PORT')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
 | 
			
		||||
@@ -122,6 +146,9 @@ if __name__ == '__main__':
 | 
			
		||||
    xmpp.register_plugin('xep_0199') # XMPP Ping
 | 
			
		||||
 | 
			
		||||
    # Connect to the XMPP server and start processing XMPP stanzas.
 | 
			
		||||
    xmpp.connect(address=("localhost",25222))
 | 
			
		||||
    if HOST != None:
 | 
			
		||||
        xmpp.connect(address=(HOST,int(PORT)))
 | 
			
		||||
    else:
 | 
			
		||||
        xmpp.connect()
 | 
			
		||||
    xmpp.process(forever=False)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,3 +4,5 @@ PASSWORD = admintestpassword
 | 
			
		||||
NICK = admin
 | 
			
		||||
ROOM1 = testroom1@conference.localhost
 | 
			
		||||
ROOM2 = testroom2@conference.localhost
 | 
			
		||||
HOST = 127.0.0.1
 | 
			
		||||
PORT = 25222
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								xmppmirror
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								xmppmirror
									
									
									
									
									
								
							@@ -59,6 +59,12 @@ if __name__ == '__main__':
 | 
			
		||||
    NICK = config.get('credentials', 'NICK')
 | 
			
		||||
    ROOM1 = config.get('credentials', 'ROOM1')
 | 
			
		||||
    ROOM2 = config.get('credentials', 'ROOM2')
 | 
			
		||||
    HOST = None
 | 
			
		||||
    PORT = 5222
 | 
			
		||||
    if "host" in config.options('credentials'):
 | 
			
		||||
        HOST = config.get('credentials', 'HOST')
 | 
			
		||||
    if "port" in config.options('credentials'):
 | 
			
		||||
        PORT = config.get('credentials', 'PORT')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
 | 
			
		||||
@@ -67,6 +73,9 @@ if __name__ == '__main__':
 | 
			
		||||
    xmpp.register_plugin('xep_0199') # XMPP Ping
 | 
			
		||||
 | 
			
		||||
    # Connect to the XMPP server and start processing XMPP stanzas.
 | 
			
		||||
    xmpp.connect()
 | 
			
		||||
    if HOST != None:
 | 
			
		||||
        xmpp.connect(address=(HOST,int(PORT)))
 | 
			
		||||
    else:
 | 
			
		||||
        xmpp.connect()
 | 
			
		||||
    xmpp.process()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user