setup config file

This commit is contained in:
Juan Ezquerro LLanes 2016-11-17 13:42:50 +01:00
parent d1c117adb4
commit ff47ccd340
2 changed files with 46 additions and 41 deletions

View File

@ -595,12 +595,12 @@ public class OrbotMainActivity extends AppCompatActivity
if(row == null) { if(row == null) {
cr.insert(HSContentProvider.CONTENT_URI, fields); cr.insert(HSContentProvider.CONTENT_URI, fields);
} else { } else {
onionHostname = row.getString(row.getColumnIndex(HSContentProvider.HiddenService.NAME)); onionHostname = row.getString(row.getColumnIndex(HSContentProvider.HiddenService.DOMAIN));
cr.update(HSContentProvider.CONTENT_URI, fields, "port=" + mHsPort, null); cr.update(HSContentProvider.CONTENT_URI, fields, "port=" + mHsPort, null);
row.close(); row.close();
} }
if(onionHostname == null) { if(onionHostname == null || onionHostname.length() < 1) {
requestTorRereadConfig(); requestTorRereadConfig();

View File

@ -16,6 +16,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.ContextWrapper; import android.content.ContextWrapper;
import android.content.Intent; import android.content.Intent;
@ -23,12 +24,15 @@ import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.BaseColumns;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils; import android.text.TextUtils;
@ -128,6 +132,26 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private Shell mShell; private Shell mShell;
private Shell mShellPolipo; private Shell mShellPolipo;
private static final Uri CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hs.providers/hs");
public static final class HiddenService implements BaseColumns {
//Nombres de columnas
public static final String NAME = "name";
public static final String PORT = "port";
public static final String ONION_PORT = "onion_port";
public static final String DOMAIN = "domain";
private HiddenService() {
}
}
private String[] mProjection = new String[]{
HiddenService._ID,
HiddenService.NAME,
HiddenService.DOMAIN,
HiddenService.PORT,
HiddenService.ONION_PORT};
public void debug(String msg) public void debug(String msg)
{ {
if (Prefs.useDebugLogging()) if (Prefs.useDebugLogging())
@ -1778,48 +1802,29 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
return false; return false;
} }
if (enableHiddenServices) /* ---- Hidden Services ---- */
{ ContentResolver mCR = getApplicationContext().getContentResolver();
logNotice("hidden services are enabled"); Cursor hidden_services = mCR.query(CONTENT_URI, mProjection, null, null, null);
if(hidden_services != null) {
try {
while (hidden_services.moveToNext()) {
Integer HSLocalPort = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.PORT));
Integer HSOnionPort = hidden_services.getInt(hidden_services.getColumnIndex(HiddenService.ONION_PORT));
String hsDirPath = new File(appCacheHome,"hs" + HSLocalPort).getCanonicalPath();
//updateConfiguration("RendPostPeriod", "600 seconds", false); //possible feature to investigate debug("Adding hidden service on port: " + HSLocalPort);
String hsPorts = prefs.getString("pref_hs_ports","");
StringTokenizer st = new StringTokenizer (hsPorts,",");
String hsPortConfig = null;
int hsPort = -1;
while (st.hasMoreTokens())
{
try
{
hsPortConfig = st.nextToken().trim();
if (hsPortConfig.indexOf(":")==-1) //setup the port to localhost if not specifed
{
hsPortConfig = hsPortConfig + " 127.0.0.1:" + hsPortConfig;
}
hsPort = Integer.parseInt(hsPortConfig.split(" ")[0]);
String hsDirPath = new File(appCacheHome,"hs" + hsPort).getCanonicalPath();
debug("Adding hidden service on port: " + hsPortConfig);
extraLines.append("HiddenServiceDir" + ' ' + hsDirPath).append('\n'); extraLines.append("HiddenServiceDir" + ' ' + hsDirPath).append('\n');
extraLines.append("HiddenServicePort" + ' ' + hsPortConfig).append('\n'); extraLines.append("HiddenServicePort" + ' ' + HSOnionPort + " 127.0.0.1:" + HSLocalPort).append('\n');
} catch (NumberFormatException e) {
Log.e(OrbotConstants.TAG,"error parsing hsport",e);
} catch (Exception e) {
Log.e(OrbotConstants.TAG,"error starting share server",e);
} }
} catch (NumberFormatException e) {
Log.e(OrbotConstants.TAG,"error parsing hsport",e);
} catch (Exception e) {
Log.e(OrbotConstants.TAG,"error starting share server",e);
} }
hidden_services.close();
} }
return true; return true;
} }