001    /**
002     * Copyright (c) 2000-2012 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.ConvertProcess;
022    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
023    import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
024    import com.liferay.portal.kernel.captcha.Captcha;
025    import com.liferay.portal.kernel.captcha.CaptchaUtil;
026    import com.liferay.portal.kernel.cluster.Address;
027    import com.liferay.portal.kernel.cluster.ClusterExecutorUtil;
028    import com.liferay.portal.kernel.cluster.ClusterLinkUtil;
029    import com.liferay.portal.kernel.cluster.ClusterRequest;
030    import com.liferay.portal.kernel.dao.shard.ShardUtil;
031    import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
032    import com.liferay.portal.kernel.io.unsync.UnsyncPrintWriter;
033    import com.liferay.portal.kernel.log.Log;
034    import com.liferay.portal.kernel.log.LogFactoryUtil;
035    import com.liferay.portal.kernel.mail.Account;
036    import com.liferay.portal.kernel.messaging.DestinationNames;
037    import com.liferay.portal.kernel.messaging.MessageBusUtil;
038    import com.liferay.portal.kernel.scripting.ScriptingException;
039    import com.liferay.portal.kernel.scripting.ScriptingUtil;
040    import com.liferay.portal.kernel.search.Indexer;
041    import com.liferay.portal.kernel.search.SearchEngineUtil;
042    import com.liferay.portal.kernel.servlet.SessionErrors;
043    import com.liferay.portal.kernel.servlet.SessionMessages;
044    import com.liferay.portal.kernel.util.CharPool;
045    import com.liferay.portal.kernel.util.Constants;
046    import com.liferay.portal.kernel.util.InstancePool;
047    import com.liferay.portal.kernel.util.MethodHandler;
048    import com.liferay.portal.kernel.util.MethodKey;
049    import com.liferay.portal.kernel.util.ParamUtil;
050    import com.liferay.portal.kernel.util.PropsKeys;
051    import com.liferay.portal.kernel.util.StringPool;
052    import com.liferay.portal.kernel.util.StringUtil;
053    import com.liferay.portal.kernel.util.ThreadUtil;
054    import com.liferay.portal.kernel.util.Time;
055    import com.liferay.portal.kernel.util.UnsyncPrintWriterPool;
056    import com.liferay.portal.kernel.util.Validator;
057    import com.liferay.portal.kernel.webcache.WebCachePoolUtil;
058    import com.liferay.portal.messaging.proxy.MessageValuesThreadLocal;
059    import com.liferay.portal.model.Portlet;
060    import com.liferay.portal.search.lucene.LuceneHelperUtil;
061    import com.liferay.portal.search.lucene.LuceneIndexer;
062    import com.liferay.portal.search.lucene.cluster.LuceneClusterUtil;
063    import com.liferay.portal.security.auth.PrincipalException;
064    import com.liferay.portal.security.permission.PermissionChecker;
065    import com.liferay.portal.service.PortletLocalServiceUtil;
066    import com.liferay.portal.service.ServiceComponentLocalServiceUtil;
067    import com.liferay.portal.struts.PortletAction;
068    import com.liferay.portal.theme.ThemeDisplay;
069    import com.liferay.portal.upload.UploadServletRequestImpl;
070    import com.liferay.portal.util.MaintenanceUtil;
071    import com.liferay.portal.util.PortalInstances;
072    import com.liferay.portal.util.PrefsPropsUtil;
073    import com.liferay.portal.util.ShutdownUtil;
074    import com.liferay.portal.util.WebKeys;
075    import com.liferay.portlet.ActionResponseImpl;
076    import com.liferay.portlet.admin.util.CleanUpPermissionsUtil;
077    import com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor;
078    import com.liferay.portlet.documentlibrary.util.PDFProcessorUtil;
079    import com.liferay.util.log4j.Log4JUtil;
080    
081    import java.io.File;
082    
083    import java.util.Enumeration;
084    import java.util.List;
085    import java.util.Map;
086    
087    import javax.portlet.ActionRequest;
088    import javax.portlet.ActionResponse;
089    import javax.portlet.PortletConfig;
090    import javax.portlet.PortletContext;
091    import javax.portlet.PortletPreferences;
092    import javax.portlet.PortletSession;
093    import javax.portlet.PortletURL;
094    import javax.portlet.WindowState;
095    
096    import org.apache.log4j.Level;
097    import org.apache.struts.action.ActionForm;
098    import org.apache.struts.action.ActionMapping;
099    
100    /**
101     * @author Brian Wing Shun Chan
102     */
103    public class EditServerAction extends PortletAction {
104    
105            @Override
106            public void processAction(
107                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
108                            ActionRequest actionRequest, ActionResponse actionResponse)
109                    throws Exception {
110    
111                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
112                            WebKeys.THEME_DISPLAY);
113    
114                    PermissionChecker permissionChecker =
115                            themeDisplay.getPermissionChecker();
116    
117                    if (!permissionChecker.isOmniadmin()) {
118                            SessionErrors.add(
119                                    actionRequest, PrincipalException.class.getName());
120    
121                            setForward(actionRequest, "portlet.admin.error");
122    
123                            return;
124                    }
125    
126                    PortletPreferences preferences = PrefsPropsUtil.getPreferences();
127    
128                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
129    
130                    String redirect = null;
131    
132                    if (cmd.equals("addLogLevel")) {
133                            addLogLevel(actionRequest);
134                    }
135                    else if (cmd.equals("cacheDb")) {
136                            cacheDb();
137                    }
138                    else if (cmd.equals("cacheMulti")) {
139                            cacheMulti();
140                    }
141                    else if (cmd.equals("cacheSingle")) {
142                            cacheSingle();
143                    }
144                    else if (cmd.equals("cleanUpPermissions")) {
145                            CleanUpPermissionsUtil.cleanUpAddToPagePermissions(actionRequest);
146                    }
147                    else if (cmd.startsWith("convertProcess.")) {
148                            redirect = convertProcess(actionRequest, actionResponse, cmd);
149                    }
150                    else if (cmd.equals("dlPreviews")) {
151                            DLPreviewableProcessor.deleteFiles();
152                    }
153                    else if (cmd.equals("gc")) {
154                            gc();
155                    }
156                    else if (cmd.equals("reindex")) {
157                            reindex(actionRequest);
158                    }
159                    else if (cmd.equals("runScript")) {
160                            runScript(portletConfig, actionRequest, actionResponse);
161                    }
162                    else if (cmd.equals("shutdown")) {
163                            shutdown(actionRequest);
164                    }
165                    else if (cmd.equals("threadDump")) {
166                            threadDump();
167                    }
168                    else if (cmd.equals("updateCaptcha")) {
169                            updateCaptcha(actionRequest, preferences);
170                    }
171                    else if (cmd.equals("updateExternalServices")) {
172                            updateExternalServices(actionRequest, preferences);
173                    }
174                    else if (cmd.equals("updateFileUploads")) {
175                            updateFileUploads(actionRequest, preferences);
176                    }
177                    else if (cmd.equals("updateLogLevels")) {
178                            updateLogLevels(actionRequest);
179                    }
180                    else if (cmd.equals("updateMail")) {
181                            updateMail(actionRequest, preferences);
182                    }
183                    else if (cmd.equals("verifyPluginTables")) {
184                            verifyPluginTables();
185                    }
186    
187                    sendRedirect(actionRequest, actionResponse, redirect);
188            }
189    
190            protected void addLogLevel(ActionRequest actionRequest) throws Exception {
191                    String loggerName = ParamUtil.getString(actionRequest, "loggerName");
192                    String priority = ParamUtil.getString(actionRequest, "priority");
193    
194                    Log4JUtil.setLevel(loggerName, priority, true);
195            }
196    
197            protected void cacheDb() throws Exception {
198                    CacheRegistryUtil.clear();
199            }
200    
201            protected void cacheMulti() throws Exception {
202                    MultiVMPoolUtil.clear();
203            }
204    
205            protected void cacheSingle() throws Exception {
206                    WebCachePoolUtil.clear();
207            }
208    
209            protected String convertProcess(
210                            ActionRequest actionRequest, ActionResponse actionResponse,
211                            String cmd)
212                    throws Exception {
213    
214                    ActionResponseImpl actionResponseImpl =
215                            (ActionResponseImpl)actionResponse;
216    
217                    PortletSession portletSession = actionRequest.getPortletSession();
218    
219                    String className = StringUtil.replaceFirst(
220                            cmd, "convertProcess.", StringPool.BLANK);
221    
222                    ConvertProcess convertProcess = (ConvertProcess)InstancePool.get(
223                            className);
224    
225                    String[] parameters = convertProcess.getParameterNames();
226    
227                    if (parameters != null) {
228                            String[] values = new String[parameters.length];
229    
230                            for (int i = 0; i < parameters.length; i++) {
231                                    String parameter =
232                                            className + StringPool.PERIOD + parameters[i];
233    
234                                    if (parameters[i].contains(StringPool.EQUAL)) {
235                                            String[] parameterPair = StringUtil.split(
236                                                    parameters[i], CharPool.EQUAL);
237    
238                                            parameter =
239                                                    className + StringPool.PERIOD + parameterPair[0];
240                                    }
241    
242                                    values[i] = ParamUtil.getString(actionRequest, parameter);
243                            }
244    
245                            convertProcess.setParameterValues(values);
246                    }
247    
248                    String path = convertProcess.getPath();
249    
250                    if (path != null) {
251                            PortletURL portletURL = actionResponseImpl.createRenderURL();
252    
253                            portletURL.setWindowState(WindowState.MAXIMIZED);
254    
255                            portletURL.setParameter("struts_action", path);
256    
257                            return portletURL.toString();
258                    }
259                    else {
260                            MaintenanceUtil.maintain(portletSession.getId(), className);
261    
262                            MessageBusUtil.sendMessage(
263                                    DestinationNames.CONVERT_PROCESS, className);
264    
265                            return null;
266                    }
267            }
268    
269            protected void gc() throws Exception {
270                    Runtime.getRuntime().gc();
271            }
272    
273            protected String getFileExtensions(
274                    ActionRequest actionRequest, String name) {
275    
276                    String value = ParamUtil.getString(actionRequest, name);
277    
278                    return value.replace(", .", ",.");
279            }
280    
281            protected void reindex(ActionRequest actionRequest) throws Exception {
282                    String portletId = ParamUtil.getString(actionRequest, "portletId");
283    
284                    long[] companyIds = PortalInstances.getCompanyIds();
285    
286                    if (LuceneHelperUtil.isLoadIndexFromClusterEnabled()) {
287                            MessageValuesThreadLocal.setValue(
288                                    ClusterLinkUtil.CLUSTER_FORWARD_MESSAGE, true);
289                    }
290    
291                    if (Validator.isNull(portletId)) {
292                            for (long companyId : companyIds) {
293                                    try {
294                                            LuceneIndexer indexer = new LuceneIndexer(companyId);
295    
296                                            indexer.reindex();
297                                    }
298                                    catch (Exception e) {
299                                            _log.error(e, e);
300                                    }
301                            }
302                    }
303                    else {
304                            Portlet portlet = PortletLocalServiceUtil.getPortletById(
305                                    companyIds[0], portletId);
306    
307                            if (portlet == null) {
308                                    return;
309                            }
310    
311                            List<Indexer> indexers = portlet.getIndexerInstances();
312    
313                            if (indexers == null) {
314                                    return;
315                            }
316    
317                            for (Indexer indexer : indexers) {
318                                    for (long companyId : companyIds) {
319                                            ShardUtil.pushCompanyService(companyId);
320    
321                                            try {
322                                                    SearchEngineUtil.deletePortletDocuments(
323                                                            companyId, portletId);
324    
325                                                    indexer.reindex(
326                                                            new String[] {String.valueOf(companyId)});
327                                            }
328                                            catch (Exception e) {
329                                                    _log.error(e, e);
330                                            }
331    
332                                            ShardUtil.popCompanyService();
333                                    }
334                            }
335                    }
336    
337                    if (LuceneHelperUtil.isLoadIndexFromClusterEnabled()) {
338                            Address localClusterNodeAddress =
339                                    ClusterExecutorUtil.getLocalClusterNodeAddress();
340    
341                            ClusterRequest clusterRequest =
342                                    ClusterRequest.createMulticastRequest(
343                                            new MethodHandler(
344                                                    _loadIndexesFromClusterMethodKey, companyIds,
345                                                    localClusterNodeAddress),
346                                            true);
347    
348                            ClusterExecutorUtil.execute(clusterRequest);
349    
350                            return;
351                    }
352            }
353    
354            protected void runScript(
355                            PortletConfig portletConfig, ActionRequest actionRequest,
356                            ActionResponse actionResponse)
357                    throws Exception {
358    
359                    String language = ParamUtil.getString(actionRequest, "language");
360                    String script = ParamUtil.getString(actionRequest, "script");
361    
362                    PortletContext portletContext = portletConfig.getPortletContext();
363    
364                    Map<String, Object> portletObjects = ScriptingUtil.getPortletObjects(
365                            portletConfig, portletContext, actionRequest, actionResponse);
366    
367                    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream =
368                            new UnsyncByteArrayOutputStream();
369    
370                    UnsyncPrintWriter unsyncPrintWriter = UnsyncPrintWriterPool.borrow(
371                            unsyncByteArrayOutputStream);
372    
373                    portletObjects.put("out", unsyncPrintWriter);
374    
375                    try {
376                            SessionMessages.add(actionRequest, "language", language);
377                            SessionMessages.add(actionRequest, "script", script);
378    
379                            ScriptingUtil.exec(null, portletObjects, language, script);
380    
381                            unsyncPrintWriter.flush();
382    
383                            SessionMessages.add(
384                                    actionRequest, "script_output",
385                                    unsyncByteArrayOutputStream.toString());
386                    }
387                    catch (ScriptingException se) {
388                            SessionErrors.add(
389                                    actionRequest, ScriptingException.class.getName(), se);
390    
391                            _log.error(se.getMessage());
392                    }
393            }
394    
395            protected void shutdown(ActionRequest actionRequest) throws Exception {
396                    long minutes =
397                            ParamUtil.getInteger(actionRequest, "minutes") * Time.MINUTE;
398                    String message = ParamUtil.getString(actionRequest, "message");
399    
400                    if (minutes <= 0) {
401                            ShutdownUtil.cancel();
402                    }
403                    else {
404                            ShutdownUtil.shutdown(minutes, message);
405                    }
406            }
407    
408            protected void threadDump() throws Exception {
409                    if (_log.isInfoEnabled()) {
410                            _log.info(ThreadUtil.threadDump());
411                    }
412                    else {
413                            _log.error(
414                                    "Thread dumps require the log level to be at least INFO for " +
415                                            getClass().getName());
416                    }
417            }
418    
419            protected void updateCaptcha(
420                            ActionRequest actionRequest, PortletPreferences preferences)
421                    throws Exception {
422    
423                    boolean reCaptchaEnabled = ParamUtil.getBoolean(
424                            actionRequest, "reCaptchaEnabled");
425                    String reCaptchaPrivateKey = ParamUtil.getString(
426                            actionRequest, "reCaptchaPrivateKey");
427                    String reCaptchaPublicKey = ParamUtil.getString(
428                            actionRequest, "reCaptchaPublicKey");
429    
430                    Captcha captcha = null;
431    
432                    if (reCaptchaEnabled) {
433                            captcha = new ReCaptchaImpl();
434                    }
435                    else {
436                            captcha = new SimpleCaptchaImpl();
437                    }
438    
439                    validateCaptcha(actionRequest);
440    
441                    if (SessionErrors.isEmpty(actionRequest)) {
442                            preferences.setValue(
443                                    PropsKeys.CAPTCHA_ENGINE_IMPL, captcha.getClass().getName());
444                            preferences.setValue(
445                                    PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PRIVATE,
446                                    reCaptchaPrivateKey);
447                            preferences.setValue(
448                                    PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PUBLIC,
449                                    reCaptchaPublicKey);
450    
451                            preferences.store();
452    
453                            CaptchaImpl captchaImpl = (CaptchaImpl)CaptchaUtil.getCaptcha();
454    
455                            captchaImpl.setCaptcha(captcha);
456                    }
457            }
458    
459            protected void updateExternalServices(
460                            ActionRequest actionRequest, PortletPreferences preferences)
461                    throws Exception {
462    
463                    boolean imageMagickEnabled = ParamUtil.getBoolean(
464                            actionRequest, "imageMagickEnabled");
465                    String imageMagickPath = ParamUtil.getString(
466                            actionRequest, "imageMagickPath");
467                    boolean openOfficeEnabled = ParamUtil.getBoolean(
468                            actionRequest, "openOfficeEnabled");
469                    int openOfficePort = ParamUtil.getInteger(
470                            actionRequest, "openOfficePort");
471                    boolean xugglerEnabled = ParamUtil.getBoolean(
472                            actionRequest, "xugglerEnabled");
473    
474                    preferences.setValue(
475                            PropsKeys.IMAGEMAGICK_ENABLED, String.valueOf(imageMagickEnabled));
476                    preferences.setValue(
477                            PropsKeys.IMAGEMAGICK_GLOBAL_SEARCH_PATH, imageMagickPath);
478                    preferences.setValue(
479                            PropsKeys.OPENOFFICE_SERVER_ENABLED,
480                            String.valueOf(openOfficeEnabled));
481                    preferences.setValue(
482                            PropsKeys.OPENOFFICE_SERVER_PORT, String.valueOf(openOfficePort));
483                    preferences.setValue(
484                            PropsKeys.XUGGLER_ENABLED, String.valueOf(xugglerEnabled));
485    
486                    preferences.store();
487    
488                    PDFProcessorUtil.reset();
489            }
490    
491            protected void updateFileUploads(
492                            ActionRequest actionRequest, PortletPreferences preferences)
493                    throws Exception {
494    
495                    long dlFileEntryThumbnailMaxHeight = ParamUtil.getLong(
496                            actionRequest, "dlFileEntryThumbnailMaxHeight");
497                    long dlFileEntryThumbnailMaxWidth = ParamUtil.getLong(
498                            actionRequest, "dlFileEntryThumbnailMaxWidth");
499                    String dlFileExtensions = getFileExtensions(
500                            actionRequest, "dlFileExtensions");
501                    long dlFileMaxSize = ParamUtil.getLong(actionRequest, "dlFileMaxSize");
502                    String journalImageExtensions = getFileExtensions(
503                            actionRequest, "journalImageExtensions");
504                    long journalImageSmallMaxSize = ParamUtil.getLong(
505                            actionRequest, "journalImageSmallMaxSize");
506                    String shoppingImageExtensions = getFileExtensions(
507                            actionRequest, "shoppingImageExtensions");
508                    long scImageMaxSize = ParamUtil.getLong(
509                            actionRequest, "scImageMaxSize");
510                    long scImageThumbnailMaxHeight = ParamUtil.getLong(
511                            actionRequest, "scImageThumbnailMaxHeight");
512                    long scImageThumbnailMaxWidth = ParamUtil.getLong(
513                            actionRequest, "scImageThumbnailMaxWidth");
514                    long shoppingImageLargeMaxSize = ParamUtil.getLong(
515                            actionRequest, "shoppingImageLargeMaxSize");
516                    long shoppingImageMediumMaxSize = ParamUtil.getLong(
517                            actionRequest, "shoppingImageMediumMaxSize");
518                    long shoppingImageSmallMaxSize = ParamUtil.getLong(
519                            actionRequest, "shoppingImageSmallMaxSize");
520                    long uploadServletRequestImplMaxSize = ParamUtil.getLong(
521                            actionRequest, "uploadServletRequestImplMaxSize");
522                    String uploadServletRequestImplTempDir = ParamUtil.getString(
523                            actionRequest, "uploadServletRequestImplTempDir");
524                    long usersImageMaxSize = ParamUtil.getLong(
525                            actionRequest, "usersImageMaxSize");
526    
527                    preferences.setValue(
528                            PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_HEIGHT,
529                            String.valueOf(dlFileEntryThumbnailMaxHeight));
530                    preferences.setValue(
531                            PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_WIDTH,
532                            String.valueOf(dlFileEntryThumbnailMaxWidth));
533                    preferences.setValue(PropsKeys.DL_FILE_EXTENSIONS, dlFileExtensions);
534                    preferences.setValue(
535                            PropsKeys.DL_FILE_MAX_SIZE, String.valueOf(dlFileMaxSize));
536                    preferences.setValue(
537                            PropsKeys.JOURNAL_IMAGE_EXTENSIONS, journalImageExtensions);
538                    preferences.setValue(
539                            PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE,
540                            String.valueOf(journalImageSmallMaxSize));
541                    preferences.setValue(
542                            PropsKeys.SHOPPING_IMAGE_EXTENSIONS, shoppingImageExtensions);
543                    preferences.setValue(
544                            PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE,
545                            String.valueOf(shoppingImageLargeMaxSize));
546                    preferences.setValue(
547                            PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE,
548                            String.valueOf(shoppingImageMediumMaxSize));
549                    preferences.setValue(
550                            PropsKeys.SHOPPING_IMAGE_SMALL_MAX_SIZE,
551                            String.valueOf(shoppingImageSmallMaxSize));
552                    preferences.setValue(
553                            PropsKeys.SC_IMAGE_MAX_SIZE, String.valueOf(scImageMaxSize));
554                    preferences.setValue(
555                            PropsKeys.SC_IMAGE_THUMBNAIL_MAX_HEIGHT,
556                            String.valueOf(scImageThumbnailMaxHeight));
557                    preferences.setValue(
558                            PropsKeys.SC_IMAGE_THUMBNAIL_MAX_WIDTH,
559                            String.valueOf(scImageThumbnailMaxWidth));
560                    preferences.setValue(
561                            PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE,
562                            String.valueOf(uploadServletRequestImplMaxSize));
563    
564                    if (Validator.isNotNull(uploadServletRequestImplTempDir)) {
565                            preferences.setValue(
566                                    PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_TEMP_DIR,
567                                    uploadServletRequestImplTempDir);
568    
569                            UploadServletRequestImpl.setTempDir(
570                                    new File(uploadServletRequestImplTempDir));
571                    }
572    
573                    preferences.setValue(
574                            PropsKeys.USERS_IMAGE_MAX_SIZE, String.valueOf(usersImageMaxSize));
575    
576                    preferences.store();
577            }
578    
579            protected void updateLogLevels(ActionRequest actionRequest)
580                    throws Exception {
581    
582                    Enumeration<String> enu = actionRequest.getParameterNames();
583    
584                    while (enu.hasMoreElements()) {
585                            String name = enu.nextElement();
586    
587                            if (name.startsWith("logLevel")) {
588                                    String loggerName = name.substring(8, name.length());
589    
590                                    String priority = ParamUtil.getString(
591                                            actionRequest, name, Level.INFO.toString());
592    
593                                    Log4JUtil.setLevel(loggerName, priority, true);
594                            }
595                    }
596            }
597    
598            protected void updateMail(
599                            ActionRequest actionRequest, PortletPreferences preferences)
600                    throws Exception {
601    
602                    String advancedProperties = ParamUtil.getString(
603                            actionRequest, "advancedProperties");
604                    String pop3Host = ParamUtil.getString(actionRequest, "pop3Host");
605                    String pop3Password = ParamUtil.getString(
606                            actionRequest, "pop3Password");
607                    int pop3Port = ParamUtil.getInteger(actionRequest, "pop3Port");
608                    boolean pop3Secure = ParamUtil.getBoolean(actionRequest, "pop3Secure");
609                    String pop3User = ParamUtil.getString(actionRequest, "pop3User");
610                    String smtpHost = ParamUtil.getString(actionRequest, "smtpHost");
611                    String smtpPassword = ParamUtil.getString(
612                            actionRequest, "smtpPassword");
613                    int smtpPort = ParamUtil.getInteger(actionRequest, "smtpPort");
614                    boolean smtpSecure = ParamUtil.getBoolean(actionRequest, "smtpSecure");
615                    String smtpUser = ParamUtil.getString(actionRequest, "smtpUser");
616    
617                    String storeProtocol = Account.PROTOCOL_POP;
618    
619                    if (pop3Secure) {
620                            storeProtocol = Account.PROTOCOL_POPS;
621                    }
622    
623                    String transportProtocol = Account.PROTOCOL_SMTP;
624    
625                    if (smtpSecure) {
626                            transportProtocol = Account.PROTOCOL_SMTPS;
627                    }
628    
629                    preferences.setValue(PropsKeys.MAIL_SESSION_MAIL, "true");
630                    preferences.setValue(
631                            PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES,
632                            advancedProperties);
633                    preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_HOST, pop3Host);
634                    preferences.setValue(
635                            PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD, pop3Password);
636                    preferences.setValue(
637                            PropsKeys.MAIL_SESSION_MAIL_POP3_PORT, String.valueOf(pop3Port));
638                    preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_USER, pop3User);
639                    preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST, smtpHost);
640                    preferences.setValue(
641                            PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD, smtpPassword);
642                    preferences.setValue(
643                            PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT, String.valueOf(smtpPort));
644                    preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER, smtpUser);
645                    preferences.setValue(
646                            PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL, storeProtocol);
647                    preferences.setValue(
648                            PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL, transportProtocol);
649    
650                    preferences.store();
651    
652                    MailServiceUtil.clearSession();
653            }
654    
655            protected void validateCaptcha(ActionRequest actionRequest)
656                    throws Exception {
657    
658                    boolean reCaptchaEnabled = ParamUtil.getBoolean(
659                            actionRequest, "reCaptchaEnabled");
660    
661                    if (!reCaptchaEnabled) {
662                            return;
663                    }
664    
665                    String reCaptchaPrivateKey = ParamUtil.getString(
666                            actionRequest, "reCaptchaPrivateKey");
667                    String reCaptchaPublicKey = ParamUtil.getString(
668                            actionRequest, "reCaptchaPublicKey");
669    
670                    if (Validator.isNull(reCaptchaPublicKey)) {
671                            SessionErrors.add(actionRequest, "reCaptchaPublicKey");
672                    }
673                    else if (Validator.isNull(reCaptchaPrivateKey)) {
674                            SessionErrors.add(actionRequest, "reCaptchaPrivateKey");
675                    }
676            }
677    
678            protected void verifyPluginTables() throws Exception {
679                    ServiceComponentLocalServiceUtil.verifyDB();
680            }
681    
682            private static Log _log = LogFactoryUtil.getLog(EditServerAction.class);
683    
684            private static MethodKey _loadIndexesFromClusterMethodKey = new MethodKey(
685                    LuceneClusterUtil.class.getName(), "loadIndexesFromCluster",
686                    long[].class, Address.class);
687    
688    }