Commit bc935095 authored by nextime's avatar nextime

first commit

parents
[307]
user: admin
pass: password
ip: 172.18.100.107
#!/usr/bin/env python
import urllib2, sys, ConfigParser, os, urllib
from threading import Thread
import signal
#>>> p=a.urlencode({'ring1': 1})
#>>> f=a.urlopen('http://admin:12345678@phone2.nexlab.thc:9999/phone.htm', p)
def alarmHandler(*args):
raise "TimeOut"
class changeThread(Thread):
def __init__(self, cfg, exten, ring):
Thread.__init__(self)
self.cfg = cfg
self.exten = exten
self.ring = ring
def run(self):
ip = self.cfg.get(self.exten, 'ip')
user = self.cfg.get(self.exten, 'user')
pwd = self.cfg.get(self.exten, 'pass')
p = urllib.urlencode({'ring1': int(self.ring)})
try:
#print 'START', ip, self.exten
signal.alarm(1)
f = urllib.urlopen('http://'+user+':'+pwd+'@'+ip+':9999/phone.htm', p)
f.close()
#print 'OK', ip, self.exten
except "TimeOut":
pass
#print 'TimeOut', ip, self.exten
#signal.alarm(0)
class changeRing:
def __init__(self):
self.cfg = ConfigParser.ConfigParser()
self.cfg.read(os.path.join(os.path.dirname(__file__), 'allnet7690ring.conf'))
if int(sys.argv[2]) in range(8):
self.change(str(sys.argv[1]), str(sys.argv[2]))
def _change(self, exten, ring):
act = changeThread(self.cfg, exten, ring)
act.start()
def change(self, exten, ring):
if len(str(exten).strip().split(',')) > 1:
for ext in str(exten).strip().split(','):
if str(ext) in self.cfg.sections():
self._change(ext, ring)
else:
if str(exten) in self.cfg.sections():
self._change(exten, ring)
if __name__ == '__main__':
if len(sys.argv) > 2:
changeRing()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment