|
@@ -1,6 +1,10 @@
|
|
|
package captiveportal;
|
|
package captiveportal;
|
|
|
|
|
|
|
|
|
|
+import java.text.DateFormat;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
|
import java.io.OutputStreamWriter;
|
|
import java.io.OutputStreamWriter;
|
|
@@ -18,11 +22,12 @@ public class json {
|
|
|
private final String teamId = "INXXX-X";
|
|
private final String teamId = "INXXX-X";
|
|
|
private String[] listTickets(String url, String json) throws Exception {
|
|
private String[] listTickets(String url, String json) throws Exception {
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //The url to the JSON listener
|
|
|
URL http = new URL(url);
|
|
URL http = new URL(url);
|
|
|
|
|
+ //Make the connection to the listener
|
|
|
HttpURLConnection con = (HttpURLConnection) http.openConnection();
|
|
HttpURLConnection con = (HttpURLConnection) http.openConnection();
|
|
|
|
|
|
|
|
- //add reuqest header
|
|
|
|
|
|
|
+ //add reuqest headers
|
|
|
con.setRequestMethod("POST");
|
|
con.setRequestMethod("POST");
|
|
|
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
|
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
|
|
con.setRequestProperty("Content-Type", "application/json");
|
|
con.setRequestProperty("Content-Type", "application/json");
|
|
@@ -30,51 +35,73 @@ public class json {
|
|
|
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
|
|
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
|
|
|
|
|
|
|
|
// Send post request
|
|
// Send post request
|
|
|
|
|
+ //Do some fancy shizzle
|
|
|
con.setDoOutput(true);
|
|
con.setDoOutput(true);
|
|
|
OutputStreamWriter data= new OutputStreamWriter(con.getOutputStream());
|
|
OutputStreamWriter data= new OutputStreamWriter(con.getOutputStream());
|
|
|
|
|
+ //Send the JSON request
|
|
|
data.write(json);
|
|
data.write(json);
|
|
|
data.flush();
|
|
data.flush();
|
|
|
|
|
+ //Get the JSON response
|
|
|
BufferedReader in = new BufferedReader(
|
|
BufferedReader in = new BufferedReader(
|
|
|
new InputStreamReader(con.getInputStream()));
|
|
new InputStreamReader(con.getInputStream()));
|
|
|
String inputLine;
|
|
String inputLine;
|
|
|
StringBuffer response = new StringBuffer();
|
|
StringBuffer response = new StringBuffer();
|
|
|
-
|
|
|
|
|
|
|
+ //Put the response in a string (not in the underpants)
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
while ((inputLine = in.readLine()) != null) {
|
|
|
response.append(inputLine);
|
|
response.append(inputLine);
|
|
|
}
|
|
}
|
|
|
in.close();
|
|
in.close();
|
|
|
|
|
|
|
|
- //print result
|
|
|
|
|
|
|
+ //Parse to JSON
|
|
|
JSONParser parser=new JSONParser();
|
|
JSONParser parser=new JSONParser();
|
|
|
|
|
+ //Make it a string
|
|
|
String s = response.toString();
|
|
String s = response.toString();
|
|
|
-
|
|
|
|
|
|
|
+ //Just give it a shot
|
|
|
try{
|
|
try{
|
|
|
|
|
+ //Create JSON object
|
|
|
Object obj = parser.parse(s);
|
|
Object obj = parser.parse(s);
|
|
|
|
|
+ //Get the ticket variable from the full JSON object
|
|
|
JSONObject tickets = (JSONObject)obj;
|
|
JSONObject tickets = (JSONObject)obj;
|
|
|
|
|
+ //Make from the value of tickets an array (because we can and it simply is)
|
|
|
JSONArray array = (JSONArray)tickets.get("tickets");
|
|
JSONArray array = (JSONArray)tickets.get("tickets");
|
|
|
|
|
+ //Create an array from every ticketNumber in the array (with maximum as amount if tickets)
|
|
|
String[] ticketNumbers = new String[(int) array.size()];
|
|
String[] ticketNumbers = new String[(int) array.size()];
|
|
|
|
|
+ //Let loop it
|
|
|
for(int i = 0; i < (int) array.size(); i++)
|
|
for(int i = 0; i < (int) array.size(); i++)
|
|
|
{
|
|
{
|
|
|
|
|
+ //Get the ticket number from each ticket
|
|
|
JSONObject ticketNumber = (JSONObject)array.get(i);
|
|
JSONObject ticketNumber = (JSONObject)array.get(i);
|
|
|
|
|
+ //Make from the number a string and put in our newly created array
|
|
|
ticketNumbers[i] = (String) ticketNumber.get("ticketNumber");
|
|
ticketNumbers[i] = (String) ticketNumber.get("ticketNumber");
|
|
|
|
|
+ //Not at the end? Lets do it again!
|
|
|
}
|
|
}
|
|
|
|
|
+ //Now the purpose of this function Return all the ticket number in a singel array
|
|
|
return ticketNumbers;
|
|
return ticketNumbers;
|
|
|
|
|
+ //If you found le wild Charizard catch it.
|
|
|
}catch(ParseException pe){
|
|
}catch(ParseException pe){
|
|
|
System.out.println("position: " + pe.getPosition());
|
|
System.out.println("position: " + pe.getPosition());
|
|
|
System.out.println(pe);
|
|
System.out.println(pe);
|
|
|
|
|
+ /*
|
|
|
|
|
+ I wanna be the very best,
|
|
|
|
|
+ Like no one ever was.
|
|
|
|
|
+ To catch them is my real test,
|
|
|
|
|
+ To train them is my cause.
|
|
|
|
|
+ */
|
|
|
}
|
|
}
|
|
|
- String[] returnArray = {"ERROR", "FOUTMELDING"};
|
|
|
|
|
|
|
+ //If error return it
|
|
|
|
|
+ String[] returnArray = {"ERROR", "BOEHOEHOE"};
|
|
|
return returnArray;
|
|
return returnArray;
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
private String grandAccessRequest(String json) throws Exception {
|
|
private String grandAccessRequest(String json) throws Exception {
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //The url to the JSON listener
|
|
|
URL http = new URL("http://webapi.implementation.computerscience.international:9323/CFIS/Ticket");
|
|
URL http = new URL("http://webapi.implementation.computerscience.international:9323/CFIS/Ticket");
|
|
|
|
|
+ //Make the connection to the listener
|
|
|
HttpURLConnection con = (HttpURLConnection) http.openConnection();
|
|
HttpURLConnection con = (HttpURLConnection) http.openConnection();
|
|
|
|
|
|
|
|
- //add reuqest header
|
|
|
|
|
|
|
+ //add reuqest headers
|
|
|
con.setRequestMethod("POST");
|
|
con.setRequestMethod("POST");
|
|
|
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
|
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
|
|
con.setRequestProperty("Content-Type", "application/json");
|
|
con.setRequestProperty("Content-Type", "application/json");
|
|
@@ -85,25 +112,32 @@ public class json {
|
|
|
con.setDoOutput(true);
|
|
con.setDoOutput(true);
|
|
|
OutputStreamWriter data= new OutputStreamWriter(con.getOutputStream());
|
|
OutputStreamWriter data= new OutputStreamWriter(con.getOutputStream());
|
|
|
data.write(json);
|
|
data.write(json);
|
|
|
|
|
+ //Send JSON request
|
|
|
data.flush();
|
|
data.flush();
|
|
|
|
|
+ //Read JSON response
|
|
|
BufferedReader in = new BufferedReader(
|
|
BufferedReader in = new BufferedReader(
|
|
|
new InputStreamReader(con.getInputStream()));
|
|
new InputStreamReader(con.getInputStream()));
|
|
|
String inputLine;
|
|
String inputLine;
|
|
|
StringBuffer response = new StringBuffer();
|
|
StringBuffer response = new StringBuffer();
|
|
|
-
|
|
|
|
|
|
|
+ //Get all the output, and place it in one string
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
while ((inputLine = in.readLine()) != null) {
|
|
|
response.append(inputLine);
|
|
response.append(inputLine);
|
|
|
}
|
|
}
|
|
|
in.close();
|
|
in.close();
|
|
|
|
|
|
|
|
- //print result
|
|
|
|
|
|
|
+ //Parse result to JSON
|
|
|
JSONParser parser=new JSONParser();
|
|
JSONParser parser=new JSONParser();
|
|
|
|
|
+ //Make from a raw JSON object an string
|
|
|
String s = response.toString();
|
|
String s = response.toString();
|
|
|
|
|
+ //Create JSON object
|
|
|
Object obj = parser.parse(s);
|
|
Object obj = parser.parse(s);
|
|
|
|
|
+ //Get the respond code
|
|
|
JSONObject resultCode = (JSONObject)obj;
|
|
JSONObject resultCode = (JSONObject)obj;
|
|
|
|
|
+ //Make the code a string
|
|
|
return (String) resultCode.get("result");
|
|
return (String) resultCode.get("result");
|
|
|
}
|
|
}
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
+ //Deprecated since version 04-01-2015. So no small talk
|
|
|
public boolean checkTicket(String ticketNumber) throws Exception
|
|
public boolean checkTicket(String ticketNumber) throws Exception
|
|
|
{
|
|
{
|
|
|
JSONObject json=new JSONObject();
|
|
JSONObject json=new JSONObject();
|
|
@@ -130,25 +164,40 @@ public class json {
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
public boolean grandAccess(String ticketNumber) throws Exception
|
|
public boolean grandAccess(String ticketNumber) throws Exception
|
|
|
{
|
|
{
|
|
|
|
|
+ //Create JSON object
|
|
|
JSONObject json=new JSONObject();
|
|
JSONObject json=new JSONObject();
|
|
|
- Random random = new Random();
|
|
|
|
|
- int requestId = random.nextInt(9999) + 1000;
|
|
|
|
|
|
|
+ //Our unique ID will be a timestamp
|
|
|
|
|
+ //Set the stamp format
|
|
|
|
|
+ DateFormat TimeStamp = new SimpleDateFormat("MMddyyyyHHmmssSSS");
|
|
|
|
|
+ //Get the current date
|
|
|
|
|
+ Date today = Calendar.getInstance().getTime();
|
|
|
|
|
+ //Make it a string
|
|
|
|
|
+ String CurrentTimeStamp = TimeStamp.format(today);
|
|
|
|
|
+ //Put variables in our JSON object
|
|
|
json.put("function", "RegisterInternetAccess");
|
|
json.put("function", "RegisterInternetAccess");
|
|
|
json.put("teamId", teamId);
|
|
json.put("teamId", teamId);
|
|
|
json.put("teamKey", teamKey);
|
|
json.put("teamKey", teamKey);
|
|
|
- json.put("requestId", new Integer(requestId));
|
|
|
|
|
|
|
+ json.put("requestId", CurrentTimeStamp);
|
|
|
json.put("ticketNumber", ticketNumber);
|
|
json.put("ticketNumber", ticketNumber);
|
|
|
|
|
+ //Write it to a string
|
|
|
StringWriter out = new StringWriter();
|
|
StringWriter out = new StringWriter();
|
|
|
json.writeJSONString(out);
|
|
json.writeJSONString(out);
|
|
|
String jsonText = out.toString();
|
|
String jsonText = out.toString();
|
|
|
|
|
+ //Call the function grandAccessRequest
|
|
|
String grandResult = grandAccessRequest(jsonText);
|
|
String grandResult = grandAccessRequest(jsonText);
|
|
|
|
|
+ //If login succesfull or if user already logged in. Then you may pass
|
|
|
if(grandResult.equals("0") || grandResult.equals("8"))
|
|
if(grandResult.equals("0") || grandResult.equals("8"))
|
|
|
{
|
|
{
|
|
|
|
|
+ //Congrats. Now you can log in!
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
+ //Else..
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
|
|
+ //Not
|
|
|
|
|
+ //Print to the system why not
|
|
|
System.out.println("Suddenly le wild error code (" +grandResult+ ") appeared!!");
|
|
System.out.println("Suddenly le wild error code (" +grandResult+ ") appeared!!");
|
|
|
|
|
+ //Say it fails
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|