localauth.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import hashlib
  2. import redis
  3. import string
  4. import random
  5. host= 'saltstack-23'
  6. #unix_time = 1459967387
  7. user = 'douyuops'
  8. redis_ip = '192.168.1.82'
  9. redis_port = 6379
  10. def decodepw(token,rd):
  11. spec_case = [x for x in '~!@#$%^&*()_+{}<>-='] + [x for x in string.lowercase]
  12. rd_list = [int(x) for x in rd.split('&')]
  13. reset_token = ''
  14. for x in range(len(token)):
  15. if x in rd_list:
  16. w = spec_case[x]
  17. else:
  18. w = token[x]
  19. reset_token += w
  20. return reset_token
  21. def getpw():
  22. r = redis.StrictRedis(host=redis_ip, port=redis_port, db=0)
  23. unix_time = r.get(host)
  24. token_rd = r.get(host + 'rd')
  25. token_hostname = hashlib.md5(host).hexdigest()[10:]
  26. token_loginuser = hashlib.md5(user).hexdigest()[10:]
  27. token_unix_time = hashlib.md5(str(int(unix_time) / 300)).hexdigest()[10:]
  28. token = hashlib.md5(token_hostname + token_loginuser + token_unix_time).hexdigest()[10:].upper()
  29. return decodepw(token, token_rd)
  30. print getpw()