Advertisement
Guest User

rewrite of cpanel admin

a guest
Jul 14th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. #!/opt/imh-python/bin/python2.7
  2. '''cPanel Admin'''
  3.  
  4. import os
  5. import argparse
  6. import string
  7. import time
  8. import requests
  9. import paramiko
  10. __version__ = 'cPanel Admin 0.2 Beta - Use -h for help'
  11. __author__ = 'written by Riley'
  12.  
  13.  
  14. def main():
  15. print __version__
  16. '''
  17. The entry function to cPanel Admin.
  18. Parsing those arguments! Eventually adding more stuff to this.
  19. '''
  20. parser = argparse.ArgumentParser(description = 'A simple tool to manipulate' +
  21. 'cPanel VPS/Dedicated accounts'
  22. )
  23. group = parser.add_argument_group('cPanel Admin --rsync help')
  24. group.add_argument('--host',
  25. dest='host',
  26. help='Use --rsync in --rsync user --host hostname format.' +
  27. 'You will be then prompted for the remote servers remote password'
  28. )
  29. group.add_argument('--port',
  30. dest='ssh_port',
  31. help='Specify an ssh port other than 22'
  32. )
  33. parser.add_argument('--user',
  34. help='Specify and review a user',
  35. dest='user',
  36. required=True
  37. )
  38. parser.add_argument('--domain',
  39. help='Copy,duplicate,or move a users domain',
  40. dest='domain',
  41. )
  42. parser.add_argument('--db',
  43. help ='Dump a users databases to ' +
  44. 'the users home directory',
  45. dest='db',
  46. )
  47. parser.add_argument('--pass',
  48. '-p',
  49. help='Specify a passowrd for rsync,or other*',
  50. dest='password')
  51. parser.add_argument('--rsync',
  52. help='Rsync files to another ' +
  53. 'vps/dedicated. See --rhelp for details'
  54. )
  55. parser.add_argument('--dbdump',
  56. help='Dump all databases to /home/dump'
  57. )
  58. parser.add_argument('--restoredb',
  59. help='Restore all databases from ' +
  60. ' /home/dump'
  61. )
  62. parser.add_argument('--remote',
  63. help='Check server status ' +
  64. 'of a remote server'
  65. )
  66. parser.add_argument('--test', help='Test a move with ' +
  67. 'Lynx browser'
  68. )
  69.  
  70. args = parser.parse_args()
  71. parsed.args = raw[0]
  72.  
  73. # cPanel Admin rsync function. Uses paramiko SFTP.
  74. def cprsync(args):
  75. host = parsed.host
  76. if not parsed.host:
  77. parsed.user = raw_input("Please enter a remote server: ")
  78. maninput = True
  79. user = parsed.user
  80. if not parsed.user:
  81. parsed.user = raw_input("Please enter the user you will be migrating: ")
  82. maninput = True
  83. port = parsed.port
  84. if not parsed.port:
  85. parsed.port = raw_input("Specify the SSH port: ")
  86. maninput = True
  87. password = parsed.password
  88. if not parsed.password:
  89. parsed.password = raw_input("Enter the remote password")
  90. maninput = True
  91. # TODO: handle transferring of files better,make sure paramiko sftp allows me to set everything from parsed.*
  92. username = parsed.user
  93. password = parsed.password
  94. port = parsed.port
  95. cpasync = paramiko.Transport((host, port))
  96. cpasync.connect(username = username, password = password)
  97. csftp = paramiko.SFTPClient.from_cpasync(cpasync)
  98. local_dir = '/home/cpmove-rileybae.tar.gz' # Local files to be moved to the remote destination
  99. remote_dir = '/home/cpmove-rileybae' # Remote destination for files
  100. csftp.put(local_dir, remote_dir) # Put files on the remote destination
  101. # cPanel Admin dbdump() function. May or may not make it handle this differently in a later update.
  102. def dbdump(args):
  103. print "Enter any database name"
  104. database = raw_input()
  105. timestamp = time.strftime('%Y-%m-%d') # Makes a timestamp so you can keep better track of when you dumped it
  106. os.popen("mysqldump -e --opt -c %s" % (database,database+"_"+timestamp)) # Running mysqldump with popen(sue me)
  107. print "\n Database dumped to "+database+"_"+timestamp
  108.  
  109.  
  110. if __name__ == '__main__':
  111. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement