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