1 46 47 package org.jahia.bin; 48 49 import java.io.BufferedReader ; 50 import java.io.File ; 51 import java.io.FileReader ; 52 import java.io.IOException ; 53 import java.io.InputStream ; 54 import java.net.MalformedURLException ; 55 import java.net.URL ; 56 import java.util.Enumeration ; 57 import java.util.HashMap ; 58 import java.util.Locale ; 59 import java.util.Properties ; 60 import java.util.ResourceBundle ; 61 import java.util.Vector ; 62 63 import javax.servlet.ServletConfig ; 64 import javax.servlet.ServletContext ; 65 import javax.servlet.ServletException ; 66 import javax.servlet.http.HttpServlet ; 67 import javax.servlet.http.HttpServletRequest ; 68 import javax.servlet.http.HttpServletResponse ; 69 70 import org.jahia.admin.database.DatabaseConnection; 71 import org.jahia.admin.database.DatabaseScripts; 72 import org.jahia.data.templates.JahiaTemplatesPackage; 73 import org.jahia.data.templates.JahiaTemplatesPackageHandler; 74 import org.jahia.data.constants.JahiaConstants; 75 import org.jahia.exceptions.JahiaException; 76 import org.jahia.params.ParamBean; 77 import org.jahia.resourcebundle.JahiaResourceBundle; 78 import org.jahia.services.usermanager.JahiaGroupManagerService; 79 import org.jahia.services.usermanager.JahiaUserManagerService; 80 import org.jahia.utils.ActionHandler; 81 import org.jahia.utils.JahiaTools; 82 import org.jahia.utils.LanguageCodeConverters; 83 import org.jahia.utils.ServletContainerUtils; 84 import org.jahia.utils.properties.PropertiesManager; 85 import org.jahia.utils.zip.JahiaArchiveFileHandler; 86 import org.jahia.security.license.Limit; 87 import org.jahia.security.license.DaysLeftValidator; 88 import org.jahia.engines.EngineMessage; 89 import org.jahia.utils.PathResolver; 90 import org.jahia.utils.WebAppPathResolver; 91 92 93 94 95 112 113 public class JahiaConfigurationWizard extends HttpServlet 114 { 115 private static org.apache.log4j.Logger logger = 116 org.apache.log4j.Logger.getLogger(JahiaConfigurationWizard.class); 117 118 private static ServletContext context = null; 119 private static ServletConfig config = null; 120 private static PathResolver pathResolver = null; 121 122 private static PropertiesManager properties = null; 123 private static ActionHandler actionHandler = null; 124 private DatabaseConnection db = new DatabaseConnection(); 125 private DatabaseScripts scripts = new DatabaseScripts(); 126 127 private static HashMap serverInfos = null; 128 private static HashMap values = new HashMap (); 129 130 private static String methods = null; 131 private static String dbScriptsPath = null; 132 private static String old_database = null; 133 private static String createTables = null; 134 135 private static String servletPath = null; 136 private static String contentServletPath = null; 137 private static Locale defaultLocale = Locale.ENGLISH; 138 private static Locale newSelectedLocale = null; 139 140 private static final String JSP = "/jsp/jahia/configuration_wizard/includer.jsp?jsp="; 141 private static final String HTTP_FILES = "/jsp/jahia/engines"; 142 protected static final String CLASS_NAME = "org.jahia.bin.JahiaConfigurationWizard"; 143 144 private static final String INIT_PARAM_CONTENT_SERVLET_PATH = "content_servlet_path"; 145 private static final String INIT_PARAM_DEFAULT_LOCALE = "default_locale"; 146 147 156 public void init( ServletConfig config ) 157 throws ServletException 158 { 159 context = config.getServletContext(); 161 JahiaConfigurationWizard.config = config; 162 pathResolver = new WebAppPathResolver(context); 163 164 serverInfos = ServletContainerUtils.getServerInformations( config ); 166 167 methods = context.getRealPath( config.getInitParameter("methods") ); 169 dbScriptsPath = context.getRealPath( config.getInitParameter("dbScriptsPath") ); 170 old_database = config.getInitParameter("old_database"); 171 createTables = config.getInitParameter("create_tables"); 172 contentServletPath = config.getInitParameter(INIT_PARAM_CONTENT_SERVLET_PATH); 173 if (contentServletPath == null) { 174 logger.debug("Missing " + INIT_PARAM_CONTENT_SERVLET_PATH + 175 ", defaulting to /content/..."); 176 contentServletPath = "/content/"; 177 } 178 String defaultLanguageCode = context.getInitParameter(INIT_PARAM_DEFAULT_LOCALE); 179 if (defaultLanguageCode == null) { 180 defaultLanguageCode = Locale.ENGLISH.toString(); 181 } 182 defaultLocale = LanguageCodeConverters.languageCodeToLocale(defaultLanguageCode); 183 184 actionHandler = new ActionHandler( methods, CLASS_NAME ); 186 187 fillDefaultValues(); 189 } 190 192 193 194 195 206 public void service (HttpServletRequest request, 207 HttpServletResponse response) throws IOException , 208 ServletException { 209 logger.debug("--[ " + request.getMethod() + " Request Start URI='" + 210 request.getRequestURI() + "' query='" + 211 request.getQueryString() + "'] --"); 212 boolean connect = false; 213 214 if (JahiaConfigurationWizard.servletPath == null) { 215 servletPath = request.getServletPath(); 216 } 217 218 if (request.getParameter("go") != null) { 220 if (request.getParameter("go").equals("connect")) { 221 connect = true; 222 } 223 } 224 225 if (Jahia.jahiaBasicFileName == null) { doRedirect(request, response, JSP + "error_standalone"); 227 } else { 228 if (JahiaTools.checkFileExists(Jahia.getJahiaPropertiesFileName()) && 229 !connect) { 230 doRedirect(request, response, JSP + "error_configured"); } else { 232 if (Jahia.initException != null) { doRedirect(request, response, contentServletPath); 234 } else { 235 dispatcher(request, response); } 237 } 238 } 239 logger.debug("--[ " + request.getMethod() + " Request End ] --"); 240 } 241 242 244 public static String getServletPath() { return servletPath; } 245 246 265 public static String composeActionURL ( HttpServletRequest request, 266 HttpServletResponse response, 267 String doAction, 268 String extraQueryParams ) { 269 String internalDoAction = ""; 270 String internalQueryParams = ""; 271 272 if (doAction != null) { 273 internalDoAction = "/?call=" + doAction; 274 } 275 276 if (extraQueryParams != null) { 277 internalQueryParams = extraQueryParams; 278 } 279 280 return response.encodeURL ( request.getContextPath() + 281 getServletPath() + 282 internalDoAction + 283 internalQueryParams ); 284 } 285 286 298 private void doRedirect( HttpServletRequest request, 299 HttpServletResponse response, 300 String target ) 301 throws IOException , ServletException 302 { 303 logger.debug("Dispatching to target=[" + target +"]"); 304 try 305 { 306 if( request.getAttribute("msg") == null ) { 308 request.setAttribute("msg", Jahia.COPYRIGHT); 309 } 310 311 if( request.getAttribute("focus") == null ) { 313 request.setAttribute("focus", "-none-"); 314 } 315 316 if( request.getAttribute("title") == null ) { 318 request.setAttribute("title", "Jahia Configuration Wizard"); 319 } 320 321 request.setAttribute( "values", values ); 323 324 request.setAttribute( "url", request.getContextPath() + HTTP_FILES ); 326 327 Integer navigator = new Integer (0); 329 if (request.getHeader("user-agent") != null) { 330 navigator = (request.getHeader("user-agent").indexOf("IE")) != -1 ? new Integer (0) : new Integer (1); 331 } else { 332 logger.debug("Couldn't reader user-agent header ! Why ?"); 333 } 334 request.setAttribute("navigator", navigator); 335 336 String contentTypeStr = "text/html;charset="; 338 String acceptCharset = request.getHeader("accept-charset"); 339 boolean acceptsUTF8 = false; 340 if (acceptCharset != null) { 341 if (acceptCharset.toLowerCase().indexOf("utf-8") != -1) { 342 acceptsUTF8 = true; 343 } 344 } 345 if (acceptsUTF8) { 346 contentTypeStr = contentTypeStr + "UTF-8"; 347 } else { 348 contentTypeStr = contentTypeStr + "ISO8859-1"; 349 } 350 request.setAttribute("content-type", contentTypeStr); 351 352 context.getRequestDispatcher( target ).forward( request, response ); 354 355 } catch (IOException ie) { 356 logger.debug("IOException in doRedirect", ie); 357 } catch (ServletException se) { 358 logger.debug("Servlet Exception in doRedirect", se); 359 logger.debug("Servlet Exception in doRedirect root cause", se.getRootCause()); 360 } 361 } 362 364 365 366 367 377 private void dispatcher( HttpServletRequest request, 378 HttpServletResponse response ) 379 throws IOException , ServletException 380 { 381 String call = request.getParameter("call") == null ? "welcome" : request.getParameter("call"); 383 384 actionHandler.call( this, call, request, response ); 386 387 } 388 390 391 392 393 402 public void displayWelcome( HttpServletRequest request, 403 HttpServletResponse response ) 404 throws IOException , ServletException 405 { 406 Properties sys = System.getProperties(); 408 409 request.setAttribute( "javaversion", sys.getProperty("java.version") ); 411 request.setAttribute( "javavendor", sys.getProperty("java.vendor") ); 412 request.setAttribute( "os", sys.getProperty("os.name") ); 413 request.setAttribute( "osVersion", sys.getProperty("os.version")); 414 request.setAttribute( "osArch", sys.getProperty("os.arch")); 415 416 request.setAttribute( "server", serverInfos.get("info") ); 418 419 Locale [] locales = Locale.getAvailableLocales(); 421 Vector availableBundleLocales = new Vector (); 422 if (ResourceBundle.getBundle(JahiaResourceBundle. 424 MESSAGE_DEFAULT_RESOURCE_BUNDLE, Locale.getDefault()) != null) { 425 availableBundleLocales.add(defaultLocale); 426 } 427 ResourceBundle res = null; 428 for (int i=0; i < locales.length; i++) { 429 Locale curLocale = locales[i]; 430 res = ResourceBundle.getBundle(JahiaResourceBundle. 431 MESSAGE_DEFAULT_RESOURCE_BUNDLE, curLocale); 432 if (res != null) { 433 if (res.getLocale().equals(curLocale) && (!curLocale.equals(defaultLocale))) { 434 availableBundleLocales.add(curLocale); 435 } 436 } 437 } 438 request.setAttribute( "availableBundleLocales", availableBundleLocales ); 439 440 Locale selectedLocale = null; 443 String selectedLanguageCode = (String ) values.get("welcome_newLocale"); 444 if (selectedLanguageCode != null) { 445 selectedLocale = LanguageCodeConverters.languageCodeToLocale(selectedLanguageCode); 446 } 447 if (selectedLocale == null) { 448 if (request.getLocale() != null) { 449 selectedLocale = request.getLocale(); 450 } else { 451 selectedLocale = defaultLocale; 452 } 453 } 454 if (availableBundleLocales.contains(selectedLocale)) { 455 values.put("welcome_newLocale", selectedLocale.toString()); 456 } 457 458 doRedirect( request, response, JSP + "welcome" ); 460 461 sys = null; 463 } 464 466 467 468 469 478 public void displayRoot( HttpServletRequest request, 479 HttpServletResponse response ) 480 throws IOException , ServletException 481 { 482 if( request.getAttribute("focus") == null ) { 484 request.setAttribute( "focus", "pwd" ); 485 } 486 487 request.setAttribute( "title", "SuperUser (administrator) settings" ); 489 490 doRedirect( request, response, JSP + "root" ); 492 } 493 495 496 506 public void processWelcome( HttpServletRequest request, 507 HttpServletResponse response ) 508 throws IOException , ServletException { 509 boolean error = true; 511 String msg = null; 512 513 values.put( "welcome_newLocale", (String ) request.getParameter("newLocale").trim() ); 515 516 if( request.getParameter("go").equals("next") ) 519 { 520 String newLocaleStr = (String ) request.getParameter("newLocale"); 521 if (newLocaleStr != null) { 522 Locale newLocale = LanguageCodeConverters.languageCodeToLocale(newLocaleStr); 523 if (newLocale != null) { 524 request.getSession().setAttribute(ParamBean.SESSION_LOCALE, newLocale); 525 Locale.setDefault(newLocale); 526 newSelectedLocale = newLocale; 527 values.put( "org.jahia.multilang.default_language_code", (String ) newSelectedLocale.toString() ); 528 } 529 } 530 error = false; } 532 if( error ) { 534 request.setAttribute( "msg", msg ); 535 displayWelcome( request, response ); 536 } else { 537 if( request.getParameter("go").equals("next") ) { displayRoot( request, response ); 539 } else if( request.getParameter("go").equals("back") ) { displayWelcome( request, response ); 541 } 542 } 543 544 msg = null; 546 } 547 548 549 550 562 public void processRoot( HttpServletRequest request, 563 HttpServletResponse response ) 564 throws IOException , ServletException 565 { 566 boolean error = true; 568 String msg = null; 569 570 values.put( "root_user", (String ) request.getParameter("user").trim() ); 572 values.put( "root_pwd", (String ) request.getParameter("pwd").trim() ); 573 values.put( "root_confirm", (String ) request.getParameter("confirm").trim() ); 574 values.put( "root_firstname", (String ) request.getParameter("firstname").trim() ); 575 values.put( "root_lastname", (String ) request.getParameter("lastname").trim() ); 576 values.put( "root_mail", (String ) request.getParameter("mail").trim() ); 577 578 if( request.getParameter("go").equals("next") ) 580 { 581 if( ((String )values.get("root_user")).length() < 4 ) { request.setAttribute( "focus", "user" ); 583 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.usernameshort.label", 584 newSelectedLocale); 585 } else if( !JahiaTools.isAlphaValid(((String )values.get("root_user"))) ) { request.setAttribute( "focus", "user" ); 587 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.usernameinvalid.label", 588 newSelectedLocale); 589 } else if( ((String )values.get("root_pwd")).length() < 8 ) { request.setAttribute( "focus", "pwd" ); 591 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.passwordshort.label", 592 newSelectedLocale); 593 } else if( !JahiaTools.isAlphaValid(((String )values.get("root_pwd"))) ) { request.setAttribute( "focus", "pwd" ); 595 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.passwordinvalid.label", 596 newSelectedLocale); 597 } else if( ((String )values.get("root_confirm")).length() == 0 ) { request.setAttribute( "focus", "confirm" ); 599 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.passwordmustsame.label", 600 newSelectedLocale); 601 } else if( !((String )values.get("root_pwd")).equals(((String )values.get("root_confirm"))) ) { request.setAttribute( "focus", "pwd" ); 603 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.passwordmustsame.label", 604 newSelectedLocale); 605 } else if( ((String )values.get("root_firstname")).length() == 0 ) { request.setAttribute( "focus", "firstname" ); 607 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.firstnamemustset.label", 608 newSelectedLocale); 609 } else if( ((String )values.get("root_lastname")).length() == 0 ) { request.setAttribute( "focus", "lastname" ); 611 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.lastnamemustset.label", 612 newSelectedLocale); 613 } else { 614 error = false; } 616 } else { 617 error = false; } 619 620 if( error ) { 622 request.setAttribute( "msg", msg ); 623 displayRoot( request, response ); 624 } else { 625 if( request.getParameter("go").equals("next") ) { displayServer( request, response ); 627 } else if( request.getParameter("go").equals("back") ) { displayWelcome( request, response ); 629 } 630 } 631 632 msg = null; 634 } 635 637 638 639 640 649 public void displayServer( HttpServletRequest request, 650 HttpServletResponse response ) 651 throws IOException , ServletException 652 { 653 if( ((String )values.get("server_url")) == null ) { 655 values.put( "server_url", request.getScheme() +"://"+request.getHeader("host") ); 656 } 657 658 if( ((String )values.get("webapps_deploybaseurl")) == null ) { 659 URL deployURL = null; 660 try { 661 deployURL = new java.net.URL ( request.getScheme() +"://"+request.getHeader("host") ); 662 } catch (MalformedURLException mue) { 663 logger.debug("Error", mue); 664 } 665 values.put( "webapps_deploybaseurl", deployURL.toString() ); 666 } 667 668 if( request.getAttribute("focus") == null ) { 670 request.setAttribute( "focus", "home" ); 671 } 672 673 request.setAttribute( "title", "Server settings" ); 675 676 doRedirect( request, response, JSP + "server" ); 678 } 679 681 682 683 684 697 public void processServer( HttpServletRequest request, 698 HttpServletResponse response ) 699 throws IOException , ServletException 700 { 701 boolean error = true; 703 boolean dbError = false; 704 String msg = null; 705 String dbMsg = null; 706 707 values.put( "server_home", (String ) request.getParameter("home").trim() ); 709 values.put( "server_url", (String ) request.getParameter("hosturl").trim() ); 710 values.put( "webapps_deploybaseurl", (String ) request.getParameter("webappsdeploybaseurl").trim() ); 711 values.put( "server_jahiafiles", (String ) request.getParameter("jahiafiles").trim() ); 712 713 if( request.getParameter("go").equals("next") ) 715 { 716 if( ((String )values.get("server_home")).length() == 0 ) { request.setAttribute( "focus", "home" ); 718 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.servletcontainer_homepath_mustset.lable", 719 newSelectedLocale); 720 } else if( ((String )values.get("server_url")).length() == 0 ) { request.setAttribute( "focus", "hosturl" ); 722 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.hosturl_mustset.label", 723 newSelectedLocale); 724 } else if( ((String )values.get("webapps_deploybaseurl")).length() == 0 ) { request.setAttribute( "focus", "webappsdeploybaseurl" ); 726 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.appdeploy_baseurl_mustset.label", 727 newSelectedLocale); 728 } else if( ((String )values.get("server_jahiafiles")).length() == 0 ) { request.setAttribute( "focus", "jahiafiles" ); 730 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.jahiafiles_path_mustset.label", 731 newSelectedLocale); 732 } else { 733 error = false; } 735 736 checkServerSlashs(); 738 739 try 741 { 742 tryServerHome(); 744 745 757 758 tryJahiaFilesPath(); 760 } catch (Exception e) { 761 msg = e.getMessage(); 762 error = true; 763 } 764 765 if( ((Boolean )values.get("database_custom")) == Boolean.FALSE ) { 767 fillDefaultValues( false, true ); 768 } 769 770 HashMap test = testDBConnection(); 772 dbError = ((Boolean )test.get("testDatabaseConnectionError")).booleanValue(); 773 dbMsg = (String )test.get("testDatabaseConnectionMessage"); 774 if (dbMsg != null && dbMsg.length() > 0) { 775 request.setAttribute( "msg", dbMsg ); 776 } 777 778 } else { 779 error = false; } 781 782 if( error ) { request.setAttribute( "msg", msg ); 785 displayServer( request, response ); 786 } else if( dbError ) { request.setAttribute( "msg", dbMsg ); 788 values.put( "database_requested", Boolean.FALSE ); 789 displayAdvSettings( request, response ); 790 } else { 791 if( request.getParameter("go").equals("next") ) { displayMail( request, response ); 793 } else if( request.getParameter("go").equals("back") ) { displayRoot( request, response ); 795 } else if( request.getParameter("go").equals("advanced") ) { values.put( "database_requested", Boolean.TRUE ); 797 displayAdvSettings( request, response ); 798 } 799 } 800 801 msg = null; 803 dbMsg = null; 804 } 805 807 808 809 810 819 public void displayAdvSettings( HttpServletRequest request, 820 HttpServletResponse response ) 821 throws IOException , ServletException 822 { 823 Vector scriptsInfos = scripts.getDatabaseScriptsInfos( scripts.getDatabaseScriptsFileObjects(), pathResolver ); 825 values.put( "database_test", scripts); 826 827 request.setAttribute( "scripts", scriptsInfos.elements() ); 829 request.setAttribute( "jsscripts", scriptsInfos.elements() ); 830 831 if( request.getAttribute("focus") == null ) { 833 request.setAttribute( "focus", "driver" ); 834 } 835 836 request.setAttribute( "title", "Advanced settings" ); 838 839 doRedirect( request, response, JSP + "adv_settings" ); 841 } 842 843 853 public void processAdvSettings( HttpServletRequest request, 854 HttpServletResponse response ) 855 throws IOException , ServletException 856 { 857 boolean error = true; 859 boolean dbError = false; 860 String msg = null; 861 String dbMsg = null; 862 863 values.put( "database_script", (String ) request.getParameter("script").trim() ); 865 values.put( "database_driver", (String ) request.getParameter("driver").trim() ); 866 values.put( "database_url", (String ) request.getParameter("dburl").trim() ); 867 values.put( "database_user", (String ) request.getParameter("user").trim() ); 868 values.put( "database_pwd", (String ) request.getParameter("pwd").trim() ); 869 values.put( "database_support_embedded_select_statement", (String ) request.getParameter("database_support_embedded_select_statement").trim() ); 870 871 String utf8Encoding = request.getParameter("utf8Encoding"); 872 if (utf8Encoding == null) utf8Encoding = "false"; 873 values.put( "utf8Encoding", utf8Encoding ); 874 875 if( request.getParameter("go").equals("next") || 877 request.getParameter("go").equals("apply") ) 878 { 879 if( ((String )values.get("database_driver")).length() == 0 ) { request.setAttribute( "focus", "driver" ); 881 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.dbdriver_mustset.label", 882 newSelectedLocale); 883 } else if( ((String )values.get("database_url")).length() == 0 ) { request.setAttribute( "focus", "dburl" ); 885 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.dburl_mustset.label", 886 newSelectedLocale); 887 } else { 888 error = false; } 890 891 HashMap test = testDBConnection(); 893 dbError = ((Boolean )test.get("testDatabaseConnectionError")).booleanValue(); 894 dbMsg = (String )test.get("testDatabaseConnectionMessage"); 895 896 } else { 897 error = false; } 899 900 if( error ) { request.setAttribute( "msg", msg ); 903 displayAdvSettings( request, response ); 904 } else if( dbError ) { request.setAttribute( "msg", dbMsg ); 906 displayAdvSettings( request, response ); 907 } else { 908 if( request.getParameter("go").equals("apply") ) { values.put( "database_custom", Boolean.TRUE ); 911 displayServer( request, response ); 912 } else if( request.getParameter("go").equals("next") ) { values.put( "database_custom", Boolean.TRUE ); 914 displayMail( request, response ); 915 } 916 } 917 918 msg = null; 920 dbMsg = null; 921 } 922 923 932 public void displayMail( HttpServletRequest request, 933 HttpServletResponse response ) 934 throws IOException , ServletException 935 { 936 if( request.getAttribute("focus") == null ) { 938 request.setAttribute( "focus", "server" ); 939 } 940 941 request.setAttribute( "title", "Mail settings" ); 943 944 doRedirect( request, response, JSP + "mail" ); 946 } 947 949 950 951 952 962 public void processMail( HttpServletRequest request, 963 HttpServletResponse response ) 964 throws IOException , ServletException 965 { 966 boolean error = true; 968 String msg = null; 969 970 values.put( "mail_server", (String ) request.getParameter("server").trim() ); 972 values.put( "mail_recipient", (String ) request.getParameter("rcpt").trim() ); 973 values.put( "mail_from", (String ) request.getParameter("from").trim() ); 974 values.put( "mail_parano", (String ) request.getParameter("parano").trim() ); 975 976 if( request.getParameter("go").equals("next") ) 978 { 979 if( !((String )values.get("mail_parano")).equals("Disabled") ) { 981 if( ((String )values.get("mail_server")).length() == 0 ) { request.setAttribute( "focus", "server" ); 983 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.mailserver_mustset.label", 984 newSelectedLocale); 985 } else if( ((String )values.get("mail_recipient")).length() == 0 ) { request.setAttribute( "focus", "rcpt" ); 987 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.mailrecipient_mustset.label", 988 newSelectedLocale); 989 } else if( ((String )values.get("mail_from")).length() == 0 ) { request.setAttribute( "focus", "from" ); 991 msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.mailfromaddress_mustset.label", 992 newSelectedLocale); 993 } else { 994 error = false; } 996 } else { 997 error = false; } 999 } else { 1000 error = false; } 1002 1003 if( error ) { request.setAttribute( "msg", msg ); 1006 displayMail( request, response ); 1007 } else { 1008 if( request.getParameter("go").equals("back") ) { if( ((Boolean )values.get("database_requested")).booleanValue() ) { 1010 displayServer( request, response ); } else { 1012 displayAdvSettings( request, response ); } 1014 } else if( request.getParameter("go").equals("next") ) { displayTemplates( request, response ); 1016 } 1017 } 1018 1019 msg = null; 1021 } 1022 1024 1025 1026 1027 1036 public void displayTemplates( HttpServletRequest request, 1037 HttpServletResponse response ) 1038 throws IOException , ServletException 1039 { 1040 request.setAttribute( "packages", listTemplatesFiles() ); 1042 1043 request.setAttribute( "title", "Choose a base templates package" ); 1045 1046 doRedirect( request, response, JSP + "templates" ); 1048 } 1049 1051 1052 1053 1054 1064 public void processTemplates( HttpServletRequest request, 1065 HttpServletResponse response ) 1066 throws IOException , ServletException 1067 { 1068 boolean error = true; 1070 String msg = null; 1071 1072 String choice = (String ) request.getParameter("choice"); 1074 if ( choice == null || choice.equals("0")){ 1075 choice = properties.getProperty("default_templates_set").trim(); 1076 } 1077 values.put( "templates", choice ); 1078 1079 if( request.getParameter("go").equals("next") ) 1081 { 1082 if( values.get("templates") == null ) { msg = JahiaResourceBundle.getMessageResource("org.jahia.bin.JahiaConfigurationWizard.JahiaConfigurationMsg.package_mustselect.label", 1084 newSelectedLocale); 1085 } else { 1086 error = false; 1087 } 1088 } else { 1089 error = false; } 1091 1092 if( error ) { request.setAttribute( "msg", msg ); 1095 values.put("templates", properties.getProperty("default_templates_set").trim()); 1096 displayTemplates( request, response ); 1097 } else { 1098 if( request.getParameter("go").equals("back") ) { displayTemplates( request, response ); 1100 } else if( request.getParameter("go").equals("next") ) { displayValues( request, response ); 1102 } else if ( request.getParameter("go").equals("change") ){ 1103 displayTemplates( request, response ); 1104 } 1105 } 1106 1107 msg = null; 1109 } 1110 1112 1113 1114 1115 1121 private Enumeration listTemplatesFiles() 1122 throws IOException 1123 { 1124 Vector vec = new Vector (); 1125 1126 String path = ((String )values.get("server_jahiafiles_default")).substring(8, ((String )values.get("server_jahiafiles_default")).length()) + File.separator + "var" + File.separator + "shared_templates"; 1127 File file = new File ( context.getRealPath(path) ); 1128 File [] list = file.listFiles(); 1129 1130 for(int i=0; i<list.length; i++) { 1131 if(!list[i].isDirectory() && list[i].getName().endsWith(".jar")) { 1132 String name = list[i].getName().substring( 0, list[i].getName().lastIndexOf(".") ); 1133 vec.add( name ); 1134 } 1135 } 1136 1137 return vec.elements(); 1138 } 1139 1141 1142 1143 1144 1153 public void displayValues( HttpServletRequest request, 1154 HttpServletResponse response ) 1155 throws IOException , ServletException 1156 { 1157 request.setAttribute( "title", "Confirm your values" ); 1159 1160 doRedirect( request, response, JSP + "values" ); 1162 } 1163 1165 1166 1167 1168 1178 public void processValues( HttpServletRequest request, 1179 HttpServletResponse response ) 1180 throws IOException , ServletException 1181 { 1182 boolean error = true; 1184 String msg = null; 1185 1186 try 1188 { 1189 if( !old_database.equals("true") ) 1191 { 1192 if (!"false".equals(createTables)) { 1193 createDBTables(); 1194 } 1195 insertDBCustomContent(); 1196 insertDBDefaultContent(); 1197 1198 copyDefaultTemplates( "myjahiasite" ); 1200 1202 properties.setProperty( "defautSite", "myjahiasite" ); 1204 1205 folderXMLtemplates(); 1207 } 1208 1209 copySharedComponents("myjahiasite"); 1211 1212 moveJahiaFiles(); 1214 1215 db.databaseClose(); 1217 1218 setPropertiesObject(); 1220 1221 properties.storeProperties( Jahia.getJahiaPropertiesFileName() ); 1223 1224 error = false; 1226 1227 } catch (Exception e) { 1228 logger.debug("Exception", e); 1229 msg = e.getMessage(); 1230 } 1231 1232 if( error ) { request.setAttribute( "errormsg", msg ); 1235 displayError( request, response ); 1236 } else { 1237 displayFinalStep( request, response ); } 1239 1240 msg = null; 1242 } 1243 1245 1246 1247 1248 1257 public void displayError( HttpServletRequest request, 1258 HttpServletResponse response ) 1259 throws IOException , ServletException 1260 { 1261 request.setAttribute( "title", "Error" ); 1263 1264 doRedirect( request, response, JSP + "error_save" ); 1266 } 1267 1269 1270 1271 1272 1281 public void displayFinalStep( HttpServletRequest request, 1282 HttpServletResponse response ) 1283 throws IOException , ServletException 1284 { 1285 request.setAttribute( "title", "Congratulations!" ); 1287 1288 Limit daysLeftLimit = Jahia.getCoreLicense().getLimit("maxUsageDays"); 1289 if (daysLeftLimit != null) { 1292 DaysLeftValidator daysLeftValidator = (DaysLeftValidator) 1293 daysLeftLimit.getValidator(); 1294 int maxDays = Integer.parseInt(daysLeftLimit.getValueStr()); 1295 request.setAttribute("allowedDays", new Integer (maxDays)); 1296 EngineMessage allowedDaysMsg = new EngineMessage("org.jahia.bin.JahiaConfigurationWizard.congratulations.daysLeftInLicense.label", new Integer (maxDays)); 1297 request.setAttribute("allowedDaysMsg", allowedDaysMsg); 1298 } 1299 1300 doRedirect( request, response, JSP + "congratulations" ); 1302 } 1303 1305 1306 1307 1308 1317 public void redirectToJahia( HttpServletRequest request, 1318 HttpServletResponse response ) 1319 throws IOException , ServletException 1320 { 1321 request.setAttribute( CLASS_NAME + ".finishedInstallation", "true" ); 1323 request.setAttribute( CLASS_NAME + ".rootName", (String )values.get("root_user") ); 1324 request.setAttribute( CLASS_NAME + ".rootPass", (String )values.get("root_pwd") ); 1325 1326 doRedirect( request, response, contentServletPath ); 1328 } 1329 1331 1332 1333 1334 1339 private void checkServerSlashs() 1340 { 1341 if( !((String )values.get("server_home")).endsWith(File.separator) ) { values.put( "server_home", 1343 ((String )values.get("server_home"))+File.separator ); 1344 } 1345 if( ((String )values.get("server_url")).endsWith("/") ) { values.put( "server_url", 1347 ((String )values.get("server_url")).substring(0, 1348 ((String )values.get("server_url")).length()-1 ) ); 1349 } 1350 if( ((String )values.get("server_jahiafiles")).endsWith(File.separator) ) { values.put( "server_jahiafiles", 1352 ((String )values.get("server_jahiafiles")).substring(0, 1353 ((String )values.get("server_jahiafiles")).length()-1 ) ); 1354 } 1355 } 1356 1358 1359 1360 1361 1372 private void tryServerHome() 1373 throws Exception 1374 { 1375 1376 1392 } 1393 1395 1396 1397 1398 1405 private void tryHostURL() 1406 throws Exception 1407 { 1408 URL url = null; 1409 InputStream istream = null; 1410 1411 try 1412 { 1413 url = new URL ( ((String )values.get("server_url")) ); 1414 istream = url.openStream(); 1415 istream.close(); 1416 1417 } catch (Exception e) { 1418 logger.error("Error while connecting to server URL " + url, e); 1419 throw new Exception ( "Cannot connect to your server URL at " + url ); 1420 } 1421 1422 istream = null; 1424 url = null; 1425 } 1426 1428 1429 1436 private void tryWebAppsDeployBaseURL() 1437 throws Exception 1438 { 1439 URL url = null; 1440 InputStream istream = null; 1441 1442 try 1443 { 1444 url = new URL ( ((String )values.get("webapps_deploybaseurl")) ); 1445 istream = url.openStream(); 1446 istream.close(); 1447 1448 } catch (Exception e) { 1449 logger.debug("Error while connecting to web apps deployment URL at : " + url, e); 1450 throw new Exception ( "Cannot connect to the web applications deployment base URL at " + url ); 1451 } 1452 1453 istream = null; 1455 url = null; 1456 } 1457 1459 1460 1461 1468 private void tryJahiaFilesPath() 1469 throws Exception 1470 { 1471 String jahiaFiles = null; 1472 1473 try 1474 { 1475 if( ((String )values.get("server_jahiafiles")).substring(0,9).equals("$context/") ) { 1477 jahiaFiles = context.getRealPath( 1478 ((String )values.get("server_jahiafiles")).substring( 1479 8, ((String )values.get("server_jahiafiles")).length() ) ); 1480 } else { 1481 throw new StringIndexOutOfBoundsException (); 1482 } 1483 } catch (StringIndexOutOfBoundsException sioobe) { 1484 jahiaFiles = (String )values.get("server_jahiafiles"); 1485 } 1486 1487 if( jahiaFiles.indexOf(File.separator) == -1 ) { 1489 throw new Exception ( "Jahia Files must be a valid filesystem or context-relative path." ); 1490 } 1491 1492 File jf = new File ( jahiaFiles ); 1494 File parent = null; 1495 1496 if( jf.exists() ) 1498 { 1499 if( jf.isFile() ) { throw new Exception ( "Jahia Files must be a directory, and not a file." ); 1501 } 1502 if( !jf.canRead() ) { throw new Exception ( "Can't read in Jahia Files directory. Please verify permissions." ); 1504 } 1505 if( !jf.canWrite() ) { throw new Exception ( "Can't write in Jahia Files directory. Please verify permissions." ); 1507 } 1508 1509 } else { 1510 parent = jf.getParentFile(); 1512 1513 if( parent.exists() ) { 1515 if( !parent.canWrite() ) { throw new Exception ( "Jahia can't create your directory (write permissions)." ); 1517 } 1518 } else { 1519 if( !parent.mkdirs() ) { throw new Exception ( "Jahia can't create your directory (write permissions)." ); 1521 } 1522 } 1523 } 1524 1525 parent = null; 1527 jf = null; 1528 jahiaFiles = null; 1529 } 1530 1532 1533 1534 1535 1543 private HashMap testDBConnection() 1544 { 1545 String line; 1546 try { 1548 BufferedReader inBuffer = new BufferedReader ( 1549 new FileReader (dbScriptsPath + File.separator + 1550 values.get("database_script"))); 1551 while ((line = inBuffer.readLine()) != null) { 1552 if (line.indexOf("jahia_db_test", 13) >= 0) { 1553 break; 1554 } 1555 } 1556 } catch (IOException ioe) { 1557 line = "unknown"; 1558 } 1559 return db.databaseTest( (String )values.get("database_script"), (String )values.get("database_driver"), 1561 (String )values.get("database_url"), (String )values.get("database_user"), 1562 (String )values.get("database_pwd"), line, 1563 "true".equals(values.get("utf8Encoding")), !"false".equals(createTables) ); 1564 } 1565 1566 1574 private void createDBTables() 1575 throws Exception 1576 { 1577 File object = null; 1578 Enumeration runtime = null; 1579 String line = null; 1580 1581 logger.debug("Creating database tables..."); 1582 1583 StringBuffer script = new StringBuffer ( dbScriptsPath ); 1585 script.append( File.separator ); 1586 script.append( (String )values.get("database_script") ); 1587 1588 try { 1590 object = new File ( script.toString() ); 1591 runtime = scripts.getDatabaseScriptsRuntime( object ); 1592 } catch (Exception e) { 1593 throw new Exception ( "Jahia can't read the appropriate database script." ); 1594 } 1595 1596 while( runtime.hasMoreElements() ) { 1598 line = (String ) runtime.nextElement(); 1599 String lowerCaseLine = line.toLowerCase(); 1600 int tableNamePos = lowerCaseLine.indexOf("create table"); 1601 if (tableNamePos != -1) { 1602 String tableName = line.substring("create table".length() + 1603 tableNamePos, 1604 line.indexOf("(")).trim(); 1605 logger.debug("Creating table [" + tableName + "] ..."); 1606 try { 1607 db.query("DROP TABLE " + tableName); 1608 } catch (Exception e) { 1609 } 1612 } 1613 try { 1614 db.query( line ); 1615 } catch (Exception e) { 1616 logger.error("Error while trying to execute query : " + line + " from script " + script.toString()); 1617 throw e; 1619 } 1620 } 1621 1622 object = null; 1624 script = null; 1625 runtime = null; 1626 line = null; 1627 } 1628 1630 1631 1632 1633 1640 private void insertDBCustomContent() 1641 throws Exception 1642 { 1643 1644 logger.debug("Inserting customized settings into database..."); 1645 1646 String rootName = (String )values.get("root_user"); 1648 int siteID0 = 0; 1649 int siteID1 = 1; 1650 String rootKey = rootName + ":" + siteID0; 1651 String grpKey0 = JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME + ":" + siteID0; 1652 String grpKey1 = JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME + ":" + siteID1; 1653 1654 StringBuffer sqlRootUser = new StringBuffer (); 1656 sqlRootUser.append( "INSERT INTO jahia_users(id_jahia_users, name_jahia_users, password_jahia_users, key_jahia_users, siteid_jahia_users) VALUES(0, '" ); 1657 sqlRootUser.append( rootName + "', '"); 1658 sqlRootUser.append( JahiaUserManagerService.encryptPassword( (String )values.get("root_pwd") ) ); 1659 sqlRootUser.append( "','" + rootKey + "', " + siteID0 + ")" ); 1660 db.query( sqlRootUser.toString() ); 1661 1662 sqlRootUser = new StringBuffer (); 1664 sqlRootUser.append( "INSERT INTO jahia_user_prop(id_jahia_users, name_jahia_user_prop, value_jahia_user_prop, provider_jahia_user_prop, userkey_jahia_user_prop) VALUES(0, 'firstname', '" ); 1665 sqlRootUser.append( JahiaTools.replacePattern((String )values.get("root_firstname"), "'", "''") + "'," ); 1666 sqlRootUser.append( "'jahia', '" + rootKey + "')" ); 1667 db.query( sqlRootUser.toString() ); 1668 1669 sqlRootUser = new StringBuffer (); 1671 sqlRootUser.append( "INSERT INTO jahia_user_prop(id_jahia_users, name_jahia_user_prop, value_jahia_user_prop, provider_jahia_user_prop, userkey_jahia_user_prop) VALUES(0, 'lastname', '" ); 1672 sqlRootUser.append( JahiaTools.replacePattern((String )values.get("root_lastname"), "'", "''") + "'," ); 1673 sqlRootUser.append( "'jahia', '" + rootKey + "')" ); 1674 db.query( sqlRootUser.toString() ); 1675 1676 sqlRootUser = new StringBuffer (); 1678 sqlRootUser.append( "INSERT INTO jahia_user_prop(id_jahia_users, name_jahia_user_prop, value_jahia_user_prop, provider_jahia_user_prop, userkey_jahia_user_prop) VALUES(0, 'email', '" ); 1679 sqlRootUser.append( (String )values.get("root_mail") + "'," ); 1680 sqlRootUser.append( "'jahia', '" + rootKey + "')" ); 1681 db.query( sqlRootUser.toString() ); 1682 1683 sqlRootUser = new StringBuffer (); 1685 sqlRootUser.append( "INSERT INTO jahia_grps(id_jahia_grps, name_jahia_grps, key_jahia_grps, siteid_jahia_grps) VALUES("); 1686 sqlRootUser.append( siteID0 + ", '"); 1687 sqlRootUser.append( JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME + "','" ); 1688 sqlRootUser.append( grpKey0 + "', " + siteID0 + ")" ); 1689 db.query( sqlRootUser.toString() ); 1690 1691 sqlRootUser = new StringBuffer (); 1693 sqlRootUser.append( "INSERT INTO jahia_grp_access(id_jahia_member, id_jahia_grps, membertype_grp_access) VALUES('" ); 1694 sqlRootUser.append( rootKey + "', '" + grpKey0 + "', 1)" ); db.query( sqlRootUser.toString() ); 1696 1697 sqlRootUser = new StringBuffer (); 1699 sqlRootUser.append( "INSERT INTO jahia_grp_access(id_jahia_member, id_jahia_grps, membertype_grp_access) VALUES('" ); 1700 sqlRootUser.append( rootKey + "','" + grpKey1 + "', 1)" ); db.query( sqlRootUser.toString() ); 1702 1703 sqlRootUser = new StringBuffer (); 1705 sqlRootUser.append( "INSERT INTO jahia_sites_users(username_sites_users, siteid_sites_users, userid_sites_users) VALUES('" ); 1706 sqlRootUser.append( rootName + "', " + siteID1 + ", '" + rootKey + "')" ); 1707 db.query( sqlRootUser.toString() ); 1708 1709 } 1710 1712 1713 1714 1715 1724 private void insertDBDefaultContent() 1725 throws Exception 1726 { 1727 File object = null; 1729 Enumeration runtime = null; 1730 String line = null; 1731 1732 1733 StringBuffer script = new StringBuffer ( dbScriptsPath ); 1735 script.append( File.separator ); 1736 if ( values.get("templates") != null ){ 1738 script.append( "default_"+JahiaTools.removeFileExtension((String )values.get("templates"),".jar") ); 1739 if (newSelectedLocale != null) { 1740 StringBuffer tmpFileName1 = new StringBuffer (script.toString()); 1741 StringBuffer tmpFileName2 = new StringBuffer (script.toString()); 1742 if (newSelectedLocale.toString().length() == 6) { 1743 tmpFileName1.append("_" + 1744 newSelectedLocale.toString(). 1745 substring(0, 5) + ".values"); 1746 } 1747 tmpFileName2.append("_" + newSelectedLocale.toString().substring(0,2) + ".values"); 1748 File tmpFile1 = new File (tmpFileName1.toString()); 1749 File tmpFile2 = new File (tmpFileName2.toString()); 1750 if ((newSelectedLocale.toString().length() == 6) && (tmpFile1.exists())) { 1751 script.append("_" + newSelectedLocale.toString().substring(0,5)); 1752 } else if (tmpFile2.exists()) { 1753 script.append("_" + newSelectedLocale.toString().substring(0,2)); 1754 } 1755 tmpFileName1 = null; 1756 tmpFileName2 = null; 1757 tmpFile1 = null; 1758 tmpFile2 = null; 1759 } 1760 script.append(".values"); 1761 } 1762 1763 try { 1765 logger.debug("Inserting default database content from file " + script.toString() + "..."); 1766 object = new File ( script.toString() ); 1767 runtime = scripts.getDatabaseScriptsRuntime( object ); 1768 } catch (Exception e) { 1769 logger.error("Jahia can't read the file containing database values.", e); 1770 throw e; 1771 } 1772 1773 int count = 0; 1775 while( runtime.hasMoreElements() ) { 1776 line = (String ) runtime.nextElement(); 1777 count++; 1778 try { 1779 db.query( line ); 1780 } catch (Exception e) { 1781 logger.error("Error while processing line "+count+"[" + line + "]"); 1782 throw e; 1783 } 1784 } 1785 1786 object = null; 1788 script = null; 1789 runtime = null; 1790 line = null; 1791 } 1792 1794 1795 1796 1797 1802 private void folderXMLtemplates() 1803 throws Exception 1804 { 1805 File folder = new File ( Jahia.jahiaTemplatesScriptsPath ); 1806 if(!folder.exists()) { 1807 folder.mkdirs(); 1808 } else { 1809 File [] list = folder.listFiles(); 1810 for(int i=0; i<list.length; i++) { 1811 JahiaTools.deleteFile( list[i] ); 1812 } 1813 list = null; 1814 } 1815 folder = null; 1816 } 1817 1819 1820 1821 1822 1827 private void setPropertiesObject() 1828 { 1829 String appsService = null; 1830 1831 StringBuffer jahiaInsideHttpPath = new StringBuffer (); 1833 jahiaInsideHttpPath.append( Jahia.getContextPath() ); 1835 jahiaInsideHttpPath.append( properties.getProperty( "jahiaJspDiskPath" ) ); 1836 1837 if( ((String )serverInfos.get("type")).equals("orion") ) { 1839 appsService = "org.jahia.services.webapps_deployer.JahiaOrionWebAppsDeployerBaseService"; 1840 } else if( ((String )serverInfos.get("type")).indexOf("JBoss") != -1 ) { 1841 appsService = "org.jahia.services.webapps_deployer.JahiaJBossWebAppsDeployerBaseService"; 1842 } else if( ((String )serverInfos.get("type")).indexOf("Tomcat") != -1 ) { 1843 appsService = "org.jahia.services.webapps_deployer.JahiaTomcatWebAppsDeployerBaseService"; 1844 } else { 1845 appsService = "org.jahia.services.webapps_deployer.GenericWebAppsDeployerBaseService"; 1846 } 1847 1848 String release = new Double (Jahia.RELEASE_NUMBER).toString() + "." + new Integer (Jahia.SERVICE_PACK_NUMBER).toString(); 1850 if (! "".equals(Jahia.PATCH_STRING)) { 1851 release = release + "_" + Jahia.PATCH_STRING; 1852 } 1853 1854 properties.setProperty("release", release ); 1856 properties.setProperty("server", (String )serverInfos.get("type") ); 1857 properties.setProperty("serverHomeDiskPath", (String )values.get("server_home") ); 1858 properties.setProperty("jahiaFilesDiskPath", (String )values.get("server_jahiafiles") ); 1859 properties.setProperty("jahiaEtcDiskPath", (String )values.get("server_jahiafiles")+"/etc/" ); 1860 properties.setProperty("jahiaVarDiskPath", (String )values.get("server_jahiafiles")+"/var/" ); 1861 properties.setProperty("jahiaFilesBigTextDiskPath", (String )values.get("server_jahiafiles")+"/var/content/bigtext/" ); 1862 properties.setProperty("slideContentDiskPath", (String )values.get("server_jahiafiles")+"/var/content/slide/" ); 1863 properties.setProperty("tmpContentDiskPath", (String )values.get("server_jahiafiles")+"/var/content/tmp/" ); 1864 properties.setProperty("jahiaFilesTemplatesDiskPath", (String )values.get("server_jahiafiles")+"/var/templates/" ); 1865 properties.setProperty("jahiaNewTemplatesDiskPath", (String )values.get("server_jahiafiles")+"/var/new_templates/" ); 1866 properties.setProperty("jahiaNewWebAppsDiskPath", (String )values.get("server_jahiafiles")+"/var/new_webapps/" ); 1867 properties.setProperty("jahiaSharedComponentsDiskPath", (String )values.get("server_jahiafiles")+"/var/shared_components/" ); 1868 properties.setProperty("jahiaSharedTemplatesDiskPath", (String )values.get("server_jahiafiles")+"/var/shared_templates/" ); 1869 properties.setProperty("jahiaFileRepositoryDiskPath", (String )values.get("server_jahiafiles")+"/var/content/filemanager/" ); 1870 properties.setProperty("jahiaHostHttpPath", "" ); 1872 properties.setProperty("jahiaCoreHttpPath", Jahia.getRelativeServletURI() ); 1873 properties.setProperty("jahiaTemplatesHttpPath", jahiaInsideHttpPath.toString() + "templates/" ); 1874 properties.setProperty("jahiaEnginesHttpPath", jahiaInsideHttpPath.toString() + "engines/" ); 1875 properties.setProperty("jahiaJavaScriptHttpPath", jahiaInsideHttpPath.toString() + "javascript/jahia.js" ); 1876 properties.setProperty("mail_server", (String )values.get("mail_server") ); 1877 properties.setProperty("mail_administrator", (String )values.get("mail_recipient") ); 1878 properties.setProperty("mail_from", (String )values.get("mail_from") ); 1879 properties.setProperty("mail_paranoia", (String )values.get("mail_parano") ); 1880 properties.setProperty("db_script", (String )values.get("database_script") ); 1881 properties.setProperty("db_driver", (String )values.get("database_driver") ); 1882 properties.setProperty("db_url", (String )values.get("database_url") ); 1883 properties.setProperty("db_username", (String )values.get("database_user") ); 1884 properties.setProperty("db_password", (String )values.get("database_pwd") ); 1885 properties.setProperty("db_transactions", (String )values.get("database_transactions") ); 1886 properties.setProperty("db_support_embedded_select_statement", (String )values.get("database_support_embedded_select_statement") ); 1887 String utf8Encoding = (String )values.get("utf8Encoding"); 1888 properties.setProperty("utf8Encoding", utf8Encoding); 1889 if ("true".equalsIgnoreCase(utf8Encoding)) { 1890 properties.setProperty("defaultResponseBodyEncoding", "UTF-8"); 1891 } else { 1892 properties.setProperty("defaultResponseBodyEncoding", "ISO-8859-1"); 1893 } 1894 if ( appsService.length() != 0 ) { 1895 properties.setProperty("JahiaWebAppsDeployerService", appsService ); 1896 properties.setProperty("jahiaWebAppsDeployerBaseURL", (String ) values.get("webapps_deploybaseurl")); 1897 } 1898 properties.setProperty("org.jahia.multilang.default_language_code", (String )values.get("org.jahia.multilang.default_language_code") ); 1899 1900 appsService = null; 1902 release = null; 1903 1904 } 1906 1907 1908 1909 1914 private void fillDefaultValues() 1915 { 1916 fillDefaultValues( true, true ); 1917 } 1918 1920 1921 1922 1923 1931 private void fillDefaultValues( boolean all, boolean database ) 1932 { 1933 properties = new PropertiesManager( context.getRealPath(config.getInitParameter("skeleton")) ); 1935 1936 if( all ) { 1938 values.put( "root_user", "root" ); 1939 values.put( "root_pwd", "" ); 1940 values.put( "root_confirm", "" ); 1941 values.put( "root_firstname", "Jahia" ); 1942 values.put( "root_lastname", "Super Administrator" ); 1943 values.put( "root_mail", "" ); 1944 } 1945 1946 if( all ) { 1948 values.put( "server_home", (String )serverInfos.get("home") ); 1949 values.put( "server_url", null ); 1950 values.put( "server_jahiafiles", properties.getProperty("jahiaFilesDiskPath").trim() ); 1951 values.put( "server_jahiafiles_default", properties.getProperty("jahiaFilesDiskPath").trim() ); 1952 } 1953 1954 if( database || all ) { 1956 values.put( "database_script", properties.getProperty("db_script").trim() ); 1957 if( ((String )serverInfos.get("type")).indexOf("JBoss") != -1 ) { 1958 values.put( "database_script", "jboss.script" ); 1959 } 1960 values.put( "database_driver", properties.getProperty("db_driver").trim() ); 1961 values.put( "database_url", properties.getProperty("db_url").trim() ); 1962 values.put( "database_user", properties.getProperty("db_username").trim() ); 1963 values.put( "database_pwd", properties.getProperty("db_password").trim() ); 1964 values.put ("database_transactions", properties.getProperty("db_transactions").trim()); 1965 values.put ("database_support_embedded_select_statement", properties.getProperty("db_support_embedded_select_statement").trim()); 1966 values.put( "utf8Encoding", properties.getProperty("utf8Encoding").trim() ); 1967 values.put( "database_custom", Boolean.FALSE ); 1968 values.put( "database_requested", Boolean.FALSE ); 1969 try { 1970 Vector scriptsInfos = scripts.getDatabaseScriptsInfos(scripts. 1973 getDatabaseScriptsFileObjects(), pathResolver); 1974 Enumeration scriptInfoEnum = scriptsInfos.elements(); 1975 while (scriptInfoEnum.hasMoreElements()) { 1976 HashMap curDatabaseHash = (HashMap ) scriptInfoEnum.nextElement(); 1977 String scriptFileName = (String ) curDatabaseHash.get("jahia.database.script"); 1978 if (scriptFileName.equals(values.get("database_script"))) { 1979 logger.debug("Found script " + scriptFileName + ", copying default values"); 1980 values.put ("database_driver", ((String ) curDatabaseHash.get("jahia.database.driver")).trim()); 1981 values.put ("database_url", ((String ) curDatabaseHash.get("jahia.database.url")).trim()); 1982 values.put ("database_user", ((String ) curDatabaseHash.get("jahia.database.user")).trim()); 1983 values.put ("database_pwd", ((String ) curDatabaseHash.get("jahia.database.pass")).trim()); 1984 values.put ("database_transactions", ((String ) curDatabaseHash.get("jahia.database.transactions")).trim()); 1985 values.put ("database_support_embedded_select_statement", ((String ) curDatabaseHash.get("jahia.database.support_embedded_select_statement")).trim()); 1986 1987 } 1988 } 1989 } catch (IOException ioe) { 1990 logger.debug("Error while loading default values from database scripts", ioe); 1991 } 1992 } 1993 1994 if( all ) { 1996 values.put( "mail_server", "" ); 1997 values.put( "mail_recipient", "" ); 1998 values.put( "mail_from", "" ); 1999 values.put( "mail_parano", "" ); 2000 } 2001 2002 if( all ) { 2004 values.put( "templates", properties.getProperty("default_templates_set").trim() ); 2005 } 2006 } 2007 2009 2010 2011 2012 2013 2014 2015 2020 2021 2022 2023 2027 private void moveJahiaFiles() 2028 throws Exception 2029 { 2030 String choosed_path = (String )values.get("server_jahiafiles"); 2032 String original_path = context.getRealPath( 2033 ((String )values.get("server_jahiafiles_default")).substring( 8, 2034 ((String )values.get("server_jahiafiles_default")).length()) ); 2035 2036 try { 2038 if(choosed_path.substring(0,9).equals("$context/")) { 2039 choosed_path = context.getRealPath( choosed_path.substring(8, choosed_path.length()) ); 2040 } 2041 } catch (StringIndexOutOfBoundsException sioobe) { 2042 } 2043 2044 File choosedFolder = new File ( choosed_path ); 2046 File originalFolder = new File ( original_path ); 2047 2048 if( !choosedFolder.equals( originalFolder ) ) { 2050 File [] originalFolderContent = originalFolder.listFiles(); 2051 HashMap originalContent = new HashMap (); 2052 for(int i=0; i<originalFolderContent.length; i++) { 2053 originalContent.put( (String )originalFolderContent[i].getName(), (String )originalFolderContent[i].getPath() ); 2054 } 2055 2056 originalContent.remove( "database" ); 2058 originalContent.remove( "config" ); 2059 2060 Object [] originalContentFinal = originalContent.values().toArray(); 2062 File startFile; 2063 2064 for(int i=0; i<originalContentFinal.length; i++) { 2066 startFile = new File ( originalContentFinal[i].toString() ); 2067 String endFile = choosedFolder.getPath() + File.separator + startFile.getName(); 2068 try { 2069 JahiaTools.copyFolderContent( startFile.getPath(), endFile ); 2070 } catch (IOException ioe) { 2071 } 2072 } 2073 2074 for(int i=0; i<originalContentFinal.length; i++) { 2076 startFile = new File ( originalContentFinal[i].toString() ); 2077 JahiaTools.deleteFile(startFile); 2078 } 2079 2080 } 2081 } 2083 2084 2085 2086 2087 2095 protected void copySharedTemplates(String siteKey) 2096 throws Exception 2097 { 2098 String sharedTemplatesFolder = ((String )values.get("server_jahiafiles_default")).substring(8, ((String )values.get("server_jahiafiles_default")).length()) + File.separator + "var" + File.separator + "shared_templates"; 2100 2101 File f = new File ( context.getRealPath(sharedTemplatesFolder) + File.separator + (String )values.get("templates") + ".jar"); 2102 2103 if ( f.isFile() ){ 2104 String newTemplatesFolder = ((String )values.get("server_jahiafiles_default")).substring(8, ((String )values.get("server_jahiafiles_default")).length()) + File.separator + "var" + File.separator + "new_templates" + File.separator + siteKey; 2106 File newTemplate = new File (context.getRealPath(newTemplatesFolder)); 2107 newTemplate.mkdirs(); 2108 2109 f.renameTo(new File (newTemplate.getAbsolutePath()+File.separator+f.getName())); 2110 } 2111 2112 } 2113 2114 2115 2123 protected void copyDefaultTemplates(String siteKey) 2124 throws Exception 2125 { 2126 2127 logger.debug("Installing templates..."); 2128 2129 String JahiaFilesTemplatesDiskPath = 2131 context.getRealPath( properties.getProperty("jahiaTemplatesDiskPath").trim() ); 2132 2133 if ( JahiaFilesTemplatesDiskPath != null ){ 2134 2135 File defaultTemplate = new File (JahiaFilesTemplatesDiskPath + File.separator + "default"); 2136 2137 if ( defaultTemplate.isDirectory() ){ 2138 2139 try { 2140 JahiaTools.copyFolderContent(defaultTemplate.getAbsolutePath(), 2142 JahiaFilesTemplatesDiskPath + File.separator + siteKey + File.separator + "default"); 2143 2144 } catch (IOException ioe) { 2145 logger.debug("error copying default templates " + ioe.getMessage()); 2146 } 2147 } 2148 } 2149 2150 logger.debug("jahiaSettingsPathJahiaFiles is " + ((String )values.get("server_jahiafiles_default")) ); 2152 String sharedTemplatesFolder = ((String )values.get("server_jahiafiles_default")).substring(8, ((String )values.get("server_jahiafiles_default")).length()) + File.separator + "var" + File.separator + "shared_templates"; 2153 2154 boolean result = deployTemplate( JahiaFilesTemplatesDiskPath, 2155 siteKey, 2156 context.getRealPath(sharedTemplatesFolder + File.separator + (String )values.get("templates")+".jar" ), 2157 (String )values.get("templates")); 2158 2159 if (!result){ 2160 File f = new File ( context.getRealPath(sharedTemplatesFolder + File.separator + (String )values.get("templates")+".jar" ) ); 2161 logger.debug(" sharedTemplatesFolder is " + f.getAbsolutePath() ); 2162 if ( f.isFile() ){ 2163 JahiaArchiveFileHandler zip = null; 2164 try { 2165 zip = new JahiaArchiveFileHandler(f.getAbsolutePath()); 2166 File destFile = new File (JahiaFilesTemplatesDiskPath + File.separator + siteKey + File.separator + (String )values.get("templates")); 2167 destFile.mkdirs(); 2168 zip.unzip(destFile.getAbsolutePath()); 2169 } catch ( JahiaException je ){ 2170 throw new Exception ( je.getMessage() ); 2171 } catch ( IOException ioe ){ 2172 throw new Exception ( ioe.getMessage() ); 2173 } finally { 2174 zip.closeArchiveFile(); 2175 } 2176 } 2177 } 2178 } 2179 2180 2189 public boolean deployTemplate(String jahiaTemplateDiskPath, String siteKey, String filePath, String rootFolder){ 2190 2191 boolean success = true; 2192 String fullPath = null; 2193 JahiaTemplatesPackageHandler ph = null; 2194 try { 2195 2196 ph = new JahiaTemplatesPackageHandler(filePath); 2197 2198 JahiaTemplatesPackage tempPack = ph.getPackage(); 2199 2200 if ( tempPack == null ){ 2201 String errMsg =" cannot create a JahiaTemplatesPackage on file " + filePath ; 2202 logger.debug(errMsg); 2203 return false; 2204 } 2205 2206 StringBuffer strBuf = new StringBuffer (1024); 2207 strBuf.append(jahiaTemplateDiskPath); 2208 strBuf.append(File.separator); 2209 strBuf.append(siteKey); 2210 strBuf.append(File.separator); 2211 if ( tempPack.getRootFolder() != null 2212 && !tempPack.getRootFolder().trim().equals("") ){ 2213 strBuf.append(tempPack.getRootFolder()); 2214 } else { 2215 strBuf.append(rootFolder); 2216 } 2217 2218 fullPath = strBuf.toString(); 2220 2221 File f = new File (fullPath); 2223 if ( f != null && !f.isDirectory() ){ 2224 f.mkdirs(); 2226 } 2227 ph.unzip(fullPath); 2228 if ( tempPack.hasClasses () ){ 2230 String classesFilePath = fullPath + File.separator + tempPack.getClassesFile(); 2231 2232 File tmpFile = new File (classesFilePath); 2233 try{ 2234 if ( tmpFile != null && tmpFile.isFile() ){ 2235 JahiaArchiveFileHandler arch = new JahiaArchiveFileHandler(classesFilePath); 2236 arch.unzip(context.getRealPath(properties.getProperty("classDiskPath")) + File.separator + "jahiatemplates"); 2237 } 2238 } catch ( IOException ioe ){ 2239 String errMsg = "Failed creating JahiaArchiveFileHandler on classes file " ; 2240 logger.debug(errMsg + "\n" + ioe.toString()); 2241 return false; 2242 } 2243 } 2244 } catch ( Throwable t ) { 2245 String errMsg = "Failed handling templates file " ; 2246 logger.debug(errMsg, t); 2247 success = false; 2248 } finally { 2249 if ( ph != null ){ 2250 ph.closeArchiveFile(); 2251 } 2252 } 2253 return success; 2254 } 2255 2256 2264 protected void copySharedComponents(String siteKey) 2265 throws Exception 2266 { 2267 logger.debug("Installing web applications..."); 2268 2269 String sharedComponentsFolder = ((String )values.get("server_jahiafiles_default")).substring(8, ((String )values.get("server_jahiafiles_default")).length()) + File.separator + "var" + File.separator + "shared_components"; 2271 File f = new File ( context.getRealPath(sharedComponentsFolder) ); 2272 2273 String newComponentsFolder = ((String )values.get("server_jahiafiles_default")).substring(8, ((String )values.get("server_jahiafiles_default")).length()) + File.separator + "var" + File.separator + "new_webapps" + File.separator + siteKey; 2275 File newComponent = new File (context.getRealPath(newComponentsFolder)); 2276 newComponent.mkdirs(); 2277 2278 try { 2279 JahiaTools.copyFolderContent(f.getAbsolutePath(), 2281 newComponent.getAbsolutePath()); 2282 } catch ( Exception e ){ 2283 } 2285 2286 } 2287 2288 2289 2290} 2291 | Popular Tags |