move all logging to a proper logging system

Former-commit-id: 2b80b4151a
Former-commit-id: 8b4aa7a33e94df5a4903c52be31b266999549b0e
This commit is contained in:
idk
2022-09-05 00:19:59 -04:00
parent c7ed068c37
commit 3de28ee877
11 changed files with 141 additions and 115 deletions

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
* @author idk * @author idk
* @since 0.0.16 * @since 0.0.16
*/ */
public class I2PBrowser { public class I2PBrowser extends I2PCommonBrowser {
private final I2PFirefox i2pFirefox = new I2PFirefox(); private final I2PFirefox i2pFirefox = new I2PFirefox();
private final I2PChromium i2pChromium = new I2PChromium(); private final I2PChromium i2pChromium = new I2PChromium();
private final I2PGenericUnsafeBrowser i2pGeneral = private final I2PGenericUnsafeBrowser i2pGeneral =
@ -32,17 +32,17 @@ public class I2PBrowser {
public boolean usability = false; public boolean usability = false;
private void launchFirefox(boolean privateWindow, String[] url) { private void launchFirefox(boolean privateWindow, String[] url) {
System.out.println("I2PFirefox"); println("I2PFirefox");
I2PFirefox.usability = usability; I2PFirefox.usability = usability;
i2pFirefox.launch(privateWindow, url); i2pFirefox.launch(privateWindow, url);
} }
private void launchChromium(boolean privateWindow, String[] url) { private void launchChromium(boolean privateWindow, String[] url) {
System.out.println("I2PChromium"); println("I2PChromium");
I2PChromiumProfileBuilder.usability = usability; I2PChromiumProfileBuilder.usability = usability;
i2pChromium.launch(privateWindow, url); i2pChromium.launch(privateWindow, url);
} }
private void launchGeneric(boolean privateWindow, String[] url) { private void launchGeneric(boolean privateWindow, String[] url) {
System.out.println("I2PChromium"); println("I2PChromium");
i2pGeneral.launch(privateWindow, url); i2pGeneral.launch(privateWindow, url);
} }
@ -176,7 +176,7 @@ public class I2PBrowser {
public static void main(String[] args) { public static void main(String[] args) {
boolean privateBrowsing = false; boolean privateBrowsing = false;
System.out.println("I2PBrowser"); println("I2PBrowser");
I2PBrowser i2pBrowser = new I2PBrowser(); I2PBrowser i2pBrowser = new I2PBrowser();
ArrayList<String> visitURL = new ArrayList<String>(); ArrayList<String> visitURL = new ArrayList<String>();
if (args != null) { if (args != null) {

View File

@ -35,7 +35,7 @@ public class I2PChromium extends I2PCommonBrowser {
for (String path : CHROMIUM_SEARCH_PATHS) { for (String path : CHROMIUM_SEARCH_PATHS) {
File f = new File(path); File f = new File(path);
if (f.exists()) { if (f.exists()) {
System.out.println("Found Chromium at " + path); println("Found Chromium at " + path);
return; return;
} }
} }
@ -44,7 +44,7 @@ public class I2PChromium extends I2PCommonBrowser {
for (String path : CHROMIUM_SEARCH_PATHS) { for (String path : CHROMIUM_SEARCH_PATHS) {
File f = new File(path); File f = new File(path);
if (f.exists()) { if (f.exists()) {
System.out.println("Found Chromium at " + path); println("Found Chromium at " + path);
return; return;
} }
} }
@ -250,10 +250,10 @@ public class I2PChromium extends I2PCommonBrowser {
for (String chrome : chromees) { for (String chrome : chromees) {
File chromeFile = new File(chrome); File chromeFile = new File(chrome);
if (chromeFile.exists()) { if (chromeFile.exists()) {
System.out.println("Found valid chromium at " + chrome); println("Found valid chromium at " + chrome);
validChromiums.add(chrome); validChromiums.add(chrome);
} }
System.out.println("chrome at " + chrome + "does not exist"); println("chrome at " + chrome + "does not exist");
} }
return validChromiums.toArray(new String[validChromiums.size()]); return validChromiums.toArray(new String[validChromiums.size()]);
} }
@ -478,7 +478,7 @@ public class I2PChromium extends I2PCommonBrowser {
return new ProcessBuilder(newArgs).directory( return new ProcessBuilder(newArgs).directory(
I2PChromiumProfileBuilder.runtimeDirectory(true)); I2PChromiumProfileBuilder.runtimeDirectory(true));
} else { } else {
System.out.println("No Chromium found."); println("No Chromium found.");
return new ProcessBuilder(args); return new ProcessBuilder(args);
} }
} }
@ -553,16 +553,15 @@ public class I2PChromium extends I2PCommonBrowser {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); String profileDirectory = I2PChromiumProfileBuilder.profileDirectory();
if (I2PChromiumProfileChecker.validateProfileDirectory( if (I2PChromiumProfileChecker.validateProfileDirectory(
profileDirectory)) { profileDirectory)) {
System.out.println("Valid profile directory: " + profileDirectory); println("Valid profile directory: " + profileDirectory);
} else { } else {
System.out.println("Invalid profile directory: " + profileDirectory + println("Invalid profile directory: " + profileDirectory +
" rebuilding..."); " rebuilding...");
if (!I2PChromiumProfileBuilder.copyBaseProfiletoProfile()) { if (!I2PChromiumProfileBuilder.copyBaseProfiletoProfile()) {
System.out.println("Failed to rebuild profile directory: " + println("Failed to rebuild profile directory: " + profileDirectory);
profileDirectory);
return null; return null;
} else { } else {
System.out.println("Rebuilt profile directory: " + profileDirectory); println("Rebuilt profile directory: " + profileDirectory);
} }
} }
if (validateProfileFirstRun(profileDirectory)) if (validateProfileFirstRun(profileDirectory))
@ -600,13 +599,13 @@ public class I2PChromium extends I2PCommonBrowser {
p = launchAndDetatch(privateWindow, url); p = launchAndDetatch(privateWindow, url);
if (p == null) if (p == null)
return; return;
System.out.println("I2PChromium"); println("I2PChromium");
try { try {
System.out.println("Waiting for I2PChromium to close..."); println("Waiting for I2PChromium to close...");
int exit = p.waitFor(); int exit = p.waitFor();
System.out.println("I2PChromium exited with value: " + exit); println("I2PChromium exited with value: " + exit);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error: " + e.getMessage()); println("Error: " + e.getMessage());
} }
} }
} }
@ -643,16 +642,16 @@ public class I2PChromium extends I2PCommonBrowser {
public static void main(String[] args) { public static void main(String[] args) {
boolean privateBrowsing = false; boolean privateBrowsing = false;
System.out.println("I2PChromium"); println("I2PChromium");
I2PChromium i2pChromium = new I2PChromium(); I2PChromium i2pChromium = new I2PChromium();
System.out.println("checking for private browsing"); println("checking for private browsing");
ArrayList<String> visitURL = new ArrayList<String>(); ArrayList<String> visitURL = new ArrayList<String>();
if (args != null) { if (args != null) {
if (args.length > 0) { if (args.length > 0) {
for (String arg : args) { for (String arg : args) {
if (arg.equals("-private")) { if (arg.equals("-private")) {
privateBrowsing = true; privateBrowsing = true;
System.out.println( println(
"private browsing is true, profile will be discarded at end of session"); "private browsing is true, profile will be discarded at end of session");
} }
if (arg.equals("-usability")) { if (arg.equals("-usability")) {

View File

@ -120,8 +120,8 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
public static boolean copyBaseProfiletoProfile() { public static boolean copyBaseProfiletoProfile() {
String baseProfile = baseProfileDirectory(usabilityMode()); String baseProfile = baseProfileDirectory(usabilityMode());
String profile = profileDirectory(); String profile = profileDirectory();
System.out.println("Copying base profile to profile directory: " + println("Copying base profile to profile directory: " + baseProfile +
baseProfile + " -> " + profile); " -> " + profile);
if (baseProfile.isEmpty() || profile.isEmpty()) { if (baseProfile.isEmpty() || profile.isEmpty()) {
return false; return false;
} }
@ -129,14 +129,14 @@ public class I2PChromiumProfileBuilder extends I2PCommonBrowser {
File profileDir = new File(profile); File profileDir = new File(profile);
if (!profileDir.exists()) { if (!profileDir.exists()) {
try { try {
System.out.println("Copying base profile to profile directory"); println("Copying base profile to profile directory");
copyDirectory(baseProfileDir, profileDir, "chromium", usabilityMode()); copyDirectory(baseProfileDir, profileDir, "chromium", usabilityMode());
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error copying base profile to profile" + e); println("Error copying base profile to profile" + e);
return false; return false;
} }
} }
System.out.println("Copied base profile to profile directory"); println("Copied base profile to profile directory");
return true; return true;
} }

View File

@ -18,7 +18,7 @@ import java.io.File;
* @author idk * @author idk
* @since 0.0.1 * @since 0.0.1
*/ */
public class I2PChromiumProfileChecker { public class I2PChromiumProfileChecker extends I2PCommonBrowser {
/** /**
* Output feedback if the profile directory is valid or invalid * Output feedback if the profile directory is valid or invalid
* *
@ -29,15 +29,15 @@ public class I2PChromiumProfileChecker {
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); String profileDirectory = I2PChromiumProfileBuilder.profileDirectory();
if (profileDirectory == null) { if (profileDirectory == null) {
System.out.println("No profile directory found"); println("No profile directory found");
return; return;
} }
System.out.println("Profile directory: " + profileDirectory); println("Profile directory: " + profileDirectory);
boolean ok = validateProfileDirectory(profileDirectory); boolean ok = validateProfileDirectory(profileDirectory);
if (ok) { if (ok) {
System.out.println("Profile directory is valid"); println("Profile directory is valid");
} else { } else {
System.out.println("Profile directory is invalid"); println("Profile directory is invalid");
} }
} }
/** /**
@ -50,23 +50,23 @@ public class I2PChromiumProfileChecker {
public static boolean validateProfileDirectory(String profileDirectory) { public static boolean validateProfileDirectory(String profileDirectory) {
File profileDir = new File(profileDirectory); File profileDir = new File(profileDirectory);
if (!profileDir.exists()) { if (!profileDir.exists()) {
System.out.println("Profile directory does not exist"); println("Profile directory does not exist");
return false; return false;
} }
if (!profileDir.isDirectory()) { if (!profileDir.isDirectory()) {
System.out.println("Profile directory is not a directory"); println("Profile directory is not a directory");
return false; return false;
} }
if (!profileDir.canRead()) { if (!profileDir.canRead()) {
System.out.println("Profile directory is not readable"); println("Profile directory is not readable");
return false; return false;
} }
if (!profileDir.canWrite()) { if (!profileDir.canWrite()) {
System.out.println("Profile directory is not writable"); println("Profile directory is not writable");
return false; return false;
} }
if (!validateExtensionDirectory(profileDir + "/extensions")) { if (!validateExtensionDirectory(profileDir + "/extensions")) {
System.out.println("extensions directory is invalid"); println("extensions directory is invalid");
return false; return false;
} }
return true; return true;
@ -81,19 +81,19 @@ public class I2PChromiumProfileChecker {
public static boolean validateFile(String file) { public static boolean validateFile(String file) {
File f = new File(file); File f = new File(file);
if (!f.exists()) { if (!f.exists()) {
System.out.println("User JavaScript file does not exist"); println("User JavaScript file does not exist");
return false; return false;
} }
if (!f.isFile()) { if (!f.isFile()) {
System.out.println("User JavaScript file is not a file"); println("User JavaScript file is not a file");
return false; return false;
} }
if (!f.canRead()) { if (!f.canRead()) {
System.out.println("User JavaScript file is not readable"); println("User JavaScript file is not readable");
return false; return false;
} }
if (!f.canWrite()) { if (!f.canWrite()) {
System.out.println("User JavaScript file is not writable"); println("User JavaScript file is not writable");
return false; return false;
} }
return true; return true;
@ -108,19 +108,19 @@ public class I2PChromiumProfileChecker {
public static boolean validateExtensionDirectory(String extensionDirectory) { public static boolean validateExtensionDirectory(String extensionDirectory) {
File extensionDir = new File(extensionDirectory); File extensionDir = new File(extensionDirectory);
if (!extensionDir.exists()) { if (!extensionDir.exists()) {
System.out.println("Extension directory does not exist"); println("Extension directory does not exist");
return false; return false;
} }
if (!extensionDir.isDirectory()) { if (!extensionDir.isDirectory()) {
System.out.println("Extension directory is not a directory"); println("Extension directory is not a directory");
return false; return false;
} }
if (!extensionDir.canRead()) { if (!extensionDir.canRead()) {
System.out.println("Extension directory is not readable"); println("Extension directory is not readable");
return false; return false;
} }
if (!extensionDir.canWrite()) { if (!extensionDir.canWrite()) {
System.out.println("Extension directory is not writable"); println("Extension directory is not writable");
return false; return false;
} }
return true; return true;

View File

@ -23,7 +23,7 @@ public class I2PChromiumProfileUnpacker extends I2PCommonBrowser {
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PChromiumProfileBuilder.profileDirectory(); String profileDirectory = I2PChromiumProfileBuilder.profileDirectory();
if (profileDirectory == null) { if (profileDirectory == null) {
System.out.println("No profile directory found"); println("No profile directory found");
return; return;
} }
} }
@ -35,7 +35,7 @@ public class I2PChromiumProfileUnpacker extends I2PCommonBrowser {
* @since 0.0.1 * @since 0.0.1
*/ */
public boolean unpackProfile(String profileDirectory, String mode) { public boolean unpackProfile(String profileDirectory, String mode) {
System.out.println("Unpacking base profile to " + profileDirectory); println("Unpacking base profile to " + profileDirectory);
return unpackProfile(profileDirectory, "chromium", mode); return unpackProfile(profileDirectory, "chromium", mode);
} }
} }

View File

@ -8,6 +8,9 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -27,6 +30,33 @@ import java.util.zip.ZipInputStream;
*/ */
public class I2PCommonBrowser { public class I2PCommonBrowser {
static Logger logger = Logger.getLogger("browserlauncher");
static FileHandler fh;
public I2PCommonBrowser() {
try {
// This block configure the logger with handler and formatter
fh = new FileHandler(logFile().toString());
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
// the following statement is used to log any messages
logger.info("Browser log");
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void println(String line) { logger.info(line); }
private static File logFile() {
File log = new File("logs");
if (!log.exists())
log.mkdirs();
return new File(log, "browserlauncher.log");
}
/** /**
* get the runtime directory, creating it if create=true * get the runtime directory, creating it if create=true
@ -118,16 +148,16 @@ public class I2PCommonBrowser {
protected boolean unpackProfile(String profileDirectory, String browser, protected boolean unpackProfile(String profileDirectory, String browser,
String base) { String base) {
System.out.println("Unpacking base profile to " + profileDirectory); println("Unpacking base profile to " + profileDirectory);
try { try {
final InputStream resources = final InputStream resources =
this.getClass().getClassLoader().getResourceAsStream( this.getClass().getClassLoader().getResourceAsStream(
"i2p." + browser + "." + base + ".profile.zip"); "i2p." + browser + "." + base + ".profile.zip");
if (resources == null) { if (resources == null) {
System.out.println("Could not find resources"); println("Could not find resources");
return false; return false;
} }
System.out.println(resources.toString()); println(resources.toString());
// InputStream corresponds to a zip file. Unzip it. // InputStream corresponds to a zip file. Unzip it.
// Files.copy(r, new File(profileDirectory).toPath(), // Files.copy(r, new File(profileDirectory).toPath(),
// StandardCopyOption.REPLACE_EXISTING); // StandardCopyOption.REPLACE_EXISTING);
@ -135,15 +165,14 @@ public class I2PCommonBrowser {
ZipEntry entry; ZipEntry entry;
// while there are entries I process them // while there are entries I process them
while ((entry = zis.getNextEntry()) != null) { while ((entry = zis.getNextEntry()) != null) {
System.out.println("entry: " + entry.getName() + ", " + println("entry: " + entry.getName() + ", " + entry.getSize());
entry.getSize());
// consume all the data from this entry // consume all the data from this entry
if (entry.isDirectory()) { if (entry.isDirectory()) {
System.out.println("Creating directory: " + entry.getName()); println("Creating directory: " + entry.getName());
File dir = new File(profileDirectory + "/" + entry.getName()); File dir = new File(profileDirectory + "/" + entry.getName());
dir.mkdirs(); dir.mkdirs();
} else { } else {
System.out.println("Creating file: " + entry.getName()); println("Creating file: " + entry.getName());
File file = new File(profileDirectory + "/" + entry.getName()); File file = new File(profileDirectory + "/" + entry.getName());
file.createNewFile(); file.createNewFile();
Files.copy(zis, file.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.copy(zis, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
@ -156,7 +185,7 @@ public class I2PCommonBrowser {
// loop through the Enumeration // loop through the Enumeration
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error copying profile files: " + e.getMessage()); println("Error copying profile files: " + e.getMessage());
return false; return false;
} }
return true; return true;
@ -203,11 +232,11 @@ public class I2PCommonBrowser {
public static boolean validateProfileFirstRun(String profileDirectory) { public static boolean validateProfileFirstRun(String profileDirectory) {
File profileDir = new File(profileDirectory); File profileDir = new File(profileDirectory);
if (!profileDir.exists()) { if (!profileDir.exists()) {
System.out.println("Profile directory does not exist"); println("Profile directory does not exist");
return false; return false;
} }
if (!profileDir.isDirectory()) { if (!profileDir.isDirectory()) {
System.out.println("Profile directory is not a directory"); println("Profile directory is not a directory");
return false; return false;
} }
File frf = new File(profileDir, "first-run"); File frf = new File(profileDir, "first-run");

View File

@ -36,7 +36,7 @@ public class I2PFirefox extends I2PCommonBrowser {
for (String path : FIREFOX_SEARCH_PATHS) { for (String path : FIREFOX_SEARCH_PATHS) {
File f = new File(path); File f = new File(path);
if (f.exists()) { if (f.exists()) {
System.out.println("Found Firefox at " + path); println("Found Firefox at " + path);
return; return;
} }
} }
@ -238,10 +238,10 @@ public class I2PFirefox extends I2PCommonBrowser {
for (String firefox : firefoxes) { for (String firefox : firefoxes) {
File firefoxFile = new File(firefox); File firefoxFile = new File(firefox);
if (firefoxFile.exists()) { if (firefoxFile.exists()) {
System.out.println("Found valid firefox at " + firefox); println("Found valid firefox at " + firefox);
validFirefoxes.add(firefox); validFirefoxes.add(firefox);
} }
System.out.println("firefox at " + firefox + "does not exist"); println("firefox at " + firefox + "does not exist");
} }
return validFirefoxes.toArray(new String[validFirefoxes.size()]); return validFirefoxes.toArray(new String[validFirefoxes.size()]);
} }
@ -382,7 +382,7 @@ public class I2PFirefox extends I2PCommonBrowser {
return new ProcessBuilder(newArgs).directory( return new ProcessBuilder(newArgs).directory(
I2PFirefoxProfileBuilder.runtimeDirectory(true)); I2PFirefoxProfileBuilder.runtimeDirectory(true));
} else { } else {
System.out.println("No Firefox found."); println("No Firefox found.");
return new ProcessBuilder(args); return new ProcessBuilder(args);
} }
} }
@ -431,7 +431,7 @@ public class I2PFirefox extends I2PCommonBrowser {
*/ */
public boolean waitForProxy(int timeout, int port, String host) { public boolean waitForProxy(int timeout, int port, String host) {
for (int i = 0; i < timeout; i++) { for (int i = 0; i < timeout; i++) {
System.out.println("Waiting for proxy"); println("Waiting for proxy");
if (checkifPortIsOccupied(port, host)) { if (checkifPortIsOccupied(port, host)) {
return true; return true;
} }
@ -464,17 +464,16 @@ public class I2PFirefox extends I2PCommonBrowser {
if (waitForProxy()) { if (waitForProxy()) {
String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(); String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory();
if (I2PFirefoxProfileChecker.validateProfileDirectory(profileDirectory)) { if (I2PFirefoxProfileChecker.validateProfileDirectory(profileDirectory)) {
System.out.println("Valid profile directory: " + profileDirectory); println("Valid profile directory: " + profileDirectory);
} else { } else {
System.out.println("Invalid profile directory: " + profileDirectory + println("Invalid profile directory: " + profileDirectory +
" rebuilding..."); " rebuilding...");
if (!I2PFirefoxProfileBuilder.copyBaseProfiletoProfile( if (!I2PFirefoxProfileBuilder.copyBaseProfiletoProfile(
usabilityMode())) { usabilityMode())) {
System.out.println("Failed to rebuild profile directory: " + println("Failed to rebuild profile directory: " + profileDirectory);
profileDirectory);
return null; return null;
} else { } else {
System.out.println("Rebuilt profile directory: " + profileDirectory); println("Rebuilt profile directory: " + profileDirectory);
} }
} }
if (validateProfileFirstRun(profileDirectory)) if (validateProfileFirstRun(profileDirectory))
@ -488,7 +487,7 @@ public class I2PFirefox extends I2PCommonBrowser {
try { try {
System.out.println(pb.command()); System.out.println(pb.command());
p = pb.start(); p = pb.start();
System.out.println("I2PFirefox"); println("I2PFirefox");
sleep(2000); sleep(2000);
return p; return p;
} catch (Throwable e) { } catch (Throwable e) {
@ -514,11 +513,11 @@ public class I2PFirefox extends I2PCommonBrowser {
if (p == null) if (p == null)
return; return;
try { try {
System.out.println("Waiting for I2PFirefox to close..."); println("Waiting for I2PFirefox to close...");
int exit = p.waitFor(); int exit = p.waitFor();
System.out.println("I2PFirefox exited with value: " + exit); println("I2PFirefox exited with value: " + exit);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error: " + e.getMessage()); println("Error: " + e.getMessage());
} }
} }
} }
@ -548,7 +547,7 @@ public class I2PFirefox extends I2PCommonBrowser {
String[] schemes = {"http", "https"}; String[] schemes = {"http", "https"};
for (String scheme : schemes) { for (String scheme : schemes) {
if (inUrl.startsWith(scheme)) { if (inUrl.startsWith(scheme)) {
System.out.println("Valid URL: " + inUrl); println("Valid URL: " + inUrl);
return inUrl; return inUrl;
} }
} }
@ -557,14 +556,14 @@ public class I2PFirefox extends I2PCommonBrowser {
public static void main(String[] args) { public static void main(String[] args) {
boolean privateBrowsing = false; boolean privateBrowsing = false;
System.out.println("checking for private browsing"); println("checking for private browsing");
ArrayList<String> visitURL = new ArrayList<String>(); ArrayList<String> visitURL = new ArrayList<String>();
if (args != null) { if (args != null) {
if (args.length > 0) { if (args.length > 0) {
for (String arg : args) { for (String arg : args) {
if (arg.equals("-private")) { if (arg.equals("-private")) {
privateBrowsing = true; privateBrowsing = true;
System.out.println( println(
"private browsing is true, profile will be discarded at end of session"); "private browsing is true, profile will be discarded at end of session");
} }
if (arg.equals("-usability")) { if (arg.equals("-usability")) {
@ -577,7 +576,7 @@ public class I2PFirefox extends I2PCommonBrowser {
} }
} }
} }
System.out.println("I2PFirefox"); println("I2PFirefox");
I2PFirefox i2pFirefox = new I2PFirefox(); I2PFirefox i2pFirefox = new I2PFirefox();
i2pFirefox.launch(privateBrowsing, i2pFirefox.launch(privateBrowsing,
visitURL.toArray(new String[visitURL.size()])); visitURL.toArray(new String[visitURL.size()]));

View File

@ -112,8 +112,8 @@ public class I2PFirefoxProfileBuilder extends I2PCommonBrowser {
public static boolean copyBaseProfiletoProfile(String base) { public static boolean copyBaseProfiletoProfile(String base) {
String baseProfile = baseProfileDirectory(base); String baseProfile = baseProfileDirectory(base);
String profile = profileDirectory(); String profile = profileDirectory();
System.out.println("Copying base profile to profile directory: " + println("Copying base profile to profile directory: " + baseProfile +
baseProfile + " -> " + profile); " -> " + profile);
if (baseProfile.isEmpty() || profile.isEmpty()) { if (baseProfile.isEmpty() || profile.isEmpty()) {
return false; return false;
} }
@ -122,13 +122,13 @@ public class I2PFirefoxProfileBuilder extends I2PCommonBrowser {
if (!profileDir.exists()) { if (!profileDir.exists()) {
try { try {
System.out.println("Copying base profile to profile directory"); println("Copying base profile to profile directory");
copyDirectory(baseProfileDir, profileDir, "firefox", base); copyDirectory(baseProfileDir, profileDir, "firefox", base);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error copying base profile to profile" + e); println("Error copying base profile to profile" + e);
return false; return false;
} }
System.out.println("Copied base profile to profile directory"); println("Copied base profile to profile directory");
} }
// if user.js does not exist yet, make an empty one. // if user.js does not exist yet, make an empty one.
// if (!touch(profileDir.toString(), "user.js")) { // if (!touch(profileDir.toString(), "user.js")) {
@ -171,7 +171,7 @@ public class I2PFirefoxProfileBuilder extends I2PCommonBrowser {
Files.copy(baseOverrides.toPath(), userOverrides.toPath(), Files.copy(baseOverrides.toPath(), userOverrides.toPath(),
StandardCopyOption.REPLACE_EXISTING); StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error copying base profile to profile" + e); println("Error copying base profile to profile" + e);
return false; return false;
} }
// if user-overrides.js does not exist yet, make an empty one. // if user-overrides.js does not exist yet, make an empty one.

View File

@ -22,7 +22,7 @@ import java.io.IOException;
* @author idk * @author idk
* @since 0.0.1 * @since 0.0.1
*/ */
public class I2PFirefoxProfileChecker { public class I2PFirefoxProfileChecker extends I2PCommonBrowser {
/** /**
* @param args unused * @param args unused
@ -30,15 +30,15 @@ public class I2PFirefoxProfileChecker {
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(); String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory();
if (profileDirectory == null) { if (profileDirectory == null) {
System.out.println("No profile directory found"); println("No profile directory found");
return; return;
} }
System.out.println("Profile directory: " + profileDirectory); println("Profile directory: " + profileDirectory);
boolean ok = validateProfileDirectory(profileDirectory); boolean ok = validateProfileDirectory(profileDirectory);
if (ok) { if (ok) {
System.out.println("Profile directory is valid"); println("Profile directory is valid");
} else { } else {
System.out.println("Profile directory is invalid"); println("Profile directory is invalid");
} }
} }
/** /**
@ -51,31 +51,31 @@ public class I2PFirefoxProfileChecker {
public static boolean validateProfileDirectory(String profileDirectory) { public static boolean validateProfileDirectory(String profileDirectory) {
File profileDir = new File(profileDirectory); File profileDir = new File(profileDirectory);
if (!profileDir.exists()) { if (!profileDir.exists()) {
System.out.println("Profile directory does not exist"); println("Profile directory does not exist");
return false; return false;
} }
if (!profileDir.isDirectory()) { if (!profileDir.isDirectory()) {
System.out.println("Profile directory is not a directory"); println("Profile directory is not a directory");
return false; return false;
} }
if (!profileDir.canRead()) { if (!profileDir.canRead()) {
System.out.println("Profile directory is not readable"); println("Profile directory is not readable");
return false; return false;
} }
if (!profileDir.canWrite()) { if (!profileDir.canWrite()) {
System.out.println("Profile directory is not writable"); println("Profile directory is not writable");
return false; return false;
} }
if (!validateFile(profileDir + "/prefs.js")) { if (!validateFile(profileDir + "/prefs.js")) {
System.out.println("prefs.js is not valid"); println("prefs.js is not valid");
return false; return false;
} }
if (!validateFile(profileDir + "/user.js")) { if (!validateFile(profileDir + "/user.js")) {
System.out.println("user.js is not valid"); println("user.js is not valid");
return false; return false;
} }
if (!validateExtensionDirectory(profileDir + "/extensions")) { if (!validateExtensionDirectory(profileDir + "/extensions")) {
System.out.println("extensions directory is invalid"); println("extensions directory is invalid");
return false; return false;
} }
return deRestrictHTTPS(profileDir.toString()); return deRestrictHTTPS(profileDir.toString());
@ -140,19 +140,19 @@ public class I2PFirefoxProfileChecker {
public static boolean validateFile(String file) { public static boolean validateFile(String file) {
File f = new File(file); File f = new File(file);
if (!f.exists()) { if (!f.exists()) {
System.out.println("User JavaScript file does not exist"); println("User JavaScript file does not exist");
return false; return false;
} }
if (!f.isFile()) { if (!f.isFile()) {
System.out.println("User JavaScript file is not a file"); println("User JavaScript file is not a file");
return false; return false;
} }
if (!f.canRead()) { if (!f.canRead()) {
System.out.println("User JavaScript file is not readable"); println("User JavaScript file is not readable");
return false; return false;
} }
if (!f.canWrite()) { if (!f.canWrite()) {
System.out.println("User JavaScript file is not writable"); println("User JavaScript file is not writable");
return false; return false;
} }
return true; return true;
@ -167,19 +167,19 @@ public class I2PFirefoxProfileChecker {
public static boolean validateExtensionDirectory(String extensionDirectory) { public static boolean validateExtensionDirectory(String extensionDirectory) {
File extensionDir = new File(extensionDirectory); File extensionDir = new File(extensionDirectory);
if (!extensionDir.exists()) { if (!extensionDir.exists()) {
System.out.println("Extension directory does not exist"); println("Extension directory does not exist");
return false; return false;
} }
if (!extensionDir.isDirectory()) { if (!extensionDir.isDirectory()) {
System.out.println("Extension directory is not a directory"); println("Extension directory is not a directory");
return false; return false;
} }
if (!extensionDir.canRead()) { if (!extensionDir.canRead()) {
System.out.println("Extension directory is not readable"); println("Extension directory is not readable");
return false; return false;
} }
if (!extensionDir.canWrite()) { if (!extensionDir.canWrite()) {
System.out.println("Extension directory is not writable"); println("Extension directory is not writable");
return false; return false;
} }
return true; return true;

View File

@ -23,7 +23,7 @@ public class I2PFirefoxProfileUnpacker extends I2PCommonBrowser {
public static void main(String[] args) { public static void main(String[] args) {
String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory(); String profileDirectory = I2PFirefoxProfileBuilder.profileDirectory();
if (profileDirectory == null) { if (profileDirectory == null) {
System.out.println("No profile directory found"); println("No profile directory found");
return; return;
} }
} }

View File

@ -216,7 +216,7 @@ public class I2PGenericUnsafeBrowser extends I2PCommonBrowser {
pb.environment().put("NO_PROXY", "http://127.0.0.1:7657"); pb.environment().put("NO_PROXY", "http://127.0.0.1:7657");
return pb; return pb;
} else { } else {
System.out.println("No Browser found."); println("No Browser found.");
return new ProcessBuilder(args); return new ProcessBuilder(args);
} }
} }
@ -336,7 +336,7 @@ public class I2PGenericUnsafeBrowser extends I2PCommonBrowser {
try { try {
System.out.println(pb.command()); System.out.println(pb.command());
p = pb.start(); p = pb.start();
System.out.println("I2PBrowser"); println("I2PBrowser");
sleep(2000); sleep(2000);
return p; return p;
} catch (Throwable e) { } catch (Throwable e) {
@ -350,16 +350,15 @@ public class I2PGenericUnsafeBrowser extends I2PCommonBrowser {
if (waitForProxy()) { if (waitForProxy()) {
p = launchAndDetatch(privateWindow, url); p = launchAndDetatch(privateWindow, url);
try { try {
System.out.println("Waiting for I2PBrowser to close..."); println("Waiting for I2PBrowser to close...");
int exit = p.waitFor(); int exit = p.waitFor();
if (privateWindow) { if (privateWindow) {
if (deleteRuntimeDirectory()) if (deleteRuntimeDirectory())
System.out.println( println("Private browsing enforced, deleting runtime directory");
"Private browsing enforced, deleting runtime directory");
} }
System.out.println("I2PBrowser exited with value: " + exit); println("I2PBrowser exited with value: " + exit);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error: " + e.getMessage()); println("Error: " + e.getMessage());
} }
} }
} }
@ -376,7 +375,7 @@ public class I2PGenericUnsafeBrowser extends I2PCommonBrowser {
String[] schemes = {"http", "https"}; String[] schemes = {"http", "https"};
for (String scheme : schemes) { for (String scheme : schemes) {
if (inUrl.startsWith(scheme)) { if (inUrl.startsWith(scheme)) {
System.out.println("Valid URL: " + inUrl); println("Valid URL: " + inUrl);
return inUrl; return inUrl;
} }
} }
@ -395,14 +394,14 @@ public class I2PGenericUnsafeBrowser extends I2PCommonBrowser {
// //
public static void main(String[] args) { public static void main(String[] args) {
boolean privateBrowsing = false; boolean privateBrowsing = false;
System.out.println("checking for private browsing"); println("checking for private browsing");
ArrayList<String> visitURL = new ArrayList<String>(); ArrayList<String> visitURL = new ArrayList<String>();
if (args != null) { if (args != null) {
if (args.length > 0) { if (args.length > 0) {
for (String arg : args) { for (String arg : args) {
if (arg.equals("-private")) { if (arg.equals("-private")) {
privateBrowsing = true; privateBrowsing = true;
System.out.println( println(
"private browsing is true, profile will be discarded at end of session"); "private browsing is true, profile will be discarded at end of session");
} }
if (!arg.startsWith("-")) { if (!arg.startsWith("-")) {
@ -412,7 +411,7 @@ public class I2PGenericUnsafeBrowser extends I2PCommonBrowser {
} }
} }
} }
System.out.println("I2PGenericUnsafeBrowser"); println("I2PGenericUnsafeBrowser");
I2PGenericUnsafeBrowser i2pBrowser = new I2PGenericUnsafeBrowser(); I2PGenericUnsafeBrowser i2pBrowser = new I2PGenericUnsafeBrowser();
i2pBrowser.launch(privateBrowsing, i2pBrowser.launch(privateBrowsing,
visitURL.toArray(new String[visitURL.size()])); visitURL.toArray(new String[visitURL.size()]));