use of net.i2p.util.Log in project i2p.i2p by i2p.
the class HostCheckHandler method handle.
/**
* Block by Host header,
* redirect HTTP to HTTPS,
* pass everything else to the delegate.
*/
public void handle(String pathInContext, Request baseRequest, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
String host = httpRequest.getHeader("Host");
if (!allowHost(host)) {
Log log = _context.logManager().getLog(HostCheckHandler.class);
host = getHost(host);
String s = "Console request denied.\n" + " To allow access using the hostname \"" + host + "\", add the line \"" + PROP_ALLOWED_HOSTS + '=' + host + "\" in the file " + RunStandalone.APP_CONFIG_FILE.getAbsolutePath() + " and restart.";
log.logAlways(Log.WARN, s);
httpResponse.sendError(403, s);
baseRequest.setHandled(true);
return;
}
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class SessionConfig method verifySignature.
/**
* Verify that the signature matches the destination's signing public key.
*
* Note that this also returns false if the creation date is too far in the
* past or future. See tooOld() and getCreationDate().
*
* @return true only if the signature matches
*/
public boolean verifySignature() {
if (getSignature() == null) {
// if (_log.shouldLog(Log.WARN)) _log.warn("Signature is null!");
return false;
}
if (getDestination() == null) {
// if (_log.shouldLog(Log.WARN)) _log.warn("Destination is null!");
return false;
}
if (getCreationDate() == null) {
// if (_log.shouldLog(Log.WARN)) _log.warn("Date is null!");
return false;
}
if (tooOld()) {
// if (_log.shouldLog(Log.WARN)) _log.warn("Too old!");
return false;
}
byte[] data = getBytes();
if (data == null) {
// if (_log.shouldLog(Log.WARN)) _log.warn("Bytes could not be found");
return false;
}
boolean ok = DSAEngine.getInstance().verifySignature(getSignature(), data, getDestination().getSigningPublicKey());
if (!ok) {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(SessionConfig.class);
if (log.shouldLog(Log.WARN))
log.warn("DSA signature failed!");
}
return ok;
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class GeoIPv6 method main.
/**
* Merge and compress CSV files to I2P compressed format
*
* GeoIPv6 infile1.csv[.gz] [infile2.csv[.gz]...] outfile.dat.gz
*
* Used to create the file for distribution, do not comment out
*/
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Usage: GeoIPv6 infile1.csv [infile2.csv...] outfile.dat.gz");
System.exit(1);
}
List<File> infiles = new ArrayList<File>();
for (int i = 0; i < args.length - 1; i++) {
infiles.add(new File(args[i]));
}
File outfile = new File(args[args.length - 1]);
boolean success = compressGeoIPv6CSVFiles(infiles, outfile);
if (!success) {
System.err.println("Failed");
System.exit(1);
}
// readback for testing
readGeoIPFile(outfile, new Long[] { Long.MAX_VALUE }, Collections.<String, String>emptyMap(), new Log(GeoIPv6.class));
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class GeoIPv6 method readGeoIPFile.
/**
* 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 failure
*/
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);
}
use of net.i2p.util.Log in project i2p.i2p by i2p.
the class MarkLiveliness method ping.
private void ping() {
FileOutputStream fos = null;
try {
fos = new SecureFileOutputStream(_pingFile);
fos.write(DataHelper.getASCII(Long.toString(System.currentTimeMillis())));
} catch (IOException ioe) {
if (!_errorLogged) {
Log log = _router.getContext().logManager().getLog(MarkLiveliness.class);
log.logAlways(Log.WARN, "Error writing to ping file " + _pingFile + ": " + ioe);
_errorLogged = true;
}
} finally {
if (fos != null)
try {
fos.close();
} catch (IOException ioe) {
}
}
}
Aggregations