public void Analys(string sFolder) { _name = _xn["l7:Name"].InnerText; _id = _xn["l7:Id"].InnerText; _type = _xn["l7:Type"].InnerText; Tracker.addName(_id, _name); sA.Append("Name:"); sA.AppendLine(_name); sA.Append("Id:"); sA.AppendLine(_id); sA.Append("Type:"); sA.AppendLine(_type); sA.Append(""); sA.AppendLine(""); sA.Append(""); sA.AppendLine(""); XmlNodeList xnList = _xn.SelectNodes("l7:Resource/l7:Policy/l7:PolicyDetail", _man); //go through list of all resource foreach (XmlNode xNode in xnList) { WriteNodes(xNode); sA.AppendLine("---------------"); } xnList = _xn.SelectNodes("l7:Resource/l7:Policy/l7:Resources", _man); //go through list of all resource foreach (XmlNode xNode in xnList) { WriteNodes(xNode); sA.AppendLine("---------------"); } //XmlNode xnList = _xn.SelectSingleNode("l7:Resource", _man); //WriteNodes(xnList); //Console.WriteLine("Name: {0} {1}", _name, _id); FileFuncs.WriteTxtFile(sFolder + @"\" + this.fileName(), sA.ToString()); }
public void AddService(string sFolder) { XmlNode nSD = _xn.SelectSingleNode("l7:Resource/l7:Service/l7:ServiceDetail", _man); SrvProp oS = new SrvProp(); oS.Name = _xn.AA_NodeText("l7:Name", _man); oS.Id = _xn.AA_NodeText("l7:Id", _man); oS.Type = _xn.AA_NodeText("l7:Type", _man); oS.FolderId = nSD.AA_AttributeValue("folderId"); oS.Version = nSD.AA_AttributeValue("version"); oS.Enabled = nSD.AA_NodeText("l7:Enabled", _man); //oS.Url = nSrvMap.AA_NodeText("l7:ServiceMappings/l7:HttpMapping/l7:UrlPattern", _man); //get node for service mapping XmlNode nSrvMap = nSD.SelectSingleNode("l7:ServiceMappings/l7:HttpMapping", _man); oS.Url = nSrvMap.AA_NodeText("l7:UrlPattern", _man); oS.Verbs = nSrvMap.AA_SubNodesTextDelimited("l7:Verbs/l7:Verb", _man); //get all properties XmlNodeList xlProp = nSD.SelectNodes("l7:Properties/l7:Property", _man); foreach (XmlNode xNode in xlProp) { string sKey = xNode.AA_AttributeValue("key"); string sVal = xNode.InnerText; switch (sKey) { case "internal": oS.Sinternal = sVal; break; case "policyRevision": oS.PolicyRevision = sVal; break; case "soap": oS.Soap = sVal; break; case "tracingEnabled": oS.TracingEnabled = sVal; break; case "wssProcessingEnabled": oS.WssProcessingEnabled = sVal; break; } } //get node for service mapping XmlNodeList nPolNodes = _xn.SelectNodes("l7:Resource/l7:Service/l7:Resources/l7:ResourceSet/l7:Resource", _man); foreach (XmlNode xNode in nPolNodes) { string sType = xNode.AA_AttributeValue("type"); if (sType == "policy") { oS.PolicyRevision = xNode.AA_AttributeValue("version"); oS.PolicyXml = xNode.InnerText; } } Tracker.addObject(oS.Id, oS); //if (_type == "SERVICE" ) // { sA.Append(""); sA.AppendLine(oS.HeaderText()); sA.AppendLine("===================================="); sA.AppendLine("======Policy Text===================="); sA.AppendLine("===================================="); sA.Append("Policy version: "); sA.AppendLine(oS.PolicyRevision); sA.AppendLine(); policyReader oP = new policyReader(oS.PolicyXml); sA.Append(oP.process()); sA.AppendLine("===================================="); sA.AppendLine("======Policy XML===================="); sA.AppendLine("===================================="); sA.AppendLine(oS.PolicyXml); //FileFuncs.WriteTxtFile(sFolder + @"\" + this.fileName(), sA.ToString()); FileFuncs.WriteTxtFile(sFolder + @"\" + oS.FileName(), sA.ToString()); //} }
static void Main(string[] args) { //read commandline arguments by position // filename|output_diff_folder|output_report_folder cmdArg aX = new cmdArg(args[0]); //Console.WriteLine("count of | delimited argumnets: " + aX.len); if (aX.len < 1) { Console.WriteLine("Invalid commandline options, please specify policy file to analyse. "); return; } string sOutputFolder = aX.strVal(1); string sFile = sOutputFolder + @"\" + aX.strVal(0); //TODO check if file exists //TODO check if folder exists and create if it does not exist //TODO append date_time_sub folder string sOutFolder = aX.strVal(1) + @"\" + aX.strVal(0).Replace(".xml", ""); // + @"\" + DateTime.Now.ToString("yyyy_MM_dd"); sOutFolder = sOutFolder.Replace(@"\\", @"\"); string sOutServiceFolder = sOutFolder + "\\SERVICE"; string sOutPolicyFolder = sOutFolder + "\\POLICY"; string sOutEnAssertFolder = sOutFolder + "\\ENCAPSULATED_ASSERTION"; FileFuncs.CreateFolder(sOutServiceFolder); FileFuncs.CreateFolder(sOutPolicyFolder); FileFuncs.CreateFolder(sOutEnAssertFolder); //String strDate = DateTime.Now.ToString("yyyy_MM_dd"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(sFile); var manager = new XmlNamespaceManager(new NameTable()); manager.AddNamespace("l7", "http://ns.l7tech.com/2010/04/gateway-management"); //XNamespace ns = XNamespace.Get("XXXX"); //read all nodes from the bundle xml //XmlNodeList xnList = xmlDoc.SelectNodes("l7:List/l7:Item", manager); XmlNodeList xnList = xmlDoc.SelectNodes("l7:Item/l7:Resource/l7:Bundle/l7:References/l7:Item", manager); foreach (XmlNode xn in xnList) { string sType = xn["l7:Type"].InnerText; string sName = xn["l7:Name"].InnerText; string sID = xn["l7:Id"].InnerText; if (!dictCheck.ContainsKey(sType)) { string sCFold = sOutFolder + @"\" + sType; FileFuncs.CreateFolder(sCFold); dictCheck.Add(sType, sCFold); FileFuncs.CreateFolder(sOutEnAssertFolder); } Item oI = new Item(); oI.Id = xn["l7:Id"].InnerText; oI.Name = xn["l7:Name"].InnerText; oI.Type = xn["l7:Type"].InnerText; oI.ItemXML = xn.InnerXml; Tracker.addItem(oI.Id, oI); } foreach (KeyValuePair <string, Item> oI in Tracker.oItems) { } StringBuilder sX = new StringBuilder(3900); StringBuilder sCluster = new StringBuilder(300); sCluster.AppendLine("----------------------------------"); sCluster.AppendLine(" Cluster Properties"); sCluster.AppendLine("----------------------------------"); sX.AppendLine("id|name|type|url|enabled"); foreach (XmlNode xn in xnList) { string sType = xn["l7:Type"].InnerText; string sName = xn["l7:Name"].InnerText; string sID = xn["l7:Id"].InnerText; string sUrlPattern = string.Empty; string sSerEnabled = string.Empty; sX.Append(sID); sX.Append("|"); sX.Append(sName); sX.Append("|"); sX.Append(sType); sX.Append("|"); switch (sType) { case "ASSERTION_ACCESS": case "AUDIT_CONFIG": break; case "CLUSTER_PROPERTY": sCluster.Append(xn.AA_NodeText("l7:Resource/l7:ClusterProperty/l7:Name", manager)); sCluster.Append("="); sCluster.AppendLine(xn.AA_NodeText("l7:Resource/l7:ClusterProperty/l7:Value", manager)); break; case "ENCAPSULATED_ASSERTION": case "FIREWALL_RULE": case "FOLDER": case "ID_PROVIDER_CONFIG": case "INTERFACE_TAG": case "JDBC_CONNECTION": case "LOG_SINK": break; case "POLICY": PolReader iP = new PolReader(xn, manager); iP.Analys(sOutPolicyFolder); break; case "RBAC_ROLE": case "RESOURCE_ENTRY": case "SCHEDULED_TASK": case "SECURE_PASSWORD": case "SECURITY_ZONE": case "SERVER_MODULE_FILE": break; case "SERVICE": //sUrlPattern = xn.AA_NodeText("l7:Resource/l7:Service/l7:ServiceDetail/l7:ServiceMappings/l7:HttpMapping/l7:UrlPattern", manager); //sSerEnabled = xn.AA_NodeText("l7:Resource/l7:Service/l7:ServiceDetail/l7:Enabled", manager); //sUrlPattern = xn["l7:Resource/l7:Service/l7:ServiceDetail/l7:ServiceMappings/l7:HttpMapping/l7:UrlPattern"].InnerText; ItemReader iSrv = new ItemReader(xn, manager); iSrv.AddService(sOutServiceFolder); SrvProp oS = null; if (Tracker.GetServiceObject(sID, out oS)) { sUrlPattern = oS.Url; sSerEnabled = oS.Enabled; } break; case "SSG_CONNECTOR": case "TRUSTED_CERT": break; case "USER": break; default: //errpr log for future break; } sX.Append(sUrlPattern); sX.Append("|"); sX.Append(sSerEnabled); sX.AppendLine("|"); } FileFuncs.WriteTxtFile(sOutFolder + "\\stats.txt", sX.ToString()); FileFuncs.WriteTxtFile(sOutFolder + "\\CLUSTER_PROPERTY\\cluster_properties.txt", sCluster.ToString()); //XmlNode n = xmlDoc.SelectSingleNode("l7:List/l7:Item", manager); //Console.WriteLine(n.InnerText); //Console.WriteLine("done"); //XmlNode rootNode = xmlDoc.DocumentElement; ////DisplayNodes(rootNode); //XmlNodeList xnList = xmlDoc.SelectNodes("//l7:List/l7:Item"); //foreach (XmlNode xn in xnList) //{ // string firstName = xn["FirstName"].InnerText; // string lastName = xn["LastName"].InnerText; // Console.WriteLine("Name: {0} {1}", firstName, lastName); //} //foreach (XmlNode xmlNode in xmlDoc.DocumentElement.ChildNodes[) //{ // Console.WriteLine(xmlNode.Attributes["currency"].Value + ": " + xmlNode.Attributes["rate"].Value); //} //// Create an isntance of XmlTextReader and call Read method to read the file //XmlTextReader textReader = new XmlTextReader("D:\\temp\\services.xml"); //textReader.Read(); //while (textReader.Read()) //{ // switch (textReader.NodeType) // { case XmlNodeType.Element: // //listBox1.Items.Add("<" + xmlReader.Name + ">"); // break; // case XmlNodeType.Text: // //listBox1.Items.Add(xmlReader.Value); // break; // case XmlNodeType.EndElement: // //listBox1.Items.Add(""); // break; // } // if (textReader.IsStartElement()) // { // Console.WriteLine(textReader.Name.ToString()); // //return only when you have START tag // switch (textReader.Name.ToString()) // { // case "Name": // Console.WriteLine("Name of the Element is : " + textReader.ReadString()); // break; // case "Location": // Console.WriteLine("Your Location is : " + textReader.ReadString()); // break; // } // } // Console.WriteLine(""); //} //// If the node has value //while (textReader.Read()) //{ // // Move to fist element // textReader.MoveToElement(); // Console.WriteLine("XmlTextReader Properties Test"); // Console.WriteLine("==================="); // // Read this element's properties and display them on console // Console.WriteLine("Name:" + textReader.Name); // Console.WriteLine("Base URI:" + textReader.BaseURI); // Console.WriteLine("Local Name:" + textReader.LocalName); // Console.WriteLine("Attribute Count:" + textReader.AttributeCount.ToString()); // Console.WriteLine("Depth:" + textReader.Depth.ToString()); // Console.WriteLine("Line Number:" + textReader.LineNumber.ToString()); // Console.WriteLine("Node Type:" + textReader.NodeType.ToString()); // Console.WriteLine("Attribute Count:" + textReader.Value.ToString()); //} }