1 19 package org.jahia.admin.jeffiles; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.Enumeration ; 24 import java.util.Hashtable ; 25 26 import javax.servlet.ServletException ; 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 import javax.servlet.http.HttpSession ; 30 31 import org.jahia.bin.Jahia; 32 import org.jahia.bin.JahiaAdministration; 33 import org.jahia.data.JahiaData; 34 import org.jahia.exceptions.JahiaException; 35 import org.jahia.params.ParamBean; 36 import org.jahia.registries.ServicesRegistry; 37 import org.jahia.resourcebundle.JahiaResourceBundle; 38 import org.jahia.services.jef.InvalidJefFileException; 39 import org.jahia.services.jef.JecFile; 40 import org.jahia.services.jef.JefFileConstants; 41 import org.jahia.services.jef.JefFileInvalidKeyValueException; 42 import org.jahia.services.jef.JefFileKeyNotFoundException; 43 import org.jahia.services.sites.JahiaSite; 44 import org.jahia.services.sites.JahiaSitesService; 45 import org.jahia.services.usermanager.JahiaUser; 46 import org.jahia.services.webapps_deployer.JahiaWebAppsDeployerService; 47 48 import org.jahia.security.license.License; 49 50 62 public class ManageJefFile { 63 64 private static final org.apache.log4j.Logger logger = 65 org.apache.log4j.Logger.getLogger (ManageJefFile.class); 66 67 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 68 69 private JahiaSite site; 70 private JahiaUser user; 71 private ServicesRegistry sReg; 72 73 private static JahiaSitesService sMgr; 74 75 private License coreLicense; 76 77 78 85 public ManageJefFile (HttpServletRequest request, 86 HttpServletResponse response, 87 HttpSession session) 88 throws Throwable 89 { 90 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 91 ParamBean jParams = null; 92 if (jData != null) { 93 jParams = jData.params (); 94 } 95 96 coreLicense = Jahia.getCoreLicense (); 97 if (coreLicense == null) { 98 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.invalidLicenseKey.label", 100 jParams, jParams.getLocale ()); 101 request.setAttribute ("jahiaDisplayMessage", dspMsg); 102 JahiaAdministration.doRedirect (request, response, session, JSP_PATH + "menu.jsp"); 104 return; 105 } 106 107 userRequestDispatcher (request, response, session); 108 } 109 110 111 118 private void userRequestDispatcher (HttpServletRequest request, 119 HttpServletResponse response, 120 HttpSession session) 121 throws Throwable { 122 123 124 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 125 ParamBean jParams = null; 126 if (jData != null) { 127 jParams = jData.params (); 128 } 129 sReg = ServicesRegistry.getInstance (); 130 131 if (sReg != null) { 132 sMgr = sReg.getJahiaSitesService (); 133 } 134 135 user = (JahiaUser)session.getAttribute (ParamBean.SESSION_USER); 137 site = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); 138 139 if (user != null && sReg != null && sMgr != null) { 140 141 String operation = request.getParameter ("sub"); 142 143 if (operation.equals ("catlist")) { 144 displayCategoryList (request, response, session); 145 } else if (operation.equals ("unlockjec")) { 146 decryptJec (request, response, session); 147 } 148 149 } else { 150 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 151 jParams, jParams.getLocale ()); 152 request.setAttribute ("jahiaDisplayMessage", dspMsg); 153 JahiaAdministration.doRedirect (request, 154 response, 155 session, JSP_PATH + "menu.jsp"); 156 } 157 } 158 159 160 168 private void displayCategoryList (HttpServletRequest request, 169 HttpServletResponse response, 170 HttpSession session) 171 throws IOException , ServletException { 172 173 logger.debug ("started"); 174 175 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 176 ParamBean jParams = null; 177 if (jData != null) { 178 jParams = jData.params (); 179 } 180 try { 181 JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService (); 182 183 if (appDepServ == null) { 184 throw new JahiaException ("Unavailable Services", 185 "Unavailable Services", 186 JahiaException.SERVICE_ERROR, 187 JahiaException.ERROR_SEVERITY); 188 } 189 190 JahiaAdministration.doRedirect (request, 191 response, 192 session, 193 JSP_PATH + "manage_jeffile.jsp"); 194 195 } catch (JahiaException je) { 196 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 197 jParams, jParams.getLocale ()); 198 request.setAttribute ("jahiaDisplayMessage", dspMsg); 199 JahiaAdministration.doRedirect (request, 200 response, 201 session, 202 JSP_PATH + "menu.jsp"); 203 } 204 205 } 206 207 208 215 private void decryptJec (HttpServletRequest request, 216 HttpServletResponse response, 217 HttpSession session) 218 throws IOException , ServletException { 219 220 logger.debug ("started"); 221 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 222 ParamBean jParams = null; 223 if (jData != null) { 224 jParams = jData.params (); 225 } 226 227 try { 228 JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService (); 229 230 if (appDepServ == null) { 231 throw new JahiaException ("Unavailable Services", 232 "Unavailable Services", 233 JahiaException.SERVICE_ERROR, 234 JahiaException.ERROR_SEVERITY); 235 } 236 237 Enumeration enumeration = null; 238 try { 239 enumeration = sMgr.getSites (); 240 } catch (JahiaException ex) { 241 throw new JahiaException ("Could not retrieve the list of sites", 242 "Could not retrieve the list of sites", 243 JahiaException.SERVICE_ERROR, 244 JahiaException.ERROR_SEVERITY); 245 } 246 247 Hashtable cryptedComp = new Hashtable (); 248 JahiaSite siteItem = null; 249 String siteLabel = ""; 250 251 while (enumeration.hasMoreElements ()) { 252 siteItem = (JahiaSite)enumeration.nextElement (); 253 254 String path = JahiaWebAppsDeployerService.getNewWebAppsPath () 256 + File.separator 257 + siteItem.getSiteKey (); 258 259 260 File folder = new File (path); 261 File [] files = new File [0]; 262 263 if (folder.isDirectory ()) { 264 files = folder.listFiles (); 265 } 266 267 int size = files.length; 268 File f = null; 269 JecFile jec = null; 270 271 int jecLicenseType = 0; 273 int jecLicenseTypeRelComp = 0; 274 siteLabel = "[" + siteItem.getServerName () + "]"; 275 276 for (int i = 0; i < size; i++) { 278 f = files[i]; 279 if (f.isFile () && (f.getName ().toLowerCase ()).endsWith (".jec")) { 280 281 boolean tryAgain = true; 282 boolean goSleep = false; 283 int status = 0; 284 String fileName = siteLabel + f.getName (); 285 286 try { 287 288 logger.debug ("Found file " + f.getAbsolutePath ()); 289 290 jec = new JecFile (f.getAbsolutePath ()); 291 297 jec.extractFiles (); 298 status = JefFileConstants.UNLOCKED; 299 f.delete (); 300 306 } catch (JefFileKeyNotFoundException knf) { 307 status = JefFileConstants.INVALID_JEF_FILE; 308 logger.warn (knf.getMessage ()); 309 File tmpFile = new File (f.getAbsolutePath () + "_error"); 310 f.renameTo (tmpFile); 311 312 } catch (JefFileInvalidKeyValueException ikv) { 313 status = JefFileConstants.INVALID_JEF_FILE; 314 logger.warn (ikv.getMessage ()); 315 File tmpFile = new File (f.getAbsolutePath () + "_error"); 316 f.renameTo (tmpFile); 317 318 } catch (InvalidJefFileException ijf) { 319 status = JefFileConstants.INVALID_JEF_FILE; 320 logger.warn (ijf.getMessage ()); 321 File tmpFile = new File (f.getAbsolutePath () + "_error"); 322 f.renameTo (tmpFile); 323 324 } catch (IOException ioe) { 325 status = JefFileConstants.IO_ERROR; 326 logger.warn (ioe.getMessage ()); 327 ioe.printStackTrace (); 328 329 } catch (JahiaException je) { 330 status = je.getErrorCode (); 331 logger.warn (je.getMessage ()); 332 je.printStackTrace (); 333 334 } catch (Throwable t) { 335 status = JefFileConstants.UNKNOWN_ERROR; 336 logger.warn (t.getMessage ()); 337 t.printStackTrace (); 338 } 339 340 341 cryptedComp.put (fileName, new Integer (status)); 342 } 343 } 344 } 345 346 request.setAttribute ("cryptedComp", cryptedComp); 347 JahiaAdministration.doRedirect (request, 348 response, 349 session, 350 JSP_PATH + "manage_jec.jsp"); 351 352 } catch (JahiaException je) { 353 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 354 jParams, jParams.getLocale ()); 355 request.setAttribute ("jahiaDisplayMessage", dspMsg); 356 JahiaAdministration.doRedirect (request, 357 response, 358 session, 359 JSP_PATH + "menu.jsp"); 360 } 361 362 } 363 364 365 } | Popular Tags |