Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipaddress parsing #269

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/org/jivesoftware/site/DiscourseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public void init(ServletConfig servletConfig) throws ServletException
{
baseUrl = "https://discourse.igniterealtime.org/";
}
if (!baseUrl.endsWith("/")) {
baseUrl = baseUrl + "/";
}

apiKey = servletConfig.getServletContext().getInitParameter("discourse-api-key");

Expand Down Expand Up @@ -76,7 +79,7 @@ private static Long doSimpleQuery(final int queryId, final int lastNumberOfDays)
parameters.put("download", "true");

try {
return restClient.post(baseUrl + "/admin/plugins/explorer/queries/"+queryId+"/run", headers, parameters).getJSONArray("rows").getJSONArray(0).getLong(0);
return restClient.post(baseUrl + "admin/plugins/explorer/queries/"+queryId+"/run", headers, parameters).getJSONArray("rows").getJSONArray(0).getLong(0);
} catch (Throwable t) {
Log.warn("Unable to interact with Discourse's API.", t);
return null;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jivesoftware/site/DownloadStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public static void addListingToDatabase( String ipAddress, String product, Strin
if (ipAddress != null && ipAddress.contains(",")) {
ipAddress = ipAddress.substring(ipAddress.indexOf(",")+1).trim();
}

final DbConnectionManager connectionManager = DbConnectionManager.getInstance();
Connection con = null;
PreparedStatement pstmt = null;
Expand Down Expand Up @@ -345,6 +346,11 @@ public static void addListingToDatabase( String ipAddress, String product, Strin
public static void addUpdateToDatabase( String ipAddress, String product, String version, String fileType,
String fileName, DownloadServlet.DownloadInfo downloadInfo )
{
// Correct for X-Forwarded-For header value sometimes containing a list of IPs. Use the last one.
if (ipAddress != null && ipAddress.contains(",")) {
ipAddress = ipAddress.substring(ipAddress.indexOf(",")+1).trim();
}

final DbConnectionManager connectionManager = DbConnectionManager.getInstance();
Connection con = null;
PreparedStatement pstmt = null;
Expand Down Expand Up @@ -397,6 +403,11 @@ public static void addUpdateToDatabase( String ipAddress, String product, String
public static void addCheckUpdate( String ipAddress, String os, String currentVersion, String latestVersion,
DownloadServlet.DownloadInfo info )
{
// Correct for X-Forwarded-For header value sometimes containing a list of IPs. Use the last one.
if (ipAddress != null && ipAddress.contains(",")) {
ipAddress = ipAddress.substring(ipAddress.indexOf(",")+1).trim();
}

final DbConnectionManager connectionManager = DbConnectionManager.getInstance();
Connection con = null;
PreparedStatement pstmt = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void doGet( HttpServletRequest request, HttpServletResponse response) thr
if ( plugin == null || !Files.exists( plugin ) || !Files.isRegularFile( plugin ) )
{
// Not a file, return 404
Log.info( "File {} does not exist (or is not a regular file).", plugin );
Log.info( "File {} does not exist (or is not a regular file). Unable to process request: {} / {}", plugin, requestURI, request.getQueryString() );
response.sendError( HttpServletResponse.SC_NOT_FOUND );
return;
}
Expand Down
Loading