public static Boolean Parse(out RegisterDump Register, Byte[] registerZipArchive, String NameEventLog) { Boolean ret = true; Register = new RegisterDump(); String registerZipArchivePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\register.zip"; String UnZIPPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\register"; String dumpfile = UnZIPPath + @"\dump.xml"; String signdumpfile = UnZIPPath + @"\dump.xml.sig"; try { File.WriteAllBytes(registerZipArchivePath, registerZipArchive); ZipFile.ExtractToDirectory(registerZipArchivePath, UnZIPPath); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(dumpfile); Register.UpdateTime = xmlDoc.GetElementsByTagName("reg:register")[0].Attributes.GetNamedItem("updateTime").InnerText; XmlNodeList content = xmlDoc.GetElementsByTagName("content"); for (int i = 0; i < content.Count; i++) { ItemRegisterDump item = new ItemRegisterDump(); item.id = content[i].Attributes.GetNamedItem("id").InnerText; item.includeTime = content[i].Attributes.GetNamedItem("includeTime").InnerText; foreach (XmlNode node in content[i].ChildNodes) { switch(node.Name) { case "decision": item.date = node.Attributes.GetNamedItem("date").InnerText; item.number = node.Attributes.GetNamedItem("number").InnerText; item.org = node.Attributes.GetNamedItem("org").InnerText; break; case "url": item.url.Add(node.InnerText); break; case "domain": item.domain.Add(node.InnerText); break; case "ip": item.ip.Add(node.InnerText); break; } } Register.Items.Add(item); } Directory.Delete(UnZIPPath, true); File.Delete(registerZipArchivePath); } catch (Exception error) { EventLog.WriteEntry(NameEventLog, "Ошибка парсера: " + error.Message, EventLogEntryType.Error, 200, 003); ret = false; } return ret; }
public static Boolean Parse(out RegisterDump Register, Byte[] registerZipArchive, String NameEventLog) { Boolean ret = true; Register = new RegisterDump(); String registerZipArchivePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\register.zip"; String UnZIPPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\register"; String dumpfile = UnZIPPath + @"\dump.xml"; String signdumpfile = UnZIPPath + @"\dump.xml.sig"; try { File.WriteAllBytes(registerZipArchivePath, registerZipArchive); // ZipFile.ExtractToDirectory(registerZipArchivePath, UnZIPPath); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(dumpfile); Register.UpdateTime = xmlDoc.GetElementsByTagName("reg:register")[0].Attributes.GetNamedItem("updateTime").InnerText; XmlNodeList content = xmlDoc.GetElementsByTagName("content"); for (int i = 0; i < content.Count; i++) { ItemRegisterDump item = new ItemRegisterDump(); item.id = content[i].Attributes.GetNamedItem("id").InnerText; item.includeTime = content[i].Attributes.GetNamedItem("includeTime").InnerText; foreach (XmlNode node in content[i].ChildNodes) { switch (node.Name) { case "decision": item.date = node.Attributes.GetNamedItem("date").InnerText; item.number = node.Attributes.GetNamedItem("number").InnerText; item.org = node.Attributes.GetNamedItem("org").InnerText; break; case "url": item.url.Add(node.InnerText); break; case "domain": item.domain.Add(node.InnerText); break; case "ip": item.ip.Add(node.InnerText); break; } } Register.Items.Add(item); } Directory.Delete(UnZIPPath, true); File.Delete(registerZipArchivePath); } catch (Exception error) { EventLog.WriteEntry(NameEventLog, "Ошибка парсера: " + error.Message, EventLogEntryType.Error, 200, 003); ret = false; } return(ret); }
public static Boolean AddFilterL7(String ip, String username, String password, RegisterDump dump, String SRCAddress, String NameEventLog) { Boolean ret = true; try { MK mikrotik = new MK(IPAddress.Parse(ip).ToString()); if (mikrotik.Login(username, password)) { mikrotik.Send("/system/script/add"); mikrotik.Send("=name=cleaner"); mikrotik.Send("=source=/ip firewall layer7-protocol remove [find comment=register]\n/ip firewall filter remove [find comment=register]", true); mikrotik.Read(); mikrotik.Send("/system/script/run"); mikrotik.Send("=number=cleaner", true); mikrotik.Read(); /* Cleaner * /ip firewall layer7-protocol remove [find comment=register] * /ip firewall filter remove [find comment=register] */ foreach (ItemRegisterDump item in dump.Items) { for (Int32 i = 0; i < item.domain.Count; i++) { mikrotik.Send("/ip/firewall/layer7-protocol/add"); mikrotik.Send("=name=" + item.id + "_" + i); mikrotik.Send("=comment=register"); mikrotik.Send("=regexp=^.+(" + item.domain[i] + ").*$", true); mikrotik.Read(); mikrotik.Send("/ip/firewall/filter/add"); mikrotik.Send("=action=drop"); mikrotik.Send("=chain=forward"); mikrotik.Send("=disabled=no"); mikrotik.Send("=dst-port=80"); mikrotik.Send("=layer7-protocol=" + item.id + "_" + i); mikrotik.Send("=protocol=tcp"); mikrotik.Send("=src-address=" + SRCAddress); mikrotik.Send("=comment=register", true); mikrotik.Read(); } } } mikrotik.Close(); } catch (Exception error) { EventLog.WriteEntry(NameEventLog, "Ошибка добавления правил: " + error.Message, EventLogEntryType.Error, 200, 004); ret = false; } return(ret); }
public static Boolean AddFilterL7(String ip, String username, String password, RegisterDump dump, String SRCAddress, String NameEventLog) { Boolean ret = true; try { MK mikrotik = new MK(IPAddress.Parse(ip).ToString()); if (mikrotik.Login(username, password)) { mikrotik.Send("/system/script/add"); mikrotik.Send("=name=cleaner"); mikrotik.Send("=source=/ip firewall layer7-protocol remove [find comment=register]\n/ip firewall filter remove [find comment=register]", true); mikrotik.Read(); mikrotik.Send("/system/script/run"); mikrotik.Send("=number=cleaner", true); mikrotik.Read(); /* Cleaner * /ip firewall layer7-protocol remove [find comment=register] * /ip firewall filter remove [find comment=register] */ foreach (ItemRegisterDump item in dump.Items) { for (Int32 i = 0; i < item.domain.Count; i++ ) { mikrotik.Send("/ip/firewall/layer7-protocol/add"); mikrotik.Send("=name=" + item.id + "_" + i); mikrotik.Send("=comment=register"); mikrotik.Send("=regexp=^.+(" + item.domain[i] + ").*$", true); mikrotik.Read(); mikrotik.Send("/ip/firewall/filter/add"); mikrotik.Send("=action=drop"); mikrotik.Send("=chain=forward"); mikrotik.Send("=disabled=no"); mikrotik.Send("=dst-port=80"); mikrotik.Send("=layer7-protocol=" + item.id + "_" + i); mikrotik.Send("=protocol=tcp"); mikrotik.Send("=src-address=" + SRCAddress); mikrotik.Send("=comment=register", true); mikrotik.Read(); } } } mikrotik.Close(); } catch (Exception error) { EventLog.WriteEntry(NameEventLog, "Ошибка добавления правил: " + error.Message, EventLogEntryType.Error, 200, 004); ret = false; } return ret; }