Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/opt/imh-python/bin/python2.7
- '''cPanel Admin'''
- import os
- import argparse
- import string
- import time
- import requests
- import paramiko
- __version__ = 'cPanel Admin 0.2 Beta - Use -h for help'
- __author__ = 'written by Riley'
- def main():
- print __version__
- '''
- The entry function to cPanel Admin.
- Parsing those arguments! Eventually adding more stuff to this.
- '''
- parser = argparse.ArgumentParser(description = 'A simple tool to manipulate' +
- 'cPanel VPS/Dedicated accounts'
- )
- group = parser.add_argument_group('cPanel Admin --rsync help')
- group.add_argument('--host',
- dest='host',
- help='Use --rsync in --rsync user --host hostname format.' +
- 'You will be then prompted for the remote servers remote password'
- )
- group.add_argument('--port',
- dest='ssh_port',
- help='Specify an ssh port other than 22'
- )
- parser.add_argument('--user',
- help='Specify and review a user',
- dest='user',
- required=True
- )
- parser.add_argument('--domain',
- help='Copy,duplicate,or move a users domain',
- dest='domain',
- )
- parser.add_argument('--db',
- help ='Dump a users databases to ' +
- 'the users home directory',
- dest='db',
- )
- parser.add_argument('--pass',
- '-p',
- help='Specify a passowrd for rsync,or other*',
- dest='password')
- parser.add_argument('--rsync',
- help='Rsync files to another ' +
- 'vps/dedicated. See --rhelp for details'
- )
- parser.add_argument('--dbdump',
- help='Dump all databases to /home/dump'
- )
- parser.add_argument('--restoredb',
- help='Restore all databases from ' +
- ' /home/dump'
- )
- parser.add_argument('--remote',
- help='Check server status ' +
- 'of a remote server'
- )
- parser.add_argument('--test', help='Test a move with ' +
- 'Lynx browser'
- )
- args = parser.parse_args()
- parsed.args = raw[0]
- # cPanel Admin rsync function. Uses paramiko SFTP.
- def cprsync(args):
- host = parsed.host
- if not parsed.host:
- parsed.user = raw_input("Please enter a remote server: ")
- maninput = True
- user = parsed.user
- if not parsed.user:
- parsed.user = raw_input("Please enter the user you will be migrating: ")
- maninput = True
- port = parsed.port
- if not parsed.port:
- parsed.port = raw_input("Specify the SSH port: ")
- maninput = True
- password = parsed.password
- if not parsed.password:
- parsed.password = raw_input("Enter the remote password")
- maninput = True
- # TODO: handle transferring of files better,make sure paramiko sftp allows me to set everything from parsed.*
- username = parsed.user
- password = parsed.password
- port = parsed.port
- cpasync = paramiko.Transport((host, port))
- cpasync.connect(username = username, password = password)
- csftp = paramiko.SFTPClient.from_cpasync(cpasync)
- local_dir = '/home/cpmove-rileybae.tar.gz' # Local files to be moved to the remote destination
- remote_dir = '/home/cpmove-rileybae' # Remote destination for files
- csftp.put(local_dir, remote_dir) # Put files on the remote destination
- # cPanel Admin dbdump() function. May or may not make it handle this differently in a later update.
- def dbdump(args):
- print "Enter any database name"
- database = raw_input()
- timestamp = time.strftime('%Y-%m-%d') # Makes a timestamp so you can keep better track of when you dumped it
- os.popen("mysqldump -e --opt -c %s" % (database,database+"_"+timestamp)) # Running mysqldump with popen(sue me)
- print "\n Database dumped to "+database+"_"+timestamp
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement