Created
January 30, 2015 21:41
-
-
Save cfg/55c5ebec803915b69ed3 to your computer and use it in GitHub Desktop.
Hack function to bulk import DNS on WP VIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Paste this into the console on your /wp-admin/admin.php?page=domains page | |
* Make sure the 'Edit DNS' tab is selected | |
* Add entries using add_record( 'example.com', 'A', '127.0.0.1' ); | |
* or add_record( 'example.com', 'MX', '10 mail.example.com' ); | |
* MX records values should be the Priority<space>mailserver | |
* | |
*/ | |
add_record = function( record, type, value ) { | |
var valid_types = { | |
A:1, MX:1, CNAME:1, TXT:1 | |
}; | |
if( !valid_types.hasOwnProperty( type ) ) { | |
console.error( 'Invalid type: %s (record: %s, type: %s, value: %s', type, record, type, value ); | |
return false; | |
} | |
if( type == 'MX' ) { | |
var parts = value.split(' '); | |
var ttl = parts[0]; | |
value = parts[1]; | |
} | |
if( type == 'TXT' && value.length >= 192 ) { | |
console.error( 'Val too long: %s (record: %s, type: %s, value: %s', type, record, type, value ); | |
return false; | |
} | |
// Change the type | |
jQuery('.addnew-record .record-type').val( type ).trigger('change'); | |
// Update the primary entry | |
jQuery('.addnew-record .record-domain').val( record ); | |
// Add the main value | |
jQuery('.addnew-record .type.type-' + type + ' [name=data]').val( value ); | |
if( type == 'MX' ) { | |
// Set the TTL | |
jQuery('.addnew-record .type.type-MX .record-aux').val( ttl ); | |
} | |
// Save | |
jQuery('.addnew-record input[type=submit].save.button-secondary').click(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment