LapisSea

CROSS WEBSITE REQUESTS

Aug 2nd, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. //CLIENT REQUEST
  2.  
  3.  
  4. function httpBuildQuery(data){
  5. var ret=[];
  6. for(var d in data)ret.push(encodeURIComponent(d)+"="+encodeURIComponent(data[d]));
  7. return ret.join("&");
  8. }
  9. function shortenUrls(urls=[],callback=function(shortUrls){}){
  10. //building request json
  11. var request={data:[],defult:{
  12. type:"POST",
  13. url:"http://tinyurl.com/create.php"
  14. }};
  15. for(var i=0;i<urls.length;i++){
  16. request.data[i]={
  17. post:httpBuildQuery({
  18. url:urls[i],
  19. submit:"Make TinyURL!",
  20. alias:""
  21. })};
  22. }
  23. //http://lapissea.byethost8.com/common/GetURLContent.js
  24. GetURLContent.post("/common/SameDomainProxy.php",JSON.stringify(request),function(txt){
  25. txt=JSON.parse(txt);
  26. if(typeof testingHTML==="undefined")testingHTML=document.createElement('html');
  27. var shortURLs=[];
  28. for(var i=0;i<txt.length;i++){
  29. testingHTML.innerHTML=txt[0];
  30. shortURLs[i]=testingHTML.querySelector("#contentcontainer").querySelector("a").href;
  31. }
  32. callback(shortURLs);
  33. });
  34. }
  35.  
  36. //SERVER
  37. <?php
  38. /*
  39. Usage: json in post
  40. {
  41. data:[
  42. {
  43. type:"get/post/head",
  44. url:"http://www.pornhub.com/",
  45. post:"GIVE ME THAT PUSSY"
  46. },
  47. {
  48. post:"GIVE ME THAT PUSSY2"
  49. },
  50. {
  51. post:"GIVE ME THAT PUSSY3"
  52. },
  53. ...
  54. ],
  55. defult:{ //defult fills missing spots in data
  56. type:"get/post/head",
  57. url:"http://www.pornhub.com/"
  58. }
  59. }
  60. */
  61.  
  62. $data=json_decode(file_get_contents("php://input"));
  63.  
  64. if(!is_array($data->data))respond("request.data is not an array!");
  65.  
  66. $def=$data->defult;
  67. $responses=[];
  68.  
  69. for($i=0;$i<count($data->data);$i++){
  70. $d=$data->data[$i];
  71.  
  72. $type=isset($d->type)?$d->type:$def->type;
  73. $type=strtolower($type);
  74.  
  75. $url=isset($d->url)?$d->url:$def->url;
  76.  
  77. if($type=="post")$responses[$i]=postRrq($url,isset($d->post)?$d->post:$def->post);
  78. else if($type=="get")$responses[$i]=file_get_contents($url);
  79. else if($type=="head")$responses[$i]=get_headers($url,1);
  80. else $responses[$i]='"'.$type.'" is an invalid type!';
  81. }
  82.  
  83. respond($responses);
  84.  
  85. function postRrq($url,$post){
  86. $options=[
  87. 'http'=>[
  88. 'header' =>"Content-type: application/x-www-form-urlencoded\r\n",
  89. 'method' =>'POST',
  90. 'content'=>$post
  91. ]
  92. ];
  93. $context =stream_context_create($options);
  94. $result=file_get_contents($url, false, $context);
  95. return $result;
  96. }
  97.  
  98. function respond($obj){
  99. echo json_encode($obj);
  100. exit;
  101. }
  102. ?>
Add Comment
Please, Sign In to add comment