001    package railo.runtime.tag;
002    
003    import java.io.IOException;
004    import java.net.MalformedURLException;
005    import java.net.URL;
006    import java.security.cert.X509Certificate;
007    import java.sql.Connection;
008    import java.sql.Driver;
009    import java.sql.SQLException;
010    import java.util.ArrayList;
011    import java.util.Arrays;
012    import java.util.Iterator;
013    import java.util.List;
014    import java.util.Locale;
015    import java.util.Map;
016    import java.util.Map.Entry;
017    import java.util.TimeZone;
018    
019    import javax.servlet.jsp.tagext.Tag;
020    
021    import org.opencfml.eventgateway.Gateway;
022    
023    import railo.commons.collections.HashTable;
024    import railo.commons.db.DBUtil;
025    import railo.commons.io.CompressUtil;
026    import railo.commons.io.SystemUtil;
027    import railo.commons.io.cache.Cache;
028    import railo.commons.io.log.Log;
029    import railo.commons.io.log.LogAndSource;
030    import railo.commons.io.log.LogResource;
031    import railo.commons.io.log.LogUtil;
032    import railo.commons.io.res.Resource;
033    import railo.commons.io.res.ResourcesImpl;
034    import railo.commons.io.res.filter.DirectoryResourceFilter;
035    import railo.commons.io.res.filter.ExtensionResourceFilter;
036    import railo.commons.io.res.filter.OrResourceFilter;
037    import railo.commons.io.res.filter.ResourceFilter;
038    import railo.commons.io.res.util.ResourceUtil;
039    import railo.commons.lang.ClassException;
040    import railo.commons.lang.ClassUtil;
041    import railo.commons.lang.StringUtil;
042    import railo.commons.net.JarLoader;
043    import railo.runtime.CFMLFactoryImpl;
044    import railo.runtime.Mapping;
045    import railo.runtime.PageContextImpl;
046    import railo.runtime.PageSource;
047    import railo.runtime.PageSourceImpl;
048    import railo.runtime.cache.CacheConnection;
049    import railo.runtime.cfx.customtag.CFXTagClass;
050    import railo.runtime.cfx.customtag.CPPCFXTagClass;
051    import railo.runtime.cfx.customtag.JavaCFXTagClass;
052    import railo.runtime.config.AdminSync;
053    import railo.runtime.config.Config;
054    import railo.runtime.config.ConfigImpl;
055    import railo.runtime.config.ConfigServer;
056    import railo.runtime.config.ConfigServerImpl;
057    import railo.runtime.config.ConfigWeb;
058    import railo.runtime.config.ConfigWebAdmin;
059    import railo.runtime.config.ConfigWebImpl;
060    import railo.runtime.config.ConfigWebUtil;
061    import railo.runtime.config.RemoteClient;
062    import railo.runtime.config.RemoteClientImpl;
063    import railo.runtime.db.DataSource;
064    import railo.runtime.db.DataSourceImpl;
065    import railo.runtime.db.DataSourceManager;
066    import railo.runtime.dump.DumpData;
067    import railo.runtime.dump.DumpUtil;
068    import railo.runtime.dump.DumpWriter;
069    import railo.runtime.engine.ThreadLocalPageContext;
070    import railo.runtime.exp.ApplicationException;
071    import railo.runtime.exp.DatabaseException;
072    import railo.runtime.exp.PageException;
073    import railo.runtime.exp.PageExceptionImpl;
074    import railo.runtime.exp.SecurityException;
075    import railo.runtime.ext.tag.DynamicAttributes;
076    import railo.runtime.ext.tag.TagImpl;
077    import railo.runtime.extension.Extension;
078    import railo.runtime.extension.ExtensionImpl;
079    import railo.runtime.extension.ExtensionProvider;
080    import railo.runtime.functions.cache.Util;
081    import railo.runtime.functions.system.ContractPath;
082    import railo.runtime.gateway.GatewayEngineImpl;
083    import railo.runtime.gateway.GatewayEntry;
084    import railo.runtime.gateway.GatewayEntryImpl;
085    import railo.runtime.i18n.LocaleFactory;
086    import railo.runtime.listener.AppListenerUtil;
087    import railo.runtime.listener.ApplicationListener;
088    import railo.runtime.monitor.IntervallMonitor;
089    import railo.runtime.monitor.Monitor;
090    import railo.runtime.monitor.RequestMonitor;
091    import railo.runtime.net.http.CertificateInstaller;
092    import railo.runtime.net.mail.SMTPException;
093    import railo.runtime.net.mail.SMTPVerifier;
094    import railo.runtime.net.mail.Server;
095    import railo.runtime.net.mail.ServerImpl;
096    import railo.runtime.net.proxy.ProxyData;
097    import railo.runtime.net.proxy.ProxyDataImpl;
098    import railo.runtime.op.Caster;
099    import railo.runtime.op.Decision;
100    import railo.runtime.op.date.DateCaster;
101    import railo.runtime.orm.ORMConfiguration;
102    import railo.runtime.reflection.Reflector;
103    import railo.runtime.security.SecurityManager;
104    import railo.runtime.security.SecurityManagerImpl;
105    import railo.runtime.spooler.ExecutionPlan;
106    import railo.runtime.spooler.SpoolerEngineImpl;
107    import railo.runtime.spooler.SpoolerTask;
108    import railo.runtime.spooler.remote.RemoteClientTask;
109    import railo.runtime.type.Array;
110    import railo.runtime.type.ArrayImpl;
111    import railo.runtime.type.Collection;
112    import railo.runtime.type.Collection.Key;
113    import railo.runtime.type.KeyImpl;
114    import railo.runtime.type.Query;
115    import railo.runtime.type.QueryImpl;
116    import railo.runtime.type.Struct;
117    import railo.runtime.type.StructImpl;
118    import railo.runtime.type.dt.DateTime;
119    import railo.runtime.type.dt.DateTimeImpl;
120    import railo.runtime.type.dt.TimeSpan;
121    import railo.runtime.type.scope.Cluster;
122    import railo.runtime.type.scope.ClusterEntryImpl;
123    import railo.runtime.type.scope.Undefined;
124    import railo.runtime.type.util.ComponentUtil;
125    import railo.transformer.library.function.FunctionLib;
126    import railo.transformer.library.tag.TagLib;
127    
128    /**
129     * 
130     */
131    public final class Admin extends TagImpl implements DynamicAttributes {
132        
133        private static final short TYPE_WEB=0;
134        private static final short TYPE_SERVER=1;
135    
136        private static final short ACCESS_FREE=0;
137        private static final short ACCESS_NOT_WHEN_WEB=1;
138        private static final short ACCESS_NOT_WHEN_SERVER=2;
139        private static final short ACCESS_NEVER=3;
140    
141        private static final short ACCESS_READ=10;
142        private static final short ACCESS_WRITE=11;
143        private static final short CHECK_PW=12;
144    
145            //private static final String USAGE_SYNC = "synchronisation";
146            //private static final String USAGE_CLUSTER = "cluster";
147            public static final String[] ORM_JARS = new String[]{"antlr.jar","dom4j.jar","hibernate.jar","javassist.jar","jta.jar","slf4j-api.jar","railo-sl4j.jar"};
148            public static final String[] CACHE_JARS = new String[]{"ehcache.jar"};
149            public static final String[] CFX_JARS = new String[]{"com.naryx.tagfusion.cfx.jar"};
150            public static final String[] UPDATE_JARS = new String[]{"ehcache.jar","antlr.jar","dom4j.jar","hibernate.jar","javassist.jar","jta.jar","slf4j-api.jar","railo-sl4j.jar","metadata-extractor.jar","icepdf-core.jar","com.naryx.tagfusion.cfx.jar","railo-inst.jar"};
151            
152            private static final Collection.Key DEBUG = KeyImpl.intern("debug");
153            private static final Collection.Key DEBUG_SRC = KeyImpl.intern("debugSrc");
154            private static final Collection.Key DEBUG_TEMPLATE = KeyImpl.intern("debugTemplate");
155            private static final Collection.Key DEBUG_SHOW_QUERY_USAGE = KeyImpl.intern("debugShowQueryUsage");
156            private static final Collection.Key STR_DEBUG_TEMPLATE = KeyImpl.intern("strdebugTemplate");
157            private static final Collection.Key TEMPLATES = KeyImpl.intern("templates");
158            private static final Collection.Key STR = KeyImpl.intern("str");
159            private static final Collection.Key DO_STATUS_CODE = KeyImpl.intern("doStatusCode");
160            private static final Collection.Key LABEL = KeyImpl.intern("label");
161            private static final Collection.Key HASH = KeyImpl.intern("hash");
162            private static final Collection.Key ROOT = KeyImpl.intern("root");
163            private static final Collection.Key CONFIG = KeyImpl.intern("config");
164            private static final Collection.Key FILE_ACCESS = KeyImpl.intern("file_access");
165            private static final Collection.Key LOG_ENABLED = KeyImpl.intern("logEnabled");
166            private static final Collection.Key CLASS = KeyImpl.intern("class");
167            
168            
169            
170            
171            /*
172            others:
173            PDFRenderer.jar
174            ?
175            xmlparserv2.jar
176            
177            not needed:
178            slf4j-simple.jar
179            xdb.jar
180            
181            
182            
183            */
184            
185            
186            
187        private Struct attributes=new StructImpl();
188        private String action=null;
189        private short type;
190        private String password;
191        private ConfigWebAdmin admin;
192        private ConfigImpl config;
193        
194        private ResourceFilter filter=
195            new OrResourceFilter(new ResourceFilter[]{
196                    new DirectoryResourceFilter(),
197                    new ExtensionResourceFilter("cfm"),
198                    new ExtensionResourceFilter("cfc"),
199                    new ExtensionResourceFilter("cfml")
200            });
201            private AdminSync adminSync;
202            
203        
204        
205        /**
206         * @see javax.servlet.jsp.tagext.Tag#release()
207         */
208        public void release() {
209            super.release();
210            attributes.clear();
211        }
212        
213        /**
214         * @see railo.runtime.ext.tag.DynamicAttributes#setDynamicAttribute(java.lang.String, java.lang.String, java.lang.Object)
215         */
216        public void setDynamicAttribute(String uri, String localName, Object value) {
217            attributes.setEL(KeyImpl.getInstance(localName),value);
218        }
219        
220        /**
221         * @see javax.servlet.jsp.tagext.Tag#doStartTag()
222         */
223        public int doStartTag() throws PageException {
224            //adminSync = pageContext.getAdminSync();
225            
226            // Action
227            Object objAction=attributes.get(KeyImpl.ACTION);
228            if(objAction==null)throw new ApplicationException("missing attrbute action for tag admin");
229            action=StringUtil.toLowerCase(Caster.toString(objAction)).trim();
230            
231            // Generals
232            if(action.equals("getlocales")) {
233                doGetLocales();
234                return SKIP_BODY;
235            }
236            if(action.equals("gettimezones")) {
237                doGetTimeZones();
238                return SKIP_BODY;
239            }
240            if(action.equals("printdebug")) {
241                doPrintDebug();
242                return SKIP_BODY;
243            }
244            if(action.equals("getdebugdata")) {
245                doGetDebugData();
246                return SKIP_BODY;
247            }
248            if(action.equals("getinfo")) {
249                doGetInfo();
250                return SKIP_BODY;
251            }
252            if(action.equals("getloginsettings")) {
253                    doGetLoginSettings();
254                return SKIP_BODY;
255            }
256            
257            // Type
258            type=toType(getString("admin",action,"type"),true);
259            
260            // has Password
261            if(action.equals("haspassword")) {
262               //long start=System.currentTimeMillis();
263                boolean hasPassword=type==TYPE_WEB?
264                        pageContext.getConfig().hasPassword():
265                        pageContext.getConfig().hasServerPassword();
266                        
267                pageContext.setVariable(getString("admin",action,"returnVariable"),Caster.toBoolean(hasPassword));
268                return SKIP_BODY;
269            }
270            
271            // update Password
272            else if(action.equals("updatepassword")) {
273                try {
274                    ConfigWebAdmin.setPassword((ConfigImpl)pageContext.getConfig(),type!=TYPE_WEB,
275                            getString("oldPassword",null),getString("admin",action,"newPassword"));
276                } 
277                catch (Exception e) {
278                    throw Caster.toPageException(e);
279                }
280                return SKIP_BODY;
281            }
282            
283    
284            try {
285                // Password
286                password = getString("password","");
287                // Config
288                config=(ConfigImpl)pageContext.getConfig();
289                if(type==TYPE_SERVER)
290                    config=(ConfigImpl)config.getConfigServer(password);
291                
292                adminSync = config.getAdminSync();
293                    admin = ConfigWebAdmin.newInstance(config,password);
294            } 
295            catch (Exception e) {
296                throw Caster.toPageException(e);
297            }
298            //int version=config.getSerialNumber().getVersion();
299            /*if(type==TYPE_SERVER && version!=SerialNumber.VERSION_ENTERPRISE && version!=SerialNumber.VERSION_DEVELOP)
300                throw new SecurityException("can't access server settings with "+config.getSerialNumber().getStringVersion()+
301                        " version of Railo");
302                        
303            */
304                   
305            try {
306                            _doStartTag();
307                    } catch (IOException e) {
308                            throw Caster.toPageException(e);
309                    }
310            
311            return Tag.SKIP_BODY;
312        }
313    
314        private short toType(String strType, boolean throwError) throws ApplicationException {
315            strType=StringUtil.toLowerCase(strType).trim();
316            if("web".equals(strType))return TYPE_WEB;
317            else if("server".equals(strType))return TYPE_SERVER;
318            if(throwError)
319                    throw new ApplicationException("invalid value for attribute type ["+strType+"] of tag admin","valid values are web, server, all");
320            return TYPE_WEB;
321            }
322    
323            private void doTagSchedule() throws PageException {
324                    Schedule schedule=new Schedule();
325                    try {
326                            
327                            
328                            schedule.setPageContext(pageContext);
329                            schedule.setAction(getString("admin",action,"scheduleAction"));
330                            schedule.setTask(getString("task",null));
331                            schedule.setHidden(getBoolV("hidden",false));
332                            schedule.setReadonly(getBoolV("readonly",false));
333                            schedule.setOperation(getString("operation",null));
334                            schedule.setFile(getString("file",null));
335                            schedule.setPath(getString("path",null));
336                            schedule.setStartdate(getObject("startDate",null));
337                            schedule.setStarttime(getObject("startTime",null));
338                            schedule.setUrl(getString("url",null));
339                            schedule.setPublish(getBoolV("publish",false));
340                            schedule.setEnddate(getObject("endDate",null));
341                            schedule.setEndtime(getObject("endTime",null));
342                            schedule.setInterval(getString("interval",null));
343                            schedule.setRequesttimeout(new Double(getDouble("requestTimeOut",-1)));
344                            schedule.setUsername(getString("username",null));
345                            schedule.setPassword(getString("schedulePassword",null));
346                            schedule.setProxyserver(getString("proxyServer",null));
347                            schedule.setProxyuser(getString("proxyuser",null));
348                            schedule.setProxypassword(getString("proxyPassword",null));
349                            schedule.setResolveurl(getBoolV("resolveURL",false));
350                            schedule.setPort(new Double(getDouble("port",-1)));
351                            schedule.setProxyport(new Double(getDouble("proxyPort",80)));
352                            schedule.setReturnvariable(getString("returnvariable","cfschedule"));
353                            
354                            schedule.doStartTag();    
355                    } 
356                    finally {
357                        schedule.release();
358                        adminSync.broadcast(attributes, config);
359                        adminSync.broadcast(attributes, config);
360                    }
361            }
362        
363        /*private void doTagSearch() throws PageException {
364                    Search search=new Search();
365                    try {
366                            
367                            search.setPageContext(pageContext);
368                            
369                            search.setName(getString("admin",action,"name"));
370                            search.setCollection(getString("admin",action,"collection"));
371                            search.setType(getString("type",null));
372                            search.setMaxrows(getDouble("maxRows",-1));
373                            search.setStartrow(getDouble("startRow",1));
374                            search.setCategory(getString("category",null));
375                            search.setCategorytree(getString("categoryTree",null));
376                            search.setStatus(getString("status",null));
377                            search.setSuggestions(getString("suggestions",null));
378                            
379                            search.doStartTag();    
380                    } 
381                    finally {
382                        search.release();
383                    }
384            }*/
385        
386        private void doTagIndex() throws PageException {
387                    Index index=new Index();
388                    try {
389                            
390                            index.setPageContext(pageContext);
391                            
392                            index.setCollection(getString("admin",action,"collection"));
393                            index.setAction(getString("admin",action,"indexAction"));
394                            index.setType(getString("indexType",null));
395                            index.setTitle(getString("title",null));
396                            index.setKey(getString("key",null));
397                            index.setBody(getString("body",null));
398                            index.setCustom1(getString("custom1",null));
399                            index.setCustom2(getString("custom2",null));
400                            index.setCustom3(getString("custom3",null));
401                            index.setCustom4(getString("custom4",null));
402                            index.setUrlpath(getString("URLpath",null));
403                            index.setExtensions(getString("extensions",null));
404                            index.setQuery(getString("query",null));
405                            index.setRecurse(getBoolV("recurse",false));
406                            index.setLanguage(getString("language",null));
407                            index.setCategory(getString("category",null));
408                            index.setCategorytree(getString("categoryTree",null));
409                            index.setStatus(getString("status",null));
410                            index.setPrefix(getString("prefix",null));
411                            
412                            index.doStartTag();    
413                    } 
414                    finally {
415                        index.release();
416                        adminSync.broadcast(attributes, config);
417                    }
418            }
419        
420    
421        private void doTagCollection() throws PageException {
422            railo.runtime.tag.Collection coll=new railo.runtime.tag.Collection();
423                    try {
424                            
425                            coll.setPageContext(pageContext);
426                            
427                            //coll.setCollection(getString("admin",action,"collection"));
428                            coll.setAction(getString("collectionAction",null));
429                            coll.setCollection(getString("collection",null));
430                            coll.setPath(getString("path",null));
431                            coll.setLanguage(getString("language",null));
432                            coll.setName(getString("name",null));
433                            
434                            
435                            coll.doStartTag();    
436                    } 
437                    finally {
438                        coll.release();
439                        adminSync.broadcast(attributes, config);
440                    }
441            }
442        
443            /**
444         * @throws PageException
445         * 
446         */
447        private void _doStartTag() throws PageException,IOException {
448            
449    
450            // getToken
451            if(action.equals("gettoken")) {
452                doGetToken();
453                return;
454            }
455            
456    
457            // schedule
458            if(action.equals("schedule")) {
459                    doTagSchedule();
460                return;
461            }
462            // search
463            if(action.equals("collection")) {
464                    doTagCollection();
465                return;
466            }
467            // index
468            if(action.equals("index")) {
469                    doTagIndex();
470                return;
471            }
472            // cluster
473            if(action.equals("setcluster")) {
474                    doSetCluster();
475                return;
476            }
477            if(action.equals("getcluster")) {
478                    doGetCluster();
479                return;
480            }
481            
482            
483            
484            if(check("connect",ACCESS_FREE) && check2(CHECK_PW)) {
485                    try{
486                            if(config instanceof ConfigServer)
487                                    ((PageContextImpl)pageContext).setServerPassword(password);
488                    }
489                    catch(Throwable t){}
490            }
491            else if(check("surveillance",           ACCESS_FREE) && check2(ACCESS_READ  )) doSurveillance();
492            else if(check("getRegional",            ACCESS_FREE) && check2(ACCESS_READ  )) doGetRegional();
493            else if(check("isMonitorEnabled",       ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ  )) doIsMonitorEnabled();
494            else if(check("resetORMSetting",            ACCESS_FREE) && check2(ACCESS_READ  )) doResetORMSetting();
495            else if(check("getORMSetting",            ACCESS_FREE) && check2(ACCESS_READ  )) doGetORMSetting();
496            else if(check("getORMEngine",            ACCESS_FREE) && check2(ACCESS_READ  )) doGetORMEngine();
497            else if(check("updateORMSetting",            ACCESS_FREE) && check2(ACCESS_READ  )) doUpdateORMSetting();
498            else if(check("getApplicationListener", ACCESS_FREE) && check2(ACCESS_READ  )) doGetApplicationListener();
499            else if(check("getProxy",               ACCESS_FREE) && check2(ACCESS_READ  )) doGetProxy();
500            else if(check("getCharset",             ACCESS_FREE) && check2(ACCESS_READ  )) doGetCharset();
501            else if(check("getComponent",           ACCESS_FREE) && check2(ACCESS_READ  )) doGetComponent();
502            else if(check("getScope",               ACCESS_FREE) && check2(ACCESS_READ  )) doGetScope();
503            else if(check("getApplicationSetting",  ACCESS_FREE) && check2(ACCESS_READ  )) doGetApplicationSetting();
504            else if(check("getOutputSetting",               ACCESS_FREE) && check2(ACCESS_READ  )) doGetOutputSetting();
505            else if(check("getDatasourceSetting",   ACCESS_FREE) && check2(ACCESS_READ  )) doGetDatasourceSetting();
506            else if(check("getCustomTagSetting",    ACCESS_FREE) && check2(ACCESS_READ  )) doGetCustomTagSetting();
507            else if(check("getDatasource",          ACCESS_FREE) && check2(ACCESS_READ  )) doGetDatasource();
508            else if(check("getCacheConnections",    ACCESS_FREE) && check2(ACCESS_READ  )) doGetCacheConnections();
509            else if(check("getCacheConnection",     ACCESS_FREE) && check2(ACCESS_READ  )) doGetCacheConnection();
510            else if(check("getCacheDefaultConnection",ACCESS_FREE) && check2(ACCESS_READ  )) doGetCacheDefaultConnection();
511            else if(check("getDatasources",         ACCESS_FREE) && check2(ACCESS_READ  )) doGetDatasources();
512            else if(check("getRemoteClients",       ACCESS_FREE) && check2(ACCESS_READ  )) doGetRemoteClients();
513            else if(check("getRemoteClient",        ACCESS_FREE) && check2(ACCESS_READ  )) doGetRemoteClient();
514            else if(check("hasRemoteClientUsage",   ACCESS_FREE) && check2(ACCESS_READ  )) doHasRemoteClientUsage();
515            else if(check("getRemoteClientUsage",   ACCESS_FREE) && check2(ACCESS_READ  )) doGetRemoteClientUsage();
516            else if(check("getSpoolerTasks",                ACCESS_FREE) && check2(ACCESS_READ  )) doGetSpoolerTasks();
517            else if(check("getPerformanceSettings", ACCESS_FREE) && check2(ACCESS_READ  )) doGetPerformanceSettings();
518            else if(check("getLogSetting", ACCESS_FREE) && check2(ACCESS_READ  )) doGetLogSetting();
519            else if(check("getLogSettings", ACCESS_FREE) && check2(ACCESS_READ  )) doGetLogSettings();
520            else if(check("updatePerformanceSettings",ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdatePerformanceSettings();
521            else if(check("getGatewayentries",    ACCESS_NOT_WHEN_SERVER) && check2(ACCESS_READ  )) doGetGatewayEntries();
522            else if(check("getGatewayentry",     ACCESS_NOT_WHEN_SERVER) && check2(ACCESS_READ  )) doGetGatewayEntry();
523            else if(check("getRunningThreads",     ACCESS_FREE) && check2(ACCESS_READ  )) doGetRunningThreads();
524            else if(check("getMonitors",     ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ  )) doGetMonitors();
525            else if(check("getMonitor",     ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ  )) doGetMonitor();
526            else if(check("gateway",     ACCESS_NOT_WHEN_SERVER) && check2(ACCESS_READ  )) doGateway();
527            
528            
529            
530            // alias for getSpoolerTasks
531            else if(check("getRemoteClientTasks",   ACCESS_FREE) && check2(ACCESS_READ  )) doGetSpoolerTasks();
532            else if(check("getDatasourceDriverList",ACCESS_FREE) && check2(ACCESS_READ  )) doGetDatasourceDriverList();
533            else if(check("getDebuggingList",               ACCESS_FREE) && check2(ACCESS_READ  )) doGetDebuggingList();
534            else if(check("getSSLCertificate",      ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ  )) doGetSSLCertificate();
535            
536            else if(check("getPluginDirectory",             ACCESS_FREE) && check2(ACCESS_READ  )) doGetPluginDirectory();
537            else if(check("getPlugins",             ACCESS_FREE) && check2(ACCESS_READ  )) doGetPlugins();
538            else if(check("updatePlugin",           ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdatePlugin();
539            else if(check("removePlugin",           ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemovePlugin();
540            
541            else if(check("getContextDirectory",ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ  )) getContextDirectory();
542            else if(check("updateContext",          ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE  )) doUpdateContext();
543            else if(check("removeContext",          ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE  )) doRemoveContext();
544            
545            else if(check("getJars",                ACCESS_FREE) && check2(ACCESS_READ  )) doGetJars();
546            else if(check("getFlds",                ACCESS_FREE) && check2(ACCESS_READ  )) doGetFLDs();
547            else if(check("getTlds",                ACCESS_FREE) && check2(ACCESS_READ  )) doGetTLDs();
548            else if(check("getMailSetting",         ACCESS_FREE) && check2(ACCESS_READ  )) doGetMailSetting();
549            else if(check("getMailServers",         ACCESS_FREE) && check2(ACCESS_READ  )) doGetMailServers();
550            else if(check("getMapping",             ACCESS_FREE) && check2(ACCESS_READ  )) doGetMapping();
551            else if(check("getMappings",            ACCESS_FREE) && check2(ACCESS_READ  )) doGetMappings();
552            else if(check("getExtensions",                  ACCESS_FREE) && check2(ACCESS_READ  )) doGetExtensions();
553            else if(check("getExtensionProviders",  ACCESS_FREE) && check2(ACCESS_READ  )) doGetExtensionProviders();
554            else if(check("getExtensionInfo",               ACCESS_FREE) && check2(ACCESS_READ  )) doGetExtensionInfo();
555            
556            else if(check("getCustomTagMappings",   ACCESS_FREE) && check2(ACCESS_READ  )) doGetCustomTagMappings();
557            else if(check("getComponentMappings",   ACCESS_FREE) && check2(ACCESS_READ  )) doGetComponentMappings();
558            else if(check("getCfxTags",             ACCESS_FREE) && check2(ACCESS_READ  )) doGetCFXTags();
559            else if(check("getCPPCfxTags",         ACCESS_FREE) && check2(ACCESS_READ  )) doGetCPPCFXTags();
560            else if(check("getJavaCfxTags",         ACCESS_FREE) && check2(ACCESS_READ  )) doGetJavaCFXTags();
561            else if(check("getDebug",               ACCESS_FREE) && check2(ACCESS_READ  )) doGetDebug();
562            else if(check("getError",               ACCESS_FREE) && check2(ACCESS_READ  )) doGetError();
563            else if(check("verifyremoteclient",     ACCESS_FREE) && check2(ACCESS_READ  )) doVerifyRemoteClient();
564            else if(check("verifyDatasource",       ACCESS_FREE) && check2(ACCESS_READ  )) doVerifyDatasource();
565            else if(check("verifyCacheConnection",  ACCESS_FREE) && check2(ACCESS_READ  )) doVerifyCacheConnection();
566            else if(check("verifyMailServer",       ACCESS_FREE) && check2(ACCESS_READ  )) doVerifyMailServer();
567            else if(check("verifyExtensionProvider",ACCESS_FREE) && check2(ACCESS_READ  )) doVerifyExtensionProvider();
568            else if(check("verifyJavaCFX",                  ACCESS_FREE) && check2(ACCESS_READ  )) doVerifyJavaCFX();
569            else if(check("verifyCFX",                      ACCESS_FREE) && check2(ACCESS_READ  )) doVerifyCFX();
570            
571            else if(check("resetId",                                ACCESS_FREE) && check2(ACCESS_WRITE  )) doResetId();
572            else if(check("updateLoginSettings", ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE  )) doUpdateLoginSettings();
573            else if(check("updateJar",                      ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateJar();
574            else if(check("updateSSLCertificate",ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE  )) doUpdateSSLCertificate();
575            else if(check("updateMonitorEnabled",   ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE  )) doUpdateMonitorEnabled();
576            else if(check("updateTLD",                      ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateTLD();
577            else if(check("updateFLD",                      ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateFLD();
578            else if(check("updateregional",         ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateRegional();
579            else if(check("updateApplicationListener",ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateApplicationListener();
580            else if(check("updateproxy",            ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateProxy();
581            else if(check("updateCharset",         ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateCharset();
582            else if(check("updatecomponent",        ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateComponent();
583            else if(check("updatescope",            ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateScope();
584            else if(check("updateApplicationSetting",ACCESS_FREE) && check2(ACCESS_WRITE  ))doUpdateApplicationSettings();
585            else if(check("updateOutputSetting",    ACCESS_FREE) && check2(ACCESS_WRITE  ))doUpdateOutputSettings();
586            else if(check("updatepsq",              ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdatePSQ();
587            else if(check("updatedatasource",       ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateDatasource();
588            else if(check("updateCacheDefaultConnection",ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateCacheDefaultConnection();
589            else if(check("updateCacheConnection",  ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateCacheConnection();
590            else if(check("updateremoteclient",     ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateRemoteClient();
591            else if(check("updateRemoteClientUsage",ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateRemoteClientUsage();
592            else if(check("updatemailsetting",      ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateMailSetting();
593            else if(check("updatemailserver",       ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateMailServer();
594            else if(check("updatemapping",          ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateMapping();
595            else if(check("updatecustomtag",        ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateCustomTag();
596            else if(check("updateComponentMapping", ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateComponentMapping();
597            
598            
599            else if(check("updatejavacfx",          ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateJavaCFX();
600            else if(check("updatecppcfx",          ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateCPPCFX();
601            else if(check("updatedebug",            ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateDebug();
602            else if(check("updateerror",            ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateError();
603            else if(check("updateCustomTagSetting", ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateCustomTagSetting();
604            else if(check("updateExtension",                ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateExtension();
605            else if(check("updateExtensionProvider",ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateExtensionProvider();
606            else if(check("updateExtensionInfo",    ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateExtensionInfo();
607            else if(check("updateGatewayEntry",  ACCESS_NOT_WHEN_SERVER) && check2(ACCESS_WRITE  )) doUpdateGatewayEntry();
608            else if(check("updateLogSettings",  ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateUpdateLogSettings();
609            else if(check("updateMonitor",  ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE  )) doUpdateMonitor();
610            
611            
612            //else if(check("removeproxy",                  ACCESS_NOT_WHEN_SERVER  )) doRemoveProxy();
613            else if(check("removeMonitor",    ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE  )) doRemoveMonitor();
614            else if(check("removejar",                      ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveJar();
615            else if(check("removeTLD",                      ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveTLD();
616            else if(check("removeFLD",                      ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveFLD();
617            else if(check("removedatasource",       ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveDatasource();
618            else if(check("removeCacheConnection",  ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveCacheConnection();
619            else if(check("removeremoteclient",     ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveRemoteClient();
620            else if(check("removeRemoteClientUsage",ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveRemoteClientUsage();
621            else if(check("removeSpoolerTask",              ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveSpoolerTask();
622            else if(check("removeAllSpoolerTask",   ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveAllSpoolerTask();
623            // alias for executeSpoolerTask
624            else if(check("removeRemoteClientTask", ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveSpoolerTask();
625            else if(check("executeSpoolerTask",             ACCESS_FREE) && check2(ACCESS_WRITE  )) doExecuteSpoolerTask();
626            // alias for executeSpoolerTask
627            else if(check("executeRemoteClientTask",ACCESS_FREE) && check2(ACCESS_WRITE  )) doExecuteSpoolerTask();
628            else if(check("removemailserver",       ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveMailServer();
629            else if(check("removemapping",          ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveMapping();
630            else if(check("removecustomtag",        ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveCustomTag();
631            else if(check("removecomponentmapping", ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveComponentMapping();
632            else if(check("removecfx",              ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveCFX();
633            else if(check("removeExtension",        ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveExtension();
634            else if(check("removeExtensionProvider",ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveExtensionProvider();
635            else if(check("removeDefaultPassword",  ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveDefaultPassword();
636            else if(check("removeGatewayEntry",  ACCESS_NOT_WHEN_SERVER) && check2(ACCESS_WRITE  )) doRemoveGatewayEntry();
637            else if(check("removeCacheDefaultConnection",ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveCacheDefaultConnection();
638            
639            else if(check("storageGet",             ACCESS_FREE) && check2(ACCESS_READ  )) doStorageGet();
640            else if(check("storageSet",             ACCESS_FREE) && check2(ACCESS_WRITE  )) doStorageSet();
641            
642            else if(check("getdefaultpassword",     ACCESS_FREE) && check2(ACCESS_READ            )) doGetDefaultPassword();
643            else if(check("getContexts",           ACCESS_FREE) && check2(ACCESS_READ            )) doGetContexts();
644            else if(check("getContextes",           ACCESS_FREE) && check2(ACCESS_READ            )) doGetContexts();
645            else if(check("updatedefaultpassword",  ACCESS_FREE) && check2(ACCESS_WRITE            )) doUpdateDefaultPassword();
646            else if(check("hasindividualsecurity",  ACCESS_FREE) && check2(ACCESS_READ            )) doHasIndividualSecurity();
647            else if(check("resetpassword",          ACCESS_FREE) && check2(ACCESS_WRITE            )) doResetPassword();
648            else if(check("stopThread",                     ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE  )) doStopThread();
649            
650            else if(check("createsecuritymanager",  ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE            )) doCreateSecurityManager();
651            else if(check("getsecuritymanager",     ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ            )) doGetSecurityManager();
652            else if(check("removesecuritymanager",  ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE            )) doRemoveSecurityManager();
653            else if(check("getdefaultsecuritymanager",ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ          )) doGetDefaultSecurityManager();
654            else if(check("updatesecuritymanager",  ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE            )) doUpdateSecurityManager();
655            else if(check("updatedefaultsecuritymanager",ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE       )) doUpdateDefaultSecurityManager();
656            else if(check("compileMapping",         ACCESS_FREE) && check2(ACCESS_WRITE             )) doCompileMapping();
657            else if(check("createArchive",         ACCESS_FREE) && check2(ACCESS_WRITE             )) doCreateArchive();
658            else if(check("reload",                         ACCESS_FREE) && check2(ACCESS_WRITE            )) doReload();
659            
660    
661            else if(check("getResourceProviders",   ACCESS_FREE) && check2(ACCESS_READ  )) doGetResourceProviders();
662            else if(check("updateResourceProvider", ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateResourceProvider();
663            else if(check("updateDefaultResourceProvider", ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateDefaultResourceProvider();
664            else if(check("removeResourceProvider", ACCESS_FREE) && check2(ACCESS_WRITE  )) doRemoveResourceProvider();
665            
666            else if(check("getClusterClass",                ACCESS_FREE) && check2(ACCESS_READ  )) doGetClusterClass();
667            else if(check("updateClusterClass",     ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateClusterClass();
668            
669            else if(check("getAdminSyncClass",              ACCESS_FREE) && check2(ACCESS_READ  )) doGetAdminSyncClass();
670            else if(check("updateAdminSyncClass",   ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateAdminSyncClass();
671            
672            else if(check("getVideoExecuterClass",   ACCESS_FREE) && check2(ACCESS_READ  )) doGetVideoExecuterClass();
673            else if(check("updateVideoExecuterClass",ACCESS_FREE) && check2(ACCESS_WRITE  )) doUpdateVideoExecuterClass();
674            else if(check("terminateRunningThread",ACCESS_FREE) && check2(ACCESS_WRITE  )) doTerminateRunningThread();
675            
676            else if(check("updateLabel",                ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE     )) doUpdateLabel();
677            else if(check("restart",                ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE     )) doRestart();
678            else if(check("runUpdate",              ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE     )) doRunUpdate();
679            else if(check("removeUpdate",           ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE     )) doRemoveUpdate();
680            else if(check("getUpdate",              ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE     )) doGetUpdate();
681            else if(check("listPatches",              ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ     )) listPatches();
682            else if(check("needNewJars",              ACCESS_NOT_WHEN_WEB) && check2(ACCESS_READ     )) needNewJars();
683            else if(check("updateJars",              ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE     )) doUpdateJars();
684            else if(check("updateupdate",           ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE     )) doUpdateUpdate();
685            else if(check("getSerial",              ACCESS_FREE) && check2(ACCESS_READ     )) doGetSerial();
686            else if(check("updateSerial",           ACCESS_NOT_WHEN_WEB) && check2(ACCESS_WRITE     )) doUpdateSerial();
687            
688            else if(check("securitymanager",        ACCESS_FREE) && check2(ACCESS_READ             )) doSecurityManager();
689            
690            
691            
692            else throw new ApplicationException("invalid action ["+action+"] for tag admin");
693                
694        }
695    
696            private boolean check2(short accessRW) throws SecurityException {
697            if(accessRW==ACCESS_READ) ConfigWebUtil.checkGeneralReadAccess(config,password);
698                    else if(accessRW==ACCESS_WRITE) ConfigWebUtil.checkGeneralWriteAccess(config,password);
699                    else if(accessRW==CHECK_PW) {
700                            ConfigWebUtil.checkGeneralReadAccess(config,password);
701                            ConfigWebUtil.checkPassword(config,null,password);
702                    }
703            return true;
704        }
705            private boolean check(String action, short access) throws ApplicationException {
706            if( this.action.equalsIgnoreCase(action)) {
707                if(access==ACCESS_FREE) {
708                }
709                else if(access==ACCESS_NOT_WHEN_SERVER) {
710                    throwNoAccessWhenServer();
711                }
712                
713                else if(access==ACCESS_NOT_WHEN_WEB) {
714                    throwNoAccessWhenWeb();
715                }
716                else if(access==ACCESS_NEVER) {
717                    throwNoAccessWhenServer();
718                    throwNoAccessWhenServer();
719                }
720                return true;
721            }
722            return false;
723        }
724        
725    
726        private void doRunUpdate() throws PageException {
727            doUpdateJars();
728            admin.runUpdate();
729            adminSync.broadcast(attributes, config);
730        }
731        
732        private void doRemoveUpdate() throws PageException {
733            boolean onlyLatest = getBoolV("onlyLatest", false);
734            
735    
736            if(onlyLatest)  admin.removeLatestUpdate();
737            else                    admin.removeUpdate();
738            adminSync.broadcast(attributes, config);
739        }
740        
741        private void doRestart() throws PageException {
742            admin.restart();
743            adminSync.broadcast(attributes, config);
744        }
745        
746        private void doCreateArchive() throws PageException {
747            String virtual = getString("admin",action,"virtual").toLowerCase();
748            String strFile = getString("admin",action,"file");
749            Resource file = ResourceUtil.toResourceNotExisting(pageContext, strFile);
750            
751            boolean secure = getBoolV("secure", false);
752            
753            // compile
754            Mapping mapping = doCompileMapping(virtual, true);
755            
756            // class files 
757            if(mapping==null)throw new ApplicationException("there is no mapping for ["+virtual+"]");
758            if(!mapping.hasPhysical())throw new ApplicationException("mapping ["+virtual+"] has no physical directory");
759            
760            Resource classRoot = mapping.getClassRootDirectory();
761            
762            try {
763                    if(file.exists())file.delete();
764                    if(!file.exists())file.createFile(true);
765                    //Resource ra = ResourceUtil.toResourceNotExisting(pageContext, "zip://"+file.getPath());
766                    //ResourceUtil.copyRecursive(classRoot, ra);
767                    filter=new ExtensionResourceFilter(new String[]{"class","cfm","cfml","cfc"},true,true);
768                            
769                    // source files
770                            if(!secure) {
771                                    Resource physical = mapping.getPhysical();
772                                    // ResourceUtil.copyRecursive(physical, ra,new ExtensionResourceFilter(new String[]{"cfm","cfml","cfc"},true));
773                                    CompressUtil.compressZip(ResourceUtil.listResources(new Resource[]{physical,classRoot},filter), file, filter);
774                            }
775                            else {
776                                    CompressUtil.compressZip(classRoot.listResources(filter), file, filter);
777                            }
778                            
779                            if(getBoolV("append", false)) {
780                                    admin.updateMapping(
781                                                    mapping.getVirtual(),
782                                    mapping.getStrPhysical(),
783                                    strFile,
784                                    mapping.isPhysicalFirst()?"physical":"archive",
785                                    mapping.isTrusted(),
786                                    mapping.isTopLevel()
787                            );
788                            store();
789                            }
790                            
791                            
792                    }
793            catch (IOException e) {
794                            throw Caster.toPageException(e); 
795                    }
796            adminSync.broadcast(attributes, config);
797        }
798        private void doCompileMapping() throws PageException {
799            doCompileMapping(getString("admin",action,"virtual").toLowerCase(), getBoolV("stoponerror", true));
800            adminSync.broadcast(attributes, config);
801        }
802        
803        private Mapping doCompileMapping(String virtual, boolean stoponerror) throws PageException {
804            
805            if(StringUtil.isEmpty(virtual))return null;
806            
807            if(!StringUtil.startsWith(virtual,'/'))virtual='/'+virtual;
808            if(!StringUtil.endsWith(virtual,'/'))virtual+='/';
809            
810            Mapping[] mappings = config.getMappings();
811            for(int i=0;i<mappings.length;i++) {
812                Mapping mapping = mappings[i];
813                if(mapping.getVirtualLowerCaseWithSlash().equals(virtual)) {
814                    Map errors = stoponerror?null:new HashTable();
815                    doCompileFile(mapping,mapping.getPhysical(),"",errors);
816                    if(errors!=null && errors.size()>0) {
817                            StringBuffer sb=new StringBuffer();
818                            Iterator it = errors.keySet().iterator();
819                            Object key;
820                            while(it.hasNext()) {
821                                    key=it.next();
822                                    if(sb.length()>0)sb.append("\n\n");
823                                    sb.append(errors.get(key));
824                                    
825                            }
826                            throw new ApplicationException(sb.toString());
827                    }
828                    return mapping;
829                }
830            }
831            return null;
832        }
833    
834        private void doCompileFile(Mapping mapping,Resource file,String path,Map<String,String> errors) throws PageException {
835            if(ResourceUtil.exists(file)) {
836                if(file.isDirectory()) {
837                    Resource[] files = file.listResources(filter);
838                    for(int i=0;i<files.length;i++) {
839                        String p=path+'/'+files[i].getName();
840                        //print.ln(files[i]+" - "+p);
841                        doCompileFile(mapping,files[i],p,errors);
842                    }
843                }
844                else if(file.isFile()) {
845                    PageSourceImpl ps=(PageSourceImpl) mapping.getPageSource(path);
846                    
847                    
848                    try {
849                            
850                        ps.clear();
851                        ps.loadPage(pageContext,pageContext.getConfig()); 
852                        //pageContext.compile(ps);
853                    } catch (PageException pe) {
854                            //PageException pe = pse.getPageException();
855                        
856                        String template=ps.getDisplayPath();
857                        StringBuilder msg=new StringBuilder(pe.getMessage());
858                        msg.append(", Error Occurred in File [");
859                        msg.append(template);
860                        if(pe instanceof PageExceptionImpl) {
861                            try{
862                            PageExceptionImpl pei=(PageExceptionImpl)pe;
863                            Array context = pei.getTagContext(config);
864                            if(context.size()>0){
865                                msg.append(":");
866                                msg.append(Caster.toString(((Struct)context.getE(1)).get("line")));
867                            }
868                            }
869                            catch(Throwable t){}
870                            
871                        }
872                        msg.append("]");
873                        if(errors!=null) errors.put(template,msg.toString());
874                        else throw new ApplicationException(msg.toString());
875                    
876                    }
877                }
878            }
879        }
880    
881        /**
882         * @throws PageException
883         * 
884         */
885        private void doResetPassword() throws PageException {
886            
887            try {
888                admin.setPassword(getString("contextPath",null),null);
889            }catch (Exception e) {} 
890            store();
891        }
892    
893        /**
894         * @throws PageException
895         */
896        private void doGetContexts() throws PageException {
897            
898            if(config instanceof ConfigServerImpl) {
899                ConfigServerImpl cs=(ConfigServerImpl) config;
900                CFMLFactoryImpl[] factories = cs.getJSPFactories(); 
901                
902                railo.runtime.type.Query qry=
903                    new QueryImpl(
904                                    new String[]{"path","id","hash","label","hasOwnSecContext","url","config_file"},
905                                    factories.length,getString("admin",action,"returnVariable"));
906                pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
907                
908                for(int i=0;i<factories.length;i++) {
909                    int row=i+1;
910                    CFMLFactoryImpl factory = factories[i];
911                    
912                    qry.setAtEL("path",row,factory.getConfigWebImpl().getServletContext().getRealPath("/"));
913                    
914                    qry.setAtEL("config_file",row,factory.getConfigWebImpl().getConfigFile().getAbsolutePath());
915                    if(factory.getURL()!=null)qry.setAtEL("url",row,factory.getURL().toExternalForm());
916                    
917    
918                    qry.setAtEL("id",row,factory.getConfig().getId());
919                    qry.setAtEL("hash",row,SystemUtil.hash(factory.getConfigWebImpl().getServletContext()));
920                    qry.setAtEL("label",row,factory.getLabel());
921                    qry.setAtEL("hasOwnSecContext",row,Caster.toBoolean(cs.hasIndividualSecurityManager(factory.getConfig().getId())));
922                }
923            }
924        }
925    
926        private void doHasIndividualSecurity() throws PageException {
927            pageContext.setVariable(
928                     getString("admin",action,"returnVariable"),
929                     Caster.toBoolean(
930                             config.getConfigServer(password).hasIndividualSecurityManager(
931                                     getString("admin",action,"id")
932                                     
933                             )
934                     )
935            );
936        }
937    
938        private void doUpdateUpdate() throws PageException {
939            admin.updateUpdate(getString("admin",action,"updatetype"),getString("admin",action,"updatelocation"));
940            store();
941            adminSync.broadcast(attributes, config);
942        }
943        
944        /**
945         * @throws PageException
946         * 
947         */
948        private void doUpdateSerial() throws PageException {
949            admin.updateSerial(getString("admin",action,"serial"));
950            store();
951            pageContext.serverScope().reload();
952        }
953    
954        /**
955         * @throws PageException
956         * 
957         */
958        private void doGetSerial() throws PageException {
959           pageContext.setVariable(
960                    getString("admin",action,"returnVariable"),
961                    config.getSerialNumber());
962        }
963        
964    
965        private Resource getPluginDirectory() {
966            return config.getConfigDir().getRealResource("context/admin/plugin");
967        }
968    
969        private Resource getContextDirectory() throws PageException  {
970            ConfigServer cs = config.getConfigServer(password);
971            Resource dist = cs.getConfigDir().getRealResource("distribution");
972            dist.mkdirs();
973            return dist;
974        }
975        
976        private void doGetPluginDirectory() throws PageException {
977            pageContext.setVariable(
978                     getString("admin",action,"returnVariable"),
979                     getPluginDirectory().getAbsolutePath());
980         }
981    
982        private void doUpdatePlugin() throws PageException, IOException {
983            String strSrc = getString("admin",action,"source");
984            Resource src = ResourceUtil.toResourceExisting(pageContext, strSrc);
985            Resource srcDir = ResourceUtil.toResourceExisting(pageContext, "zip://"+src.getAbsolutePath());
986            String name=ResourceUtil.getName(src.getName());
987            if(!PluginFilter.doAccept(srcDir))
988                    throw new ApplicationException("plugin ["+strSrc+"] is invalid, missing one of the following files [Action.cfc,language.xml] in root, existing files are ["+railo.runtime.type.List.arrayToList(srcDir.list(), ", ")+"]");
989            
990            Resource dir = getPluginDirectory();
991            Resource trgDir = dir.getRealResource(name);
992            if(trgDir.exists()){
993                    trgDir.remove(true);
994            }
995            
996            ResourceUtil.copyRecursive(srcDir, trgDir);    
997            store();
998        }
999        private void doUpdateLabel() throws PageException, IOException {
1000            if(config instanceof ConfigServer) {
1001                     if(admin.updateLabel(getString("admin",action,"hash"),getString("admin",action,"label"))) {
1002                         store();
1003                         adminSync.broadcast(attributes, config);
1004                     }
1005            }
1006        }
1007        
1008        private void doUpdateContext() throws PageException, IOException {
1009            String strSrc = getString("admin",action,"source");
1010            String strRealpath = getString("admin",action,"destination");
1011            Resource src = ResourceUtil.toResourceExisting(pageContext, strSrc);
1012            
1013            ConfigServerImpl server = (ConfigServerImpl) config.getConfigServer(password);
1014            ConfigWeb[] webs = server.getConfigWebs();
1015            ConfigWeb web;
1016            Resource trg,p;
1017            
1018            for(int i=0;i<webs.length;i++){
1019                    web=webs[i];
1020                    trg=web.getConfigDir().getRealResource("context").getRealResource(strRealpath);
1021                    
1022                    if(trg.exists()) trg.remove(true);
1023                    p = trg.getParentResource();
1024                if(!p.isDirectory())p.createDirectory(true);
1025               
1026                src.copyTo(trg, false);
1027            }
1028            store();
1029        }
1030        
1031        
1032        private void doRemoveContext() throws PageException, IOException {
1033            String strRealpath = getString("admin",action,"destination");
1034            
1035            ConfigServerImpl server = (ConfigServerImpl) config.getConfigServer(password);
1036            ConfigWeb[] webs = server.getConfigWebs();
1037            ConfigWeb web;
1038            Resource trg,p,dsStore;
1039            for(int i=0;i<webs.length;i++){
1040                    web=webs[i];
1041                    trg=web.getConfigDir().getRealResource("context").getRealResource(strRealpath);
1042                    if(trg.exists()) trg.remove(true);
1043                    p=trg.getParentResource();
1044                dsStore=p.getRealResource(".DS_Store");
1045                dsStore.delete();
1046                while(p.isDirectory() && ResourceUtil.isEmptyDirectory(p)) {
1047                    p.remove(false);
1048                    p=p.getParentResource();
1049                    dsStore=p.getRealResource(".DS_Store");
1050                    dsStore.delete();
1051                }
1052            }
1053            store();
1054        }
1055        
1056        private void doRemovePlugin() throws PageException, IOException {
1057            Resource dir = getPluginDirectory();
1058            String name = getString("admin",action,"name");
1059            Resource trgDir = dir.getRealResource(name);
1060            trgDir.remove(true);
1061            
1062            store();
1063        }
1064        
1065        private void doGetPlugins() throws PageException {
1066            Resource dir = getPluginDirectory();
1067            
1068            String[] list = dir.list(new PluginFilter());
1069            railo.runtime.type.Query qry=
1070                    new QueryImpl(
1071                                    new String[]{"name"},
1072                                    list.length,getString("admin",action,"returnVariable"));
1073            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1074            
1075            for(int i=0;i<list.length;i++) {
1076                int row=i+1;
1077                qry.setAtEL("name",row,list[i]);
1078            }
1079         }
1080        
1081        private void doStorageSet() throws PageException {
1082            try {
1083                            admin.storageSet(config,getString("admin",action,"key"),getObject("admin", action, "value"));
1084                    } 
1085            catch (Exception e) {
1086                            throw Caster.toPageException(e);
1087                    }
1088            }
1089    
1090            private void doStorageGet() throws PageException {
1091           try {
1092                    pageContext.setVariable(
1093                                getString("admin",action,"returnVariable"),
1094                                admin.storageGet(config,getString("admin",action,"key")));
1095                    } 
1096           catch (Exception e) {
1097               throw Caster.toPageException(e);
1098                    } 
1099            }
1100    
1101        /**
1102         * @throws PageException
1103         * 
1104         */
1105        private void doGetDefaultPassword() throws PageException {
1106            String password = admin.getDefaultPassword();
1107            if(password==null) password="";
1108            
1109            pageContext.setVariable(
1110                    getString("admin",action,"returnVariable"),
1111                    password);
1112            
1113        }
1114        
1115        /**
1116         * @throws PageException
1117         * 
1118         */
1119        private void doUpdateDefaultPassword() throws PageException {
1120            admin.updateDefaultPassword(getString("admin",action,"newPassword"));
1121            store();
1122        }
1123        private void doRemoveDefaultPassword() throws PageException {
1124            admin.removeDefaultPassword();
1125            store();
1126        }
1127        
1128    
1129        /* *
1130         * @throws PageException
1131         * 
1132         * /
1133        private void doUpdatePassword() throws PageException {
1134            try {
1135                ConfigWebAdmin.setPassword(config,password==null?null:Caster.toString(password),getString("admin",action,"newPassword"));
1136            } 
1137            catch (Exception e) {
1138                throw Caster.toPageException(e);
1139            }
1140            //store();
1141        }*/
1142        
1143        /**
1144         * @throws PageException
1145         * 
1146         */
1147        private void doGetDebug() throws PageException {
1148            Struct sct=new StructImpl();
1149            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
1150            
1151            String src = config.intDebug()==ConfigImpl.SERVER_BOOLEAN_TRUE || config.intDebug()==ConfigImpl.SERVER_BOOLEAN_FALSE?"server":"web";
1152            
1153            sct.set(DEBUG,Caster.toBoolean(config.debug()));
1154            sct.set(DEBUG_SRC,src);
1155            sct.set(DEBUG_TEMPLATE,config.getDebugTemplate());
1156            sct.set(DEBUG_SHOW_QUERY_USAGE,Caster.toBoolean(config.getDebugShowQueryUsage()));
1157            
1158            
1159            try {
1160                PageSource ps = ((PageContextImpl)pageContext).getPageSourceExisting(config.getDebugTemplate());
1161                if(ps!=null) sct.set(DEBUG_TEMPLATE,ps.getDisplayPath());
1162                else sct.set(DEBUG_TEMPLATE,"");
1163            } catch (PageException e) {
1164                sct.set(DEBUG_TEMPLATE,"");
1165            }
1166            sct.set(STR_DEBUG_TEMPLATE,config.getDebugTemplate());
1167        }
1168        
1169        private void doGetError() throws PageException {
1170            Struct sct=new StructImpl();
1171            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
1172            //sct.set("errorTemplate",config.getErrorTemplate());
1173            
1174            Struct templates=new StructImpl();
1175            Struct str=new StructImpl();
1176            sct.set(TEMPLATES, templates);
1177            sct.set(STR, str);
1178            sct.set(DO_STATUS_CODE, Caster.toBoolean(config.getErrorStatusCode()));
1179            
1180            // 500
1181            String template=config.getErrorTemplate(500);
1182            try {
1183                PageSource ps = ((PageContextImpl)pageContext).getPageSourceExisting(template);
1184                if(ps!=null) templates.set("500",ps.getDisplayPath());
1185                else templates.set("500","");
1186            } catch (PageException e) {
1187                    templates.set("500","");
1188            }
1189            str.set("500",template);
1190    
1191            // 404
1192            template=config.getErrorTemplate(404);
1193            try {
1194                PageSource ps = ((PageContextImpl)pageContext).getPageSourceExisting(template);
1195                if(ps!=null) templates.set("404",ps.getDisplayPath());
1196                else templates.set("404","");
1197            } catch (PageException e) {
1198                    templates.set("404","");
1199            }
1200            str.set("404",template);
1201    
1202            
1203            
1204            
1205            
1206            
1207        }
1208    
1209        /**
1210         * @throws PageException
1211         * 
1212         */
1213        private void doGetDebugData() throws PageException {
1214            pageContext.setVariable(
1215                    getString("admin",action,"returnVariable"),
1216                    pageContext.getDebugger().getDebuggingData());
1217        }
1218        private void doGetInfo() throws PageException {
1219            Struct sct=new StructImpl();
1220            pageContext.setVariable(
1221                    getString("admin",action,"returnVariable"),
1222                    sct);
1223            
1224            
1225            if(config instanceof ConfigWebImpl){
1226                    ConfigWebImpl cw=(ConfigWebImpl) config;
1227                    sct.setEL(LABEL, cw.getLabel());
1228                    sct.setEL(HASH, cw.getHash());
1229                    sct.setEL(ROOT, cw.getRootDirectory().getAbsolutePath());
1230            }
1231            
1232            sct.setEL(CONFIG, config.getConfigFile().getAbsolutePath());
1233            
1234        }
1235    
1236        /**
1237         * 
1238         */
1239        private void doPrintDebug() {
1240            try {
1241                    DumpWriter writer = pageContext.getConfig().getDefaultDumpWriter();
1242                    DumpData data = pageContext.getDebugger().toDumpData(pageContext, 9999,DumpUtil.toDumpProperties());
1243                pageContext.forceWrite(writer.toString(pageContext,data,true));
1244            } catch (IOException e) {}
1245        }
1246    
1247        /**
1248         * @throws PageException
1249         * 
1250         */
1251        private void doCreateSecurityManager() throws  PageException {
1252            admin.createSecurityManager(getString("admin",action,"id"));
1253            store();
1254        }
1255        
1256        private void doRemoveSecurityManager() throws  PageException {
1257            admin.removeSecurityManager(getString("admin",action,"id"));
1258            store();
1259        }
1260        
1261        
1262    
1263        private short fb(String key) throws PageException {
1264            return getBool("admin",action,key)?SecurityManager.VALUE_YES:SecurityManager.VALUE_NO;
1265        }
1266        private short fb2(String key) throws PageException {
1267            return SecurityManagerImpl.toShortAccessRWValue(getString("admin",action,key));
1268        }
1269    
1270        private void doUpdateDefaultSecurityManager() throws  PageException {
1271            
1272            admin.updateDefaultSecurity(
1273                    fb("setting"),
1274                    SecurityManagerImpl.toShortAccessValue(getString("admin",action,"file")),
1275                    getFileAcces(),
1276                    fb("direct_java_access"),
1277                    fb("mail"),
1278                    SecurityManagerImpl.toShortAccessValue(getString("admin",action,"datasource")),
1279                    fb("mapping"),
1280                    fb("remote"),
1281                    fb("custom_tag"),
1282                    fb("cfx_setting"),
1283                    fb("cfx_usage"),
1284                    fb("debugging"),
1285                    fb("search"),
1286                    fb("scheduled_task"),
1287                    fb("tag_execute"),
1288                    fb("tag_import"),
1289                    fb("tag_object"),
1290                    fb("tag_registry"),
1291                    fb("cache"),
1292                    fb("gateway"),
1293                    fb("orm"),
1294                    fb2("access_read"),
1295                    fb2("access_write")
1296            );
1297            store();
1298            adminSync.broadcast(attributes, config);
1299        }
1300    
1301        private Resource[] getFileAcces() throws PageException {
1302            Object value=attributes.get(FILE_ACCESS,null);
1303            if(value==null) return null;
1304            Array arr = Caster.toArray(value);
1305            List rtn = new ArrayList();
1306            Iterator it = arr.valueIterator();
1307            String path;
1308            Resource res;
1309            while(it.hasNext()){
1310                    path=Caster.toString(it.next());
1311                    if(StringUtil.isEmpty(path))continue;
1312                    
1313                    res=config.getResource(path);
1314                    if(!res.exists())
1315                            throw new ApplicationException("path ["+path+"] does not exist");
1316                    if(!res.isDirectory())
1317                            throw new ApplicationException("path ["+path+"] is not a directory");
1318                    rtn.add(res);
1319            }
1320            return (Resource[])rtn.toArray(new Resource[rtn.size()]);
1321            }
1322    
1323            private void doUpdateSecurityManager() throws  PageException {
1324                    admin.updateSecurity(
1325                    getString("admin",action,"id"),
1326                    fb("setting"),
1327                    SecurityManagerImpl.toShortAccessValue(getString("admin",action,"file")),
1328                    getFileAcces(),
1329                    fb("direct_java_access"),
1330                    fb("mail"),
1331                    SecurityManagerImpl.toShortAccessValue(getString("admin",action,"datasource")),
1332                    fb("mapping"),
1333                    fb("remote"),
1334                    fb("custom_tag"),
1335                    fb("cfx_setting"),
1336                    fb("cfx_usage"),
1337                    fb("debugging"),
1338                    fb("search"),
1339                    fb("scheduled_task"),
1340                    fb("tag_execute"),
1341                    fb("tag_import"),
1342                    fb("tag_object"),
1343                    fb("tag_registry"),
1344                    fb("cache"),
1345                    fb("gateway"),
1346                    fb("orm"),
1347                    fb2("access_read"),
1348                    fb2("access_write")
1349            );
1350            store();
1351        }
1352    
1353        
1354        
1355        /**
1356         * @throws PageException
1357         * 
1358         */
1359        private void doGetDefaultSecurityManager() throws PageException {
1360            SecurityManager dsm = config.getConfigServer(password).getDefaultSecurityManager();
1361            _fillSecData(dsm);
1362        }
1363    
1364        private void doGetSecurityManager() throws PageException {
1365            SecurityManager sm = config.getConfigServer(password).getSecurityManager(getString("admin",action,"id"));
1366            _fillSecData(sm);
1367        }
1368        
1369        private void _fillSecData(SecurityManager sm) throws PageException {
1370            
1371            Struct sct=new StructImpl();
1372            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
1373            sct.set("cfx_setting",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CFX_SETTING)==SecurityManager.VALUE_YES));
1374            sct.set("cfx_usage",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CFX_USAGE)==SecurityManager.VALUE_YES));
1375            sct.set("custom_tag",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CUSTOM_TAG)==SecurityManager.VALUE_YES));
1376            sct.set("datasource",_fillSecDataDS(sm.getAccess(SecurityManager.TYPE_DATASOURCE)));
1377            sct.set("debugging",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_DEBUGGING)==SecurityManager.VALUE_YES));
1378            sct.set("direct_java_access",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_DIRECT_JAVA_ACCESS)==SecurityManager.VALUE_YES));
1379            sct.set("mail",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_MAIL)==SecurityManager.VALUE_YES));
1380            sct.set("mapping",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_MAPPING)==SecurityManager.VALUE_YES));
1381            sct.set("remote",Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_REMOTE)==SecurityManager.VALUE_YES));
1382            sct.set("setting",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SETTING)==SecurityManager.VALUE_YES));
1383            sct.set("search",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SEARCH)==SecurityManager.VALUE_YES));
1384            sct.set("scheduled_task",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SCHEDULED_TASK)==SecurityManager.VALUE_YES));
1385            sct.set("cache",Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_CACHE)==SecurityManager.VALUE_YES));
1386            sct.set("gateway",Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_GATEWAY)==SecurityManager.VALUE_YES));
1387            sct.set("orm",Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_ORM)==SecurityManager.VALUE_YES));
1388            
1389            sct.set("tag_execute",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_EXECUTE)==SecurityManager.VALUE_YES));
1390            sct.set("tag_import",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_IMPORT)==SecurityManager.VALUE_YES));
1391            sct.set("tag_object",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_OBJECT)==SecurityManager.VALUE_YES));
1392            sct.set("tag_registry",Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_REGISTRY)==SecurityManager.VALUE_YES));
1393            sct.set("access_read",SecurityManagerImpl.toStringAccessRWValue(sm.getAccess(SecurityManager.TYPE_ACCESS_READ)));
1394            sct.set("access_write",SecurityManagerImpl.toStringAccessRWValue(sm.getAccess(SecurityManager.TYPE_ACCESS_WRITE)));
1395            short accessFile = sm.getAccess(SecurityManager.TYPE_FILE);
1396            String str = SecurityManagerImpl.toStringAccessValue(accessFile);
1397            if(str.equals("yes"))str="all";
1398            sct.set("file",str);
1399            
1400            Array arr=new ArrayImpl();
1401            if(accessFile!=SecurityManager.VALUE_ALL){
1402                    Resource[] reses = ((SecurityManagerImpl)sm).getCustomFileAccess();
1403                    for(int i=0;i<reses.length;i++){
1404                            arr.appendEL(reses[i].getAbsolutePath());
1405                    }
1406            }
1407            sct.set("file_access",arr);
1408        
1409        }
1410    
1411            private Double _fillSecDataDS(short access) {
1412                    switch(access) {
1413                    case SecurityManager.VALUE_YES: return Caster.toDouble(-1);
1414                    case SecurityManager.VALUE_NO: return Caster.toDouble(0);
1415                    case SecurityManager.VALUE_1: return Caster.toDouble(1);
1416                    case SecurityManager.VALUE_2: return Caster.toDouble(2);
1417                    case SecurityManager.VALUE_3: return Caster.toDouble(3);
1418                    case SecurityManager.VALUE_4: return Caster.toDouble(4);
1419                    case SecurityManager.VALUE_5: return Caster.toDouble(5);
1420                    case SecurityManager.VALUE_6: return Caster.toDouble(6);
1421                    case SecurityManager.VALUE_7: return Caster.toDouble(7);
1422                    case SecurityManager.VALUE_8: return Caster.toDouble(8);
1423                    case SecurityManager.VALUE_9: return Caster.toDouble(9);
1424                    case SecurityManager.VALUE_10: return Caster.toDouble(10);
1425                    }
1426                    return Caster.toDouble(-1);
1427            }
1428    
1429            /**
1430         * @throws PageException
1431         * 
1432         */
1433        private void doUpdateDebug() throws PageException {
1434            admin.updateDebug(Caster.toBoolean(getString("debug",""),null));
1435            admin.updateDebugTemplate(getString("admin",action,"debugTemplate"));
1436            admin.updateDebugShowQueryUsage(Caster.toBoolean(getString("debugShowQueryUsage",""),null));
1437            store();
1438            adminSync.broadcast(attributes, config);
1439        }
1440        private void doUpdateError() throws PageException {
1441    
1442            admin.updateErrorTemplate(500,getString("admin",action,"template500"));
1443            admin.updateErrorTemplate(404,getString("admin",action,"template404"));
1444            admin.updateErrorStatusCode(getBoolObject("admin",action,"statuscode"));
1445            store();
1446            adminSync.broadcast(attributes, config);
1447        }
1448    
1449        /**
1450         * @throws PageException
1451         * 
1452         */
1453        private void doUpdateJavaCFX() throws PageException {
1454            String name=getString("admin",action,"name");
1455            if(StringUtil.startsWithIgnoreCase(name,"cfx_"))name=name.substring(4);
1456            admin.updateJavaCFX(
1457                    name,
1458                    getString("admin",action,"class")
1459            );
1460            store();
1461            adminSync.broadcast(attributes, config);
1462        }
1463    
1464        private void doVerifyJavaCFX() throws PageException {
1465            String name=getString("admin",action,"name");
1466            admin.verifyJavaCFX(
1467                    name,
1468                    getString("admin",action,"class")
1469            );
1470        }
1471        private void doVerifyCFX() throws PageException {
1472            String name=getString("admin",action,"name");
1473            if(StringUtil.startsWithIgnoreCase(name,"cfx_"))name=name.substring(4);
1474            admin.verifyCFX(name);
1475        }
1476        
1477    
1478        private void doUpdateCPPCFX() throws PageException {
1479            String name=getString("admin",action,"name");
1480            String procedure=getString("admin",action,"procedure");
1481            String serverLibrary=getString("admin",action,"serverLibrary");
1482            boolean keepAlive=getBool("admin",action,"keepAlive");
1483            
1484            
1485            if(StringUtil.startsWithIgnoreCase(name,"cfx_"))name=name.substring(4);
1486            admin.updateCPPCFX(name,procedure,serverLibrary,keepAlive);
1487            store();
1488            adminSync.broadcast(attributes, config);
1489        }
1490        
1491        
1492    
1493        /**
1494         * @throws PageException
1495         * 
1496         */
1497        private void doRemoveCFX() throws PageException {
1498            admin.removeCFX(
1499                    getString("admin",action,"name")
1500            );
1501            store();
1502            adminSync.broadcast(attributes, config);
1503        }
1504        private void doRemoveExtension() throws PageException {
1505            admin.removeExtension(
1506                    getString("admin",action,"provider"),
1507                    getString("admin",action,"id")
1508            );
1509            store();
1510            //adminSync.broadcast(attributes, config);
1511        }
1512        
1513        
1514    
1515        /**
1516         * @throws PageException
1517         * 
1518         */
1519        private void doGetJavaCFXTags() throws PageException {
1520            Map map = config.getCFXTagPool().getClasses();
1521            railo.runtime.type.Query qry=new QueryImpl(new String[]{"displayname","sourcename","readonly","class","name","isvalid"},0,"query");
1522            Iterator it = map.keySet().iterator();
1523            
1524            int row=0;
1525            while(it.hasNext()) {
1526                CFXTagClass tag=(CFXTagClass) map.get(it.next());
1527                if(tag instanceof JavaCFXTagClass) {
1528                    row++;
1529                    qry.addRow(1);
1530                    JavaCFXTagClass jtag =(JavaCFXTagClass) tag;
1531                    qry.setAt("displayname",row,tag.getDisplayType());
1532                    qry.setAt("sourcename",row,tag.getSourceName());
1533                    qry.setAt("readonly",row,Caster.toBoolean(tag.isReadOnly()));
1534                    qry.setAt("isvalid",row,Caster.toBoolean(tag.isValid()));
1535                    qry.setAt("name",row,jtag.getName());
1536                    qry.setAt("class",row,jtag.getStrClass());
1537                }
1538                
1539            }
1540            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1541        }
1542        
1543        private void doGetCPPCFXTags() throws PageException {
1544            Map map = config.getCFXTagPool().getClasses();
1545            railo.runtime.type.Query qry=new QueryImpl(new String[]{"displayname","sourcename","readonly","procedure","name","isvalid","serverlibrary","keepalive"},0,"query");
1546            Iterator it = map.keySet().iterator();
1547            
1548            int row=0;
1549            while(it.hasNext()) {
1550                CFXTagClass tag=(CFXTagClass) map.get(it.next());
1551                if(tag instanceof CPPCFXTagClass) {
1552                    row++;
1553                    qry.addRow(1);
1554                    CPPCFXTagClass ctag =(CPPCFXTagClass) tag;
1555                    qry.setAt("displayname",row,tag.getDisplayType());
1556                    qry.setAt("sourcename",row,tag.getSourceName());
1557                    qry.setAt("readonly",row,Caster.toBoolean(tag.isReadOnly()));
1558                    qry.setAt("isvalid",row,Caster.toBoolean(tag.isValid()));
1559                    qry.setAt("name",row,ctag.getName());
1560                    qry.setAt("procedure",row,ctag.getProcedure());
1561                    qry.setAt("serverlibrary",row,ctag.getServerLibrary());
1562                    qry.setAt("keepalive",row,Caster.toBoolean(ctag.getKeepAlive()));
1563                }
1564                
1565            }
1566            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1567        }
1568        
1569        /**
1570         * @throws PageException
1571         * 
1572         */
1573        private void doGetCFXTags() throws PageException {
1574            Map map = config.getCFXTagPool().getClasses();
1575            railo.runtime.type.Query qry=new QueryImpl(new String[]{"displayname","sourcename","readonly","isvalid","name","procedure_class","keep_alive"},map.size(),"query");
1576            Iterator it = map.keySet().iterator();
1577            
1578            int row=0;
1579            while(it.hasNext()) {
1580                row++;
1581                CFXTagClass tag=(CFXTagClass) map.get(it.next());
1582                
1583                qry.setAt("displayname",row,tag.getDisplayType());
1584                qry.setAt("sourcename",row,tag.getSourceName());
1585                qry.setAt("readonly",row,Caster.toBoolean(tag.isReadOnly()));
1586                qry.setAt("isvalid",row,Caster.toBoolean(tag.isValid()));
1587                
1588                if(tag instanceof CPPCFXTagClass) {
1589                    CPPCFXTagClass ctag =(CPPCFXTagClass) tag;
1590                    qry.setAt("name",row,ctag.getName());
1591                    qry.setAt("procedure_class",row,ctag.getProcedure());
1592                    qry.setAt("keepalive",row,Caster.toBoolean(ctag.getKeepAlive()));
1593                }
1594                else if(tag instanceof JavaCFXTagClass) {
1595                    JavaCFXTagClass jtag =(JavaCFXTagClass) tag;
1596                    qry.setAt("name",row,jtag.getName());
1597                    qry.setAt("procedure_class",row,jtag.getStrClass());
1598                }
1599                
1600            }
1601            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1602        } 
1603        
1604        
1605        /**
1606         * @throws PageException
1607         */
1608        private void doUpdateComponentMapping() throws PageException {
1609            admin.updateComponentMapping(
1610                    getString("virtual",""),
1611                    getString("physical",""),
1612                    getString("archive",""),
1613                    getString("primary","physical"),
1614                    getBool("trusted",false)
1615            );
1616            store();
1617            adminSync.broadcast(attributes, config);
1618        }
1619    
1620        /**
1621         * @throws PageException
1622         * 
1623         */
1624        private void doRemoveComponentMapping() throws PageException {
1625            admin.removeComponentMapping(
1626                    getString("admin",action,"virtual")
1627            );
1628            store();
1629            adminSync.broadcast(attributes, config);
1630        }
1631        
1632        
1633    
1634        /**
1635         * @throws PageException
1636         */
1637        private void doUpdateCustomTag() throws PageException {
1638            admin.updateCustomTag(
1639                    getString("admin",action,"virtual"),
1640                    getString("admin",action,"physical"),
1641                    getString("admin",action,"archive"),
1642                    getString("admin",action,"primary"),
1643                    Caster.toBooleanValue(getString("admin",action,"trusted"))
1644            );
1645            store();
1646            adminSync.broadcast(attributes, config);
1647        }
1648    
1649        /**
1650         * @throws PageException
1651         * 
1652         */
1653        private void doRemoveCustomTag() throws PageException {
1654            admin.removeCustomTag(
1655                    getString("admin",action,"virtual")
1656            );
1657            store();
1658            adminSync.broadcast(attributes, config);
1659        }
1660    
1661        /**
1662         * @throws PageException
1663         * 
1664         */
1665        private void doGetCustomTagMappings() throws PageException {
1666            Mapping[] mappings = config.getCustomTagMappings();
1667            railo.runtime.type.Query qry=new QueryImpl(new String[]{"archive","strarchive","physical","strphysical","virtual","hidden","physicalFirst","readonly","trusted"},mappings.length,"query");
1668            
1669            
1670            for(int i=0;i<mappings.length;i++) {
1671                Mapping m=mappings[i];
1672                int row=i+1;
1673                qry.setAt("archive",row,m.getArchive());
1674                qry.setAt("strarchive",row,m.getStrArchive());
1675                qry.setAt("physical",row,m.getPhysical());
1676                qry.setAt("strphysical",row,m.getStrPhysical());
1677                qry.setAt("virtual",row,m.getVirtual());
1678                qry.setAt("hidden",row,Caster.toBoolean(m.isHidden()));
1679                qry.setAt("physicalFirst",row,Caster.toBoolean(m.isPhysicalFirst()));
1680                qry.setAt("readonly",row,Caster.toBoolean(m.isReadonly()));
1681                qry.setAt("trusted",row,Caster.toBoolean(m.isTrusted()));
1682            }
1683            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1684        }
1685        
1686        private void doGetComponentMappings() throws PageException {
1687            Mapping[] mappings = config.getComponentMappings();
1688            railo.runtime.type.Query qry=new QueryImpl(new String[]{"archive","strarchive","physical","strphysical","virtual","hidden","physicalFirst","readonly","trusted"},mappings.length,"query");
1689            
1690            
1691            for(int i=0;i<mappings.length;i++) {
1692                Mapping m=mappings[i];
1693                int row=i+1;
1694                qry.setAt("archive",row,m.getArchive());
1695                qry.setAt("strarchive",row,m.getStrArchive());
1696                qry.setAt("physical",row,m.getPhysical());
1697                qry.setAt("strphysical",row,m.getStrPhysical());
1698                qry.setAt("virtual",row,m.getVirtual());
1699                qry.setAt("hidden",row,Caster.toBoolean(m.isHidden()));
1700                qry.setAt("physicalFirst",row,Caster.toBoolean(m.isPhysicalFirst()));
1701                qry.setAt("readonly",row,Caster.toBoolean(m.isReadonly()));
1702                qry.setAt("trusted",row,Caster.toBoolean(m.isTrusted()));
1703            }
1704            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1705        }
1706        
1707    
1708        /**
1709         * @throws PageException
1710         * 
1711         */
1712        private void doRemoveMapping() throws PageException {
1713            admin.removeMapping(
1714                    getString("admin",action,"virtual")
1715            );
1716            store();
1717            adminSync.broadcast(attributes, config);
1718        }
1719    
1720        /**
1721         * @throws PageException
1722         * 
1723         */
1724        private void doUpdateMapping() throws PageException {
1725            admin.updateMapping(
1726                    getString("admin",action,"virtual"),
1727                    getString("admin",action,"physical"),
1728                    getString("admin",action,"archive"),
1729                    getString("admin",action,"primary"),
1730                    Caster.toBooleanValue(getString("admin",action,"trusted")),
1731                    Caster.toBooleanValue(getString("toplevel","true"))
1732            );
1733            store();
1734            adminSync.broadcast(attributes, config);
1735        }
1736    
1737        /**
1738         * @throws PageException
1739         * 
1740         */
1741        private void doGetMapping() throws PageException {
1742            
1743            
1744            Mapping[] mappings = config.getMappings();
1745            Struct sct=new StructImpl();
1746            String virtual=getString("admin",action,"virtual");
1747            
1748            for(int i=0;i<mappings.length;i++) {
1749                Mapping m=mappings[i];
1750                if(!m.getVirtual().equals(virtual)) continue;
1751                
1752                sct.set("archive",m.getArchive());
1753                sct.set("strarchive",m.getStrArchive());
1754                sct.set("physical",m.getPhysical());
1755                sct.set("strphysical",m.getStrPhysical());
1756                sct.set("virtual",m.getVirtual());
1757                sct.set("hidden",Caster.toBoolean(m.isHidden()));
1758                sct.set("physicalFirst",Caster.toBoolean(m.isPhysicalFirst()));
1759                sct.set("readonly",Caster.toBoolean(m.isReadonly()));
1760                sct.set("trusted",Caster.toBoolean(m.isTrusted()));
1761                sct.set("toplevel",Caster.toBoolean(m.isTopLevel()));
1762    
1763                pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
1764                return;
1765            }
1766            throw new ApplicationException("there is no mapping with virtual ["+virtual+"]");
1767        }
1768        
1769    
1770        private void doGetExtensionProviders() throws PageException {
1771            ExtensionProvider[] providers = config.getExtensionProviders();
1772            railo.runtime.type.Query qry=new QueryImpl(new String[]{"url","isReadOnly"},providers.length,"query");
1773            
1774            ExtensionProvider provider;
1775            for(int i=0;i<providers.length;i++) {
1776                    provider=providers[i];
1777                int row=i+1;
1778                //qry.setAt("name",row,provider.getName());
1779                qry.setAt("url",row,provider.getUrlAsString());
1780                qry.setAt("isReadOnly",row,Caster.toBoolean(provider.isReadOnly()));
1781                //qry.setAt("cacheTimeout",row,Caster.toDouble(provider.getCacheTimeout()/1000));
1782            }
1783            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1784        }
1785    
1786        private void doGetExtensionInfo() throws PageException {
1787            Resource ed = config.getExtensionDirectory();
1788            Struct sct=new StructImpl();
1789            sct.set("directory", ed.getPath());
1790            sct.set("enabled", Caster.toBoolean(config.isExtensionEnabled()));
1791            
1792            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
1793        }
1794        
1795        
1796        
1797        private void doGetExtensions() throws PageException {
1798            Extension[] extensions = config.getExtensions();
1799            railo.runtime.type.Query qry=new QueryImpl(new String[]{
1800                            "type","provider","id","config","version","category","description","image","label","name",
1801                            "author","codename","video","support","documentation","forum","mailinglist","network","created"},0,"query");
1802            
1803            String provider=getString("provider",null);
1804            String id=getString("id",null);
1805            Extension extension;
1806            String extProvider,extId;
1807            int row=0;
1808            for(int i=0;i<extensions.length;i++) {
1809                    extension=extensions[i];
1810                    if(!extension.getType().equalsIgnoreCase("all") && toType(extension.getType(), false)!=type)
1811                            continue;
1812    
1813                    extProvider=extension.getProvider();
1814                    extId=extension.getId();
1815                    if(provider!=null && !provider.equalsIgnoreCase(extProvider)) continue;
1816                    if(id!=null && !id.equalsIgnoreCase(extId)) continue;
1817    
1818                qry.addRow();
1819                    row++;
1820                qry.setAt("provider",row,extProvider);
1821                qry.setAt("id",row,extId);
1822                qry.setAt("config",row,extension.getConfig(pageContext));
1823                qry.setAt("version",row,extension.getVersion());
1824                
1825                qry.setAt("category",row,extension.getCategory());
1826                qry.setAt("description",row,extension.getDescription());
1827                qry.setAt("image",row,extension.getImage());
1828                qry.setAt("label",row,extension.getLabel());
1829                qry.setAt("name",row,extension.getName());
1830    
1831                qry.setAt("author",row,extension.getAuthor());
1832                qry.setAt("codename",row,extension.getCodename());
1833                qry.setAt("video",row,extension.getVideo());
1834                qry.setAt("support",row,extension.getSupport());
1835                qry.setAt("documentation",row,extension.getDocumentation());
1836                qry.setAt("forum",row,extension.getForum());
1837                qry.setAt("mailinglist",row,extension.getMailinglist());
1838                qry.setAt("network",row,extension.getNetwork());
1839                qry.setAt("created",row,extension.getCreated());
1840                qry.setAt("type",row,extension.getType());
1841                
1842            }
1843            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1844        }
1845        
1846        
1847        
1848        
1849    private void doGetMappings() throws PageException {
1850            
1851    
1852            Mapping[] mappings = config.getMappings();
1853            railo.runtime.type.Query qry=new QueryImpl(new String[]{"archive","strarchive","physical","strphysical","virtual","hidden","physicalFirst","readonly","trusted","toplevel"},mappings.length,"query");
1854            
1855            
1856            for(int i=0;i<mappings.length;i++) {
1857                Mapping m=mappings[i];
1858                int row=i+1;
1859                qry.setAt("archive",row,m.getArchive());
1860                qry.setAt("strarchive",row,m.getStrArchive());
1861                qry.setAt("physical",row,m.getPhysical());
1862                qry.setAt("strphysical",row,m.getStrPhysical());
1863                qry.setAt("virtual",row,m.getVirtual());
1864                qry.setAt("hidden",row,Caster.toBoolean(m.isHidden()));
1865                qry.setAt("physicalFirst",row,Caster.toBoolean(m.isPhysicalFirst()));
1866                qry.setAt("readonly",row,Caster.toBoolean(m.isReadonly()));
1867                qry.setAt("trusted",row,Caster.toBoolean(m.isTrusted()));
1868                qry.setAt("toplevel",row,Caster.toBoolean(m.isTopLevel()));
1869            }
1870            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
1871        }
1872    
1873            private void doGetResourceProviders() throws PageException {
1874            
1875                    pageContext.setVariable(getString("admin",action,"returnVariable"),admin.getResourceProviders());
1876        }
1877            
1878            private void doGetClusterClass() throws PageException {
1879                    pageContext.setVariable(getString("admin",action,"returnVariable"),config.getClusterClass().getName());
1880        }
1881    
1882        
1883        private void doUpdateClusterClass() throws PageException {
1884            admin.updateClusterClass(getString("admin",action,"class"));
1885            store();
1886        }
1887        
1888            private void doUpdateAdminSyncClass() throws PageException {
1889                    admin.updateAdminSyncClass(getString("admin",action,"class"));
1890            store();
1891            }
1892    
1893            private void doGetAdminSyncClass() throws PageException {
1894                    pageContext.setVariable(getString("admin",action,"returnVariable"),config.getAdminSyncClass().getName());
1895            }
1896    
1897            private void doUpdateVideoExecuterClass() throws PageException {
1898                    admin.updateVideoExecuterClass(getString("admin",action,"class"));
1899            store();
1900            }
1901    
1902            private void doGetVideoExecuterClass() throws PageException {
1903                    pageContext.setVariable(getString("admin",action,"returnVariable"),config.getVideoExecuterClass().getName());
1904            }
1905        
1906            
1907    
1908        /**
1909         * @throws PageException
1910         * 
1911         */
1912        private void doRemoveMailServer() throws PageException {
1913            admin.removeMailServer(getString("admin",action,"hostname"));
1914            store();
1915            adminSync.broadcast(attributes, config);
1916        }
1917    
1918        /**
1919         * @throws PageException
1920         * 
1921         */
1922        private void doUpdateMailServer() throws PageException {
1923            
1924            admin.updateMailServer(
1925                    getString("admin",action,"hostname"),
1926                    getString("admin",action,"dbusername"),
1927                    getString("admin",action,"dbpassword"),
1928                    Caster.toIntValue(getString("admin",action,"port")),
1929                    getBoolV("tls", false),
1930                    getBoolV("ssl", false)
1931            );
1932            store();
1933            adminSync.broadcast(attributes, config);
1934        }
1935    
1936        /**
1937         * @throws PageException
1938         * 
1939         */
1940        private void doUpdateMailSetting() throws PageException {
1941            admin.setMailLog(getString("admin",action,"logfile"),getString("loglevel","ERROR"));
1942            
1943            //print.ln("----------------------------------");
1944            admin.setMailSpoolEnable(getBoolObject("admin",action,"spoolenable"));
1945            // spool intervall
1946            String str=getString("admin",action,"spoolinterval");
1947            Integer i=null;
1948            if(!StringUtil.isEmpty(str))i=Caster.toInteger(str);
1949            admin.setMailSpoolInterval(i);
1950            
1951         // timeout
1952            str=getString("admin",action,"timeout");
1953            i=null;
1954            if(!StringUtil.isEmpty(str))i=Caster.toInteger(str);
1955            admin.setMailTimeout(i);
1956                    
1957            admin.setMailDefaultCharset(getString("admin", action, "defaultencoding"));
1958            store();
1959            adminSync.broadcast(attributes, config);
1960        }
1961    
1962        
1963    
1964        private void listPatches() throws PageException  {
1965            try {
1966                            pageContext.setVariable(getString("admin",action,"returnVariable"),Caster.toArray(config.getInstalledPatches()));
1967                    } catch (Exception e) {
1968                            throw Caster.toPageException(e);
1969                    }
1970        }
1971    
1972        private void needNewJars() throws PageException  {
1973            boolean needNewJars = JarLoader.changed(pageContext.getConfig(), UPDATE_JARS);
1974                    
1975            try {
1976                            pageContext.setVariable(getString("admin",action,"returnVariable"),needNewJars);
1977                    }
1978            catch (Exception e) {
1979                            throw Caster.toPageException(e);
1980                    }
1981        }
1982    
1983        private void doUpdateJars() throws PageException  {
1984            try {
1985                            JarLoader.download(pageContext, UPDATE_JARS);
1986                    } catch (IOException e) {
1987                            throw Caster.toPageException(e);
1988                    }
1989            
1990        }
1991        
1992        
1993        
1994        private void doGetMailServers() throws PageException {
1995            
1996            
1997    
1998            Server[] servers = config.getMailServers();
1999            railo.runtime.type.Query qry=new QueryImpl(new String[]{"hostname","password","username","port","authentication","readonly","tls","ssl"},servers.length,"query");
2000            
2001            
2002            for(int i=0;i<servers.length;i++) {
2003                Server s= servers[i];
2004                int row=i+1;
2005                qry.setAt("hostname",row,s.getHostName());
2006                qry.setAt("password",row,s.isReadOnly()?"":s.getPassword());
2007                qry.setAt("username",row,s.isReadOnly()?"":s.getUsername());
2008                qry.setAt("port",row,Caster.toInteger(s.getPort()));
2009                qry.setAt("readonly",row,Caster.toBoolean(s.isReadOnly()));
2010                qry.setAt("authentication",row,Caster.toBoolean(s.hasAuthentication()));
2011                if(s instanceof ServerImpl) {
2012                    ServerImpl si = (ServerImpl)s;
2013                        qry.setAt("ssl",row,Caster.toBoolean(si.isSSL()));
2014                        qry.setAt("tls",row,Caster.toBoolean(si.isTLS()));
2015                }
2016            }
2017            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2018        }
2019        
2020        private void doGetRunningThreads() throws PageException {
2021            railo.runtime.type.Query qry=new QueryImpl(new String[]{"Id","Start","Timeout","ThreadType","StackTrace","TagContext",
2022                            "Label","RootPath","ConfigFile","URL"},0,"query");
2023            
2024            
2025            if(type==TYPE_WEB){
2026                    fillGetRunningThreads(qry,pageContext.getConfig());
2027            }
2028            else {
2029                    ConfigServer cs = pageContext.getConfig().getConfigServer(password);
2030                    ConfigWeb[] webs = cs.getConfigWebs();
2031                    for(int i=0;i<webs.length;i++){
2032                            fillGetRunningThreads(qry,webs[i]);
2033                    }
2034            }
2035            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2036        }
2037        
2038        private static void fillGetRunningThreads(railo.runtime.type.Query qry, ConfigWeb configWeb) throws PageException {
2039            CFMLFactoryImpl factory = ((CFMLFactoryImpl)configWeb.getFactory());
2040            Struct pcs =factory.getRunningPageContextes();
2041            Iterator it = pcs.keyIterator();
2042            PageContextImpl pc;
2043            Collection.Key key;
2044            int row=0;
2045            while(it.hasNext()) {
2046                    key=KeyImpl.toKey(it.next(),null);
2047                pc=(PageContextImpl) pcs.get(key,null);
2048                qry.addRow();
2049                row++;
2050                StackTraceElement[] st = pc.getThread().getStackTrace();
2051                configWeb.getConfigDir();
2052                configWeb.getId();
2053                configWeb.getConfigDir();
2054                qry.setAt("Id",row,new Double(pc.getId()));
2055                qry.setAt("Start",row,new DateTimeImpl(pc.getStartTime(),false));
2056                qry.setAt("Timeout",row,new Double(pc.getRequestTimeout()/1000));
2057                qry.setAt("ThreadType",row,pc.getParentPageContext()==null?"main":"child");
2058                qry.setAt("StackTrace",row,toString(st));
2059                qry.setAt("TagContext",row,PageExceptionImpl.getTagContext(pc.getConfig(), st));
2060                
2061                qry.setAt("label",row,factory.getLabel());
2062                qry.setAt("RootPath",row,((ConfigWebImpl)configWeb).getServletContext().getRealPath("/"));
2063                qry.setAt("ConfigFile",row,configWeb.getConfigFile().getAbsolutePath());
2064                if(factory.getURL()!=null)qry.setAt("url",row,factory.getURL().toExternalForm());
2065                
2066            }
2067            
2068            }
2069    
2070            private static String toString(StackTraceElement[] traces) {
2071            StackTraceElement trace;
2072            StringBuffer sb=new StringBuffer();
2073            for(int i=0;i<traces.length;i++){
2074                trace=traces[i];
2075                sb.append("\tat "+trace+":"+trace.getLineNumber()+"\n");
2076            }
2077            return sb.toString();
2078        }
2079        
2080    
2081        /**
2082         * @throws PageException
2083         * 
2084         */
2085        private void doGetMailSetting() throws PageException {
2086            Struct sct=new StructImpl();
2087            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
2088            
2089            LogAndSource ls=config.getMailLogger();
2090            railo.commons.io.log.Log log=ls.getLog();
2091            String logFile="";
2092            //String logLevel="";
2093            if(log instanceof LogResource)logFile=((LogResource)log).getResource().toString();
2094            String logLevel=LogUtil.toStringType(log.getLogLevel(),"ERROR");
2095            sct.set("strlogfile",ls.getSource());
2096            sct.set("logfile",logFile);
2097            sct.set("loglevel",logLevel);
2098            
2099            sct.set("spoolEnable",Caster.toBoolean(config.isMailSpoolEnable()));
2100            sct.set("spoolInterval",Caster.toInteger(config.getMailSpoolInterval()));
2101            sct.set("timeout",Caster.toInteger(config.getMailTimeout()));
2102                    sct.set("defaultencoding", config.getMailDefaultEncoding());
2103            
2104        }
2105    
2106        /**
2107         * @throws PageException
2108         * 
2109         */
2110        private void doGetTLDs() throws PageException {
2111            railo.runtime.type.Query qry=new QueryImpl(
2112                            new String[]{"displayname","namespace","namespaceseparator","shortname","type","description","uri","elclass","source"},
2113                            new String[]{"varchar","varchar","varchar","varchar","varchar","varchar","varchar","varchar","varchar"},
2114                            0,"tlds");
2115           
2116    
2117            TagLib[] libs = config.getTLDs();
2118            for(int i=0;i<libs.length;i++) {
2119                    qry.addRow();
2120                    qry.setAt("displayname", i+1, libs[i].getDisplayName());
2121                    qry.setAt("namespace", i+1, libs[i].getNameSpace());
2122                    qry.setAt("namespaceseparator", i+1, libs[i].getNameSpaceSeparator());
2123                    qry.setAt("shortname", i+1, libs[i].getShortName());
2124                    qry.setAt("type", i+1, libs[i].getType());
2125                    qry.setAt("description", i+1, libs[i].getDescription());
2126                    qry.setAt("uri", i+1, Caster.toString(libs[i].getUri()));
2127                    qry.setAt("elclass", i+1, libs[i].getELClass());
2128                    qry.setAt("source", i+1, StringUtil.emptyIfNull(libs[i].getSource()));
2129            }
2130            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2131        }
2132    
2133        /**
2134         * @throws PageException
2135         * 
2136         */
2137        private void doGetFLDs() throws PageException {
2138            railo.runtime.type.Query qry=new QueryImpl(
2139                            new String[]{"displayname","namespace","namespaceseparator","shortname","description","uri","source"},
2140                            new String[]{"varchar","varchar","varchar","varchar","varchar","varchar","varchar"},
2141                            0,"tlds");
2142           
2143    
2144            FunctionLib[] libs = config.getFLDs();
2145            for(int i=0;i<libs.length;i++) {
2146                    qry.addRow();
2147                    qry.setAt("displayname", i+1, libs[i].getDisplayName());
2148                    qry.setAt("namespace", i+1, "");// TODO support for namespace
2149                    qry.setAt("namespaceseparator", i+1, "");
2150                    qry.setAt("shortname", i+1, libs[i].getShortName());
2151                    qry.setAt("description", i+1, libs[i].getDescription());
2152                    qry.setAt("uri", i+1, Caster.toString(libs[i].getUri()));
2153                    qry.setAt("source", i+1, StringUtil.emptyIfNull(libs[i].getSource()));
2154            }
2155            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2156        }
2157    
2158        private void doGetRemoteClientUsage() throws PageException {
2159            railo.runtime.type.Query qry=new QueryImpl(
2160                            new String[]{"code","displayname"},
2161                            new String[]{"varchar","varchar"},
2162                            0,"usage");
2163            Struct usages = config.getRemoteClientUsage();
2164            Key[] keys = usages.keys();
2165            for(int i=0;i<keys.length;i++) {
2166                    qry.addRow();
2167                    qry.setAt("code", i+1, keys[i].getString());
2168                    qry.setAt("displayname", i+1, usages.get(keys[i]));
2169                    //qry.setAt("description", i+1, usages[i].getDescription());
2170            }
2171            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2172        }
2173    
2174        private void doHasRemoteClientUsage() throws PageException {
2175            
2176            Struct usages = config.getRemoteClientUsage();
2177            pageContext.setVariable(getString("admin",action,"returnVariable"),usages.isEmpty()?Boolean.FALSE:Boolean.TRUE);
2178        }
2179        
2180        
2181        
2182        private void doGetJars() throws PageException {
2183            Resource lib = config.getConfigDir().getRealResource("lib");
2184                    railo.runtime.type.Query qry=new QueryImpl(new String[]{"name","source"},new String[]{"varchar","varchar"},0,"jars");
2185           
2186                    if(lib.isDirectory()){
2187                            Resource[] children = lib.listResources(new ExtensionResourceFilter(new String[]{".jar",".zip"},false,true));
2188                            for(int i=0;i<children.length;i++){
2189                                    qry.addRow();
2190                                    qry.setAt("name", i+1, children[i].getName());
2191                                    qry.setAt("source", i+1, children[i].getAbsolutePath());
2192                            }
2193                    }
2194            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2195        }
2196    
2197        /**
2198         * @throws PageException
2199         * 
2200         */
2201        private void doUpdateDatasource() throws PageException {
2202            int allow=
2203            (getBoolV("allowed_select",false)?DataSource.ALLOW_SELECT:0)+
2204            (getBoolV("allowed_insert",false)?DataSource.ALLOW_INSERT:0)+
2205            (getBoolV("allowed_update",false)?DataSource.ALLOW_UPDATE:0)+
2206            (getBoolV("allowed_delete",false)?DataSource.ALLOW_DELETE:0)+
2207            (getBoolV("allowed_alter",false)?DataSource.ALLOW_ALTER:0)+
2208            (getBoolV("allowed_drop",false)?DataSource.ALLOW_DROP:0)+
2209            (getBoolV("allowed_revoke",false)?DataSource.ALLOW_REVOKE:0)+
2210            (getBoolV("allowed_grant",false)?DataSource.ALLOW_GRANT:0)+
2211            (getBoolV("allowed_create",false)?DataSource.ALLOW_CREATE:0);
2212            if(allow==0)allow=DataSource.ALLOW_ALL;
2213            String classname=getString("admin",action,"classname");
2214            /*Class clazz=null;
2215            try {
2216                    clazz = ClassUtil.loadClass(config.getClassLoader(),classname);//Class.orName(classname);
2217            } 
2218            catch (ClassException e) {
2219                    throw new DatabaseException("can't find class ["+classname+"] for jdbc driver, check if driver (jar file) is inside lib folder",e.getMessage(),null,null,null);
2220            }*/
2221            
2222            String dsn=getString("admin",action,"dsn");
2223            String name=getString("admin",action,"name");
2224            String newName=getString("admin",action,"newName");
2225            String username=getString("admin",action,"dbusername");
2226            String password=getString("admin",action,"dbpassword");
2227            String host=getString("host","");
2228            String timezone=getString("timezone","");
2229            String database=getString("database","");
2230            int port=getInt("port",-1);
2231            int connLimit=getInt("connectionLimit",-1);
2232            int connTimeout=getInt("connectionTimeout",-1);
2233            long metaCacheTimeout=getLong("metaCacheTimeout",60000);
2234            boolean blob=getBoolV("blob",false);
2235            boolean clob=getBoolV("clob",false);
2236            boolean validate=getBoolV("validate",false);
2237            boolean storage=getBoolV("storage",false);
2238            boolean verify=getBoolV("verify",true);
2239            Struct custom=getStruct("custom",new StructImpl());
2240            
2241            config.getDatasourceConnectionPool().remove(name);
2242            //config.getConnectionPool().remove(name);
2243            DataSource ds=null;
2244                    try {
2245                            ds = new DataSourceImpl(name,classname,host,dsn,database,port,username,password,connLimit,connTimeout,metaCacheTimeout,blob,clob,allow,custom,false,validate,storage,null);
2246                    } catch (ClassException e) {
2247                            throw new DatabaseException("can't find class ["+classname+"] for jdbc driver, check if driver (jar file) is inside lib folder",e.getMessage(),null,null,null);
2248                    }
2249            
2250            if(verify)_doVerifyDatasource(classname,ds.getDsnTranslated(),username,password);
2251            //print.out("limit:"+connLimit);
2252            admin.updateDataSource(
2253                            name,
2254                            newName,
2255                    classname,
2256                    dsn,
2257                    username,
2258                    password,
2259                    host,
2260                    database,
2261                    port,
2262                    connLimit,
2263                    connTimeout,
2264                    metaCacheTimeout,
2265                    blob,
2266                    clob,
2267                    allow,
2268                    validate,
2269                    storage,
2270                    timezone,
2271                    custom
2272                    
2273            );
2274            store();
2275            adminSync.broadcast(attributes, config);
2276        }
2277    
2278        private void doUpdateCacheConnection() throws PageException {
2279            admin.updateCacheConnection(
2280                            getString("admin",action,"name"),
2281                    getString("admin",action,"class"),
2282                    toCacheConstant("default"),
2283                    getStruct("admin", action, "custom"),
2284                    getBoolV("readOnly", false),
2285                    getBoolV("storage", false)
2286                    
2287            );
2288            store();
2289            adminSync.broadcast(attributes, config);
2290        }
2291    
2292        private void doUpdateGatewayEntry() throws PageException {
2293            String strStartupMode=getString("admin",action,"startupMode");
2294            int startup=GatewayEntryImpl.toStartup(strStartupMode,-1);
2295            if(startup==-1)
2296                    throw new ApplicationException("invalid startup mode ["+strStartupMode+"], valid values are [automatic,manual,disabled]");
2297            //print.out("doUpdateGatewayEntry");
2298            admin.updateGatewayEntry(
2299                            getString("admin",action,"id"),
2300                    getString("admin",action,"class"),
2301                            getString("admin",action,"cfcPath"),
2302                            getString("admin",action,"listenerCfcPath"),
2303                    startup,
2304                    getStruct("admin", action, "custom"),
2305                    getBoolV("readOnly", false)
2306                    
2307            );
2308            store();
2309            adminSync.broadcast(attributes, config);
2310        }
2311        
2312        private int toCacheConstant(String name) throws ApplicationException {
2313                    String def = getString(name, null);
2314                    if(StringUtil.isEmpty(def)) return ConfigImpl.CACHE_DEFAULT_NONE;
2315                    def=def.trim().toLowerCase();
2316    
2317                    if(def.equals("object")) return ConfigImpl.CACHE_DEFAULT_OBJECT;
2318                    if(def.equals("template")) return ConfigImpl.CACHE_DEFAULT_TEMPLATE;
2319                    if(def.equals("query")) return ConfigImpl.CACHE_DEFAULT_QUERY;
2320                    if(def.equals("resource")) return ConfigImpl.CACHE_DEFAULT_RESOURCE;
2321            
2322                    throw new ApplicationException("invalid default type ["+def+"], valid default types are [object,template]");
2323            }
2324    
2325            private void doUpdateCacheDefaultConnection() throws PageException {
2326                    admin.updateCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_OBJECT,getString("admin",action,"object"));
2327                    admin.updateCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_TEMPLATE,getString("admin",action,"template"));
2328                    admin.updateCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_QUERY,getString("admin",action,"query"));
2329                    admin.updateCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_RESOURCE,getString("admin",action,"resource"));
2330            store();
2331            adminSync.broadcast(attributes, config);
2332        }
2333    
2334            private void doRemoveCacheDefaultConnection() throws PageException {
2335                    admin.removeCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_OBJECT);
2336                    admin.removeCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_TEMPLATE);
2337                    admin.removeCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_QUERY);
2338                    admin.removeCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_RESOURCE);
2339            store();
2340            adminSync.broadcast(attributes, config);
2341        }
2342    
2343        private void doRemoveResourceProvider() throws PageException {
2344            String classname=getString("admin",action,"class");
2345            
2346            Class clazz=null;
2347                    try {
2348                            clazz = ClassUtil.loadClass(config.getClassLoader(),classname);
2349                    } catch (ClassException e) {
2350                            throw Caster.toPageException(e);
2351                    }
2352            
2353            admin.removeResourceProvider(clazz);
2354            
2355            store();
2356            adminSync.broadcast(attributes, config);
2357        }
2358        
2359        
2360        private void doUpdateResourceProvider() throws PageException {
2361            String classname=getString("admin",action,"class");
2362            
2363            Class clazz=null;
2364                    try {
2365                            clazz = ClassUtil.loadClass(config.getClassLoader(),classname);
2366                    } catch (ClassException e) {
2367                            throw Caster.toPageException(e);
2368                    }
2369            String scheme=getString("admin",action,"scheme");
2370            
2371            Struct sctArguments = getStruct("arguments", null);
2372            if(sctArguments!=null) {
2373                    
2374                    admin.updateResourceProvider(scheme,clazz,sctArguments);
2375            }
2376            else {
2377                    String strArguments=getString("admin",action,"arguments");
2378                    admin.updateResourceProvider(scheme,clazz,strArguments);
2379            }
2380            
2381            
2382            
2383            //admin.updateResourceProvider(scheme,clazz,arguments);
2384            store();
2385            adminSync.broadcast(attributes, config);
2386        }
2387        
2388        private void doUpdateDefaultResourceProvider() throws PageException {
2389            String classname=getString("admin",action,"class");
2390            Class clazz=null;
2391                    try {
2392                            clazz = ClassUtil.loadClass(config.getClassLoader(),classname);
2393                    } catch (ClassException e) {
2394                            throw Caster.toPageException(e);
2395                    }
2396            String arguments=getString("admin",action,"arguments");
2397            
2398            admin.updateDefaultResourceProvider(clazz,arguments);
2399            store();
2400            adminSync.broadcast(attributes, config);
2401        }
2402        
2403        
2404    
2405        private void doVerifyMailServer() throws PageException {
2406            _doVerifyMailServer(
2407                        getString("admin",action,"hostname"),
2408                        getInt("admin",action,"port"),
2409                        getString("admin",action,"mailusername"),
2410                        getString("admin",action,"mailpassword")
2411            );
2412        }
2413        
2414        private void _doVerifyMailServer(String host, int port, String user, String pass) throws PageException {
2415               try {
2416                SMTPVerifier.verify(host,user,pass,port);
2417            } catch (SMTPException e) {
2418                throw Caster.toPageException(e);
2419            }
2420        }
2421    
2422        /**
2423         * @throws PageException
2424         * 
2425         */
2426        private void doVerifyDatasource() throws PageException {
2427            String classname=(String) attributes.get("classname",null);
2428            String dsn=(String) attributes.get("dsn",null);
2429            if(classname!=null && dsn!=null) {
2430                _doVerifyDatasource(classname,dsn,
2431                        getString("admin",action,"dbusername"),
2432                        getString("admin",action,"dbpassword"));
2433            }
2434            else {
2435                _doVerifyDatasource(
2436                        getString("admin",action,"name"),
2437                        getString("admin",action,"dbusername"),
2438                        getString("admin",action,"dbpassword"));
2439            }
2440        }
2441        
2442        private void doVerifyRemoteClient() throws PageException {
2443            // SNSN
2444            /*SerialNumber sn = config.getSerialNumber();
2445            if(sn.getVersion()==SerialNumber.VERSION_COMMUNITY)
2446                throw new SecurityException("can not verify remote client with "+sn.getStringVersion()+" version of railo");
2447                */
2448            ProxyData pd=null;
2449            String proxyServer=getString("proxyServer",null);
2450            if(!StringUtil.isEmpty(proxyServer)) {
2451                    String proxyUsername=getString("proxyUsername",null);
2452                    String proxyPassword=getString("proxyPassword",null);
2453                    int proxyPort = getInt("proxyPort",-1);
2454                    pd=new ProxyDataImpl();
2455                            pd.setServer(proxyServer);
2456                            if(!StringUtil.isEmpty(proxyUsername))pd.setUsername(proxyUsername);
2457                            if(!StringUtil.isEmpty(proxyPassword))pd.setPassword(proxyPassword);
2458                            if(proxyPort!=-1)pd.setPort(proxyPort);
2459            }       
2460            RemoteClient client = new RemoteClientImpl(
2461                            getString("admin",action,"label"),
2462                            type==TYPE_WEB?"web":"server",
2463                            getString("admin",action,"url"),
2464                            getString("serverUsername",null),
2465                            getString("serverPassword",null),
2466                            getString("admin",action,"adminPassword"),
2467                            pd,
2468                            getString("admin",action,"securityKey"),
2469                            getString("admin",action,"usage")
2470                            
2471            );
2472            
2473            Struct attrColl=new StructImpl();
2474            attrColl.setEL("action", "connect");
2475            try {
2476                            new RemoteClientTask(null,client,attrColl,getCallerId(),"synchronisation").execute(config);
2477                    } 
2478            catch (Throwable t) {
2479                            throw Caster.toPageException(t);
2480                    }
2481        }
2482        
2483    
2484        private void _doVerifyDatasource(String classname, String dsn, String username, String password) throws PageException {
2485            try {
2486                    Class clazz=null;
2487                    try {
2488                            clazz=Class.forName(classname);
2489                            } catch (ClassNotFoundException e) {
2490                                    e.printStackTrace();
2491                            }
2492                            if(clazz==null)clazz=ClassUtil.loadClass(config.getClassLoader(),classname);
2493                _doVerifyDatasource(clazz, dsn, username, password);
2494            } 
2495            catch (ClassException e) {
2496                throw Caster.toPageException(e);
2497            }
2498        }
2499    
2500        private void _doVerifyDatasource(Class clazz, String dsn, String username, String password) throws PageException {
2501                if(!Reflector.isInstaneOf(clazz,Driver.class))
2502                    throw new DatabaseException("class ["+clazz.getName()+"] is not a JDBC Driver","class must implement interface [java.sql.Driver]",null,null,null);
2503            getConnection(dsn, username, password);
2504        }
2505    
2506        private void _doVerifyDatasource(String name, String username, String password) throws PageException {
2507            DataSourceManager manager = pageContext.getDataSourceManager();
2508            manager.releaseConnection(pageContext,manager.getConnection(pageContext,name, username, password));
2509            //config.getConnection(name, username, password);
2510        }
2511        
2512        
2513        private Connection getConnection(String dsn, String user, String pass) throws DatabaseException  {
2514            Connection conn=null;
2515            try {
2516                    conn = DBUtil.getConnection(dsn, user, pass);
2517                conn.setAutoCommit(true);
2518            } 
2519            catch (SQLException e) {
2520                throw new DatabaseException(e,null);
2521            }
2522            return conn;
2523        }
2524        
2525        
2526    
2527        /**
2528         * @throws PageException
2529         * 
2530         */
2531        private void doUpdatePSQ() throws PageException {
2532            admin.updatePSQ(getBoolObject("admin",action,"psq"));
2533            store();
2534            adminSync.broadcast(attributes, config);
2535        }
2536        
2537        private void doReload() throws PageException {
2538            store();
2539        }
2540    
2541        /**
2542         * @throws PageException
2543         * 
2544         */
2545        private void doRemoveDatasource() throws PageException {
2546            admin.removeDataSource(getString("admin",action,"name"));
2547            store();
2548            adminSync.broadcast(attributes, config);
2549        }
2550        
2551        private void doTerminateRunningThread() throws PageException {
2552            int id = getInt("admin", "RemoveRunningThread", "id");
2553            
2554            if(type==TYPE_WEB){
2555                    terminateRunningThread(pageContext.getConfig(),id);
2556            }
2557            else {
2558                    ConfigServer cs = pageContext.getConfig().getConfigServer(password);
2559                    ConfigWeb[] webs = cs.getConfigWebs();
2560                    for(int i=0;i<webs.length;i++){
2561                            if(terminateRunningThread(webs[i],id))break;
2562                    }
2563            }
2564        }
2565        
2566        
2567        
2568        
2569        private static boolean terminateRunningThread(ConfigWeb configWeb,int id) {
2570    
2571            Struct pcs = ((CFMLFactoryImpl)configWeb.getFactory()).getRunningPageContextes();
2572            
2573            Iterator it = pcs.keyIterator();
2574            PageContextImpl pc;
2575            Collection.Key key;
2576            while(it.hasNext()) {
2577                    key=KeyImpl.toKey(it.next(),null);
2578                pc=(PageContextImpl) pcs.get(key,null);
2579                if(pc.getId()==id){
2580                    CFMLFactoryImpl.terminate(pc);
2581                    return true;
2582                }
2583            }
2584            return false;
2585            }
2586    
2587            private void doRemoveRemoteClient() throws PageException {
2588            admin.removeRemoteClient(getString("admin",action,"url"));
2589            store();
2590        }
2591        private void doRemoveSpoolerTask() throws PageException {
2592            config.getSpoolerEngine().remove(getString("admin",action,"id"));
2593        }
2594        private void doRemoveAllSpoolerTask() throws PageException {
2595            ((SpoolerEngineImpl)config.getSpoolerEngine()).removeAll();
2596        }
2597        private void doExecuteSpoolerTask() throws PageException {
2598            PageException pe = config.getSpoolerEngine().execute(getString("admin",action,"id"));
2599                    if(pe!=null) throw pe;
2600        }
2601    
2602        /**
2603         * @throws PageException
2604         * 
2605         */
2606        private void doGetDatasourceSetting() throws PageException {
2607            Struct sct=new StructImpl();
2608            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
2609            sct.set("psq",Caster.toBoolean(config.getPSQL()));
2610        }
2611    
2612        private void doGetORMSetting() throws PageException {
2613            pageContext.setVariable(getString("admin",action,"returnVariable"),config.getORMConfig().toStruct());
2614        }
2615    
2616        private void doGetORMEngine() throws PageException {
2617            pageContext.setVariable(getString("admin",action,"returnVariable"),config.getORMEngineClass().getName());
2618        }
2619        
2620    
2621        private void doUpdateORMSetting() throws SecurityException, PageException {
2622            ORMConfiguration oc = config.getORMConfig();
2623            Struct settings=new StructImpl();
2624            
2625            settings.set(ORMConfiguration.AUTO_GEN_MAP, getBool("admin",action,"autogenmap"));
2626            settings.set(ORMConfiguration.EVENT_HANDLING, getBool("admin",action,"eventHandling"));
2627            settings.set(ORMConfiguration.FLUSH_AT_REQUEST_END, getBool("admin",action,"flushatrequestend"));
2628            settings.set(ORMConfiguration.LOG_SQL, getBool("admin",action,"logSQL"));
2629            settings.set(ORMConfiguration.SAVE_MAPPING, getBool("admin",action,"savemapping"));
2630            settings.set(ORMConfiguration.USE_DB_FOR_MAPPING, getBool("admin",action,"useDBForMapping"));
2631            settings.set(ORMConfiguration.SECONDARY_CACHE_ENABLED, getBool("admin",action,"secondarycacheenabled"));
2632            
2633            settings.set(ORMConfiguration.CATALOG, getString("admin",action,"catalog"));
2634            settings.set(ORMConfiguration.SCHEMA, getString("admin",action,"schema"));
2635            settings.set(ORMConfiguration.SQL_SCRIPT, getString("admin",action,"sqlscript"));
2636            settings.set(ORMConfiguration.CACHE_CONFIG, getString("admin",action,"cacheconfig"));
2637            settings.set(ORMConfiguration.CACHE_PROVIDER, getString("admin",action,"cacheProvider"));
2638            settings.set(ORMConfiguration.ORM_CONFIG, getString("admin",action,"ormConfig"));
2639            
2640            
2641            // dbcreate
2642            String strDbcreate=getString("admin",action,"dbcreate");
2643            String dbcreate="none";
2644            if("none".equals(strDbcreate))                          dbcreate="none";
2645            else if("update".equals(strDbcreate))           dbcreate="update";
2646            else if("dropcreate".equals(strDbcreate))       dbcreate="dropcreate";
2647                    else throw new ApplicationException("invalid dbcreate definition ["+strDbcreate+"], valid dbcreate definitions are [none,update,dropcreate]");
2648            settings.set(ORMConfiguration.DB_CREATE, getString("admin",action,"dbcreate"));
2649            
2650            // cfclocation
2651            String strCfclocation=getString("admin",action,"cfclocation");
2652            Array arrCfclocation = railo.runtime.type.List.listToArray(strCfclocation, ",\n");
2653            Iterator it = arrCfclocation.valueIterator();
2654            String path;
2655            while(it.hasNext()){
2656                    path=(String) it.next();
2657                    ResourceUtil.toResourceExisting(config, path);
2658            }
2659            settings.set(ORMConfiguration.CFC_LOCATION, arrCfclocation);
2660            
2661            admin.updateORMSetting(ORMConfiguration.load(config,null, settings, null, oc));
2662            
2663            
2664            store();
2665            adminSync.broadcast(attributes, config);
2666            }
2667        
2668        private void doResetORMSetting() throws SecurityException, PageException {
2669            ORMConfiguration oc = config.getORMConfig();
2670            
2671            admin.resetORMSetting();
2672            
2673            store();
2674            adminSync.broadcast(attributes, config);
2675            }
2676        
2677        
2678    
2679        private void doUpdatePerformanceSettings() throws SecurityException, PageException {
2680            admin.updateInspectTemplate(getString("admin",action,"inspectTemplate"));
2681            store();
2682            adminSync.broadcast(attributes, config);
2683            }
2684        
2685        private void doGetLogSetting() throws PageException {
2686            String name=getString("admin", "GetLogSetting", "name");
2687            name=name.trim().toLowerCase();
2688            Query qry=_doGetLogSettings();
2689            
2690            int records = qry.getRecordcount();
2691            for(int row=1;row<=records;row++){
2692                    String n = Caster.toString(qry.getAt("name", row, null),null);
2693                    if(!StringUtil.isEmpty(n) && n.trim().equalsIgnoreCase(name)) {
2694                            Struct sct=new StructImpl();
2695                            String returnVariable=getString("admin",action,"returnVariable");
2696                            pageContext.setVariable(returnVariable,sct);
2697    
2698                            sct.setEL(KeyImpl.NAME, qry.getAt(KeyImpl.NAME, row, ""));
2699                            sct.setEL("level", qry.getAt("level", row, ""));
2700                            sct.setEL("virtualpath", qry.getAt("virtualpath", row, ""));
2701                            sct.setEL("class", qry.getAt("class", row, ""));
2702                            sct.setEL("maxFile", qry.getAt("maxFile", row, ""));
2703                            sct.setEL("maxFileSize", qry.getAt("maxFileSize", row, ""));
2704                            sct.setEL(KeyImpl.PATH, qry.getAt(KeyImpl.PATH, row, ""));
2705                            
2706                            return;
2707                    }
2708            }
2709            throw new ApplicationException("invalig log name ["+name+"]");
2710            
2711            }
2712        
2713        private void doGetLogSettings() throws  PageException {
2714            String returnVariable=getString("admin",action,"returnVariable");
2715                    pageContext.setVariable(returnVariable,_doGetLogSettings());
2716        }
2717        
2718        private Query _doGetLogSettings() throws  PageException {
2719            Query qry=new QueryImpl(
2720                                    new String[]{"name","level","path","virtualpath","class","maxFile","maxFileSize"},
2721                                    new String[]{"varchar","varchar","varchar","varchar","varchar","varchar","varchar"},
2722                                    0,railo.runtime.type.List.last("logs", '.'));
2723            int row=0;
2724            
2725            doGetLogSettings(qry,"application",config.getApplicationLogger(),++row);
2726            doGetLogSettings(qry,"scope",config.getScopeLogger(),++row);
2727            doGetLogSettings(qry,"exception",config.getExceptionLogger(),++row);
2728            if(config instanceof ConfigWeb)doGetLogSettings(qry,"gateway",((ConfigWebImpl)config).getGatewayLogger(),++row);
2729            doGetLogSettings(qry,"mail",config.getMailLogger(),++row);
2730            doGetLogSettings(qry,"mapping",config.getMappingLogger(),++row);
2731            doGetLogSettings(qry,"orm",config.getORMLogger(),++row);
2732            doGetLogSettings(qry,"remote-client",config.getRemoteClientLog(),++row);
2733            doGetLogSettings(qry,"request-timeout",config.getRequestTimeoutLogger(),++row);
2734            if(config instanceof ConfigWeb){
2735                    doGetLogSettings(qry,"schedule-task",config.getScheduleLogger(),++row);
2736                    doGetLogSettings(qry,"search",config.getSearchEngine().getLogger(),++row);
2737            }
2738            doGetLogSettings(qry,"thread",config.getThreadLogger(),++row);
2739            doGetLogSettings(qry,"trace",config.getTraceLogger(),++row);
2740            return qry;
2741            }
2742        
2743    
2744            private void doGetLogSettings(Query qry, String name,LogAndSource log, int row) {
2745                    qry.addRow();
2746                    qry.setAtEL("name", row, name);
2747                    qry.setAtEL("level", row, LogUtil.toStringType(log.getLogLevel(), ""));
2748                    qry.setAtEL("virtualpath", row, log.getSource());
2749                    qry.setAtEL("class", row, log.getLog().getClass().getName());
2750            Log l = log.getLog();
2751            if(l instanceof LogResource){
2752                    LogResource lr = (LogResource)l;
2753                    qry.setAtEL("maxFile", row, Caster.toString(lr.getMaxFiles()));
2754                    qry.setAtEL("maxFileSize", row, Caster.toString(lr.getMaxFileSize()));
2755                    qry.setAtEL("path", row, lr.getResource().getAbsolutePath());
2756            }
2757            
2758            
2759            }
2760    
2761            private void doGetPerformanceSettings() throws ApplicationException, PageException {
2762                    Struct sct=new StructImpl();
2763            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
2764            
2765            short it = config.getInspectTemplate();
2766            String str="once";
2767            if(it==ConfigImpl.INSPECT_ALWAYS)str="always";
2768            else if(it==ConfigImpl.INSPECT_NEVER)str="never";
2769            sct.set("inspectTemplate",str);
2770            }
2771        
2772        
2773        private void doGetCustomTagSetting() throws PageException {
2774            Struct sct=new StructImpl();
2775            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
2776            sct.set("customTagDeepSearch",Caster.toBoolean(config.doCustomTagDeepSearch()));// deprecated
2777            sct.set("customTagLocalSearch",Caster.toBoolean(config.doLocalCustomTag()));// deprecated
2778            
2779            sct.set("deepSearch",Caster.toBoolean(config.doCustomTagDeepSearch()));
2780            sct.set("localSearch",Caster.toBoolean(config.doLocalCustomTag()));
2781            sct.set("customTagPathCache",Caster.toBoolean(config.useCTPathCache()));
2782            sct.set("extensions",new ArrayImpl(config.getCustomTagExtensions()));
2783        }
2784    
2785        private void doGetDatasourceDriverList() throws PageException {
2786            Resource railoContext = ResourceUtil.toResourceExisting(pageContext ,"/railo-context/admin/dbdriver/");
2787            Resource[] children = railoContext.listResources(new ExtensionResourceFilter("cfc"));
2788            String rtnVar=getString("admin",action,"returnVariable");
2789            
2790            railo.runtime.type.Query qry=new QueryImpl(new String[]{"name"},children.length,rtnVar);
2791             
2792            
2793            for(int i=0;i<children.length;i++) {
2794                    qry.setAt("name", i+1, children[i].getName());
2795            }
2796            pageContext.setVariable(rtnVar,qry);
2797            
2798        }
2799    
2800        /*private String getContextPath() {
2801                    String cp = pageContext. getHttpServletRequest().getContextPath();
2802                    if(cp==null)return "";
2803                    return cp;
2804            }*/
2805    
2806            private void doGetDebuggingList() throws PageException {
2807            Resource railoContext = ResourceUtil.toResourceExisting(pageContext ,"/railo-context/templates/debugging/");
2808            Resource[] children = railoContext.listResources(new ExtensionResourceFilter("cfm"));
2809            String rtnVar=getString("admin",action,"returnVariable");
2810            
2811            railo.runtime.type.Query qry=new QueryImpl(new String[]{"name"},children.length,rtnVar);
2812             
2813            
2814            for(int i=0;i<children.length;i++) {
2815                    qry.setAt("name", i+1, children[i].getName());
2816            }
2817            pageContext.setVariable(rtnVar,qry);
2818            
2819        }
2820            
2821            private void doGetGatewayEntries() throws PageException  {
2822                    Map entries = ((ConfigWebImpl)config).getGatewayEngine().getEntries();
2823                    Iterator it = entries.entrySet().iterator();
2824                    railo.runtime.type.Query qry=
2825                            new QueryImpl(new String[]{"class","id","custom","cfcPath","listenerCfcPath","startupMode","state","readOnly"}, 0, "entries");
2826            Map.Entry entry;
2827            GatewayEntry ge;
2828            Gateway g;
2829            int row=0;
2830            while(it.hasNext()){
2831                            row++;
2832                        entry=(Entry) it.next();
2833                            ge=(GatewayEntry) entry.getValue();
2834                            g=ge.getGateway();
2835                    qry.addRow();
2836                    qry.setAtEL("class", row, ge.getClassName());
2837                    qry.setAtEL("id", row, ge.getId());
2838                    qry.setAtEL("listenerCfcPath", row, ge.getListenerCfcPath());
2839                    qry.setAtEL("cfcPath", row, ge.getCfcPath());
2840                    qry.setAtEL("startupMode", row, GatewayEntryImpl.toStartup(ge.getStartupMode(),"automatic"));
2841                    qry.setAtEL("custom", row, ge.getCustom());
2842                    qry.setAtEL("readOnly", row, Caster.toBoolean(ge.isReadOnly()));
2843                    qry.setAtEL("state",row,GatewayEngineImpl.toStringState(g.getState(), "failed"));
2844                    
2845            }
2846            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2847            }
2848            
2849    
2850            private void doGetMonitors() throws PageException  {
2851                    if(!(config instanceof ConfigServerImpl))
2852                            throw new ApplicationException("invalid context for this action");
2853                    
2854                    ConfigServerImpl cs=(ConfigServerImpl) config;
2855                    IntervallMonitor[] intervalls = cs.getIntervallMonitors();
2856                    RequestMonitor[] requests = cs.getRequestMonitors();
2857                    
2858                    railo.runtime.type.Query qry=
2859                            new QueryImpl(new Collection.Key[]{KeyImpl.NAME,KeyImpl.TYPE,LOG_ENABLED,CLASS}, 0, "monitors�");
2860                    doGetMonitors(qry,intervalls);
2861                    doGetMonitors(qry,requests);
2862                    
2863            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2864            }
2865            private void doGetMonitor() throws PageException  {
2866                    if(!(config instanceof ConfigServerImpl))
2867                            throw new ApplicationException("invalid context for this action");
2868                    ConfigServerImpl cs=(ConfigServerImpl) config;
2869    
2870                    String type=getString("admin",action,"monitorType");
2871                    String name=getString("admin",action,"name");
2872                    type=type.trim();
2873                    Monitor m;
2874                    if("request".equalsIgnoreCase(type)) 
2875                            m=cs.getRequestMonitor(name);
2876                    else
2877                            m=cs.getIntervallMonitor(name);
2878                    
2879                    Struct sct=new StructImpl();
2880                    sct.setEL(KeyImpl.NAME, m.getName());
2881                    sct.setEL(KeyImpl.TYPE, m.getType()==Monitor.TYPE_INTERVALL?"intervall":"request");
2882                    sct.setEL(LOG_ENABLED, m.isLogEnabled());
2883                    sct.setEL(CLASS, m.getClazz().getName());
2884                    
2885            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
2886            }
2887            
2888            private void doGetMonitors(Query qry, Monitor[] monitors) {
2889                    Monitor m;
2890                    int row;
2891                    for(int i=0;i<monitors.length;i++){
2892                            m=monitors[i];
2893                            row=qry.addRow();
2894                    qry.setAtEL(KeyImpl.NAME, row, m.getName());
2895                    qry.setAtEL(KeyImpl.TYPE, row, m.getType()==Monitor.TYPE_INTERVALL?"intervall":"request");
2896                    qry.setAtEL(LOG_ENABLED, row, m.isLogEnabled());
2897                    qry.setAtEL(CLASS, row, m.getClazz().getName());
2898                    }
2899                    
2900            }
2901    
2902            private void doGetGatewayEntry() throws PageException {
2903            
2904            String id=getString("admin",action,"id");
2905            Map entries = ((ConfigWebImpl)config).getGatewayEngine().getEntries();
2906                    Iterator it = entries.keySet().iterator();
2907                    GatewayEntry ge;
2908                    Gateway g;
2909                    Struct sct;
2910                    while(it.hasNext()) {
2911                String key=(String)it.next();
2912                if(key.equalsIgnoreCase(id)) {
2913                    ge=(GatewayEntry) entries.get(key);
2914                    g=ge.getGateway();
2915                    sct=new StructImpl();
2916                    sct.setEL("id",ge.getId());
2917                    sct.setEL("class",ge.getClassName());
2918                    sct.setEL("listenerCfcPath", ge.getListenerCfcPath());
2919                    sct.setEL("cfcPath",ge.getCfcPath());
2920                    sct.setEL("startupMode",GatewayEntryImpl.toStartup(ge.getStartupMode(),"automatic"));
2921                    sct.setEL("custom",ge.getCustom());
2922                    sct.setEL("readOnly",Caster.toBoolean(ge.isReadOnly()));
2923                    sct.setEL("state",GatewayEngineImpl.toStringState(g.getState(), "failed"));
2924                    
2925                    pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
2926                    return;
2927                }
2928            }
2929            throw new ApplicationException("there is no gateway entry with id ["+id+"]");
2930        }
2931            
2932            private void doGateway() throws PageException {
2933            
2934                    String id=getString("admin",action,"id");
2935                    String act=getString("admin",action,"gatewayAction").trim().toLowerCase();
2936                    if("restart".equals(act))       ((ConfigWebImpl)config).getGatewayEngine().restart(id);
2937                    else if("start".equals(act))((ConfigWebImpl)config).getGatewayEngine().start(id);
2938                    else if("stop".equals(act))     ((ConfigWebImpl)config).getGatewayEngine().stop(id);
2939                    else throw new ApplicationException("invalid gateway action ["+act+"], valid actions are [start,stop,restart]");
2940        }
2941            
2942            
2943            
2944            private void doGetCacheConnections() throws PageException  {
2945                    Map conns = config.getCacheConnections();
2946                    Iterator it = conns.entrySet().iterator();
2947                    railo.runtime.type.Query qry=new QueryImpl(new String[]{"class","name","custom","default","readOnly","storage"}, 0, "connections");
2948            Map.Entry entry;
2949            CacheConnection cc;
2950            CacheConnection defObj=config.getCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_OBJECT);
2951            CacheConnection defTmp=config.getCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_TEMPLATE);
2952            CacheConnection defQry=config.getCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_QUERY);
2953            CacheConnection defRes=config.getCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_RESOURCE);
2954            int row=0;
2955            String def;
2956                    while(it.hasNext()){
2957                            row++;
2958                        entry=(Entry) it.next();
2959                            cc=(CacheConnection) entry.getValue();
2960                    qry.addRow();
2961                    def="";
2962                    if(cc==defObj)def="object";
2963                    if(cc==defTmp)def="template";
2964                    if(cc==defQry)def="query";
2965                    if(cc==defRes)def="resource";
2966                    qry.setAtEL("class", row, cc.getClazz().getName());
2967                    qry.setAtEL("name", row, cc.getName());
2968                    qry.setAtEL("custom", row, cc.getCustom());
2969                    qry.setAtEL("default", row, def);
2970                    qry.setAtEL("readOnly", row, Caster.toBoolean(cc.isReadOnly()));
2971                    qry.setAtEL("storage", row, Caster.toBoolean(cc.isStorage()));
2972                    
2973            }
2974            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
2975            }
2976    
2977            
2978            private void doGetCacheDefaultConnection() throws PageException {
2979                    int type;
2980            String strType=getString("admin", "GetCacheDefaultConnection", "cacheType");
2981            strType=strType.toLowerCase().trim();
2982            if(strType.equals("object"))
2983                    type=ConfigImpl.CACHE_DEFAULT_OBJECT;
2984            else if(strType.equals("template"))
2985                    type=ConfigImpl.CACHE_DEFAULT_TEMPLATE;
2986            else if(strType.equals("query"))
2987                    type=ConfigImpl.CACHE_DEFAULT_QUERY;
2988            else if(strType.equals("resource"))
2989                    type=ConfigImpl.CACHE_DEFAULT_RESOURCE;
2990            else
2991                    throw new ApplicationException("inv,query,resourcealid type defintion, valid values are [object, template]");
2992                    
2993            CacheConnection cc = config.getCacheDefaultConnection(type);
2994            if(cc!=null){
2995                    Struct sct=new StructImpl();
2996                
2997                sct.setEL(KeyImpl.NAME,cc.getName());
2998                sct.setEL("class",cc.getClazz().getName());
2999                sct.setEL("custom",cc.getCustom());
3000                sct.setEL("default",Caster.toBoolean(true));
3001                sct.setEL("readOnly",Caster.toBoolean(cc.isReadOnly()));
3002                
3003                    pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
3004            }
3005            else throw new ApplicationException("there is no cache default connection");
3006        }
3007            
3008            private void doGetCacheConnection() throws PageException {
3009            
3010            String name=getString("admin",action,"name");
3011            Map conns = config.getCacheConnections();
3012                    Iterator it = conns.keySet().iterator();
3013                    CacheConnection cc;
3014                    CacheConnection dObj=config.getCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_OBJECT);
3015                    CacheConnection dTmp=config.getCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_TEMPLATE);
3016                    CacheConnection dQry=config.getCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_QUERY);
3017                    CacheConnection dRes=config.getCacheDefaultConnection(ConfigImpl.CACHE_DEFAULT_RESOURCE);
3018                    
3019                    Struct sct;
3020                    String d;
3021            while(it.hasNext()) {
3022                String key=(String)it.next();
3023                if(key.equalsIgnoreCase(name)) {
3024                    cc=(CacheConnection) conns.get(key);
3025                    sct=new StructImpl();
3026                    d="";
3027                    if(cc==dObj)d="object";
3028                    else if(cc==dTmp)d="template";
3029                    else if(cc==dQry)d="query";
3030                    else if(cc==dRes)d="resource";
3031                    sct.setEL(KeyImpl.NAME,cc.getName());
3032                    sct.setEL("class",cc.getClazz().getName());
3033                    sct.setEL("custom",cc.getCustom());
3034                    sct.setEL("default",d);
3035                    sct.setEL("readOnly",Caster.toBoolean(cc.isReadOnly()));
3036                    sct.setEL("storage",Caster.toBoolean(cc.isStorage()));
3037                    
3038                    pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
3039                    return;
3040                }
3041            }
3042            throw new ApplicationException("there is no cache connection with name ["+name+"]");
3043        }
3044    
3045            private void doRemoveCacheConnection() throws PageException {
3046                    admin.removeCacheConnection(getString("admin",action,"name"));
3047            store();
3048            adminSync.broadcast(attributes, config);
3049        }
3050            
3051            private void doRemoveGatewayEntry() throws PageException {
3052                    admin.removeCacheGatewayEntry(getString("admin",action,"id"));
3053            store();
3054            adminSync.broadcast(attributes, config);
3055        }
3056            
3057            private void doVerifyCacheConnection() throws PageException {
3058            try {
3059                            Cache cache = Util.getCache(pageContext.getConfig(), getString("admin",action,"name"));
3060                            // FUTURE cache.verify();
3061                            cache.getCustomInfo();
3062                    } catch (IOException e) {
3063                            throw Caster.toPageException(e);
3064                    }
3065        }
3066    
3067        /**
3068         * @throws PageException
3069         * 
3070         */
3071        private void doGetDatasource() throws PageException {
3072            
3073            String name=getString("admin",action,"name");
3074            Map ds = config.getDataSourcesAsMap();
3075            Iterator it = ds.keySet().iterator();
3076            
3077            while(it.hasNext()) {
3078                String key=(String)it.next();
3079                if(key.equalsIgnoreCase(name)) {
3080                    DataSourceImpl d=(DataSourceImpl) ds.get(key);
3081                    Struct sct=new StructImpl();
3082                    
3083                    sct.setEL(KeyImpl.NAME,key);
3084                    sct.setEL("host",d.getHost());
3085                    sct.setEL("classname",d.getClazz().getName());
3086                    sct.setEL("dsn",d.getDsnOriginal());
3087                    sct.setEL("database",d.getDatabase());
3088                    sct.setEL("port",d.getPort()<1?"":Caster.toString(d.getPort()));
3089                    sct.setEL("dsnTranslated",d.getDsnTranslated());
3090                    sct.setEL("timezone",toStringTimeZone(d.getTimeZone()));
3091                    sct.setEL("password",d.getPassword());
3092                    sct.setEL("username",d.getUsername());
3093                    sct.setEL("readonly",Caster.toBoolean(d.isReadOnly()));
3094                    sct.setEL("select",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_SELECT)));
3095                    sct.setEL("delete",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DELETE)));
3096                    sct.setEL("update",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_UPDATE)));
3097                    sct.setEL("insert",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_INSERT)));
3098                    sct.setEL("create",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_CREATE)));
3099                    sct.setEL("insert",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_INSERT)));
3100                    sct.setEL("drop",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DROP)));
3101                    sct.setEL("grant",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_GRANT)));
3102                    sct.setEL("revoke",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_REVOKE)));
3103                    sct.setEL("alter",Boolean.valueOf(d.hasAllow(DataSource.ALLOW_ALTER)));
3104        
3105                    sct.setEL("connectionLimit",d.getConnectionLimit()<1?"":Caster.toString(d.getConnectionLimit()));
3106                    sct.setEL("connectionTimeout",d.getConnectionTimeout()<1?"":Caster.toString(d.getConnectionTimeout()));
3107                    sct.setEL("metaCacheTimeout",Caster.toDouble(d.getMetaCacheTimeout()));
3108                    sct.setEL("custom",d.getCustoms());
3109                    sct.setEL("blob",Boolean.valueOf(d.isBlob()));
3110                    sct.setEL("clob",Boolean.valueOf(d.isClob()));
3111                    sct.setEL("validate",Boolean.valueOf(d.validate()));
3112                    sct.setEL("storage",Boolean.valueOf(d.isStorage()));
3113                    pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
3114                    return;
3115                }
3116            }
3117            throw new ApplicationException("there is no datasource with name ["+name+"]");
3118        }
3119        private Object toStringTimeZone(TimeZone timeZone) {
3120                    if(timeZone==null) return "";
3121                    return timeZone.getID();
3122            }
3123    
3124            private void doGetRemoteClient() throws PageException {
3125            
3126            String url=getString("admin",action,"url");
3127            RemoteClient[] clients = config.getRemoteClients();
3128            RemoteClient client;
3129            for(int i=0;i<clients.length;i++) {
3130                    client=clients[i];
3131                
3132                if(client.getUrl().equalsIgnoreCase(url)) {
3133                    Struct sct=new StructImpl();
3134                    ProxyData pd = client.getProxyData();
3135                    sct.setEL("label",client.getLabel());
3136                    sct.setEL("usage",client.getUsage());
3137                    sct.setEL("securityKey",client.getSecurityKey());
3138                    sct.setEL("adminPassword",client.getAdminPassword());
3139                    sct.setEL("ServerUsername",client.getServerUsername());
3140                    sct.setEL("ServerPassword",client.getServerPassword());
3141                    sct.setEL("type",client.getType());
3142                    sct.setEL("url",client.getUrl());
3143                    sct.setEL("proxyServer",pd==null?"":StringUtil.emptyIfNull(pd.getServer()));
3144                    sct.setEL("proxyUsername",pd==null?"":StringUtil.emptyIfNull(pd.getUsername()));
3145                    sct.setEL("proxyPassword",pd==null?"":StringUtil.emptyIfNull(pd.getPassword()));
3146                    sct.setEL("proxyPort",pd==null?"":(pd.getPort()==-1?"":Caster.toString(pd.getPort())));
3147                    
3148                    
3149                    pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
3150                    return;
3151                }
3152            }
3153            throw new ApplicationException("there is no remote client with url ["+url+"]");
3154        }
3155        
3156        private void doGetSpoolerTasks() throws PageException {
3157            int startrow = getInt("startrow",1);
3158            if(startrow <1) startrow=1;
3159            int maxrow = getInt("maxrow",-1);
3160            String result=getString("result", null);
3161            SpoolerEngineImpl engine = (SpoolerEngineImpl) config.getSpoolerEngine();
3162            
3163            Query qry = engine.getAllTasksAsQuery(startrow,maxrow);
3164            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
3165                    if(!StringUtil.isEmpty(result)){
3166                            Struct sct=new StructImpl();
3167                            pageContext.setVariable(result,sct);
3168                            sct.setEL("open", engine.getOpenTaskCount());
3169                                    sct.setEL("closed", engine.getClosedTaskCount());
3170                    }
3171            
3172            /*
3173            SpoolerTask[] open = config.getSpoolerEngine().getOpenTasks();
3174                            SpoolerTask[] closed = config.getSpoolerEngine().getClosedTasks();
3175                            String v="VARCHAR"; 
3176                            railo.runtime.type.Query qry=new QueryImpl(
3177                                            new String[]{"type","name","detail","id","lastExecution","nextExecution","closed","tries","exceptions","triesmax"},
3178                                            new String[]{v,v,"object",v,d,d,"boolean","int","object","int"},
3179                                            open.length+closed.length,"query");
3180    
3181                    int row=0;
3182                            row=doGetRemoteClientTasks(qry,open,row);
3183                            doGetRemoteClientTasks(qry,closed,row);
3184                    pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
3185               */  
3186            
3187            
3188            
3189        }
3190        
3191        private int doGetRemoteClientTasks(railo.runtime.type.Query qry, SpoolerTask[] tasks, int row) throws PageException {
3192            SpoolerTask task;
3193                    for(int i=0;i<tasks.length;i++) {
3194                            row++;
3195                            task=tasks[i];
3196                            try{
3197                                    qry.setAt("type", row, task.getType());
3198                                    qry.setAt("name", row, task.subject());
3199                                    qry.setAt("detail", row, task.detail());
3200                                    qry.setAt("id", row, task.getId());
3201            
3202                                    
3203                                    qry.setAt("lastExecution", row,new DateTimeImpl(pageContext,task.lastExecution(),true));
3204                                    qry.setAt("nextExecution", row,new DateTimeImpl(pageContext,task.nextExecution(),true));
3205                                    qry.setAt("closed", row,Caster.toBoolean(task.closed()));
3206                                    qry.setAt("tries", row,Caster.toDouble(task.tries()));
3207                                    qry.setAt("triesmax", row,Caster.toDouble(task.tries()));
3208                                    qry.setAt("exceptions", row,translateTime(task.getExceptions()));
3209                                    
3210                                    int triesMax=0;
3211                                    ExecutionPlan[] plans = task.getPlans();
3212                                    for(int y=0;y<plans.length;y++) {
3213                                            triesMax+=plans[y].getTries();
3214                                    }
3215                                    qry.setAt("triesmax", row,Caster.toDouble(triesMax));
3216                            }
3217                            catch(Throwable t){}
3218                    }
3219            return row;
3220            }
3221    
3222            private Array translateTime(Array exp) {
3223                    exp=(Array) exp.duplicate(true);
3224                    Iterator it = exp.iterator();
3225                    Struct sct;
3226                    while(it.hasNext()) {
3227                            sct=(Struct) it.next();
3228                            sct.setEL("time",new DateTimeImpl(pageContext,Caster.toLongValue(sct.get("time",null),0),true));
3229                    }
3230                    return exp;
3231            }
3232    
3233            private void doGetRemoteClients() throws PageException {
3234            RemoteClient[] clients = config.getRemoteClients();
3235            RemoteClient client;
3236            ProxyData pd;
3237            railo.runtime.type.Query qry=new QueryImpl(new String[]{"label","usage","securityKey","adminPassword","serverUsername","serverPassword","type","url",
3238                            "proxyServer","proxyUsername","proxyPassword","proxyPort"},clients.length,"query");
3239            
3240            int row=0;
3241    
3242            for(int i=0;i<clients.length;i++) {
3243                client=clients[i];
3244                pd=client.getProxyData();
3245                row=i+1;
3246                qry.setAt("label",row,client.getLabel());
3247                qry.setAt("usage",row,client.getUsage());
3248                qry.setAt("securityKey",row,client.getSecurityKey());
3249                qry.setAt("adminPassword",row,client.getAdminPassword());
3250                qry.setAt("ServerUsername",row,client.getServerUsername());
3251                qry.setAt("ServerPassword",row,client.getServerPassword());
3252                qry.setAt("type",row,client.getType());
3253                qry.setAt("url",row,client.getUrl());
3254                qry.setAt("proxyServer",row,pd==null?"":pd.getServer());
3255                qry.setAt("proxyUsername",row,pd==null?"":pd.getUsername());
3256                qry.setAt("proxyPassword",row,pd==null?"":pd.getPassword());
3257                qry.setAt("proxyPort",row,pd==null?"":Caster.toString(pd.getPort()));
3258                
3259            }
3260            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
3261        }
3262    
3263            private void doSetCluster()  {// MUST remove this
3264                    try {
3265                            _doSetCluster();
3266                    } catch (Throwable t) {
3267                            //print.printST(t);
3268                    }
3269            }
3270            
3271            private void _doSetCluster() throws PageException {
3272                    
3273                    Struct entries = Caster.toStruct(getObject("admin",action,"entries"));
3274                    Struct entry;
3275                    Key[] keys = entries.keys();
3276                    Cluster cluster = pageContext.clusterScope();
3277                    for(int i=0;i<keys.length;i++) {
3278                            entry=Caster.toStruct(entries.get(keys[i]));
3279                            cluster.setEntry(
3280                                    new ClusterEntryImpl(
3281                                                    KeyImpl.getInstance(Caster.toString(entry.get(KeyImpl.KEY))),
3282                                                    Caster.toSerializable(entry.get(KeyImpl.VALUE,null),null),
3283                                                    Caster.toLongValue(entry.get(KeyImpl.TIME))
3284                                    )
3285                            );
3286                    }
3287    
3288                    cluster.broadcast();
3289            }
3290            
3291            
3292            private void doGetCluster() throws PageException {
3293                    pageContext.setVariable(
3294                                    getString("admin",action,"returnVariable"),
3295                                    ((PageContextImpl)pageContext).clusterScope(false)
3296                            );
3297            }
3298            
3299            private void doGetToken() throws PageException {
3300                    pageContext.setVariable(
3301                                    getString("admin",action,"returnVariable"),
3302                                    config.getSecurityToken()
3303                            );
3304            }
3305            
3306            
3307            
3308            
3309        /**
3310         * @throws PageException
3311         * 
3312         */
3313        private void doGetDatasources() throws PageException {
3314            
3315            
3316            Map ds = config.getDataSourcesAsMap();
3317            Iterator it = ds.keySet().iterator();
3318            railo.runtime.type.Query qry=new QueryImpl(new String[]{"name","host","classname","dsn","DsnTranslated","database","port",
3319                    "timezone","username","password","readonly"
3320                    ,"grant","drop","create","revoke","alter","select","delete","update","insert"
3321                    ,"connectionLimit","connectionTimeout","clob","blob","validate","storage","customSettings"},ds.size(),"query");
3322            
3323            int row=0;
3324    
3325            while(it.hasNext()) {
3326                Object key=it.next();
3327                DataSourceImpl d=(DataSourceImpl) ds.get(key);
3328                row++;
3329                qry.setAt("name",row,key);
3330                qry.setAt("host",row,d.getHost());
3331                qry.setAt("classname",row,d.getClazz().getName());
3332                //qry.setAt("driverversion",row,getDriverVersion(d.getClazz())); 
3333                qry.setAt("dsn",row,d.getDsnOriginal());
3334                qry.setAt("database",row,d.getDatabase());
3335                qry.setAt("port",row,d.getPort()<1?"":Caster.toString(d.getPort()));
3336                qry.setAt("dsnTranslated",row,d.getDsnTranslated());
3337                qry.setAt("timezone",row,toStringTimeZone(d.getTimeZone()));
3338                qry.setAt("password",row,d.getPassword());
3339                qry.setAt("username",row,d.getUsername());
3340                qry.setAt("readonly",row,Caster.toBoolean(d.isReadOnly()));
3341                qry.setAt("select",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_SELECT)));
3342                qry.setAt("delete",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DELETE)));
3343                qry.setAt("update",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_UPDATE)));
3344                qry.setAt("insert",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_INSERT)));
3345                qry.setAt("create",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_CREATE)));
3346                qry.setAt("insert",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_INSERT)));
3347                qry.setAt("drop",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_DROP)));
3348                qry.setAt("grant",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_GRANT)));
3349                qry.setAt("revoke",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_REVOKE)));
3350                qry.setAt("alter",row,Boolean.valueOf(d.hasAllow(DataSource.ALLOW_ALTER)));
3351    
3352                qry.setAt("connectionLimit",row,d.getConnectionLimit()<1?"":Caster.toString(d.getConnectionLimit()));
3353                qry.setAt("connectionTimeout",row,d.getConnectionTimeout()<1?"":Caster.toString(d.getConnectionTimeout()));
3354                qry.setAt("customSettings",row,d.getCustoms());
3355                qry.setAt("blob",row,Boolean.valueOf(d.isBlob()));
3356                qry.setAt("clob",row,Boolean.valueOf(d.isClob()));
3357                qry.setAt("validate",row,Boolean.valueOf(d.validate()));
3358                qry.setAt("storage",row,Boolean.valueOf(d.isStorage()));
3359                
3360            }
3361            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
3362        }
3363    
3364    
3365        /**
3366         * @throws PageException
3367         * 
3368         */
3369        private void doUpdateScope() throws PageException {
3370            
3371            admin.updateScopeCascadingType(getString("admin",action,"scopeCascadingType"));
3372            admin.updateAllowImplicidQueryCall(getBoolObject("admin",action,"allowImplicidQueryCall"));
3373            admin.updateMergeFormAndUrl(getBoolObject("admin",action,"mergeFormAndUrl"));
3374            admin.updateSessionManagement(getBoolObject("admin",action,"sessionManagement"));
3375            admin.updateClientManagement(getBoolObject("admin",action,"clientManagement"));
3376            admin.updateDomaincookies(getBoolObject("admin",action,"domainCookies"));
3377            admin.updateClientCookies(getBoolObject("admin",action,"clientCookies"));
3378            //admin.updateRequestTimeout(getTimespan("admin",action,"requestTimeout"));
3379            admin.updateClientTimeout(getTimespan("admin",action,"clientTimeout"));
3380            admin.updateSessionTimeout(getTimespan("admin",action,"sessionTimeout"));
3381            admin.updateApplicationTimeout(getTimespan("admin",action,"applicationTimeout"));
3382            admin.updateSessionType(getString("admin",action,"sessionType"));
3383            admin.updateLocalMode(getString("admin",action,"localMode"));
3384            store();
3385            adminSync.broadcast(attributes, config);
3386        }
3387    
3388        private void doUpdateApplicationSettings() throws PageException {
3389            admin.updateRequestTimeout(getTimespan("admin",action,"requestTimeout"));
3390            admin.updateScriptProtect(getString("admin",action,"scriptProtect"));
3391            admin.updateAllowURLRequestTimeout(getBoolObject("admin",action,"allowURLRequestTimeout")); // DIFF 23
3392            store();
3393            adminSync.broadcast(attributes, config);
3394        }
3395    
3396        private void doUpdateOutputSettings() throws PageException {
3397            admin.updateSuppressWhitespace(getBoolObject("admin",action, "suppressWhitespace"));
3398            admin.updateSuppressContent(getBoolObject("admin",action, "suppressContent"));
3399            //admin.updateShowVersion(getBoolObject("admin",action, "showVersion"));
3400            admin.updateAllowCompression(getBoolObject("admin",action, "allowCompression"));
3401            admin.updateContentLength(getBoolObject("admin",action, "contentLength"));
3402            store();
3403            adminSync.broadcast(attributes, config);
3404        }
3405        
3406        private void doUpdateCustomTagSetting() throws PageException {
3407            admin.updateCustomTagDeepSearch(getBool("admin", action, "deepSearch"));
3408            admin.updateCustomTagLocalSearch(getBool("admin", action, "localSearch"));
3409            admin.updateCTPathCache(getBool("admin", action, "customTagPathCache"));
3410            admin.updateCustomTagExtensions(getString("admin", action, "extensions"));
3411            store();
3412            adminSync.broadcast(attributes, config);
3413        }
3414        
3415        private void doUpdateUpdateLogSettings() throws PageException  {
3416            int level=LogUtil.toIntType(getString("admin", "updateUpdateLogSettings", "level"), -1);
3417            String source=getString("admin", "updateUpdateLogSettings", "path");
3418            if(source.indexOf("{")==-1){
3419                    Resource res = ResourceUtil.toResourceNotExisting(pageContext, source, false);
3420                    String tmp=SystemUtil.addPlaceHolder(res, config, null);
3421                            
3422                    
3423                    if(tmp!=null) source=tmp;
3424                    else source=ContractPath.call(pageContext, source);
3425            }
3426            
3427            admin.updateLogSettings(
3428                            getString("admin", "updateUpdateLogSettings", "name"),
3429                            level,
3430                            source,
3431                            getInt("admin", "updateUpdateLogSettings", "maxfile"),
3432                            getInt("admin", "updateUpdateLogSettings", "maxfilesize")
3433            );
3434            store();
3435            adminSync.broadcast(attributes, config);
3436        }
3437        
3438    
3439    
3440        private void doUpdateMonitor() throws PageException  {
3441            admin.updateMonitor(
3442                            getString("admin", "updateMonitor", "class"),
3443                            getString("admin", "updateMonitor", "monitorType"),
3444                            getString("admin", "updateMonitor", "name"),
3445                            getBool("admin", "updateMonitor", "logEnabled")
3446            );
3447            store();
3448            adminSync.broadcast(attributes, config);
3449        }
3450    
3451        private void doRemoveMonitor() throws PageException  {
3452            admin.removeMonitor(
3453                            getString("admin", "updateMonitor", "name")
3454            );
3455            store();
3456            adminSync.broadcast(attributes, config);
3457        }
3458        
3459        
3460        
3461        private void doUpdateExtension() throws PageException {
3462            
3463                    
3464                            admin.updateExtension(new ExtensionImpl(
3465                                                    getStruct("config", null),
3466                                            getString("admin", "UpdateExtensions", "id"),
3467                                            getString("admin", "UpdateExtensions","provider"),
3468                                            getString("admin", "UpdateExtensions","version"),
3469                                            
3470                                            getString("admin", "UpdateExtensions","name"),
3471                                            getString("admin", "UpdateExtensions","label"),
3472                                            getString("admin", "UpdateExtensions","description"),
3473                                            getString("admin", "UpdateExtensions","category"),
3474                                            getString("admin", "UpdateExtensions","image"),
3475                                            getString("admin", "UpdateExtensions","author"),
3476                                            getString("admin", "UpdateExtensions","codename"),
3477                                            getString("admin", "UpdateExtensions","video"),
3478                                            getString("admin", "UpdateExtensions","support"),
3479                                            getString("admin", "UpdateExtensions","documentation"),
3480                                            getString("admin", "UpdateExtensions","forum"),
3481                                            getString("admin", "UpdateExtensions","mailinglist"),
3482                                            getString("admin", "UpdateExtensions","network"),
3483                                            getDateTime("created",null),
3484                                            getString("admin", "UpdateExtensions","_type")
3485                                    ));
3486                    
3487            
3488    
3489            
3490            store();
3491            //adminSync.broadcast(attributes, config);
3492        }
3493        
3494        private void doUpdateExtensionProvider() throws PageException {
3495            admin.updateExtensionProvider(
3496                            getString("admin", "UpdateExtensionProvider","url")
3497                            );
3498            store();
3499        }
3500        
3501        private void doUpdateExtensionInfo() throws PageException {
3502            admin.updateExtensionInfo(
3503                            getBool("admin", "UpdateExtensionInfo","enabled")
3504                            );
3505            store();
3506        }
3507    
3508        private void doVerifyExtensionProvider() throws PageException {
3509            admin.verifyExtensionProvider(getString("admin", "VerifyExtensionProvider","url"));
3510                    
3511        }
3512        private void doResetId() throws PageException {
3513            admin.resetId();
3514            store();
3515                    
3516        }
3517        
3518        private void doRemoveExtensionProvider() throws PageException {
3519            admin.removeExtensionProvider(getString("admin", "RemoveExtensionProvider","url"));
3520            store();
3521        }
3522    
3523        /**
3524         * @throws PageException
3525         * 
3526         */
3527        private void doGetApplicationSetting() throws PageException {
3528            
3529            Struct sct=new StructImpl();
3530            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
3531            sct.set("scriptProtect",AppListenerUtil.translateScriptProtect(config.getScriptProtect()));
3532            
3533            // request timeout
3534            sct.set("requestTimeout",config.getRequestTimeout());
3535            sct.set("requestTimeout_day",Caster.toInteger(config.getRequestTimeout().getDay()));
3536            sct.set("requestTimeout_hour",Caster.toInteger(config.getRequestTimeout().getHour()));
3537            sct.set("requestTimeout_minute",Caster.toInteger(config.getRequestTimeout().getMinute()));
3538            sct.set("requestTimeout_second",Caster.toInteger(config.getRequestTimeout().getSecond()));
3539            
3540            // AllowURLRequestTimeout
3541            sct.set("AllowURLRequestTimeout",Caster.toBoolean(config.isAllowURLRequestTimeout()));// DIF 23
3542        }
3543        
3544        private void doGetOutputSetting() throws PageException {
3545            
3546            Struct sct=new StructImpl();
3547            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
3548            sct.set("suppressWhitespace",Caster.toBoolean(config.isSuppressWhitespace()));
3549            sct.set("suppressContent",Caster.toBoolean(config.isSuppressContent()));
3550            sct.set("contentLength",Caster.toBoolean(config.contentLength()));
3551            //sct.set("showVersion",Caster.toBoolean(config.isShowVersion()));
3552            sct.set("allowCompression",Caster.toBoolean(config.allowCompression()));
3553            
3554            
3555        }
3556        
3557        /**
3558         * @throws PageException
3559         * 
3560         */
3561        private void doGetScope() throws PageException {
3562            String sessionType=config.getSessionType()==Config.SESSION_TYPE_J2EE?"j2ee":"cfml";
3563            String localMode="update";
3564            if(config.getLocalMode()==Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS)localMode="always";
3565            
3566            
3567            Struct sct=new StructImpl();
3568            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
3569            sct.set("allowImplicidQueryCall",Caster.toBoolean(config.allowImplicidQueryCall()));
3570            sct.set("mergeFormAndUrl",Caster.toBoolean(config.mergeFormAndURL()));
3571            
3572            sct.set("sessiontype",sessionType);
3573            sct.set("localmode",localMode);
3574            sct.set("sessionManagement",Caster.toBoolean(config.isSessionManagement()));
3575            sct.set("clientManagement",Caster.toBoolean(config.isClientManagement()));
3576            sct.set("domainCookies",Caster.toBoolean(config.isDomainCookies()));
3577            sct.set("clientCookies",Caster.toBoolean(config.isClientCookies()));
3578    
3579            TimeSpan ts=config.getSessionTimeout();
3580            sct.set("sessionTimeout",ts);
3581            sct.set("sessionTimeout_day",Caster.toInteger(ts.getDay()));
3582            sct.set("sessionTimeout_hour",Caster.toInteger(ts.getHour()));
3583            sct.set("sessionTimeout_minute",Caster.toInteger(ts.getMinute()));
3584            sct.set("sessionTimeout_second",Caster.toInteger(ts.getSecond()));
3585    
3586            ts=config.getApplicationTimeout();
3587            sct.set("applicationTimeout",ts);
3588            sct.set("applicationTimeout_day",Caster.toInteger(ts.getDay()));
3589            sct.set("applicationTimeout_hour",Caster.toInteger(ts.getHour()));
3590            sct.set("applicationTimeout_minute",Caster.toInteger(ts.getMinute()));
3591            sct.set("applicationTimeout_second",Caster.toInteger(ts.getSecond()));
3592    
3593            ts=config.getClientTimeout();
3594            sct.set("clientTimeout",ts);
3595            sct.set("clientTimeout_day",Caster.toInteger(ts.getDay()));
3596            sct.set("clientTimeout_hour",Caster.toInteger(ts.getHour()));
3597            sct.set("clientTimeout_minute",Caster.toInteger(ts.getMinute()));
3598            sct.set("clientTimeout_second",Caster.toInteger(ts.getSecond()));
3599            
3600            
3601            // scope cascading type
3602            if(config.getScopeCascadingType()==Config.SCOPE_STRICT) sct.set("scopeCascadingType","strict");
3603            else if(config.getScopeCascadingType()==Config.SCOPE_SMALL) sct.set("scopeCascadingType","small");
3604            else if(config.getScopeCascadingType()==Config.SCOPE_STANDARD) sct.set("scopeCascadingType","standard");
3605        }
3606    
3607        /**
3608         * @throws PageException
3609         * 
3610         */
3611        private void doUpdateComponent() throws PageException {
3612    
3613            admin.updateComponentDeepSearch(getBoolObject("admin", action, "deepSearch"));
3614            admin.updateBaseComponent(getString("admin",action,"baseComponentTemplate"));
3615            admin.updateComponentDumpTemplate(getString("admin",action,"componentDumpTemplate"));
3616            admin.updateComponentDataMemberDefaultAccess(getString("admin",action,"componentDataMemberDefaultAccess"));
3617            admin.updateTriggerDataMember(getBoolObject("admin",action,"triggerDataMember"));
3618            admin.updateComponentUseShadow(getBoolObject("admin",action,"useShadow"));
3619            admin.updateComponentDefaultImport(getString("admin",action,"componentDefaultImport"));
3620            admin.updateComponentLocalSearch(getBoolObject("admin",action,"componentLocalSearch"));
3621            admin.updateComponentPathCache(getBoolObject("admin",action,"componentPathCache"));
3622            store();
3623            adminSync.broadcast(attributes, config);
3624        }
3625    
3626        /**
3627         * @throws PageException 
3628         * @throws PageException
3629         * 
3630         */
3631        private void doGetComponent() throws PageException {
3632            Struct sct=new StructImpl();
3633            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
3634            // Base Component
3635            try {
3636                PageSource ps = ((PageContextImpl)pageContext).getPageSourceExisting(config.getBaseComponentTemplate());
3637                if(ps!=null) sct.set("baseComponentTemplate",ps.getDisplayPath());
3638                else sct.set("baseComponentTemplate","");
3639            } catch (PageException e) {
3640                sct.set("baseComponentTemplate","");
3641            }
3642            sct.set("strBaseComponentTemplate",config.getBaseComponentTemplate());
3643            
3644            // dump template
3645            try {
3646                PageSource ps = ((PageContextImpl)pageContext).getPageSourceExisting(config.getComponentDumpTemplate());
3647                if(ps!=null) sct.set("componentDumpTemplate",ps.getDisplayPath());
3648                else sct.set("componentDumpTemplate","");
3649            } catch (PageException e) {
3650                sct.set("componentDumpTemplate","");
3651            }
3652            sct.set("strComponentDumpTemplate",config.getComponentDumpTemplate());
3653    
3654            sct.set("deepSearch",Caster.toBoolean(config.doComponentDeepSearch()));
3655            sct.set("componentDataMemberDefaultAccess",ComponentUtil.toStringAccess(config.getComponentDataMemberDefaultAccess()));
3656            sct.set("triggerDataMember",Caster.toBoolean(config.getTriggerComponentDataMember()));
3657            sct.set("useShadow",Caster.toBoolean(config.useComponentShadow()));
3658            sct.set("ComponentDefaultImport",config.getComponentDefaultImport());
3659            sct.set("componentLocalSearch",config.getComponentLocalSearch());
3660            sct.set("componentPathCache",config.useComponentPathCache());
3661            
3662        }
3663    
3664        /**
3665         * @throws PageException
3666         * 
3667         */
3668        private void doUpdateRegional() throws PageException {
3669            Boolean useTimeServer=getBool("usetimeserver",null);
3670            
3671            try{
3672                    admin.updateLocale(getString("admin",action,"locale"));
3673                    admin.updateTimeZone(getString("admin",action,"timezone"));
3674                    admin.updateTimeServer(getString("admin",action,"timeserver"),useTimeServer);
3675                    admin.updateTimeZone(getString("admin",action,"timezone"));
3676            }
3677            finally {
3678                     store();
3679            }
3680            adminSync.broadcast(attributes, config);
3681        }
3682        private void doUpdateMonitorEnabled() throws PageException {
3683            
3684            try{
3685                    admin.updateMonitorEnabled(getBool("admin","UpdateMonitorEnabled","monitorEnabled"));
3686            }
3687            finally {
3688                     store();
3689            }
3690            adminSync.broadcast(attributes, config);
3691        }
3692        
3693        
3694    
3695        private void doUpdateTLD() throws PageException {
3696            try {
3697                    String jar = getString("jar",null);
3698                    if(!StringUtil.isEmpty(jar,true)){
3699                            Resource resJar = ResourceUtil.toResourceExisting(pageContext, jar);
3700                            admin.updateJar(resJar);
3701                    }
3702                    Resource resTld = ResourceUtil.toResourceExisting(pageContext, getString("admin",action,"tld"));
3703                    admin.updateTLD(resTld);
3704                    } 
3705            catch (Exception e) {
3706                            throw Caster.toPageException(e);
3707                    }
3708            store();
3709        }
3710        private void doUpdateFLD() throws PageException {
3711            try {
3712                    String jar = getString("jar",null);
3713                    if(!StringUtil.isEmpty(jar,true)){
3714                            Resource resJar = ResourceUtil.toResourceExisting(pageContext, jar);
3715                            admin.updateJar(resJar);
3716                    }
3717                    Resource resFld = ResourceUtil.toResourceExisting(pageContext, getString("admin",action,"fld"));
3718                    admin.updateFLD(resFld);
3719                    } 
3720            catch (Exception e) {
3721                            throw Caster.toPageException(e);
3722                    }
3723            store();
3724        }
3725        
3726        private void doUpdateJar() throws PageException {
3727            try {
3728                    Resource resJar = ResourceUtil.toResourceExisting(pageContext, getString("admin",action,"jar"));
3729                    admin.updateJar(resJar);
3730                    } 
3731            catch (Exception e) {
3732                            throw Caster.toPageException(e);
3733                    }
3734            store();
3735        }
3736        
3737    
3738            
3739    
3740    
3741            private void doUpdateLoginSettings() throws PageException {
3742                    boolean captcha = getBool("admin", "UpdateLoginSettings", "captcha");
3743                    int delay = getInt("admin", "UpdateLoginSettings", "delay");
3744                    admin.updateLoginSettings(captcha,delay);
3745                    store();
3746            }
3747        
3748        
3749        
3750        private void doUpdateSSLCertificate() throws PageException {
3751            String host=getString("admin", "UpdateSSLCertificateInstall", "host");
3752            int port = getInt("port", 443);
3753            updateSSLCertificate((ConfigServer)config, host, port);
3754        }
3755        
3756        public static void updateSSLCertificate(Config config,String host, int port) throws PageException {
3757            Resource cacerts=getCacerts(config);
3758             
3759            try {
3760                            CertificateInstaller installer = new CertificateInstaller(cacerts,host,(int)port);
3761                            installer.installAll();
3762                    } catch (Exception e) {
3763                            throw Caster.toPageException(e);
3764                    }
3765        }
3766        
3767        private void doGetSSLCertificate() throws PageException {
3768            String host=getString("admin", "GetSSLCertificate", "host");
3769            int port = getInt("port", 443);
3770            pageContext.setVariable(getString("admin",action,"returnVariable"),getSSLCertificate((ConfigServer)config,host,port));
3771        }
3772        
3773        public static Query getSSLCertificate(Config config,String host, int port) throws PageException {
3774            Resource cacerts=getCacerts(config);
3775            CertificateInstaller installer;
3776                    try {
3777                            installer = new CertificateInstaller(cacerts,host,(int)port);
3778                    } catch (Exception e) {
3779                            throw Caster.toPageException(e);
3780                    }
3781            X509Certificate[] certs = installer.getCertificates();
3782            X509Certificate cert;
3783            
3784            Query qry=new QueryImpl(new String[]{"subject","issuer"},certs.length,"certificates");
3785            for(int i=0;i<certs.length;i++){
3786                    cert=certs[i];
3787                    qry.setAtEL("subject",i+1, cert.getSubjectDN().getName());
3788                    qry.setAtEL("issuer",i+1, cert.getIssuerDN().getName());
3789            }
3790            return qry;
3791        }
3792        
3793        
3794        private static Resource getCacerts(Config config) throws PageException {
3795            Resource cacerts=null;
3796            // javax.net.ssl.trustStore
3797            String trustStore = SystemUtil.getPropertyEL("javax.net.ssl.trustStore");
3798            if(trustStore!=null){
3799                    cacerts = ResourcesImpl.getFileResourceProvider().getResource(trustStore);
3800            }
3801            
3802            // security/cacerts
3803            if(cacerts==null || !cacerts.exists()) {
3804                    cacerts = ((ConfigImpl)config).getConfigServerDir().getRealResource("security/cacerts");
3805            }
3806            return cacerts;
3807        }
3808        
3809        
3810    
3811        private void doRemoveJar() throws PageException {
3812            try {
3813                    String name = getString("jar",null);
3814                    if(StringUtil.isEmpty(name))name=getString("admin",action,"name");
3815                    
3816                    admin.removeJar(name);
3817                    } 
3818            catch (Exception e) {
3819                            throw Caster.toPageException(e);
3820                    }
3821            store();
3822        }
3823        
3824        private void doRemoveTLD() throws PageException {
3825            try {
3826                    String name = getString("tld",null);
3827                    if(StringUtil.isEmpty(name))name=getString("admin",action,"name");
3828                    admin.removeTLD(name);
3829                    } 
3830            catch (Exception e) {
3831                            throw Caster.toPageException(e);
3832                    }
3833            store();
3834        }
3835        
3836    
3837        
3838        private void doRemoveFLD() throws PageException {
3839            try {
3840                    String name = getString("fld",null);
3841                    if(StringUtil.isEmpty(name))name=getString("admin",action,"name");
3842                    admin.removeFLD(name);
3843                    } 
3844            catch (Exception e) {
3845                            throw Caster.toPageException(e);
3846                    }
3847            store();
3848        }
3849        
3850        private void doUpdateRemoteClient() throws PageException {
3851            
3852            
3853            
3854            admin.updateRemoteClient(
3855                            getString("admin",action,"label"),
3856                            getString("admin",action,"url"),
3857                            getString("admin",action,"remotetype"),
3858                            getString("admin",action,"securityKey"),
3859                            getString("admin",action,"usage"),
3860                            getString("admin",action,"adminPassword"),
3861                            getString("ServerUsername",""),
3862                            getString("ServerPassword",""),
3863                            getString("proxyServer",""),
3864                            getString("proxyUsername",""),
3865                            getString("proxyPassword",""),
3866                            getString("proxyPort","")
3867                            
3868            );
3869            
3870            store();
3871        }
3872        private void doUpdateRemoteClientUsage() throws PageException {
3873            admin.updateRemoteClientUsage(
3874                       getString("admin",action,"code"),
3875                       getString("admin",action,"displayname")
3876                            
3877             );
3878             store();
3879         }
3880        private void doRemoveRemoteClientUsage() throws PageException {
3881            admin.removeRemoteClientUsage(
3882                       getString("admin",action,"code")
3883                            
3884             );
3885             store();
3886         }
3887    
3888            private String getCallerId() throws IOException {
3889                    if(type==TYPE_WEB) {
3890                            return config.getId();
3891                            //return GetRailoId.createId(config.getId(), config.getConfigDir());
3892                    }
3893                    if(config instanceof ConfigWebImpl){
3894                            ConfigWebImpl cwi = (ConfigWebImpl)config;
3895                            return cwi.getServerId();
3896                            //return GetRailoId.createId(cwi.getServerId(), cwi.getServerConfigDir());
3897                    }
3898                    if(config instanceof ConfigServer){
3899                            return config.getId();
3900                            //return GetRailoId.createId(config.getId(), config.getConfigDir());
3901                    }
3902                    throw new IOException("can not create id");
3903            }
3904    
3905            private void doUpdateApplicationListener() throws PageException {
3906            admin.updateApplicationListener(
3907                            getString("admin",action,"listenerType"),
3908                            getString("admin",action,"listenerMode")
3909            );
3910           
3911            store();
3912            adminSync.broadcast(attributes, config);
3913        }
3914        
3915        
3916        
3917        private void doUpdateProxy() throws PageException {
3918            admin.updateProxy(
3919                            getBool("admin",action,"proxyenabled"), 
3920                            getString("admin",action,"proxyserver"), 
3921                            getInt("admin",action,"proxyport"), 
3922                            getString("admin",action,"proxyusername"), 
3923                            getString("admin",action,"proxypassword")
3924                    );
3925            store();
3926        }
3927        
3928    
3929            private void doUpdateCharset() throws PageException {
3930            admin.updateResourceCharset(getString("admin",action,"resourceCharset"));
3931            admin.updateTemplateCharset(getString("admin",action,"templateCharset"));
3932            admin.updateWebCharset(getString("admin",action,"webCharset"));
3933                    store();
3934            adminSync.broadcast(attributes, config);
3935            }
3936    
3937        /**
3938         * @throws PageException
3939         * 
3940         */
3941        private void doSecurityManager() throws PageException {
3942            String rtnVar = getString("admin",action,"returnVariable");
3943            String secType = getString("admin",action,"sectype");
3944            String secValue = getString("secvalue",null);
3945            boolean isServer=config instanceof ConfigServer;
3946            
3947            if(secValue==null) {
3948                    if(isServer)    {
3949                            pageContext.setVariable(
3950                            rtnVar,
3951                            SecurityManagerImpl.toStringAccessValue(SecurityManager.VALUE_YES)
3952                    );
3953                    }
3954                    else {
3955                            pageContext.setVariable(
3956                            rtnVar,
3957                            SecurityManagerImpl.toStringAccessValue(config.getSecurityManager().getAccess(secType))
3958                    );
3959                    }
3960                    return;
3961            }
3962            pageContext.setVariable(
3963                    rtnVar,
3964                    Caster.toBoolean(
3965                            isServer ||
3966                            config.getSecurityManager().getAccess(secType) == SecurityManagerImpl.toShortAccessValue(secValue)
3967                    )
3968            );
3969        }
3970    
3971        /**
3972         * @throws PageException
3973         * 
3974         */
3975        private void doGetTimeZones() throws PageException {
3976            
3977            
3978            
3979            String strLocale=getString("locale","english (united kingdom)");
3980            Locale locale = LocaleFactory.getLocale(strLocale);
3981            
3982            String[] timeZones = TimeZone.getAvailableIDs();
3983            railo.runtime.type.Query qry=new QueryImpl(new String[]{"id","display"},new String[]{"varchar","varchar"},timeZones.length,"timezones");
3984            Arrays.sort(timeZones);
3985            TimeZone timeZone;
3986            for(int i=0;i<timeZones.length;i++) {
3987                timeZone=TimeZone.getTimeZone(timeZones[i]);
3988                qry.setAt("id",i+1,timeZones[i]);
3989                qry.setAt("display",i+1,timeZone.getDisplayName(locale));
3990                
3991            }
3992            pageContext.setVariable(getString("admin",action,"returnVariable"),qry);
3993        }
3994    
3995        /**
3996         * @throws PageException
3997         * 
3998         */
3999        private void doGetLocales() throws PageException {
4000            Struct sct=new StructImpl(StructImpl.TYPE_LINKED);
4001            //Array arr=new ArrayImpl();
4002            String strLocale=getString("locale","english (united kingdom)");
4003            Locale locale = LocaleFactory.getLocale(strLocale);
4004            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
4005            Map locales = LocaleFactory.getLocales();
4006            Iterator it = locales.keySet().iterator();
4007           
4008            String key;
4009            Locale l;
4010            while(it.hasNext()) {
4011                key=(String)it.next();
4012                l=(Locale) locales.get(key);
4013                sct.setEL(l.toString(),l.getDisplayName(locale));
4014                //arr.append(locale.getDisplayName());
4015            }
4016            //arr.sort("textnocase","asc");
4017        }
4018        
4019        
4020        private void doGetApplicationListener() throws PageException  {
4021            Struct sct=new StructImpl();
4022            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
4023            ApplicationListener appListener = config.getApplicationListener();
4024            sct.set("type",AppListenerUtil.toStringType(appListener));
4025            sct.set("mode",AppListenerUtil.toStringMode(appListener.getMode()));
4026                    // replaced with encoding outputsct.set("defaultencoding", config.get DefaultEncoding());
4027        }
4028        /**
4029         * @throws PageException
4030         * 
4031         */
4032        private void doGetRegional() throws PageException  {
4033            Struct sct=new StructImpl();
4034            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
4035            sct.set("locale",Caster.toString(config.getLocale()));
4036            sct.set("timezone",toStringTimeZone(pageContext.getTimeZone()));
4037            sct.set("timeserver",config.getTimeServer());
4038            sct.set("usetimeserver",config.getUseTimeServer());
4039                    // replaced with encoding outputsct.set("defaultencoding", config.get DefaultEncoding());
4040        }
4041        private void doIsMonitorEnabled() throws PageException  {
4042            if(config instanceof ConfigServerImpl) {
4043                    ConfigServerImpl cs=(ConfigServerImpl) config;
4044                    pageContext.setVariable(getString("admin",action,"returnVariable"),Caster.toBoolean(cs.isMonitoringEnabled()));
4045            }
4046        }
4047        
4048    
4049            private void doSurveillance() throws PageException {
4050                    // Server
4051                    if(config instanceof ConfigServer) {
4052                            ConfigServer cs=(ConfigServer) config;
4053                            ConfigWeb[] webs = cs.getConfigWebs();
4054                            Struct sct=new StructImpl();
4055                            for(int i=0;i<webs.length;i++){
4056                                    ConfigWebImpl cw=(ConfigWebImpl) webs[i];
4057                                    sct.setEL(cw.getLabel(), ((CFMLFactoryImpl)cw.getFactory()).getInfo());
4058                            }
4059                            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
4060                            
4061                    }
4062                    // Web
4063                    else {
4064                            CFMLFactoryImpl factory = (CFMLFactoryImpl) config.getFactory();
4065                            pageContext.setVariable(getString("admin",action,"returnVariable"),
4066                                            factory.getInfo());
4067                    }
4068                    
4069                    
4070                    
4071                    
4072                    //pageContext.setVariable(getString("admin",action,"returnVariable"),Surveillance.getInfo(config));
4073            }
4074            
4075            private void doStopThread() throws PageException {
4076                    String contextId=getString("admin", "stopThread", "contextId");
4077                    String threadId=getString("admin", "stopThread", "threadId");
4078                    String stopType=getString("stopType","exception");
4079                    
4080                    if(!(config instanceof ConfigServer)) 
4081                            throw new ApplicationException("invalid context for this action");
4082                    
4083                    
4084                    ConfigServer cs=(ConfigServer) config;
4085                    ConfigWeb[] webs = cs.getConfigWebs();
4086                    for(int i=0;i<webs.length;i++){
4087                            ConfigWebImpl cw=(ConfigWebImpl) webs[i];
4088                            if(!cw.getId().equals(contextId)) continue;
4089                             ((CFMLFactoryImpl)cw.getFactory()).stopThread(threadId,stopType);
4090                             break;
4091                                    
4092                    }
4093            }
4094        
4095        private void doGetProxy() throws PageException  {
4096            Struct sct=new StructImpl();
4097            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
4098            //sct.set("enabled",Caster.toBoolean(config.isProxyEnable()));
4099            sct.set("port",Caster.toString(config.getProxyPort()));
4100            sct.set("server",emptyIfNull(config.getProxyServer()));
4101            sct.set("username",emptyIfNull(config.getProxyUsername()));
4102            sct.set("password",emptyIfNull(config.getProxyPassword()));
4103        }
4104        
4105    
4106    
4107            private void doGetLoginSettings() throws ApplicationException, PageException {
4108                    Struct sct=new StructImpl();
4109                    config=(ConfigImpl) ThreadLocalPageContext.getConfig(config);
4110            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
4111            sct.set("captcha",Caster.toBoolean(config.getLoginCaptcha()));
4112            sct.set("delay",Caster.toDouble(config.getLoginDelay()));
4113            
4114            }
4115    
4116    
4117            private void doGetCharset() throws PageException {
4118                    Struct sct=new StructImpl();
4119            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
4120            sct.set("resourceCharset",config.getResourceCharset());
4121            sct.set("templateCharset",config.getTemplateCharset());
4122            sct.set("webCharset",config.getWebCharset());
4123            sct.set("jreCharset",SystemUtil.getCharset());
4124            }
4125    
4126        /**
4127         * @throws PageException
4128         * 
4129         */
4130        private void doGetUpdate() throws PageException  {
4131            Struct sct=new StructImpl();
4132            pageContext.setVariable(getString("admin",action,"returnVariable"),sct);
4133            URL location = config.getUpdateLocation();
4134            if(location==null) {
4135                try {
4136                    location=new URL("http://www.getrailo.org");
4137                } 
4138                catch (MalformedURLException e) {}
4139            }
4140            String type=config.getUpdateType();
4141            if(StringUtil.isEmpty(type))type="manual";
4142            
4143            sct.set("location",location.toExternalForm());
4144            sct.set("type",type);
4145            
4146        }
4147        
4148    
4149        /**
4150         * @throws PageException
4151         * 
4152         */
4153        private void store() throws PageException {
4154            try {
4155                admin.store();
4156            } catch (Exception e) {
4157                throw Caster.toPageException(e);
4158            } 
4159        }
4160    
4161        private String getString(String tagName, String actionName, String attributeName) throws ApplicationException {
4162            String value=getString(attributeName,null);
4163            if(value==null) throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
4164            return value;
4165        }
4166    
4167        private double getDouble(String tagName, String actionName, String attributeName) throws ApplicationException {
4168            double value=getDouble(attributeName,Double.NaN);
4169            if(!Decision.isValid(value)) throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
4170            return value;
4171        }
4172    
4173        private String getString(String attributeName, String defaultValue)  {
4174            Object value=attributes.get(attributeName,null);
4175            if(value==null)return defaultValue;
4176            return Caster.toString(value,null);
4177        }
4178    
4179        private DateTime getDateTime(String attributeName, DateTime defaultValue)  {
4180            Object value=attributes.get(attributeName,null);
4181            if(value==null)return defaultValue;
4182            return DateCaster.toDateAdvanced(value, null, defaultValue);
4183        }
4184        
4185        private Object getObject(String attributeName, Object defaultValue)  {
4186            return attributes.get(attributeName,defaultValue);
4187        }
4188    
4189        private boolean getBool(String tagName, String actionName, String attributeName) throws PageException {
4190            Object value=attributes.get(attributeName,null);
4191            if(value==null)
4192                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
4193            return Caster.toBooleanValue(value);
4194        }
4195        private Boolean getBoolObject(String tagName, String actionName, String attributeName) throws PageException {
4196            Object value=attributes.get(attributeName,null);
4197            if(value==null)
4198                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
4199            if(StringUtil.isEmpty(value)) return null;
4200            return Caster.toBoolean(value);
4201        }
4202        
4203        private Object getObject(String tagName, String actionName, String attributeName) throws PageException {
4204            Object value=attributes.get(attributeName,null);
4205            if(value==null)
4206                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
4207            return value;
4208        }
4209    
4210        private boolean getBoolV(String attributeName, boolean defaultValue) {
4211            Object value=attributes.get(attributeName,null);
4212            if(value==null) return defaultValue;
4213            return Caster.toBooleanValue(value,defaultValue);
4214        }
4215    
4216        private Boolean getBool(String attributeName, Boolean defaultValue) {
4217            Object value=attributes.get(attributeName,null);
4218            if(value==null) return defaultValue;
4219            return Caster.toBoolean(value,defaultValue);
4220        }
4221        
4222        private Struct getStruct(String attributeName, Struct defaultValue) {
4223            Object value=attributes.get(attributeName,null);
4224            if(value==null) return defaultValue;
4225            try {
4226                return Caster.toStruct(value);
4227            } catch (PageException e) {
4228                return defaultValue;
4229            }
4230        }
4231       
4232        private Struct getStruct(String tagName, String actionName, String attributeName) throws PageException {
4233            Object value=attributes.get(attributeName,null);
4234            if(value==null)
4235                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
4236            return Caster.toStruct(value);
4237        }
4238        
4239        private int getInt(String tagName, String actionName, String attributeName) throws PageException {
4240            Object value=attributes.get(attributeName,null);
4241            if(value==null)
4242                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
4243            return (int)Caster.toDoubleValue(value);
4244        }
4245    
4246        private int getInt(String attributeName, int defaultValue) {
4247            Object value=attributes.get(attributeName,null);
4248            if(value==null) return defaultValue;
4249            return Caster.toIntValue(value,defaultValue);
4250        }
4251        private long getLong(String attributeName, long defaultValue) {
4252            Object value=attributes.get(attributeName,null);
4253            if(value==null) return defaultValue;
4254            return Caster.toLongValue(value,defaultValue);
4255        }
4256        
4257        private double getDouble(String attributeName, double defaultValue) {
4258            Object value=attributes.get(attributeName,null);
4259            if(value==null) return defaultValue;
4260            return Caster.toDoubleValue(value,defaultValue);
4261        }
4262        
4263        private TimeSpan getTimespan(String tagName, String actionName, String attributeName) throws PageException {
4264            Object value=attributes.get(attributeName,null);
4265            if(value==null)
4266                throw new ApplicationException("Attribute ["+attributeName+"] for tag ["+tagName+"] is required if attribute action has the value ["+actionName+"]");
4267            if(StringUtil.isEmpty(value))return null;
4268            return Caster.toTimespan(value);
4269        }
4270    
4271            private Object emptyIfNull(String str) {
4272                    if(str==null) return "";
4273                    return str;
4274            }
4275    
4276        private void throwNoAccessWhenWeb() throws ApplicationException {
4277            if(type==TYPE_WEB)throw new ApplicationException(
4278                    "you have no access for action [web."+action+"]");
4279        }
4280    
4281        private void throwNoAccessWhenServer() throws ApplicationException {
4282            if(type==TYPE_SERVER) {
4283                throw new ApplicationException(
4284                        "you have no access for action [server."+action+"]");
4285            }
4286        }
4287    }
4288    
4289    
4290    
4291    
4292    
4293    final class PluginFilter implements ResourceFilter {
4294            /**
4295         *
4296         * @see railo.commons.io.res.filter.ResourceFilter#accept(railo.commons.io.res.Resource)
4297         */
4298            public boolean accept(Resource res) {
4299            return doAccept(res);
4300        }
4301            
4302            public static boolean doAccept(Resource res) {
4303                    return res.isDirectory() && res.getRealResource("/Action.cfc").isFile() && res.getRealResource("/language.xml").isFile();
4304        }
4305    
4306    }