| | |
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | |
|
| | | import com.gitblit.Constants.RpcRequest;
|
| | | import com.gitblit.models.RefModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.SettingModel;
|
| | | import com.gitblit.models.ServerSettings;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.HttpUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.RpcUtils;
|
| | |
|
| | | /**
|
| | |
| | |
|
| | | UserModel user = (UserModel) request.getUserPrincipal();
|
| | |
|
| | | boolean allowManagement = user != null && user.canAdmin
|
| | | && GitBlit.getBoolean(Keys.web.enableRpcManagement, false);
|
| | |
|
| | | boolean allowAdmin = user != null && user.canAdmin
|
| | | && GitBlit.getBoolean(Keys.web.enableRpcAdministration, false);
|
| | |
|
| | | Object result = null;
|
| | | if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {
|
| | | // Determine the Gitblit clone url
|
| | |
| | | repositories.put(url, model);
|
| | | }
|
| | | result = repositories;
|
| | | } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {
|
| | | // list all local branches in all repositories accessible to user
|
| | | Map<String, List<String>> localBranches = new HashMap<String, List<String>>();
|
| | | List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);
|
| | | for (RepositoryModel model : models) {
|
| | | if (!model.hasCommits) {
|
| | | // skip empty repository
|
| | | continue;
|
| | | }
|
| | | // get local branches
|
| | | Repository repository = GitBlit.self().getRepository(model.name);
|
| | | List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);
|
| | | if (model.showRemoteBranches) {
|
| | | // add remote branches if repository displays them
|
| | | refs.addAll(JGitUtils.getRemoteBranches(repository, false, -1));
|
| | | }
|
| | | if (refs.size() > 0) {
|
| | | List<String> branches = new ArrayList<String>();
|
| | | for (RefModel ref : refs) {
|
| | | branches.add(ref.getName());
|
| | | }
|
| | | localBranches.put(model.name, branches);
|
| | | }
|
| | | repository.close();
|
| | | }
|
| | | result = localBranches;
|
| | | } else if (RpcRequest.LIST_USERS.equals(reqType)) {
|
| | | // list users
|
| | | List<String> names = GitBlit.self().getAllUsernames();
|
| | |
| | | }
|
| | | } else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {
|
| | | // return the list of federation registrations
|
| | | result = GitBlit.self().getFederationRegistrations();
|
| | | if (allowAdmin) {
|
| | | result = GitBlit.self().getFederationRegistrations();
|
| | | } else {
|
| | | response.sendError(notAllowedCode);
|
| | | }
|
| | | } else if (RpcRequest.LIST_FEDERATION_RESULTS.equals(reqType)) {
|
| | | // return the list of federation result registrations
|
| | | if (GitBlit.canFederate()) {
|
| | | if (allowAdmin && GitBlit.canFederate()) {
|
| | | result = GitBlit.self().getFederationResultRegistrations();
|
| | | } else {
|
| | | response.sendError(notAllowedCode);
|
| | | }
|
| | | } else if (RpcRequest.LIST_FEDERATION_PROPOSALS.equals(reqType)) {
|
| | | // return the list of federation proposals
|
| | | if (GitBlit.canFederate()) {
|
| | | if (allowAdmin && GitBlit.canFederate()) {
|
| | | result = GitBlit.self().getPendingFederationProposals();
|
| | | } else {
|
| | | response.sendError(notAllowedCode);
|
| | | }
|
| | | } else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {
|
| | | // return the list of federation sets
|
| | | if (GitBlit.canFederate()) {
|
| | | if (allowAdmin && GitBlit.canFederate()) {
|
| | | String gitblitUrl = HttpUtils.getGitblitURL(request);
|
| | | result = GitBlit.self().getFederationSets(gitblitUrl);
|
| | | } else {
|
| | |
| | | }
|
| | | } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {
|
| | | // return the server's settings
|
| | | if (GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {
|
| | | result = GitBlit.self().getSettingsModel();
|
| | | ServerSettings settings = GitBlit.self().getSettingsModel();
|
| | | if (allowAdmin) {
|
| | | // return all settings
|
| | | result = settings;
|
| | | } else {
|
| | | response.sendError(notAllowedCode);
|
| | | // anonymous users get a few settings to allow browser launching
|
| | | List<String> keys = new ArrayList<String>();
|
| | | keys.add(Keys.web.siteName);
|
| | | keys.add(Keys.web.mountParameters);
|
| | | keys.add(Keys.web.syndicationEntries);
|
| | | |
| | | if (allowManagement) {
|
| | | // keys necessary for repository and/or user management
|
| | | keys.add(Keys.realm.minPasswordLength);
|
| | | keys.add(Keys.realm.passwordStorage);
|
| | | keys.add(Keys.federation.sets);
|
| | | }
|
| | | // build the settings
|
| | | ServerSettings managementSettings = new ServerSettings();
|
| | | for (String key : keys) {
|
| | | managementSettings.add(settings.get(key));
|
| | | }
|
| | | result = managementSettings;
|
| | | }
|
| | | } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {
|
| | | // update settings on the server
|
| | | if (GitBlit.getBoolean(Keys.web.enableRpcAdministration, false)) {
|
| | | Collection<SettingModel> settings = deserialize(request, response,
|
| | | if (allowAdmin) {
|
| | | Map<String, String> settings = deserialize(request, response,
|
| | | RpcUtils.SETTINGS_TYPE);
|
| | | GitBlit.self().updateSettings(settings);
|
| | | } else {
|
| | |
| | | }
|
| | | } else if (RpcRequest.LIST_STATUS.equals(reqType)) {
|
| | | // return the server's status information
|
| | | result = GitBlit.self().getStatus();
|
| | | if (allowAdmin) {
|
| | | result = GitBlit.self().getStatus();
|
| | | } else {
|
| | | response.sendError(notAllowedCode);
|
| | | }
|
| | | }
|
| | |
|
| | | // send the result of the request
|