| | |
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import org.apache.wicket.Application;
|
| | | import org.apache.wicket.MarkupContainer;
|
| | | import org.apache.wicket.Page;
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.RedirectToUrlException;
|
| | | import org.apache.wicket.RestartResponseException;
|
| | | import org.apache.wicket.markup.html.CSSPackageResource;
|
| | | import org.apache.wicket.markup.html.basic.Label;
|
| | | import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
| | | import org.apache.wicket.markup.html.link.ExternalLink;
|
| | | import org.apache.wicket.markup.html.panel.FeedbackPanel;
|
| | | import org.apache.wicket.markup.html.panel.Fragment;
|
| | | import org.apache.wicket.protocol.http.RequestUtils;
|
| | | import org.apache.wicket.protocol.http.WebResponse;
|
| | | import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
|
| | | import org.apache.wicket.util.time.Duration;
|
| | | import org.apache.wicket.util.time.Time;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | |
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.utils.TimeUtils;
|
| | | import com.gitblit.wicket.CacheControl;
|
| | | import com.gitblit.wicket.GitBlitWebApp;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.LinkPanel;
|
| | |
|
| | | public abstract class BasePage extends SessionPage {
|
| | |
|
| | | private final Logger logger;
|
| | | |
| | |
|
| | | private transient TimeUtils timeUtils;
|
| | |
|
| | | public BasePage() {
|
| | |
| | | logger = LoggerFactory.getLogger(getClass());
|
| | | customizeHeader();
|
| | | }
|
| | | |
| | |
|
| | | private void customizeHeader() {
|
| | | if (GitBlit.getBoolean(Keys.web.useResponsiveLayout, true)) {
|
| | | add(CSSPackageResource.getHeaderContribution("bootstrap/css/bootstrap-responsive.css"));
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | protected String getCanonicalUrl() {
|
| | | return getCanonicalUrl(getClass(), getPageParameters());
|
| | | }
|
| | |
|
| | | protected String getCanonicalUrl(Class<? extends BasePage> clazz, PageParameters params) {
|
| | | String relativeUrl = urlFor(clazz, params).toString();
|
| | | String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
|
| | | return canonicalUrl;
|
| | | }
|
| | |
|
| | | protected String getLanguageCode() {
|
| | | return GitBlitWebSession.get().getLocale().getLanguage();
|
| | | }
|
| | | |
| | |
|
| | | protected String getCountryCode() {
|
| | | return GitBlitWebSession.get().getLocale().getCountry().toLowerCase();
|
| | | }
|
| | | |
| | |
|
| | | protected TimeUtils getTimeUtils() {
|
| | | if (timeUtils == null) {
|
| | | ResourceBundle bundle; |
| | | ResourceBundle bundle;
|
| | | try {
|
| | | bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp", GitBlitWebSession.get().getLocale());
|
| | | } catch (Throwable t) {
|
| | | bundle = ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp");
|
| | | }
|
| | | timeUtils = new TimeUtils(bundle);
|
| | | timeUtils = new TimeUtils(bundle, getTimeZone());
|
| | | }
|
| | | return timeUtils;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | protected void onBeforeRender() {
|
| | | if (GitBlit.isDebugMode()) {
|
| | |
| | | Application.get().getMarkupSettings().setStripWicketTags(false);
|
| | | }
|
| | | super.onAfterRender();
|
| | | } |
| | | }
|
| | |
|
| | | @Override
|
| | | protected void setHeaders(WebResponse response) {
|
| | | // set canonical link as http header for SEO (issue-304)
|
| | | // https://support.google.com/webmasters/answer/139394?hl=en
|
| | | response.setHeader("Link" ,MessageFormat.format("<{0}>; rel=\"canonical\"", getCanonicalUrl()));
|
| | | int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0);
|
| | | if (expires > 0) {
|
| | | // pages are personalized for the authenticated user so they must be
|
| | | // marked private to prohibit proxy servers from caching them
|
| | | response.setHeader("Cache-Control", "private, must-revalidate");
|
| | | setLastModified();
|
| | | } else {
|
| | | // use default Wicket caching behavior
|
| | | super.setHeaders(response);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Sets the last-modified header date, if appropriate, for this page. The
|
| | | * date used is determined by the CacheControl annotation.
|
| | | *
|
| | | */
|
| | | protected void setLastModified() {
|
| | | if (getClass().isAnnotationPresent(CacheControl.class)) {
|
| | | CacheControl cacheControl = getClass().getAnnotation(CacheControl.class);
|
| | | switch (cacheControl.value()) {
|
| | | case ACTIVITY:
|
| | | setLastModified(GitBlit.getLastActivityDate());
|
| | | break;
|
| | | case BOOT:
|
| | | setLastModified(GitBlit.getBootDate());
|
| | | break;
|
| | | case NONE:
|
| | | break;
|
| | | default:
|
| | | logger.warn(getClass().getSimpleName() + ": unhandled LastModified type " + cacheControl.value());
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Sets the last-modified header field and the expires field.
|
| | | *
|
| | | * @param when
|
| | | */
|
| | | protected final void setLastModified(Date when) {
|
| | | if (when == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | if (when.before(GitBlit.getBootDate())) {
|
| | | // last-modified can not be before the Gitblit boot date
|
| | | // this helps ensure that pages are properly refreshed after a
|
| | | // server config change
|
| | | when = GitBlit.getBootDate();
|
| | | }
|
| | |
|
| | | int expires = GitBlit.getInteger(Keys.web.pageCacheExpires, 0);
|
| | | WebResponse response = (WebResponse) getResponse();
|
| | | response.setLastModifiedTime(Time.valueOf(when));
|
| | | response.setDateHeader("Expires", System.currentTimeMillis() + Duration.minutes(expires).getMilliseconds());
|
| | | }
|
| | |
|
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | String siteName = GitBlit.getString(Keys.web.siteName, Constants.NAME);
|
| | | if (StringUtils.isEmpty(siteName)) {
|
| | | siteName = Constants.NAME;
|
| | | }
|
| | | if (repositoryName != null && repositoryName.trim().length() > 0) {
|
| | | add(new Label("title", repositoryName + " - " + siteName));
|
| | | } else {
|
| | | add(new Label("title", siteName));
|
| | | }
|
| | |
|
| | | ExternalLink rootLink = new ExternalLink("rootLink", urlFor(RepositoriesPage.class, null).toString());
|
| | | WicketUtils.setHtmlTooltip(rootLink, siteName);
|
| | | String rootLinkUrl = GitBlit.getString(Keys.web.rootLink, urlFor(GitBlitWebApp.HOME_PAGE_CLASS, null).toString());
|
| | | ExternalLink rootLink = new ExternalLink("rootLink", rootLinkUrl);
|
| | | WicketUtils.setHtmlTooltip(rootLink, GitBlit.getString(Keys.web.siteName, Constants.NAME));
|
| | | add(rootLink);
|
| | |
|
| | | // Feedback panel for info, warning, and non-fatal error messages
|
| | | add(new FeedbackPanel("feedback"));
|
| | |
|
| | | // footer
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateViewPages, true)
|
| | | || GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | UserFragment userFragment = new UserFragment("userPanel", "userFragment", BasePage.this);
|
| | | add(userFragment);
|
| | | } else {
|
| | | add(new Label("userPanel", ""));
|
| | | }
|
| | |
|
| | | add(new Label("gbVersion", "v" + Constants.getVersion()));
|
| | | if (GitBlit.getBoolean(Keys.web.aggressiveHeapManagement, false)) {
|
| | |
| | | }
|
| | | return map;
|
| | | }
|
| | | |
| | |
|
| | | protected Map<AccessPermission, String> getAccessPermissions() {
|
| | | Map<AccessPermission, String> map = new LinkedHashMap<AccessPermission, String>();
|
| | | for (AccessPermission type : AccessPermission.values()) {
|
| | |
| | | }
|
| | | return map;
|
| | | }
|
| | | |
| | |
|
| | | protected Map<FederationStrategy, String> getFederationTypes() {
|
| | | Map<FederationStrategy, String> map = new LinkedHashMap<FederationStrategy, String>();
|
| | | for (FederationStrategy type : FederationStrategy.values()) {
|
| | |
| | | }
|
| | | return map;
|
| | | }
|
| | | |
| | |
|
| | | protected Map<AuthorizationControl, String> getAuthorizationControls() {
|
| | | Map<AuthorizationControl, String> map = new LinkedHashMap<AuthorizationControl, String>();
|
| | | for (AuthorizationControl type : AuthorizationControl.values()) {
|
| | |
| | | HttpServletRequest req = servletWebRequest.getHttpServletRequest();
|
| | | return req.getServerName();
|
| | | }
|
| | | |
| | |
|
| | | protected List<ProjectModel> getProjectModels() {
|
| | | final UserModel user = GitBlitWebSession.get().getUser();
|
| | | List<ProjectModel> projects = GitBlit.self().getProjectModels(user, true);
|
| | | return projects;
|
| | | }
|
| | | |
| | |
|
| | | protected List<ProjectModel> getProjects(PageParameters params) {
|
| | | if (params == null) {
|
| | | return getProjectModels();
|
| | |
| | | String regex = WicketUtils.getRegEx(params);
|
| | | String team = WicketUtils.getTeam(params);
|
| | | int daysBack = params.getInt("db", 0);
|
| | | int maxDaysBack = GitBlit.getInteger(Keys.web.activityDurationMaximum, 30);
|
| | |
|
| | | List<ProjectModel> availableModels = getProjectModels();
|
| | | Set<ProjectModel> models = new HashSet<ProjectModel>();
|
| | |
| | |
|
| | | // time-filter the list
|
| | | if (daysBack > 0) {
|
| | | if (maxDaysBack > 0 && daysBack > maxDaysBack) {
|
| | | daysBack = maxDaysBack;
|
| | | }
|
| | | Calendar cal = Calendar.getInstance();
|
| | | cal.set(Calendar.HOUR_OF_DAY, 0);
|
| | | cal.set(Calendar.MINUTE, 0);
|
| | |
| | | public void warn(String message, Throwable t) {
|
| | | logger.warn(message, t);
|
| | | }
|
| | | |
| | |
|
| | | public void error(String message, boolean redirect) {
|
| | | logger.error(message + " for " + GitBlitWebSession.get().getUsername());
|
| | | if (redirect) {
|
| | | GitBlitWebSession.get().cacheErrorMessage(message);
|
| | | String relativeUrl = urlFor(RepositoriesPage.class, null).toString();
|
| | | String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
|
| | | throw new RedirectToUrlException(absoluteUrl);
|
| | | } else {
|
| | | super.error(message);
|
| | | }
|
| | | error(message, null, redirect ? getApplication().getHomePage() : null);
|
| | | }
|
| | |
|
| | | public void error(String message, Throwable t, boolean redirect) {
|
| | | logger.error(message, t);
|
| | | if (redirect) {
|
| | | error(message, t, getApplication().getHomePage());
|
| | | }
|
| | |
|
| | | public void error(String message, Throwable t, Class<? extends Page> toPage) {
|
| | | error(message, t, toPage, null);
|
| | | }
|
| | |
|
| | | public void error(String message, Throwable t, Class<? extends Page> toPage, PageParameters params) {
|
| | | if (t == null) {
|
| | | logger.error(message + " for " + GitBlitWebSession.get().getUsername());
|
| | | } else {
|
| | | logger.error(message + " for " + GitBlitWebSession.get().getUsername(), t);
|
| | | }
|
| | | if (toPage != null) {
|
| | | GitBlitWebSession.get().cacheErrorMessage(message);
|
| | | throw new RestartResponseException(getApplication().getHomePage());
|
| | | String relativeUrl = urlFor(toPage, params).toString();
|
| | | String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
|
| | | throw new RedirectToUrlException(absoluteUrl);
|
| | | } else {
|
| | | super.error(message);
|
| | | }
|
| | |
| | | GitBlitWebSession.get().cacheRequest(getClass());
|
| | | }
|
| | | error(message, true);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Panel fragment for displaying login or logout/change_password links.
|
| | | * |
| | | */
|
| | | static class UserFragment extends Fragment {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public UserFragment(String id, String markupId, MarkupContainer markupProvider) {
|
| | | super(id, markupId, markupProvider);
|
| | |
|
| | | GitBlitWebSession session = GitBlitWebSession.get();
|
| | | if (session.isLoggedIn()) { |
| | | UserModel user = session.getUser();
|
| | | boolean editCredentials = GitBlit.self().supportsCredentialChanges(user);
|
| | | boolean standardLogin = session.authenticationType.isStandard();
|
| | |
|
| | | // username, logout, and change password
|
| | | add(new Label("username", user.getDisplayName() + ":"));
|
| | | add(new LinkPanel("loginLink", null, markupProvider.getString("gb.logout"),
|
| | | LogoutPage.class).setVisible(standardLogin));
|
| | | |
| | | // quick and dirty hack for showing a separator
|
| | | add(new Label("separator", "|").setVisible(standardLogin && editCredentials));
|
| | | add(new BookmarkablePageLink<Void>("changePasswordLink", |
| | | ChangePasswordPage.class).setVisible(editCredentials));
|
| | | } else {
|
| | | // login
|
| | | add(new Label("username").setVisible(false));
|
| | | add(new Label("loginLink").setVisible(false));
|
| | | add(new Label("separator").setVisible(false));
|
| | | add(new Label("changePasswordLink").setVisible(false));
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|