-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit;\r
-\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.List;\r
-\r
-import org.kohsuke.args4j.CmdLineException;\r
-import org.kohsuke.args4j.CmdLineParser;\r
-import org.kohsuke.args4j.Option;\r
-\r
-import com.gitblit.manager.FederationManager;\r
-import com.gitblit.manager.GitblitManager;\r
-import com.gitblit.manager.IGitblit;\r
-import com.gitblit.manager.INotificationManager;\r
-import com.gitblit.manager.RepositoryManager;\r
-import com.gitblit.manager.RuntimeManager;\r
-import com.gitblit.manager.UserManager;\r
-import com.gitblit.models.FederationModel;\r
-import com.gitblit.models.Mailing;\r
-import com.gitblit.service.FederationPullService;\r
-import com.gitblit.utils.FederationUtils;\r
-import com.gitblit.utils.StringUtils;\r
-import com.gitblit.utils.XssFilter;\r
-import com.gitblit.utils.XssFilter.AllowXssFilter;\r
-\r
-/**\r
- * Command-line client to pull federated Gitblit repositories.\r
- *\r
- * @author James Moger\r
- *\r
- */\r
-public class FederationClient {\r
-\r
- public static void main(String[] args) {\r
- Params params = new Params();\r
- CmdLineParser parser = new CmdLineParser(params);\r
- try {\r
- parser.parseArgument(args);\r
- } catch (CmdLineException t) {\r
- usage(parser, t);\r
- }\r
-\r
- System.out.println("Gitblit Federation Client v" + Constants.getVersion() + " (" + Constants.getBuildDate() + ")");\r
-\r
- // command-line specified base folder\r
- File baseFolder = new File(System.getProperty("user.dir"));\r
- if (!StringUtils.isEmpty(params.baseFolder)) {\r
- baseFolder = new File(params.baseFolder);\r
- }\r
-\r
- File regFile = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, baseFolder, params.registrationsFile);\r
- FileSettings settings = new FileSettings(regFile.getAbsolutePath());\r
- List<FederationModel> registrations = new ArrayList<FederationModel>();\r
- if (StringUtils.isEmpty(params.url)) {\r
- registrations.addAll(FederationUtils.getFederationRegistrations(settings));\r
- } else {\r
- if (StringUtils.isEmpty(params.token)) {\r
- System.out.println("Must specify --token parameter!");\r
- System.exit(0);\r
- }\r
- FederationModel model = new FederationModel("Gitblit");\r
- model.url = params.url;\r
- model.token = params.token;\r
- model.mirror = params.mirror;\r
- model.bare = params.bare;\r
- model.folder = "";\r
- registrations.add(model);\r
- }\r
- if (registrations.size() == 0) {\r
- System.out.println("No Federation Registrations! Nothing to do.");\r
- System.exit(0);\r
- }\r
-\r
- // command-line specified repositories folder\r
- if (!StringUtils.isEmpty(params.repositoriesFolder)) {\r
- settings.overrideSetting(Keys.git.repositoriesFolder, new File(\r
- params.repositoriesFolder).getAbsolutePath());\r
- }\r
-\r
- // configure the Gitblit singleton for minimal, non-server operation\r
- XssFilter xssFilter = new AllowXssFilter();\r
- RuntimeManager runtime = new RuntimeManager(settings, xssFilter, baseFolder).start();\r
- NoopNotificationManager notifications = new NoopNotificationManager().start();\r
- UserManager users = new UserManager(runtime, null).start();\r
- RepositoryManager repositories = new RepositoryManager(runtime, null, users).start();\r
- FederationManager federation = new FederationManager(runtime, notifications, repositories).start();\r
- IGitblit gitblit = new GitblitManager(runtime, null, notifications, users, null, null, repositories, null, federation);\r
-\r
- FederationPullService puller = new FederationPullService(gitblit, federation.getFederationRegistrations()) {\r
- @Override\r
- public void reschedule(FederationModel registration) {\r
- // NOOP\r
- }\r
- };\r
- puller.run();\r
-\r
- System.out.println("Finished.");\r
- System.exit(0);\r
- }\r
-\r
- private static void usage(CmdLineParser parser, CmdLineException t) {\r
- System.out.println(Constants.getGitBlitVersion());\r
- System.out.println();\r
- if (t != null) {\r
- System.out.println(t.getMessage());\r
- System.out.println();\r
- }\r
-\r
- if (parser != null) {\r
- parser.printUsage(System.out);\r
- }\r
- System.exit(0);\r
- }\r
-\r
- /**\r
- * Parameters class for FederationClient.\r
- */\r
- private static class Params {\r
-\r
- @Option(name = "--registrations", usage = "Gitblit Federation Registrations File", metaVar = "FILE")\r
- public String registrationsFile = "${baseFolder}/federation.properties";\r
-\r
- @Option(name = "--url", usage = "URL of Gitblit instance to mirror from", metaVar = "URL")\r
- public String url;\r
-\r
- @Option(name = "--mirror", usage = "Mirror repositories")\r
- public boolean mirror;\r
-\r
- @Option(name = "--bare", usage = "Create bare repositories")\r
- public boolean bare;\r
-\r
- @Option(name = "--token", usage = "Federation Token", metaVar = "TOKEN")\r
- public String token;\r
-\r
- @Option(name = "--baseFolder", usage = "Base folder for received data", metaVar = "PATH")\r
- public String baseFolder;\r
-\r
- @Option(name = "--repositoriesFolder", usage = "Destination folder for cloned repositories", metaVar = "PATH")\r
- public String repositoriesFolder;\r
-\r
- }\r
-\r
- private static class NoopNotificationManager implements INotificationManager {\r
-\r
- @Override\r
- public NoopNotificationManager start() {\r
- return this;\r
- }\r
-\r
- @Override\r
- public NoopNotificationManager stop() {\r
- return this;\r
- }\r
-\r
- @Override\r
- public boolean isSendingMail() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public void sendMailToAdministrators(String subject, String message) {\r
- }\r
-\r
- @Override\r
- public void sendMail(String subject, String message, Collection<String> toAddresses) {\r
- }\r
-\r
- @Override\r
- public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) {\r
- }\r
-\r
- @Override\r
- public void send(Mailing mailing) {\r
- }\r
- }\r
-}\r
+/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.Option;
+
+import com.gitblit.manager.FederationManager;
+import com.gitblit.manager.GitblitManager;
+import com.gitblit.manager.IGitblit;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.RepositoryManager;
+import com.gitblit.manager.RuntimeManager;
+import com.gitblit.manager.UserManager;
+import com.gitblit.models.FederationModel;
+import com.gitblit.models.Mailing;
+import com.gitblit.service.FederationPullService;
+import com.gitblit.utils.FederationUtils;
+import com.gitblit.utils.StringUtils;
++import com.gitblit.utils.XssFilter;
++import com.gitblit.utils.XssFilter.AllowXssFilter;
+
+/**
+ * Command-line client to pull federated Gitblit repositories.
+ *
+ * @author James Moger
+ *
+ */
+public class FederationClient {
+
+ public static void main(String[] args) {
+ Params params = new Params();
+ CmdLineParser parser = new CmdLineParser(params);
+ try {
+ parser.parseArgument(args);
+ } catch (CmdLineException t) {
+ usage(parser, t);
+ }
+
+ System.out.println("Gitblit Federation Client v" + Constants.getVersion() + " (" + Constants.getBuildDate() + ")");
+
+ // command-line specified base folder
+ File baseFolder = new File(System.getProperty("user.dir"));
+ if (!StringUtils.isEmpty(params.baseFolder)) {
+ baseFolder = new File(params.baseFolder);
+ }
+
+ File regFile = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, baseFolder, params.registrationsFile);
+ FileSettings settings = new FileSettings(regFile.getAbsolutePath());
+ List<FederationModel> registrations = new ArrayList<FederationModel>();
+ if (StringUtils.isEmpty(params.url)) {
+ registrations.addAll(FederationUtils.getFederationRegistrations(settings));
+ } else {
+ if (StringUtils.isEmpty(params.token)) {
+ System.out.println("Must specify --token parameter!");
+ System.exit(0);
+ }
+ FederationModel model = new FederationModel("Gitblit");
+ model.url = params.url;
+ model.token = params.token;
+ model.mirror = params.mirror;
+ model.bare = params.bare;
+ model.folder = "";
+ registrations.add(model);
+ }
+ if (registrations.size() == 0) {
+ System.out.println("No Federation Registrations! Nothing to do.");
+ System.exit(0);
+ }
+
+ // command-line specified repositories folder
+ if (!StringUtils.isEmpty(params.repositoriesFolder)) {
+ settings.overrideSetting(Keys.git.repositoriesFolder, new File(
+ params.repositoriesFolder).getAbsolutePath());
+ }
+
+ // configure the Gitblit singleton for minimal, non-server operation
- RuntimeManager runtime = new RuntimeManager(settings, baseFolder).start();
++ XssFilter xssFilter = new AllowXssFilter();
++ RuntimeManager runtime = new RuntimeManager(settings, xssFilter, baseFolder).start();
+ NoopNotificationManager notifications = new NoopNotificationManager().start();
+ UserManager users = new UserManager(runtime, null).start();
+ RepositoryManager repositories = new RepositoryManager(runtime, null, users).start();
+ FederationManager federation = new FederationManager(runtime, notifications, repositories).start();
+ IGitblit gitblit = new GitblitManager(null, null, runtime, null, notifications, users, null, repositories, null, federation);
+
+ FederationPullService puller = new FederationPullService(gitblit, federation.getFederationRegistrations()) {
+ @Override
+ public void reschedule(FederationModel registration) {
+ // NOOP
+ }
+ };
+ puller.run();
+
+ System.out.println("Finished.");
+ System.exit(0);
+ }
+
+ private static void usage(CmdLineParser parser, CmdLineException t) {
+ System.out.println(Constants.getGitBlitVersion());
+ System.out.println();
+ if (t != null) {
+ System.out.println(t.getMessage());
+ System.out.println();
+ }
+
+ if (parser != null) {
+ parser.printUsage(System.out);
+ }
+ System.exit(0);
+ }
+
+ /**
+ * Parameters class for FederationClient.
+ */
+ private static class Params {
+
+ @Option(name = "--registrations", usage = "Gitblit Federation Registrations File", metaVar = "FILE")
+ public String registrationsFile = "${baseFolder}/federation.properties";
+
+ @Option(name = "--url", usage = "URL of Gitblit instance to mirror from", metaVar = "URL")
+ public String url;
+
+ @Option(name = "--mirror", usage = "Mirror repositories")
+ public boolean mirror;
+
+ @Option(name = "--bare", usage = "Create bare repositories")
+ public boolean bare;
+
+ @Option(name = "--token", usage = "Federation Token", metaVar = "TOKEN")
+ public String token;
+
+ @Option(name = "--baseFolder", usage = "Base folder for received data", metaVar = "PATH")
+ public String baseFolder;
+
+ @Option(name = "--repositoriesFolder", usage = "Destination folder for cloned repositories", metaVar = "PATH")
+ public String repositoriesFolder;
+
+ }
+
+ private static class NoopNotificationManager implements INotificationManager {
+
+ @Override
+ public NoopNotificationManager start() {
+ return this;
+ }
+
+ @Override
+ public NoopNotificationManager stop() {
+ return this;
+ }
+
+ @Override
+ public boolean isSendingMail() {
+ return false;
+ }
+
+ @Override
+ public void sendMailToAdministrators(String subject, String message) {
+ }
+
+ @Override
+ public void sendMail(String subject, String message, Collection<String> toAddresses) {
+ }
+
+ @Override
+ public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) {
+ }
+
+ @Override
+ public void send(Mailing mailing) {
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.guice;
+
+import com.gitblit.FileSettings;
+import com.gitblit.GitBlit;
+import com.gitblit.IStoredSettings;
+import com.gitblit.manager.AuthenticationManager;
+import com.gitblit.manager.FederationManager;
+import com.gitblit.manager.IAuthenticationManager;
+import com.gitblit.manager.IFederationManager;
+import com.gitblit.manager.IGitblit;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
+import com.gitblit.manager.IProjectManager;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.IServicesManager;
+import com.gitblit.manager.IUserManager;
+import com.gitblit.manager.NotificationManager;
+import com.gitblit.manager.PluginManager;
+import com.gitblit.manager.ProjectManager;
+import com.gitblit.manager.RepositoryManager;
+import com.gitblit.manager.RuntimeManager;
+import com.gitblit.manager.ServicesManager;
+import com.gitblit.manager.UserManager;
+import com.gitblit.tickets.ITicketService;
+import com.gitblit.transport.ssh.IPublicKeyManager;
++import com.gitblit.utils.JSoupXssFilter;
+import com.gitblit.utils.WorkQueue;
++import com.gitblit.utils.XssFilter;
+import com.google.inject.AbstractModule;
+
+/**
+ * CoreModule references all the core business objects.
+ *
+ * @author James Moger
+ *
+ */
+public class CoreModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+
+ bind(IStoredSettings.class).toInstance(new FileSettings());
++ bind(XssFilter.class).to(JSoupXssFilter.class);
+
+ // bind complex providers
+ bind(IPublicKeyManager.class).toProvider(IPublicKeyManagerProvider.class);
+ bind(ITicketService.class).toProvider(ITicketServiceProvider.class);
+ bind(WorkQueue.class).toProvider(WorkQueueProvider.class);
+
+ // core managers
+ bind(IRuntimeManager.class).to(RuntimeManager.class);
+ bind(IPluginManager.class).to(PluginManager.class);
+ bind(INotificationManager.class).to(NotificationManager.class);
+ bind(IUserManager.class).to(UserManager.class);
+ bind(IAuthenticationManager.class).to(AuthenticationManager.class);
+ bind(IRepositoryManager.class).to(RepositoryManager.class);
+ bind(IProjectManager.class).to(ProjectManager.class);
+ bind(IFederationManager.class).to(FederationManager.class);
+
+ // the monolithic manager
+ bind(IGitblit.class).to(GitBlit.class);
+
+ // manager for long-running daemons and services
+ bind(IServicesManager.class).to(ServicesManager.class);
+ }
+}
--- /dev/null
+ /*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ package com.gitblit.utils;
+
+ import org.jsoup.Jsoup;
+ import org.jsoup.nodes.Document;
+ import org.jsoup.safety.Cleaner;
+ import org.jsoup.safety.Whitelist;
+
++import com.google.inject.Inject;
++import com.google.inject.Singleton;
++
+ /**
+ * Implementation of an XSS filter based on JSoup.
+ *
+ * @author James Moger
+ *
+ */
++@Singleton
+ public class JSoupXssFilter implements XssFilter {
+
+ private final Cleaner none;
+
+ private final Cleaner relaxed;
+
++ @Inject
+ public JSoupXssFilter() {
+ none = new Cleaner(Whitelist.none());
+ relaxed = new Cleaner(getRelaxedWhiteList());
+ }
+
+ @Override
+ public String none(String input) {
+ return clean(input, none);
+ }
+
+ @Override
+ public String relaxed(String input) {
+ return clean(input, relaxed);
+ }
+
+ protected String clean(String input, Cleaner cleaner) {
+ Document unsafe = Jsoup.parse(input);
+ Document safe = cleaner.clean(unsafe);
+ return safe.body().html();
+ }
+
+ /**
+ * Builds & returns a loose HTML whitelist similar to Github.
+ *
+ * https://github.com/github/markup/tree/master#html-sanitization
+ * @return a loose HTML whitelist
+ */
+ protected Whitelist getRelaxedWhiteList() {
+ return new Whitelist()
+ .addTags(
+ "a", "b", "blockquote", "br", "caption", "cite", "code", "col",
+ "colgroup", "dd", "del", "div", "dl", "dt", "em", "h1", "h2", "h3", "h4", "h5", "h6", "hr",
+ "i", "img", "ins", "kbd", "li", "ol", "p", "pre", "q", "samp", "small", "strike", "strong",
+ "sub", "sup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "tt", "u",
+ "ul", "var")
+
+ .addAttributes("a", "href", "title")
+ .addAttributes("blockquote", "cite")
+ .addAttributes("col", "span", "width")
+ .addAttributes("colgroup", "span", "width")
+ .addAttributes("img", "align", "alt", "height", "src", "title", "width")
+ .addAttributes("ol", "start", "type")
+ .addAttributes("q", "cite")
+ .addAttributes("table", "summary", "width")
+ .addAttributes("td", "abbr", "axis", "colspan", "rowspan", "width")
+ .addAttributes("th", "abbr", "axis", "colspan", "rowspan", "scope", "width")
+ .addAttributes("ul", "type")
+
+ .addEnforcedAttribute("a", "rel", "nofollow")
+ ;
+ }
+
+ }