public long getLastModified() { String cpath = getServletContext().getContextPath(); // this won't work if we aren't at top level String cname = "".equals(cpath) ? "i2psnark" : cpath.substring(1).replace("/", "_"); return (new File(_context.getBaseDir(), "webapps/" + cname + ".war")).lastModified(); }
/** * foo => errordir/foo-header_xx.ht for lang xx, or errordir/foo-header.ht, * or the backup byte array on fail. * * .ht files must be UTF-8 encoded and use \r\n terminators so the * HTTP headers are conformant. * We can't use FileUtil.readFile() because it strips \r * * @return non-null * @since 0.9.4 moved from I2PTunnelHTTPClient */ protected static String getErrorPage(I2PAppContext ctx, String base, String backup) { File errorDir = new File(ctx.getBaseDir(), "docs"); File file = new File(errorDir, base + "-header.ht"); try { return readFile(ctx, file); } catch(IOException ioe) { return backup; } }
/** * Get the GeoIP2 database file * * @return null if not found * @since 0.9.38 */ private File getGeoIP2() { String geoDir = _context.getProperty(PROP_GEOIP_DIR, GEOIP_DIR_DEFAULT); File geoFile = new File(geoDir); if (!geoFile.isAbsolute()) geoFile = new File(_context.getBaseDir(), geoDir); geoFile = new File(geoFile, GEOIP2_FILE_DEFAULT); if (!geoFile.exists()) { if (_log.shouldLog(Log.WARN)) _log.warn("GeoIP2 file not found: " + geoFile.getAbsolutePath()); return null; } return geoFile; }
/** * Get all themes * @return String[] -- Array of all the themes found, non-null, unsorted */ public String[] getThemes() { String[] themes; if (_context.isRouterContext()) { File dir = new File(_context.getBaseDir(), "docs/themes/snark"); FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); } }; File[] dirnames = dir.listFiles(fileFilter); if (dirnames != null) { List<String> th = new ArrayList<String>(dirnames.length); boolean skipOld = _context.getProperty(PROP_DISABLE_OLD, DEFAULT_DISABLE_OLD); for (int i = 0; i < dirnames.length; i++) { String name = dirnames[i].getName(); if (skipOld && (name.equals("midnight") || name.equals("classic"))) continue; th.add(name); } themes = th.toArray(new String[th.size()]); } else { themes = new String[0]; } } else { themes = new String[] { "dark", "light", "ubergine", "vanilla" }; } return themes; }
private RunStandalone(String args[]) throws Exception { Properties p = new Properties(); if (APP_CONFIG_FILE.exists()) { try { DataHelper.loadProps(p, APP_CONFIG_FILE); } catch (IOException ioe) {} } _context = new I2PAppContext(p); File base = _context.getBaseDir(); File xml = new File(base, "jetty-i2psnark.xml"); _jettyStart = new JettyStart(_context, null, new String[] { xml.getAbsolutePath() } ); if (args.length > 1) { _port = Integer.parseInt(args[1]); } if (args.length > 0) { _host = args[0]; } }
/** * Won't be available on Android or on any builds not using our build.xml. * * @return 0 if unknown */ private static long getBuildTime(SimpleDateFormat fmt, String jar) { if (SystemVersion.isAndroid()) return 0; File f = new File(I2PAppContext.getGlobalContext().getBaseDir(), "lib"); f = new File(f, jar); Attributes atts = attributes(f); if (atts == null) return 0; String s = atts.getValue("Build-Date"); if (s == null) return 0; try { Date date = fmt.parse(s); if (date != null) { return date.getTime(); } } catch (ParseException pe) {} return 0; }
File f = new File(_appContext.getBaseDir(), "docs/themes/console/images/itoopie_sm.png"); if (!f.exists()) return;
File geoFile = new File(geoDir); if (!geoFile.isAbsolute()) geoFile = new File(_context.getBaseDir(), geoDir); geoFile = new File(geoFile, CONTINENT_FILE_DEFAULT); if (!geoFile.exists()) {
/** * Lookup search items in the geoip file. * See below for format. * * @param search a sorted array of IPs to search * @return an array of country codes, same order as the search param, * or a zero-length array on total failure. * Individual array elements will be null for lookup failure of that item. */ public static String[] readGeoIPFile(I2PAppContext context, Long[] search, Map<String, String> codeCache) { Log log = context.logManager().getLog(GeoIPv6.class); File geoFile = new File(context.getBaseDir(), GEOIP_DIR_DEFAULT); geoFile = new File(geoFile, GEOIP_FILE_DEFAULT); if (!geoFile.exists()) { if (log.shouldLog(Log.WARN)) log.warn("GeoIP file not found: " + geoFile.getAbsolutePath()); return new String[0]; } return readGeoIPFile(geoFile, search, codeCache, log); }
File dir = new File(ctx.getBaseDir(), CERT_DIR); dir = new File(dir, REVOCATION_DIR); loadCRLs(crls, dir); boolean diff = true; try { diff = !ctx.getBaseDir().getCanonicalPath().equals(ctx.getConfigDir().getCanonicalPath()); } catch (IOException ioe) {} if (diff) {
/** * Start an I2P router instance. * This method has limited knowledge * (there is no I2P instance running to collect information from). * * It determines the I2P location using the I2PAppContext. */ public static void start() { try { //TODO: set/get PID String separator = System.getProperty("file.separator"); String location = getAppContext().getBaseDir().getAbsolutePath(); String[] args = new String[] { location + separator + "i2psvc", location + separator + "wrapper.config" }; Runtime.getRuntime().exec(args); } catch (IOException e) { Log log = getAppContext().logManager().getLog(RouterManager.class); log.log(Log.WARN, "Failed to start I2P", e); } }
File geoFile = new File(geoDir); if (!geoFile.isAbsolute()) geoFile = new File(_context.getBaseDir(), geoDir); geoFile = new File(geoFile, COUNTRY_FILE_DEFAULT); if (!geoFile.exists()) {
File newFile = new File(I2PAppContext.getGlobalContext().getBaseDir(), filename); FileUtil.copy(outFile, newFile, false, true); return true;
File geoFile = new File(geoDir); if (!geoFile.isAbsolute()) geoFile = new File(ctx.getBaseDir(), geoDir); geoFile = new File(geoFile, COUNTRY_FILE_DEFAULT); if (!geoFile.exists()) {
File dir2 = new File(context.getBaseDir(), relativeCertPath); if (!dir.getAbsolutePath().equals(dir2.getAbsolutePath())) { adds = KeyStoreUtil.addCerts(dir2, ks);
a.add("-keypass"); a.add(keyPW); if (keyAlg.equals("Ed") || keyAlg.equals("EdDSA") || keyAlg.equals("ElGamal")) { File f = I2PAppContext.getGlobalContext().getBaseDir(); f = new File(f, "lib"); f = new File(f, "i2p.jar");
File geoFile = new File(geoDir); if (!geoFile.isAbsolute()) geoFile = new File(_context.getBaseDir(), geoDir); geoFile = new File(geoFile, GEOIP_FILE_DEFAULT); if (!geoFile.exists()) {
File newFile = new File(I2PAppContext.getGlobalContext().getBaseDir(), filename); FileUtil.copy(outFile, newFile, false, true); return true;
/** * Signal the wrapper to asynchronously dump threads to wrapper.log. * It waits for the signal to complete (which should be fast) * but does not wait for the dump itself. * * @param secondsToWait if <= 0, don't wait * @return success, false if windows or no wrapper, true if secondsToWait <= 0, false if timed out, dump result otherwise */ public static boolean dump(I2PAppContext context, int secondsToWait) { if (SystemVersion.isWindows() || !context.hasWrapper()) return false; ShellCommand sc = new ShellCommand(); File i2pr = new File(context.getBaseDir(), "i2prouter"); String[] args = new String[2]; args[0] = i2pr.getAbsolutePath(); args[1] = "dump"; boolean success = sc.executeSilentAndWaitTimed(args, secondsToWait); if (secondsToWait <= 0) success = true; if (success) { Log log = context.logManager().getLog(ThreadDump.class); File f = new File(context.getConfigDir(), "wrapper.log"); String loc = f.exists() ? f.getAbsolutePath() : "wrapper.log"; log.log(Log.CRIT, "Threads dumped to " + loc); } return success; } }
File geoFile = new File(geoDir); if (!geoFile.isAbsolute()) geoFile = new File(ctx.getBaseDir(), geoDir); geoFile = new File(geoFile, PUBLIC_SUFFIX_LIST); Log log = ctx.logManager().getLog(I2PSSLSocketFactory.class);