Skip to content

Commit

Permalink
fix reading of ippattern config array in URLProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
reger committed Dec 20, 2015
1 parent b7e8358 commit d5fd031
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions source/net/yacy/http/servlets/UrlProxyServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.regex.PatternSyntaxException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -122,22 +122,18 @@ public void service (ServletRequest req, ServletResponse res) throws ServletExce
}
// 2 - get target url
URL proxyurl = null;
String strARGS = request.getQueryString();
if (strARGS == null) {
final String strUrl = request.getParameter("url");
if (strUrl == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,"url parameter missing");
return;
}

if (strARGS.startsWith("url=")) {
final String strUrl = strARGS.substring(4); // strip "url="

try {
proxyurl = new URL(strUrl);
} catch (final MalformedURLException e) {
proxyurl = new URL(URLDecoder.decode(strUrl, UTF8.charset.name()));

}
try {
proxyurl = new URL(strUrl);
} catch (final MalformedURLException e) {
proxyurl = new URL(URLDecoder.decode(strUrl, UTF8.charset.name()));
}

if (proxyurl == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,"url parameter missing");
return;
Expand Down Expand Up @@ -334,16 +330,17 @@ private String readLine(final InputStream in) throws IOException {
private boolean proxyippatternmatch(final String key) {
// the cfgippattern is a comma-separated list of patterns
// each pattern may contain one wildcard-character '*' which matches anything
final String cfgippattern = Switchboard.getSwitchboard().getConfig("proxyURL.access", "*");
if (cfgippattern.equals("*")) {
final String[] cfgippattern = Switchboard.getSwitchboard().getConfigArray("proxyURL.access", "*");
if (cfgippattern[0].equals("*")) {
return true;
}
final StringTokenizer st = new StringTokenizer(cfgippattern, ",");
String pattern;
while (st.hasMoreTokens()) {
pattern = st.nextToken();
if (key.matches(pattern)) {
return true;
for (String pattern : cfgippattern) {
try {
if (key.matches(pattern)) {
return true;
}
} catch (PatternSyntaxException ex) {
this._log.warn("wrong ip pattern in url proxy config", ex.getMessage() );
}
}
return false;
Expand Down

0 comments on commit d5fd031

Please sign in to comment.