package com.cisco.nm.hsa.whisk.servlet;


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.net.InetAddress;

public class UpdateTextServlet extends HttpServlet {
    
    public void init(ServletConfig config) throws ServletException {
    }
    
  public void service (ServletRequest req, ServletResponse res )
                                 throws ServletException, IOException  {
                                    
    res.setContentType( "text/html" );
    PrintWriter out = res.getWriter();
    out.println( "<html>" );
    out.println( "<body>" );
    
 
    out.println( "<B>Follow these steps using CLI to upgrade to WLSE 2.5:</B><br>");

    out.println( "1. SSH or Telnet to the WLSE to be upgraded and log in as the admin user. For security reasons, Telnet is disabled on the WLSE by default. If you want to be able to connect to the CLI interface using Telnet, please refer to WLSE online help.");   
    
    out.println( "<br>");
    out.println( "2. Execute the <B>install</B> command.<br>"); 
    out.println( "<br>");

    out.println( "3 Install the package:<br>");
    out.println( "&nbsp;&nbsp;&nbsp; install:<B>configure url http://"+getLocalIP()+":9851</B><br>");
    out.println( "&nbsp;&nbsp;&nbsp; install:<B>update "+getRelease()+"</B><br>");
    out.println( "<br><br>");
    out.println( "<B>It will take 10-15 mins for the upgrade to complete.<br>");
    out.println( "Do not close the command window opened on your win2k system until the upgrade is complete.</B>");
    out.println( "</body>" );
    out.println( "</html>" );
    out.close();
  }
    String getLocalIP() {
        try  {
            String ip = InetAddress.getLocalHost().getHostAddress();
            return ip;
        } catch(Exception _ex)  {
            System.out.println("Cannot get local IP address");
        }
        return null;
    }
    String getRelease() {
        File f = new File(".\\packages\\ApplianceTOC\\index.toc");
        try {
            FileInputStream fis = new FileInputStream(f);
            BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
            String line = reader.readLine();
            if (line != null && line.indexOf("=") > 0) {
                return line.substring(0,line.indexOf("="));
            }
        } catch(Exception _ex)  {
            System.out.println("Cannot get local IP address");
        }
        return null;
    }

}