diff --git a/KUASWifiAutoLogin/.idea/workspace.xml b/KUASWifiAutoLogin/.idea/workspace.xml
index aa89709..974d946 100644
--- a/KUASWifiAutoLogin/.idea/workspace.xml
+++ b/KUASWifiAutoLogin/.idea/workspace.xml
@@ -6,7 +6,7 @@
-
+
@@ -36,126 +36,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1318,7 +1230,7 @@
-
-
-
-
+
+
+
+
@@ -1670,74 +1582,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -1965,7 +1815,7 @@
-
+
@@ -2018,15 +1868,15 @@
-
-
-
+
+
+
@@ -2058,27 +1908,27 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -2091,15 +1941,15 @@
-
-
-
+
+
+
@@ -2118,15 +1968,15 @@
-
-
-
+
+
+
@@ -2158,27 +2008,27 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -2191,15 +2041,15 @@
-
-
-
+
+
+
@@ -2218,15 +2068,15 @@
-
-
-
+
+
+
@@ -2250,27 +2100,27 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -2283,15 +2133,15 @@
-
-
-
+
+
+
@@ -2310,15 +2160,15 @@
-
-
-
+
+
+
@@ -2338,15 +2188,15 @@
-
-
-
+
+
+
@@ -2365,15 +2215,15 @@
-
-
-
+
+
+
@@ -2401,14 +2251,6 @@
-
-
-
-
-
-
-
-
@@ -2417,115 +2259,123 @@
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/KUASWifiAutoLogin/app/build.gradle b/KUASWifiAutoLogin/app/build.gradle
index 2199d7a..4214ac3 100644
--- a/KUASWifiAutoLogin/app/build.gradle
+++ b/KUASWifiAutoLogin/app/build.gradle
@@ -8,8 +8,8 @@ android {
applicationId "tw.edu.kuas.wifiautologin"
minSdkVersion 9
targetSdkVersion 22
- versionCode 211
- versionName "2.1.1"
+ versionCode 212
+ versionName "2.1.2"
}
buildTypes {
release {
diff --git a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/MainActivity.java b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/MainActivity.java
index f7a6b1e..0b26904 100644
--- a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/MainActivity.java
+++ b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/MainActivity.java
@@ -138,7 +138,7 @@ private void saveAndLogin() {
String password = mPasswordEditText.getText().toString();
if (mUsernameEditText.getText().toString().equals("") || mPasswordEditText.getText().toString().equals(""))
{
- userData = tranUser("0937808285@guest@guest");
+ userData = tranUser("0937808285@guest");
password = "1306";
}
else
@@ -169,7 +169,7 @@ private String tranUser(String user)
return user + ",1,Student";
else
return user + ",@gm.kuas.edu.tw,Student";
- else if (user.length() == 10)
+ else if (user.length() == 10 && !user.substring(0,2).equals("09"))
if (Integer.parseInt(user.substring(1,4)) <= 102)
return user + "@kuas.edu.tw" + ",1,Student";
else
@@ -177,7 +177,10 @@ else if (user.length() == 10)
else if (user.contains("@") && !user.contains("@guest"))
return user + ",,Cyber";
else
- return user + ",,Guest";
+ if (user.contains("@guest"))
+ return user + ",,Guest";
+ else
+ return user + "@guest,,Guest";
}
private void showMessage(CharSequence message, boolean shake) {
diff --git a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/WifiReceiver.java b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/WifiReceiver.java
index 5212822..77b441d 100644
--- a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/WifiReceiver.java
+++ b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/WifiReceiver.java
@@ -56,19 +56,22 @@ public void onReceive(final Context context, Intent intent) {
private String tranUser(String user)
{
- if (user.contains("@kuas.edu.tw") || user.contains("@gm.kuas.edu.tw"))
- if (user.contains("@kuas.edu.tw"))
- return user + ",1,Student";
- else
- return user + ",@gm.kuas.edu.tw,Student";
- else if (user.length() == 10)
- if (Integer.parseInt(user.substring(1,4)) <= 102)
- return user + "@kuas.edu.tw" + ",1,Student";
- else
- return user + "@gm.kuas.edu.tw" + ",@gm.kuas.edu.tw,Student";
- else if (user.contains("@") && !user.contains("@guest"))
- return user + ",,Cyber";
- else
- return user + ",,Guest";
+ if (user.contains("@kuas.edu.tw") || user.contains("@gm.kuas.edu.tw"))
+ if (user.contains("@kuas.edu.tw"))
+ return user + ",1,Student";
+ else
+ return user + ",@gm.kuas.edu.tw,Student";
+ else if (user.length() == 10 && !user.substring(0,2).equals("09"))
+ if (Integer.parseInt(user.substring(1,4)) <= 102)
+ return user + "@kuas.edu.tw" + ",1,Student";
+ else
+ return user + "@gm.kuas.edu.tw" + ",@gm.kuas.edu.tw,Student";
+ else if (user.contains("@") && !user.contains("@guest"))
+ return user + ",,Cyber";
+ else
+ if (user.contains("@guest"))
+ return user + ",,Guest";
+ else
+ return user + "@guest,,Guest";
}
}
\ No newline at end of file
diff --git a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/libs/LoginHelper.java b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/libs/LoginHelper.java
index 8075491..a28c298 100644
--- a/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/libs/LoginHelper.java
+++ b/KUASWifiAutoLogin/app/src/main/java/tw/edu/kuas/wifiautologin/libs/LoginHelper.java
@@ -6,6 +6,8 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.Toast;
@@ -19,6 +21,10 @@
import org.apache.http.Header;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.Enumeration;
+
import tw.edu.kuas.wifiautologin.R;
import tw.edu.kuas.wifiautologin.callbacks.Constant;
import tw.edu.kuas.wifiautologin.callbacks.GeneralCallback;
@@ -74,6 +80,8 @@ public static void login(final Context context, String idType, String user, Stri
return;
}
+ Log.d(Constant.TAG, getIPAddress(context));
+
final RequestParams params = new RequestParams();
params.put("idtype", idType);
params.put("username", user);
@@ -88,149 +96,52 @@ public static void login(final Context context, String idType, String user, Stri
String.format(context.getString(R.string.login_to_ssid), currentSsid))
.setSmallIcon(R.drawable.ic_stat_login).setProgress(0, 0, true).setOngoing(true);
- mNotificationManager.notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
-
mTestClient.get(context, "http://www.example.com", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
String resultString = context.getString(R.string.login_ready);
if (statusCode == 200) {
+ Log.d(Constant.TAG, "Already Login.");
+
if (callback != null)
callback.onSuccess(resultString);
- Toast.makeText(context, resultString, Toast.LENGTH_SHORT).show();
- mNotificationManager.cancel(Constant.NOTIFICATION_LOGIN_ID);
+ Toast.makeText(context, resultString, Toast.LENGTH_LONG).show();
}
else
{
- mTestClient.get(context, "http://172.16.61.253/login.php", new AsyncHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
- if (statusCode == 200)
- loginJiangong(context, params, loginType, callback);
- else // 302
- loginYanchao(context, params, loginType, callback);
- Log.d(Constant.TAG, Integer.toString(statusCode));
- }
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable throwable) {
- Log.d(Constant.TAG, Integer.toString(statusCode));
- mTestClient.get(context, "http://172.16.109.253/login.php", new AsyncHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
- loginYanchao(context, params, loginType, callback);
- }
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable throwable) {
- String resultString, resultDetailString = "Connection problem.";
-
- if (headers != null) {
- resultDetailString = "";
- for (Header header : headers) {
- resultDetailString += header.toString() + "\n";
- }
- }
-
- resultString = context.getString(R.string.failed_to_login);
- mBuilder.setContentTitle(context.getString(R.string.app_name))
- .setContentText(resultString).setSmallIcon(R.drawable.ic_stat_login)
- .setContentIntent(getDefaultPendingIntent(context))
- .setAutoCancel(true)
- .setVibrate(new long[]{300, 200, 300, 200})
- .setLights(Color.RED, 800, 800)
- .setProgress(0, 0, false);
-
- if (callback != null) {
- callback.onFail(resultString + "\n" + resultDetailString);
- }
- // Show error details in the expanded notification
- mBuilder.setStyle(new NotificationCompat.BigTextStyle()
- .bigText(resultString + "\n" + resultDetailString));
-
- mNotificationManager
- .notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
- }
- });
- }
- });
+ mNotificationManager.notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
+
+ String _IP = getIPAddress(context);
+ if (_IP.split("\\.")[0].equals("172"))
+ if (_IP.split("\\.")[1].equals("17"))
+ loginJiangong(context, params, loginType, callback);
+ else
+ loginYanchaoDorm(context, params, loginType, callback);
+ else
+ loginYanchao(context, params, loginType, callback);
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable throwable) {
- mTestClient.get(context, "http://172.16.61.253/login.php", new AsyncHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
- if (statusCode == 200)
- loginJiangong(context, params, loginType, callback);
- else // 302
- {
- loginYanchao(context, params, loginType, callback);
-
- tracker.send(new HitBuilders.EventBuilder()
- .setCategory("UX")
- .setAction("Test")
- .setLabel("302")
- .build());
- }
- Log.d(Constant.TAG, Integer.toString(statusCode));
- }
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable throwable) {
- Log.d(Constant.TAG, Integer.toString(statusCode));
- mTestClient.get(context, "http://172.16.109.253/login.php", new AsyncHttpResponseHandler() {
- @Override
- public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
- loginYanchao(context, params, loginType, callback);
- }
-
- @Override
- public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable throwable) {
- String resultString, resultDetailString = "Connection problem.";
-
- if (headers != null) {
- resultDetailString = "";
- for (Header header : headers) {
- resultDetailString += header.toString() + "\n";
- }
- }
-
- resultString = context.getString(R.string.failed_to_login);
- mBuilder.setContentTitle(context.getString(R.string.app_name))
- .setContentText(resultString).setSmallIcon(R.drawable.ic_stat_login)
- .setContentIntent(getDefaultPendingIntent(context))
- .setAutoCancel(true)
- .setVibrate(new long[]{300, 200, 300, 200})
- .setLights(Color.RED, 800, 800)
- .setProgress(0, 0, false);
-
- if (callback != null) {
- callback.onFail(resultString + "\n" + resultDetailString);
- }
- // Show error details in the expanded notification
- mBuilder.setStyle(new NotificationCompat.BigTextStyle()
- .bigText(resultString + "\n" + resultDetailString));
-
- mNotificationManager
- .notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
-
- tracker.send(new HitBuilders.EventBuilder()
- .setCategory("UX")
- .setAction("onFailure")
- .setLabel("Double Check Error")
- .build());
- }
- });
- }
- });
+ mNotificationManager.notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
+
+ String _IP = getIPAddress(context);
+ if (_IP.split("\\.")[0].equals("172"))
+ if (_IP.split("\\.")[1].equals("17"))
+ loginJiangong(context, params, loginType, callback);
+ else
+ loginYanchaoDorm(context, params, loginType, callback);
+ else
+ loginYanchao(context, params, loginType, callback);
}
});
}
private static void loginJiangong(final Context context, final RequestParams params, final String loginType, final GeneralCallback callback)
{
+ Log.d(Constant.TAG, "loginJiangong");
+
mClient.post(context, "http://172.16.61.253/cgi-bin/ace_web_auth.cgi", params,
new AsyncHttpResponseHandler() {
@@ -295,8 +206,8 @@ public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
- e.printStackTrace();
- loginYanchao(context, params, loginType, callback);
+ e.printStackTrace();
+ loginYanchao(context, params, loginType, callback);
tracker.send(new HitBuilders.EventBuilder()
.setCategory("UX")
@@ -307,8 +218,10 @@ public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Th
});
}
- private static void loginYanchao(final Context context, RequestParams params, final String loginType, final GeneralCallback callback)
+ private static void loginYanchaoDorm(final Context context, RequestParams params, final String loginType, final GeneralCallback callback)
{
+ Log.d(Constant.TAG, "loginYanchaoDorm");
+
mClient.post(context, "http://172.16.109.253/cgi-bin/ace_web_auth.cgi", params,
new AsyncHttpResponseHandler() {
@@ -350,7 +263,7 @@ else if (loginType.equals("Cyber"))
tracker.send(new HitBuilders.EventBuilder()
.setCategory("UX")
.setAction("onSuccess")
- .setLabel("燕巢/" + loginType)
+ .setLabel("燕巢宿舍/" + loginType)
.build());
}
@@ -388,7 +301,7 @@ public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable
tracker.send(new HitBuilders.EventBuilder()
.setCategory("UX")
.setAction("onFailure")
- .setLabel("燕巢/" + loginType)
+ .setLabel("燕巢宿舍/" + loginType)
.build());
}
});
@@ -399,14 +312,14 @@ public void onFailure(int statusCode, Header[] headers, byte[] errorResponse,
Throwable e) {
e.printStackTrace();
- String resultString, resultDetailString = "Connection problem.";
+ String resultString, resultDetailString = "";
- if (headers != null) {
+ /*if (headers != null) {
resultDetailString = "";
for (Header header : headers) {
resultDetailString += header.toString() + "\n";
}
- }
+ }*/
resultString = context.getString(R.string.failed_to_login);
mBuilder.setContentTitle(context.getString(R.string.app_name))
@@ -430,12 +343,115 @@ public void onFailure(int statusCode, Header[] headers, byte[] errorResponse,
tracker.send(new HitBuilders.EventBuilder()
.setCategory("UX")
.setAction("onFailure")
- .setLabel("燕巢/" + loginType)
+ .setLabel("燕巢宿舍/" + loginType)
.build());
}
});
}
+ private static void loginYanchao(final Context context, final RequestParams params, final String loginType, final GeneralCallback callback)
+ {
+ Log.d(Constant.TAG, "loginYanchao");
+
+ mClient.post(context, "http://74.125.203.101/cgi-bin/ace_web_auth.cgi", params,
+ new AsyncHttpResponseHandler() {
+
+ @Override
+ public void onSuccess(int statusCode, Header[] headers, final byte[] response) {
+
+ mTestClient.get(context, "http://www.example.com", new AsyncHttpResponseHandler() {
+ @Override
+ public void onSuccess(int statusCode, Header[] headers, byte[] bytes) {
+ String resultString;
+ if (statusCode == 200) {
+ if (loginType.equals("Student"))
+ resultString = context.getString(R.string.login_successfully);
+ else if (loginType.equals("Cyber"))
+ resultString = context.getString(R.string.login_cyber_successfully);
+ else
+ resultString = context.getString(R.string.login_guest_successfully);
+ if (callback != null) {
+ callback.onSuccess(resultString);
+ }
+ } else {
+ resultString = "Status: " + statusCode;
+ if (callback != null) {
+ callback.onFail(resultString);
+ }
+ }
+
+ mBuilder.setContentTitle(context.getString(R.string.app_name))
+ .setContentText(resultString).setSmallIcon(R.drawable.ic_stat_login)
+ .setContentIntent(getDefaultPendingIntent(context))
+ .setAutoCancel(true)
+ .setVibrate(new long[]{300, 200, 300, 200})
+ .setLights(Color.GREEN, 800, 800)
+ .setDefaults(Notification.DEFAULT_SOUND)
+ .setProgress(0, 0, false);
+ mNotificationManager
+ .notify(Constant.NOTIFICATION_LOGIN_ID, mBuilder.build());
+
+ tracker.send(new HitBuilders.EventBuilder()
+ .setCategory("UX")
+ .setAction("onSuccess")
+ .setLabel("燕巢/" + loginType)
+ .build());
+ }
+
+ @Override
+ public void onFailure(int statusCode, Header[] headers, byte[] bytes, Throwable e) {
+ e.printStackTrace();
+ loginYanchaoDorm(context, params, loginType, callback);
+
+ tracker.send(new HitBuilders.EventBuilder()
+ .setCategory("UX")
+ .setAction("onFailure")
+ .setLabel("燕巢/" + loginType)
+ .build());
+ }
+ });
+ }
+
+ @Override
+ public void onFailure(int statusCode, Header[] headers, byte[] errorResponse,
+ Throwable e) {
+ e.printStackTrace();
+ loginYanchaoDorm(context, params, loginType, callback);
+
+ tracker.send(new HitBuilders.EventBuilder()
+ .setCategory("UX")
+ .setAction("onFailure")
+ .setLabel("燕巢/" + loginType)
+ .build());
+ }
+ });
+ }
+
+ public static String getIPAddress(Context context) {
+ WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ WifiInfo wifiInf = wifiMan.getConnectionInfo();
+ long ip = wifiInf.getIpAddress();
+ if( ip != 0 )
+ return String.format( "%d.%d.%d.%d",
+ (ip & 0xff),
+ (ip >> 8 & 0xff),
+ (ip >> 16 & 0xff),
+ (ip >> 24 & 0xff));
+ try {
+ for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
+ NetworkInterface intf = en.nextElement();
+ for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
+ InetAddress inetAddress = enumIpAddr.nextElement();
+ if (!inetAddress.isLoopbackAddress()) {
+ return inetAddress.getHostAddress().toString();
+ }
+ }
+ }
+ } catch (Exception e) {
+ }
+ return "0.0.0.0";
+ }
+
private static PendingIntent getDefaultPendingIntent(Context context) {
return PendingIntent.getActivity(context, 0, new Intent(), 0);
}
diff --git a/README.md b/README.md
index ec4c06b..8dc0b2c 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ KUAS Wifi Auto Login
## 已完成功能:
- Wifi Auto Login
- Wifi Auto Login (Backgroud)
-- GPS定位校區 (目前改用IP判斷)
+- GPS定位校區 (目前改用IP網段判斷)
## TODO-List:
- TANetRoaming支援