public void clear() { string str = ""; string str1 = ""; Scraper scraper = new Scraper(); str = string.Concat(new object[] { "http://", clearZombies.host, ":", clearZombies.port, "/manage/home" }); clearZombies.debugmsg(string.Concat("Generating session ID cookie by accessing URL: ", str)); string str2 = scraper.Load(str, str1, null, 60000, string.Concat(clearZombies.host, ":", clearZombies.port), "", "", "application/x-www-form-urlencoded"); if ((str2.Contains("Sign In") ? false : !str2.Contains("Login"))) { Console.WriteLine("Could not access server manager URL, please make sure server manager is up and details provided are correct!"); } else { clearZombies.debugmsg("Page loaded sucessfully"); str2 = ""; str = string.Concat(new object[] { "http://", clearZombies.host, ":", clearZombies.port, "/manage/j_security_check" }); clearZombies.debugmsg(string.Concat("Authenticating session ID by sending credentials to URL: ", str)); str1 = string.Concat(new string[] { "j_username="******"&j_password="******"&url=%2Fmanage%2Fhome" }); str2 = scraper.Load(str, str1, null, 60000, string.Concat(clearZombies.host, ":", clearZombies.port), "", "", "application/x-www-form-urlencoded"); if (!str2.Contains("logout")) { Console.WriteLine("Could not login to server manager, please make sure credential details provided are correct!"); } else { clearZombies.debugmsg("Login to Server Manager was successful"); str2 = ""; str = string.Concat(new object[] { "http://", clearZombies.host, ":", clearZombies.port, "/manage/target?&hostName=", clearZombies.entHost, "&instanceName=", clearZombies.instName, "&targetType=entserver&jdeHome=", clearZombies.jdeHome, "&action=processes" }); clearZombies.debugmsg(string.Concat("Accessing process details page at URL: ", str)); str1 = ""; str2 = scraper.Load(str, str1, null, 60000, string.Concat(clearZombies.host, ":", clearZombies.port), "", "", "application/x-www-form-urlencoded"); clearZombies.debugmsg("Checking for zombie kernels on process details page..."); ArrayList arrayLists = clearZombies.findZombies(str2); int count = arrayLists.Count; if (count != 0) { Console.WriteLine(string.Concat("Total number of zombies detected: ", count)); Console.WriteLine("Initiating cleanup... following are details of zombies cleared:"); Console.WriteLine(string.Concat(new string[] { "Hostname".PadRight(20), "Process ID".PadRight(12), "Process Type".PadRight(20), "Process Name".PadRight(20), "Status".PadRight(8) })); for (int i = 0; i < count; i++) { Processes item = (Processes)arrayLists[i]; str = string.Concat(new object[] { "http://", clearZombies.host, ":", clearZombies.port, "/manage/ajax" }); str1 = item.generatePayload(); str2 = scraper.Load(str, str1, null, 60000, string.Concat(clearZombies.host, ":", clearZombies.port), "", "", "application/xml"); if (!str2.Contains("success")) { item.status = "Failed"; } else { item.status = "Success"; } Console.WriteLine(string.Concat(new string[] { item.host.PadRight(20), item.processID.PadRight(12), item.processType.PadRight(20), item.processName.PadRight(20), item.status.PadRight(8) })); item = null; } } else { clearZombies.displayNoZombies(); } } } }
public static ArrayList findZombies(string data) { string str = "clearZombie=\"clearZombie\\('([^']+)', '([^']+)', '([^']+)', '([^']+)'\\)\" /\\>\\</td\\>\\<td\\>\\<a href=\"[^\"]+\"\\>([^\\<]+)\\</a\\>\\</td\\>\\<td\\>([^\\<]+)\\</td\\>\\<td\\>([^\\<]+)\\</td\\>"; int num = 0; ArrayList arrayLists = new ArrayList(); foreach (Match match in Regex.Matches(data, str)) { if (match.Groups.Count == 8) { Processes process = new Processes(); for (int i = 1; i < match.Groups.Count; i++) { switch (i) { case 1: { process.host = match.Groups[i].Value; break; } case 2: { process.port = match.Groups[i].Value; break; } case 3: { process.objectName = match.Groups[i].Value; break; } case 4: { process.processIndex = match.Groups[i].Value; break; } case 5: { process.processName = match.Groups[i].Value; break; } case 6: { process.processType = match.Groups[i].Value; break; } case 7: { process.processID = match.Groups[i].Value; break; } } } arrayLists.Add(process); num++; } } return(arrayLists); }