Advertisement
Guest User

Untitled

a guest
Nov 7th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. public onSocketReceiveData(Socket:id, remote_clientid, data[], data_len)
  2. {
  3. new str[256];
  4. if(!fexist(HTDOCS_NAME))
  5. {
  6. printf("documents folder(\""HTDOCS_NAME"\") is missing!");
  7. SendHTTP(id,remote_clientid,sINTERNAL,.content="Internal server error!");
  8. socket_close_remote_client(id, remote_clientid);
  9. SendRconCommand("exit");
  10. return 1;
  11. }
  12.  
  13. new where = strfind(data,"user-agent:",true);
  14. new where2 = strfind(data,"referer:",true);
  15. new url[256], referer[256];
  16. UserAgent[remote_clientid][0] = EOS;
  17. str[0] = EOS;
  18. for(new i; i<data_len; i++)
  19. {
  20. if((data[i] == '\r' || data[i] == '\n') && isnull(str))
  21. {
  22. strmid(str,data,0,i,256);//fejléc első sora
  23. }
  24. if(isnull(UserAgent[remote_clientid]) && (data[i] == '\r' || data[i] == '\n') && where != -1 && where+12 < i)
  25. {
  26. strmid(UserAgent[remote_clientid],data,where+12,i,256);//user agent
  27. }
  28. if(isnull(referer) && (data[i] == '\r' || data[i] == '\n') && where2 != -1 && where2+9 < i)
  29. {
  30. strmid(referer,data,where2+9,i,256);
  31. new where3 = strfind(referer,"/",true,9);
  32. strmid(referer,referer,where3,strlen(referer),256);
  33. }
  34. }
  35. new per = -1;
  36. for(new i; i<strlen(str); i++)
  37. {
  38. if(str[i] == '/' && per == -1)per = i;
  39. else if(per != -1 && str[i] == ' ')
  40. {
  41. strmid(url,str,per,i,256);
  42. break;
  43. }
  44. }
  45. //if(isnull(url) || Compare(url,"/"))format(url,256,"/index.html");
  46.  
  47. if(strfind(url,".") == -1 && url[strlen(url)-1] == '/')url[strlen(url)-1] = '\0';
  48.  
  49. new str2[256];
  50. format(str2,256,"scriptfiles/htdocs%s",url);
  51. printf("STR: %s",str2);
  52. if(dir_exists(str2) == 1)
  53. {
  54. printf("STR2-dir_exists: %s",str2);
  55. if(isnull(url) || strfind(url,".") == -1 && url[strlen(url)-1] != '/')strcat(url,"/");
  56. if(strfind(url,".") == -1 && url[strlen(url)-1] == '/' || isnull(url))
  57. {
  58. printf("URL: %s",url);
  59. format(str2,256,"htdocs/%sindex.htm",url);
  60. if(fexist(str2))strcat(url,"index.htm");
  61. else strcat(url,"index.html");
  62. format(str2,256,"Location: %s",url);
  63. SendHTTP(id,remote_clientid,sMOVED,.header=str2);
  64. socket_close_remote_client(id, remote_clientid);
  65. return 1;
  66. }
  67. }
  68.  
  69. //else if(strfind(url,".") == -1 && url[strlen(url)-1] != '/')format(url,256,"%s/index.html",url);
  70. format(str,256,url);
  71. for(new i; i<strlen(str); i++)if(str[i] == '/' || str[i] == '.')str[i] = '_';
  72. format(str,256,"page%s",str);
  73. if(ExtCheck(url,".html") || ExtCheck(url,".htm"))
  74. {
  75. //format(WorkingURL[remote_clientid],256,url);
  76. if(CallRemoteFunction(str,"ddss",_:id,remote_clientid,data,url) != 1)
  77. {
  78. LoadDocument(id,remote_clientid,url);
  79. }
  80. }
  81. else
  82. {
  83. LoadDocument(id,remote_clientid,url);
  84. }
  85. socket_close_remote_client(id, remote_clientid);
  86. return 1;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement