Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. #!/usr/bin/python
  2. import socket,md5,string,time,os,sys,random,urllib
  3.  
  4. ##### CONFIG :-) ##########
  5. tumsoul_server = ('ns-server.epita.fr', 4242)
  6. testlink_server = ('ns-server.epita.fr', 80)
  7. testlink_server2 = ('10.42.4.20',  80)
  8. user = 'lachau_j'
  9. password = ''
  10. location = urllib.quote("Tumsoul 0.3.3")
  11. useragent = urllib.quote("tumsoul v0.3 [%d]"%os.getpid())
  12. states = ["actif", "away"]
  13. delays = [ 10 ] + [ 4242 ]*10 + [ 424 ]*10
  14.  
  15. def md5sum(str):
  16.     chk = md5.new()
  17.     chk.update(str)
  18.     return chk.digest()
  19.  
  20. def hexify(str):
  21.     return string.join(map(lambda c:"%02x"%ord(c),str),"")
  22.  
  23. def expect(file,str):
  24.     reply = file.readline()[:-1]
  25.     if reply[:len(str)]==str: return
  26.     print "Invalid reply : '%s*' expected, '%s' received."%(str,reply)
  27.     time.sleep(3)
  28.     sys.exit()
  29.  
  30. s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  31. s.connect(tumsoul_server)
  32. f=s.makefile()
  33. cmd,code,hash,ip,port,timestamp=string.split(f.readline()[:-1])
  34. sum=md5sum("%s-%s/%s%s"%(hash,ip,port,password))
  35. authreply=hexify(sum)
  36. s.send("auth_ag ext_user none none\n")
  37. expect(f,"rep 002 --")
  38. s.send("ext_user_log %s %s %s %s\n"%(user,authreply,location,useragent))
  39. expect(f,"rep 002 --")
  40. print "Authentication complete, proceeding..."
  41. statechange_deadline = string.atoi(timestamp)
  42. ping_deadline = string.atoi(timestamp)
  43. ping_delay = 40
  44. check_delay = 10
  45. check_deadline = string.atoi(timestamp)
  46. localtime = string.atoi(timestamp)
  47. while 1:
  48.     localtime += 1
  49.     if localtime > ping_deadline:
  50.         ping_deadline += ping_delay
  51.         #print "Ping..."
  52.         s.send("ping\n")
  53.     if localtime > statechange_deadline:
  54.         delay = random.choice(delays)
  55.         newstate = random.choice(states)
  56.         statechange_deadline+=delay
  57.         #print "Newstate : %s, next change in %d seconds..."%(newstate,delay)
  58.         s.send("state %s:%i\n"%(newstate,int(localtime)))
  59.     if localtime > check_deadline:
  60.         scheck = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  61.         try: scheck.connect(testlink_server)
  62.         except:
  63.             print "Could not connect to %s:%d, trying next server in 5 seconds..."%testlink_server
  64.             time.sleep(5)
  65.             try: scheck.connect(testlink_server2)
  66.             except:
  67.                 print "Could not connect to %s:%d, exitting in 5 seconds..."%testlink_server2
  68.                 time.sleep(5)
  69.                 sys.exit()
  70.         print "Connection to %s:%d OK."%testlink_server
  71.         scheck.close()
  72.         check_deadline+=check_delay
  73.     time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement