Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Created by Alan M. Orther - alan.orther@gmail.com
  3. # This script is used to duplicate a Wordpress website and DB.
  4.  
  5. import os
  6. import random
  7.  
  8. # Variables
  9. website_url = ""
  10. website_url_dir = ""
  11. city_name = ""
  12. state_abb = ""
  13. db_name = ""
  14. db_user = ""
  15. db_pass = ""
  16.  
  17.  
  18. def website_url_function():
  19. # Get the domain name and create the domain directory name.
  20. global website_url, website_url_dir
  21. user_input = raw_input("\nPlease copy and paste the new domain name:"
  22. " ").lower()
  23. website_url = user_input.strip()
  24. website_url_dir = website_url.replace('.', '')
  25.  
  26.  
  27. def city():
  28. # Get the name of the city for this jobs website and remove spaces.
  29. global city_name
  30. user_input = raw_input("What city is this site for? ").lower()
  31. city_input = user_input.strip()
  32. city_name = city_input.replace(" ", "")
  33.  
  34.  
  35. def state():
  36. # Get the name of the state for this jobs website and remove spaces.
  37. global state_abb
  38. user_input = raw_input("What is the state abbreviation for the city? Ex: "
  39. "California = CA : ").lower()
  40. state_input = user_input.strip()
  41. state_abb = state_input.replace(" ", "")
  42.  
  43. # Confirm the state abbreviation is 2 characters or quit.
  44. if len(state_abb) != 2:
  45. print "\nThe state abbreviation needs to be 2 characters.\n"
  46. state()
  47.  
  48.  
  49. def db_info():
  50. global db_name, db_user, db_pass, website_url_dir, state_abb, city_name
  51. # Create the DB, DB user (max 16 char), and DB password.
  52. # DB name is wpjob + the domain name without the "." + state abbreviation.
  53. db_name = "wpjob" + website_url_dir + state_abb
  54.  
  55. # Create DB user. It is the wpjob + first 5 of the city name + the state
  56. # abbreviation + random 2 digit number.
  57. db_user = "wpjob" + str(random.randint(10, 99)) + city_name[:6] + state_abb
  58.  
  59. # Create the DB password. It is wppass + first 2 of the city name + the
  60. # state abbreviation + random 2 digit number.
  61. db_pass = "wppass" + str(random.randint(10, 99)) + city_name[:2] + state_abb
  62.  
  63.  
  64. website_url_function()
  65. city()
  66. state()
  67. db_info()
  68.  
  69. print "\nWebsite URL = " + website_url
  70. print "Website directory = /var/www/" + website_url_dir
  71. print "DB name = " + db_name
  72. print "DB user = " + db_user
  73. print "DB password = " + db_pass + "\n"
  74.  
  75. # Create webpage directory in /var/www/ if it doesn't already exist.
  76. # Create the directory path and expand it in the shell.
  77. webpage_directory_string = "/var/www/%s/" % website_url_dir
  78. webpage_directory = os.path.expanduser(webpage_directory_string)
  79.  
  80. # Check if the directory exists. If it exists, warn and quit. If not, create it.
  81. # Check for directory and exit script if it exists.
  82. if os.path.exists(webpage_directory):
  83. print "\nThis website directory already exists. Exiting program.\n"
  84. quit()
  85.  
  86. # Check for directory and create it is it doesn't.
  87. if not os.path.exists(webpage_directory):
  88. os.makedirs(webpage_directory)
  89.  
  90. # Create or open and append to webinfo.log file. Adds all names and credentials.
  91. log = open(webpage_directory + 'webpageinfo.log', 'a+')
  92. write = "\nWebsite URL: %s\n" % website_url
  93. log.write(write)
  94. write = "Website directory: %s\n" % webpage_directory_string
  95. log.write(write)
  96. write = "City: %s\n" % city_name
  97. log.write(write)
  98. write = "State: %s\n" % state_abb
  99. log.write(write)
  100. write = "DB Name: %s\n" % db_name
  101. log.write(write)
  102. write = "DB Username: %s\n" % db_user
  103. log.write(write)
  104. write = "DB Password: %s\n" % db_pass
  105. log.write(write)
  106. write = "\n"
  107. log.write(write)
  108. log.close()
  109.  
  110. # Ask user to input the root database password.
  111. password = raw_input("Please type the DB root password and hit Enter: ")
  112.  
  113. print "The MySQL root password is: %s" % password
  114.  
  115. # Edit the files
  116. # s = open("mount.txt").read()
  117. # s = s.replace('mickey', 'minnie')
  118. # f = open("mount.txt", 'w')
  119. # f.write(s)
  120. # f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement