/* $Id: ListTotalsServlet.java,v 0.0 2001/01/04 20:21:33 roma Exp $ * */ import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import com.stalker.CGPro.*; //make sure you have CGProCLI.jar file /** * Example servlet showing the total number of CGPro accounts, forwarders, groups and lists * * @author Roman Prokhorov */ public class ListTotalsServlet extends HttpServlet { ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); int totalAccounts,totalGroups,totalForwarders,totalLists; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String host,adminPassword; out.println(""); out.println(""); out.println(""); String title = "CommuniGate Pro ListTotals servlet"; out.println("" + title + ""); out.println(""); out.println(""); try { host = rb.getString("cgpro.host"); adminPassword = rb.getString("cgpro.password"); //if you can recompile this, it will be more convinient for you to //hard-code the host and password instead of reading them from a file } catch(MissingResourceException x) { out.println("Error in configuration:
"); out.println("The CGPro host address and postmaster password must be included into LocalStrings.properties file.
"); out.println(""); out.println(""); return; } out.println("

" + "The number of accounts, forwarders, groups and mailing lists for \""+host + "\"


"); try { CGProCLI cli=new CGProCLI(host,106,"postmaster",adminPassword); try { out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); Vector domains=cli.listDomains(); for(Enumeration e = domains.elements(); e.hasMoreElements();) { String domain=(String)e.nextElement(); drawDomain(out,cli,domain); } out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
DomainAccountsGroupsForwardersLists
Total:"+totalAccounts+""+totalGroups+""+totalForwarders+""+totalLists+"
"); } catch (CGProException x) { out.println("Error:"+x.getMessage()); } cli.logout(); } catch (CGProException x) { out.println("Error:"+x.getMessage()); } out.println(""); out.println(""); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } private void drawDomain(PrintWriter out,CGProCLI cli,String domain) throws CGProException { out.println(""); out.println(""+domain+""); Hashtable accounts=cli.listAccounts(domain); int nAccounts=accounts.size(); totalAccounts+=nAccounts; out.println(""+nAccounts+""); Vector groups=cli.listGroups(domain); int nGroups=groups.size(); totalGroups+=nGroups; out.println(""+nGroups+""); Vector forwarders=cli.listForwarders(domain); int nForwarders=forwarders.size(); totalForwarders+=nForwarders; out.println(""+nForwarders+""); Vector lists=cli.listLists(domain); int nLists=lists.size(); totalLists+=nLists; out.println(""+nLists+""); out.println(""); } }