-
- if ("backup".equalsIgnoreCase(action)) {
- return prepare(ctx, "BACKUP", "backup");
- }
- if ("restorebackup".equalsIgnoreCase(action)) {
- return prepare(ctx, "RESTOREBACKUP", "restorebackup");
- }
- if ("deletebackup".equalsIgnoreCase(action)) {
- return prepare(ctx, "DELETEBACKUP", "deletebackup");
- }
- if ("audit".equalsIgnoreCase(action)) {
- return audit(ctx, "FULL");
- }
- if ("getrunningconfig".equalsIgnoreCase(action)) {
- return audit(ctx, "RUNNING");
- }
-
- if ((key.equals("put")) || (key.equals("get"))) {
- String loginId = parameters.get("loginId");
- String host = parameters.get("host");
- String password = parameters.get("password");
- password = EncryptionTool.getInstance().decrypt(password);
- String fullPathFileName = parameters.get("fullPathFileName");
- String data = null;
-
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
- log.debug("SCP: SshJcraftWrapper has been instantiated");
- debugLog.printRTAriDebug(fnName, "SCP: SshJcraftWrapper has been instantiated");
- try {
- if (key.equals("put")) {
- data = parameters.get("data");
- if (data != null) {
- debugLog.printRTAriDebug(fnName, "Command is for put: Length of data is: " + data.length());
- InputStream is = new ByteArrayInputStream(data.getBytes());
- log.debug("SCP: Doing a put: fullPathFileName=" + fullPathFileName);
- debugLog.printRTAriDebug(fnName, "SCP: Doing a put: fullPathFileName=" + fullPathFileName);
- sshJcraftWrapper.put(is, fullPathFileName, host, loginId, password);
- try {
- debugLog.printRTAriDebug(fnName, "Sleeping for 180 seconds....");
- Thread.sleep(1000 * 180);
- debugLog.printRTAriDebug(fnName, "Woke up....");
- } catch (java.lang.InterruptedException ee) {
- boolean ignore = true;
- }
- } else {
- r.code = HttpURLConnection.HTTP_INTERNAL_ERROR;
- log.debug(fnName + " Command is for put: data is null");
- }
- } else // Must be a get
+ sshJcraftWrapper = null;
+ return (setResponseStatus(ctx, r));
+ }
+ catch (IOException e)
+ {
+ DebugLog.printAriDebug(fnName, "Caught a IOException e=" + e);
+ log.debug(fnName + " : Caught a IOException e=" + e);
+ r.code = HttpURLConnection.HTTP_INTERNAL_ERROR;
+ r.message = e.getMessage();
+ sshJcraftWrapper = null;
+ return (setResponseStatus(ctx, r));
+ }
+ }
+ if (key.equals("cli"))
+ {
+ String loginId = parameters.get("loginId");
+ String host = parameters.get("host");
+ String password = parameters.get("password");
+ password = EncryptionTool.getInstance().decrypt(password);
+ String cliCommand = parameters.get("cli");
+ String portNumber = parameters.get("portNumber");
+ SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ try
+ {
+ log.debug("CLI: Attempting to login: host=" + host + " loginId=" + loginId + " password=" + password +
+ " portNumber=" + portNumber);
+ debugLog.printRTAriDebug(fnName, "CLI: Attempting to login: host=" + host + " loginId=" + loginId +
+ " password=" + password + " portNumber=" + portNumber);
+ sshJcraftWrapper.connect(host, loginId, password, Integer.parseInt(portNumber));
+
+ DebugLog.printAriDebug(fnName, "Sending 'sdc'");
+ String response = sshJcraftWrapper.send("sdc", ":");
+ DebugLog.printAriDebug(fnName, "Sending 1");
+ response = sshJcraftWrapper.send("1", ":");
+ DebugLog.printAriDebug(fnName, "Sending 1, the second time");
+ response = sshJcraftWrapper.send("1", "#");
+ DebugLog.printAriDebug(fnName, "Sending paging-options disable");
+ response = sshJcraftWrapper.send("paging-options disable", "#");
+ DebugLog.printAriDebug(fnName, "Sending show config");
+ response = sshJcraftWrapper.send("show config", "#");
+
+ DebugLog.printAriDebug(fnName, "response is now:'" + response + "'");
+ DebugLog.printAriDebug(fnName, "Populating the ctx object with the response");
+ ctx.setAttribute("cliOutput", response);
+ sshJcraftWrapper.closeConnection();
+ r.code = 200;
+ sshJcraftWrapper = null;
+ return (setResponseStatus(ctx, r));
+ }
+ catch (IOException e)
+ {
+ DebugLog.printAriDebug(fnName, "Caught a IOException e=" + e);
+ log.debug(fnName + " : Caught a IOException e=" + e);
+ sshJcraftWrapper.closeConnection();
+ r.code = HttpURLConnection.HTTP_INTERNAL_ERROR;
+ r.message = e.getMessage();
+ sshJcraftWrapper = null;
+ DebugLog.printAriDebug(fnName, "Returning error message");
+ return (setResponseStatus(ctx, r));
+ }
+ }
+ if (key.equals("escapeSql"))
+ {
+ String data = parameters.get("artifactContents");
+ log.debug("ConfigComponentAdaptor.configure - escapeSql");
+ data = escapeMySql(data);
+ ctx.setAttribute("escapedData", data);
+ return (setResponseStatus(ctx, r));
+ }
+ if(key.equals("GetCliRunningConfig"))
+ {
+ debugLog.printRTAriDebug (fnName, "key was: GetCliRunningConfig: ");
+ log.debug("key was: GetCliRunningConfig: ");
+ String User_name = parameters.get("User_name");
+ String Host_ip_address = parameters.get("Host_ip_address");
+ String Password = parameters.get("Password");
+ Password = EncryptionTool.getInstance().decrypt(Password);
+ String Port_number = parameters.get("Port_number");
+ String Get_config_template = parameters.get("Get_config_template");
+ SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ log.debug("GetCliRunningConfig: sshJcraftWrapper was instantiated");
+ debugLog.printRTAriDebug (fnName, "GetCliRunningConfig: sshJcraftWrapper was instantiated");
+ try
+ {
+ DebugLog.printAriDebug(fnName, "GetCliRunningConfig: User_name="+User_name +" Host_ip_address="+Host_ip_address +" Password="+Password +" Port_number="+Port_number);
+ log.debug("GetCliRunningConfig: Attempting to login: Host_ip_address="+Host_ip_address +" User_name="+User_name+" Password="+Password+" Port_number="+Port_number);
+ StringBuffer sb = new StringBuffer();
+ String response = "";
+ String CliResponse = "";
+ boolean showConfigFlag = false;
+ sshJcraftWrapper.connect (Host_ip_address, User_name, Password, "", 30000, Integer.parseInt(Port_number));
+ DebugLog.printAriDebug(fnName, "GetCliRunningConfig: On the VNF device");
+ StringTokenizer st = new StringTokenizer(Get_config_template, "\n");
+ String command = null;
+ try
+ {
+ while (st.hasMoreTokens())
+ {
+ String line = st.nextToken();
+ DebugLog.printAriDebug(fnName, "line="+line);
+ if (line.indexOf("Request:") != -1)
+ {
+ DebugLog.printAriDebug(fnName, "Found a Request line: line="+line);
+ command = getStringBetweenQuotes(line);
+ DebugLog.printAriDebug(fnName, "Sending command="+command);
+ sshJcraftWrapper.send(command);
+ DebugLog.printAriDebug(fnName, "command has been sent");
+ if (line.indexOf("show config") != -1)
+ {
+ showConfigFlag = true;
+ DebugLog.printAriDebug(fnName, "GetCliRunningConfig: setting 'showConfigFlag' to true");
+ log.debug("GetCliRunningConfig: GetCliRunningConfig: setting 'showConfigFlag' to true");
+ }
+ }
+ if (line.indexOf("Response: Ends_With") != -1)
+ {
+ DebugLog.printAriDebug(fnName, "Found a Response line: line="+line);
+ String delemeter = getStringBetweenQuotes(line);
+ DebugLog.printAriDebug(fnName, "The delemeter="+delemeter);
+ String tmpResponse = sshJcraftWrapper.receiveUntil(delemeter, 120*1000, command);
+ response += tmpResponse;
+ if (showConfigFlag)
+ {
+ showConfigFlag = false;
+ StringTokenizer st2 = new StringTokenizer(tmpResponse, "\n");
+ while (st2.hasMoreTokens())