#!/usr/bin/python
#author songnan
import tool
import string
import os
CTI_LINK_FILE = 'CTI_LINK.ini'
CCS_LINK_FILE = 'icdpub.ini'
def config_CCS_CTILINK():
oldCtiLinkIp = tool.read_val(CTI_LINK_FILE, 'CTI-Link1', ' ', 2)
oldCcsIp = tool.read_val(CCS_LINK_FILE, 'MainIP', ' ', 2)
print "**************************** System IP **********************************"
print "CCS IP="+oldCcsIp
print "CTI-LINK IP="+oldCtiLinkIp
print "*************************************************************************"
while [ 1 ]:
confim = raw_input("----Do you want to retain the current value?(Y/N)")
if confim == 'y':
break
elif confim == 'n':
break
else:
print "Error input"
if confim == 'n':
while [ 1 ]:
newCcsIp = raw_input("----Please input CCS IP:"+oldCcsIp)
newCtiLinkIp = raw_input("----Please input CTI-LINK IP:"+oldCtiLinkIp)
print "**************************** System IP **********************************"
print "CCS IP="+newCcsIp
print "CTI-LINK IP="+newCtiLinkIp
print "*************************************************************************"
confim = raw_input("----Are all the above IP addresses correct?( Y/N ) :")
if confim == 'y':
tool.replacedSingleString(CTI_LINK_FILE, 'CTI-Link1', oldCtiLinkIp,newCtiLinkIp)
tool.replacedSingleString(CCS_LINK_FILE, 'MainIP', oldCcsIp,newCcsIp)
break
elif confim == 'n':
continue
else:
print "Error input"
def config_Uap():
flag = 0
while [ 1 ]:
if flag == 1:
break
i = 1
uap = ['','','','','','','','','','','','','','','','','','','','','','','']
lines = open(CTI_LINK_FILE).readlines()
print "******************************** UAP ***********************************"
print "NO. Module UAP IP"
for s in lines:
if s.find('ModuleDesc') == 0:
strlist = s.split('=')
tmp1=strlist[0].strip().split('c')
tmp=string.atoi(tmp1[1].strip())
s = str(tmp * 2 - 1)
olduapIp = 'Mem'+s
print '<'+str(i)+'\t'+str(tmp)+'\t'+'\t'+tool.read_val(CTI_LINK_FILE,olduapIp,'=', 1)
uap[i-1]=tool.read_val(CTI_LINK_FILE,olduapIp,'=', 1)
i=i+1
print "*************************************************************************"
print "The above UAP IP have been configured!"
if i == 1:
number = 2
else:
while [ 1 ]:
input_val=raw_input("----Do you want to modify,add,remove UAP IP or retain current?(1:Modify 2:Add 3:Retain current 4:Remove)")
if input_val == '1':
number = 1
break
elif input_val == '2':
number = 2
break
elif input_val == '3':
number = 3
break
elif input_val == '4':
number = 4
break
else:
print 'Error input.Please input number 1, 2, 3 or 4!'
if number == 1:
print "1"
break
elif number == 2:
add_UapIp()
elif number == 3:
flag = 0
elif number ==4:
del_UapIp()
while [ 1 ]:
confirm=raw_input("----Continue or ReConfig?(1:Continue 2:ReConfig)")
if confirm == '1':
flag = 1
break
elif confirm == '2':
flag = 0
break
else:
print "Error input.Please input number 1 or 2 !"
def del_UapIp():
flag = 0
uap=['','','','','','','','','','','','','','','','','','','','','','','']
while [ 1 ]:
i=1
if flag == 1:
break
lines = open(CTI_LINK_FILE).readlines()
print "******************************** UAP ***********************************"
print "NO. Module UAP IP"
for s in lines:
if s.find('ModuleDesc') == 0:
strlist = s.split('=')
tmp1=strlist[0].strip().split('c')
tmp=string.atoi(tmp1[1].strip())
s = str(tmp * 2 - 1)
olduapIp = 'Mem'+s
print '<'+str(i)+'\t'+str(tmp)+'\t'+'\t'+tool.read_val(CTI_LINK_FILE,olduapIp,'=', 1)
uap[i-1]=tool.read_val(CTI_LINK_FILE,olduapIp,'=', 1)
i=i+1
print "*************************************************************************"
print "The above UAP IP have been configured!"
no=raw_input("----Please input the serial number of UAP IP which you want to remove:")
if no != '':
val=os.system("echo %s |grep ^[0-9]*$ >/dev/null" %no)
if val != 0:
print "The module number which you input is wrong!"
else:
no=string.atoi(no)
no=no-1
if uap[no] != '':
confirm = raw_input("----Are you sure remove the ip "+uap[no]+" ?(Y/N)")
if confirm == 'y':
os.system("line=`cat %s |grep -n '\<'%s'\>' |grep Mem |cut -d ':' -f1` \n two=`expr $line + 2` \n sed -i ${line},${two}d %s" %(CTI_LINK_FILE,uap[no],CTI_LINK_FILE))
break
elif confirm == 'n':
continue
else:
print "error input"
else:
print "error input"
def add_UapIp():
while [ 1 ]:
module_number_new=raw_input("----Please input a new module number of UAP:")
if module_number_new != "":
val=os.system("echo %s |grep ^[0-9]*$ >/dev/null" %module_number_new)
if val != 0:
print "The module number which you input is wrong!"
else:
check1=os.system("check=$((%s*2-1)) \n cat %s |grep Mem$check= >/dev/null" %(module_number_new,CTI_LINK_FILE))
if check1 != 0:
module_number_new=string.atoi(module_number_new)
if module_number_new >=1 and module_number_new <=253:
break
else:
print "The module number should be between 1 and 253 !"
else:
print "The module number has been exist!"
else:
print "Error input"
while [ 1 ]:
uap_ip_new=raw_input("----Please input a new ip of UAP:")
if uap_ip_new != "":
check2=os.system("cat %s |grep Mem |grep '\<'%s'\>' >/dev/null" %(CTI_LINK_FILE,uap_ip_new))
if check2 != 0:
break
else:
print "The UAP IP has been exist!"
else:
print "Error input"
tool.addUapIp(CTI_LINK_FILE, module_number_new, uap_ip_new)
config_CCS_CTILINK()
config_Uap()
CTI_LINK.ini
[CTI-Link]
CTI-Link1 = 10.71.106.184
CTI-Link2 =
ShakeHandWithVP = 1
WriteStatusLog = 1
DebugListenPort = 2556
[DirectChannel]
LocalIP =
RemoteIP =
HBPort = 10004
[UDP]
UdpPort = 65535
OldUdpPID0 = 102
OldUdpPID1 = 103
[CSTA]
PID_SWITCH_CSTA = 87
[Switch]
Type = MEM
MemPort = 5600
[IsAIP]
AIPFlag = 0
[Alert]
AlertFlag = 0
AppName = CTI-Link
ServiceName = CTI-Link
Level = 0
LightPos = 0
ServerIP = 0.0.0.0