001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.admin.action;
016    
017    import com.liferay.mail.service.MailServiceUtil;
018    import com.liferay.portal.captcha.CaptchaImpl;
019    import com.liferay.portal.captcha.recaptcha.ReCaptchaImpl;
020    import com.liferay.portal.captcha.simplecaptcha.SimpleCaptchaImpl;
021    import com.liferay.portal.convert.ConvertException;
022    import com.liferay.portal.convert.ConvertProcess;
023    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
024    import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
025    import com.liferay.portal.kernel.cache.SingleVMPoolUtil;
026    import com.liferay.portal.kernel.captcha.Captcha;
027    import com.liferay.portal.kernel.captcha.CaptchaUtil;
028    import com.liferay.portal.kernel.dao.shard.ShardUtil;
029    import com.liferay.portal.kernel.image.GhostscriptUtil;
030    import com.liferay.portal.kernel.image.ImageMagickUtil;
031    import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
032    import com.liferay.portal.kernel.io.unsync.UnsyncPrintWriter;
033    import com.liferay.portal.kernel.json.JSONFactoryUtil;
034    import com.liferay.portal.kernel.json.JSONObject;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.log.SanitizerLogWrapper;
038    import com.liferay.portal.kernel.mail.Account;
039    import com.liferay.portal.kernel.messaging.DestinationNames;
040    import com.liferay.portal.kernel.messaging.MessageBusUtil;
041    import com.liferay.portal.kernel.scripting.ScriptingException;
042    import com.liferay.portal.kernel.scripting.ScriptingHelperUtil;
043    import com.liferay.portal.kernel.scripting.ScriptingUtil;
044    import com.liferay.portal.kernel.search.Indexer;
045    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
046    import com.liferay.portal.kernel.search.SearchEngineUtil;
047    import com.liferay.portal.kernel.servlet.DirectServletRegistryUtil;
048    import com.liferay.portal.kernel.servlet.SessionErrors;
049    import com.liferay.portal.kernel.servlet.SessionMessages;
050    import com.liferay.portal.kernel.util.CharPool;
051    import com.liferay.portal.kernel.util.Constants;
052    import com.liferay.portal.kernel.util.InstancePool;
053    import com.liferay.portal.kernel.util.ParamUtil;
054    import com.liferay.portal.kernel.util.ProgressStatusConstants;
055    import com.liferay.portal.kernel.util.ProgressTracker;
056    import com.liferay.portal.kernel.util.PropsKeys;
057    import com.liferay.portal.kernel.util.StringPool;
058    import com.liferay.portal.kernel.util.StringUtil;
059    import com.liferay.portal.kernel.util.ThreadUtil;
060    import com.liferay.portal.kernel.util.Time;
061    import com.liferay.portal.kernel.util.UnsyncPrintWriterPool;
062    import com.liferay.portal.kernel.util.Validator;
063    import com.liferay.portal.kernel.xuggler.XugglerUtil;
064    import com.liferay.portal.search.SearchEngineInitializer;
065    import com.liferay.portal.security.auth.PrincipalException;
066    import com.liferay.portal.security.lang.DoPrivilegedBean;
067    import com.liferay.portal.security.membershippolicy.OrganizationMembershipPolicy;
068    import com.liferay.portal.security.membershippolicy.OrganizationMembershipPolicyFactoryUtil;
069    import com.liferay.portal.security.membershippolicy.RoleMembershipPolicy;
070    import com.liferay.portal.security.membershippolicy.RoleMembershipPolicyFactoryUtil;
071    import com.liferay.portal.security.membershippolicy.SiteMembershipPolicy;
072    import com.liferay.portal.security.membershippolicy.SiteMembershipPolicyFactoryUtil;
073    import com.liferay.portal.security.membershippolicy.UserGroupMembershipPolicy;
074    import com.liferay.portal.security.membershippolicy.UserGroupMembershipPolicyFactoryUtil;
075    import com.liferay.portal.security.permission.PermissionChecker;
076    import com.liferay.portal.service.ServiceComponentLocalServiceUtil;
077    import com.liferay.portal.struts.ActionConstants;
078    import com.liferay.portal.struts.PortletAction;
079    import com.liferay.portal.theme.ThemeDisplay;
080    import com.liferay.portal.upload.UploadServletRequestImpl;
081    import com.liferay.portal.util.MaintenanceUtil;
082    import com.liferay.portal.util.Portal;
083    import com.liferay.portal.util.PortalInstances;
084    import com.liferay.portal.util.PrefsPropsUtil;
085    import com.liferay.portal.util.ShutdownUtil;
086    import com.liferay.portal.util.WebKeys;
087    import com.liferay.portlet.ActionResponseImpl;
088    import com.liferay.portlet.admin.util.CleanUpPermissionsUtil;
089    import com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor;
090    import com.liferay.util.log4j.Log4JUtil;
091    
092    import java.io.File;
093    
094    import java.util.Enumeration;
095    import java.util.HashSet;
096    import java.util.Map;
097    import java.util.Set;
098    
099    import javax.portlet.ActionRequest;
100    import javax.portlet.ActionResponse;
101    import javax.portlet.PortletConfig;
102    import javax.portlet.PortletContext;
103    import javax.portlet.PortletPreferences;
104    import javax.portlet.PortletSession;
105    import javax.portlet.PortletURL;
106    import javax.portlet.WindowState;
107    
108    import org.apache.log4j.Level;
109    import org.apache.struts.action.ActionForm;
110    import org.apache.struts.action.ActionMapping;
111    
112    /**
113     * @author Brian Wing Shun Chan
114     * @author Shuyang Zhou
115     */
116    public class EditServerAction extends PortletAction {
117    
118            @Override
119            public void processAction(
120                            ActionMapping actionMapping, ActionForm actionForm,
121                            PortletConfig portletConfig, ActionRequest actionRequest,
122                            ActionResponse actionResponse)
123                    throws Exception {
124    
125                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
126                            WebKeys.THEME_DISPLAY);
127    
128                    PermissionChecker permissionChecker =
129                            themeDisplay.getPermissionChecker();
130    
131                    if (!permissionChecker.isOmniadmin()) {
132                            SessionErrors.add(
133                                    actionRequest, PrincipalException.class.getName());
134    
135                            setForward(actionRequest, "portlet.admin.error");
136    
137                            return;
138                    }
139    
140                    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences();
141    
142                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
143    
144                    String redirect = null;
145    
146                    if (cmd.equals("addLogLevel")) {
147                            addLogLevel(actionRequest);
148                    }
149                    else if (cmd.equals("cacheDb")) {
150                            cacheDb();
151                    }
152                    else if (cmd.equals("cacheMulti")) {
153                            cacheMulti();
154                    }
155                    else if (cmd.equals("cacheServlet")) {
156                            cacheServlet();
157                    }
158                    else if (cmd.equals("cacheSingle")) {
159                            cacheSingle();
160                    }
161                    else if (cmd.equals("cleanUpPermissions")) {
162                            CleanUpPermissionsUtil.cleanUpAddToPagePermissions(actionRequest);
163                    }
164                    else if (cmd.startsWith("convertProcess.")) {
165                            redirect = convertProcess(actionRequest, actionResponse, cmd);
166                    }
167                    else if (cmd.equals("dlPreviews")) {
168                            DLPreviewableProcessor.deleteFiles();
169                    }
170                    else if (cmd.equals("gc")) {
171                            gc();
172                    }
173                    else if (cmd.equals("installXuggler")) {
174                            installXuggler(actionRequest, actionResponse);
175    
176                            setForward(actionRequest, ActionConstants.COMMON_NULL);
177    
178                            return;
179                    }
180                    else if (cmd.equals("reindex")) {
181                            reindex(actionRequest);
182                    }
183                    else if (cmd.equals("reindexDictionaries")) {
184                            reindexDictionaries(actionRequest);
185                    }
186                    else if (cmd.equals("runScript")) {
187                            runScript(portletConfig, actionRequest, actionResponse);
188                    }
189                    else if (cmd.equals("shutdown")) {
190                            shutdown(actionRequest);
191                    }
192                    else if (cmd.equals("threadDump")) {
193                            threadDump();
194                    }
195                    else if (cmd.equals("updateCaptcha")) {
196                            updateCaptcha(actionRequest, portletPreferences);
197                    }
198                    else if (cmd.equals("updateExternalServices")) {
199                            updateExternalServices(actionRequest, portletPreferences);
200                    }
201                    else if (cmd.equals("updateFileUploads")) {
202                            updateFileUploads(actionRequest, portletPreferences);
203                    }
204                    else if (cmd.equals("updateLogLevels")) {
205                            updateLogLevels(actionRequest);
206                    }
207                    else if (cmd.equals("updateMail")) {
208                            updateMail(actionRequest, portletPreferences);
209                    }
210                    else if (cmd.equals("verifyMembershipPolicies")) {
211                            verifyMembershipPolicies();
212                    }
213                    else if (cmd.equals("verifyPluginTables")) {
214                            verifyPluginTables();
215                    }
216    
217                    sendRedirect(actionRequest, actionResponse, redirect);
218            }
219    
220            protected void addLogLevel(ActionRequest actionRequest) throws Exception {
221                    String loggerName = ParamUtil.getString(actionRequest, "loggerName");
222                    String priority = ParamUtil.getString(actionRequest, "priority");
223    
224                    Log4JUtil.setLevel(loggerName, priority, true);
225            }
226    
227            protected void cacheDb() throws Exception {
228                    CacheRegistryUtil.clear();
229            }
230    
231            protected void cacheMulti() throws Exception {
232                    MultiVMPoolUtil.clear();
233            }
234    
235            protected void cacheServlet() throws Exception {
236                    DirectServletRegistryUtil.clearServlets();
237            }
238    
239            protected void cacheSingle() throws Exception {
240                    SingleVMPoolUtil.clear();
241            }
242    
243            protected String convertProcess(
244                            ActionRequest actionRequest, ActionResponse actionResponse,
245                            String cmd)
246                    throws Exception {
247    
248                    ActionResponseImpl actionResponseImpl =
249                            (ActionResponseImpl)actionResponse;
250    
251                    PortletSession portletSession = actionRequest.getPortletSession();
252    
253                    String className = StringUtil.replaceFirst(
254                            cmd, "convertProcess.", StringPool.BLANK);
255    
256                    ConvertProcess convertProcess = (ConvertProcess)InstancePool.get(
257                            className);
258    
259                    String[] parameters = convertProcess.getParameterNames();
260    
261                    if (parameters != null) {
262                            String[] values = new String[parameters.length];
263    
264                            for (int i = 0; i < parameters.length; i++) {
265                                    String parameter =
266                                            className + StringPool.PERIOD + parameters[i];
267    
268                                    if (parameters[i].contains(StringPool.EQUAL)) {
269                                            String[] parameterPair = StringUtil.split(
270                                                    parameters[i], CharPool.EQUAL);
271    
272                                            parameter =
273                                                    className + StringPool.PERIOD + parameterPair[0];
274                                    }
275    
276                                    values[i] = ParamUtil.getString(actionRequest, parameter);
277                            }
278    
279                            convertProcess.setParameterValues(values);
280                    }
281    
282                    try {
283                            convertProcess.validate();
284                    }
285                    catch (ConvertException ce) {
286                            SessionErrors.add(actionRequest, ce.getClass(), ce);
287    
288                            return null;
289                    }
290    
291                    String path = convertProcess.getPath();
292    
293                    if (path != null) {
294                            PortletURL portletURL = actionResponseImpl.createRenderURL();
295    
296                            portletURL.setParameter("struts_action", path);
297                            portletURL.setWindowState(WindowState.MAXIMIZED);
298    
299                            return portletURL.toString();
300                    }
301    
302                    MaintenanceUtil.maintain(portletSession.getId(), className);
303    
304                    MessageBusUtil.sendMessage(DestinationNames.CONVERT_PROCESS, className);
305    
306                    return null;
307            }
308    
309            protected void gc() throws Exception {
310                    Runtime.getRuntime().gc();
311            }
312    
313            protected String getFileExtensions(
314                    ActionRequest actionRequest, String name) {
315    
316                    String value = ParamUtil.getString(actionRequest, name);
317    
318                    return value.replace(", .", ",.");
319            }
320    
321            protected void installXuggler(
322                            ActionRequest actionRequest, ActionResponse actionResponse)
323                    throws Exception {
324    
325                    ProgressTracker progressTracker = new ProgressTracker(
326                            WebKeys.XUGGLER_INSTALL_STATUS);
327    
328                    progressTracker.addProgress(
329                            ProgressStatusConstants.DOWNLOADING, 15, "downloading-xuggler");
330                    progressTracker.addProgress(
331                            ProgressStatusConstants.COPYING, 70, "copying-xuggler-files");
332    
333                    progressTracker.initialize(actionRequest);
334    
335                    String jarName = ParamUtil.getString(actionRequest, "jarName");
336    
337                    try {
338                            XugglerUtil.installNativeLibraries(jarName, progressTracker);
339    
340                            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
341    
342                            jsonObject.put("success", Boolean.TRUE);
343    
344                            writeJSON(actionRequest, actionResponse, jsonObject);
345                    }
346                    catch (Exception e) {
347                            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
348    
349                            jsonObject.put("exception", e.getMessage());
350                            jsonObject.put("success", Boolean.FALSE);
351    
352                            writeJSON(actionRequest, actionResponse, jsonObject);
353                    }
354    
355                    progressTracker.finish(actionRequest);
356            }
357    
358            protected void reindex(ActionRequest actionRequest) throws Exception {
359                    String className = ParamUtil.getString(actionRequest, "className");
360    
361                    long[] companyIds = PortalInstances.getCompanyIds();
362    
363                    Set<String> usedSearchEngineIds = new HashSet<>();
364    
365                    if (Validator.isNull(className)) {
366                            for (long companyId : companyIds) {
367                                    try {
368                                            SearchEngineInitializer searchEngineInitializer =
369                                                    new SearchEngineInitializer(companyId);
370    
371                                            searchEngineInitializer.reindex();
372    
373                                            usedSearchEngineIds.addAll(
374                                                    searchEngineInitializer.getUsedSearchEngineIds());
375                                    }
376                                    catch (Exception e) {
377                                            _log.error(e, e);
378                                    }
379                            }
380                    }
381                    else {
382                            Indexer indexer = IndexerRegistryUtil.getIndexer(className);
383    
384                            if (indexer == null) {
385                                    return;
386                            }
387    
388                            Set<String> searchEngineIds = new HashSet<>();
389    
390                            searchEngineIds.add(indexer.getSearchEngineId());
391    
392                            for (String searchEngineId : searchEngineIds) {
393                                    for (long companyId : companyIds) {
394                                            SearchEngineUtil.deleteEntityDocuments(
395                                                    searchEngineId, companyId, className, true);
396                                    }
397                            }
398    
399                            for (long companyId : companyIds) {
400                                    ShardUtil.pushCompanyService(companyId);
401    
402                                    try {
403                                            indexer.reindex(new String[] {String.valueOf(companyId)});
404    
405                                            usedSearchEngineIds.add(indexer.getSearchEngineId());
406                                    }
407                                    catch (Exception e) {
408                                            _log.error(e, e);
409                                    }
410                                    finally {
411                                            ShardUtil.popCompanyService();
412                                    }
413                            }
414                    }
415            }
416    
417            protected void reindexDictionaries(ActionRequest actionRequest)
418                    throws Exception {
419    
420                    long[] companyIds = PortalInstances.getCompanyIds();
421    
422                    for (long companyId : companyIds) {
423                            SearchEngineUtil.indexQuerySuggestionDictionaries(companyId);
424                            SearchEngineUtil.indexSpellCheckerDictionaries(companyId);
425                    }
426            }
427    
428            protected void runScript(
429                            PortletConfig portletConfig, ActionRequest actionRequest,
430                            ActionResponse actionResponse)
431                    throws Exception {
432    
433                    String language = ParamUtil.getString(actionRequest, "language");
434                    String script = ParamUtil.getString(actionRequest, "script");
435    
436                    PortletContext portletContext = portletConfig.getPortletContext();
437    
438                    Map<String, Object> portletObjects =
439                            ScriptingHelperUtil.getPortletObjects(
440                                    portletConfig, portletContext, actionRequest, actionResponse);
441    
442                    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream =
443                            new UnsyncByteArrayOutputStream();
444    
445                    UnsyncPrintWriter unsyncPrintWriter = UnsyncPrintWriterPool.borrow(
446                            unsyncByteArrayOutputStream);
447    
448                    portletObjects.put("out", unsyncPrintWriter);
449    
450                    try {
451                            SessionMessages.add(actionRequest, "language", language);
452                            SessionMessages.add(actionRequest, "script", script);
453    
454                            ScriptingUtil.exec(
455                                    null, portletObjects, language, script, StringPool.EMPTY_ARRAY);
456    
457                            unsyncPrintWriter.flush();
458    
459                            SessionMessages.add(
460                                    actionRequest, "scriptOutput",
461                                    unsyncByteArrayOutputStream.toString());
462                    }
463                    catch (ScriptingException se) {
464                            SessionErrors.add(
465                                    actionRequest, ScriptingException.class.getName(), se);
466    
467                            Log log = SanitizerLogWrapper.allowCRLF(_log);
468    
469                            log.error(se.getMessage());
470                    }
471            }
472    
473            protected void shutdown(ActionRequest actionRequest) throws Exception {
474                    if (ShutdownUtil.isInProcess()) {
475                            ShutdownUtil.cancel();
476                    }
477                    else {
478                            long minutes =
479                                    ParamUtil.getInteger(actionRequest, "minutes") * Time.MINUTE;
480    
481                            if (minutes <= 0) {
482                                    SessionErrors.add(actionRequest, "shutdownMinutes");
483                            }
484                            else {
485                                    String message = ParamUtil.getString(actionRequest, "message");
486    
487                                    ShutdownUtil.shutdown(minutes, message);
488                            }
489                    }
490            }
491    
492            protected void threadDump() throws Exception {
493                    if (_log.isInfoEnabled()) {
494                            Log log = SanitizerLogWrapper.allowCRLF(_log);
495    
496                            log.info(ThreadUtil.threadDump());
497                    }
498                    else {
499                            Class<?> clazz = getClass();
500    
501                            _log.error(
502                                    "Thread dumps require the log level to be at least INFO for " +
503                                            clazz.getName());
504                    }
505            }
506    
507            protected void updateCaptcha(
508                            ActionRequest actionRequest, PortletPreferences portletPreferences)
509                    throws Exception {
510    
511                    boolean reCaptchaEnabled = ParamUtil.getBoolean(
512                            actionRequest, "reCaptchaEnabled");
513                    String reCaptchaPrivateKey = ParamUtil.getString(
514                            actionRequest, "reCaptchaPrivateKey");
515                    String reCaptchaPublicKey = ParamUtil.getString(
516                            actionRequest, "reCaptchaPublicKey");
517    
518                    Captcha captcha = null;
519    
520                    if (reCaptchaEnabled) {
521                            captcha = new ReCaptchaImpl();
522                    }
523                    else {
524                            captcha = new SimpleCaptchaImpl();
525                    }
526    
527                    validateCaptcha(actionRequest);
528    
529                    if (SessionErrors.isEmpty(actionRequest)) {
530                            portletPreferences.setValue(
531                                    PropsKeys.CAPTCHA_ENGINE_IMPL, captcha.getClass().getName());
532                            portletPreferences.setValue(
533                                    PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PRIVATE,
534                                    reCaptchaPrivateKey);
535                            portletPreferences.setValue(
536                                    PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PUBLIC,
537                                    reCaptchaPublicKey);
538    
539                            portletPreferences.store();
540    
541                            CaptchaImpl captchaImpl = null;
542    
543                            Captcha currentCaptcha = CaptchaUtil.getCaptcha();
544    
545                            if (currentCaptcha instanceof DoPrivilegedBean) {
546                                    DoPrivilegedBean doPrivilegedBean =
547                                            (DoPrivilegedBean)currentCaptcha;
548    
549                                    captchaImpl = (CaptchaImpl)doPrivilegedBean.getActualBean();
550                            }
551                            else {
552                                    captchaImpl = (CaptchaImpl)currentCaptcha;
553                            }
554    
555                            captchaImpl.setCaptcha(captcha);
556                    }
557            }
558    
559            protected void updateExternalServices(
560                            ActionRequest actionRequest, PortletPreferences portletPreferences)
561                    throws Exception {
562    
563                    boolean imageMagickEnabled = ParamUtil.getBoolean(
564                            actionRequest, "imageMagickEnabled");
565                    String imageMagickPath = ParamUtil.getString(
566                            actionRequest, "imageMagickPath");
567                    boolean openOfficeEnabled = ParamUtil.getBoolean(
568                            actionRequest, "openOfficeEnabled");
569                    int openOfficePort = ParamUtil.getInteger(
570                            actionRequest, "openOfficePort");
571                    boolean xugglerEnabled = ParamUtil.getBoolean(
572                            actionRequest, "xugglerEnabled");
573    
574                    portletPreferences.setValue(
575                            PropsKeys.IMAGEMAGICK_ENABLED, String.valueOf(imageMagickEnabled));
576                    portletPreferences.setValue(
577                            PropsKeys.IMAGEMAGICK_GLOBAL_SEARCH_PATH, imageMagickPath);
578                    portletPreferences.setValue(
579                            PropsKeys.OPENOFFICE_SERVER_ENABLED,
580                            String.valueOf(openOfficeEnabled));
581                    portletPreferences.setValue(
582                            PropsKeys.OPENOFFICE_SERVER_PORT, String.valueOf(openOfficePort));
583                    portletPreferences.setValue(
584                            PropsKeys.XUGGLER_ENABLED, String.valueOf(xugglerEnabled));
585    
586                    Enumeration<String> enu = actionRequest.getParameterNames();
587    
588                    while (enu.hasMoreElements()) {
589                            String name = enu.nextElement();
590    
591                            if (name.startsWith("imageMagickLimit")) {
592                                    String key = StringUtil.toLowerCase(
593                                            name.substring(16, name.length()));
594                                    String value = ParamUtil.getString(actionRequest, name);
595    
596                                    portletPreferences.setValue(
597                                            PropsKeys.IMAGEMAGICK_RESOURCE_LIMIT + key, value);
598                            }
599                    }
600    
601                    portletPreferences.store();
602    
603                    GhostscriptUtil.reset();
604                    ImageMagickUtil.reset();
605            }
606    
607            protected void updateFileUploads(
608                            ActionRequest actionRequest, PortletPreferences portletPreferences)
609                    throws Exception {
610    
611                    long dlFileEntryPreviewableProcessorMaxSize = ParamUtil.getLong(
612                            actionRequest, "dlFileEntryPreviewableProcessorMaxSize");
613                    long dlFileEntryThumbnailMaxHeight = ParamUtil.getLong(
614                            actionRequest, "dlFileEntryThumbnailMaxHeight");
615                    long dlFileEntryThumbnailMaxWidth = ParamUtil.getLong(
616                            actionRequest, "dlFileEntryThumbnailMaxWidth");
617                    String dlFileExtensions = getFileExtensions(
618                            actionRequest, "dlFileExtensions");
619                    long dlFileMaxSize = ParamUtil.getLong(actionRequest, "dlFileMaxSize");
620                    String journalImageExtensions = getFileExtensions(
621                            actionRequest, "journalImageExtensions");
622                    long journalImageSmallMaxSize = ParamUtil.getLong(
623                            actionRequest, "journalImageSmallMaxSize");
624                    String shoppingImageExtensions = getFileExtensions(
625                            actionRequest, "shoppingImageExtensions");
626                    long scImageMaxSize = ParamUtil.getLong(
627                            actionRequest, "scImageMaxSize");
628                    long scImageThumbnailMaxHeight = ParamUtil.getLong(
629                            actionRequest, "scImageThumbnailMaxHeight");
630                    long scImageThumbnailMaxWidth = ParamUtil.getLong(
631                            actionRequest, "scImageThumbnailMaxWidth");
632                    long shoppingImageLargeMaxSize = ParamUtil.getLong(
633                            actionRequest, "shoppingImageLargeMaxSize");
634                    long shoppingImageMediumMaxSize = ParamUtil.getLong(
635                            actionRequest, "shoppingImageMediumMaxSize");
636                    long shoppingImageSmallMaxSize = ParamUtil.getLong(
637                            actionRequest, "shoppingImageSmallMaxSize");
638                    long uploadServletRequestImplMaxSize = ParamUtil.getLong(
639                            actionRequest, "uploadServletRequestImplMaxSize");
640                    String uploadServletRequestImplTempDir = ParamUtil.getString(
641                            actionRequest, "uploadServletRequestImplTempDir");
642                    long usersImageMaxSize = ParamUtil.getLong(
643                            actionRequest, "usersImageMaxSize");
644    
645                    portletPreferences.setValue(
646                            PropsKeys.DL_FILE_ENTRY_PREVIEWABLE_PROCESSOR_MAX_SIZE,
647                            String.valueOf(dlFileEntryPreviewableProcessorMaxSize));
648                    portletPreferences.setValue(
649                            PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_HEIGHT,
650                            String.valueOf(dlFileEntryThumbnailMaxHeight));
651                    portletPreferences.setValue(
652                            PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_WIDTH,
653                            String.valueOf(dlFileEntryThumbnailMaxWidth));
654                    portletPreferences.setValue(
655                            PropsKeys.DL_FILE_EXTENSIONS, dlFileExtensions);
656                    portletPreferences.setValue(
657                            PropsKeys.DL_FILE_MAX_SIZE, String.valueOf(dlFileMaxSize));
658                    portletPreferences.setValue(
659                            PropsKeys.JOURNAL_IMAGE_EXTENSIONS, journalImageExtensions);
660                    portletPreferences.setValue(
661                            PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE,
662                            String.valueOf(journalImageSmallMaxSize));
663                    portletPreferences.setValue(
664                            PropsKeys.SHOPPING_IMAGE_EXTENSIONS, shoppingImageExtensions);
665                    portletPreferences.setValue(
666                            PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE,
667                            String.valueOf(shoppingImageLargeMaxSize));
668                    portletPreferences.setValue(
669                            PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE,
670                            String.valueOf(shoppingImageMediumMaxSize));
671                    portletPreferences.setValue(
672                            PropsKeys.SHOPPING_IMAGE_SMALL_MAX_SIZE,
673                            String.valueOf(shoppingImageSmallMaxSize));
674                    portletPreferences.setValue(
675                            PropsKeys.SC_IMAGE_MAX_SIZE, String.valueOf(scImageMaxSize));
676                    portletPreferences.setValue(
677                            PropsKeys.SC_IMAGE_THUMBNAIL_MAX_HEIGHT,
678                            String.valueOf(scImageThumbnailMaxHeight));
679                    portletPreferences.setValue(
680                            PropsKeys.SC_IMAGE_THUMBNAIL_MAX_WIDTH,
681                            String.valueOf(scImageThumbnailMaxWidth));
682                    portletPreferences.setValue(
683                            PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE,
684                            String.valueOf(uploadServletRequestImplMaxSize));
685    
686                    if (Validator.isNotNull(uploadServletRequestImplTempDir)) {
687                            portletPreferences.setValue(
688                                    PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_TEMP_DIR,
689                                    uploadServletRequestImplTempDir);
690    
691                            UploadServletRequestImpl.setTempDir(
692                                    new File(uploadServletRequestImplTempDir));
693                    }
694    
695                    portletPreferences.setValue(
696                            PropsKeys.USERS_IMAGE_MAX_SIZE, String.valueOf(usersImageMaxSize));
697    
698                    portletPreferences.store();
699            }
700    
701            protected void updateLogLevels(ActionRequest actionRequest)
702                    throws Exception {
703    
704                    Enumeration<String> enu = actionRequest.getParameterNames();
705    
706                    while (enu.hasMoreElements()) {
707                            String name = enu.nextElement();
708    
709                            if (name.startsWith("logLevel")) {
710                                    String loggerName = name.substring(8);
711    
712                                    String priority = ParamUtil.getString(
713                                            actionRequest, name, Level.INFO.toString());
714    
715                                    Log4JUtil.setLevel(loggerName, priority, true);
716                            }
717                    }
718            }
719    
720            protected void updateMail(
721                            ActionRequest actionRequest, PortletPreferences portletPreferences)
722                    throws Exception {
723    
724                    String advancedProperties = ParamUtil.getString(
725                            actionRequest, "advancedProperties");
726                    String pop3Host = ParamUtil.getString(actionRequest, "pop3Host");
727                    String pop3Password = ParamUtil.getString(
728                            actionRequest, "pop3Password");
729                    int pop3Port = ParamUtil.getInteger(actionRequest, "pop3Port");
730                    boolean pop3Secure = ParamUtil.getBoolean(actionRequest, "pop3Secure");
731                    String pop3User = ParamUtil.getString(actionRequest, "pop3User");
732                    String smtpHost = ParamUtil.getString(actionRequest, "smtpHost");
733                    String smtpPassword = ParamUtil.getString(
734                            actionRequest, "smtpPassword");
735                    int smtpPort = ParamUtil.getInteger(actionRequest, "smtpPort");
736                    boolean smtpSecure = ParamUtil.getBoolean(actionRequest, "smtpSecure");
737                    String smtpUser = ParamUtil.getString(actionRequest, "smtpUser");
738    
739                    String storeProtocol = Account.PROTOCOL_POP;
740    
741                    if (pop3Secure) {
742                            storeProtocol = Account.PROTOCOL_POPS;
743                    }
744    
745                    String transportProtocol = Account.PROTOCOL_SMTP;
746    
747                    if (smtpSecure) {
748                            transportProtocol = Account.PROTOCOL_SMTPS;
749                    }
750    
751                    portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL, "true");
752                    portletPreferences.setValue(
753                            PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES,
754                            advancedProperties);
755                    portletPreferences.setValue(
756                            PropsKeys.MAIL_SESSION_MAIL_POP3_HOST, pop3Host);
757    
758                    if (!pop3Password.equals(Portal.TEMP_OBFUSCATION_VALUE)) {
759                            portletPreferences.setValue(
760                                    PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD, pop3Password);
761                    }
762    
763                    portletPreferences.setValue(
764                            PropsKeys.MAIL_SESSION_MAIL_POP3_PORT, String.valueOf(pop3Port));
765                    portletPreferences.setValue(
766                            PropsKeys.MAIL_SESSION_MAIL_POP3_USER, pop3User);
767                    portletPreferences.setValue(
768                            PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST, smtpHost);
769    
770                    if (!smtpPassword.equals(Portal.TEMP_OBFUSCATION_VALUE)) {
771                            portletPreferences.setValue(
772                                    PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD, smtpPassword);
773                    }
774    
775                    portletPreferences.setValue(
776                            PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT, String.valueOf(smtpPort));
777                    portletPreferences.setValue(
778                            PropsKeys.MAIL_SESSION_MAIL_SMTP_USER, smtpUser);
779                    portletPreferences.setValue(
780                            PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL, storeProtocol);
781                    portletPreferences.setValue(
782                            PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL, transportProtocol);
783    
784                    portletPreferences.store();
785    
786                    MailServiceUtil.clearSession();
787            }
788    
789            protected void validateCaptcha(ActionRequest actionRequest)
790                    throws Exception {
791    
792                    boolean reCaptchaEnabled = ParamUtil.getBoolean(
793                            actionRequest, "reCaptchaEnabled");
794    
795                    if (!reCaptchaEnabled) {
796                            return;
797                    }
798    
799                    String reCaptchaPrivateKey = ParamUtil.getString(
800                            actionRequest, "reCaptchaPrivateKey");
801                    String reCaptchaPublicKey = ParamUtil.getString(
802                            actionRequest, "reCaptchaPublicKey");
803    
804                    if (Validator.isNull(reCaptchaPublicKey)) {
805                            SessionErrors.add(actionRequest, "reCaptchaPublicKey");
806                    }
807                    else if (Validator.isNull(reCaptchaPrivateKey)) {
808                            SessionErrors.add(actionRequest, "reCaptchaPrivateKey");
809                    }
810            }
811    
812            protected void verifyMembershipPolicies() throws Exception {
813                    OrganizationMembershipPolicy organizationMembershipPolicy =
814                            OrganizationMembershipPolicyFactoryUtil.
815                                    getOrganizationMembershipPolicy();
816    
817                    organizationMembershipPolicy.verifyPolicy();
818    
819                    RoleMembershipPolicy roleMembershipPolicy =
820                            RoleMembershipPolicyFactoryUtil.getRoleMembershipPolicy();
821    
822                    roleMembershipPolicy.verifyPolicy();
823    
824                    SiteMembershipPolicy siteMembershipPolicy =
825                            SiteMembershipPolicyFactoryUtil.getSiteMembershipPolicy();
826    
827                    siteMembershipPolicy.verifyPolicy();
828    
829                    UserGroupMembershipPolicy userGroupMembershipPolicy =
830                            UserGroupMembershipPolicyFactoryUtil.getUserGroupMembershipPolicy();
831    
832                    userGroupMembershipPolicy.verifyPolicy();
833            }
834    
835            protected void verifyPluginTables() throws Exception {
836                    ServiceComponentLocalServiceUtil.verifyDB();
837            }
838    
839            private static final Log _log = LogFactoryUtil.getLog(
840                    EditServerAction.class);
841    
842    }