MsDNS2012 fix

This commit is contained in:
dev_amdtel 2014-08-18 16:57:44 +04:00
parent 61f6820f98
commit 1fee4f0f85
2 changed files with 52 additions and 8 deletions

View file

@ -306,17 +306,61 @@ namespace WebsitePanel.Providers.DNS
ps.RunPipeline( cmd ); ps.RunPipeline( cmd );
} }
public static void Remove_DnsServerResourceRecord( this PowerShellHelper ps, string zoneName, string Name, string type, string recordData ) public static void Remove_DnsServerResourceRecord( this PowerShellHelper ps, string zoneName, DnsRecord record)
{ {
string type;
if (!RecordTypes.rrTypeFromRecord.TryGetValue(record.RecordType, out type))
throw new Exception( "Unknown record type" );
string Name = record.RecordName;
if (String.IsNullOrEmpty(Name)) Name = "@"; if (String.IsNullOrEmpty(Name)) Name = "@";
var cmd = new Command( "Remove-DnsServerResourceRecord" ); var cmd = new Command("Get-DnsServerResourceRecord");
cmd.addParam("ZoneName", zoneName); cmd.addParam("ZoneName", zoneName);
cmd.addParam("Name", Name); cmd.addParam("Name", Name);
cmd.addParam("RRType", type); cmd.addParam("RRType", type);
Collection<PSObject> resourceRecords = ps.RunPipeline(cmd);
if (!String.IsNullOrEmpty(recordData)) object inputObject = null;
cmd.addParam("RecordData", recordData); foreach (PSObject resourceRecord in resourceRecords)
{
DnsRecord dnsResourceRecord = resourceRecord.asDnsRecord(zoneName);
bool found = false;
switch(dnsResourceRecord.RecordType)
{
case DnsRecordType.A:
case DnsRecordType.AAAA:
case DnsRecordType.CNAME:
case DnsRecordType.NS:
case DnsRecordType.TXT:
found = dnsResourceRecord.RecordData == record.RecordData;
break;
case DnsRecordType.SOA:
found = true;
break;
case DnsRecordType.MX:
found = (dnsResourceRecord.RecordData == record.RecordData) && (dnsResourceRecord.MxPriority == record.MxPriority);
break;
case DnsRecordType.SRV:
found = (dnsResourceRecord.RecordData == record.RecordData)
&&(dnsResourceRecord.SrvPriority == record.SrvPriority)
&&(dnsResourceRecord.SrvWeight == record.SrvWeight)
&&(dnsResourceRecord.SrvPort == record.SrvPort);
break;
}
if (found)
{
inputObject = resourceRecord;
break;
}
}
cmd = new Command( "Remove-DnsServerResourceRecord" );
cmd.addParam( "ZoneName", zoneName );
cmd.addParam("InputObject", inputObject);
cmd.addParam( "Force" ); cmd.addParam( "Force" );
ps.RunPipeline( cmd ); ps.RunPipeline( cmd );

View file

@ -172,7 +172,7 @@ namespace WebsitePanel.Providers.DNS
string rrType; string rrType;
if( !RecordTypes.rrTypeFromRecord.TryGetValue( record.RecordType, out rrType ) ) if( !RecordTypes.rrTypeFromRecord.TryGetValue( record.RecordType, out rrType ) )
throw new Exception( "Unknown record type" ); throw new Exception( "Unknown record type" );
ps.Remove_DnsServerResourceRecord( zoneName, record.RecordName, rrType, record.RecordData ); ps.Remove_DnsServerResourceRecord( zoneName, record);
} }
catch( Exception ex ) catch( Exception ex )
{ {