Skip to content

Commit

Permalink
Added tweaks for configuring the proxy using pac files
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Sep 2, 2011
1 parent 6678619 commit 34b5df0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
4 changes: 3 additions & 1 deletion install/lantern.install4j
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<install4j version="5.0.9" transformSequenceNumber="3">
<directoryPresets config="../lantern_littleproxy_cert" />
<directoryPresets config="../proxy_off.pac" />
<application name="Lantern" distributionSourceDir="" applicationId="3831-6452-7413-7646" mediaDir="." mediaFilePattern="${compiler:sys.shortName}_${compiler:sys.platform}_${compiler:sys.version}" compression="6" lzmaCompression="true" pack200Compression="true" excludeSignedFromPacking="true" commonExternalFiles="false" createMd5Sums="true" shrinkRuntime="true" shortName="lantern" publisher="Brave New Software Project, Inc" publisherWeb="http://www.getlantern.org" version="0.2" allPathsRelative="true" backupOnSave="false" autoSave="true" convertDotsToUnderscores="true" macSignature="????" installerName="" javaMinVersion="1.6" javaMaxVersion="" allowBetaVM="false" jdkMode="runtimeJre" jdkName="">
<languages skipLanguageSelection="false" languageSelectionInPrincipalLanguage="false">
<principalLanguage id="en" customLocalizationFile="" />
Expand Down Expand Up @@ -43,6 +43,8 @@
</dirEntry>
<fileEntry mountPoint="25" file="../whitelist.txt" overwriteMode="4" shared="false" fileMode="644" uninstallMode="0" overrideFileMode="false" overrideOverwriteMode="false" overrideUninstallMode="false" />
<fileEntry mountPoint="25" file="../lantern_littleproxy_cert" overwriteMode="4" shared="false" fileMode="644" uninstallMode="0" overrideFileMode="false" overrideOverwriteMode="false" overrideUninstallMode="false" />
<fileEntry mountPoint="25" file="../proxy_on.pac" overwriteMode="4" shared="false" fileMode="644" uninstallMode="0" overrideFileMode="false" overrideOverwriteMode="false" overrideUninstallMode="false" />
<fileEntry mountPoint="25" file="../proxy_off.pac" overwriteMode="4" shared="false" fileMode="644" uninstallMode="0" overrideFileMode="false" overrideOverwriteMode="false" overrideUninstallMode="false" />
<dirEntry mountPoint="149" file="./win" overwriteMode="4" shared="false" fileMode="644" uninstallMode="0" overrideFileMode="false" overrideOverwriteMode="false" overrideUninstallMode="false" entryMode="direct" subDirectory="win" excludeSuffixes="" dirMode="755" overrideDirMode="false">
<exclude>
<entry location=".svn" fileType="regular" />
Expand Down
47 changes: 42 additions & 5 deletions src/main/java/org/lantern/Configurator.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.lantern;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -30,6 +32,12 @@ public class Configurator {
private static final String LANTERN_PROXY_ADDRESS = "127.0.0.1:"+
LanternConstants.LANTERN_LOCALHOST_HTTP_PORT;

private static final File PROXY_ON = new File("proxy_on.pac");
private static final File PROXY_OFF = new File("proxy_off.pac");

private static final File ACTIVE_PAC =
new File(LanternUtils.configDir(), "proxy.pac");

public static void configure() {
if (configured) {
LOG.error("Configure called twice?");
Expand Down Expand Up @@ -69,8 +77,24 @@ public static void reconfigure() {
LOG.info("Not auto-configuring proxy in an uncensored country");
}
}

private static void configureOsxProxy() {
configureOsxProxyPacFile();
}

/**
* Uses a pack file to manipulate browser's use of Lantern.
*/
private static void configureOsxProxyPacFile() {
try {
FileUtils.copyFile(PROXY_ON, ACTIVE_PAC);
} catch (final IOException e) {
LOG.error("Could not copy pac file?", e);
}
}


private static void configureOsxProxyNetworkSetup() {
final Collection<String> services = mpm.getNetworkServices();
for (final String service : services) {
LOG.info("Setting web proxy for {}", service);
Expand Down Expand Up @@ -106,8 +130,10 @@ private static void configureWindowsProxy() {

// We first want to read the start values so we can return the
// registry to the original state when we shut down.
final String proxyServerOriginal = WindowsRegistry.read(WINDOWS_REGISTRY_PROXY_KEY, ps);
final String proxyEnableOriginal = WindowsRegistry.read(WINDOWS_REGISTRY_PROXY_KEY, pe);
final String proxyServerOriginal =
WindowsRegistry.read(WINDOWS_REGISTRY_PROXY_KEY, ps);
final String proxyEnableOriginal =
WindowsRegistry.read(WINDOWS_REGISTRY_PROXY_KEY, pe);

final String proxyServerUs = "127.0.0.1:"+
LanternConstants.LANTERN_LOCALHOST_HTTP_PORT;
Expand Down Expand Up @@ -188,8 +214,19 @@ protected static void unproxyWindows(final String proxyServerOriginal,
LOG.info("Done resetting the Windows registry");
}


protected static void unproxyOsx() {
private static void unproxyOsx() {
unproxyOsxPacFile();
}

private static void unproxyOsxPacFile() {
try {
FileUtils.copyFile(PROXY_OFF, ACTIVE_PAC);
} catch (final IOException e) {
LOG.error("Could not copy pac file?", e);
}
}

private static void unproxyOsxNetworkServices() {
final Collection<String> services = mpm.getNetworkServices();
for (final String service : services) {

Expand Down

0 comments on commit 34b5df0

Please sign in to comment.