From f76fee63ed9cb3a30d3c0c092d860b1cb93a481b Mon Sep 17 00:00:00 2001
From: Gerard Smyth <gerard.smyth@gmail.com>
Date: Thu, 08 May 2014 13:09:30 -0400
Subject: [PATCH] Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits. This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT. If this is not provided, then COMMIT is assumed to maintain backwards compatability. If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored.
---
src/main/java/com/gitblit/transport/ssh/WelcomeShell.java | 91 +++++++++++++++++++++++++++++++++++++--------
1 files changed, 74 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/gitblit/transport/ssh/WelcomeShell.java b/src/main/java/com/gitblit/transport/ssh/WelcomeShell.java
index 156e99e..852756a 100644
--- a/src/main/java/com/gitblit/transport/ssh/WelcomeShell.java
+++ b/src/main/java/com/gitblit/transport/ssh/WelcomeShell.java
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2009 The Android Open Source Project
* Copyright 2014 gitblit.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,6 +35,8 @@
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.models.UserModel;
+import com.gitblit.transport.ssh.commands.DispatchCommand;
+import com.gitblit.transport.ssh.commands.SshCommandFactory;
import com.gitblit.utils.StringUtils;
/**
@@ -56,7 +59,7 @@
private static class SendMessage implements Command, SessionAware {
private final IStoredSettings settings;
- private SshDaemonClient client;
+ private ServerSession session;
private InputStream in;
private OutputStream out;
@@ -89,7 +92,7 @@
@Override
public void setSession(final ServerSession session) {
- this.client = session.getAttribute(SshDaemonClient.KEY);
+ this.session = session;
}
@Override
@@ -105,31 +108,83 @@
@Override
public void destroy() {
+ this.session = null;
}
String getMessage() {
+ SshDaemonClient client = session.getAttribute(SshDaemonClient.KEY);
UserModel user = client.getUser();
+ String hostname = getHostname();
+ int port = settings.getInteger(Keys.git.sshPort, 0);
+
+ final String b1 = StringUtils.rightPad("", 72, '═');
+ final String b2 = StringUtils.rightPad("", 72, '─');
+ final String nl = "\r\n";
StringBuilder msg = new StringBuilder();
- msg.append("\r\n");
- msg.append(" Hi ");
+ msg.append(nl);
+ msg.append(b1);
+ msg.append(nl);
+ msg.append(" ");
+ msg.append(com.gitblit.Constants.getGitBlitVersion());
+ msg.append(nl);
+ msg.append(b1);
+ msg.append(nl);
+ msg.append(nl);
+ msg.append(" Hi ");
msg.append(user.getDisplayName());
- msg.append(", you have successfully connected to Gitblit over SSH.");
- msg.append("\r\n");
- msg.append("\r\n");
+ msg.append(", you have successfully connected over SSH.");
+ msg.append(nl);
+ msg.append(" Interactive shells are not available.");
+ msg.append(nl);
+ msg.append(nl);
+ msg.append(" client: ");
+ msg.append(session.getClientVersion());
+ msg.append(nl);
+ msg.append(nl);
- msg.append(" You may clone a repository with the following Git syntax:\r\n");
- msg.append("\r\n");
+ msg.append(b2);
+ msg.append(nl);
+ msg.append(nl);
+ msg.append(" You may clone a repository with the following Git syntax:");
+ msg.append(nl);
+ msg.append(nl);
- msg.append(" git clone ");
- msg.append(formatUrl(user.username));
- msg.append("\r\n");
- msg.append("\r\n");
+ msg.append(" git clone ");
+ msg.append(formatUrl(hostname, port, user.username));
+ msg.append(nl);
+ msg.append(nl);
+
+ msg.append(b2);
+ msg.append(nl);
+ msg.append(nl);
+
+ if (client.getKey() == null) {
+ // user has authenticated with a password
+ // display add public key instructions
+ msg.append(" You may upload an SSH public key with the following syntax:");
+ msg.append(nl);
+ msg.append(nl);
+
+ msg.append(String.format(" cat ~/.ssh/id_rsa.pub | ssh -l %s -p %d %s keys add", user.username, port, hostname));
+ msg.append(nl);
+ msg.append(nl);
+
+ msg.append(b2);
+ msg.append(nl);
+ msg.append(nl);
+ }
+
+ // display the core commands
+ SshCommandFactory cmdFactory = (SshCommandFactory) session.getFactoryManager().getCommandFactory();
+ DispatchCommand root = cmdFactory.createRootDispatcher(client, "");
+ String usage = root.usage().replace("\n", nl);
+ msg.append(usage);
return msg.toString();
}
- private String formatUrl(String username) {
+ private String getHostname() {
String host = null;
String url = settings.getString(Keys.web.canonicalUrl, "https://localhost:8443");
if (url != null) {
@@ -141,15 +196,17 @@
if (StringUtils.isEmpty(host)) {
host = SystemReader.getInstance().getHostname();
}
+ return host;
+ }
- int port = settings.getInteger(Keys.git.sshPort, 0);
+ private String formatUrl(String hostname, int port, String username) {
if (port == 22) {
// standard port
- return MessageFormat.format("{0}@{1}/REPOSITORY.git", username, host);
+ return MessageFormat.format("{0}@{1}/REPOSITORY.git", username, hostname);
} else {
// non-standard port
return MessageFormat.format("ssh://{0}@{1}:{2,number,0}/REPOSITORY.git",
- username, host, port);
+ username, hostname, port);
}
}
}
--
Gitblit v1.9.1