1 42 43 44 package org.jahia.admin.components; 45 46 import org.jahia.bin.Jahia; 47 import org.jahia.bin.JahiaAdministration; 48 import org.jahia.data.JahiaData; 49 import org.jahia.data.applications.ApplicationBean; 50 import org.jahia.data.webapps.JahiaWebAppsPackage; 51 import org.jahia.exceptions.JahiaException; 52 import org.jahia.params.ParamBean; 53 import org.jahia.registries.ServicesRegistry; 54 import org.jahia.resourcebundle.JahiaResourceBundle; 55 import org.jahia.security.license.License; 56 import org.jahia.services.applications.JahiaApplicationsManagerService; 57 import org.jahia.services.jef.*; 58 import org.jahia.services.shares.AppsShareService; 59 import org.jahia.services.sites.JahiaSite; 60 import org.jahia.services.sites.JahiaSiteTools; 61 import org.jahia.services.sites.JahiaSitesService; 62 import org.jahia.services.usermanager.JahiaGroupManagerService; 63 import org.jahia.services.usermanager.JahiaUser; 64 import org.jahia.services.webapps_deployer.JahiaWebAppsDeployerService; 65 import org.jahia.utils.JahiaTools; 66 67 import javax.servlet.ServletException ; 68 import javax.servlet.http.HttpServletRequest ; 69 import javax.servlet.http.HttpServletResponse ; 70 import javax.servlet.http.HttpSession ; 71 import java.io.File ; 72 import java.io.IOException ; 73 import java.util.Enumeration ; 74 import java.util.Hashtable ; 75 import java.util.Vector ; 76 77 78 91 public class ManageComponents { 92 93 94 private static org.apache.log4j.Logger logger = 95 org.apache.log4j.Logger.getLogger (ManageComponents.class); 96 97 private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; 98 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 99 100 private JahiaSite site; 101 private JahiaUser user; 102 private ServicesRegistry sReg; 103 104 private License coreLicense; 105 106 113 public ManageComponents (HttpServletRequest request, 114 HttpServletResponse response, 115 HttpSession session) 116 throws Throwable { 117 118 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 119 ParamBean jParams = null; 120 if (jData != null) { 121 jParams = jData.params (); 122 } 123 coreLicense = Jahia.getCoreLicense (); 124 if (coreLicense == null) { 125 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.invalidLicense.label", 127 jParams, jParams.getLocale ()); 128 request.setAttribute ("jahiaDisplayMessage", dspMsg); 129 JahiaAdministration.doRedirect (request, response, session, JSP_PATH + "menu.jsp"); 131 return; 132 } 133 134 userRequestDispatcher (request, response, session); 135 } 137 138 139 147 private void userRequestDispatcher (HttpServletRequest request, 148 HttpServletResponse response, 149 HttpSession session) 150 throws Throwable { 151 String operation = request.getParameter ("sub"); 152 153 sReg = ServicesRegistry.getInstance (); 154 155 user = (JahiaUser)session.getAttribute (ParamBean.SESSION_USER); 157 site = (JahiaSite)session.getAttribute (ParamBean.SESSION_SITE); 158 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 159 ParamBean jParams = null; 160 if (jData != null) { 161 jParams = jData.params (); 162 } 163 164 if (site != null && user != null && sReg != null) { 165 166 if (JahiaSiteTools.getAdminGroup (site).isMember (user)) { 167 168 request.setAttribute ("site", site); 170 171 if (operation.equals ("display")) { 172 displayComponentList (request, response, session); 173 } else if (operation.equals ("displaynewlist")) { 174 displayNewComponentList (request, response, session); 175 } else if (operation.equals ("details")) { 176 displayNewComponentDetail (request, response, session); 177 } else if (operation.equals ("visibility")) { 178 confirmComponentVisibilityChange (request, response, session); 179 } else if (operation.equals ("savevisibility")) { 180 saveComponentVisibility (request, response, session); 181 } else if (operation.equals ("edit")) { 182 editComponent (request, response, session); 183 } else if (operation.equals ("add")) { 184 addComponent (request, response, session); 185 } else if (operation.equals ("share")) { 186 shareComponent (request, response, session); 187 } else if (operation.equals ("options")) { 188 editComponentOption (request, response, session); 189 } else if (operation.equals ("decryptjec")) { 190 decryptJec (request, response, session); 191 } 192 193 } else { 194 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 196 jParams, jParams.getLocale ()); 197 request.setAttribute ("jahiaDisplayMessage", dspMsg); 198 JahiaAdministration.doRedirect (request, 199 response, 200 session, JSP_PATH + "menu.jsp"); 201 } 202 } else { 203 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 204 jParams, jParams.getLocale ()); 205 request.setAttribute ("jahiaDisplayMessage", dspMsg); 206 JahiaAdministration.doRedirect (request, 207 response, 208 session, JSP_PATH + "menu.jsp"); 209 } 210 } 212 213 214 222 private void displayComponentList (HttpServletRequest request, 223 HttpServletResponse response, 224 HttpSession session) 225 throws IOException , ServletException { 226 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 227 ParamBean jParams = null; 228 if (jData != null) { 229 jParams = jData.params (); 230 } 231 try { 232 233 JahiaApplicationsManagerService appPersServ = 234 sReg.getJahiaApplicationsManagerService (); 235 236 AppsShareService appShareServ = sReg.getAppsShareService (); 237 238 if (appPersServ == null || appShareServ == null) { 239 throw new JahiaException ("Unavailable Services", 240 "Unavailable Services", 241 JahiaException.SERVICE_ERROR, 242 JahiaException.ERROR_SEVERITY); 243 } 244 245 Vector appList = appPersServ.getApplications (); 247 248 Vector authAppList = new Vector (); 250 251 int size = appList.size (); 252 ApplicationBean app = null; 253 for (int i = 0; i < size; i++) { 254 app = (ApplicationBean)appList.get (i); 255 if (app.isShared () || (app.getJahiaID () == site.getID ()) 256 || (appShareServ.getShare (site, app) != null)) { 257 authAppList.add (app); 258 } 259 } 260 261 request.setAttribute ("appsList", authAppList.elements ()); 262 263 JahiaAdministration.doRedirect (request, 264 response, 265 session, 266 JSP_PATH + "manage_components.jsp"); 267 268 } catch (JahiaException je) { 269 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 270 jParams, jParams.getLocale ()); 271 request.setAttribute ("jahiaDisplayMessage", dspMsg); 272 JahiaAdministration.doRedirect (request, 273 response, 274 session, 275 JSP_PATH + "menu.jsp"); 276 } 277 278 279 } 281 282 283 291 private void displayNewComponentList (HttpServletRequest request, 292 HttpServletResponse response, 293 HttpSession session) 294 throws IOException , ServletException { 295 296 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 297 ParamBean jParams = null; 298 if (jData != null) { 299 jParams = jData.params (); 300 } 301 try { 302 JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService (); 303 304 if (appDepServ == null) { 305 throw new JahiaException ("Unavailable Services", 306 "Unavailable Services", 307 JahiaException.SERVICE_ERROR, 308 JahiaException.ERROR_SEVERITY); 309 } 310 311 Enumeration newWebAppsKeys = appDepServ.getWebAppsPackageKeys (site.getSiteKey ()); 313 314 Enumeration enumeration = appDepServ.getWebAppsPackages (site.getSiteKey ()); 315 Vector vec = new Vector (); 316 JahiaWebAppsPackage aPackage = null; 317 318 while (enumeration.hasMoreElements ()) { 319 aPackage = (JahiaWebAppsPackage)enumeration.nextElement (); 320 if (aPackage != null) { 321 vec.add (aPackage); 322 } else { 323 } 325 } 326 327 request.setAttribute ("packagesList", vec.elements ()); 328 329 JahiaAdministration.doRedirect (request, 330 response, 331 session, 332 JSP_PATH + "new_components.jsp"); 333 } catch (JahiaException je) { 334 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 335 jParams, jParams.getLocale ()); 336 request.setAttribute ("jahiaDisplayMessage", dspMsg); 337 JahiaAdministration.doRedirect (request, 338 response, 339 session, 340 JSP_PATH + "menu.jsp"); 341 } 342 343 } 344 345 346 354 private void displayNewComponentDetail (HttpServletRequest request, 355 HttpServletResponse response, 356 HttpSession session) 357 throws IOException , ServletException { 358 359 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 360 ParamBean jParams = null; 361 if (jData != null) { 362 jParams = jData.params (); 363 } 364 365 try { 366 JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService (); 367 368 if (appDepServ == null) { 369 throw new JahiaException ("Unavailable Services", 370 "Unavailable Services", 371 JahiaException.SERVICE_ERROR, 372 JahiaException.ERROR_SEVERITY); 373 } 374 375 String packageName = request.getParameter ("package_name"); 377 JahiaWebAppsPackage aPackage = (JahiaWebAppsPackage)appDepServ 378 .getWebAppsPackage (site.getSiteKey () 379 + "_" 380 + packageName); 381 382 String subAction = request.getParameter ("subaction"); 383 384 if (subAction == null) { 385 request.setAttribute ("canDeploy", new Boolean (appDepServ.canDeploy ())); 386 request.setAttribute ("aPackage", aPackage); 387 JahiaAdministration.doRedirect (request, 388 response, 389 session, 390 JSP_PATH + "new_component_detail.jsp"); 391 } else if (subAction.equals ("deploy")) { 392 393 try { 394 if (appDepServ.deploy (site, 395 aPackage.getContextRoot (), 396 aPackage.getFilePath ())) { 397 398 displayNewComponentList (request, response, session); 399 400 } else { 401 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.deployingPackageError.label", 402 jParams, jParams.getLocale ()); 403 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", dspMsg); 404 request.setAttribute ("aPackage", aPackage); 405 JahiaAdministration.doRedirect (request, 406 response, 407 session, 408 JSP_PATH + "new_component_detail.jsp"); 409 } 410 } catch (JahiaException je) { 411 request.setAttribute ("aPackage", aPackage); 412 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.deployingPackageError.label", 413 jParams, jParams.getLocale ()); 414 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", dspMsg); 415 JahiaAdministration.doRedirect (request, 416 response, 417 session, 418 JSP_PATH + "new_component_detail.jsp"); 419 } 420 } else if (subAction.equals ("delete")) { 421 422 try { 423 if (appDepServ.deletePackage (site, aPackage.getFilePath ())) { 424 displayNewComponentList (request, response, session); 425 } else { 426 request.setAttribute ("aPackage", aPackage); 427 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.deletingPackageError.label", 428 jParams, jParams.getLocale ()); 429 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", dspMsg); 430 JahiaAdministration.doRedirect (request, 431 response, 432 session, 433 JSP_PATH + "new_component_detail.jsp"); 434 } 435 } catch (IOException ioe) { 436 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.deletingPackageError.label", 437 jParams, jParams.getLocale ()); 438 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", dspMsg); 439 JahiaAdministration.doRedirect (request, 440 response, 441 session, 442 JSP_PATH + "new_component_detail.jsp"); 443 } 444 } 445 446 } catch (JahiaException je) { 447 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 448 jParams, jParams.getLocale ()); 449 request.setAttribute ("jahiaDisplayMessage", dspMsg); 450 JahiaAdministration.doRedirect (request, 451 response, 452 session, 453 JSP_PATH + "menu.jsp"); 454 } 455 456 } 457 458 459 467 private void confirmComponentVisibilityChange (HttpServletRequest request, 468 HttpServletResponse response, 469 HttpSession session) 470 throws IOException , ServletException { 471 472 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 473 ParamBean jParams = null; 474 if (jData != null) { 475 jParams = jData.params (); 476 } 477 try { 478 479 JahiaApplicationsManagerService appManServ = sReg.getJahiaApplicationsManagerService (); 480 481 if (appManServ == null) { 482 throw new JahiaException ("Unavailable Services", 483 "Unavailable Services", 484 JahiaException.SERVICE_ERROR, 485 JahiaException.ERROR_SEVERITY); 486 } 487 488 String [] ids = request.getParameterValues ("visible_status"); 490 491 Vector webApps = appManServ.getApplications (site.getID ()); 492 if (webApps == null) { 493 webApps = new Vector (); 494 } 495 Enumeration enumeration = webApps.elements (); 496 497 if (enumeration != null) { 498 ApplicationBean app = null; 499 Vector apps = new Vector (); 501 while (enumeration.hasMoreElements ()) { 502 app = (ApplicationBean)enumeration.nextElement (); 503 if ((app.getJahiaID () == site.getID ()) 504 && (app.getVisibleStatus () == 1) 505 && !(JahiaTools.inValues (String.valueOf (app.getID ()), ids))) { 506 apps.add (app); 507 } else if ((app.getJahiaID () == site.getID ()) 508 && (app.getVisibleStatus () == 0) 509 && (JahiaTools.inValues (String.valueOf (app.getID ()), ids))) { 510 apps.add (app); 511 } 512 } 513 514 if (apps.size () > 0) { 515 request.setAttribute ("appsList", apps.elements ()); 516 JahiaAdministration.doRedirect (request, 517 response, 518 session, 519 JSP_PATH + "comps_confirmvisibilitychange.jsp"); 520 } else { 521 request.setAttribute ("appsList", webApps.elements ()); 522 JahiaAdministration.doRedirect (request, 523 response, 524 session, 525 JSP_PATH + "manage_components.jsp"); 526 } 527 } else { 528 request.setAttribute ("appsList", enumeration); 529 JahiaAdministration.doRedirect (request, 530 response, 531 session, 532 JSP_PATH + "manage_components.jsp"); 533 } 534 535 } catch (JahiaException je) { 536 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 537 jParams, jParams.getLocale ()); 538 request.setAttribute ("jahiaDisplayMessage", dspMsg); 539 JahiaAdministration.doRedirect (request, 540 response, 541 session, 542 JSP_PATH + "menu.jsp"); 543 } 544 545 } 547 548 556 private void saveComponentVisibility (HttpServletRequest request, 557 HttpServletResponse response, 558 HttpSession session) 559 throws IOException , ServletException { 560 561 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 562 ParamBean jParams = null; 563 if (jData != null) { 564 jParams = jData.params (); 565 } 566 try { 567 568 JahiaApplicationsManagerService appManServ = sReg.getJahiaApplicationsManagerService (); 569 570 if (appManServ == null) { 571 throw new JahiaException ("Unavailable Services", 572 "Unavailable Services", 573 JahiaException.SERVICE_ERROR, 574 JahiaException.ERROR_SEVERITY); 575 } 576 577 String [] ids = request.getParameterValues ("visible_status"); 579 580 int id = 0; 582 int visStatus = 0; 583 ApplicationBean app = null; 584 for (int i = 0; i < ids.length; i++) { 585 id = Integer.parseInt (ids[i]); 586 app = appManServ.getApplication (id); 587 if (app != null) { 588 visStatus = app.getVisibleStatus (); 589 if (visStatus == 0) { 590 app.setVisible (1); 591 } else { 592 app.setVisible (0); 593 } 594 595 appManServ.saveDefinition (app); 596 } 597 } 598 599 Vector webApps = appManServ.getApplications (site.getID ()); 600 if (webApps == null) { 601 webApps = new Vector (); 602 } 603 Enumeration enumeration = webApps.elements (); 604 if (enumeration != null) { 605 request.setAttribute ("appsList", enumeration); 606 } 607 608 JahiaAdministration.doRedirect (request, 609 response, 610 session, 611 JSP_PATH + "manage_components.jsp"); 612 613 } catch (JahiaException je) { 614 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 615 jParams, jParams.getLocale ()); 616 request.setAttribute ("jahiaDisplayMessage", dspMsg); 617 JahiaAdministration.doRedirect (request, 618 response, 619 session, 620 JSP_PATH + "menu.jsp"); 621 } 622 623 } 624 625 626 634 private void editComponent (HttpServletRequest request, 635 HttpServletResponse response, 636 HttpSession session) 637 throws IOException , ServletException { 638 639 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 640 ParamBean jParams = null; 641 if (jData != null) { 642 jParams = jData.params (); 643 } 644 try { 645 646 JahiaSitesService sitesServ = sReg.getJahiaSitesService (); 647 JahiaApplicationsManagerService appManServ = sReg.getJahiaApplicationsManagerService (); 648 AppsShareService appShareServ = sReg.getAppsShareService (); 649 JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService (); 650 JahiaApplicationsManagerService appPersServ = 651 sReg.getJahiaApplicationsManagerService (); 652 653 if (appManServ == null 654 || sitesServ == null 655 || appShareServ == null 656 || appDepServ == null 657 || appPersServ == null) { 658 throw new JahiaException ("Unavailable Services", 659 "Unavailable Services", 660 JahiaException.SERVICE_ERROR, 661 JahiaException.ERROR_SEVERITY); 662 } 663 664 String strVal = request.getParameter ("appid"); 666 if (strVal == null) { 667 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.errMsg.applicaionNotFound.label", 668 jParams, jParams.getLocale ()); 669 request.setAttribute ("errMsg", dspMsg); 670 displayComponentList (request, response, session); 671 return; 672 } 673 int id = Integer.parseInt (strVal); 674 ApplicationBean app = appManServ.getApplication (id); 675 676 if (app == null) { 677 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.errMsg.applicaionNotFound.label", 678 jParams, jParams.getLocale ()); 679 request.setAttribute ("errMsg", dspMsg); 680 displayComponentList (request, response, session); 681 return; 682 } 683 684 String subAction = request.getParameter ("subaction"); 685 if (subAction == null || (subAction.length () <= 0)) { 686 687 Enumeration authSitesID = null; 689 690 authSitesID = appShareServ.getSites (app); 691 Vector authSites = new Vector (); 692 Integer siteID = null; 693 while (authSitesID.hasMoreElements ()) { 694 siteID = (Integer )authSitesID.nextElement (); 695 JahiaSite aSite = sitesServ.getSite (siteID.intValue ()); 696 authSites.add (aSite); 697 } 698 699 request.setAttribute ("authSites", authSites.elements ()); 700 request.setAttribute ("nbShare", new Integer (authSites.size ())); 701 702 request.setAttribute ("appItem", app); 703 JahiaAdministration.doRedirect (request, 704 response, 705 session, 706 JSP_PATH + "component_edit.jsp"); 707 } else if (subAction.equals ("delete")) { 708 String undeploy = request.getParameter ("undeploy"); 709 710 if (undeploy != null 712 && (!app.getContext ().equalsIgnoreCase (request.getContextPath ()))) { 713 appDepServ.undeploy (app); 714 } 715 716 appManServ.deleteApplicationGroups (app); 718 719 appPersServ.removeApplication (app.getID ()); 721 722 ServicesRegistry.getInstance().getJahiaApplicationContextService().removeContextFromCache(app.getContext()); 723 724 displayComponentList (request, response, session); 725 726 } else if (subAction.equals ("confirmdelete")) { 727 request.setAttribute ("currAction", "confirmdelete"); 728 request.setAttribute ("appItem", app); 729 JahiaAdministration.doRedirect (request, 730 response, 731 session, 732 JSP_PATH + "component_edit.jsp"); 733 } else if (subAction.equals ("save")) { 734 735 String appName = request.getParameter ("appName"); 736 737 String visible_status = request.getParameter ("visible_status"); 738 if (appName != null && (appName.trim ().length () > 0)) { 739 app.setName (appName); 740 } 741 if (visible_status != null) { 742 app.setVisible (1); 743 } else { 744 app.setVisible (0); 745 } 746 747 String appDescr = request.getParameter ("appDescr"); 748 app.setdesc (appDescr); 749 750 if (appManServ.saveDefinition (app)) { 751 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.applicationUpdated.label", 752 jParams, jParams.getLocale ()); 753 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", dspMsg); 754 } else { 755 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.applicationNotUpdated.label", 756 jParams, jParams.getLocale ()); 757 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", dspMsg); 758 } 759 760 app = appManServ.getApplication (id); 761 request.setAttribute ("appItem", app); 762 JahiaAdministration.doRedirect (request, 763 response, 764 session, 765 JSP_PATH + "component_edit.jsp"); 766 } 767 768 } catch (JahiaException je) { 769 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 770 jParams, jParams.getLocale ()); 771 request.setAttribute ("jahiaDisplayMessage", dspMsg); 772 JahiaAdministration.doRedirect (request, 773 response, 774 session, 775 JSP_PATH + "menu.jsp"); 776 } 777 778 } 779 780 781 789 private void editComponentOption (HttpServletRequest request, 790 HttpServletResponse response, 791 HttpSession session) 792 throws IOException , ServletException { 793 794 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 795 ParamBean jParams = null; 796 if (jData != null) { 797 jParams = jData.params (); 798 } 799 try { 800 801 JahiaSitesService sitesServ = sReg.getJahiaSitesService (); 802 803 if (sitesServ == null) { 804 throw new JahiaException ("Unavailable Services", 805 "Unavailable Services", 806 JahiaException.SERVICE_ERROR, 807 JahiaException.ERROR_SEVERITY); 808 } 809 810 int autoDeploy = 0; 811 812 if (site.getWebAppsAutoDeployMode ()) { 813 autoDeploy = 1; 814 } 815 816 request.setAttribute ("autoDeploy", new Integer (autoDeploy)); 817 818 String subAction = request.getParameter ("subaction"); 820 if (subAction != null && subAction.equals ("save")) { 821 822 String strVal = request.getParameter ("autoDeploy"); 823 int intVal = 0; 824 825 if (strVal != null) { 826 intVal = 1; 827 } 828 829 if (intVal != autoDeploy) { 830 831 try { 832 site.setWebAppsAutoDeployMode (intVal == 1); 833 sitesServ.updateSite (site); 834 session.setAttribute (ParamBean.SESSION_SITE, site); 835 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.changeUpdated.label", 836 jParams, jParams.getLocale ()); 837 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", dspMsg); 838 839 } catch (JahiaException je) { 840 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.changeNotUpdated.label", 841 jParams, jParams.getLocale ()); 842 session.setAttribute (CLASS_NAME + "jahiaDisplayMessage", dspMsg); 843 } 844 845 request.setAttribute ("autoDeploy", new Integer (intVal)); 846 } 847 } 848 849 JahiaAdministration.doRedirect (request, 850 response, 851 session, 852 JSP_PATH + "component_option.jsp"); 853 } catch (JahiaException je) { 854 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 855 jParams, jParams.getLocale ()); 856 request.setAttribute ("jahiaDisplayMessage", dspMsg); 857 JahiaAdministration.doRedirect (request, 858 response, 859 session, 860 JSP_PATH + "menu.jsp"); 861 } 862 863 864 } 865 866 867 875 private void addComponent (HttpServletRequest request, 876 HttpServletResponse response, 877 HttpSession session) 878 879 throws IOException , ServletException { 880 881 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 882 ParamBean jParams = null; 883 if (jData != null) { 884 jParams = jData.params (); 885 } 886 try { 887 888 JahiaApplicationsManagerService appManServ = sReg.getJahiaApplicationsManagerService (); 889 JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService (); 890 891 if (appManServ == null 892 || appDepServ == null) { 893 throw new JahiaException ("Unavailable Services", 894 "Unavailable Services", 895 JahiaException.SERVICE_ERROR, 896 JahiaException.ERROR_SEVERITY); 897 } 898 899 request.setAttribute ("warningMsg", ""); 900 901 String subAction = request.getParameter ("subaction"); 902 String appPath = request.getParameter ("appPath"); 903 String appName = request.getParameter ("appName"); 904 String appDescr = request.getParameter ("appDescr"); 905 906 if (subAction == null || (subAction.length () <= 0)) { 907 request.setAttribute ("appPath", ""); 908 } else if (subAction.equals ("scanDir")) { 909 appPath = request.getParameter ("appPath"); 910 JahiaWebAppsPackage pack = appDepServ.loadWebAppInfo (appPath); 911 if (pack != null) { 912 request.setAttribute ("appPath", appPath); 913 914 ApplicationBean app = appManServ.getApplication ("/" + pack.getContextRoot ()); 916 if (app != null) { 917 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.componentAlreadyRegistered.label", 918 jParams, jParams.getLocale ()); 919 request.setAttribute ("warningMsg", dspMsg); 920 request.setAttribute ("appName", ""); 921 request.setAttribute ("appDescr", ""); 922 } else { 923 if (appName == null) { 924 appName = pack.getContextRoot (); 925 } 926 if (appDescr == null) { 927 appDescr = ""; 928 } 929 request.setAttribute ("appName", appName); 930 request.setAttribute ("appDescr", appDescr); 931 request.setAttribute ("aPackage", pack); 932 } 933 } else { 934 request.setAttribute ("appPath", appPath); 935 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.noComponentInfoFound.label", 936 jParams, jParams.getLocale ()); 937 request.setAttribute ("warningMsg", dspMsg); 938 } 939 940 } else if (subAction.equals ("deploy")) { 941 request.setAttribute ("appPath", appPath); 942 request.setAttribute ("appName", appName); 943 request.setAttribute ("appDescr", appDescr); 944 945 JahiaWebAppsPackage pack = appDepServ.loadWebAppInfo (appPath); 946 947 if (pack != null) { 948 if (!pack.isDirectory ()) { 949 if (appDepServ.deploy (site, pack.getContextRoot (), appPath)) { 950 ApplicationBean app = appManServ.getApplication ("/" + pack.getContextRoot ()); 952 if (app != null) { 953 if (appName != null && appName.trim ().length () > 0) { 954 app.setName (appName); 955 } 956 app.setdesc (appDescr); 957 appManServ.saveDefinition (app); 958 } 959 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.componentRegistered.label", 960 jParams, jParams.getLocale ()); 961 request.setAttribute ("warningMsg", dspMsg); 962 } else { 963 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.componentNotRegistered.label", 964 jParams, jParams.getLocale ()); 965 request.setAttribute ("warningMsg", dspMsg); 966 request.setAttribute ("aPackage", pack); 967 } 968 } else { 969 appDepServ.registerWebApps (site, 970 pack.getContextRoot (), 971 appPath, 972 pack.getWebApps ()); 973 974 ApplicationBean app = appManServ.getApplication ("/" + pack.getContextRoot ()); 976 if (app != null) { 977 if (appName != null && appName.trim ().length () > 0) { 978 app.setName (appName); 979 } 980 app.setdesc (appDescr); 981 appManServ.saveDefinition (app); 982 } 983 984 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.componentRegistered.label", 985 jParams, jParams.getLocale ()); 986 request.setAttribute ("warningMsg", dspMsg); 987 } 988 989 } else { 990 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.noComponentInfoFound.label", 991 jParams, jParams.getLocale ()); 992 request.setAttribute ("warningMsg", dspMsg); 993 } 994 } 995 JahiaAdministration.doRedirect (request, 996 response, 997 session, 998 JSP_PATH + "component_add.jsp"); 999 } catch (JahiaException je) { 1000 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 1001 jParams, jParams.getLocale ()); 1002 request.setAttribute ("jahiaDisplayMessage", dspMsg); 1003 JahiaAdministration.doRedirect (request, 1004 response, 1005 session, 1006 JSP_PATH + "menu.jsp"); 1007 } 1008 1009 1010 } 1012 1013 1021 private void shareComponent (HttpServletRequest request, 1022 HttpServletResponse response, 1023 HttpSession session) 1024 throws IOException , ServletException { 1025 1026 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 1027 ParamBean jParams = null; 1028 if (jData != null) { 1029 jParams = jData.params (); 1030 } 1031 try { 1032 JahiaApplicationsManagerService appManServ = sReg.getJahiaApplicationsManagerService (); 1033 JahiaSitesService sitesServ = sReg.getJahiaSitesService (); 1034 AppsShareService appShareServ = sReg.getAppsShareService (); 1035 JahiaApplicationsManagerService appPersServ = 1036 sReg.getJahiaApplicationsManagerService (); 1037 JahiaGroupManagerService grpManServ = sReg.getJahiaGroupManagerService (); 1038 1039 if (appManServ == null 1040 || sitesServ == null 1041 || appShareServ == null 1042 || appPersServ == null 1043 || grpManServ == null) { 1044 throw new JahiaException ("Unavailable Services", 1045 "Unavailable Services", 1046 JahiaException.SERVICE_ERROR, 1047 JahiaException.ERROR_SEVERITY); 1048 } 1049 1050 1051 Vector apps = appPersServ.getApplications (); 1053 Vector ownApps = new Vector (); if (apps == null) { 1055 apps = new Vector (); 1056 } 1057 int size = apps.size (); 1058 ApplicationBean appItem = null; 1059 for (int i = 0; i < size; i++) { 1060 appItem = (ApplicationBean)apps.get (i); 1061 if (appItem.getJahiaID () == site.getID ()) { 1062 ownApps.add (appItem); 1063 } 1064 } 1065 1066 request.setAttribute ("appsList", ownApps.elements ()); 1067 1068 Vector grantedSites = new Vector (); 1069 1070 try { 1072 grantedSites = grpManServ.getAdminGrantedSites (user); 1073 } catch (Exception e) { 1074 grantedSites.add (site); 1075 } 1076 1077 request.setAttribute ("sitesList", grantedSites); 1078 1079 int appID = -1; 1081 String appIDStr = ""; 1082 ApplicationBean app = null; 1083 if (request.getParameter ("apps") == null) { 1084 1085 if (ownApps.size () > 0) { 1086 1087 app = (ApplicationBean)ownApps.get (0); appID = app.getID (); 1089 } 1090 } else { 1091 appIDStr = request.getParameter ("apps"); 1092 appID = Integer.parseInt (appIDStr); 1093 app = appManServ.getApplication (appID); 1094 } 1095 1096 String subAction = null; 1097 if (request.getParameter ("subaction") != null) { 1098 subAction = request.getParameter ("subaction"); 1099 } 1100 1101 if (subAction != null && subAction.equals ("save")) { 1102 appShareServ.removeShares (app); 1104 String [] vals = request.getParameterValues ("authSites"); 1106 if (vals != null) { 1107 JahiaSite authSite = null; 1108 for (int i = 0; i < vals.length; i++) { 1109 authSite = sitesServ.getSite (Integer.parseInt (vals[i])); 1110 appShareServ.addShare (authSite, app); 1111 } 1112 } 1113 1114 appPersServ.saveDefinition (app); 1115 1116 } 1117 1118 1119 Enumeration authSitesID = null; 1121 1122 authSitesID = appShareServ.getSites (app); 1123 Vector authSites = new Vector (); 1124 Integer siteID = null; 1125 while (authSitesID.hasMoreElements ()) { 1126 siteID = (Integer )authSitesID.nextElement (); 1127 JahiaSite aSite = sitesServ.getSite (siteID.intValue ()); 1128 authSites.add (aSite); 1129 } 1130 1131 request.setAttribute ("app", app); 1132 request.setAttribute ("appID", new Integer (appID)); 1133 request.setAttribute ("authSites", authSites.elements ()); 1134 1135 JahiaAdministration.doRedirect (request, 1136 response, 1137 session, 1138 JSP_PATH + "component_share.jsp"); 1139 1140 } catch (JahiaException je) { 1141 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 1142 jParams, jParams.getLocale ()); 1143 request.setAttribute ("jahiaDisplayMessage", dspMsg); 1144 JahiaAdministration.doRedirect (request, 1145 response, 1146 session, 1147 JSP_PATH + "menu.jsp"); 1148 } 1149 1150 } 1151 1152 1153 1161 private void decryptJec (HttpServletRequest request, 1162 HttpServletResponse response, 1163 HttpSession session) 1164 throws IOException , ServletException { 1165 1166 1167 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 1168 ParamBean jParams = null; 1169 if (jData != null) { 1170 jParams = jData.params (); 1171 } 1172 try { 1173 logger.debug ("decryptJec started"); 1174 1175 JahiaWebAppsDeployerService appDepServ = sReg.getJahiaWebAppsDeployerService (); 1176 1177 if (appDepServ == null) { 1178 throw new JahiaException ("Unavailable Services", 1179 "Unavailable Services", 1180 JahiaException.SERVICE_ERROR, 1181 JahiaException.ERROR_SEVERITY); 1182 } 1183 1184 String path = JahiaWebAppsDeployerService.getNewWebAppsPath () 1186 + File.separator 1187 + site.getSiteKey (); 1188 1189 1190 File folder = new File (path); 1191 File [] files = new File [0]; 1192 1193 if (folder.isDirectory ()) { 1194 files = folder.listFiles (); 1195 } 1196 1197 int size = files.length; 1198 Hashtable cryptedComp = new Hashtable (); 1199 File f = null; 1200 JecFile jec = null; 1201 1202 int jecLicenseType = 0; 1204 int jecLicenseTypeRelComp = 0; 1205 1206 1207 for (int i = 0; i < size; i++) { 1209 f = files[i]; 1210 if (f.isFile () && (f.getName ().toLowerCase ()).endsWith (".jec")) { 1211 1212 int status = 0; 1213 try { 1214 1215 logger.debug ("Found file " + f.getAbsolutePath ()); 1216 1217 jec = new JecFile (f.getAbsolutePath ()); 1218 jecLicenseType = jec.getLicenseType (); 1219 jecLicenseTypeRelComp = jec.getLicenseTypeRelComp (); 1220 1224 jec.extractFiles (); 1225 status = JefFileConstants.UNLOCKED; 1226 f.delete (); 1227 1232 jec = null; 1233 1234 } catch (JefFileKeyNotFoundException knf) { 1235 status = JefFileConstants.INVALID_JEF_FILE; 1236 logger.warn (knf); 1237 File tmpFile = new File (f.getAbsolutePath () + "_error"); 1238 f.renameTo (tmpFile); 1239 1240 } catch (JefFileInvalidKeyValueException ikv) { 1241 status = JefFileConstants.INVALID_JEF_FILE; 1242 logger.warn (ikv); 1243 File tmpFile = new File (f.getAbsolutePath () + "_error"); 1244 f.renameTo (tmpFile); 1245 1246 } catch (InvalidJefFileException ijf) { 1247 status = JefFileConstants.INVALID_JEF_FILE; 1248 logger.warn (ijf); 1249 File tmpFile = new File (f.getAbsolutePath () + "_error"); 1250 f.renameTo (tmpFile); 1251 1252 } catch (IOException ioe) { 1253 status = JefFileConstants.IO_ERROR; 1254 logger.warn (ioe); 1255 1256 } catch (JahiaException je) { 1257 status = je.getErrorCode (); 1258 logger.warn (je); 1259 1260 } catch (Throwable t) { 1261 status = JefFileConstants.UNKNOWN_ERROR; 1262 logger.warn (t); 1263 } 1264 1265 cryptedComp.put (f.getName (), new Integer (status)); 1266 1267 logger.debug ("decryptJec Status " + status); 1268 } 1269 } 1270 1271 request.setAttribute ("cryptedComp", cryptedComp); 1272 JahiaAdministration.doRedirect (request, 1273 response, 1274 session, 1275 JSP_PATH + "component_decryptjec.jsp"); 1276 1277 } catch (JahiaException je) { 1278 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 1279 jParams, jParams.getLocale ()); 1280 request.setAttribute ("jahiaDisplayMessage", dspMsg); 1281 JahiaAdministration.doRedirect (request, 1282 response, 1283 session, 1284 JSP_PATH + "menu.jsp"); 1285 } 1286 1287 } 1288 1289 1290} | Popular Tags |