From c8b6a513b9118e9d5334d9388c8ccf70387a543b Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Thu, 19 Jun 2003 20:21:20 +0000 Subject: [PATCH] some more minor mods to the module manager, and implementation of the module uninstallation page --- conf/venice-db-init-mysql.sql | 11 +- .../com/silverwrist/dynamo/iface/Module.java | 2 + .../dynamo/iface/ModuleFunctions.java | 2 + .../dynamo/index/IndexServiceImpl.java | 2 +- .../dynamo/module/ModuleLoader.java | 6 + .../dynamo/module/ModuleManager.java | 13 ++- .../dynamo/module/ModuleOperations.java | 2 + .../com/silverwrist/dynamo/testmod/Main.java | 8 ++ .../scripts/sysadmin/module_install.js | 6 + .../scripts/sysadmin/module_uninstall.js | 109 ++++++++++++++++++ .../velocity/sysadmin/module_uninstall.vm | 41 +++++++ .../sysadmin/module_uninstall_result.vm | 39 +++++++ 12 files changed, 230 insertions(+), 11 deletions(-) create mode 100644 venice-data/scripts/sysadmin/module_uninstall.js create mode 100644 venice-data/velocity/sysadmin/module_uninstall.vm create mode 100644 venice-data/velocity/sysadmin/module_uninstall_result.vm diff --git a/conf/venice-db-init-mysql.sql b/conf/venice-db-init-mysql.sql index 7aa43b8..a16fd45 100644 --- a/conf/venice-db-init-mysql.sql +++ b/conf/venice-db-init-mysql.sql @@ -1444,18 +1444,19 @@ INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link, perm_ns (8, 6, 'TEXT', 'Edit Password Reminder E-Mail Message', 'SERVLET', 'sysadmin/pwremind_email.js.vs', 12, 'set.property'); +# Create the sysadmin modules menu. (ID #9) INSERT INTO menus (menuid, menu_nsid, menu_name, title, subtitle) VALUES (9, 13, 'system.admin.module', 'Manage Modules', NULL); INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link, perm_nsid, perm_name) VALUES - (9, 0, 'TEXT', 'Return to Previous Menu', 'SERVLET', 'sysadmin/main.js.vs', NULL, + (9, 0, 'TEXT', 'Return to Previous Menu', 'SERVLET', 'sysadmin/main.js.vs', NULL, NULL ), - (9, 1, 'TEXT', 'Install New Modules', 'SERVLET', 'sysadmin/module_install.js.vs', 13, + (9, 1, 'TEXT', 'Install New Modules', 'SERVLET', 'sysadmin/module_install.js.vs', 13, 'install.modules' ), - (9, 2, 'TEXT', 'Uninstall Modules', 'SERVLET', 'sysadmin/TODO', 13, + (9, 2, 'TEXT', 'Uninstall Modules', 'SERVLET', 'sysadmin/module_uninstall.js.vs', 13, 'uninstall.modules'), - (9, 100, 'MARKER', 'begin-module-sysadmin', NULL, NULL, NULL, + (9, 100, 'MARKER', 'begin-module-sysadmin', NULL, NULL, NULL, NULL ), - (9, 65000, 'MARKER', 'end-module-sysadmin', NULL, NULL, NULL, + (9, 65000, 'MARKER', 'end-module-sysadmin', NULL, NULL, NULL, NULL ); # Create the sideboxes tables. diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/Module.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/Module.java index 3ca4d7e..e79cb9a 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/iface/Module.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/Module.java @@ -26,6 +26,8 @@ public interface Module { public QualifiedNameKey getModuleID(); + public String getDescription(); + public void install(Principal installer, DynamoLog log) throws DatabaseException, ModuleException; public void uninstall(Principal uninstaller, DynamoLog log) throws DatabaseException, ModuleException; diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/ModuleFunctions.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/ModuleFunctions.java index 28c84bf..20a4dbf 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/iface/ModuleFunctions.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/ModuleFunctions.java @@ -25,6 +25,8 @@ public interface ModuleFunctions { public QualifiedNameKey getModuleID(); + public String getDescription(); + public void initialize(ModuleSite site, ServiceProvider services) throws ModuleException; public void shutdown(); diff --git a/src/dynamo-framework/com/silverwrist/dynamo/index/IndexServiceImpl.java b/src/dynamo-framework/com/silverwrist/dynamo/index/IndexServiceImpl.java index 32e0170..f9866e3 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/index/IndexServiceImpl.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/index/IndexServiceImpl.java @@ -298,7 +298,7 @@ class IndexServiceImpl implements IndexService private final List doQuery(Query query, int offset, int count) throws IndexException { - SubsetCollector subc = new SubsetCollector(offset,count); + SubsetCollector subc = new SubsetCollector(offset,count+1); List rc = null; IndexReader irdr = null; IndexSearcher srch = null; diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleLoader.java b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleLoader.java index 812d4fa..6dc7ade 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleLoader.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleLoader.java @@ -284,6 +284,12 @@ class ModuleLoader extends URLClassLoader implements Module } // end getModuleID + public String getDescription() + { + return m_modfuncs.getDescription(); + + } // end getDescription + public synchronized void install(Principal installer, DynamoLog log) throws DatabaseException, ModuleException { if (m_ops.isModuleInstalled(m_filename)) diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleManager.java b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleManager.java index 44fd557..e19b245 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleManager.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleManager.java @@ -261,16 +261,19 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen QualifiedNameKey qname = new QualifiedNameKey(namespace,name); synchronized (this) { // look up module in hash table - ModuleLoader rc = (ModuleLoader)(m_qname_to_module.get(qname)); - if (rc!=null) - return (Module)rc; + return (Module)(m_qname_to_module.get(qname)); } // end synchronized block - return null; - } // end findModule + public synchronized Module findModuleByFilename(String filename) + { + // look for the right module already in the map + return (Module)(m_jar_to_module.get(filename)); + + } // end findModuleByFilename + public Module loadModule(String name, boolean initialize) throws ModuleException { ModuleLoader rc = null; diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleOperations.java b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleOperations.java index 1c7c13a..846d882 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleOperations.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleOperations.java @@ -29,6 +29,8 @@ public interface ModuleOperations { public Module findModule(String namespace, String name); + public Module findModuleByFilename(String filename); + public Module loadModule(String name, boolean initialize) throws ModuleException; public void freeUnusedModules(); diff --git a/src/dynamo-test-module/com/silverwrist/dynamo/testmod/Main.java b/src/dynamo-test-module/com/silverwrist/dynamo/testmod/Main.java index 8681f74..d6773af 100644 --- a/src/dynamo-test-module/com/silverwrist/dynamo/testmod/Main.java +++ b/src/dynamo-test-module/com/silverwrist/dynamo/testmod/Main.java @@ -35,6 +35,8 @@ public class Main implements ModuleFunctions private static final QualifiedNameKey ID = new QualifiedNameKey("http://www.silverwrist.com/NS/dynamo/2003/05/18/testapp","testmodule"); + private static final String DESCR = "Dynamo Test Module"; + /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- @@ -62,6 +64,12 @@ public class Main implements ModuleFunctions } // end getModuleID + public String getDescription() + { + return DESCR; + + } // end getDescription + public void initialize(ModuleSite site, ServiceProvider services) throws ModuleException { m_site = site; diff --git a/venice-data/scripts/sysadmin/module_install.js b/venice-data/scripts/sysadmin/module_install.js index 1534422..432f828 100644 --- a/venice-data/scripts/sysadmin/module_install.js +++ b/venice-data/scripts/sysadmin/module_install.js @@ -29,6 +29,12 @@ req = bsf.lookupBean("request"); req_help = bsf.lookupBean("request_help"); user = vlib.getUser(req); +// Make sure we are permitted to be here. +srm = cast.querySecurityReferenceMonitor(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"srm")); +acl = srm.getGlobalAcl(); +if (!(acl.testPermission(user,VeniceNamespaces.SYSTEM_PERMS_NAMESPACE,"install.modules"))) + dynamo.scriptReturn(vlib.stdErrorBox(req,"Security Error","You are not permitted to install modules.")); + modops = cast.queryModuleOperations(req); the_module = req_help.getParameterString("mod"); diff --git a/venice-data/scripts/sysadmin/module_uninstall.js b/venice-data/scripts/sysadmin/module_uninstall.js new file mode 100644 index 0000000..bf42c3d --- /dev/null +++ b/venice-data/scripts/sysadmin/module_uninstall.js @@ -0,0 +1,109 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importPackage(java.util); +importClass(Packages.com.silverwrist.dynamo.Namespaces); +importPackage(Packages.com.silverwrist.dynamo.except); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.module); +importPackage(Packages.com.silverwrist.dynamo.security); +importPackage(Packages.com.silverwrist.dynamo.util); +importClass(Packages.com.silverwrist.venice.VeniceNamespaces); +importPackage(Packages.com.silverwrist.venice.content); +importPackage(Packages.com.silverwrist.venice.iface); + +req = bsf.lookupBean("request"); +req_help = bsf.lookupBean("request_help"); +user = vlib.getUser(req); + +// Make sure we are permitted to be here. +srm = cast.querySecurityReferenceMonitor(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"srm")); +acl = srm.getGlobalAcl(); +if (!(acl.testPermission(user,VeniceNamespaces.SYSTEM_PERMS_NAMESPACE,"uninstall.modules"))) + dynamo.scriptReturn(vlib.stdErrorBox(req,"Security Error","You are not permitted to uninstall modules.")); + +modops = cast.queryModuleOperations(req); + +the_module = rhelp.getParameterString("mod"); +if (the_module!=null) +{ // we want to uninstall this module + rc = null; + if (vlib.confirmed(req,"/sysadmin/module_uninstall.js.vs","confirmation","confnum")) + { // OK, they have confirmed they want to uninstall the module...do it! + mod = modops.findModuleByFilename(n); + except = null; + log = new SimpleMemoryLog(); + try + { // uninstall the module + mod.uninstall(user,log); + modops.freeUnusedModules(); // GC the module list, as it were + + } // end try + catch (e) + { // save the exception + except = e; + + } // end catch + + // Return the results. + rc = new VelocityView("Module Uninstallation","sysadmin/module_uninstall_result.vm"); + rc.setParameter("module",the_module); + rc.setParameter("log",log.getLog()); + if (except!=null) + rc.setParameter("except",except); + + } // end if + else + { // generate a confirmation number box + msg = "You are about to uninstall module '" + the_module + "'! This will cause any and all data associated with " + + "this module (such as database tables and their contents) to be DESTROYED AND IRREVOCABLY LOST! " + + "Are you really sure you want to do this?"; + ok_url = "sysadmin/module_uninstall.js.vs?mod=" + stringutils.encodeURL(the_module); + rc = new ConfirmBox(req,"/sysadmin/module_uninstall.js.vs","confirmation","confnum", + "Module Uninstall Confirmation",msg,"SERVLET",ok_url,"SERVLET", + "sysadmin/module_uninstall.js.vs"); + + } // end else + + dynamo.scriptReturn(rc); + +} // end if + +// Get the set of all installed module files. +instmod = modops.listInstalledModuleNames(); + +// Turn it into a list of name/description pairs. +namelist = new ArrayList(); +it = instmod.iterator(); +while (it.hasNext()) +{ // get each module name in turn, and get the module reference + n = it.next() + ""; + mod = modops.findModuleByFilename(n); + if (mod!=null) + { // get the module's description and add it + tmp = new HashMap(); + tmp.put("name",n); + tmp.put("descr",mod.getDescription()); + namelist.add(tmp); + + } // end if + +} // end while + +// Return the Velocity view. +rc = new VelocityView("Uninstall Modules","sysadmin/module_uninstall.vm"); +rc.setParameter("modlist",namelist); +dynamo.scriptOutput(rc); diff --git a/venice-data/velocity/sysadmin/module_uninstall.vm b/venice-data/velocity/sysadmin/module_uninstall.vm new file mode 100644 index 0000000..8c56d81 --- /dev/null +++ b/venice-data/velocity/sysadmin/module_uninstall.vm @@ -0,0 +1,41 @@ +#* + The contents of this file are subject to the Mozilla Public License Version 1.1 + (the "License"); you may not use this file except in compliance with the License. + You may obtain a copy of the License at . + + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + WARRANTY OF ANY KIND, either express or implied. See the License for the specific + language governing rights and limitations under the License. + + The Original Code is the Venice Web Communities System. + + The Initial Developer of the Original Code is Eric J. Bowersox , + for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + + Contributor(s): +*# +#* + Parameters: + modlist = List of module file names which are not yet installed. +*# +#header1( "Uninstall Modules" ) +

Return to Previous Menu

+#if( $modlist.isEmpty() ) +

No modules are curently installed in the system.

+#else +

The following modules are presently installed on the system. Click a module's name to uninstall it.

+
+ + + + + #foreach( $x in $modlist ) + #set( $en = "#encodeURL( $x.name )" ) + + + + + #end +
NameDescription
#encodeHTML( $x.name )#encodeHTML( $x.descr )
+#end diff --git a/venice-data/velocity/sysadmin/module_uninstall_result.vm b/venice-data/velocity/sysadmin/module_uninstall_result.vm new file mode 100644 index 0000000..5a46d3b --- /dev/null +++ b/venice-data/velocity/sysadmin/module_uninstall_result.vm @@ -0,0 +1,39 @@ +#* + The contents of this file are subject to the Mozilla Public License Version 1.1 + (the "License"); you may not use this file except in compliance with the License. + You may obtain a copy of the License at . + + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + WARRANTY OF ANY KIND, either express or implied. See the License for the specific + language governing rights and limitations under the License. + + The Original Code is the Venice Web Communities System. + + The Initial Developer of the Original Code is Eric J. Bowersox , + for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + + Contributor(s): +*# +#* + Parameters: + module = The name of the module we were uninstalling + except = The exception that occurred if uninstall failed (null on success) + log = List containing log messages from the uninstallation +*# +#header2( "Uninstall Module:" $module ) +#if( $except ) +

The uninstallation of module #encodeHTML( $module ) failed. The following is the exception that was + thrown by uninstallation:

+
#stacktrace( $except )
+#else +

The uninstallation of module #encodeHTML( $module ) was completed successfully.

+#end +

The following are the log messages generated by module uninstallation:

+
+ #foreach( $x in $log ) + #encodeHTML( $x )
+ #end +
+

Uninstall more modules

+

Return to previous menu