Guest User

Untitled

a guest
Feb 8th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #!/usr/bin/env lua
  2.  
  3. function md5sum(str)
  4. local command="echo -n "..str.." | md5sum"
  5. local f=io.popen(command)
  6. local out=f:read('*all')
  7. return out:sub(1,-5)
  8. --f:close()
  9. end
  10. --print(md5sum("asdf")) -- 912ec803b2ce49e4a541068d495ab570
  11.  
  12.  
  13. --START HERE
  14. function get_account(username,password)
  15. local ver="Tyroth"
  16. local temp=string.format("%X",os.time())
  17. username=string.upper(username)
  18. local s=temp..ver..username..password
  19. local m=string.upper(md5sum(s))
  20. m=string.sub(m,1,20)
  21. local encodedaccont="~ghca"..temp.."2002"..m..username
  22. return encodedaccont
  23. end
  24. --print(get_account(arg[1],arg[2]))
  25.  
  26. function get_account_v07(username,password)
  27. --the encrypt algorithm version 07
  28. --For backup
  29. local ver="jepyid"
  30. local temp=string.format("%X",os.time())
  31. username=string.upper(username)
  32. local s=ver..username..temp..password
  33. local m=string.upper(md5sum(s))
  34. m=string.sub(m,1,20)
  35. local encodedaccont="~ghca"..temp.."2007"..m..username
  36. return encodedaccont
  37. end
  38.  
  39. function pppoe_dial(username,password)
  40.  
  41. --restore network config file
  42. local restore="if [ ! -f /etc/config/network ];then cp /root/network.bak /etc/config/network;fi"
  43. os.execute(restore)
  44. print("Dialing...")
  45. --print(username)
  46. local setuser="uci set network.wan.username="..get_account_v07(username,password)
  47. local setpass="uci set network.wan.password="..password
  48. os.execute(setuser)
  49. os.execute(setpass)
  50. os.execute("uci commit")
  51. os.execute("/etc/init.d/network restart")
  52. os.execute("logread|grep pppd |tail -n 20 >/root/ppplog")
  53.  
  54. --local pppd="pppd plugin rp-pppoe.so mtu 1492 mru 1492"
  55. --if not io.open("/etc/crontabs/root") then
  56. --cron--
  57. os.execute("killall -9 crond")
  58. --local mycron="flag=0;for ip in 126.com 163.com qq.com; do if ping -c 1 $ip | grep 'ttl' >/dev/null;then flag=1; break;fi; done; if [ $flag -eq 0 ] ;then STRD "..username.." "..password.." >/dev/null;fi;"
  59. local mycron="*/1 * * * * flag=0;for ip in 126.com 163.com qq.com; do if ping -c 1 $ip | grep 'ttl' >/dev/null;then flag=1; break;fi; done; if [ $flag -eq 0 ] ;then sh /etc/rc.local >/dev/null;else cp -f /etc/config/network /root/network.bak;fi; 2>/dev/null"
  60. --local setcron="*/1 * * * * "..mycron.." 2>/dev/null"
  61. crontab=io.open("/etc/crontabs/root","w")
  62. crontab:write(mycron)
  63. crontab:close()
  64. local startcron="crond -c /etc/crontabs"
  65. os.execute(startcron)
  66. --end
  67. print("Done!")
  68. end
  69.  
  70.  
  71. --main--
  72. if arg[1] and arg[2] then
  73. pppoe_dial(arg[1],arg[2])
  74. else
  75. print("USAGE:\n "..arg[0].." USERNAME PASSWORD\n")
  76. end
  77. os.exit(0)
  78. --end main--
Add Comment
Please, Sign In to add comment