package com.sun.sysid.core;

import com.sun.wizards.core.*;
import com.sun.sysid.core.*;
import java.util.*;
import java.io.*;


public class SysIDServerObject implements ServerObject, Serializable
{
  
  private transient WizardState wizardState = null;
  static boolean rtcSet = false;

  public SysIDServerObject()
    {
    }
  
  public void setWizardState(WizardState wizardState)
    {
      this.wizardState = wizardState;

    }
  
  public void setupKiosk()
    {
      Integer retcode;
      
	String ifName = (String)wizardState.getData("ifName");
	if (Def.DEBUG) 
	  System.out.println("Running setupKiosk");
	if (Def.DEBUG) System.out.println("Executing /etc/rc2.d/S69inet stop");
	String inetCmd = "/etc/rc2.d/S69inet stop";
	 
	retcode = runCommand(inetCmd, true);
	if (Def.DEBUG) System.out.println("Finished  /etc/rc2.d/S69inet stop");
	
	if (Def.DEBUG) System.out.println("Executing /etc/rc2.d/S69inet start");
	inetCmd = "/etc/rc2.d/S69inet start";
	retcode = runCommand(inetCmd, true);
	if (Def.DEBUG) System.out.println("Finished  /etc/rc2.d/S69inet start");

	if (Def.DEBUG) System.out.println("Executing /etc/rc2.d/S71rpc stop");
	String rpcCmd = "/etc/rc2.d/S71rpc stop";
	retcode = runCommand(rpcCmd, true);
	if (Def.DEBUG) System.out.println("Finished  /etc/rc2.d/S71rpc stop");
	//sleep to give ypstop time to kill ypbind.
	try
	  {
	    Thread.sleep(1000);
	  }
	catch(InterruptedException e)
	  {
	  }
	
	String cmd = "pgrep ypbind";
	retcode = runCommand(cmd, true);
	if (retcode.intValue() == 0) {
	  // it's still running, lets really make sure
	  try
            {
              Thread.sleep(15000);
            }
          catch(InterruptedException e)
            {
            }
	  retcode = runCommand(cmd, true);
	  if (retcode.intValue() == 0) {    
	    /*
	     * ypbind is still running, kill it again, show no mercy
	     * workaround for bugid 
	     * 4262125 - x86 system hangs at sysid due to 
	     *		  ypbind never time out with cd0.
	     */
	    System.err.println("ypbind is still running, trying to kill it again");
	    cmd = "pkill -9 ypbind";
	    retcode = runCommand(cmd, true);
	  }
	}
	  
	if (Def.DEBUG) System.out.println("Executing /etc/rc2.d/S71rpc start");
	rpcCmd = "/etc/rc2.d/S71rpc start";
	retcode = runCommand(rpcCmd, true);
	if (Def.DEBUG) System.out.println("Finished /etc/rc2.d/S71rpc start");
	if (Def.DEBUG) System.out.println("Executing  /etc/rc2.d/S72inetsvc stop");
	String inetSvcCmd = "/etc/rc2.d/S72inetsvc stop";
	retcode = runCommand(inetSvcCmd, true);
	if (Def.DEBUG) System.out.println("Finished /etc/rc2.d/S2inetsvc stop");
	if (Def.DEBUG) System.out.println("Executing  /etc/rc2.d/S72inetsvc start");
	inetSvcCmd = "/etc/rc2.d/S72inetsvc start";
	retcode = runCommand(inetSvcCmd, true);
	if (Def.DEBUG) System.out.println("Finished  /etc/rc2.d/S72inetsvc start");
    }

  public Integer executeCmd(String cmd)
  {
    Integer retcode = runCommand(cmd, false);
    if (Def.DEBUG)
      System.out.println("running cmd : " + cmd);
    if (retcode.intValue() != 0) {
      System.err.println("Unable to run cmd: " + cmd);
     
    }
    return retcode;
  }

  public Integer executeWaitCmd(String cmd)
  {
    Integer retcode = runCommand(cmd, true);
    if (Def.DEBUG)
      System.out.println("running cmd : " + cmd);

    if (retcode.intValue() != 0) {
      System.err.println("Unable to run cmd: " + cmd);
      
    }
    return retcode;
  }
  
  public void addSysStates(String fn)
    {
      String line;
      String key;
      String value;
      BufferedReader in;
      try {
	in = new BufferedReader(new FileReader(fn));
	
	
	while((line = in.readLine()) != null)
	  {
	    StringTokenizer st = new StringTokenizer(line);
	    key = st.nextToken();
	    if (st.hasMoreTokens())
	      value = st.nextToken();
	    else 
	      value = "";
	    if (Def.DEBUG) 
	      System.out.println("data: " + key + " value: " + value);
	    if (key.equals("nameServerList")) {
	      /* Have a dns name service List */
	      String[] dnsNameServers = new String[3];
	      StringTokenizer dnsList = new StringTokenizer(value, ",");
	      for (int i=0; i<3;++i)
		if (dnsList.hasMoreTokens()) {
		  dnsNameServers[i] = dnsList.nextToken();
		   if (Def.DEBUG) 
		     System.out.println("DNS LIST " + i + " = " + dnsNameServers[i]);
		} else dnsNameServers[i] = "";
	      
	      wizardState.setData("DNSnameServers", dnsNameServers);
	    } else if (key.equals("searchList")){
	      String[] dnsSearchList = new String[6];
	      StringTokenizer srchList = new StringTokenizer(value, ",");
	      for (int i=0; i<6; ++i){
		if (srchList.hasMoreTokens()) {
		  dnsSearchList[i] = srchList.nextToken();
		   if (Def.DEBUG)
		     System.out.println("SEARCH LIST " + i + " = " + dnsSearchList[i]);
		} else dnsSearchList[i] = "";
	      }
	      wizardState.setData("DNSsearchList", dnsSearchList);
	    } else {
	      /* Not DNS, all others are OK */
	      if (value.equals("true"))
		wizardState.setData(key, new Boolean(true));
	      else if (value.equals("false")) 
		wizardState.setData(key, new Boolean(false));
	      else
		wizardState.setData(key, value);
	    }
	    
	    
	  }
	String initFile = "/etc/default/init";
	in = new BufferedReader(new FileReader(initFile));
	
	while((line = in.readLine()) != null)
	  {
	    if (! line.startsWith("#")) {
	      StringTokenizer st = new StringTokenizer(line,"=");
	      key = st.nextToken();
	      if (key.equals("TZ")) {
		if (st.hasMoreTokens()){
		  value = st.nextToken();
		  if (Def.DEBUG) System.out.println("setting timezone to value in " +
						    "/etc/default/init: " + value);
		  wizardState.setData("timeZone", value);
		}
	      }
	      
	      if (key.equals("LC_CTYPE") || key.equals("LANG")){
		if (st.hasMoreTokens()){
		  value = st.nextToken();
		  if (Def.DEBUG) System.out.println("setting locale to value in " +
						    "/etc/default/init: " + value);
		  wizardState.setData("locale", value);
		  break;
		}
	      }
	    }
	    
	  }
	String locale = (String) wizardState.getData("locale");
	if (locale.equals("")){
	  if (Def.DEBUG) System.out.println("No locale found in /etc/default/init " +
					    "setting to C");
	  locale = "C";
	  wizardState.setData("locale", locale);
	}
      } catch (FileNotFoundException ex)
	{
	  System.err.println("File not found: " + ex);
	  return;
	}
      catch (IOException ex)
	{
	  System.err.println("Exception caught: " + ex);
	  return;
	}
      
    }

  public Integer runCommand(String cmd, boolean wait)
    {
      Integer errcode;
      RunCmd R = new RunCmd(cmd, wait);
      errcode = new Integer(R.getResult());
      if (errcode.intValue() != 0)
	{
	  System.err.println("runCmd error in " + 
			     cmd + " with output: " + 
			     R.getAllOutput());
	}
      return(errcode);
    }


    /**
     * Tests to see if we are EStar compliant and sets the wizard state
     * for useEStar (boolean)
     */
    public void testEStar() {
	RunCmd testEStarCommand = new RunCmd("/usr/sbin/prtconf -pv | grep energy", true);
	String resultString = testEStarCommand.getOutput();

	// Test to see if we received any output. If we got output
	// containing energystar, then set the wizardState 'usePM' to true.
	if (resultString.indexOf("energystar-v2") != -1) {
	    wizardState.setData("usePM", new Boolean(true));
	    wizardState.setData("skipPM", new Boolean(false));
	} else {
	    wizardState.setData("usePM", new Boolean(false));
	    wizardState.setData("eStarOn", new Boolean(false));
	    wizardState.setData("skipPM", new Boolean(true));
	}
	    
    } // testEStar()

  /**
   * Writes out the proxyConfiguration for the kiosk
   * to read off of.
   */
  public void writeProxyConfig() {
  	final String PROXY_STATUS_FILE	= new String("/tmp/.proxyStatus");
  	final File PROXY_FILE			= new File(PROXY_STATUS_FILE);
	FileOutputStream outputFileStream = null;
	PrintWriter fileWriter;
	Date dateStamp = null;
	boolean fileExists;
	boolean deleted;
	
		
	// Create the date stamp
	dateStamp = new Date();
		
	// Check to see if this file exists already
	fileExists = PROXY_FILE.exists();	
	if (fileExists) 
		deleted = PROXY_FILE.delete();		
	
		
	try {
		// Set up for the stream
		outputFileStream = new FileOutputStream(PROXY_FILE);
		fileWriter = new PrintWriter(outputFileStream);
		fileWriter.println("success=" + (Boolean)wizardState.getData("connectSuccess"));
			
		fileWriter.println("needsProxy=" + (Boolean)wizardState.getData("needsProxy"));
		fileWriter.println("proxyServer=" + (String)wizardState.getData("proxyServer"));
		fileWriter.println("proxyPort=" + (String)wizardState.getData("proxyPort"));
		fileWriter.println("date=" + dateStamp);
		fileWriter.close();	
	} catch (IOException e) {
		System.err.println("Error creating output to file.");
	} catch (SecurityException e) { 
		System.err.println("There was a security exception: " + e);
	}
  } // writeProxyConfig()


  public void writeCfgFile()
    {
      
      FileWriter out;
     
      try 
        {
	  
	  out = new FileWriter("/tmp/root/etc/sysidcfg");
	  // Write network info
	  Boolean isNetworked = new Boolean(false);
	  isNetworked = 
	    (Boolean)wizardState.getData("isNetworked");;
	  
	  if (isNetworked.booleanValue()) {
	    writeNetworked(true,out);
	    writeNS(true,out);
	   
	  } else {
	    writeNetworked(false,out);
	    writeNS(false,out);
	  }   
	  writeRootPw(out);	 
	  writeTermType(out);
	  writeTZ(out);
	  writeKRB(out);
	  out.close();
	}
      catch(IOException e)
	{
	  e.printStackTrace();
	}      
      
      // Run the EStar setup...
      doEstar();
	    
    }
  
  private void writeNetworked(boolean networked, FileWriter out) {
    String networkStr = new String("");
    String ifName = new String("");
    String hostName = new String("");
    String ipAddress = new String("");
    String subNetMask = new String("");
    Boolean enableIpv6;
    Boolean isDHCP = new Boolean(false);

    hostName =  
      (String)wizardState.getData("hostName");
    String netif = new String("network_interface=");
    if (networked) {
      isDHCP = (Boolean)wizardState.getData("isDHCP");
      ifName =
	(String)wizardState.getData("ifName");
      if (!ifName.equals("")) {
	networkStr = netif + ifName;
      } else {	
	networkStr = netif + "Primary";
      }
     	String ipv6String;
	enableIpv6 = (Boolean) wizardState.getData("enableIpv6");
	if (enableIpv6.booleanValue())
	  ipv6String = "protocol_ipv6=yes";
	else
	  ipv6String = "protocol_ipv6=no";
      if (!isDHCP.booleanValue()) {
	ipAddress = 
	  (String)wizardState.getData("ipAddress");
	subNetMask = 
	  (String)wizardState.getData("subNetMask");	
	networkStr = networkStr + " " + "{" +
	  "hostname=" + hostName + " " +
	  "ip_address=" + ipAddress + 
	  " " +
	  "netmask=" + subNetMask + " " +
	  ipv6String + "}\n";
      } else {
	networkStr = networkStr + " " + "{" +
	  "dhcp" + " " + ipv6String + "}\n";
      }
    } else {
      networkStr = netif + "\'none\'\n";
    }
    try {
      out.write(networkStr);
    }
    catch(IOException e)
      {
	e.printStackTrace();
      }    
  }
  private void writeNS(boolean networked, FileWriter out) {
    String nameServerString = new String("");
    String name_service = new String("name_service=");
    String nameService;
    //Write the name service stuf
    if (networked) {	   
      nameService= 
	(String)wizardState.getData("nameService");
      nameService.toUpperCase();
      if (Def.DEBUG) System.out.println("Name Service is set to : " + nameService);
      if (!nameService.equals("")) {
	if (nameService.startsWith("NIS")) {
	  nameServerString = getNISstr(nameService);
	} else if (nameService.equals("DNS")) {
	  nameServerString = getDNSstr(nameService);	
	} else {
	  System.out.println("Setting to none");
	  nameServerString = name_service + "none\n";
	}
      } else {
	nameServerString = name_service + "none\n";
      }
    } else {
      nameServerString = name_service + "none\n";
    }
    try
      {
	out.write(nameServerString);
      } 
    catch (IOException e)
      {
	e.printStackTrace();
      }
  }
  private String getDNSstr(String nameService) {
    String nameServerString = new String("");
    String name_service = new String("name_service=");
    String name_server = new String("name_server=");
    String search = new String("search=");
    String domain_name = new String("domain_name=");
    String nameServers = new String();
    String nsString = new String();
    String searchList = new String();
    String serverString = new String();
    String domString  = new String();

	  // Get the values
    String[] dnsServers = 
      (String[])wizardState.getData("DNSnameServers");
    String[] srchList = 
      (String[])wizardState.getData("DNSsearchList");
    String domainName = 
      (String)wizardState.getData("domainName");
		
	  //Load the nameServer string with the , del. list
    for (int i=0; i<dnsServers.length;++i)
      if ((!dnsServers[i].equals("")) &&
	  ((i+1) <= dnsServers.length) &&
	  (i != 0))
	nameServers = nameServers + "," + dnsServers[i];
      else
	nameServers = nameServers + dnsServers[i];
    //Load the searchList string with the , del. list
   
    for (int i=0; i<srchList.length;++i)
      if ((!srchList[i].equals("")) &&
	  ((i+1) <= srchList.length) &&
	  (i != 0))
	searchList = searchList + ","+ srchList[i];
      else
	searchList = searchList + srchList[i];
		
	  //Name Service String name_service=...
    
    nsString = name_service + nameService;
    //Name Server string name_server=...
    
    if (! nameServers.equals(""))
      serverString = name_server + nameServers;
    else
      serverString = "";

	  //Domain Name string domain_name=....
    
    if (!domainName.equals(""))
      domString = domain_name + domainName;
    else
      domString = "";
    //Search string search=....
    String srchString = new String();
    if (!searchList.equals(""))
      srchString = search + searchList;
    else 
      srchString = "";
		
	  //Fill in the string to output to the file
    nameServerString = 
      nsString + " " +
      "{" + serverString + " " +
      domString + " " +
      srchString + " " + "}" + "\n";
    return nameServerString;
  }
  private String getNISstr(String nameService) {
    Boolean findAServer = (Boolean)wizardState.getData("findAServer");
    String name_service = new String("name_service=");
    String domain_name = new String("domain_name=");
    String domainName = 
      (String)wizardState.getData("domainName");
    String nameServerString = "";
    if (findAServer.booleanValue()) {
      nameServerString = name_service + 
	nameService +
	" " + "{" + 
	domain_name + domainName + 
	"}" + "\n";
    } else {
      String nameServerName = 
	(String)wizardState.getData("nameServerName");
      String nameServerAddr =
	(String)wizardState.getData("nameServerAddr");
      String name_server = "name_server=";
      nameServerString = name_service + 
	nameService + " " + "{" +
	domain_name +
	domainName + " " +
	name_server + 
	nameServerName + "(" +
	nameServerAddr + ")" +
	"}" + "\n";
    }
    return nameServerString;
  }
    private void writeRootPw(FileWriter out){
       // Root Passwd
	  String rootPasswd = 
	    (String)wizardState.getData("rootPasswd");
	  
	  String root_password = 
	    new String("root_password=");
	  
	  String rootpasswdString = null;
	  if (! rootPasswd.equals("")) {
	    EncryptString encryptedPW =
	      new EncryptString(rootPasswd);
	    rootPasswd = encryptedPW.GetEncryptedString();
	    int i = rootPasswd.indexOf("\0");
	    if (i != -1){
		
	      rootPasswd = rootPasswd.substring(0, i);
	    }
	      
	    rootpasswdString = root_password 
	      + '"' +
	      rootPasswd + '"' +
	      "\n";
	      
	  } else {
	    rootpasswdString = root_password + '"' + '"' + "\n";
	  }
	  try
	    {
	      out.write(rootpasswdString);
	    }
	  catch (IOException e)
	    {
	      e.printStackTrace();
	    }
    }
    private void writeTZ(FileWriter out) {
       String timeZone = 
	 (String)wizardState.getData("timeZone");
       String locale =
	 (String)wizardState.getData("locale");
	    
	  String timezoneString = null;
	  String timezone = new String("timezone=");
	  if (! timeZone.equals(null)) {
	    // Fix for bugid	   
	    timezoneString = timezone +
	      '"' + timeZone + '"' + "\n";
	      
	  } else {
	    timeZone = "US/Pacific";
	    timezoneString = timezone +
	      '"' + timeZone + '"' + "\n";
	  }
	  try {

	    out.write(timezoneString);
	    
	    out.write("timeserver=localhost\n");
	    
	    if ((! locale.equals(null)) || 
		(! locale.equals("")))
	      out.write("system_locale=" + locale + "\n");
	    else
	      out.write("system_locale=C\n");
	  }
	  catch (IOException e)
	    {
	      e.printStackTrace();
	    }
    }

  private void writeTermType(FileWriter out) {
    String termType = 
	    (String)wizardState.getData("termType");
    String terminal = new String("terminal=");
	  String termTypeString = null;
	  if (! termType.equals(null)) {
	    termTypeString = terminal +
	      termType + "\n";
	      
	  } else {
	    termType = "sun-cmd";
	    termTypeString = terminal +
	      termType + "\n";
	  }
	  try {

	    out.write(termTypeString);

	  }
	  catch (IOException e)
	    {
	      e.printStackTrace();
	    }
    }

  private void writeKRB(FileWriter out) {

    String securityKRB = (String)wizardState.getData("securityKRB");
    String security_policy = "security_policy=";
    try {
      if (securityKRB != null) {
	if (securityKRB.equals("none")) {
	  out.write(security_policy + securityKRB + "\n");
	} else {
	  String defaultRealm = (String)wizardState.getData("defaultRealm");
	  String adminServer = (String)wizardState.getData("adminServer");
	  String kdcKRB = (String)wizardState.getData("adminServer");

	  // set the default_realm
	  String default_realm;
	  if (defaultRealm == null)
	    default_realm = "";
	  else
	    default_realm = "default_realm=" + defaultRealm;
	  //set the admin_server
	  String admin_server;
	  if (adminServer == null)
	    admin_server="";
	  else
	    admin_server="admin_server=" + adminServer;
	  // set the kdc list
	  String kdc;
	  if (kdcKRB == null)
	    kdc = "";
	  else
	    kdc="kdc=" + kdcKRB;
	
	  out.write(security_policy + securityKRB + " " + "{" + default_realm +
		    " " + admin_server + " " + kdc + " " + "}\n");
	}
      } else
	out.write(security_policy + "none" + "\n");
       } catch (IOException e)
	 {
	   e.printStackTrace();
	 }
  }

  private void doEstar() {
    Boolean usePM = (Boolean) wizardState.getData("usePM");
    Boolean eStarOn = (Boolean) wizardState.getData("eStarOn");
    FileWriter out;
    
    if (eStarOn.booleanValue()) {
      // Means to turn on autoshutdown, so place the flag
      // accordingly.
      try {
	out = new FileWriter("/tmp/root/autoshutdown");
	out.write("");
	out.close();
      } catch(IOException e) {
	e.printStackTrace();
      }
      
    } else {
      // Means not to autoshutdown.
      try {
	out = new FileWriter("/tmp/root/noautoshutdown");
	out.write("");
	out.close();
      } catch(IOException e) {
	e.printStackTrace();
      }
    }
    
    Boolean askAtReboot = (Boolean) wizardState.getData("askAtReboot");
    if (askAtReboot.booleanValue()) {
      try {
	out = new FileWriter("/tmp/root/etc/.PM_RECONFIGURE");
	out.write("");
	out.close();
      } catch(IOException e) {
	e.printStackTrace();
      }
    } else 
      if (new PanelServices().validFile("/tmp/root/etc/.PM_RECONFIGURE"))
	runCommand("rm /tmp/root/etc/.PM_RECONFIGURE", true);
  } // doEstar()
  
  /*
   *
   * This method get's the current rtc value from the system
   *
   */
  private String getRTC() {
    if (Def.DEBUG) System.out.println("Running getRTC");
    String currentRTC = "PS8PDT";
    String rtc = "/usr/sbin/rtc";
    File f = new File(rtc);
    if (f.exists()) {
      try {
	Process p = Runtime.getRuntime().exec(rtc);
	InputStream is = p.getInputStream();
	BufferedReader in = new BufferedReader(new InputStreamReader(is));
	p.waitFor();
	currentRTC = in.readLine();
      } catch (Exception e) {}
    }
    return currentRTC;
  }

  /* 
   *
   * This method sets the runtime clock to the timezone, tz
   * Only run on intel machines, for sparc it is a noop.
   *
   */
  private void setRTC(String tz) {
    if (Def.DEBUG) System.out.println("Running setRTC, setting rtc to " + tz);
    String rtcExec = "/usr/sbin/rtc";
    File f = new File(rtcExec);
    if (f.exists()) {
      try {
	Process p = Runtime.getRuntime().exec(rtcExec + " -z " + tz);
	p.waitFor();
      } catch (Exception e) {}
    }
  }

  
  public String[] getDate(String tz)
  {

    String origRTC = getRTC();
    setRTC(tz);
    String envp[] = {"TZ="+tz};
    String dateString[] = new String[6];

    try{
      Process proc = Runtime.getRuntime().exec("/usr/bin/date +%d.%m.%Y.%T",
					     envp);
      InputStream is = proc.getInputStream();
      InputStreamReader isr = new InputStreamReader(is);
      

      proc.waitFor();
      if (is.available() != 20) {
	if (Def.DEBUG) System.out.println("bad Date length");
	return null;
      }
      
      char dateStr[] = new char[20];
      int count = 20;
      
      while (count>0)
	dateStr[20-count--] = (char) isr.read();
      
      String day = String.valueOf(dateStr[0]) +
	String.valueOf(dateStr[1]);
      String month = String.valueOf(dateStr[3]) +
	String.valueOf(dateStr[4]);
      String year = String.valueOf(dateStr[6]) +
	String.valueOf(dateStr[7]) +
	String.valueOf(dateStr[8]) +
	String.valueOf(dateStr[9]);
      String hour = String.valueOf(dateStr[11]) +
	String.valueOf(dateStr[12]);
      String minute = String.valueOf(dateStr[14]) + 
	String.valueOf(dateStr[15]);
      String second = String.valueOf(dateStr[17]) +
	String.valueOf(dateStr[18]);
      
      dateString[0] = year;
      dateString[1] = month;
      dateString[2] = day;
      dateString[3] = hour;
      dateString[4] = minute;


      String locale = (String)wizardState.getData("locale");
      String env2[] = getEnv(tz);

      proc = Runtime.getRuntime().exec("/usr/bin/date", env2 );
      isr = new InputStreamReader(proc.getInputStream());
      proc.waitFor();
      dateString[5] = String.valueOf((char)isr.read());
      while (isr.ready())
	{
	  dateString[5] += String.valueOf((char)isr.read());
	}
    } 
    catch(Exception e){
      if (Def.DEBUG) System.out.println(e+" process problem");
      return null;
    }
    setRTC(origRTC);
    return dateString;
  }

  public Integer setDate(String dateString, String tz)
  {


    try{
      String envp[] = {"TZ="+tz};
      Runtime.getRuntime().exec("/usr/bin/date "+dateString, envp);
    }
    catch(Exception e)
      {
	if (Def.DEBUG) System.out.println(e+" bad timezone/date");
	return new Integer(1);
      }
    return new Integer(0);
    
  }

  public String[] getEnv(String tz)
  {
    String env[] = new String[9];
    env[0] = "TZ="+tz;
    
    try 
      {
	Runtime runtime = Runtime.getRuntime();
	Process localeCheck = runtime.exec("/usr/bin/locale");
	InputStream is = localeCheck.getInputStream();
	BufferedReader in = new BufferedReader(new InputStreamReader(is));	
	
	localeCheck.waitFor();
	String key = null;
	String lc = in.readLine();
	int i = 1;
	
	while (lc != null) 
	  {
	    int next = 0;
	    char newStr[] = new char[lc.length()];
	    for (int j = 0; j< lc.length(); j++)
	      if (lc.charAt(j) != '\"')
		newStr[next++] = lc.charAt(j);
	    
	    env[i] = new String(newStr);
	    lc = in.readLine();
	    i++;
	  }
      } 
    catch(IOException e) 
      {
      }
    catch(InterruptedException e) 
      {
      }
    
    return env;
    
  }

    /**
     * Get the runtime classes required by this ServerObject.
     */
  public void addRuntimeResources(Vector resourceVector)
    {
      resourceVector.addElement(new String[] {null, 
				"com.sun.sysid.core.SysIDServerObject"});
      resourceVector.addElement(new String[] {null,
				"com.sun.sysid.core.RunCmd"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.wizards.core.SystemInterface"});
      resourceVector.addElement(new String[] {null, 
				"com.sun.sysid.core.PanelServices"});
    
    }



}
