Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r3279 - in branches/WebAdmin/perfSONARWebAdmin: admin/sql auxiliary/sql test

Subject: perfsonar development work

List archive

perfsonar: r3279 - in branches/WebAdmin/perfSONARWebAdmin: admin/sql auxiliary/sql test


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r3279 - in branches/WebAdmin/perfSONARWebAdmin: admin/sql auxiliary/sql test
  • Date: Wed, 30 Jan 2008 02:47:18 -0500

Author: michalis
Date: 2008-01-30 02:47:18 -0500 (Wed, 30 Jan 2008)
New Revision: 3279

Added:
branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/IbatisConf.java
Modified:
branches/WebAdmin/perfSONARWebAdmin/admin/sql/SQLAdmin.java
branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/HTMLOutput.java
branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/SQLDBManager.java
branches/WebAdmin/perfSONARWebAdmin/test/ExistTesterXmlRpc.java
Log:
Committing recent code changes

Modified: branches/WebAdmin/perfSONARWebAdmin/admin/sql/SQLAdmin.java
===================================================================
--- branches/WebAdmin/perfSONARWebAdmin/admin/sql/SQLAdmin.java 2008-01-30
07:32:26 UTC (rev 3278)
+++ branches/WebAdmin/perfSONARWebAdmin/admin/sql/SQLAdmin.java 2008-01-30
07:47:18 UTC (rev 3279)
@@ -1,7 +1,12 @@
package perfSONARWebAdmin.admin.sql;

+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Iterator;
import java.util.LinkedList;
+import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@@ -61,6 +66,17 @@
super.init(config);
ServletContext sc = getServletContext();
ServicePath = sc.getRealPath("/");
+ try {
+ FileInputStream in = new
FileInputStream(ServicePath+ServicePropertiesPath);
+ Properties properties= new Properties();
+ properties.load(in);
+ String databaseType=properties.getProperty("");
+
+
+ } catch (Exception e) {
+ throw new ServletException(getFault(e));
+ }
+
}

//
-----------------------------------------------------------------------
@@ -109,7 +125,8 @@
session.setAttribute("authenticated",
false);
String userName =
request.getParameter("username");
String password =
request.getParameter("password");
- authenticator = new
AuthenticatorImpl(ServicePath+ServletPropertiesPath);
+ authenticator = new
AuthenticatorImpl(ServicePath
+ +
ServletPropertiesPath);
if
(authenticator.authenticate(userName, password)) {

session.setAttribute("authenticated", true);
output
@@ -168,54 +185,221 @@

/**
* @param request
- * @throws Exception
+ * @throws Exception
*/
private void handleDatabases(HttpServletRequest request) throws
Exception {

- String[] databases ;
- String[] tables ;
- LinkedList fields=new LinkedList();
- SQLDBManager manager = new
SQLDBManager("com.mysql.jdbc.Driver","");
- databases=manager.getDatabases();
+ String[] pr = { "Select_priv", "Insert_priv", "Update_priv",
+ "Delete_priv", "Create_priv", "Drop_priv",
"Grant_priv",
+ "References_priv", "Index_priv", "Alter_priv",
+ "Lock_tables_priv" };
+ String[] prAlias = { "SELECT", "INSERT", "UPDATE", "DELETE",
"CREATE",
+ "DROP", "GRANT OPTION", "REFERENCES",
"INDEX", "ALTER", "LOCK TABLES" };
+ Hashtable privTable=new Hashtable();
+ for(int i=0;i<pr.length;i++){
+ privTable.put(prAlias[i], pr[i]);
+ }
+ String[] databases;
+ String[] tables;
+ LinkedList fields = new LinkedList();
+ SQLDBManager manager = new
SQLDBManager("com.mysql.jdbc.Driver", "");
+ databases = manager.getDatabases();
String exec = request.getParameter("Execute");
if (exec != null) {
if (exec.equals("Show Database")) {
-
+
String database =
request.getParameter("database");
- databases=manager.getDatabases();
- tables=manager.getTables(database);
+ databases = manager.getDatabases();
+ tables = manager.getTables(database);
output.databasePage("Welcome to the users
management page!",
databases, database, tables,
null, null);
}
- if (exec.equals("Show Table Fields")) {
+
+ else if (exec.equals("Set Privileges")) {
+
+ String database =
request.getParameter("database");
+ String[] users = manager.getUsers();
+ output.privilegePage(database, null, users,
null, null, null);
+ }
+
+ else if (exec.equals("Get Privileges")) {
+
String database =
request.getParameter("databaseName");
+ String user =
request.getParameter("username");
+ String[] part = user.split("@");
+ user = part[0];
+ String host = part[1];
+ Hashtable privileges = manager
+ .getDatabasePrivileges(user,
host);
+ String[] users = manager.getUsers();
+ output.privilegePage(database, null, users,
user+"@"+host, privileges,
+ null);
+ }
+ else if (exec.equals("Grant Privileges")) {
+
+ String database =
request.getParameter("databaseName");
+ String user =
request.getParameter("username");
+ String[] part = user.split("@");
+ user = part[0];
+ String host = part[1];
+ String[]
privileges=request.getParameterValues("Privileges");
+
+
manager.grantDatabasePrivileges(database,user,host,privileges);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully granted
privileges to user <a href=\"SQLAdmin?function=databases\">Back</a>.",
+ "manage");
+ }
+
+ else if (exec.equals("Create")) {
+
+ String database =
request.getParameter("databaseName");
+ manager.createDatabase(database);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully
created the database <a href=\"SQLAdmin?function=databases\">Back</a>.",
+ "manage");
+ } else if (exec.equals("Delete")) {
+
+ String database =
request.getParameter("database");
+ manager.dropDatabase(database);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully
deleted the database <a href=\"SQLAdmin?function=databases\">Back</a>.",
+ "manage");
+ } else if (exec.equals("Show Table Fields")) {
+ String database =
request.getParameter("databaseName");
String table = request.getParameter("table");
- tables=manager.getTables(database);
- fields=manager.getTableDescription(database,
table);
+ tables = manager.getTables(database);
+ fields =
manager.getTableDescription(database, table);
output.databasePage("Welcome to the users
management page!",
databases, database, tables,
table, fields);
}
+
+ else if (exec.equals("Delete Table")) {
+ String database =
request.getParameter("databaseName");
+ String table = request.getParameter("table");
+ manager.dropTable(database, table);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully
deleted the table <a href=\"SQLAdmin?function=databases\">Back</a>.",
+ "manage");
+ } else if (exec.equals("Create Table")) {
+ String database =
request.getParameter("databaseName");
+ String table =
request.getParameter("tableName");
+ LinkedList<String[]> newFields = new
LinkedList<String[]>();
+ Iterator it =
request.getParameterMap().keySet().iterator();
+ while (it.hasNext()) {
+ String param = (String) it.next();
+ if (param.startsWith("field")) {
+ String fieldName =
request.getParameter(param);
+ if (!fieldName.equals("")) {
+ String number =
param.substring(param.length() - 1);
+ String[] field = new
String[6];
+ field[0] = fieldName;
+ field[1] =
request.getParameter("type" + number);
+ field[2] =
request.getParameter("size" + number);
+ field[3] =
request.getParameter("null" + number);
+ field[4] =
request.getParameter("default" + number);
+ field[5] =
request.getParameter("extra" + number);
+ newFields.add(field);
+ }
+
+ }
+ }
+ manager.createTable(database, table,
newFields);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully
created the table <a href=\"SQLAdmin?function=databases\">Back</a>.",
+ "manage");
+
+ }
+ else if(exec.equals("Import Data")){
+ String
database=request.getParameter("databaseName");
+ String table=request.getParameter("table");
+ String file=request.getParameter("dataFile");
+ manager.loadDataToFile(database, table, file);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully added data to
the table <a href=\"SQLAdmin?function=databases\">Back</a>.",
+ "manage");
+ }
+ else{
+ output.databasePage(
+ "Welcome to the SQL databases
management page!", databases,
+ null, null, null, null);
+ }
} else
- output.databasePage("Welcome to the users management
page!",
- databases, null, null, null, null);
+ output.databasePage(
+ "Welcome to the SQL databases
management page!", databases,
+ null, null, null, null);
}

/**
* @param request
- * @throws Exception
+ * @throws Exception
*/
private void handleUsers(HttpServletRequest request) throws Exception
{

- String[] users ;
- String[] privilages = { "SELECT", "UPDATE", "CREATE",
"DELETE", "DROP" };
- String[] databases ;
- SQLDBManager manager = new
SQLDBManager("com.mysql.jdbc.Driver","");
- databases=manager.getDatabases();
- users=manager.getUsers();
- output.usersPage("Welcome to the users management page!",
users,
- privilages, databases);
+ String[] users;
+ SQLDBManager manager = new
SQLDBManager("com.mysql.jdbc.Driver", "");
+ users = manager.getUsers();
+ String exec = request.getParameter("Execute");
+ if (exec != null) {
+ if (exec.equals("Edit User")) {
+ String user = request.getParameter("user");
+ output.usersPage("", users, user);
+ }
+ if (exec.equals("Delete User")) {
+ String user = request.getParameter("user");
+ String[] part = user.split("@");
+ user = part[0];
+ String host = part[1];
+ manager.dropUser(user, host);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully
deleted the user <a href=\"SQLAdmin?function=users\">Back</a>.",
+ "manage");
+
+ }
+ if (exec.equals("Edit")) {
+ String user =
request.getParameter("username");
+ String[] part = user.split("@");
+ user = part[0];
+ String host = part[1];
+ String password =
request.getParameter("password");
+ manager.editUser(user, host, password);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully
edited the user <a href=\"SQLAdmin?function=users\">Back</a>.",
+ "manage");
+ }
+ if (exec.equals("Create")) {
+ String user =
request.getParameter("username");
+ String host = request.getParameter("host");
+ String password =
request.getParameter("password");
+ manager.createUser(user, host, password);
+ output
+ .infoPage(
+ "Success!",
+ "Succesfully
created the user <a href=\"SQLAdmin?function=users\">Back</a>.",
+ "manage");
+ }
+ } else {
+ output.usersPage("Welcome to the SQL users management
page!",
+ users, null);
+ }
+
}
-
+
/**
* Method to get the stack trace of an exception
*

Modified: branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/HTMLOutput.java
===================================================================
--- branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/HTMLOutput.java
2008-01-30 07:32:26 UTC (rev 3278)
+++ branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/HTMLOutput.java
2008-01-30 07:47:18 UTC (rev 3279)
@@ -1,6 +1,7 @@
package perfSONARWebAdmin.auxiliary.sql;

import java.io.IOException;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;

@@ -110,67 +111,80 @@
* @param message
* @throws IOException
*/
- public void usersPage(String message, String[] users, String[]
privilages,
- String[] databases) throws IOException {
+ public void usersPage(String message, String[] users, String user)
+ throws IOException {

String display = "block";
String onClick = " onclick=\"checkIt(this);\"";
preempt("default.css", true);
out.println("<div class=\"manage\" >");
- out
- .println("<br/><p><button type=\"button\"
name=\"action\" value=\"Edit User\""
- + onClick + " >Edit
User</button>");
- out
- .println("<button type=\"button\"
name=\"action\" value=\"Create User\""
- + onClick + ">Create
User</button></p>");
- out.println("<div id=\"Edit User\" style=\"display:" +
display
- + ";\">");
+
+ out.println("<div id=\"Options\" >");
out.println("<br/>");
out.println("<form action=\"SQLAdmin\" method=\"POST\"> ");
out
.println("<input type=\"hidden\"
name=\"function\" value=\"users\" >");
- out.println("<input type=\"hidden\" name=\"action\"
value=\"Edit\" >");
out.println("<table align=\"center\">");
out.println("<tr>");
- out.println("<th>User:</th>");
- out.println("<td><select name=\"users\">");
+ out.println("<th>Choose User:</th>");
+ out.println("<td><select name=\"user\" >");
for (int i = 0; i < users.length; i++) {
- out.println("<option value =\"" + users[i] + "\">" +
users[i]
+ out.println("<option value =\"" + users[i] + "\" >" +
users[i]
+ "</option>");
}
out.println("</select></td>");
- out
- .println("<td><input type=\"submit\"
name=\"Execute\" value=\"Delete\" /></td>");
out.println("</tr>");
- out.println("<tr>");
- out.println("<th>Password:</th>");
+ out.println("</table>");
+
out
- .println("<td><input type=\"password\"
name=\"password\" value=\"\" size=20 /></td><td/>");
- out.println("</tr>");
- out.println("<tr>");
- out.println("<th>Confirm Password:</th>");
+ .println("<br/><input type=\"submit\"
name=\"Execute\" value=\"Delete User\" />");
out
- .println("<td><input type=\"password\"
name=\"confirmPassword\" value=\"\" size=20 /></td><td/>");
- out.println("</tr>");
- out.println("<tr><th>Privileges</th><td/><td/></tr>");
- for (int i = 0; i < privilages.length; i++) {
- out.println("<tr><td/><td><input type=\"checkbox\"
value =\""
- + privilages[i] + "\" >" +
privilages[i]
- + "</input></td><td/></tr>");
- }
+ .println("<input type=\"submit\"
name=\"Execute\" value=\"Edit User\" />");
out
- .println("<tr><th>Databases:</th><td><input
type=\"text\" name=\"databases\" value=\"*\" size=\"20\" /></td><td/></tr>");
- out
- .println("<tr><td><input type=\"submit\"
name=\"Execute\" value=\"Edit\" /></td><td/><td/></tr>");
- out.println("</table></form>");
+ .println("<button type=\"button\"
name=\"Execute\" value=\"Create User\""
+ + onClick + ">Create
User</button>");
+ out.println("</form>");
out.println("</div>");

+ if (user != null) {
+ out.println("<div id=\"Edit User\" style=\"display:"
+ display
+ + ";\">");
+ out.println("<br/>");
+ out
+ .println("<form action=\"SQLAdmin\"
name=\"userform\" method=\"POST\" onsubmit=\"return confirm(this)\" > ");
+ out
+ .println("<input type=\"hidden\"
name=\"function\" value=\"users\" >");
+ out
+ .println("<input type=\"hidden\"
name=\"action\" value=\"Edit\" >");
+ out.println("<input type=\"hidden\" name=\"username\"
value=\""
+ + user + "\" >");
+ out.println("<table align=\"center\">");
+ out.println("<tr>");
+ out.println("<th>User:</th>");
+ out.println("<td>" + user + "</td>");
+ out.println("<tr>");
+ out.println("<th>Password:</th>");
+ out
+ .println("<td><input
type=\"password\" name=\"password\" value=\"\" size=20 /></td><td/>");
+ out.println("</tr>");
+ out.println("<tr>");
+ out.println("<th>Confirm Password:</th>");
+ out
+ .println("<td><input
type=\"password\" name=\"confirmPassword\" value=\"\" size=20 /></td><td/>");
+ out.println("</tr>");
+ out
+ .println("<tr><td><input
type=\"submit\" name=\"Execute\" value=\"Edit\" /></td><td/><td/></tr>");
+ out.println("</table></form>");
+ out.println("</div>");
+
+ }
display = "none";
out.println("<div id=\"Create User\" style=\"display:" +
display
+ ";\">");
out.println("<br/>");
- out.println("<form action=\"SQLAdmin\" method=\"POST\"> ");
out
+ .println("<form action=\"SQLAdmin\"
name=\"userform\" method=\"POST\" onsubmit=\"return confirm(this)\" > ");
+ out
.println("<input type=\"hidden\"
name=\"function\" value=\"users\" >");
out
.println("<input type=\"hidden\"
name=\"action\" value=\"Create\" >");
@@ -188,16 +202,10 @@
out
.println("<td><input type=\"password\"
name=\"confirmPassword\" value=\"\" size=20 /></td><td/>");
out.println("</tr>");
- out.println("<tr><th>Privileges</th><td/><td/></tr>");
- for (int i = 0; i < privilages.length; i++) {
- out.println("<tr><td/><td><input type=\"checkbox\"
value =\""
- + privilages[i] + "\" >" +
privilages[i]
- + "</input></td></tr>");
- }
out
- .println("<tr><th>Databases:</th><td><input
type=\"text\" name=\"databases\" value=\"*\" size=\"20\" /></td><td/></tr>");
+ .println("<th>Host</th><td><input
type=\"text\" name=\"host\" value=\"\" size=\"20\" /></td></tr>");
out
- .println("<tr><td><input type=\"submit\"
name=\"Execute\" value=\"Edit\" /></td><td/><td/></tr>");
+ .println("<tr><td><input type=\"submit\"
name=\"Execute\" value=\"Create\" /></td><td/><td/></tr>");
out.println("</table></form>");
out.println("</div>");

@@ -243,6 +251,8 @@
out
.println("<input type=\"submit\"
name=\"Execute\" value=\"Show Database\" />");
out
+ .println("<input type=\"submit\"
name=\"Execute\" value=\"Set Privileges\" />");
+ out
.println("<button type=\"button\"
name=\"Execute\" value=\"Create Database\""
+ onClick + ">Create
Database</button>");
out.println("</form>");
@@ -261,13 +271,13 @@
out
.println("<tr><th>Database
Name:</th><td><input type=\"text\" name=\"databaseName\" value=\"*\"
size=\"20\" /></td><td/></tr>");
out
- .println("<tr><td><input type=\"submit\"
name=\"Execute\" value=\"Create Database\" /></td><td/></tr>");
+ .println("<tr><td><input type=\"submit\"
name=\"Execute\" value=\"Create\" /></td><td/></tr>");
out.println("</table></form>");
out.println("</div>");
if (database != null) {
out.println("<div id=\"showDatabase\" >");
out.println("<br/>");
- out.println("<form action=\"SQLAdmin\"
method=\"POST\"> ");
+ out.println("<form action=\"SQLAdmin\"
name=\"tableForm\" method=\"POST\"> ");
out
.println("<input type=\"hidden\"
name=\"function\" value=\"databases\" >");
out.println("<input type=\"hidden\"
name=\"databaseName\" value=\""
@@ -297,11 +307,17 @@
out
.println("<button type=\"button\"
name=\"Execute\" value=\"Create Table\""
+ onClick + ">Create
Table</button>");
+
+ onClick = " onclick=\"checkIt(this);\"";
+ out
+ .println("<button type=\"button\" name=\"Execute\"
value=\"Import Data\""
+ + onClick + ">Import Data</button>");
+
out.println("</form>");
out.println("</div>");

if (table != null) {
- out.println("<div id=\"showTable\" >");
+ out.println("<div id=\"showTable\"
style=display: block;\" >");
out.println("<br/>");
out
.println("<input
type=\"hidden\" name=\"function\" value=\"databases\" >");
@@ -326,9 +342,9 @@
out.println("<th>Default</th>");
out.println("<th>Extra</th>");
out.println("</tr>");
- Iterator it =tableFields.iterator();
- while(it.hasNext()){
- String[] fields=(String[]) it.next();
+ Iterator it = tableFields.iterator();
+ while (it.hasNext()) {
+ String[] fields = (String[])
it.next();
out.println("<tr>");
for (int i = 0; i < fields.length;
i++) {
out.println("<td>" +
fields[i] + "</td>");
@@ -365,7 +381,24 @@
.println("<tr><td><input
type=\"submit\" name=\"Execute\" value=\"Create Table\"
/></td><td/><td/><td/><td/></tr>");
out.println("</table></form>");
out.println("</div>");
+
+ out.println("<div id=\"Import Data\"
style=\"display:" + display
+ + ";\">");
+ out.println("<br/>");
+ out.println("<form action=\"SQLAdmin\"
name=\"dataForm\" method=\"POST\"> ");

+ out
+ .println("<input type=\"hidden\"
name=\"function\" value=\"databases\" />");
+ out.println("<input type=\"hidden\"
name=\"databaseName\" value=\""
+ + database + "\" />");
+ out.println("<table align=\"center\"
id=\"dataTable\">");
+ out
+ .println("<tr><td>Path to data file:</td><td><input
type=\"text\" name=\"dataFile\" value=\"\" /></td>");
+ out
+ .println("<td><input type=\"submit\"
name=\"Execute\" value=\"Import Data\" /></td></tr>");
+ out.println("</table></form>");
+ out.println("</div>");
+
}

out.println("</div>");
@@ -375,8 +408,150 @@

}

+ /**
+ * @param database
+ * @param table
+ * @throws IOException
+ */
+ public void privilegePage(String database, String table, String
users[],
+ String user, Hashtable databasePrivileges, Hashtable
tablePrivileges)
+ throws IOException {
+
+
+ preempt("default.css", true);
+ out.println("<div class=\"manage\" >");
+
+ out.println("<div id=\"Privileges\" >");
+ out.println("<br/>");
+ out.println("<form action=\"SQLAdmin\" method=\"GET\"> ");
+ out
+ .println("<input type=\"hidden\"
name=\"function\" value=\"databases\" >");
+ if (table == null) {
+
+ if (user == null) {
+ out
+ .println("<input
type=\"hidden\" name=\"databaseName\" value=\""
+ + database +
"\" >");
+
+ out.println("<table align=\"center\">");
+ out.println("<tr>");
+ out.println("<th>Database:</th>");
+ out.println("<td>" + database + "</td>");
+ out.println("</tr>");
+ out.println("<tr>");
+ out.println("<th>Choose User:</th>");
+ out.println("<td><select name=\"username\"
>");
+ for (int i = 0; i < users.length; i++) {
+ out.println("<option value =\"" +
users[i] + "\" >"
+ + users[i] +
"</option>");
+ }
+ out
+
.println("</select></td><td><input type=\"submit\" name=\"Execute\"
value=\"Get Privileges\" /></td>");
+ out.println("</tr>");
+ out.println("</table></form>");
+ out.println("</div>");
+ } else {
+ out
+ .println("<input
type=\"hidden\" name=\"databaseName\" value=\""
+ + database +
"\" >");
+ out.println("<input type=\"hidden\"
name=\"username\" value=\""
+ + user + "\" >");
+ out.println("<table align=\"center\">");
+
+ out.println("<tr>");
+ Iterator it =
databasePrivileges.keySet().iterator();
+ String key = (String) it.next();
+ String value = (String)
databasePrivileges.get(key);
+ String checked = "";
+ if (value.equalsIgnoreCase("Y")) {
+ checked = "checked";
+ }
+ out.println("<tr>");
+ out.println("<th>Database:</th>");
+ out.println("<td>" + database + "</td><td/>");
+ out.println("</tr>");
+ out.println("<tr>");
+ out.println("<th>User:</th>");
+ out.println("<td>" + user + "</td><td/>");
+ out.println("</tr>");
+ out.println("<th>Privileges:</th>");
+ out
+ .println("<td><input
type=\"checkbox\" " + checked
+ + "
name=\"privileges\" value=\"" + key
+ + "\"
/></td><td>"+key+"</td>");
+ out.println("</tr>");
+ while (it.hasNext()) {
+ key = (String) it.next();
+ value = (String)
databasePrivileges.get(key);
+ checked = "";
+ if (value.equalsIgnoreCase("Y")) {
+ checked = "checked";
+ }
+ out.println("<tr><td/><td><input
type=\"checkbox\" "
+ + checked + "
name=\"Privileges\" value=\"" + key
+ + "\"
/></td><td>"+key+"</td>");
+ out.println("</tr>");
+ }
+ out
+ .println("<tr><td><input
type=\"submit\" name=\"Execute\" value=\"Grant Privileges\"
/></td><td/></tr>");
+ out.println("</table></form>");
+
+ out.println("</div>");
+ }
+
+ } else {
+
+ out.println("<input type=\"hidden\"
name=\"databaseName\" value=\""
+ + database + "\" >");
+ out.println("<input type=\"hidden\"
name=\"tableName\" value=\""
+ + table + "\" >");
+ out.println("<table align=\"center\">");
+ out.println("<tr>");
+ out.println("<th>Database:</th>");
+ out.println("<td>" + database + "</td>");
+ out.println("</tr>");
+ out.println("<tr>");
+ out.println("<th>Table:</th>");
+ out.println("<td>" + table + "</td>");
+ out.println("</tr>");
+ out.println("<tr>");
+ out.println("<th>Choose User:</th>");
+ out.println("<td><select name=\"database\" >");
+ for (int i = 0; i < users.length; i++) {
+ out.println("<option value =\"" + users[i] +
"\" >" + users[i]
+ + "</option>");
+ }
+ out.println("</select></td>");
+ out.println("</tr>");
+ out.println("</table>");
+
+ out.println("<table align=\"center\">");
+ out.println("<tr>");
+ out.println("<th>Privileges:</th>");
+ out.println("<td><select name=\"database\" >");
+ /*
+ * for (int i = 1; i < tablePrivileges.length; i++) {
out.println("<option
+ * value =\"" + users[i] + "\" >" +
tablePrivileges[i] + "</option>"); }
+ */
+ out.println("</select></td>");
+ out.println("</tr>");
+ out
+ .println("<tr><td><input
type=\"submit\" name=\"Execute\" value=\"Grant Privileges\"
/></td><td/></tr>");
+ out.println("</table></form>");
+
+ out.println("</div>");
+
+ }
+
+ out.println("</div>");
+ out.println("</body>");
+ out.println("</html>");
+ out.close();
+
+ }
+
//
-----------------------------------------------------------------------
- // private mmathods
+ // private methods

/**
* Used by current wizard servlet

Added: branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/IbatisConf.java


Property changes on:
branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/IbatisConf.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native

Modified: branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/SQLDBManager.java
===================================================================
--- branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/SQLDBManager.java
2008-01-30 07:32:26 UTC (rev 3278)
+++ branches/WebAdmin/perfSONARWebAdmin/auxiliary/sql/SQLDBManager.java
2008-01-30 07:47:18 UTC (rev 3279)
@@ -1,23 +1,23 @@
package perfSONARWebAdmin.auxiliary.sql;

-import java.io.FileInputStream;
-import java.sql.Array;
+import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.Iterator;
import java.util.LinkedList;
-import java.util.Properties;

/**
* @author Michalis Michael,CyNet
- *
+ *
*/
public class SQLDBManager {
//
-----------------------------------------------------------------------
// class fields
-
+
// The path to the conf folder
private static final String confPath =
"WEB-INF/classes/perfsonar/conf/";

@@ -32,13 +32,19 @@
// The path to the folder under the webapps directory in which the
service
// is installed
private static String ServicePath;
-
+
private static String adminPassword;

private static String Driver;
-
+
private static String DBURI;
-
+
+ private String[] privileges;
+
+ private String[] privilegesAlias;
+
+ private Hashtable privAliasTable;
+
//
-----------------------------------------------------------------------
// constructors
/**
@@ -46,132 +52,354 @@
* @param password
* @throws Exception
*/
- public SQLDBManager(String driver,String password) throws Exception{
- Driver=driver;
- //FileInputStream in=new
FileInputStream(ServicePath+ServletPropertiesPath);
- //Properties pr= new Properties();
- //pr.load(in);
- adminPassword=password;
- if(adminPassword==null) adminPassword="";
-
- if(Driver.equals("com.mysql.jdbc.Driver")){
- DBURI="jdbc:mysql://localhost/";
+ public SQLDBManager(String driver, String password) throws Exception {
+ Driver = driver;
+ // FileInputStream in=new
+ // FileInputStream(ServicePath+ServletPropertiesPath);
+ // Properties pr= new Properties();
+ // pr.load(in);
+ adminPassword = password;
+ if (adminPassword == null)
+ adminPassword = "";
+
+ if (Driver.equals("com.mysql.jdbc.Driver")) {
+ DBURI = "jdbc:mysql://localhost/";
+ } else if (Driver.equals("org.postgresql.Driver")) {
+ DBURI = "jdbc:postgresql://localhost/";
+ } else {
+ throw new Exception("Database driver is
unsupported!");
}
- else if(Driver.equals("org.postgresql.Driver")){
- DBURI="jdbc:postgresql://localhost/";
+ String[] pr = { "Select_priv", "Insert_priv", "Update_priv",
+ "Delete_priv", "Create_priv", "Drop_priv",
"Grant_priv",
+ "References_priv", "Index_priv", "Alter_priv",
+ "Lock_tables_priv" };
+ String[] prAlias = { "SELECT", "INSERT", "UPDATE", "DELETE",
"CREATE",
+ "DROP", "GRANT OPTION", "REFERENCES",
"INDEX", "ALTER",
+ "LOCK TABLES" };
+ privileges = pr;
+ privilegesAlias = prAlias;
+ privAliasTable = new Hashtable();
+ for (int i = 0; i < pr.length; i++) {
+ privAliasTable.put(prAlias[i], pr[i]);
}
- else{
- throw new Exception("Database driver is
unsupported!");
- }
-
+
}
-
+
//
-----------------------------------------------------------------------
// public methods
-
+
/**
* @return
* @throws SQLException
* @throws Exception
*/
- public String[] getDatabases() throws SQLException, Exception{
-
+ public String[] getDatabases() throws SQLException, Exception {
+
Class.forName(Driver);
- Connection connnection =
DriverManager.getConnection(DBURI+"mysql","root", adminPassword);
- if (!connnection.isClosed()){
- String statement="SHOW DATABASES";
- PreparedStatement
ps=connnection.prepareStatement(statement);
- ResultSet rs=ps.executeQuery();
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "SHOW DATABASES";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ ResultSet rs = ps.executeQuery();
rs.last();
- String[] databases=new String[rs.getRow()];
+ String[] databases = new String[rs.getRow()];
rs.beforeFirst();
- int i=0;
- while(rs.next()){
+ int i = 0;
+ while (rs.next()) {
i++;
- databases[i-1]=rs.getString(1);
+ databases[i - 1] = rs.getString(1);
}
connnection.close();
return databases;
-
- }else{
+
+ } else {
throw new Exception("Cannot connect to database!");
}
-
-
+
}
-
+
/**
* @return
* @throws SQLException
* @throws Exception
*/
- public String[] getUsers()throws SQLException, Exception{
-
+ public String[] getUsers() throws SQLException, Exception {
+
Class.forName(Driver);
- Connection connnection =
DriverManager.getConnection(DBURI+"mysql","root", adminPassword);
- if (!connnection.isClosed()){
- String statement="SELECT user FROM user";
- PreparedStatement
ps=connnection.prepareStatement(statement);
- ResultSet rs=ps.executeQuery();
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "SELECT user,host FROM user";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ ResultSet rs = ps.executeQuery();
rs.last();
- String[] users=new String[rs.getRow()];
+ String[] users = new String[rs.getRow()];
rs.beforeFirst();
- int i=0;
- while(rs.next()){
+ int i = 0;
+ while (rs.next()) {
i++;
- users[i-1]=rs.getString(1);
+ users[i - 1] = rs.getString(1) + "@" +
rs.getString(2);
}
connnection.close();
return users;
-
- }else{
+
+ } else {
throw new Exception("Cannot connect to database!");
}
-
+
}
+
/**
+ * @param user
+ * @return
+ * @throws SQLException
+ * @throws Exception
+ */
+ public String[] getUserHosts(String user) throws SQLException,
Exception {
+
+ Class.forName(Driver);
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "SELECT host FROM user WHERE
user='" + user
+ + "'";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ ResultSet rs = ps.executeQuery();
+ rs.last();
+ String[] hosts = new String[rs.getRow()];
+ rs.beforeFirst();
+ int i = 0;
+ while (rs.next()) {
+ i++;
+ hosts[i - 1] = rs.getString(1);
+ }
+ connnection.close();
+ return hosts;
+
+ } else {
+ throw new Exception("Cannot connect to database!");
+ }
+ }
+
+ /**
+ * @param userName
+ * @param password
+ * @param host
+ * @return
+ * @throws Exception
+ */
+ public boolean createUser(String userName, String host, String
password)
+ throws Exception {
+ Class.forName(Driver);
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+
+ String statement = "CREATE USER '" + userName + "'@'"
+ host
+ + "' IDENTIFIED by '" + password +
"'";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ boolean result = ps.execute();
+ return result;
+
+ } else {
+ throw new Exception("Cannot connect to database!");
+ }
+ }
+
+ /**
+ * @param userName
+ * @param password
+ * @param host
+ * @return
+ * @throws Exception
+ */
+ public boolean editUser(String userName, String host, String password)
+ throws Exception {
+ Class.forName(Driver);
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "SET PASSWORD FOR '" + userName +
"'@'" + host
+ + "'=PASSWORD('" + password + "')";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ boolean result = ps.execute();
+ return result;
+
+ } else {
+ throw new Exception("Cannot connect to database!");
+ }
+ }
+
+ /**
+ * @param userName
+ * @return
+ * @throws Exception
+ */
+ public boolean dropUser(String userName, String host) throws
Exception {
+ Class.forName(Driver);
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ PreparedStatement ps;
+ String statement = "REVOKE ALL PRIVILEGES, GRANT
OPTION FROM '"
+ + userName + "'@'" + host + "'";
+ ps = connnection.prepareStatement(statement);
+ boolean result = ps.execute();
+ statement = "DROP USER '" + userName + "'@'" + host +
"'";
+ ps = connnection.prepareStatement(statement);
+ result = ps.execute();
+ return result;
+
+ } else {
+ throw new Exception("Cannot connect to database!");
+ }
+ }
+
+ /**
+ * @param user
+ * @param host
+ * @return
+ * @throws Exception
+ */
+ public Hashtable getDatabasePrivileges(String user, String host)
+ throws Exception {
+
+ Class.forName(Driver);
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ String statement = "SELECT ";
+ for (int i = 0; i < privileges.length; i++) {
+ statement = statement + privileges[i];
+ if (i < privileges.length - 1) {
+ statement = statement + ",";
+ }
+ }
+ if (!connnection.isClosed()) {
+ statement = statement + " FROM db WHERE user='" + user
+ + "' && host='" + host + "'";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ Hashtable<String, String> privilegesTable = new
Hashtable<String, String>();
+ ResultSet rs = ps.executeQuery();
+ rs.last();
+ if (rs.getRow() == 0) {
+ for (int i = 0; i < privilegesAlias.length;
i++) {
+
privilegesTable.put(privilegesAlias[i], "N");
+ }
+ } else {
+ rs.beforeFirst();
+ while (rs.next()) {
+ for (int i = 0; i <
privilegesAlias.length; i++) {
+
privilegesTable.put(privilegesAlias[i], rs
+ .getString(i
+ 1));
+ }
+ }
+ }
+ connnection.close();
+ return privilegesTable;
+
+ } else {
+ throw new Exception("Cannot connect to database!");
+ }
+ }
+
+ /**
+ * @param database
+ * @param user
+ * @param host
+ * @param privileges
+ */
+ public boolean grantDatabasePrivileges(String database, String user,
+ String host, String[] pr) throws Exception {
+
+ Class.forName(Driver);
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ PreparedStatement ps;
+ boolean result = false;
+ String statement = "SELECT USER from db where db='" +
database
+ + "' && User='" + user + "'&& host='"
+ host + "'";
+ ps = connnection.prepareStatement(statement);
+ ResultSet rs = ps.executeQuery();
+
+ rs.last();
+ if (rs.getRow() > 0) {
+ statement = "REVOKE ALL PRIVILEGES ON " +
database
+ + ".* FROM '" + user + "'@'"
+ host + "'";
+ ps = connnection.prepareStatement(statement);
+ result = ps.execute();
+ statement = "REVOKE GRANT OPTION ON " +
database + ".* FROM '"
+ + user + "'@'" + host + "'";
+ ps = connnection.prepareStatement(statement);
+ result = ps.execute();
+ }
+ if (pr != null) {
+ statement = "GRANT ";
+ for (int i = 0; i < pr.length; i++) {
+ statement = statement + pr[i];
+ if (i < pr.length - 1) {
+ statement = statement + ",";
+ }
+ }
+ statement = statement + " ON " + database +
".* TO '" + user
+ + "'@'" + host + "'";
+ ps = connnection.prepareStatement(statement);
+ result = ps.execute();
+ }
+
+ return result;
+
+ } else {
+ throw new Exception("Cannot connect to database!");
+ }
+ }
+
+ /**
* @param databaseName
* @return
* @throws Exception
*/
- public boolean createDatabase(String databaseName) throws Exception{
-
+ public boolean createDatabase(String databaseName) throws Exception {
+
Class.forName(Driver);
- Connection connnection =
DriverManager.getConnection(DBURI+"mysql","root", adminPassword);
- if (!connnection.isClosed()){
- String statement="CREATE DATABASE "+databaseName;
- PreparedStatement
ps=connnection.prepareStatement(statement);
- boolean result=ps.execute();
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "CREATE DATABASE " + databaseName;
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ boolean result = ps.execute();
connnection.close();
return result;
-
- }else{
+
+ } else {
throw new Exception("Cannot connect to database!");
}
}
-
+
/**
* @param database
* @return
* @throws SQLException
* @throws Exception
*/
- public boolean dropDatabase(String database)throws SQLException,
Exception{
-
+ public boolean dropDatabase(String database) throws SQLException,
Exception {
+
Class.forName(Driver);
- Connection connnection =
DriverManager.getConnection(DBURI+"mysql","root", adminPassword);
- if (!connnection.isClosed()){
- String statement="DROP DATABASE "+database;
- PreparedStatement
ps=connnection.prepareStatement(statement);
- boolean result=ps.execute();
+ Connection connnection = DriverManager.getConnection(DBURI +
"mysql",
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "DROP DATABASE " + database;
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ boolean result = ps.execute();
connnection.close();
return result;
-
- }else{
+
+ } else {
throw new Exception("Cannot connect to database!");
}
}
-
+
/**
* @param database
* @param table
@@ -179,45 +407,49 @@
* @throws SQLException
* @throws Exception
*/
- public boolean dropTable(String database,String table)throws
SQLException, Exception{
-
+ public boolean dropTable(String database, String table)
+ throws SQLException, Exception {
+
Class.forName(Driver);
- Connection connnection =
DriverManager.getConnection(DBURI+database,"root", adminPassword);
- if (!connnection.isClosed()){
- String statement="DROP TABLE"+table;
- PreparedStatement
ps=connnection.prepareStatement(statement);
- boolean result=ps.execute();
+ Connection connnection = DriverManager.getConnection(DBURI +
database,
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "DROP TABLE " + table;
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ boolean result = ps.execute();
connnection.close();
return result;
-
- }else{
+
+ } else {
throw new Exception("Cannot connect to database!");
}
}
-
- public String[] getTables(String database)throws SQLException,
Exception{
-
+
+ public String[] getTables(String database) throws SQLException,
Exception {
+
Class.forName(Driver);
- Connection connnection =
DriverManager.getConnection(DBURI+database,"root", adminPassword);
- if (!connnection.isClosed()){
- String statement="SHOW TABLES";
- PreparedStatement
ps=connnection.prepareStatement(statement);
- ResultSet rs=ps.executeQuery();
+ Connection connnection = DriverManager.getConnection(DBURI +
database,
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "SHOW TABLES";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ ResultSet rs = ps.executeQuery();
rs.last();
- String[] tables=new String[rs.getRow()];
+ String[] tables = new String[rs.getRow()];
rs.beforeFirst();
- int i=0;
- while(rs.next()){
+ int i = 0;
+ while (rs.next()) {
i++;
- tables[i-1]=rs.getString(1);
+ tables[i - 1] = rs.getString(1);
}
connnection.close();
return tables;
-
- }else{
+
+ } else {
throw new Exception("Cannot connect to database!");
}
}
+
/**
* @param database
* @param table
@@ -225,61 +457,138 @@
* @throws SQLException
* @throws Exception
*/
- public LinkedList getTableDescription(String database,String
table)throws SQLException, Exception{
-
+ public LinkedList getTableDescription(String database, String table)
+ throws SQLException, Exception {
+
Class.forName(Driver);
- Connection connnection =
DriverManager.getConnection(DBURI+database,"root", adminPassword);
- if (!connnection.isClosed()){
- String statement="DESCRIBE "+table;
- PreparedStatement
ps=connnection.prepareStatement(statement);
- ResultSet rs=ps.executeQuery();
- int i=0;
- LinkedList<String[]> tableFields= new
LinkedList<String[]>();
- while(rs.next()){
+ Connection connnection = DriverManager.getConnection(DBURI +
database,
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "DESCRIBE " + table;
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ ResultSet rs = ps.executeQuery();
+ int i = 0;
+ LinkedList<String[]> tableFields = new
LinkedList<String[]>();
+ while (rs.next()) {
i++;
- String[] fields=new String[6];
- for(int j=0;j<fields.length;j++){
- fields[j]=rs.getString(j+1);
+ String[] fields = new String[6];
+ for (int j = 0; j < fields.length; j++) {
+ fields[j] = rs.getString(j + 1);
}
tableFields.add(fields);
}
connnection.close();
return tableFields;
- }else{
+ } else {
throw new Exception("Cannot connect to database!");
}
}
-
- public static void main(String args[]){
-
+
+ /**
+ * @param database
+ * @param tableName
+ * @param fields
+ * @return
+ * @throws Exception
+ */
+ public boolean createTable(String database, String tableName,
+ LinkedList<String[]> fields) throws Exception {
+
+ Class.forName(Driver);
+ Connection connnection = DriverManager.getConnection(DBURI +
database,
+ "root", adminPassword);
+ if (!connnection.isClosed()) {
+ String statement = "CREATE TABLE " + tableName + "( ";
+ Iterator it = fields.iterator();
+ while (it.hasNext()) {
+
+ String[] field = (String[]) it.next();
+ statement = statement + field[0] + " " +
field[1] + "("
+ + field[2] + ") " + field[3]
+ " DEFAULT '" + field[4]
+ + "' " + field[5];
+ if (it.hasNext()) {
+ statement = statement + " ,";
+ }
+ }
+ statement = statement + " )";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ boolean result = ps.execute();
+ connnection.close();
+ return result;
+ } else {
+ throw new Exception("Cannot connect to database!");
+ }
+ }
+
+ /**
+ * @param database
+ * @param user
+ * @param file
+ * @return
+ * @throws Exception
+ */
+ public boolean loadDataToFile(String database, String table, String
file)
+ throws Exception {
+ Class.forName(Driver);
+ Connection connnection = DriverManager.getConnection(DBURI +
database,
+ "root", adminPassword);
+ File f = new File(file);
+ if (!f.exists()) {
+ throw new Exception("The file " + file
+ + " does not exist! Please input the
right path. ");
+ } else {
+ if (!connnection.isClosed()) {
+ String statement = "LOAD DATA INFILE '" + file
+ + "' INTO TABLE " + table;
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ boolean result = ps.execute();
+ connnection.close();
+ return result;
+
+ } else {
+ throw new Exception("Cannot connect to
database!");
+ }
+ }
+ }
+
+ public static void main(String args[]) {
+
try {
Class.forName("com.mysql.jdbc.Driver");
- Connection connnection =
DriverManager.getConnection("jdbc:mysql://192.168.10.86:3306/perfsonar_ma","root",
"michael");
- if (!connnection.isClosed()){
- String statement="SHOW DATABASES";
- PreparedStatement
ps=connnection.prepareStatement(statement);
- //ps.setString(1, "robinio");
- ResultSet rs=ps.executeQuery();
- String[] description=new String[10];
- int i=0;
+ Connection connnection = DriverManager.getConnection(
+
"jdbc:mysql://192.168.10.86:3306/perfsonar_ma", "root",
+ "michael");
+ if (!connnection.isClosed()) {
+ String statement = "SHOW DATABASES";
+ PreparedStatement ps =
connnection.prepareStatement(statement);
+ // ps.setString(1, "robinio");
+ ResultSet rs = ps.executeQuery();
+ String[] description = new String[10];
+ int i = 0;
rs.last();
- String[] databases=new String[rs.getRow()];
+ String[] databases = new String[rs.getRow()];
rs.beforeFirst();
-
- while(rs.next()){
+
+ while (rs.next()) {
i++;
-
databases[i-1]=rs.getString(1);
-
System.out.println(databases[i-1]);//+" "+rs.getString(2)+"
"+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5)+"
"+rs.getString(6));
- //users[i]=rs.getString("user");
+ databases[i - 1] = rs.getString(1);
+ System.out.println(databases[i -
1]);// +"
+ // "+rs.getString(2)+"
+ // "+rs.getString(3)+"
+ // "+rs.getString(4)+"
+ // "+rs.getString(5)+"
+ // "+rs.getString(6));
+ // users[i]=rs.getString("user");
}
-
- }else{
+
+ } else {
throw new Exception("Cannot connect to
database!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+
}
+
}

Modified: branches/WebAdmin/perfSONARWebAdmin/test/ExistTesterXmlRpc.java
===================================================================
--- branches/WebAdmin/perfSONARWebAdmin/test/ExistTesterXmlRpc.java
2008-01-30 07:32:26 UTC (rev 3278)
+++ branches/WebAdmin/perfSONARWebAdmin/test/ExistTesterXmlRpc.java
2008-01-30 07:47:18 UTC (rev 3279)
@@ -1,22 +1,5 @@
package perfSONARWebAdmin.test;
-import java.io.File;
-import java.io.FileInputStream;

-import org.exist.security.Permission;
-import org.exist.xmldb.UserManagementService;
-import org.w3c.dom.Document;
-import org.xmldb.api.base.Collection;
-import org.xmldb.api.base.Resource;
-import org.xmldb.api.base.XMLDBException;
-import org.xmldb.api.modules.XMLResource;
-import org.xmldb.api.modules.XQueryService;
-
-import perfSONARWebAdmin.auxiliary.wizard.WizardProperties;
-import perfSONARWebAdmin.auxiliary.xmlDB.XMLDocument;
-import perfSONARWebAdmin.auxiliary.xmlDB.eXistServletProperties;
-import perfSONARWebAdmin.auxiliary.xmlDB.eXistServletPropertiesImpl;
-import perfSONARWebAdmin.auxiliary.xmlDB.xmlDBCollection;
-import perfSONARWebAdmin.auxiliary.xmlDB.xmlDBCollectionImpl;
import perfSONARWebAdmin.auxiliary.xmlDB.xmlDBManager;
import perfSONARWebAdmin.auxiliary.xmlDB.xmlDBManagerImpl;

@@ -25,160 +8,30 @@

public static void main(String[] argv){

- /*try {
- // theClass = Class.forName( className, true,
Thread.currentThread().getContextClassLoader() );
- Class
clas=Class.forName("perfSONARWebAdmin.auxiliary.wizardProperties",true,
Thread.currentThread().getContextClassLoader());
- wizardProperties pr=(wizardProperties)
clas.newInstance();
- pr.setProperty("hell0", "world");
- System.out.println("Hell0"+pr.getProperty("hell0"));
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }*/
- try {
- eXistServletProperties pr=new
eXistServletPropertiesImpl("servlet.properties","service.properties");
- System.out.println(pr.getAdminPassword()+"
"+pr.getDBLocation());
- //xmlDBManager manager= new
xmlDBManagerImpl("192.168.10.86:8080/exist/xmlrpc","admin","perfsonar");
-
-
- // xmlDBCollection root = manager.getCollection(null);
- // System.out.println(root.getName());
- // manager.createCollection("mike");
- // String[] collections=manager.getCollections();
- // for(int i=0;i<collections.length;i++){
-
//System.out.println(collections[i]);
-
- // manager.createCollection("/db/testcol/no");
- //xmlDBCollection
col=manager.getCollection("/db/testcol/no");
- //col.getName();
- //System.out.println("");
- //collections=manager.getCollections();
- // for(int i=0;i<collections.length;i++){
- //
System.out.println(collections[i]);
- //}
-
- // xmlDBCollection
test=manager.getCollection("/db/testcol/no");
-
- // XMLResource res=(XMLResource)
test.getCollection().createResource("hello", "XMLResource");
-
- //res.setContent( new FileInputStream(new
File("test.xml")));
- //manager.removeCollection("aris");
- //manager.createUser("mike","mike", "pass",
null);
- //manager.createUser(null, "mike", "pass",
null);
- //manager.removeUser("mike");
- //manager.deleteCollection("mike");
- //manager.createCollection("testcol");
- //String[]group= {"dba"};
- //manager.createUser("/db", "mike", "hello",group);
- //manager.modifyUser("mike", null, null, group);
- //manager.changeUserPass("mike3", "test");
-
- //manager.changeUserPass("mike", "changedpass");
- //String[] users=manager.getUsers();
- //for(int i=0;i<users.length;i++){
- // System.out.println(users[i]);
- //}
-
- //String[]
collections=manager.getCollections();
- //for(int i=0;i<collections.length;i++){
- //System.out.println(collections[i]);
- //}
- //String childCollection="/db/shakespeare/plays";
- //xmlDBCollection root
=manager.getCollection(null);
- //xmlDBCollection currentCollection=root;
- //String[] col= childCollection.split("/");
- // for(int i=2;i<col.length;i++){
- // System.out.println(i+" "+col[i]);
- //currentCollection = new
xmlDBCollectionImpl(currentCollection.getCollection().getChildCollection(col[i]));

- // }
- //XQueryService queryService =
(XQueryService) root.getService("XPathQueryService", "1.0");
- //String resources[]=root.listResources();
-
- //for(int i=0;i<resources.length;i++){
- // System.out.println(resources[i]);
-
- //}
-
//System.out.println(root.getProperty("Group"));
- //Resource res =root.getResource("/db/mike");
- //System.out.println(res.getResourceType());
- //xmlDBCollection test =
manager.getCollection("/db/shakespeare");
- //test.getCollection().listResources();
- //test.addDocument(new
File("rrd-database_TEST.xml"), "mike3");
-
//test.removeDocument("rrd-database_TEST.xml");
- //test.chown("admin");
- //Document
doc=test.getDocument("rrd-database_TEST.xml");
-
- //test.addDocument(doc,"test.xml","mike3");
- // System.out.println("");
- //String[] docs=test.getDocuments();
- // for(int i=0;i<docs.length;i++){
- // XMLDocument
doc=test.getXMLDocument(docs[i]);
-
- // System.out.println(docs[i]+"
"+doc.getOwner()+" "+doc.getGroup()+" "+doc.getPermissions()+"
"+doc.creationDate().toString());
-
//System.out.println(doc.getDocumentAsString());
- // }
- //
System.out.print(test.getCollection().getName()+" ");
- // System.out.println(test.getOwner()+"
"+test.getGroup()+" "+test.getCreationDate()+" "+test.getPermissions());
-
- //mike.setPermissions(7, 7, 7);
- //System.out.println(mike.getPermissions());
-
//manager.getCollection("mike").setPermissions(7, 6, 5);
- //UserManagementService
service=(UserManagementService)
manager.getCollection("mike").getCollection().getService("UserManagementService",
"1.0");
- //Permission
p=service.getPermissions(mike.getCollection());
- //p.;
- //System.out.println(p.getPermissions());
- //p.setUserPermissions(7);
- //p.setGroupPermissions(5);
- //p.setPublicPermissions(7);
- //p.setPermissions(755);
- //System.out.println(p.getUserPermissions()+"
"+p.getGroupPermissions()+" "+p.getPublicPermissions());
-
//service.setPermissions(manager.getCollection("mike").getCollection(), p);
-
- //System.out.println(mike.getPermissions());
- //int user=7;
- //int group=5;
- //int other=5;
- //mike.setPermissions(user, group, other);
- //int perm= user<<6 | group<<3 | other;
- //p.setPermissions(perm);
- //p.setUserPermissions(7);
- //p.setGroupPermissions(5);
- //p.setPublicPermissions(5);
-
//service.setPermissions(manager.getCollection("mike").getCollection(), p);
-
- //System.out.println(mike.getPermissions());
-
//service.chmod(manager.getCollection("mike").getCollection(), 755);
- //int k=0;
- //k |=4;
- //k |=2;
- //k|=1;
- //int o= 3|5;
- //System.out.println(k+" "+o);
- //System.out.println("mike");
-
- } catch (Exception e) {
+
+
+ xmlDBManager manager;
+ try {
+ manager = new
xmlDBManagerImpl(argv[0],argv[1],argv[2]);
+ String[] user=manager.getUsers();
+ for(int i=0;i<user.length;i++){
+ System.out.println(user[i]);
+ }
+ } catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- //} catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- // } catch (XMLDBException e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- //} catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- //*/ catch (InstantiationException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- // } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
+
+
+
}
}



  • perfsonar: r3279 - in branches/WebAdmin/perfSONARWebAdmin: admin/sql auxiliary/sql test, svnlog, 01/30/2008

Archive powered by MHonArc 2.6.16.

Top of Page