#!/usr/bin/python # An SMTP Mail sender import os import sys sys.path.append("/home/mojowen/MoveIt") from models.mail import send_mail if __name__ == '__main__': subject = (sys.argv[1] if len(sys.argv) > 1 else 'Automated Message from Webfaction') to_addrs = (sys.argv[2] if len(sys.argv) > 2 else None) raw_msg = "\n".join(sys.stdin.readlines()) if len(raw_msg) > 0: send_mail(raw_msg, subject, to_addrs)
sql = [ 'mysqldump -u ', user, ' --password='******' > wp-content/db-backup.sql' ] sql = " ".join(sql) local.c(sql) local.c('tar -jcvf ' + backup + ' wp-content') local.c('rm wp-content/db-backup.sql') php = ''' \ include_once("wp-load.php"); \ include_once("wp-admin/includes/admin.php"); \ $updates = get_core_updates(); \ if( $updates[0]->response != "latest" ) echo "upgrade needed"; ''' upgrade = local.c("php -r '%s' " % php) if upgrade == 'upgrade needed': output += site + " needs WordPress upgrade \n" else: local.c('tar -jcvf ' + backup + ' .') except: output += "Something went wrong with " + site + "\n" if len(output) > 0: send_mail(output, "%s Backup Report" % type_of_backup.capitalize())
def get_head(domain): conn = httplib.HTTPConnection(domain) conn.request('HEAD', '/') return conn.getresponse() def check_site(website, follow=True): res = get_head(website) if res.status / 100 == 3: location = [hd for hd in res.getheaders() if hd[0] == 'location'][0][1] location = [ st for st in location.replace('http', '').split('/') if len(st) > 1 ][0] return check_site(location, False) # Follow one redirect else: return res for website in websites: if website['name'] not in exceptions: main_domain = website['subdomains'][0] res = check_site(main_domain) if res.status != 200: output.append("%s at %s responded with a %d" % (website['name'], main_domain, res.status)) if len(output) > 0: send_mail("\n".join(output), "Uptime Report")
websites = wf.server.list_websites(wf.session_id) exceptions = ['hubbot'] output = [] def get_head(domain): conn = httplib.HTTPConnection(domain) conn.request('HEAD','/') return conn.getresponse() def check_site(website, follow=True): res = get_head(website) if res.status / 100 == 3: location = [hd for hd in res.getheaders() if hd[0] == 'location'][0][1] location = [st for st in location.replace('http', '').split('/') if len(st) > 1][0] return check_site(location, False) # Follow one redirect else: return res for website in websites: if website['name'] not in exceptions: main_domain = website['subdomains'][0] res = check_site(main_domain) if res.status != 200: output.append("%s at %s responded with a %d" % (website['name'], main_domain, res.status)) if len(output) > 0: send_mail("\n".join(output), "Uptime Report")
password = strip_wp_grep( local.c('grep DB_PASSWORD wp-config.php') ) user = strip_wp_grep( local.c('grep DB_USER wp-config.php') ) sql = ['mysqldump -u ',user,' --password='******' > wp-content/db-backup.sql'] sql = " ".join(sql) local.c(sql) local.c('tar -jcvf '+backup+' wp-content') local.c('rm wp-content/db-backup.sql') php = ''' \ include_once("wp-load.php"); \ include_once("wp-admin/includes/admin.php"); \ $updates = get_core_updates(); \ if( $updates[0]->response != "latest" ) echo "upgrade needed"; ''' upgrade = local.c("php -r '%s' " % php ) if upgrade == 'upgrade needed': output += site+" needs WordPress upgrade \n" else: local.c('tar -jcvf '+backup+' .') except: output += "Something went wrong with "+site+"\n" if len(output) > 0: send_mail(output, "%s Backup Report" % type_of_backup.capitalize())