org.alltimeflashdreamer.mailwebform
Class AdminServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.alltimeflashdreamer.mailwebform.AbstractMailWebFormServlet
org.alltimeflashdreamer.mailwebform.AdminServlet
- All Implemented Interfaces:
- MailWebFormConstants, Serializable, Servlet, ServletConfig
- public class AdminServlet
- extends AbstractMailWebFormServlet
Title: AdminServlet
Description: This is the controller servlet of the admin tool which allows
the administrator of the current MailWebForm installation to configure the
registered providers "on-line", i.e. using the browser. These settings
could be edited in the mailwebform.properties file manually, but because
the file resides on the serlvet runner's host machine and the application
is malfunctioning in case the file isn't edited properly, it's much easier
and safer to use this servlet.
The admin tool has several different sites/views: The login screen, the
main window and the edit provider settings screen. The tasks of these sites
are:
-
Login Window: In case it's the first time the administrator accesses
the admin tool, no login/password file of the administrator exists yet.
Therefore, the application accepts the first login as the reference and
stores the login and the password within the specified file (the password
is MD5 encoded). Each following access references the contents of the file.
If one wants to reset the login, he's got to delete the file. Because the
password file should be accessible for the administrator on the file system
only, it's assured that only the one who installed MailWebForm is able to
reset/change the admin account.
-
Main Window: The application's main window lists up the registered
providers (which contains at least of the built-in system account). On this
screen, the administrator may add a new, edit or remove an existing, change
the admin credentials or the password of an existing provider. Removing of
a provider is only allowed if it's not the system provider, because this
account contains the applications default/main settings which must be
defined (else the application doesn't work!). In case of removing a
provider, a JavaScript prompt asks you for comitting the deletion (enter a
"y" if you really want to remove a provider), but of course only if
JavaScript is activated and not filtered out of the stream by a firewall.
-
Edit Provider Window: In case the "add new provider" button was
clicked, the user must choose a previously unused provider name (selecting
an already defined one leads to an exception) and enter this provider's
settings, as for an existing one.
In case the "edit selected provider" button was clicked, the user may edit
the settings of the selected provider. If the selected provider is a
"normal" one, these settings are "PROVIDERDIRECTORY" (which is the
directory of the provider's own overriding file and the mail template),
"TONAME", "TOADDRESS" (the name and the address to be used to send
MailWebForm's generated mails to, i.e. the creator of the mail sending
site), "SMTP_ALLOWOVERWRITE" (is the provider allowed to use an overriding
file, the default SMTP server settings entered by the administrator are
replaced with those settings) and "TEMPLATE" (name of the mail template to
be used). If the selected one is the provider named "system", the
application's default/global settings may be edited too, which are
"SMTP_HOST", "SMTP_PORT" (the default server to send the generated mails
to), "SUCCESS_URL", "ERROR_URL" (the sites to redirect the mail writer to
in case of successful or unsuccessful sending of the mail) and
"SPAMERROR_URL" (the site to redirect the client to in case he tried to
abuse MailWebForm, using illegal command line parameters), but neither an
overwrite path nor a template file may be defined, because the system
provider is not allowed to have such files.
-
Edit Admin Credentials / Provider Password Window: On this page, the
administrator may change the user name and the password of the admin
account itself or set a password for a specific provider. Since the
passwords are stored as a MD5-encoded string, this feature is absolutely
required.
-
Edit Individual Provider Window: In case the administrator set a
password for a certain provider, the application allows to log in using
this provider's name and the specified password. Having logged in using
this account, one can change the individual settings of a provider, i.e.
those that override the default ones defined by the administrator.
Restrictions on the provider settings are as follows:
-
The provider names must be valid Java identifiers, as described in the
java.lang.Character class, methods isJavaIdentifierStart and
isJavaIdentifierPart. To make it short: Don't use any "special" signs, i.e.
only characters and perhaps an underscore.
-
The provider names must be unique (case-insensitive check!).
-
A provider's own overriding file is named "<somehow>.properties" and
resides in the directory defined within the provider's settings (see
"PROVIDERDIRECTORY" description above) or in the application's dedicated
config directory, if this property isn't set. Therefore, this setting is
optional.
-
The "to name" setting is optional. If it isn't defined, the generated mail's
address line doesn't contain a recipient's name specification, i.e. the
address only.
-
The "provider is allowed to override" setting's hard-coded default is true
(stored as "YES"). If one wants to change this value to false, he must
unselect the corresponding checkbox.
-
The system provider's redirection URL's are optional. If such a site isn't
defined anywhere (neither for the system nor for the site provider),
MailWebForm prints it's own, unformatted, debug-like output.
-
The mail template setting is optional. If none is defined, MailWebForm
formats the mail by first adding the user-specific URL parameters, one at a
line, followed by a separator line and the mail text. If the setting is
defined, MailWebForm parses the template and replaces the placeholders with
the URL parameters having the same name (case-insensitive check).
- Version:
- 0.9
- Author:
- Copyright (c) 2001-2004 Florian Steinsiepe, Adrian Zaugg
- See Also:
- Serialized Form
Fields inherited from interface org.alltimeflashdreamer.mailwebform.MailWebFormConstants |
ADMIN, ADMINSERVLET, APPNAME, COOKIENAME, CURRENTUSER, ERROR_URL, FILESEPARATOR, JSPBEAN, MAILFORMPROVIDER, MAILFORMPROVIDERLIST, MAILWEBFORM, MAILWEBFORMSERVLET, NEWLINE, PARAM_ADD, PARAM_APPLYGLOBAL, PARAM_APPLYINDIVIDUAL, PARAM_CANCEL, PARAM_CHANGE_CREDENTIALS, PARAM_CONFIGFILE, PARAM_CREDENTIALS_ADMIN, PARAM_EDIT, PARAM_ERRORURL, PARAM_FROMEMAIL, PARAM_FROMNAME, PARAM_LOGIN, PARAM_LOGOUT, PARAM_OVERWRITE, PARAM_PASSWORD, PARAM_PASSWORD_PROVIDER, PARAM_PROVIDER, PARAM_PROVIDERDIRECTORY, PARAM_REMOVE, PARAM_SMTPHOST, PARAM_SMTPPORT, PARAM_SPAMURL, PARAM_STORE, PARAM_SUBJECT, PARAM_SUCCESSURL, PARAM_TEMPLATE, PARAM_TEXT, PARAM_TOADDRESS, PARAM_TONAME, PARAM_USERNAME, PASSWORD, PASSWORDFILE, PLACEHOLDER_END, PLACEHOLDER_START, PROPERTY_CONFIGDIR, PROPERTY_SUFFIX, PROVIDERDIRECTORY, RESOURCENAME, SITE_CHANGE_CREDENTIALS, SITE_DEFAULTFORM, SITE_EDIT, SITE_ERROR, SITE_FOOTER, SITE_HEADER, SITE_LOGIN, SITE_MAIN, SITE_PROVIDER, SMTP_ALLOWOVERWRITE, SMTP_HOST, SMTP_PORT, SPAMERROR_URL, SUCCESS_URL, SYSTEMPROVIDER, TEMPLATE, TEMPLATE_SUFFIX, TOADDRESS, TONAME, USERNAME |
Method Summary |
void |
destroy()
Cleans up pointers and closes resources. |
void |
doGet(HttpServletRequest request,
HttpServletResponse response)
Since this servlet makes no distinction between a GET and a POST, pass
the GET requests over to the doPost method. |
void |
doPost(HttpServletRequest request,
HttpServletResponse response)
This method can be called from different contexts, i.e. with different
request parameters. |
(package private) static String |
getConfigDirProperty()
Reads the system property defining the app's config directory. |
(package private) File |
getCredentialsFile()
Returns the abstract File instance pointing to the user credentials
file. |
(package private) String |
getParameterIgnoreCase(HttpServletRequest request,
String sKey)
Searches the list of parameter names case-insensitively for the given
key and returns the first value, if found. |
(package private) String[] |
getParameterValuesIgnoreCase(HttpServletRequest request,
String sKey)
Searches the list of parameter names case-insensitively for the given
key and returns the value list, if found. |
(package private) File |
getPropertyFile()
Returns the abstract File instance pointing to the global properties
file. |
(package private) void |
printOutput(String sText,
HttpServletResponse response)
Prints the given text to the response's output writer, flushes and
finally closes it. |
(package private) void |
readGlobalProperties()
Reads the settings from the global properties file which must reside in
the application classes' root folder. |
(package private) void |
showErrorScreen(MailWebFormException mwfe,
HttpServletRequest request,
HttpServletResponse response)
Wraps the given error message into the JSPBean and redirects the client
to the error page. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
globalProperties
GlobalProperties globalProperties
- Properties instance storing the values read from the global properties
file
mailFormProviders
MailFormProviderList mailFormProviders
- the list of known providers of a mailwebform hosted by this servlet,
including the "system" provider
AdminServlet
public AdminServlet()
doPost
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException
- This method can be called from different contexts, i.e. with different
request parameters. The servlet then decides which mode is "active" and
reacts accordingly.
The possible modes are:
-
First call: Shows the login screen to the caller
-
Main screen: The client sees the list of registered providers. On this
screen, he's able to add, edit or remove providers.
-
Provider settings screen: The user is able to edit a certain amount of
settings of the currently selected provider. This number is varying
depending on whether it's a new, an existing or the system provider.
-
Action call ("logical site"): This mode is called lots of times, i.e.
each time the administrator executes an action, such as logging in,
changing the view, storing added or edited data or remove a provider.
-
Individual provider screen: If the user logs in as a provider directly,
he's able to edit the individual settings of a provider, i.e. those
that override the global/default ones.
-
Change admin credentials / provider password: The user may change the
login name and/or the password of the admin account itself or the
password of the previously selected provider.
- Specified by:
doPost
in class AbstractMailWebFormServlet
- Parameters:
request
- contains the request parameters we need to haveresponse
- contains the client's url to write to
- Throws:
ServletException
- in case problems occurred within the servlet
container
IOException
- in case problems occurred accessing a properties
file
doGet
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
IOException
- Since this servlet makes no distinction between a GET and a POST, pass
the GET requests over to the doPost method.
- Parameters:
request
- (see description of implementing doPost method)response
- (see description of implementing doPost method)
- Throws:
ServletException
- (see description of implementing doPost method)
IOException
- (see description of implementing doPost method)
readGlobalProperties
void readGlobalProperties()
throws MailWebFormException
- Reads the settings from the global properties file which must reside in
the application classes' root folder. In case this file isn't found,
the upcoming exception is wrapped into a ServletException which is
thrown, for convenience with each possible caller method.
- Throws:
MailWebFormException
- wrapped and commented IOException, if one was
thrown
getPropertyFile
File getPropertyFile()
throws MailWebFormException
- Returns the abstract File instance pointing to the global properties
file. If the file doesn't exist or the servlet runner user can't write
to it, an exception is thrown.
- Returns:
- the global property file wrapper
- Throws:
MailWebFormException
- if the file is missing or not editable
getCredentialsFile
File getCredentialsFile()
throws MailWebFormException
- Returns the abstract File instance pointing to the user credentials
file.
- Returns:
- the user credentials file wrapper
- Throws:
MailWebFormException
- if the system's configdir property isn't
set
getConfigDirProperty
static String getConfigDirProperty()
throws MailWebFormException
- Reads the system property defining the app's config directory. If this
property isn't set, an exception is thrown since the app can't work
without this directory.
- Returns:
- the path to the config dir, containing forward slashes only
and ending with such a forward slash
- Throws:
MailWebFormException
- if the property isn't defined
getParameterIgnoreCase
String getParameterIgnoreCase(HttpServletRequest request,
String sKey)
- Searches the list of parameter names case-insensitively for the given
key and returns the first value, if found.
- Parameters:
request
- what to query for the URL parameterssKey
- the key that shall case-insensitively be searched for
- Returns:
- the first parameter value, if found, else null
getParameterValuesIgnoreCase
String[] getParameterValuesIgnoreCase(HttpServletRequest request,
String sKey)
- Searches the list of parameter names case-insensitively for the given
key and returns the value list, if found.
- Parameters:
request
- what to query for the URL parameterssKey
- the key that shall case-insensitively be searched for
- Returns:
- the list parameter values, if found, else null
printOutput
void printOutput(String sText,
HttpServletResponse response)
throws IOException
- Prints the given text to the response's output writer, flushes and
finally closes it.
- Parameters:
sText
- a text that is wrapped into a very simple HTML pageresponse
- contains the client's url to write to
- Throws:
IOException
- thrown by the PrintWriter class, if any
showErrorScreen
void showErrorScreen(MailWebFormException mwfe,
HttpServletRequest request,
HttpServletResponse response)
throws IOException
- Wraps the given error message into the JSPBean and redirects the client
to the error page.
- Parameters:
mwfe
- the application-specific error object that is to be renderedrequest
- the client's request objectresponse
- used for redirecting the client
- Throws:
IOException
- thrown by the PrintWriter class, if any
destroy
public void destroy()
- Cleans up pointers and closes resources.
- Specified by:
destroy
in interface Servlet