/* $Id: ListAccountsServlet.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 list of CGPro accounts * * @author Roman Prokhorov */ public class ListAccountsServlet extends HttpServlet { ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); 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 ListAccounts 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 list of CGPro accounts for \""+host + "\"

"); out.println("

"); out.print("

"); out.println("(sub)domain name:"); out.println(""); out.println("
"); out.println(""); out.println("
"); String domain = request.getParameter("domain"); if(domain != null) { out.println("The domain:" + domain + "
"); try { CGProCLI cli=new CGProCLI(host,106,"postmaster",adminPassword); try { Hashtable accounts=cli.listAccounts(domain); out.println(accounts.size()+ " accounts total
"); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); for(Enumeration e = accounts.keys(); e.hasMoreElements();) { String account=(String)e.nextElement(); String boxType=(String)accounts.get(account); drawAccount(out,cli,account,domain,boxType); } out.println("
AccountReal NameMailbox TypeMax sizeUsed sizeLast login
"); } catch (CGProException x) { out.println("Error:"+x.getMessage()); } cli.logout(); } catch (CGProException x) { out.println("Error:"+x.getMessage()); } } else { out.println("Please enter the domain name"); } out.println(""); out.println(""); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } private void drawAccount(PrintWriter out,CGProCLI cli,String account,String domain,String boxType) throws CGProException { out.println(""); out.println(""+account+""); if(domain!=null && domain.length()>0) account=account+"@"+domain; Hashtable settings=cli.getAccount(account); String realName=(String)settings.get("RealName"); out.println(""+CGProCLI.decodeString(realName)+""); if(boxType.equals("macnt")) boxType="MultiMailbox"; else if(boxType.equals("mbox")) boxType="TextMailbox"; else if(boxType.equals("mdir")) boxType="MailDirMailbox"; out.println(""+boxType+""); String maxAccountSize=(String)settings.get("MaxAccountSize"); if(maxAccountSize==null) maxAccountSize="*"; out.println(""+maxAccountSize+""); String storageUsed=(String)cli.getAccountInfo(account,"StorageUsed"); out.println(""+storageUsed+""); String lastLogin=(String)cli.getAccountInfo(account,"LastLogin"); out.println(""+lastLogin+""); out.println(""); } }