Advertisement
Guest User

Untitled

a guest
Dec 1st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. key value store via PHP only
  2.  
  3. LSL----------------------------------------------------------------------------------------------
  4. string PHPURL = "https://opushub.000webhostapp.com/kvs/keyvaluestore.php";
  5.  
  6. integer working;
  7.  
  8. integer handle;
  9. key user;
  10. string mKey;
  11.  
  12. TextBox(key user, string msg, integer channel)
  13. {
  14. llListenRemove(handle);
  15. handle = llListen(channel, "",user,"");
  16. llTextBox(user,msg,channel);
  17. }
  18.  
  19. string buildbody(string func, string keyvalue, string value, string pvalue)
  20. {
  21. string body = "arg="+llStringToBase64("abc123easy")+"&";
  22. list modules = ["func="+func, "key="+keyvalue, "value="+(string)value, "pvalue="+pvalue];
  23. return body+llDumpList2String(modules,"&");
  24. }
  25.  
  26.  
  27. ReadKeyValue(string input)
  28. {
  29. llHTTPRequest(PHPURL,[HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],buildbody("get",input,"#","#"));
  30. }
  31.  
  32. SetKeyValue(string input, string value)
  33. {
  34. llHTTPRequest(PHPURL,[HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],buildbody("set",input,value,"#"));
  35. }
  36.  
  37. integer catcherror(string input)
  38. {
  39. if(input == "FNF" || input == "CONF") return 1;
  40. else return 0;
  41. }
  42.  
  43. error(string input)
  44. {
  45. if(input == "FNF") llSay(0,"error, key not found.");
  46. if(input == "CONF") llSay(0,"key-value set!");
  47. else llSay(0,input);
  48. }
  49.  
  50.  
  51. default
  52. {
  53. state_entry()
  54. {
  55. llSay(0, "Hello, Avatar!");
  56. }
  57.  
  58. touch_start(integer total_number)
  59. {
  60. if(!working)
  61. {
  62. working=1;
  63. TextBox(user=llDetectedKey(0),"input key you want to set",-40);
  64. }
  65. }
  66.  
  67. listen(integer channel, string name, key id, string message)
  68. {
  69. if(channel == -40)
  70. {
  71. mKey = message;
  72. TextBox(user,"input key's value",-41);
  73. }
  74.  
  75. if(channel == -41)
  76. {
  77. SetKeyValue(mKey,message);
  78. }
  79. }
  80.  
  81. http_response(key id, integer status, list meta, string body)
  82. {
  83. if(catcherror(body)) error(body);
  84. else
  85. {
  86. llListenRemove(handle);
  87. working=0;
  88. llSay(0,"value: "+body);
  89. }
  90. }
  91. }
  92.  
  93. PHP-----------------------------------------------------------------------------------------------------------------
  94.  
  95. <?php
  96.  
  97. $password = "abc123easy";
  98.  
  99. $arg = $_POST['arg'];
  100. $func = $_POST['func'];
  101. $key = $_POST['key'];
  102. $value = $_POST['value'];
  103. $pvalue = $_POST['pvalue'];
  104.  
  105. if(base64_decode($arg) == $password)
  106. {
  107. if($func == "get")
  108. {
  109. $file = @fopen($key,"r") or die("FNF");
  110. $msg = fread($file,filesize($key));
  111. fclose($file);
  112. die($msg);
  113. }
  114.  
  115. if($func == "set")
  116. {
  117. $file = fopen($key,"w");
  118. fwrite($file,$value);
  119. fclose($file);
  120. die("CONF");
  121. }
  122.  
  123. if($func == "upd")
  124. {
  125. $file = fopen($key,"r");
  126. $tmpvalue = fread($file,filesize($key));
  127. if($tmpvalue == $pvalue)
  128. {
  129. $file = fopen($key,"w");
  130. fwrite($file,$value);
  131. fclose($file);
  132. die("UCONF");
  133. }
  134.  
  135. else
  136. {
  137. fclose($file);
  138. die("FAIL");
  139. }
  140. }
  141. }
  142.  
  143. else die("UA");
  144.  
  145.  
  146. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement