| | |
| | | package com.gitblit.manager; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.URI; |
| | | import java.text.MessageFormat; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | |
| | | import com.gitblit.fanout.FanoutNioService; |
| | | import com.gitblit.fanout.FanoutService; |
| | | import com.gitblit.fanout.FanoutSocketService; |
| | | import com.gitblit.git.GitDaemon; |
| | | import com.gitblit.models.FederationModel; |
| | | import com.gitblit.models.RepositoryModel; |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.service.FederationPullService; |
| | | import com.gitblit.transport.git.GitDaemon; |
| | | import com.gitblit.transport.ssh.SshDaemon; |
| | | import com.gitblit.utils.IdGenerator; |
| | | import com.gitblit.utils.StringUtils; |
| | |
| | | sshDaemon.stop(); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | | public boolean isServingRepositories() { |
| | | return settings.getBoolean(Keys.git.enableGitServlet, true) |
| | | || (gitDaemon != null && gitDaemon.isRunning()) |
| | | || (sshDaemon != null && sshDaemon.isRunning()); |
| | | } |
| | | |
| | | protected void configureFederation() { |
| | |
| | | return null; |
| | | } |
| | | if (user.canClone(repository)) { |
| | | String servername = request.getServerName(); |
| | | String url = gitDaemon.formatUrl(servername, repository.name); |
| | | String hostname = getHostname(request); |
| | | String url = gitDaemon.formatUrl(hostname, repository.name); |
| | | return url; |
| | | } |
| | | } |
| | |
| | | return AccessPermission.NONE; |
| | | } |
| | | |
| | | public String getSshDaemonUrl(HttpServletRequest request, UserModel user, RepositoryModel repository) { |
| | | if (user == null || UserModel.ANONYMOUS.equals(user)) { |
| | | // SSH always requires authentication - anonymous access prohibited |
| | | return null; |
| | | } |
| | | if (sshDaemon != null) { |
| | | String bindInterface = settings.getString(Keys.git.sshBindInterface, "localhost"); |
| | | if (bindInterface.equals("localhost") |
| | | && (!request.getServerName().equals("localhost") && !request.getServerName().equals("127.0.0.1"))) { |
| | | // ssh daemon is bound to localhost and the request is from elsewhere |
| | | return null; |
| | | } |
| | | if (user.canClone(repository)) { |
| | | String hostname = getHostname(request); |
| | | String url = sshDaemon.formatUrl(user.username, hostname, repository.name); |
| | | return url; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Extract the hostname from the canonical url or return the |
| | | * hostname from the servlet request. |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | protected String getHostname(HttpServletRequest request) { |
| | | String hostname = request.getServerName(); |
| | | String canonicalUrl = gitblit.getSettings().getString(Keys.web.canonicalUrl, null); |
| | | if (!StringUtils.isEmpty(canonicalUrl)) { |
| | | try { |
| | | URI uri = new URI(canonicalUrl); |
| | | String host = uri.getHost(); |
| | | if (!StringUtils.isEmpty(host) && !"localhost".equals(host)) { |
| | | hostname = host; |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | return hostname; |
| | | } |
| | | |
| | | private class FederationPuller extends FederationPullService { |
| | | |