Skip to content

Commit

Permalink
Overcome the last bugs and finally send a knock
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-bennett committed Jun 1, 2015
1 parent e276dba commit 5287998
Show file tree
Hide file tree
Showing 64 changed files with 14,130 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni/libfko" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
Expand All @@ -69,7 +70,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/19.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
Expand All @@ -84,17 +85,14 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="commons-beanutils-1.8.3" level="project" />
<orderEntry type="library" exported="" name="commons-validator-1.4.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-19.0.0" level="project" />
<orderEntry type="library" exported="" name="commons-digester-1.8.1" level="project" />
</component>
</module>
17 changes: 14 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
compileSdkVersion 19
buildToolsVersion "22.0.1"
sourceSets.main {
jni.srcDirs = ['src/main/jni',
'src/main/jni/libfko'
]
}
lintOptions {
abortOnError false
}
Expand All @@ -23,9 +28,15 @@ android {
defaultConfig {
applicationId "biz.incomsystems.fwknop2"
minSdkVersion 15
targetSdkVersion 22
targetSdkVersion 19
versionCode 1
versionName "1.0"
ndk {
moduleName 'libfwknop'
ldLibs 'log'
cFlags '-DHAVE_CONFIG_H'
}

}
buildTypes {
release {
Expand All @@ -37,7 +48,7 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.android.support:support-v4:22.1.1'
compile('commons-validator:commons-validator:1.4.1') {
exclude group: 'commons-collections', module: 'commons-collections'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="biz.incomsystems.fwknop2" >
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand Down
115 changes: 95 additions & 20 deletions app/src/main/java/biz/incomsystems/fwknop2/ConfigDetailFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Base64;
import android.util.Base64DataException;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -37,7 +40,8 @@
*/
public class ConfigDetailFragment extends Fragment {
DBHelper mydb ;

private String output;
public native String sendSPAPacket();
TextView txt_NickName ; // objects representing the config options
Spinner spn_allowip ;
TextView txt_allowIP ;
Expand Down Expand Up @@ -178,28 +182,28 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
String contents = data.getStringExtra("SCAN_RESULT");
for (String stanzas: contents.split(" ")){
String[] tmp = stanzas.split(":");
switch (tmp[0]) {
if (tmp[0].equalsIgnoreCase("KEY_BASE64")) {

case "KEY_BASE64":
//case "KEY_BASE64":

txt_KEY.setText(tmp[1]);
chkb64key.setChecked(true);
break;
txt_KEY.setText(tmp[1]);
chkb64key.setChecked(true);
// break;

case "KEY":
txt_KEY.setText(tmp[1]);
chkb64key.setChecked(false);
break;
} else if (tmp[0].equalsIgnoreCase("KEY")) {
txt_KEY.setText(tmp[1]);
chkb64key.setChecked(false);
// break;

case "HMAC_KEY_BASE64":
txt_HMAC.setText(tmp[1]);
chkb64hmac.setChecked(true);
break;
} else if (tmp[0].equalsIgnoreCase("HMAC_KEY_BASE64")) {
txt_HMAC.setText(tmp[1]);
chkb64hmac.setChecked(true);
// break;

case "HMAC_KEY":
} else if (tmp[0].equalsIgnoreCase( "HMAC_KEY")) {
txt_HMAC.setText(tmp[1]);
chkb64hmac.setChecked(false);
break;
// break;

} // end switch
}// end for loop
Expand Down Expand Up @@ -241,8 +245,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
chkb64hmac = (CheckBox) rootView.findViewById(R.id.chkb64hmac);
chkb64key = (CheckBox) rootView.findViewById(R.id.chkb64key);

//lay_allowIP.setVisibility(LinearLayout.VISIBLE);

spn_allowip = (Spinner) rootView.findViewById(R.id.allowip);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.spinner_options, android.R.layout.simple_spinner_item);
Expand Down Expand Up @@ -301,4 +303,77 @@ public void onNothingSelected(AdapterView<?> parent) {
}
return rootView;
}

public void sendSPA() {
startSPASend();
}

// Start calling the JNI interface
public synchronized void startSPASend() {
output = sendSPAPacket();
//sendHandlerMessage(handler, 1003);
// if (startApp) {
// startApp();
// }
}

public int send(String nick){
loadNativeLib("libfwknop.so", "/data/data/biz.incomsystems.fwknop2/lib");
//mydb = new DBHelper(Fwknop2.getContext());
Cursor CurrentIndex = mydb.getData(nick);
CurrentIndex.moveToFirst();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor edit = prefs.edit();
edit.putString("tcpAccessPorts_str", CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_TCP_PORTS)));
edit.putString("access_str", ",tcp/" + CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_TCP_PORTS)));
edit.putString("allowip_str", "0.0.0.0");
edit.putString("passwd_str", CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_KEY)));
edit.putString("hmac_str", "");
edit.putString("destip_str", CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_IP)));
edit.putString("destport_str", CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_PORT)));
edit.putString("fw_timeout_str", CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_TIMEOUT)));
edit.commit();
this.sendSPA();
return 0;
}

private void loadNativeLib(String lib, String destDir) {
if (true) {
String libLocation = destDir + "/" + lib;
try {
System.load(libLocation);
} catch (Exception ex) {
Log.e("JNIExample", "failed to load native library: " + ex);
}
}

}

public Handler handler = new Handler() {

@Override
public synchronized void handleMessage(Message msg) {
Bundle b = msg.getData();
Integer messageType = (Integer) b.get("message_type");

Toast.makeText(getActivity(),messageType.toString(), Toast.LENGTH_LONG).show();
// if (messageType != null && messageType == IPS_RESOLVED) {
// progDialog.dismiss();
// } else if (messageType != null && messageType == EXTIP_NOTRESOLVED) {
// progDialog.dismiss();
// UIAlert("Error", "Could not resolve your external IP. This means that "
// + "you're not connected to the internet or ifconfig.me "
// + "is not be accesible right now", activity);
// } else if (messageType != null && messageType == LOCALIP_NOTRESOLVED) {
// progDialog.dismiss();
// UIAlert("Error", "Could not find any IP, makes sure you have an internet connection", activity);
// } else if (messageType != null && messageType == SPA_SENT) {
// Toast.makeText(activity, output, Toast.LENGTH_LONG).show();
// }

}
};


}

94 changes: 94 additions & 0 deletions app/src/main/java/biz/incomsystems/fwknop2/ConfigListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
Expand All @@ -12,6 +18,7 @@
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

Expand All @@ -30,6 +37,18 @@ public class ConfigListFragment extends ListFragment {
public ArrayAdapter customAdapter;
ArrayList array_list = new ArrayList();
DBHelper mydb;
private String output;

//These are the configs to pass to the native code
public native String sendSPAPacket();
public String access_str;
public String allowip_str;
public String tcpAccessPorts_str;
public String passwd_str;
public String hmac_str;
public String destip_str;
public String destport_str;
public String fw_timeout_str;

/**
* The serialization (saved instance state) Bundle key representing the
Expand Down Expand Up @@ -145,6 +164,9 @@ public boolean onContextItemSelected(MenuItem item) {
customAdapter.notifyDataSetChanged();
return true;

case R.id.knock:
send(((TextView) info.targetView).getText().toString());

default:
return super.onContextItemSelected(item);
}
Expand Down Expand Up @@ -210,4 +232,76 @@ private void setActivatedPosition(int position) {

mActivatedPosition = position;
}

public void sendSPA() {
startSPASend();
}

// Start calling the JNI interface
public synchronized void startSPASend() {
output = sendSPAPacket();
//sendHandlerMessage(handler, 1003);
// if (startApp) {
// startApp();
// }
}

public int send(String nick){
loadNativeLib("libfwknop.so", "/data/data/biz.incomsystems.fwknop2/lib");
//mydb = new DBHelper(Fwknop2.getContext());
Cursor CurrentIndex = mydb.getData(nick);
CurrentIndex.moveToFirst();
//SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
// SharedPreferences.Editor edit = prefs.edit();
tcpAccessPorts_str = CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_TCP_PORTS));
// edit.putString("access_str", ",tcp/" + CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_TCP_PORTS)));
access_str="tcp/" + CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_TCP_PORTS));
allowip_str = "0.0.0.0";
passwd_str = CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_KEY));
hmac_str = "";
destip_str = CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_IP));
destport_str = CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_PORT));
fw_timeout_str = CurrentIndex.getString(CurrentIndex.getColumnIndex(DBHelper.CONFIGS_COLUMN_SERVER_TIMEOUT));
// edit.commit();
this.sendSPA();
return 0;
}

private void loadNativeLib(String lib, String destDir) {
if (true) {
String libLocation = destDir + "/" + lib;
try {
System.load(libLocation);
} catch (Exception ex) {
Log.e("JNIExample", "failed to load native library: " + ex);
}
}

}

public Handler handler = new Handler() {

@Override
public synchronized void handleMessage(Message msg) {
Bundle b = msg.getData();
Integer messageType = (Integer) b.get("message_type");

Toast.makeText(getActivity(), messageType.toString(), Toast.LENGTH_LONG).show();
// if (messageType != null && messageType == IPS_RESOLVED) {
// progDialog.dismiss();
// } else if (messageType != null && messageType == EXTIP_NOTRESOLVED) {
// progDialog.dismiss();
// UIAlert("Error", "Could not resolve your external IP. This means that "
// + "you're not connected to the internet or ifconfig.me "
// + "is not be accesible right now", activity);
// } else if (messageType != null && messageType == LOCALIP_NOTRESOLVED) {
// progDialog.dismiss();
// UIAlert("Error", "Could not find any IP, makes sure you have an internet connection", activity);
// } else if (messageType != null && messageType == SPA_SENT) {
// Toast.makeText(activity, output, Toast.LENGTH_LONG).show();
// }

}
};

}
Loading

0 comments on commit 5287998

Please sign in to comment.