#!/usr/bin/env python
import oursql, time, sys, requests, re
import smtplib
import datetime
db = oursql.connect(host="localhost", user="root", passwd="", db="transfer")
mail_start = """
Hello,
As announced a short while ago, we are going to migrate your VPSes to new servers.
We've had some unforeseen technical difficulties that led to a delay, but these
have been resolved. This e-mail is to inform you that the migration process has
been started.
The following of your VPSes are affected:
%s
You can follow the queue position and progress of your VPS migrations here: %s
You will receive further notifications for every individual VPS that is being migrated.
Please ensure that you add admin@bluevm.com to your address book, so that
our e-mails do not end up in your spam folder.
Regards,
BlueVM Staff
https://bluevm.com/
"""
mail_vps_start = """
Hello,
This e-mail is to inform you that the migration of your VPS with the username %s has started.
You will receive an e-mail when this migration is finished.
You can follow the progress of all your VPS migrations at %s
Regards,
BlueVM Staff
https://bluevm.com/
"""
mail_vps_success = """
Hello,
This e-mail is to inform you that the migration of your VPS with the username %s has
finished successfully.
Your new IP addresses are:
%s
You can follow the progress of all your VPS migrations at %s
Regards,
BlueVM Staff
https://bluevm.com/
"""
mail_vps_error = """
Hello,
This e-mail is to inform you that the migration of your VPS with the username %s has
been aborted because an error has occurred. No data loss has occurred, and staff
will be looking into the issue shortly.
You can follow the progress of all your VPS migrations at %s
Regards,
BlueVM Staff
https://bluevm.com/
"""
class Panel(object):
def __init__(self, target):
self.target = target
self.sess = requests.Session()
def login(self, username, password):
page = self.sess.get("%s/login/" % self.target).text
match = re.search('', page)
if match is None:
raise Exception("Not a valid HyperVM panel.")
fid = match.group(1)
error_string = "Login Unsuccessful"
post_target = "%s/htmllib/phplib/" % self.target
post_vars = {
"frm_clientname": username,
"frm_password": password,
"id": fid,
"login": "Login"
}
page = self.sess.post(post_target, data=post_vars).text
if error_string in page:
raise Exception("Login failed.")
def run_command(self, node, command):
post_target = "%s/display.php" % self.target
post_vars = {
"frm_o_o[0][class]": "pserver",
"frm_o_o[0][nname]": node,
"frm_pserver_c_ccenter_command": command,
"frm_pserver_c_ccenter_error": "",
"frm_action": "updateform",
"frm_subaction": "commandcenter",
"frm_change": "Execute"
}
page = self.sess.post(post_target, data=post_vars).text
result = re.search("