- fp = file('/etc/inetd.conf', 'r')
- datas = fp.readlines()
- fp.close()
- except:
-# print "file open error, inetd.conf!"
- self.showMessage("Set port failed.", MessageBox.TYPE_ERROR)
- return
- try:
- newdatas=""
- s_port = ""
- if port == "8001":
- s_port = "8002"
- else:
- s_port = "8001"
- for line in datas:
- if line.find("transtreamproxy") != -1:
- p=line.replace('\t',' ').find(' ')
- line = port+line[p:]
- elif line.find("filestreamproxy") != -1:
- p=line.replace('\t',' ').find(' ')
- line = "8003"+line[p:]
- elif line.find("streamproxy") != -1:
- p=line.replace('\t',' ').find(' ')
- line = s_port+line[p:]
- newdatas+=line
-
- if newdatas.find("transtreamproxy") == -1:
- newdatas+=port+'\t'+'stream'+'\t'+'tcp'+'\t'+'nowait'+'\t'+'root'+'\t'+'/usr/bin/transtreamproxy'+'\t'+'transtreamproxy\n'
- if newdatas.find("filestreamproxy") == -1:
- newdatas+='8003\t'+'stream'+'\t'+'tcp'+'\t'+'nowait'+'\t'+'root'+'\t'+'/usr/bin/filestreamproxy'+'\t'+'filestreamproxy\n'
- fd = file("/etc/inetd.conf",'w')
- fd.write(newdatas)
- fd.close()
+ newConfigData = ""
+ oldConfigData = file('/etc/inetd.conf').read()
+ for L in oldConfigData.splitlines():
+ try:
+ if L[0] == '#':
+ newConfigData += L + '\n'
+ continue
+ except: continue
+ LL = L.split()
+ if LL[5] == '/usr/bin/streamproxy':
+ LL[0] = port2
+ elif LL[5] == '/usr/bin/transtreamproxy':
+ LL[0] = port
+ newConfigData += ''.join(str(X) + " " for X in LL) + '\n'
+
+ if newConfigData.find("transtreamproxy") == -1:
+ newConfigData += port + " stream tcp nowait root /usr/bin/transtreamproxy transtreamproxy\n"
+ file('/etc/inetd.conf', 'w').write(newConfigData)