| | |
| | | import java.text.MessageFormat;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | |
| | | import org.eclipse.jgit.errors.ConfigInvalidException;
|
| | | import org.eclipse.jgit.lib.StoredConfig;
|
| | | import org.eclipse.jgit.storage.file.FileBasedConfig;
|
| | | import org.eclipse.jgit.util.Base64;
|
| | | import org.eclipse.jgit.util.FS;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.models.FeedModel;
|
| | | import com.gitblit.utils.Base64;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | | /**
|
| | |
| | | public class GitblitManager extends JFrame implements RegistrationsDialog.RegistrationListener {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | | private static final String SERVER = "server";
|
| | | private static final String FEED = "feed";
|
| | | private final SimpleDateFormat dateFormat;
|
| | | private JTabbedPane serverTabs;
|
| | | private File configFile = new File(System.getProperty("user.home"), ".gitblit/config");
|
| | |
| | | EditRegistrationDialog dialog = new EditRegistrationDialog(this, reg, true);
|
| | | dialog.setLocationRelativeTo(GitblitManager.this);
|
| | | dialog.setVisible(true);
|
| | | reg = dialog.getRegistration();
|
| | | if (reg == null) {
|
| | | GitblitRegistration newReg = dialog.getRegistration();
|
| | | if (newReg == null) {
|
| | | // user canceled
|
| | | return;
|
| | | }
|
| | | // preserve feeds
|
| | | newReg.feeds.addAll(reg.feeds);
|
| | |
|
| | | // use new reg
|
| | | reg = newReg;
|
| | | }
|
| | |
|
| | | // login
|
| | |
| | | private void loadRegistrations() {
|
| | | try {
|
| | | StoredConfig config = getConfig();
|
| | | Set<String> servers = config.getSubsections("servers");
|
| | | Set<String> servers = config.getSubsections(SERVER);
|
| | | for (String server : servers) {
|
| | | Date lastLogin = new Date(0);
|
| | | String date = config.getString("servers", server, "lastLogin");
|
| | | String date = config.getString(SERVER, server, "lastLogin");
|
| | | if (!StringUtils.isEmpty(date)) {
|
| | | lastLogin = dateFormat.parse(date);
|
| | | }
|
| | | String url = config.getString("servers", server, "url");
|
| | | String account = config.getString("servers", server, "account");
|
| | | String url = config.getString(SERVER, server, "url");
|
| | | String account = config.getString(SERVER, server, "account");
|
| | | char[] password;
|
| | | String pw = config.getString("servers", server, "password");
|
| | | String pw = config.getString(SERVER, server, "password");
|
| | | if (StringUtils.isEmpty(pw)) {
|
| | | password = new char[0];
|
| | | } else {
|
| | | password = new String(Base64.decode(pw)).toCharArray();
|
| | | }
|
| | | GitblitRegistration reg = new GitblitRegistration(server, url, account, password);
|
| | | String[] feeds = config.getStringList("servers", server, "feeds");
|
| | | String[] feeds = config.getStringList(SERVER, server, FEED);
|
| | | if (feeds != null) {
|
| | | reg.feeds = new ArrayList<String>(Arrays.asList(feeds));
|
| | | // deserialize the field definitions
|
| | | for (String definition : feeds) {
|
| | | FeedModel feed = new FeedModel(definition);
|
| | | reg.feeds.add(feed);
|
| | | }
|
| | | }
|
| | | reg.lastLogin = lastLogin;
|
| | | registrations.put(reg.name, reg);
|
| | |
| | | if (!StringUtils.isEmpty(name) && !name.equals(reg.name)) {
|
| | | // delete old registration
|
| | | registrations.remove(name);
|
| | | config.unsetSection("servers", name);
|
| | | config.unsetSection(SERVER, name);
|
| | | }
|
| | |
|
| | | // update registration
|
| | | config.setString("servers", reg.name, "url", reg.url);
|
| | | config.setString("servers", reg.name, "account", reg.account);
|
| | | config.setString(SERVER, reg.name, "url", reg.url);
|
| | | config.setString(SERVER, reg.name, "account", reg.account);
|
| | | if (reg.savePassword) {
|
| | | config.setString("servers", reg.name, "password",
|
| | | config.setString(SERVER, reg.name, "password",
|
| | | Base64.encodeBytes(new String(reg.password).getBytes("UTF-8")));
|
| | | } else {
|
| | | config.setString("servers", reg.name, "password", "");
|
| | | config.setString(SERVER, reg.name, "password", "");
|
| | | }
|
| | | if (reg.lastLogin != null) {
|
| | | config.setString("servers", reg.name, "lastLogin", dateFormat.format(reg.lastLogin));
|
| | | config.setString(SERVER, reg.name, "lastLogin", dateFormat.format(reg.lastLogin));
|
| | | }
|
| | | if (reg.feeds != null) {
|
| | | config.setStringList("servers", reg.name, "feeds", reg.feeds);
|
| | | // serialize the feed definitions
|
| | | List<String> definitions = new ArrayList<String>();
|
| | | for (FeedModel feed : reg.feeds) {
|
| | | definitions.add(feed.toString());
|
| | | }
|
| | | if (definitions.size() > 0) {
|
| | | config.setStringList(SERVER, reg.name, FEED, definitions);
|
| | | }
|
| | | config.save();
|
| | | return true;
|
| | |
| | | try {
|
| | | StoredConfig config = getConfig();
|
| | | for (GitblitRegistration reg : list) {
|
| | | config.unsetSection("servers", reg.name);
|
| | | config.unsetSection(SERVER, reg.name);
|
| | | registrations.remove(reg.name);
|
| | | }
|
| | | config.save();
|