/lib/www/cgi/login.c

https://github.com/quixadhal/bloodlines · C · 117 lines · 104 code · 13 blank · 0 comment · 21 complexity · 56b3e706d755753b437fb49e44138abe MD5 · raw file

  1. #include <daemons.h>
  2. mapping Tries = ([]);
  3. mapping Specials = ([
  4. "%21" : "\!",
  5. "%40" : "\@",
  6. "%23" : "\#",
  7. "%24" : "\$",
  8. "%25" : "\%",
  9. "%5E" : "\^",
  10. "%26" : "\&",
  11. "%28" : "\(",
  12. "%29" : "\)",
  13. "%2B" : "\+",
  14. "%60" : "\`",
  15. "%7E" : "\~",
  16. "%3D" : "\=",
  17. "%7B" : "\{",
  18. "%7D" : "\}",
  19. "%7C" : "\|",
  20. "%3A" : "\:",
  21. "%22" : "\"",
  22. "%3C" : "\<",
  23. "%3E" : "\>",
  24. "%3F" : "\?",
  25. "%5B" : "\[",
  26. "%5D" : "\]",
  27. "%5C" : "\\",
  28. "%3B" : "\;",
  29. "%27" : "\'",
  30. "%2C" : "\,",
  31. "%2F" : "\/",
  32. ]);
  33. varargs string gateway(mixed args){
  34. string pass_hash, who, password, ip;
  35. string ret = "";
  36. int max_tries = 3;
  37. int no_user = 0;
  38. if(ENABLE_CREWEB){
  39. ip = previous_object()->GetIp();
  40. if(!args || !stringp(args)) args = "123456789101112";
  41. if(sscanf(args,"%s&%s",who, password) != 2){
  42. ret = "<br>";
  43. }
  44. else {
  45. who = lower_case(who);
  46. if(!strsrch(who,"username=")){
  47. who = replace_string(who,"username=","",1);
  48. }
  49. if(!strsrch(password,"password=")){
  50. password = replace_string(password,"password=","",1);
  51. if(grepp(password, "%")){
  52. foreach(string key, string val in Specials){
  53. password = replace_string(password, key, val);
  54. }
  55. }
  56. }
  57. if(!ret && !user_exists(who)){
  58. no_user = 1;
  59. }
  60. else {
  61. if(!Tries) Tries = ([]);
  62. if(!Tries[ip]) Tries[ip] = 0;
  63. if(no_user){
  64. pass_hash = alpha_crypt(32);
  65. }
  66. else {
  67. pass_hash = PLAYERS_D->GetPlayerData(who,"Password");
  68. }
  69. if(pass_hash != crypt(password, pass_hash) ||
  70. PLAYERS_D->GetPaused(who)){
  71. Tries[ip]++;
  72. ret = "Fail! Tries left: "+(max_tries - Tries[ip])+"<br>";
  73. if(Tries[ip] >= max_tries){
  74. previous_object()->eventBlockIp();
  75. Tries[ip] = 0;
  76. }
  77. }
  78. else {
  79. string shibboleth = alpha_crypt(32);
  80. string packet=who+"."+shibboleth;
  81. WEB_SESSIONS_D->StartSession(ip,who,shibboleth);
  82. ret = "Login successful<br>";
  83. Tries[ip] = 0;
  84. ret += "<meta http-equiv=\"Set-Cookie\" content=\"creweb="+packet+";path=/\">";
  85. ret += "<META http-equiv=\"refresh\" content=\"1;URL=creweb.html\">";
  86. return ret;
  87. }
  88. }
  89. }
  90. ret += "Log in to CreWeb using your mud username and mud password.<br><br>";
  91. ret += "<FORM ACTION=\"login.html\" METHOD=POST>";
  92. ret += "username: <INPUT TYPE=TEXT NAME=\"username\" MAXLENGTH=32><BR>";
  93. ret += "password: <INPUT TYPE=PASSWORD NAME=\"password\" MAXLENGTH=32>";
  94. ret += "<P><INPUT TYPE=SUBMIT VALUE=\"submit\">";
  95. ret += "</FORM>";
  96. ret += "<br>";
  97. }
  98. else {
  99. ret += "CreWeb is disabled. To enable it: mudconfig creweb enable<br><br>";
  100. }
  101. ret += "<br><br><a href=\"/index.html\">Home</a><br><br>";
  102. ret += "<a href=\"http://dead-souls.net\">Dead Souls Home</a>";
  103. return ret;
  104. }