def is_internet_on_classroom(classroom): print 'asasas 1.1' network_type=classroom.network_device.network_type print 'asasas 1.2' firewall_rule=classroom.firewall_rule classroom_pcs=classroom.computer_set.all().order_by('identifier') #First Classroom computer pc1=None if classroom_pcs: pc1=classroom_pcs[0] if network_type=="Mikrotik": #try: mk =MikrotikRouter() mk.set_networkdevice(classroom.network_device) print 'asasas 1.3' #If we block the classroom only taking into account MAC addresses if classroom.mac_filter: if pc1: resposta = mk.list_firewall_rule(settings.FW_PREFIX+' '+pc1.mac.upper()) else: print 'asasas 1.4 '+firewall_rule.comment resposta = mk.list_firewall_rule(firewall_rule.comment,firewall_rule.src_address,str(firewall_rule.src_netmask)) print 'asasas 1.5' if resposta: return False else: return True #except Exception ,msg: # return False else: return True
def is_internet_partial_on_classroom(classroom): network_type=classroom.network_device.network_type firewall_rule=classroom.firewall_rule if network_type=="Mikrotik": mk =MikrotikRouter() mk.set_networkdevice(classroom.network_device) resposta = mk.list_firewall_rule("LLISTA-"+str(classroom.id)) if resposta: return resposta[0]['dst-address-list'] else: return None else: return None