Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public onSocketReceiveData(Socket:id, remote_clientid, data[], data_len)
- {
- new str[256];
- if(!fexist(HTDOCS_NAME))
- {
- printf("documents folder(\""HTDOCS_NAME"\") is missing!");
- SendHTTP(id,remote_clientid,sINTERNAL,.content="Internal server error!");
- socket_close_remote_client(id, remote_clientid);
- SendRconCommand("exit");
- return 1;
- }
- new where = strfind(data,"user-agent:",true);
- new where2 = strfind(data,"referer:",true);
- new url[256], referer[256];
- UserAgent[remote_clientid][0] = EOS;
- str[0] = EOS;
- for(new i; i<data_len; i++)
- {
- if((data[i] == '\r' || data[i] == '\n') && isnull(str))
- {
- strmid(str,data,0,i,256);//fejléc első sora
- }
- if(isnull(UserAgent[remote_clientid]) && (data[i] == '\r' || data[i] == '\n') && where != -1 && where+12 < i)
- {
- strmid(UserAgent[remote_clientid],data,where+12,i,256);//user agent
- }
- if(isnull(referer) && (data[i] == '\r' || data[i] == '\n') && where2 != -1 && where2+9 < i)
- {
- strmid(referer,data,where2+9,i,256);
- new where3 = strfind(referer,"/",true,9);
- strmid(referer,referer,where3,strlen(referer),256);
- }
- }
- new per = -1;
- for(new i; i<strlen(str); i++)
- {
- if(str[i] == '/' && per == -1)per = i;
- else if(per != -1 && str[i] == ' ')
- {
- strmid(url,str,per,i,256);
- break;
- }
- }
- //if(isnull(url) || Compare(url,"/"))format(url,256,"/index.html");
- if(strfind(url,".") == -1 && url[strlen(url)-1] == '/')url[strlen(url)-1] = '\0';
- new str2[256];
- format(str2,256,"scriptfiles/htdocs%s",url);
- printf("STR: %s",str2);
- if(dir_exists(str2) == 1)
- {
- printf("STR2-dir_exists: %s",str2);
- if(isnull(url) || strfind(url,".") == -1 && url[strlen(url)-1] != '/')strcat(url,"/");
- if(strfind(url,".") == -1 && url[strlen(url)-1] == '/' || isnull(url))
- {
- printf("URL: %s",url);
- format(str2,256,"htdocs/%sindex.htm",url);
- if(fexist(str2))strcat(url,"index.htm");
- else strcat(url,"index.html");
- format(str2,256,"Location: %s",url);
- SendHTTP(id,remote_clientid,sMOVED,.header=str2);
- socket_close_remote_client(id, remote_clientid);
- return 1;
- }
- }
- //else if(strfind(url,".") == -1 && url[strlen(url)-1] != '/')format(url,256,"%s/index.html",url);
- format(str,256,url);
- for(new i; i<strlen(str); i++)if(str[i] == '/' || str[i] == '.')str[i] = '_';
- format(str,256,"page%s",str);
- if(ExtCheck(url,".html") || ExtCheck(url,".htm"))
- {
- //format(WorkingURL[remote_clientid],256,url);
- if(CallRemoteFunction(str,"ddss",_:id,remote_clientid,data,url) != 1)
- {
- LoadDocument(id,remote_clientid,url);
- }
- }
- else
- {
- LoadDocument(id,remote_clientid,url);
- }
- socket_close_remote_client(id, remote_clientid);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement