Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit of uf wifi autologin app

  • Loading branch information...
commit 0ab873b91bb7e7a0a781db0c1aff9d0827f22909 0 parents
Forrest Voight authored
3  .gitignore
... ... @@ -0,0 +1,3 @@
  1 +/build.xml
  2 +/local.properties
  3 +*~
22 AndroidManifest.xml
... ... @@ -0,0 +1,22 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 + package="st.forre.ufw_login"
  4 + android:versionCode="1"
  5 + android:versionName="1.0">
  6 + <uses-feature android:name="android.hardware.wifi" />
  7 + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  8 + <uses-permission android:name="android.permission.INTERNET" />
  9 + <application android:label="@string/app_name" >
  10 + <activity android:name="ufw_login"
  11 + android:label="@string/app_name">
  12 + <intent-filter>
  13 + <action android:name="android.intent.action.MAIN" />
  14 + <category android:name="android.intent.category.LAUNCHER" />
  15 + </intent-filter>
  16 + </activity>
  17 + <activity android:name="ufw_login$Preferences"
  18 + android:label="ufw_login preferences"/>
  19 + <service android:name="ufw_login$WatchService" android:label="ufw_login daemon">
  20 + </service>
  21 + </application>
  22 +</manifest>
17 ant.properties
... ... @@ -0,0 +1,17 @@
  1 +# This file is used to override default values used by the Ant build system.
  2 +#
  3 +# This file must be checked in Version Control Systems, as it is
  4 +# integral to the build system of your project.
  5 +
  6 +# This file is only used by the Ant script.
  7 +
  8 +# You can use this to override default values such as
  9 +# 'source.dir' for the location of your java source folder and
  10 +# 'out.dir' for the location of your output folder.
  11 +
  12 +# You can also use it define how the release builds are signed by declaring
  13 +# the following properties:
  14 +# 'key.store' for the location of your keystore and
  15 +# 'key.alias' for the name of the key to use.
  16 +# The password will be asked during the build when you use the 'release' target.
  17 +
40 proguard.cfg
... ... @@ -0,0 +1,40 @@
  1 +-optimizationpasses 5
  2 +-dontusemixedcaseclassnames
  3 +-dontskipnonpubliclibraryclasses
  4 +-dontpreverify
  5 +-verbose
  6 +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
  7 +
  8 +-keep public class * extends android.app.Activity
  9 +-keep public class * extends android.app.Application
  10 +-keep public class * extends android.app.Service
  11 +-keep public class * extends android.content.BroadcastReceiver
  12 +-keep public class * extends android.content.ContentProvider
  13 +-keep public class * extends android.app.backup.BackupAgentHelper
  14 +-keep public class * extends android.preference.Preference
  15 +-keep public class com.android.vending.licensing.ILicensingService
  16 +
  17 +-keepclasseswithmembernames class * {
  18 + native <methods>;
  19 +}
  20 +
  21 +-keepclasseswithmembers class * {
  22 + public <init>(android.content.Context, android.util.AttributeSet);
  23 +}
  24 +
  25 +-keepclasseswithmembers class * {
  26 + public <init>(android.content.Context, android.util.AttributeSet, int);
  27 +}
  28 +
  29 +-keepclassmembers class * extends android.app.Activity {
  30 + public void *(android.view.View);
  31 +}
  32 +
  33 +-keepclassmembers enum * {
  34 + public static **[] values();
  35 + public static ** valueOf(java.lang.String);
  36 +}
  37 +
  38 +-keep class * implements android.os.Parcelable {
  39 + public static final android.os.Parcelable$Creator *;
  40 +}
11 project.properties
... ... @@ -0,0 +1,11 @@
  1 +# This file is automatically generated by Android Tools.
  2 +# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
  3 +#
  4 +# This file must be checked in Version Control Systems.
  5 +#
  6 +# To customize properties used by the Ant build system use,
  7 +# "ant.properties", and override values to adapt the script to your
  8 +# project structure.
  9 +
  10 +# Project target.
  11 +target=android-10
20 res/layout/main.xml
... ... @@ -0,0 +1,20 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<ScrollView
  3 + xmlns:android="http://schemas.android.com/apk/res/android"
  4 + android:id="@+id/scroll"
  5 + android:layout_width="fill_parent"
  6 + android:layout_height="wrap_content">
  7 + <LinearLayout
  8 + android:orientation="vertical"
  9 + android:layout_width="fill_parent"
  10 + android:layout_height="fill_parent"
  11 + android:gravity="fill"
  12 + >
  13 + <TextView
  14 + android:id="@+id/text"
  15 + android:layout_width="match_parent"
  16 + android:layout_height="wrap_content"
  17 + android:text="hello world"
  18 + />
  19 + </LinearLayout>
  20 +</ScrollView>
4 res/values/strings.xml
... ... @@ -0,0 +1,4 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <string name="app_name">ufw_login</string>
  4 +</resources>
34 res/xml/preferences.xml
... ... @@ -0,0 +1,34 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +
  3 +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
  4 + <PreferenceCategory
  5 + android:title="GatorLink login"
  6 + android:key="first_category">
  7 +
  8 + <EditTextPreference
  9 + android:key="username"
  10 + android:title="Username"
  11 + android:summary="Gatorlink username"
  12 + android:dialogTitle="Gatorlink username"
  13 + android:dialogMessage="Provide your username" />
  14 +
  15 + <EditTextPreference
  16 + android:key="password"
  17 + android:title="Password"
  18 + android:summary="Gatorlink password"
  19 + android:dialogTitle="Gatorlink password"
  20 + android:dialogMessage="Provide your password"
  21 + android:inputType="textPassword" />
  22 + </PreferenceCategory>
  23 +
  24 + <PreferenceCategory
  25 + android:title="Options"
  26 + android:key="second_category">
  27 +
  28 + <CheckBoxPreference
  29 + android:key="display_notification"
  30 + android:summary="Display an icon in the notification area. If disabled, this program may be terminated in low-memory conditions."
  31 + android:title="Display notification icon"
  32 + android:defaultValue="true" />
  33 + </PreferenceCategory>
  34 +</PreferenceScreen>
246 src/st/forre/ufw_login/ufw_login.java
... ... @@ -0,0 +1,246 @@
  1 +package st.forre.ufw_login;
  2 +
  3 +import java.io.IOException;
  4 +import java.io.UnsupportedEncodingException;
  5 +import java.util.List;
  6 +import java.util.ArrayList;
  7 +
  8 +import android.app.Activity;
  9 +import android.app.Service;
  10 +import android.content.ComponentName;
  11 +import android.content.Intent;
  12 +import android.content.ServiceConnection;
  13 +import android.net.wifi.WifiInfo;
  14 +import android.net.wifi.WifiManager;
  15 +import android.os.AsyncTask;
  16 +import android.os.Binder;
  17 +import android.os.Bundle;
  18 +import android.os.Handler;
  19 +import android.os.IBinder;
  20 +import android.os.Message;
  21 +import android.widget.TextView;
  22 +import org.apache.http.HttpResponse;
  23 +import org.apache.http.NameValuePair;
  24 +import org.apache.http.client.entity.UrlEncodedFormEntity;
  25 +import org.apache.http.client.methods.HttpPost;
  26 +import org.apache.http.impl.client.DefaultHttpClient;
  27 +import org.apache.http.message.BasicNameValuePair;
  28 +
  29 +import android.content.SharedPreferences;
  30 +import android.text.format.Formatter;
  31 +import java.lang.StringBuilder;
  32 +import java.io.BufferedReader;
  33 +import java.io.InputStreamReader;
  34 +import java.io.InputStream;
  35 +import java.net.URI;
  36 +import android.preference.PreferenceActivity;
  37 +import android.view.Menu;
  38 +import android.view.MenuItem;
  39 +import android.preference.PreferenceManager;
  40 +
  41 +public class ufw_login extends Activity
  42 +{
  43 + public static class Preferences extends PreferenceActivity {
  44 + @Override
  45 + protected void onCreate(Bundle savedInstanceState) {
  46 + super.onCreate(savedInstanceState);
  47 + addPreferencesFromResource(R.xml.preferences);
  48 + }
  49 + }
  50 +
  51 + public static String slurp(final InputStream file) throws IOException {
  52 + StringBuilder result = new StringBuilder();
  53 + BufferedReader reader = new BufferedReader(new InputStreamReader(file));
  54 + try {
  55 + char[] buf = new char[1024];
  56 + int r = 0;
  57 + while ((r = reader.read(buf)) != -1) {
  58 + result.append(buf, 0, r);
  59 + }
  60 + }
  61 + finally {
  62 + reader.close();
  63 + }
  64 + return result.toString();
  65 + }
  66 +
  67 + public static class WatchService extends Service {
  68 + private final IBinder mBinder = new LocalBinder();
  69 +
  70 + private class AuthTask extends AsyncTask<String, Void, String> {
  71 + protected String doInBackground(String... x) {
  72 + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(WatchService.this);
  73 + if(sp.getString("password", "").equals("") || sp.getString("username", "").equals(""))
  74 + return "Username/password not set yet!";
  75 +
  76 + List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  77 + nameValuePairs.add(new BasicNameValuePair("compact", "true"));
  78 + nameValuePairs.add(new BasicNameValuePair("index", "0"));
  79 + nameValuePairs.add(new BasicNameValuePair("password", sp.getString("password", "")));
  80 + nameValuePairs.add(new BasicNameValuePair("pageid", "-1"));
  81 + nameValuePairs.add(new BasicNameValuePair("passwordLabel", "Password"));
  82 + nameValuePairs.add(new BasicNameValuePair("cm", "ws32vklm"));
  83 + nameValuePairs.add(new BasicNameValuePair("registerGuest", "NO"));
  84 + nameValuePairs.add(new BasicNameValuePair("username", sp.getString("username", "")));
  85 + nameValuePairs.add(new BasicNameValuePair("uri", "http://www.google.com/search?client=ubuntu"));
  86 + nameValuePairs.add(new BasicNameValuePair("reqFrom", "perfigo_frame_login.jsp"));
  87 + nameValuePairs.add(new BasicNameValuePair("guestUserNameLabel", "Guest ID"));
  88 + nameValuePairs.add(new BasicNameValuePair("provider", "Radius"));
  89 + nameValuePairs.add(new BasicNameValuePair("userip", x[1]));
  90 + nameValuePairs.add(new BasicNameValuePair("guestPasswordLabel", "Password"));
  91 + nameValuePairs.add(new BasicNameValuePair("userNameLabel", "Username:"));
  92 + nameValuePairs.add(new BasicNameValuePair("pm", "Linux x86_64"));
  93 +
  94 + HttpPost hp = new HttpPost(x[0]);
  95 + try {
  96 + hp.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  97 + } catch(UnsupportedEncodingException e) {
  98 + return "UnsupportedEncodingException happened: " + e.getMessage();
  99 + }
  100 +
  101 + DefaultHttpClient c = new DefaultHttpClient();
  102 + HttpResponse r;
  103 + try {
  104 + r = c.execute(hp);
  105 + } catch(IOException e) {
  106 + return "IOException happened: " + e.getMessage();
  107 + }
  108 + try {
  109 + return slurp(r.getEntity().getContent());
  110 + } catch(IOException e) {
  111 + return "IOException error: " + e.getMessage();
  112 + }
  113 + }
  114 +
  115 + protected void onPostExecute(String result) {
  116 + WatchService.this.status += "\n\n" + result;
  117 + }
  118 + }
  119 +
  120 + private boolean on_wifi_before = false;
  121 + private String status = "just started";
  122 + private RefreshHandler2 mRedrawHandler2 = new RefreshHandler2();
  123 + class RefreshHandler2 extends Handler {
  124 + @Override
  125 + public void handleMessage(Message msg) {
  126 + this.removeMessages(0);
  127 +
  128 + WifiInfo wi = ((WifiManager)getSystemService(WIFI_SERVICE)).getConnectionInfo();
  129 + boolean on_wifi_now = wi != null && wi.getSSID() != null && wi.getSSID().equals("ufw");
  130 + if(on_wifi_now && !on_wifi_before) {
  131 + status = "On \"ufw\". Attempting authentication...";
  132 + String ip = Formatter.formatIpAddress(wi.getIpAddress());
  133 + (new WatchService.AuthTask()).execute("https://nac-serv-1.ns.ufl.edu/auth/perfigo_cm_validate.jsp", ip);
  134 + (new WatchService.AuthTask()).execute("https://nac-serv-2.ns.ufl.edu/auth/perfigo_cm_validate.jsp", ip);
  135 + (new WatchService.AuthTask()).execute("https://nac-serv-3.ns.ufl.edu/auth/perfigo_cm_validate.jsp", ip);
  136 + (new WatchService.AuthTask()).execute("https://nac-serv-4.ns.ufl.edu/auth/perfigo_cm_validate.jsp", ip);
  137 + } else if(!on_wifi_now) {
  138 + status = "Not on \"ufw\".";
  139 + }
  140 + on_wifi_before = on_wifi_now;
  141 +
  142 + sendMessageDelayed(obtainMessage(0), 1000);
  143 + }
  144 + };
  145 +
  146 + @Override
  147 + public int onStartCommand(Intent intent, int flags, int startId) {
  148 + mRedrawHandler2.handleMessage(null);
  149 + return START_STICKY;
  150 + }
  151 +
  152 + @Override
  153 + public IBinder onBind(Intent intent) {
  154 + return mBinder;
  155 + }
  156 +
  157 + public class LocalBinder extends Binder {
  158 + String getStatus() {
  159 + WifiInfo wi = ((WifiManager)getSystemService(WIFI_SERVICE)).getConnectionInfo();
  160 + return "SSID: " + wi.getSSID() + "\nRSSI: " + wi.getRssi() + "\nStatus: " + status;
  161 + }
  162 + }
  163 + }
  164 +
  165 + private RefreshHandler mRedrawHandler = new RefreshHandler();
  166 +
  167 + class RefreshHandler extends Handler {
  168 + @Override
  169 + public void handleMessage(Message msg) {
  170 + this.removeMessages(0);
  171 + if(!running)
  172 + return;
  173 + if(mService == null)
  174 + ((TextView)ufw_login.this.findViewById(R.id.text)).setText("service not connected?");
  175 + else
  176 + ((TextView)ufw_login.this.findViewById(R.id.text)).setText(mService.getStatus());
  177 + sendMessageDelayed(obtainMessage(0), 100);
  178 + }
  179 + };
  180 +
  181 +
  182 + @Override
  183 + public void onCreate(Bundle savedInstanceState)
  184 + {
  185 + super.onCreate(savedInstanceState);
  186 + setContentView(R.layout.main);
  187 + }
  188 +
  189 + @Override
  190 + public boolean onCreateOptionsMenu(Menu menu) {
  191 + menu.add(Menu.NONE, 0, 0, "Preferences");
  192 + return super.onCreateOptionsMenu(menu);
  193 + }
  194 +
  195 + @Override
  196 + public boolean onOptionsItemSelected(MenuItem item) {
  197 + switch (item.getItemId()) {
  198 + case 0:
  199 + startActivity(new Intent(this, Preferences.class));
  200 + return true;
  201 + }
  202 + return false;
  203 + }
  204 +
  205 + private boolean running = false;
  206 +
  207 + @Override
  208 + protected void onStart() {
  209 + super.onStart();
  210 +
  211 + startService(new Intent(ufw_login.this, WatchService.class));
  212 + bindService(new Intent(this, WatchService.class), mConnection, BIND_AUTO_CREATE);
  213 +
  214 + running = true;
  215 +
  216 + mRedrawHandler.handleMessage(null);
  217 +
  218 + /*Editor e = getSharedPreferences("login", Context.MODE_PRIVATE).edit();
  219 + e.putString("password", mPassword);
  220 + e.commit();*/
  221 + }
  222 +
  223 + @Override
  224 + protected void onStop() {
  225 + super.onStop();
  226 +
  227 + running = false;
  228 +
  229 + if (mConnection != null)
  230 + unbindService(mConnection);
  231 + }
  232 +
  233 +
  234 + WatchService.LocalBinder mService = null;
  235 + private ServiceConnection mConnection = new ServiceConnection() {
  236 + @Override
  237 + public void onServiceConnected(ComponentName className, IBinder service) {
  238 + mService = (WatchService.LocalBinder)service;
  239 + }
  240 +
  241 + @Override
  242 + public void onServiceDisconnected(ComponentName arg0) {
  243 + mService = null;
  244 + }
  245 + };
  246 +}

0 comments on commit 0ab873b

Please sign in to comment.
Something went wrong with that request. Please try again.