<commit_before>package com.be55.android.ferecauth;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.preference.PreferenceManager;

public class FerecAuthManager {
	Context context;
	SharedPreferences sharedPreferences;

	public FerecAuthManager(Context contextArg) {
		context = contextArg;
	}

	public boolean isTargetNetwork() {
		sharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(context.getApplicationContext());

		String ssid = sharedPreferences.getString("auth_ssid", "");

		if (this.getSSID().equals(ssid)) {
			return true;
		}

		return false;
	}

	public boolean needAuth() {
		if (this.testConnection()) {
			return false;
		}

		return true;
	}

	public void doAuth() {
		sharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(context.getApplicationContext());

		String authUri = sharedPreferences.getString("auth_uri", "");
		String authUsername = sharedPreferences.getString("auth_username", "");
		String authPassword = sharedPreferences.getString("auth_password", "");
		String authHidden = sharedPreferences.getString("auth_hidden", "");
		
		this.doAuth(authUri, authUsername, authPassword, authHidden);
	}

	public void doAuth(String authUri, String authUsername,
			String authPassword, String authHidden) {
		String postArg = "user=" + authUsername + "&pass=" + authPassword + "&"
				+ authHidden;

		try {
			HttpPost method = new HttpPost(authUri);
			DefaultHttpClient client = new DefaultHttpClient();

			StringEntity paramEntity = new StringEntity(postArg);
			paramEntity.setChunked(false);
			paramEntity.setContentType("application/x-www-form-urlencoded");
			method.setEntity(paramEntity);

			client.execute(method);
		} catch (Exception e) {

		}
	}

	protected String getSSID() {
		WifiManager wifiMan;
		WifiInfo wifiInfo;

		wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		wifiInfo = wifiMan.getConnectionInfo();

		return wifiInfo.getSSID();
	}

	protected boolean testConnection() {

		try {
			String postString = new SimpleDateFormat("yyyyMMddHHmmss")
					.format(new Date());
			HttpGet method = new HttpGet(
					"http://2ndlab.skr.jp/ferecauth/echo.php?s=" + postString);

			DefaultHttpClient client = new DefaultHttpClient();
			method.setHeader("Connection", "Keep-Alive");

			HttpResponse response = client.execute(method);

			String retval = EntityUtils.toString(response.getEntity(), "UTF-8");<commit_msg>Change echo server from sakura to google app engine<commit_after>package com.be55.android.ferecauth;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.preference.PreferenceManager;

public class FerecAuthManager {
	Context context;
	SharedPreferences sharedPreferences;

	public FerecAuthManager(Context contextArg) {
		context = contextArg;
	}

	public boolean isTargetNetwork() {
		sharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(context.getApplicationContext());

		String ssid = sharedPreferences.getString("auth_ssid", "");

		if (this.getSSID().equals(ssid)) {
			return true;
		}

		return false;
	}

	public boolean needAuth() {
		if (this.testConnection()) {
			return false;
		}

		return true;
	}

	public void doAuth() {
		sharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(context.getApplicationContext());

		String authUri = sharedPreferences.getString("auth_uri", "");
		String authUsername = sharedPreferences.getString("auth_username", "");
		String authPassword = sharedPreferences.getString("auth_password", "");
		String authHidden = sharedPreferences.getString("auth_hidden", "");
		
		this.doAuth(authUri, authUsername, authPassword, authHidden);
	}

	public void doAuth(String authUri, String authUsername,
			String authPassword, String authHidden) {
		String postArg = "user=" + authUsername + "&pass=" + authPassword + "&"
				+ authHidden;

		try {
			HttpPost method = new HttpPost(authUri);
			DefaultHttpClient client = new DefaultHttpClient();

			StringEntity paramEntity = new StringEntity(postArg);
			paramEntity.setChunked(false);
			paramEntity.setContentType("application/x-www-form-urlencoded");
			method.setEntity(paramEntity);

			client.execute(method);
		} catch (Exception e) {

		}
	}

	protected String getSSID() {
		WifiManager wifiMan;
		WifiInfo wifiInfo;

		wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		wifiInfo = wifiMan.getConnectionInfo();

		return wifiInfo.getSSID();
	}

	protected boolean testConnection() {

		try {
			String postString = new SimpleDateFormat("yyyyMMddHHmmss")
					.format(new Date());
			HttpGet method = new HttpGet(
					"http://ferecauth.appspot.com/echo?s=" + postString);

			DefaultHttpClient client = new DefaultHttpClient();
			method.setHeader("Connection", "Keep-Alive");

			HttpResponse response = client.execute(method);

			String retval = EntityUtils.toString(response.getEntity(), "UTF-8");
{'fraction_non_alphanumeric': 0.1130766562608394, 'fraction_numerical': 0.0012140131807145335, 'mean_word_length': 5.128586609989373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4259217', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1670, 'n_words': 339}