def GET(self): # noqa i = web.input(bill='') if not i.bill: return dumps({ 'status': Status.ERROR }) bill = H.check_bill(i.bill) if not bill: return dumps({ 'status': Status.ERROR }) region = H.get_region_by_bill(bill) result = [] for key, value in brases[region].iteritems(): result.append(value['name'].upper()) if not result: return dumps({ 'status' : Status.EMPTY }) return dumps({ 'status' : Status.SUCCESS, 'data' : result })
def POST(self): # noqa i = web.input(bill='', ip='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) bill = H.check_bill(i.bill) if not bill: msg = 'not bill "{0}"'.format(i.bill) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) log.save_action(session.name, 'traffic', 'Просмотр трафика абонента {0}, ip: {1}'.format(bill, ip)) return sb.get_user_traffic(bill, ip)
def POST(self): # noqa i = web.input(inp='') if not i.inp: return dumps({ 'status' : Status.ERROR, 'db' : 'orange' }) log.save_action(session.name, 'ipaddr', 'Поиск в ORANGE {0}'.format(i.inp.encode('utf8'))) bill = H.check_bill(i.inp) ip = None if not bill: ip = H.check_ip(i.inp) if not ip: return dumps({ 'status' : Status.ERROR, 'db' : 'orange' }) res = ora.get_bill_id_for_ip(ip) if res['status'] != Status.SUCCESS: return dumps({ 'status' : Status.ERROR, 'db' : 'orange' }) bill = res['billid'] if not bill: return dumps({ 'status' : Status.EMPTY, 'db' : 'orange' }) if not H.is_region_allowed(bill, session.regions): return dumps({ 'status' : Status.NOAUTH, 'db' : 'orange' }) return ora.get_user_params(bill, ip)
def POST(self): # noqa i = web.input(inp='') if not i.inp: return dumps({ 'status' : Status.ERROR }) log.save_action(session.name, 'switch', 'Запрос клиентов на свитче {0}'.format(i.inp.encode('utf8'))) res = ora.get_clients_on_switch(i.inp) if res['status'] != Status.SUCCESS: return dumps(res) # составим список клиентов на свитче для запроса в сбмс orange_data = res['data'] bill_list = [] for bill in orange_data.values(): if bill[1] and H.check_bill(bill[1]): bill_list.append(bill[1]) # если есть хоть 1 абонент if bill_list: sbms_data = sb.get_users_params(bill_list) if not sbms_data: return dumps({ 'status' : Status.ERROR }) result = [] for port in orange_data.keys(): row = {} # если есть договор, достаем о нем инфу из сбмс port_info = orange_data[port] ip = port_info[0] billid = port_info[1] portid = port_info[2] row['port'] = port row['portid'] = portid if not billid: result.append(row) continue row['bill'] = billid row['ip'] = ip addr = 'Nowhere' fio = 'John Doe' if billid not in sbms_data.keys(): addr = '' fio = '' elif sbms_data[billid] == 'onyma': addr = 'Onyma' fio = 'Onyma' else: fio = sbms_data[billid][1] addr = sbms_data[billid][2] bill_status = sbms_data[billid][0] row['bill-status'] = bill_status if bill_status == 'danger': row['blocked'] = sbms_data[billid][4] row['release'] = sbms_data[billid][3] row['addr'] = addr row['fio'] = fio result.append(row) # port bill ip addr blocked fio release portid return dumps({ 'status' : Status.SUCCESS, 'data' : result, 'swip' : res['swip'] })
def POST(self): # noqa i = web.input(billid='', portid='', swip='', swport='') if not i.billid or not i.portid or not i.swip or not i.swport: print('not billid or portid or swip or swport') return dumps({ 'status' : Status.ERROR }) billid = H.check_bill(i.billid) if not billid: print('wrong billid {0}'.format(i.billid)) return dumps({ 'status' : Status.ERROR }) try: portid = int(i.portid) except ValueError: msg = 'portid not int, raw portid: "{0}"'.format(i.portid) print(msg) return dumps({ 'status' : Status.ERROR }) swip = H.check_ip(i.swip) if not swip: msg = 'not switch ip "{0}"'.format(i.swip) print(msg) return dumps({ 'status' : Status.ERROR }) try: swport = int(i.swport) except ValueError: msg = 'swport not int, raw port: "{0}"'.format(i.swport) print(msg) return dumps({ 'status' : Status.ERROR }) log.save_action( session.name, 'reserve', 'Попытка привязать абонента {0} на {1} порт {2}'.format(billid, swip, swport)) res = sb.get_one_subs_id(billid) if res['status'] != Status.SUCCESS: return dumps(res) # есть привязка, освобождаем в оранже if res['portid']: res_in = sb.release_port(res['subsid']) msg = '' if res_in['status'] != Status.SUCCESS: msg = 'Отвязывание абонента {0} с portid {1} прошло с ошибкой!'.format( billid, res['portid']) log.save_action(session.name, 'reserve', msg) return dumps(res_in) msg = 'Успешно отвязал абонента {0} с portid {1}'.format(billid, res['portid']) log.save_action(session.name, 'reserve', msg) # теперь привяжем res = sb.reserve_port(res['subsid'], portid) msg = 'Привязал абонента {0} на {1} порт {2}'.format(billid, swip, swport) if res['status'] != Status.SUCCESS: msg = 'Привязка абонента {0} на {1} порт {2} прошла с ошибкой!'.format(billid, swip, swport) log.save_action(session.name, 'reserve', msg) return dumps(res)
def POST(self): # noqa i = web.input(billid='', portid='', days='', swip='', swport='') if not i.billid or not i.portid or not i.days or not i.swip or not i.swport: print('incorrect parameters {0}'.format(i)) return dumps({ 'status' : Status.ERROR }) billid = H.check_bill(i.billid) if not billid: return dumps({ 'status' : Status.ERROR }) try: portid = int(i.portid) except ValueError: msg = 'port not int, port: "{0}"'.format(i.portid) print(msg) return dumps({ 'status' : Status.ERROR }) try: days = int(i.days) swport = int(i.swport) except ValueError: msg = 'not valid num of days or port: "{0}" "{1}"'.format(i.days, i.swport) print(msg) return dumps({ 'status' : Status.ERROR }) swip = H.check_ip(i.swip) if not swip: print('not switch ip {0}'.format(i.swip)) return dumps({ 'status' : Status.ERROR }) perm = 'relhigh' if days >= 180: perm = 'rellow' if not session.get(perm, False): return dumps({ 'status' : Status.NOAUTH }) log.save_action( session.name, 'release', 'Попытка отвязать абонента {0} с {1} порт {2} portid {3}'.format( billid, swip, swport, portid)) res = sb.get_subs_id_by_portid(billid, portid) if res['status'] != Status.SUCCESS: return dumps(res) perm = 'relhigh' if res['priv'] == 'low': perm = 'rellow' if not session.get(perm, False): return dumps({ 'status' : Status.NOAUTH }) res = sb.release_port(res['subsid']) msg = 'Успешно отвязал абонента {0} c {1} порт {2} portid {3}'.format( billid, swip, swport, portid) if res['status'] != Status.SUCCESS: msg = 'Отвязывание абонента {0} с {1} порт {2} portid {3} прошло с ошибкой!'.format( billid, swip, swport, portid) log.save_action(session.name, 'release', msg) return dumps(res)