-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddWebsite.rb
More file actions
executable file
·58 lines (46 loc) · 2 KB
/
AddWebsite.rb
File metadata and controls
executable file
·58 lines (46 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env ruby
###################################################
# Author: Randy Hoover <randy.hoover@gmail.com> #
# Date Created: 2013-10-14 #
# Last Modified: 2013-10-18 #
###################################################
# HighLine for making prompting easier, ipaddress for ip checking
require 'highline/import'
# check to see if we're running as root
raise 'Must run as root' unless Process.uid ==0
# define method to "sanitize" our inputed information
def sanitize_text(text)
text.gsub(/\s+/,"")
text.downcase
end
# define method to see if user exists
def user_exists(username)
username = sanitize_text(username)
File.directory? "/home/#{username}"
end
# method for checking to see if the site exists either in the form of a directory
# or in the form of an apache virtualhost
def site_exists(username,hostname,tld)
# strip out all the junk and make sure everything is lowercase
hostname = sanitize_text(hostname)
tld = sanitze_text(tld)
# check to see if user already has a folder and error if folder exists
if (File.directory? "/home/#{username}/webroot/#{hostname}.#{tld}" == true)
abort("ERROR: Folder exists for user #{username} and website #{hostname}.#{tld} please delete or pick a new hostname")
end
# then check to see if there's already an apache configuration for the site
if (File.file? "/etc/apache2/sites-available/#{hostname}.#{tld}.conf" == true)
abort("ERROR: Configuration file exists for website #{hostname}.#{tld} please delete or pick new hostname")
end
end
username = ask "Username of the account the website will go under: "
# kill the script if user doesn't exist
if (user_exists(username) == false)
abort("ERROR: User doesn't exist, please create user")
end
hostname = ask "Hostname without tld (ie clarionhoover test.clarionhoover): "
tld = ask "TLD for hostname (ie com co org without the .): "
# not sure what to do here for this
if (site_exists(username,hostname,tld) == false)
# it works so do i just do nothing?
end