public TemplatePluginData OnGetTemplateData(BindingList <RecordDnsPoison> dnsPoisonRecords) { var templateData = new TemplatePluginData(); var genericObjectList = new List <RecordDnsPoison>(); // Where necessary replace current configuration parameter // with placeholder values foreach (RecordDnsPoison tmpRecord in dnsPoisonRecords) { var realRecord = new RecordDnsPoison(tmpRecord.HostName, tmpRecord.IpAddress, tmpRecord.ResponseType, tmpRecord.CName, tmpRecord.TTL, tmpRecord.MustMatch); if (tmpRecord.IpAddress == this.plugin.Config.HostApplication.CurrentIP) { realRecord.IpAddress = MinaryLib.DSL.Config.CONSTANT_LOCAL_IP; } genericObjectList.Add(realRecord); } // Serialize the list var stream = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(stream, genericObjectList); stream.Seek(0, SeekOrigin.Begin); // Assign plugin data to "Plugin Template DTO" templateData.PluginConfigurationItems = stream.ToArray(); return(templateData); }
public void VerifyInputData(RecordDnsPoison newRecord) { // Verify whether Hostname and IPaddress for correctness. if (this.VerifyHostNameStructure(newRecord.HostName) == false) { throw new Exception("Something is wrong with the host name"); } if (this.VerifyIpAddressStructure(newRecord.IpAddress) == false) { throw new Exception("Something is wrong with the IP address"); } if (newRecord.ResponseType == DnsResponseType.CNAME && this.VerifyCNameStructure(newRecord.CName) == false) { throw new Exception("Something is wrong with the CName host name"); } // Verify whether TTL has a valid value long ttl = 0; if (Regex.Match(this.tb_ttl.Text, @"^\d{1,10}$").Success == false || long.TryParse(this.tb_ttl.Text, out ttl) == false || ttl < 1 || ttl > 4294967296) { throw new Exception("Something is wront with the TTL.\r\nValue must be 1-4'294'967'296"); } // Verify whether only "mustMatch" or "doesntMatch" records are in list if (this.dnsPoisonRecords.Count > 0 && this.dnsPoisonRecords[0].MustMatch != newRecord.MustMatch) { throw new Exception("All records must either use \"does match\" or dont use it. You can't mix it."); } // Ensure that host/ip combination does not exist. foreach (RecordDnsPoison tmpRecord in this.dnsPoisonRecords) { if (tmpRecord.HostName.ToLower() == newRecord.HostName.ToLower()) { throw new Exception("An entry for this hostname already exists"); } } }
private void AddRecord(RecordDnsPoison newRecord) { if (this.InvokeRequired) { this.BeginInvoke(new AddRecordDelegate(this.AddRecord), new object[] { newRecord }); return; } var firstVisibleRowTop = -1; this.VerifyInputData(newRecord); lock (this) { // Memorize DataGridView position and selection firstVisibleRowTop = this.dgv_Spoofing.FirstDisplayedScrollingRowIndex; // Update DataGridView this.dgv_Spoofing.SuspendLayout(); try { this.dnsPoisonRecords.Insert(0, newRecord); while (this.dgv_Spoofing.Rows.Count > this.maxRowNum) { this.dnsPoisonRecords.RemoveAt(this.dgv_Spoofing.Rows.Count - 1); } if (firstVisibleRowTop >= 0) { this.dgv_Spoofing.FirstDisplayedScrollingRowIndex = firstVisibleRowTop; } } catch (Exception) { } this.dgv_Spoofing.ResumeLayout(); } }