-
Notifications
You must be signed in to change notification settings - Fork 5
/
fixips.py
47 lines (45 loc) · 1.98 KB
/
fixips.py
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
#!/usr/bin/env python
import subprocess
import os
from optparse import OptionParser
def main():
usage = "usage: python %prog [options] arg"
parser = OptionParser(usage)
parser.add_option("-s", "--source", dest="sourceip", type=str,
help="set the source ip address.")
parser.add_option("-p", "--port", dest="sourceport", default="22",
help="set port, defaults to 22 if not set")
(options, args) = parser.parse_args()
if (os.path.isfile("/etc/domainips-src") == False):
if (options.sourceip is None):
print("You must provide an IP address.")
quit()
else:
try:
grabips = "rsync -ave 'ssh -p %s' %s:/etc/domainips /etc/domainips-src" % (
options.sourceport, options.sourceip)
subprocess.call(grabips, shell=True)
except Exception:
print (
"\nrsync failed\nplease retry and manually move the /etc/domainips file to /etc/domainips-src on destination system\n")
quit()
f = open('/var/cpanel/mainip', 'r')
mainip = f.read()
print("setting all cPanel accounts to default shared ip.\n")
with open('/etc/trueuserdomains') as input_file:
for i in input_file: # set all cPanel accounts to default main ip
i = i.split()
print("\n%s -> %s\n" % (i[1], mainip))
setip = "whmapi1 setsiteip ip=%s user=%s" % (mainip, i[1])
subprocess.call(setip, shell=True)
with open('/etc/domainips-src') as input_file:
next(input_file)
for i in input_file: # set all dedicated ip cPanel accounts to proper IP
i = i.split()
i[0] = i[0].replace(':', '')
i[1] = i[1].replace(' ', '')
print("\n%s -> %s\n" % (i[1], i[0]))
setip = "whmapi1 setsiteip ip=%s domain=%s" % (i[0], i[1])
subprocess.call(setip, shell=True)
if __name__ == "__main__":
main()