1 19 package org.jahia.admin.info; 20 21 import java.io.IOException ; 22 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpSession ; 27 28 import org.jahia.bin.Jahia; 29 import org.jahia.bin.JahiaAdministration; 30 import org.jahia.data.JahiaData; 31 import org.jahia.exceptions.JahiaException; 32 import org.jahia.params.ParamBean; 33 import org.jahia.registries.ServicesRegistry; 34 import org.jahia.resourcebundle.JahiaResourceBundle; 35 import org.jahia.utils.properties.PropertiesManager; 36 import org.jahia.security.license.License; 37 import org.jahia.security.license.Limit; 38 import org.jahia.security.license.DaysLeftValidator; 39 import java.util.Date ; 40 41 42 52 public class LicenseInfo 53 { 54 private static org.apache.log4j.Logger logger = 55 org.apache.log4j.Logger.getLogger(LicenseInfo.class); 56 57 private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; 58 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 59 60 private static ServicesRegistry sReg; 61 62 private License coreLicense; 63 64 65 66 73 public LicenseInfo( HttpServletRequest request, 74 HttpServletResponse response, 75 HttpSession session ) 76 77 throws Throwable 78 { 79 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 80 ParamBean jParams = null; 81 if (jData != null) { 82 jParams = jData.params(); 83 } 84 coreLicense = Jahia.getCoreLicense(); 85 if ( coreLicense == null ){ 86 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.invalidLicenseKey.label", 88 jParams, jParams.getLocale()); 89 request.setAttribute("jahiaDisplayMessage", dspMsg); 90 JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); 92 return; 93 } 94 95 displayLicenseInfo( request, response, session ); 96 } 98 99 106 private void displayLicenseInfo( HttpServletRequest req, 107 HttpServletResponse res, 108 HttpSession sess ) 109 throws IOException , ServletException 110 { 111 112 JahiaData jData = (JahiaData) req.getAttribute("org.jahia.data.JahiaData"); 113 ParamBean jParams = null; 114 if (jData != null) { 115 jParams = jData.params(); 116 } 117 ServicesRegistry sReg = ServicesRegistry.getInstance(); 118 119 if (sReg != null) { 120 121 try { 122 int nbCurrentSites = sReg.getJahiaSitesService().getNbSites(); 123 int nbMaxSites = Jahia.getSiteLimit(); 124 int nbCurrentUsers = sReg.getJahiaUserManagerService().getNbUsers(); 125 int nbMaxUsers = Jahia.getUserLimit(); 126 int nbCurrentTemplates = sReg.getJahiaPageTemplateService().getNbPageTemplates(); 127 int nbMaxTemplates = Jahia.getTemplateLimit(); 128 int nbCurrentPages = sReg.getJahiaPageService().getRealActiveNbPages(); 129 int nbMaxPages = Jahia.getPageLimit(); 130 131 String maxSites = (nbMaxSites == -1) ? "unlimited" : Integer.toString(nbMaxSites); 132 String maxUsers = (nbMaxUsers == -1) ? "unlimited" : Integer.toString(nbMaxUsers); 133 String maxTemplates = (nbMaxTemplates == -1) ? "unlimited" : Integer.toString(nbMaxTemplates); 134 String maxPages = (nbMaxPages == -1) ? "unlimited" : Integer.toString(nbMaxPages); 135 136 Limit daysLeftLimit = Jahia.getCoreLicense().getLimit("maxUsageDays"); 137 if (daysLeftLimit != null) { 140 DaysLeftValidator daysLeftValidator = (DaysLeftValidator) 141 daysLeftLimit.getValidator(); 142 int maxDays = Integer.parseInt(daysLeftLimit.getValueStr()); 143 req.setAttribute("allowedDays", new Integer (maxDays)); 144 long expirationTime = daysLeftValidator. 145 getComponentInstallDate().getTime() + 146 1000L * 60L * 60L * 24L * maxDays; 147 Date expirationDate = new Date (expirationTime); 148 req.setAttribute("expirationDate", expirationDate); 149 } 150 151 req.setAttribute("nbCurrentSites", Integer.toString(nbCurrentSites) ); 152 req.setAttribute("nbMaxSites", maxSites ); 153 req.setAttribute("nbCurrentUsers", Integer.toString(nbCurrentUsers) ); 154 req.setAttribute("nbMaxUsers", maxUsers ); 155 req.setAttribute("nbCurrentTemplates", Integer.toString(nbCurrentTemplates) ); 156 req.setAttribute("nbMaxTemplates", maxTemplates ); 157 req.setAttribute("nbCurrentPages", Integer.toString(nbCurrentPages) ); 158 req.setAttribute("nbMaxPages", maxPages ); 159 PropertiesManager pm = new PropertiesManager(Jahia.getJahiaPropertiesFileName()); 160 req.setAttribute("release", pm.getProperty("release")); 161 req.setAttribute("build", Integer.toString(Jahia.BUILD_NUMBER) ); 162 JahiaAdministration.doRedirect( req, res, sess, JSP_PATH + "show_info.jsp" ); 163 164 } catch (JahiaException je) { 165 logger.debug("Error while retrieving license information", je); 166 167 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.jahiaServicesProblem.label", 168 jParams, jParams.getLocale()); 169 sess.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 170 JahiaAdministration.displayMenu( req, res, sess ); } 172 173 } else { 174 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.noServicesRegistry.label", 175 jParams, jParams.getLocale()); 176 sess.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 177 JahiaAdministration.displayMenu( req, res, sess ); } 179 180 } 182 183 } | Popular Tags |