Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates a new e-mail forwarder for your DomainFactory (www.df.eu) account
//
// Creates a new e-mail forwarder for your DomainFactory (www.df.eu) account
//
// Sadly DomainFactory doesn't provide an API for managing "ManagedHosting"
// accounts, so I decided to write a short script for creating e-mail
// forwarders, because I like to have one e-mail address for every service
// I register for and I don't like to waste my time clicking through several
// pages to archive this ;)
//
// To run this code you need PhantomJS - http://www.phantomjs.org/
//
// Usage:
// ------
// $ phantomjs df-forward-email.js user:password forward@email.de to@email.de
//
// Author: Lay Flags
// E-mail: code@layfla.gs
// Date: 8th of May 2011
//
// _ __ _
// | | __ _ _ _ / _| | __ _ __ _ ___
// | |/ _` | | | | |_| |/ _` |/ _` / __|
// | | (_| | |_| | _| | (_| | (_| \__ \
// |_|\__,_|\__, |_| |_|\__,_|\__, |___/
// |___/ |___/
//
//
// This is free and unencumbered software released into the public domain
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org/>
//
(function() {
var helper = {
followUrl: function(url) {
console.log(' - open url: ' + url);
phantom.open(url);
}
};
// checks args
//TODO validate args (i.e. regex)
if (phantom.args.length < 3) {
console.log('Usage: phantomjs df-forward-email.js user:password' +
' forward@email.de to@email.de');
return phantom.exit();
}
// check response for maintenance
if (phantom.content.match(/Wartung/) !== null) {
console.log("ERROR: Site currently in maintenance mode!");
return phantom.exit();
}
phantom.state = phantom.state || 0;
console.log("Step " + phantom.state);
[
function _load_login_page_() {
helper.followUrl('https://admin.df.eu/kunde/email.php?' +
'action=createAddress');
},
function _login_() {
var user_password = phantom.args[0].split(':')
var u = user_password[0], p = user_password[1];
console.log(' - login with ' + u + ":" + p);
document.getElementById('login').setAttribute('value', u);
document.querySelector('input[name=km_password]')
.setAttribute('value', p);
document.querySelector('form').submit();
},
function _enter_new_forward_email_address_() {
var email = phantom.args[1];
var domain = document.querySelector(
'#localhost > option[value^="' + email.split('@')[1] +
'"]').value.split('|')[1];
var button = document.querySelector(
'button[name*="createStorage"]');
console.log(' - enter new forward email: ' + email)
console.log(' - determine domain code: ' + domain);
document.getElementById('address').value = email;
document.getElementById('domain').value = domain;
button.onclick = null;
button.click();
},
function _select_classic_email_type_() {
var email = phantom.args[1];
var msgNode = document.querySelector('.d-msg-text');
if (msgNode) {
console.log(' - [ERROR] ' + msgNode.innerText);
return phantom.exit();
}
console.log(' - select classic email type for: ' + email);
document.querySelector('input[src*="klassisch"]').click();
},
function _enter_target_email_address_() {
var targetEmail = phantom.args[2];
console.log(' - enter target email: ' + targetEmail);
document.getElementById('forwarder_switch').click();
document.getElementById('fwtarget').value = targetEmail;
phantom.sleep(1000);
document.querySelector('button[name*="add_forwarder"]').click();
document.querySelector(
'table button[name="action[save]"]').click();
},
function _check_response_() {
var email = phantom.args[1];
var msgNode = document.querySelector('.d-msg-text');
if (msgNode) {
console.log(' - [SUCCESS] ' + msgNode.innerText);
} else {
console.log(' - [FAILED]');
}
phantom.exit();
}
][phantom.state++]();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment