package com.gitblit.servlet;\r
\r
import java.io.IOException;\r
+import java.net.URL;\r
import java.text.MessageFormat;\r
\r
import javax.servlet.ServletException;\r
import javax.servlet.http.HttpServletRequest;\r
import javax.servlet.http.HttpServletResponse;\r
\r
-import com.gitblit.Constants;\r
import com.gitblit.IStoredSettings;\r
import com.gitblit.Keys;\r
import com.gitblit.dagger.DaggerServlet;\r
javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r
java.io.IOException {\r
\r
+ int sshPort = settings.getInteger(Keys.git.sshPort, 0);\r
+ if (sshPort == 0) {\r
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);\r
+ response.getWriter().append("SSH is not active on this server!");\r
+ return;\r
+ }\r
// extract repo name from request\r
String repoUrl = request.getPathInfo().substring(1);\r
\r
repoUrl = repoUrl.substring(0, repoUrl.length() - 4);\r
}\r
\r
- String servletPath = Constants.R_PATH;\r
-\r
- int schemeIndex = repoUrl.indexOf("://") + 3;\r
- String host = repoUrl.substring(0, repoUrl.indexOf('/', schemeIndex));\r
- String path = repoUrl.substring(repoUrl.indexOf(servletPath) + servletPath.length());\r
String username = null;\r
+ String path;\r
int fetchIndex = repoUrl.indexOf('@');\r
if (fetchIndex > -1) {\r
- username = repoUrl.substring(schemeIndex, fetchIndex);\r
+ username = repoUrl.substring(0, fetchIndex);\r
+ path = repoUrl.substring(fetchIndex + 1);\r
+ } else {\r
+ path = repoUrl;\r
+ }\r
+\r
+ String host = request.getServerName();\r
+ String url = settings.getString(Keys.web.canonicalUrl, "https://localhost:8443");\r
+ if (!StringUtils.isEmpty(url) && url.indexOf("localhost") == -1) {\r
+ host = new URL(url).getHost();\r
}\r
+\r
UserModel user;\r
if (StringUtils.isEmpty(username)) {\r
user = authenticationManager.authenticate(request);\r
} else {\r
user = userManager.getUserModel(username);\r
}\r
- if (user == null) {\r
- user = UserModel.ANONYMOUS;\r
- username = "";\r
+ if (user == null || user.disabled) {\r
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);\r
+ response.getWriter().append("Access is not permitted!");\r
+ return;\r
}\r
\r
// ensure that the requested repository exists\r
return;\r
}\r
\r
+ if (!user.canRewindRef(model)) {\r
+ response.setStatus(HttpServletResponse.SC_FORBIDDEN);\r
+ response.getWriter().append(MessageFormat.format("{0} does not have RW+ permissions to \"{1}\"!", user.username, model.name));\r
+ }\r
+\r
StringBuilder sb = new StringBuilder();\r
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");\r
sb.append("<sparkleshare><invite>\n");\r
- sb.append(MessageFormat.format("<address>{0}</address>\n", host));\r
- sb.append(MessageFormat.format("<remote_path>{0}{1}</remote_path>\n", servletPath, model.name));\r
- if (settings.getInteger(Keys.fanout.port, 0) > 0) {\r
+ sb.append(MessageFormat.format("<address>ssh://{0}@{1}:{2,number,0}/</address>\n", user.username, host, sshPort));\r
+ sb.append(MessageFormat.format("<remote_path>/{0}</remote_path>\n", model.name));\r
+ int fanoutPort = settings.getInteger(Keys.fanout.port, 0);\r
+ if (fanoutPort > 0) {\r
// Gitblit is running it's own fanout service for pubsub notifications\r
- sb.append(MessageFormat.format("<announcements_url>tcp://{0}:{1}</announcements_url>\n", request.getServerName(), settings.getString(Keys.fanout.port, "")));\r
+ sb.append(MessageFormat.format("<announcements_url>tcp://{0}:{1,number,0}</announcements_url>\n", request.getServerName(), fanoutPort));\r
}\r
sb.append("</invite></sparkleshare>\n");\r
\r
return urlPanel;\r
}\r
\r
- protected Fragment createApplicationMenus(String wicketId, UserModel user, final RepositoryModel repository, final List<RepositoryUrl> repositoryUrls) {\r
+ protected Fragment createApplicationMenus(String wicketId, final UserModel user, final RepositoryModel repository, final List<RepositoryUrl> repositoryUrls) {\r
final List<GitClientApplication> displayedApps = new ArrayList<GitClientApplication>();\r
final String userAgent = ((WebClientInfo) GitBlitWebSession.get().getClientInfo()).getUserAgent();\r
\r
\r
if (!StringUtils.isEmpty(clientApp.cloneUrl)) {\r
// custom registered url\r
- String url = substitute(clientApp.cloneUrl, repoUrl.url, baseURL);\r
+ String url = substitute(clientApp.cloneUrl, repoUrl.url, baseURL, user.username, repository.name);\r
fragment.add(new LinkPanel("content", "applicationMenuItem", getString("gb.clone") + " " + repoUrl.url, url));\r
repoLinkItem.add(fragment);\r
fragment.add(new Label("copyFunction").setVisible(false));\r
} else if (!StringUtils.isEmpty(clientApp.command)) {\r
// command-line\r
- String command = substitute(clientApp.command, repoUrl.url, baseURL);\r
+ String command = substitute(clientApp.command, repoUrl.url, baseURL, user.username, repository.name);\r
Label content = new Label("content", command);\r
WicketUtils.setCssClass(content, "commandMenuItem");\r
fragment.add(content);\r
return applicationMenus;\r
}\r
\r
- protected String substitute(String pattern, String repoUrl, String baseUrl) {\r
- return pattern.replace("${repoUrl}", repoUrl).replace("${baseUrl}", baseUrl);\r
+ protected String substitute(String pattern, String repoUrl, String baseUrl, String username, String repository) {\r
+ return pattern.replace("${repoUrl}", repoUrl).replace("${baseUrl}", baseUrl).replace("${username}", username).replace("${repository}", repository);\r
}\r
\r
protected Label createPermissionBadge(String wicketId, RepositoryUrl repoUrl) {\r