|
1 | 1 | package me.checkium.vhackapi.console; |
2 | 2 |
|
| 3 | +import me.checkium.vhackapi.Utils; |
| 4 | +import org.json.JSONArray; |
| 5 | +import org.json.JSONObject; |
| 6 | + |
3 | 7 | import java.io.BufferedReader; |
4 | 8 | import java.io.IOException; |
5 | 9 | import java.io.InputStreamReader; |
6 | | -import java.net.MalformedURLException; |
7 | 10 | import java.net.URL; |
8 | 11 | import java.net.URLConnection; |
9 | 12 | import java.util.HashMap; |
10 | 13 | import java.util.concurrent.TimeUnit; |
11 | 14 |
|
12 | | -import org.json.JSONArray; |
13 | | -import org.json.JSONObject; |
| 15 | +public class AdwareManager { |
14 | 16 |
|
15 | | -import me.checkium.vhackapi.Utils; |
| 17 | + protected String password; |
| 18 | + protected String username; |
16 | 19 |
|
17 | | -public class AdwareManager { |
| 20 | + public AdwareManager(String pass, String user) { |
| 21 | + password = pass; |
| 22 | + username = user; |
| 23 | + } |
| 24 | + |
| 25 | + public boolean uploadAdware(String target) { |
| 26 | + |
| 27 | + URLConnection in; |
| 28 | + try { |
| 29 | + in = new URL(Utils.generateURL("user::::pass::::target", username + "::::" + password + "::::" + target, "vh_adwareUpload.php")).openConnection(); |
| 30 | + |
| 31 | + BufferedReader br = new BufferedReader(new InputStreamReader((in.getInputStream()))); |
| 32 | + String line = br.readLine(); |
| 33 | + return line.contains("0"); |
| 34 | + } catch (IOException e) { |
| 35 | + // TODO Auto-generated catch block |
| 36 | + e.printStackTrace(); |
| 37 | + } |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + public boolean removeAdware(String target) { |
| 42 | + @SuppressWarnings("unused") |
| 43 | + URLConnection in; |
| 44 | + try { |
| 45 | + in = new URL(Utils.generateURL("user::::pass::::target", username + "::::" + password + "::::" + target, "vh_removeAdwareRemote.php")).openConnection(); |
| 46 | + BufferedReader br = new BufferedReader(new InputStreamReader((in.getInputStream()))); |
| 47 | + String line = br.readLine(); |
| 48 | + JSONObject json = new JSONObject(line); |
| 49 | + return json.getInt("result") == 0; |
| 50 | + } catch (IOException e) { |
| 51 | + e.printStackTrace(); |
| 52 | + } |
| 53 | + return false; |
| 54 | + |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + public HashMap<String, Integer> getAdwares() { |
| 59 | + try { |
| 60 | + TimeUnit.MILLISECONDS.sleep(100); |
| 61 | + } catch (InterruptedException e) { |
| 62 | + // TODO Auto-generated catch block |
| 63 | + e.printStackTrace(); |
| 64 | + } |
| 65 | + HashMap<String, Integer> map = new HashMap<>(); |
| 66 | + JSONObject json = Utils.JSONRequest("user::::pass", username + "::::" + password, "vh_adwareInfo.php"); |
| 67 | + if (json.getInt("remote") <= 0) { |
| 68 | + return null; |
| 69 | + } |
| 70 | + JSONArray array = json.getJSONArray("data"); |
| 71 | + for (int i = 0; i <= array.length() - 1; i++) { |
| 72 | + String IP = array.getJSONObject(i).getString("ip"); |
| 73 | + Integer earn = array.getJSONObject(i).getInt("earn"); |
| 74 | + map.put(IP, earn); |
| 75 | + } |
18 | 76 |
|
19 | | - protected String password; |
20 | | - protected String username; |
21 | | - public AdwareManager(String pass, String user) { |
22 | | - password = pass; |
23 | | - username = user; |
24 | | - } |
25 | | - public boolean uploadAdware(String target) { |
26 | | - |
27 | | - URLConnection in; |
28 | | - try { |
29 | | - in = new URL(Utils.generateURL("user::::pass::::target", username + "::::" + password + "::::" + target, "vh_adwareUpload.php")).openConnection(); |
30 | | - |
31 | | - BufferedReader br = new BufferedReader(new InputStreamReader((in.getInputStream()))); |
32 | | - String line = br.readLine(); |
33 | | - if (line.contains("11")) { |
34 | | - return true; |
35 | | - } else { |
36 | | - return false; |
37 | | - } |
38 | | - } catch (MalformedURLException e) { |
39 | | - // TODO Auto-generated catch block |
40 | | - e.printStackTrace(); |
41 | | - } catch (IOException e) { |
42 | | - // TODO Auto-generated catch block |
43 | | - e.printStackTrace(); |
44 | | - } |
45 | | - return false; |
46 | | - } |
47 | | - |
48 | | - public boolean removeAdware(String target) { |
49 | | - @SuppressWarnings("unused") |
50 | | - URLConnection in; |
51 | | - try { |
52 | | - in = new URL(Utils.generateURL("user::::pass::::target", username + "::::" + password + "::::" + target, "vh_removeAdwareRemote.php")).openConnection(); |
53 | | - } catch (MalformedURLException e) { |
54 | | - e.printStackTrace(); |
55 | | - } catch (IOException e) { |
56 | | - e.printStackTrace(); |
57 | | - } |
58 | | - |
59 | | - return true; |
60 | | - |
61 | | - } |
62 | | - |
63 | | - |
64 | | - public HashMap<String, Integer> getAdware() { |
65 | | - try { |
66 | | - TimeUnit.MILLISECONDS.sleep(100); |
67 | | - } catch (InterruptedException e) { |
68 | | - // TODO Auto-generated catch block |
69 | | - e.printStackTrace(); |
70 | | - } |
71 | | - HashMap<String, Integer> map = new HashMap<>(); |
72 | | - JSONObject json = Utils.JSONRequest("user::::pass", username + "::::" + password, "vh_adwareInfo.php"); |
73 | | - if (json.getInt("remote") <= 0) { |
74 | | - return null; |
75 | | - } |
76 | | - JSONArray array = json.getJSONArray("data"); |
77 | | - for (int i = 0; i <= array.length() - 1; i++) { |
78 | | - String IP = array.getJSONObject(i).getString("ip"); |
79 | | - Integer earn = array.getJSONObject(i).getInt("earn"); |
80 | | - map.put(IP, earn); |
81 | | - } |
82 | | - |
83 | | - return map; |
84 | | - } |
| 77 | + return map; |
| 78 | + } |
85 | 79 | } |
0 commit comments