diff --git a/tutorial/1/misc/Dockerfile b/tutorial/1/misc/Dockerfile new file mode 100644 index 0000000..c42c4fe --- /dev/null +++ b/tutorial/1/misc/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine + +RUN apk add --no-cache python + +COPY tumsoul_0.3.3.py /tumsoul_0.3.3.py +COPY docker-entrypoint.sh /docker-entrypoint.sh + +ENTRYPOINT [ "/docker-entrypoint.sh" ] +CMD [ "/tumsoul_0.3.3.py" ] diff --git a/tutorial/1/misc/docker-entrypoint.sh b/tutorial/1/misc/docker-entrypoint.sh new file mode 100755 index 0000000..d6914e4 --- /dev/null +++ b/tutorial/1/misc/docker-entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +[ -n "${NETSOUL_LOGIN}" ] && sed -i "s/user = '%LOGIN%'/user = '${NETSOUL_LOGIN}'/" /tumsoul_0.3.3.py +[ -n "${PASSSOCKS}" ] && sed -i "s/password = '%PASSSOCKS%'/password = '${PASSSOCKS}'/" /tumsoul_0.3.3.py + +exec $@ diff --git a/tutorial/1/misc/tumsoul_0.3.3.py b/tutorial/1/misc/tumsoul_0.3.3.py new file mode 100755 index 0000000..95855fc --- /dev/null +++ b/tutorial/1/misc/tumsoul_0.3.3.py @@ -0,0 +1,73 @@ +#!/usr/bin/python2 +import socket,md5,string,time,os,sys,random,urllib + +##### CONFIG :-) ########## +tumsoul_server = ('ns-server.epitech.net', 4242) +testlink_server = ('10.224.3.42', 80) +testlink_server2 = ('10.224.2.42', 80) +user = '%LOGIN%' +password = '%PASSSOCKS%' +location = urllib.quote("Tumsoul 0.3.3") +useragent = urllib.quote("tumsoul v0.3 [%d]"%os.getpid()) +states = ["actif", "away"] +delays = [ 10 ] + [ 4242 ]*10 + [ 424 ]*10 + +def md5sum(str): + chk = md5.new() + chk.update(str) + return chk.digest() + +def hexify(str): + return string.join(map(lambda c:"%02x"%ord(c),str),"") + +def expect(file,str): + reply = file.readline()[:-1] + if reply[:len(str)]==str: return + print "Invalid reply : '%s*' expected, '%s' received."%(str,reply) + time.sleep(3) + sys.exit() + +s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) +s.connect(tumsoul_server) +f=s.makefile() +cmd,code,hash,ip,port,timestamp=string.split(f.readline()[:-1]) +sum=md5sum("%s-%s/%s%s"%(hash,ip,port,password)) +authreply=hexify(sum) +s.send("auth_ag ext_user none none\n") +expect(f,"rep 002 --") +s.send("ext_user_log %s %s %s %s\n"%(user,authreply,location,useragent)) +expect(f,"rep 002 --") +print "Authentication complete, proceeding..." +statechange_deadline = string.atoi(timestamp) +ping_deadline = string.atoi(timestamp) +ping_delay = 40 +check_delay = 10 +check_deadline = string.atoi(timestamp) +localtime = string.atoi(timestamp) +while 1: + localtime += 1 + if localtime > ping_deadline: + ping_deadline += ping_delay + #print "Ping..." + s.send("ping\n") + if localtime > statechange_deadline: + delay = random.choice(delays) + newstate = random.choice(states) + statechange_deadline+=delay + #print "Newstate : %s, next change in %d seconds..."%(newstate,delay) + s.send("state %s:%i\n"%(newstate,int(localtime))) + if localtime > check_deadline: + scheck = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + try: scheck.connect(testlink_server) + except: + print "Could not connect to %s:%d, trying next server in 5 seconds..."%testlink_server + time.sleep(5) + try: scheck.connect(testlink_server2) + except: + print "Could not connect to %s:%d, exitting in 5 seconds..."%testlink_server2 + time.sleep(5) + sys.exit() + print "Connection to %s:%d OK."%testlink_server + scheck.close() + check_deadline+=check_delay + time.sleep(1)