proccess.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* This is the proccessing page of the captive portal.
  2. * Copy right: Deben Oldert
  3. * Here classes are called to check and update database query's and to configure iptables.
  4. * Called classe are: {JSON, Command}
  5. */
  6. package captiveportal;
  7. import java.io.IOException;
  8. import java.io.PrintWriter;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.annotation.WebServlet;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. /**
  15. * Servlet implementation class proccess
  16. */
  17. @WebServlet("/proccess")
  18. public class proccess extends HttpServlet {
  19. private static final long serialVersionUID = 1L;
  20. /**
  21. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  22. */
  23. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  24. // Set the MIME type for the page
  25. response.setContentType("text/html");
  26. PrintWriter out = response.getWriter();
  27. // Send user back to login form
  28. try {
  29. out.println("<script>window.location.replace('http://portal.corendon.nl/Portal');</script>");
  30. } finally {
  31. out.close(); // Close the output writer
  32. }
  33. }
  34. /**
  35. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  36. */
  37. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  38. // Set the MIME type for the page
  39. response.setContentType("text/html");
  40. // Define variables
  41. //#####################################
  42. String ticketNumber = request.getParameter("ticket");
  43. int exitCode = 2;
  44. String javaReturn0 = "<script>setTimeout(function(){window.location.replace('http://corendon.nl')},2700);</script>";
  45. String javaReturnErrorS = "<script>window.location.replace('http://portal.corendon.nl/Portal/?err=";
  46. String javaReturnErrorE = "');</script>";
  47. //#####################################
  48. //Start the output writer
  49. PrintWriter out = response.getWriter();
  50. //Load classes
  51. Command CMD = new Command();
  52. json JSON = new json();
  53. try {
  54. // Fallback to version 04-01-2015 (Only if you want to be a badboy)
  55. //if(JSON.checkTicket(ticketNumber)) {
  56. //Call to the grandAccess function in json.java
  57. if(JSON.grandAccess(ticketNumber))
  58. {
  59. //Now lets give the user actually access to the interwebzz
  60. if(CMD.Grand(request.getRemoteAddr())) {
  61. exitCode = 0;
  62. }
  63. //If you did not pass, say so
  64. else {
  65. exitCode = 3;
  66. }
  67. }
  68. //If you did not pass, say so
  69. else
  70. {
  71. exitCode = 2;
  72. }
  73. //Part of the fallback
  74. /*}
  75. else {
  76. exitCode = 1;
  77. }*/
  78. // what ya' gonna do, what ya' gonna do when they come for you....
  79. } catch (Exception e) {
  80. e.printStackTrace();
  81. exitCode = 4;
  82. }
  83. //What to do with a exitCode?
  84. switch (exitCode) {
  85. //Whet could we do, what could we do...
  86. case 0:
  87. //Eureka!! Making the path to the interwebzz
  88. request.getRequestDispatcher("/loading.html").include(request, response);
  89. out.println(javaReturn0);
  90. break;
  91. //For the following cases: Get back where you came from (index.html) but with a return code
  92. case 1:
  93. out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
  94. break;
  95. case 2:
  96. out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
  97. break;
  98. case 3:
  99. out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
  100. break;
  101. case 4:
  102. out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
  103. break;
  104. case 5:
  105. out.println(javaReturnErrorS+exitCode+javaReturnErrorE);
  106. break;
  107. }
  108. }
  109. }