-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCheck_Support.java
214 lines (159 loc) · 7.51 KB
/
Check_Support.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* Copyright (C) 2017 rakesh
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package focus;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
/*
*
* @author rakesh
*/
/**
*
* @author rakesh
*/
public class Check_Support {
String url; // If url does not require any script then it should end with a slash (/) (http://lol.com/ or http://lol.com/forum.php)
Multimap<String, String> signature_cookie = ArrayListMultimap.create();
Multimap<String, String> signature_body = ArrayListMultimap.create();
HashMap<String, String> index_url = new HashMap<String, String>();
HashMap<String, String> thread_url = new HashMap<String, String>();
static String forum_package=""; // For storing detected forum package type
/**
*
*/
public Check_Support(){
signature_cookie.put("MYBB-1","mybb[lastactive]");
signature_cookie.put("DISCUZ","_lastact=");
signature_cookie.put("DISCUZ","_lastvisit=");
signature_body.put("DISCUZ","<meta name=\"generator\" content=\"Discuz");
signature_body.put("DISCUZ","Powered by Discuz!</title>");
signature_body.put("MYBB", "Powered By <a href=\"http://www.mybboard.net");
signature_body.put("MYBB", "Powered By <a href=\"https://www.mybboard.net");
signature_body.put("MYBB-1", "\" target=\"_blank\">MyBB Group</a>");
signature_body.put("MYBB-1","Powered By <a href=\"http://mybb.com");
signature_body.put("MYBB-1","Powered By <a href=\"https://mybb.com");
signature_body.put("FLUXBB","<p id=\"poweredby\">Powered by <a href=\"http://fluxbb.org");
signature_body.put("FLUXBB","<p id=\"poweredby\">Powered by <a href=\"https://fluxbb.org");
signature_body.put("PHPBB","Powered by <a href=\"https://www.phpbb.com");
signature_body.put("PHPBB","Powered by <a href=\"http://www.phpbb.com");
signature_body.put("PHPBB","var style_cookie = 'phpBBstyle';"); //https://www.raspberrypi.org/forums/
signature_body.put("PHPBB", "<body id=\"phpbb\""); //http://www.airliners.net/forum/
//signature_body.put("DISCUZ-1", "discuz_uid = '");
signature_body.put("PUNBB", "Powered by <a href=\"http://www.punbb.org");
signature_body.put("PUNBB", "Powered by <a href=\"http://punbb.informer.com");
signature_body.put("PUNBB", "<p id=\"copyright\">Powered by <strong><a href=\"http://punbb.informer.com");
signature_body.put("PUNBB", "Powered by <a href=\"https://www.punbb.org");
signature_body.put("PUNBB", "Powered by <a href=\"https://punbb.informer.com");
signature_body.put("PUNBB", "<p id=\"copyright\">Powered by <strong><a href=\"https://punbb.informer.com");
index_url.put("DISCUZ","?mod=forumdisplay&fid=1");
//index_url.put("DISCUZ-1","forum-1-1.html");
index_url.put("MYBB","forum-1.html");
index_url.put("FLUXBB","viewforum.php?id=1");
index_url.put("PHPBB","viewforum.php?f=1");
index_url.put("PUNBB","viewforum.php?id=1");
index_url.put("MYBB-1","forumdisplay.php?fid=1");
thread_url.put("DISCUZ","?mod=viewthread&tid=1&extra=page%3D1");
//thread_url.put("DISCUZ-1","thread-1-1-1.html");
thread_url.put("MYBB","thread-1.html");
thread_url.put("FLUXBB","viewtopic.php?id=1");
thread_url.put("PHPBB","viewtopic.php?f=1&t=1");
thread_url.put("PUNBB","viewtopic.php?id=1");
thread_url.put("MYBB-1","showthread.php?tid=1");
}
//Identify thread and index URL
/**
*
* @param url
* @return
*/
public int isSupported(String url)
{
this.url=url;
try {
Connection.Response response = Jsoup.connect(url).method(Connection.Method.GET).followRedirects(false).userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36").timeout(100000).execute();
Document doc = response.parse();
String cookies="Cookies Not Set.";
if(response.header("Set-Cookie")!=null)
{
cookies=response.header("Set-Cookie");
}
System.out.println(cookies);
//Check signature in cookies
for(String sign:signature_cookie.keySet()){
for(String value:signature_cookie.get(sign))
{
if(cookies.toLowerCase().contains(value.toLowerCase()))
{
System.out.println(sign);
forum_package=sign;
return 1;
}
}
}
//Check signature in the body
for(String sign:signature_body.keySet()){
System.out.println(sign);
for(String value:signature_body.get(sign))
{ System.out.println(value);
if(doc.html().toLowerCase().contains(value.toLowerCase()))
{
System.out.println(sign);
forum_package=sign;
// temporary fix for MyBB
if(forum_package=="MYBB"||forum_package=="MYBB-1")
if(doc.html().toLowerCase().contains("showthread.php?tid=") && doc.html().toLowerCase().contains("forumdisplay.php?fid="))
{
forum_package="MYBB-1";
}
else{
forum_package="MYBB";
}
return 1;
}
}
}
System.out.println("Couldn't find software package");
return 0; // because forum is not supported
} catch (IOException ex) {
Logger.getLogger(Check_Support.class.getName()).log(Level.SEVERE, null, ex);
}
return 0; // because forum is not supported or unable to detect forum
}
/**
*
* @return
*/
public String getThreadURL()
{
return url+thread_url.get(forum_package);
}
/**
*
* @return
*/
public String getIndexURL()
{
return url+index_url.get(forum_package);
}
}