Skip to content

Commit

Permalink
Merge pull request #77 from w-shackleton/blueball
Browse files Browse the repository at this point in the history
Fixed the blue ball machine (crudely)
  • Loading branch information
w-shackleton committed Apr 27, 2015
2 parents 6081b08 + 350d79d commit 0a6fb20
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class RedirectSpoof extends Spoof implements LogConf {
public static final int MODE_BLUEBALL = 1;
public static final int MODE_CUSTOM = 2;

private String redirect, host;
private String redirect, host, topLevelDomain;

private static String getTitle(Context context, int mode) {
switch(mode) {
Expand Down Expand Up @@ -138,8 +138,9 @@ public void modifyRequest(HttpRequest request) {
}
@Override
public void modifyResponse(HttpResponse response, HttpRequest request) {
if(response.getContentType().startsWith("text/html")) {
if(request.getHost().equals(host)) return;
if (response.getContentType().startsWith("text/html")) {
if (request.getHost().equals(host)) return;
if (request.getHost().endsWith(topLevelDomain)) return;
response.reset();
response.setResponseCode(301);
response.setResponseMessage("Moved Permanently");
Expand All @@ -155,6 +156,12 @@ private void setRedirect(String redirect) {
this.redirect = redirect;
try {
host = Uri.parse(redirect).getHost();
int index = host.indexOf('.');
if (index == -1) {
topLevelDomain = host;
} else {
topLevelDomain = host.substring(index + 1);
}
} catch(Exception e) { } // This exception will only happen on user
// stupidity
}
Expand Down

0 comments on commit 0a6fb20

Please sign in to comment.