rf-sbc-repair

#!/usr/bin/env python
 
####################################################
# #
# Copyright (C) 2016 Ringfree Communications LLC #
# By Kendall Weaver <kendall@ringfree.com> #
# #
####################################################
 
 
import os, sys
 
 
# Test for the CTID argument, print usage and exit if we don't see it.
try:
sys.argv[1]

except:
print("Usage: rf-sbc-repair [CTID]\n")
sys.exit(0)
 
 
# Quick test for dev purposes. Ignore in production.
if (sys.argv[1] == "test"):
wd = "/home/kendall/DEV/rf-sbc-repair"
 
else:
wd = "/home/" + sys.argv[1]


if not (os.path.exists(wd)):
print("Error: Please specify a valid CTID.")
sys.exit(1)
 
 
# Iterate through the items in the CTID home directory, find all of the
# .cfg files, test them to see if they look like actual configuration
# files (versus templates or whatever else), and then replace the proxy
# string in the appropriate place. We're using David's sed command
# instead of Python's str.replace() method because we want him to feel
# warm and fuzzy inside.
for item in os.listdir(wd):

global x
global y
x = 0
y = 0

if (item[-4:] == ".cfg"):
try:
cfgfile = open(wd + "/" + item, 'r')
except:
print("Unable to open " + item)
continue

for line in cfgfile.readlines():
if "TEMPLATE" in line:
print("Skipping: " + item)
x = 1
break

if 'reg.1.outboundProxy.address=""' in line:
print("Changing: " + item)
y = 1
break

cfgfile.close()

if (x == 1):
x = 0
continue

elif (y == 1):
y = 0
os.system('sed -i -e \'s/reg.1.outboundProxy.address=""/reg.1.outboundProxy.address="sbc001.ringfree.biz"/g\' ' + item)
 
 
# Check that rf-ppt-repair exists in the right place. Run it if it does.
if (os.path.exists("/usr/bin/rf-ppt-repair")):
os.system("rf-ppt-repair " + sys.argv[1])

else:
print("You do not have rf-ppt-repair installed.")