added admin functions for viewing audit records; gave users the ability

to set their default language and time zone preferences; added footer text
and account signup accept/decline rules; added additional implementation
of dictyionary code for future; minor cleanup of rendering config; and
so forth
This commit is contained in:
Eric J. Bowersox
2001-03-25 08:10:07 +00:00
parent a258f6ee80
commit 15a7fa56d2
31 changed files with 1315 additions and 62 deletions

View File

@@ -176,12 +176,26 @@ public class Account extends VeniceServlet
return new ErrorBox("Error","You cannot create a new account while logged in on an existing "
+ "one. You must log out first.",tgt);
// display the "Create Account" dialog
NewAccountDialog dlg = makeNewAccountDialog();
dlg.setEngine(engine);
dlg.setTarget(tgt);
dlg.setFieldValue("country","US");
return dlg;
final String yes = "yes";
if (yes.equals(request.getParameter("agree")))
{ // display the "Create Account" dialog
NewAccountDialog dlg = makeNewAccountDialog();
dlg.setEngine(engine);
dlg.setTarget(tgt);
dlg.setFieldValue("country","US");
return dlg;
} // end if
else
{ // display the account terms dialog
String[] choices = new String[2];
choices[0] = "account?cmd=C&agree=yes&tgt=" + URLEncoder.encode(tgt);
choices[1] = "top";
return new TextMessageDialog(TextMessageDialog.TYPE_ACCEPT_DECLINE,
rdat.getStockMessage("user-agreement-title"),
rdat.getStockMessage("user-agreement"),choices);
} // end else
} // end if ("C" command)

View File

@@ -254,6 +254,47 @@ public class SIGAdmin extends VeniceServlet
} // end if ("M" command)
if (cmd.equals("A"))
{ // "A" = "Display Audit Records"
try
{
int offset = 0;
try
{ // convert the offset parameter
String s_ofs = request.getParameter("ofs");
if (!StringUtil.isStringEmpty(s_ofs))
offset = Integer.parseInt(s_ofs);
} // end try
catch (NumberFormatException nfe)
{ // if it's untranslatable, set it at 0
offset = 0;
} // end catch
// generate the lists
List audit_list = sig.getAuditRecords(offset,engine.getNumAuditRecordsPerPage());
int audit_count = sig.getAuditRecordCount();
// return the audit viewer
return new AuditDataViewer(engine,audit_list,offset,audit_count,"Audit Records for SIG \""
+ sig.getName() + "\"","sigadmin?sig=" + sig.getSIGID() + "&cmd=A&ofs=%");
} // end try
catch (AccessError ae)
{ // you don't have access
return new ErrorBox("Access Error",ae.getMessage(),on_error);
} // end catch
catch (DataException de)
{ // something wrong in the database
return new ErrorBox("Database Error","Database error getting audit records: " + de.getMessage(),
on_error);
} // end catch
} // end if ("A" command)
if (cmd.equals("DEL"))
{ // "DEL" = "Delete SIG" (requires a confirmation)
if (!(sig.canDelete()))

View File

@@ -18,9 +18,11 @@
package com.silverwrist.venice.servlets;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.servlets.format.*;
@@ -82,7 +84,50 @@ public class SystemAdmin extends VeniceServlet
if (logger.isDebugEnabled())
logger.debug("SystemAdmin/doGet command value = " + cmd);
// TODO: command handling
if (cmd.equals("A"))
{ // "A" = View System Audit Records
try
{ // get the list of audit records
AdminOperations adm = user.getAdminInterface();
int offset = 0;
try
{ // convert the offset parameter
String s_ofs = request.getParameter("ofs");
if (!StringUtil.isStringEmpty(s_ofs))
offset = Integer.parseInt(s_ofs);
} // end try
catch (NumberFormatException nfe)
{ // if it's untranslatable, set it at 0
offset = 0;
} // end catch
// generate the lists
List audit_list = adm.getAuditRecords(offset,engine.getNumAuditRecordsPerPage());
int audit_count = adm.getAuditRecordCount();
// return the audit viewer
setMyLocation(request,"sysadmin?cmd=A&ofs=" + offset);
return new AuditDataViewer(engine,audit_list,offset,audit_count,"System Audit Records",
"sysadmin?cmd=A&ofs=%");
} // end try
catch (AccessError ae)
{ // an access error generally means we're not an administrator
return new ErrorBox("Access Error","You do not have permission to administer the system.",null);
} // end catch
catch (DataException de)
{ // error pulling the audit records
return new ErrorBox("Database Error","Unable to retrieve audit records: " + de.getMessage(),
"sysadmin");
} // end catch
} // end if ("A" command)
// TODO: other command handling
if (!(user.hasAdminAccess()))
return new ErrorBox("Access Error","You do not have permission to administer the system.",null);

View File

@@ -0,0 +1,152 @@
/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format;
import java.io.*;
import java.util.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.*;
public class AuditDataViewer implements ContentRender
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private List audit_list;
private int offset;
private int total_count;
private int last_index;
private String title;
private String next_url;
private String prev_url;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public AuditDataViewer(VeniceEngine engine, List audit_list, int offset, int total_count, String title,
String template_url)
{
this.audit_list = audit_list;
this.offset = offset;
this.total_count = total_count;
int npage = engine.getNumAuditRecordsPerPage();
this.last_index = offset + npage;
if (this.last_index>total_count)
this.last_index = total_count;
this.title = title;
if (this.last_index<total_count)
this.next_url = StringUtil.replaceAllInstances(template_url,"%",String.valueOf(offset+npage));
else
this.next_url = null;
if (offset>0)
this.prev_url = StringUtil.replaceAllInstances(template_url,"%",String.valueOf(offset-npage));
else
this.prev_url = null;
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface VeniceContent
*--------------------------------------------------------------------------------
*/
public String getPageTitle(RenderData rdat)
{
return title;
} // end getPageTitle
/*--------------------------------------------------------------------------------
* Implementations from interface ContentRender
*--------------------------------------------------------------------------------
*/
public void renderHere(Writer out, RenderData rdat) throws IOException
{
rdat.writeContentHeader(out,title,null);
// Write the informational and navigational table
out.write("<TABLE WIDTH=\"100%\" BORDER=0><TR VALIGN=MIDDLE><TD ALIGN=LEFT>" + rdat.getStdFontTag(null,2));
out.write("\nDisplaying records <B>" + (offset+1) + "</B> to <B>" + last_index + "</B> of <B>"
+ total_count + "</B>\n");
out.write("</FONT></TD><TD ALIGN=RIGHT>\n");
if (prev_url==null)
out.write("<IMG SRC=\"" + rdat.getFullImagePath("bn_transparent.gif")
+ "\" ALT=\"\" WIDTH=80 HEIGHT=24 BORDER=0>\n");
else
out.write("<A HREF=\"" + rdat.getEncodedServletPath(prev_url) + "\"><IMG SRC=\""
+ rdat.getFullImagePath("bn_ar_previous.gif")
+ "\" ALT=\"Previous\" WIDTH=80 HEIGHT=24 BORDER=0></A>");
out.write("&nbsp;");
if (next_url==null)
out.write("<IMG SRC=\"" + rdat.getFullImagePath("bn_transparent.gif")
+ "\" ALT=\"\" WIDTH=80 HEIGHT=24 BORDER=0>\n");
else
out.write("<A HREF=\"" + rdat.getEncodedServletPath(next_url) + "\"><IMG SRC=\""
+ rdat.getFullImagePath("bn_ar_next.gif")
+ "\" ALT=\"Next\" WIDTH=80 HEIGHT=24 BORDER=0></A>");
out.write("\n</TD></TR></TABLE>\n");
// Start writing the table containing the actual audit records.
String tb_font = rdat.getStdFontTag(null,2);
out.write("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=3>\n");
out.write("<TR>\n<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>Date/Time</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>Description</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>User</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>SIG</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT NOWRAP>" + tb_font + "<B>IP Address</B></FONT></TH>\n");
out.write("<TH ALIGN=LEFT COLSPAN=4 NOWRAP>" + tb_font + "<B>Additional Data</B></FONT></TH>\n</TR>\n");
Iterator it = audit_list.iterator();
while (it.hasNext())
{ // display each record in turn
AuditData dat = (AuditData)(it.next());
out.write("<TR>\n<TD ALIGN=LEFT NOWRAP>" + tb_font
+ rdat.formatDateForDisplay(dat.getDateTime()) + "</FONT></TD>\n");
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getDescription()) + "</FONT></TD>\n");
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getUserName()) + "</FONT></TD>\n");
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getSIGName()) + "</FONT></TD>\n");
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font
+ StringUtil.encodeHTML(dat.getIPAddress()) + "</FONT></TD>\n");
for (int i=0; i<AuditData.DATA_COUNT; i++)
{ // write the data values
out.write("<TD ALIGN=LEFT NOWRAP>" + tb_font);
if (dat.getData(i)!=null)
out.write(StringUtil.encodeHTML(dat.getData(i)));
else
out.write("&nbsp;");
out.write("</FONT></TD>\n");
} // end for
out.write("</TR>\n");
} // end while
out.write("</TABLE>\n");
rdat.writeFooter(out);
} // end renderHere
} // end class AuditDataViewer

View File

@@ -36,6 +36,7 @@ public class CDTimeZoneListFormField extends CDPickListFormField
TimeZoneList()
{
array = TimeZone.getAvailableIDs();
Arrays.sort(array);
} // end constructor

View File

@@ -54,7 +54,6 @@ public class RenderConfig
private boolean want_comments;
private boolean allow_gzip;
private String font_face;
private String base_url;
private String image_url;
private String static_url;
private String site_logo;
@@ -130,17 +129,6 @@ public class RenderConfig
} // end if
DOMElementHelper paths_sect_h = new DOMElementHelper(paths_sect);
base_url = paths_sect_h.getSubElementText("base");
if (base_url==null)
{ // no <base/> tag - bail out now!
logger.fatal("<paths/> section has no <base/> element");
throw new ConfigException("no <base/> found in <paths/> section",paths_sect);
} // end if
if (logger.isDebugEnabled())
logger.debug("Base path: " + base_url);
image_url = paths_sect_h.getSubElementText("image");
if (image_url==null)
{ // no <image/> tag - bail out now!
@@ -284,14 +272,6 @@ public class RenderConfig
} // end isGZIPAllowed
String getFullServletPath(String name)
{
StringBuffer buf = new StringBuffer();
buf.append(base_url).append(name);
return buf.toString();
} // end getFullServletPath
String getFullImagePath(String name)
{
StringBuffer buf = new StringBuffer();
@@ -341,6 +321,14 @@ public class RenderConfig
} // end getStdFontTag
String getStdBaseFontTag(int size)
{
StringBuffer buf = new StringBuffer("<BASEFONT FACE=\"");
buf.append(font_face).append("\" SIZE=").append(size).append('>');
return buf.toString();
} // end getStdBaseFontTag
public String getRequiredBullet()
{
StringBuffer buf = new StringBuffer("<FONT FACE=\"");
@@ -351,9 +339,15 @@ public class RenderConfig
void writeFooter(Writer out) throws IOException
{
out.write("<HR WIDTH=\"80%\"><DIV ALIGN=\"CENTER\">\n<IMG SRC=\"");
out.write("<HR WIDTH=\"80%\">\n<TABLE ALIGN=CENTER BORDER=0 CELLPADDING=0 CELLSPACING=6><TR VALIGN=TOP>"
+ "\n<TD ALIGN=RIGHT>\n");
out.write(getStdFontTag(null,1));
out.write(getStockMessage("footer-text"));
out.write("</FONT>\n</TD>\n<TD ALIGN=LEFT>\n<A HREF=\"http://venice.sourceforge.net\" TARGET=\"_blank\">"
+ "<IMG SRC=\"");
out.write(getFullImagePath("powered-by-venice.gif"));
out.write("\" ALT=\"Powered by Venice\" WIDTH=140 HEIGHT=80 HSPACE=0 VSPACE=0>\n</DIV>\n");
out.write("\" ALT=\"Powered by Venice\" WIDTH=140 HEIGHT=80 BORDER=0 HSPACE=0 VSPACE=0></A>\n</TD>\n"
+ "</TR></TABLE>\n");
} // end writeFooter

View File

@@ -137,13 +137,15 @@ public class RenderData
public String getFullServletPath(String name)
{
return rconf.getFullServletPath(name);
StringBuffer buf = new StringBuffer(request.getContextPath());
buf.append('/').append(name);
return buf.toString();
} // end getFullServletPath
public String getEncodedServletPath(String name)
{
return response.encodeURL(rconf.getFullServletPath(name));
return response.encodeURL(this.getFullServletPath(name));
} // end getEncodedServletPath
@@ -171,6 +173,12 @@ public class RenderData
} // end getStdFontTag
public String getStdBaseFontTag(int size)
{
return rconf.getStdBaseFontTag(size);
} // end getStdBaseFontTag
public String getTitleTag(String specific)
{
return rconf.getTitleTag(specific);
@@ -306,7 +314,7 @@ public class RenderData
public void redirectTo(String servlet) throws IOException
{
String url = response.encodeRedirectURL(rconf.getFullServletPath(servlet));
String url = response.encodeRedirectURL(this.getFullServletPath(servlet));
response.sendRedirect(url);
} // end redirectTo

View File

@@ -36,6 +36,7 @@ public class SIGAdminTop extends ContentMenuPanel
addChoice("Set SIG Category","sigadmin?sig=$s&cmd=T");
addChoice("Set SIG Features","sigadmin?sig=$s&cmd=F");
addChoice("Membership Control","sigadmin?sig=$s&cmd=M");
addChoice("Display Audit Records","sigadmin?sig=$s&cmd=A");
// TODO: More options
addChoice("Delete SIG","sigadmin?sig=$s&cmd=DEL");

View File

@@ -34,6 +34,7 @@ public class SystemAdminTop extends ContentMenuPanel
addChoice("Set Global Parameters","TODO");
addChoice("View/Edit Banned Users","TODO");
addChoice("User Account Management","TODO");
addChoice("System Audit Logs","sysadmin?cmd=A");
} // end constructor

View File

@@ -0,0 +1,156 @@
/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.htmlcheck.*;
import com.silverwrist.venice.core.*;
public class TextMessageDialog implements ContentRender
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
// Dialog types
public static final int TYPE_ACCEPT_DECLINE = 0;
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private int type;
private String title;
private String text;
private String[] choices;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public TextMessageDialog(int type, String title, String text, String[] choices)
{
this.type = type;
this.title = title;
this.text = text;
this.choices = choices;
int nbutton = getNumButtons(type);
if (choices.length<nbutton)
throw new InternalStateError("insufficient elements in choices array");
} // end constructor
/*--------------------------------------------------------------------------------
* Internal overrideable operations
*--------------------------------------------------------------------------------
*/
protected int getNumButtons(int xtype)
{
if (xtype==TYPE_ACCEPT_DECLINE)
return 2;
throw new InternalStateError("invalid TextMessageDialog type :" + type);
} // end getNumButtons
protected String getImageNameForButton(int xtype, int ndx)
{
if (xtype==TYPE_ACCEPT_DECLINE)
{ // accept or decline
if (ndx==0)
return "bn_i_accept.gif";
else if (ndx==1)
return "bn_i_decline.gif";
throw new InternalStateError("invalid button index: " + ndx);
} // end if
throw new InternalStateError("invalid TextMessageDialog type :" + type);
} // end getImageNameForButton
protected String getAltTextForButton(int xtype, int ndx)
{
if (xtype==TYPE_ACCEPT_DECLINE)
{ // accept or decline
if (ndx==0)
return "I Accept";
else if (ndx==1)
return "I Decline";
throw new InternalStateError("invalid button index: " + ndx);
} // end if
throw new InternalStateError("invalid TextMessageDialog type :" + type);
} // end getImageNameForButton
/*--------------------------------------------------------------------------------
* Implementations from interface VeniceContent
*--------------------------------------------------------------------------------
*/
public String getPageTitle(RenderData rdat)
{
return title;
} // end getPageTitle
/*--------------------------------------------------------------------------------
* Implementations from interface ContentRender
*--------------------------------------------------------------------------------
*/
public void renderHere(Writer out, RenderData rdat) throws IOException
{
rdat.writeContentHeader(out,title,null);
out.write(rdat.getStdFontTag(null,2));
out.write("\n");
out.write(text);
out.write("</FONT><P>\n<DIV ALIGN=\"center\">\n");
int nbutton = getNumButtons(type);
for (int i=0; i<nbutton; i++)
{ // write out the individual buttons
if (i>0)
out.write("&nbsp;\n");
out.write("<A HREF=\"");
out.write(rdat.getEncodedServletPath(choices[i]));
out.write("\"><IMG SRC=\"");
out.write(rdat.getFullImagePath(getImageNameForButton(type,i)));
out.write("\" ALT=\"");
out.write(getAltTextForButton(type,i));
out.write("\" WIDTH=80 HEIGHT=24 BORDER=0></A>\n");
} // end for
out.write("</DIV>\n");
rdat.writeFooter(out);
} // end renderHere
} // end class TextMessageDialog