Skip to content

Commit

Permalink
Fix logout bugs, Add server response reason list, New UI design
Browse files Browse the repository at this point in the history
  • Loading branch information
hearsilent committed Jun 20, 2015
1 parent 7546ca6 commit dcc6f93
Show file tree
Hide file tree
Showing 12 changed files with 353 additions and 311 deletions.
396 changes: 190 additions & 206 deletions KUASWifiAutoLogin/.idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion KUASWifiAutoLogin/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="jsoup-1.8.2" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="jsoup-1.8.2" level="project" />
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
Expand Down
4 changes: 2 additions & 2 deletions KUASWifiAutoLogin/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "tw.edu.kuas.wifiautologin"
minSdkVersion 9
targetSdkVersion 22
versionCode 213
versionName "2.1.3"
versionCode 214
versionName "2.1.4"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package tw.edu.kuas.wifiautologin.callbacks;

public class Reason {

public static String dumpReason(int reason)
{
switch (reason)
{
case 1: return "登入頁面出現了系統錯誤!";
case 2: return "沒有指定認證策略!";
case 3: return "認證策略中自動增加指定的組不存在!";
case 7: return "用戶已經被列入黑名單!";
case 8: return "超出帳號最大登入數!";
case 9: return "帳號綁定檢查失敗!";
case 10: case 44: case 56: return "帳號不存在!";
case 11: case 45: case 57: return "密碼不正確!";
case 12: return "該帳號已經被凍結!";
case 20:case 21:case 22:case 25: return "連接RADIUS伺服器時,發生了故障(" + reason +")!";
case 24: return "無法連接到指定的RADIUS伺服器!";
case 26: return "RADIUS伺服器回應數據不正確!";
case 27:case 35: return "認證失敗,請檢查您的帳號及密碼 ";
case 30: return "無法連接到指定的POP3伺服器!";
case 31:case 32: return "連接POP3伺服器時,發生了故障(" + reason + ")!";
case 33:case 34: return "POP3伺服器回應數據不正確(" + reason + ")!";
case 40:case 42:case 43: return "連接LDAP伺服器時,發生了故障(" + reason + ")!";
case 41: return "無法連接到指定的LDAP伺服器!";
case 50: return "AD伺服器域名配置錯誤!";
case 51:case 53:case 54: return "連接AD伺服器時,發生了故障(" + reason + ")!";
case 52: return "無法連接到指定的AD伺服器!";
case 55: return "AD伺服器的查詢密碼不正確!";
case 60: return "登入失敗次數超出最大限制!";
default: return "web_auth_error_" + reason;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import tw.edu.kuas.wifiautologin.callbacks.Constant;
import tw.edu.kuas.wifiautologin.callbacks.GeneralCallback;
import tw.edu.kuas.wifiautologin.callbacks.Memory;
import tw.edu.kuas.wifiautologin.callbacks.Reason;

public class LoginHelper {
private static AsyncHttpClient mClient = init();
Expand Down Expand Up @@ -100,8 +101,9 @@ public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
if (callback != null)
{
loginSuccess(context, loginType, callback,
(_IP.split("\\.")[0].equals("172") && _IP.split("\\.")[1].equals("17")) ? Constant.JIANGONG_WIFI_SERVER : Constant.YANCHAO_WIFI_SERVER
, resultString, false);
(_IP.split("\\.")[0].equals("172") && _IP.split("\\.")[1].equals("17")) ?
Constant.JIANGONG_WIFI_SERVER : Constant.YANCHAO_WIFI_SERVER
, resultString, false);
Toast.makeText(context, resultString, Toast.LENGTH_SHORT).show();

tracker.send(new HitBuilders.EventBuilder()
Expand Down Expand Up @@ -166,7 +168,7 @@ private static void login(final Context context, final LinkedHashMap<String, Str
@Override
public void run() {
try{
Connection.Response response = Jsoup.connect(String.format("http://%s/cgi-bin/ace_web_auth.cgi", loginServer))
final Connection.Response response = Jsoup.connect(String.format("http://%s/cgi-bin/ace_web_auth.cgi", loginServer))
.data(paramsMap)
.userAgent(Constant.USER_AGENT)
.timeout(Constant.TIMEOUT_LOGIN)
Expand All @@ -177,35 +179,37 @@ public void run() {
.execute();

final String _response = response.body();
final int _statusCode = response.statusCode();

if(_statusCode == HttpStatus.SC_OK) {
if (_response.contains("reason=27&") || _response.contains("reason=35&")) {
refresh.post(new Runnable() {
public void run() {
mClient.get(context, "http://www.example.com/", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(final int statusCode, Header[] headers, byte[] bytes) {
if (statusCode == HttpStatus.SC_OK)
loginSuccess(context, loginType, callback, loginServer, "", true);
else
retryLogin(context, paramsMap, loginType, callback, retry, loginServer, "",
retry ? "" : _response);
}

@Override
public void onFailure(final int statusCode, Header[] headers, byte[] bytes, Throwable e) {
e.printStackTrace();

retryLogin(context, paramsMap, loginType, callback, retry, loginServer, "",
retry ? "" : _response);
}
});
retryLogin(context, paramsMap, loginType, callback, false, loginServer,
context.getString(R.string.user_pwd_error), _response);
}
});
}
else {
if (_statusCode == HttpStatus.SC_MOVED_TEMPORARILY)
Log.d(Constant.TAG, Integer.toString(_statusCode));
} else if (_response.contains("reason=")) {
final String _reason = _response.substring(_response.indexOf("reason=") + 7,
_response.indexOf("&", _response.indexOf("reason=")));
refresh.post(new Runnable() {
public void run() {
retryLogin(context, paramsMap, loginType, callback, false, loginServer,
Reason.dumpReason(Integer.parseInt(_reason)), _response);
}
});
} else if (_response.contains("404 - Not Found")) {
refresh.post(new Runnable() {
public void run() {
retryLogin(context, paramsMap, loginType, callback, retry, loginServer,
context.getString(R.string.login_timeout), "Time Out");
}
});
} else if (_response.contains("login_online_detail.php")) {
refresh.post(new Runnable() {
public void run() {
loginSuccess(context, loginType, callback, loginServer, "", true);
}
});
} else {
refresh.post(new Runnable() {
public void run() {
mClient.get(context, "http://www.example.com/", new AsyncHttpResponseHandler() {
Expand Down Expand Up @@ -246,67 +250,82 @@ public static void logout(final Context context, final GeneralCallback callback)
if (!checkSSID(context, callback)) return;
initGA(context);

mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

mClient.setTimeout(Constant.TIMEOUT_LOGOUT);
mClient.get(String.format("http://%s/", Constant.JIANGONG_WIFI_SERVER),
new AsyncHttpResponseHandler() {
String loginServer = "";
String location = "";

@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
if (statusCode == HttpStatus.SC_TEMPORARY_REDIRECT) {
if (headers != null) {
for (Header header : headers) {
if (header.getName().toLowerCase().equals("location")) {
Uri uri = Uri.parse(header.getValue());
loginServer = uri.getAuthority();
break;
}
if (headers != null) {
for (Header header : headers) {
if (header.getName().toLowerCase().equals("location")) {
location = header.getValue();
break;
}
}
if (!loginServer.equals("")) {
if (loginServer.contains("login_online"))
logout(context, callback, Constant.JIANGONG_WIFI_SERVER);
else if (loginServer.contains("auth_entry")) {
tracker.send(new HitBuilders.EventBuilder()
.setCategory("onFailure")
.setAction("Logout")
.setLabel("Already logged out")
.build());
callback.onFail(context.getText(R.string.already_logged_out).toString());
} else
logout(context, callback, Constant.YANCHAO_WIFI_SERVER);
} else {
callback.onFail(context.getText(R.string.failed_to_logout).toString());
tracker.send(new HitBuilders.EventBuilder()
.setCategory("onFailure")
.setAction("Logout")
.setLabel("Null headers")
.build());
}
} else {
callback.onFail(context.getText(R.string.failed_to_logout).toString());
tracker.send(new HitBuilders.EventBuilder()
.setCategory("onFailure")
.setAction("Logout")
.setLabel(Integer.toString(statusCode))
.build());
checkLogoutLocation(context, callback, location);
}
else
checkLogoutLocation(context, callback, "");
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse,
Throwable e) {
if (statusCode == HttpStatus.SC_NOT_FOUND) {
callback.onFail(context.getText(R.string.login_timeout).toString());

callback.onFail(context.getText(R.string.login_timeout).toString());
tracker.send(new HitBuilders.EventBuilder()
.setCategory("onFailure")
.setAction("Logout")
.setLabel("Time Out")
.build());
tracker.send(new HitBuilders.EventBuilder()
.setCategory("onFailure")
.setAction("Logout")
.setLabel("Time Out")
.build());
} else {
if (headers != null) {
for (Header header : headers) {
if (header.getName().toLowerCase().equals("location")) {
location = header.getValue();
break;
}
}
checkLogoutLocation(context, callback, location);
}
else
checkLogoutLocation(context, callback, "");
}
}
});
}

private static void checkLogoutLocation(final Context context, final GeneralCallback callback, String location)
{
if (!location.equals("")) {
if (location.contains("login_online"))
logout(context, callback, Constant.JIANGONG_WIFI_SERVER);
else if (location.contains("auth_entry")) {
tracker.send(new HitBuilders.EventBuilder()
.setCategory("onFailure")
.setAction("Logout")
.setLabel("Already logged out")
.build());
callback.onFail(context.getText(R.string.already_logged_out).toString());
} else
logout(context, callback, Constant.YANCHAO_WIFI_SERVER);
} else {
callback.onFail(context.getText(R.string.failed_to_logout).toString());
tracker.send(new HitBuilders.EventBuilder()
.setCategory("onFailure")
.setAction("Logout")
.setLabel("Null headers")
.build());
}
}


private static void logout(final Context context, final GeneralCallback callback, final String logoutServer) {
mClient.get(String.format("http://%s/cgi-bin/ace_web_auth.cgi?logout", logoutServer),
new AsyncHttpResponseHandler() {
Expand All @@ -319,13 +338,19 @@ public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
tracker.send(new HitBuilders.EventBuilder()
.setCategory("onSuccess")
.setAction("Logout")
.setLabel("logout successful")
.setLabel(logoutServer.equals(Constant.JIANGONG_WIFI_SERVER) ? "建工" : "燕巢")
.build());
}

@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
callback.onFail(context.getText(R.string.failed_to_logout).toString());

tracker.send(new HitBuilders.EventBuilder()
.setCategory("onFailure")
.setAction("Logout")
.setLabel("Time Out")
.build());
}
});
}
Expand Down Expand Up @@ -366,8 +391,7 @@ private static void retryLogin(Context context, final LinkedHashMap<String, Stri
.bigText(resultString));

if (!(callback == null && errorTimes >= 3))
mNotificationManager
.notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
mNotificationManager.notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());

errorTimes++;
Memory.setInt(context, Constant.MEMORY_KEY_ERRORTIMES, errorTimes);
Expand Down Expand Up @@ -400,6 +424,11 @@ private static void loginSuccess(Context context, String loginType, GeneralCallb
(loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? context.getString(R.string.jiangong) :
context.getString(R.string.yanchao)));
break;
case "Teacher":
resultString = String.format(context.getString(R.string.login_teacher_successfully),
(loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? context.getString(R.string.jiangong) :
context.getString(R.string.yanchao)));
break;
default:
resultString = String.format(context.getString(R.string.login_guest_successfully),
(loginServer.equals(Constant.JIANGONG_WIFI_SERVER) ? context.getString(R.string.jiangong) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ else if (user.length() == 10 && !user.substring(0,2).equals("09"))
return user + "@kuas.edu.tw" + ",1,Student";
else
return user + "@gm.kuas.edu.tw" + ",@gm.kuas.edu.tw,Student";
else if (user.length() == 5)
return user + "@kuas.edu.tw" + ",,Teacher";
else if (user.contains("@") && !user.contains("@guest"))
return user + ",,Cyber";
else
if (user.contains("@guest"))
return user + ",,Guest";
else
return user + "@guest,,Guest";
if (user.contains("@guest"))
return user + ",,Guest";
else
return user + "@guest,,Guest";
}

}
Binary file modified KUASWifiAutoLogin/app/src/main/res/drawable-nodpi/ic_main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 2 additions & 9 deletions KUASWifiAutoLogin/app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@
android:orientation="vertical">

<ImageView
android:layout_width="150dp"
android:layout_width="match_parent"
android:layout_height="150dp"
android:padding="8dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_main"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/kuas_wifi_auto_login"
android:textColor="@color/primary_material_dark"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"/>
</LinearLayout>

<ScrollView
Expand Down
Loading

0 comments on commit dcc6f93

Please sign in to comment.