Ejemplo n.º 1
0
    def __init__(self, portnum=None, *args, **kwargs):
        Notifications.Notifier.__init__(self, *args, **kwargs)
        self._portnum = portnum
        self._swversion = Version.getRevision()
        self._fwversion = 0
        self._setState(STATE_INITIALIZING)
        self._captureHandler = CaptureFiles.CaptureFileHandler()
        self._exit = False
        self._connectionAccessAddress = None
        self._packetListLock = threading.RLock()
        with self._packetListLock:
            self._packets = []

        self._packetReader = Packet.PacketReader(self._portnum,
                                                 callbacks=[
                                                     ("*",
                                                      self.passOnNotification)
                                                 ])
        self._devices = Devices.DeviceList(
            callbacks=[("*", self.passOnNotification)])

        self._missedPackets = 0
        self._packetsInLastConnection = None
        self._connectEventPacketCounterValue = None
        self._inConnection = False
        self._currentConnectRequest = None

        self._nProcessedPackets = 0

        self._switchingBaudRate = False

        self._attemptedBaudRates = []

        self._boardId = self._makeBoardId()
Ejemplo n.º 2
0
    def _processBLEPacket(self, packet):
        packet.boardId = self._boardId
        self._appendPacket(packet)

        self.notify("NEW_BLE_PACKET", {"packet": packet})
        self._captureHandler.writePacket(packet)

        self._nProcessedPackets += 1
        if packet.OK:
            try:
                if packet.blePacket.accessAddress == ADV_ACCESS_ADDRESS:

                    if self.state == STATE_FOLLOWING and packet.blePacket.advType == 5:
                        self._connectionAccessAddress = packet.blePacket.accessAddress

                    if self.state == STATE_SCANNING:
                        if (packet.blePacket.advType == 0
                                or packet.blePacket.advType == 1
                                or packet.blePacket.advType == 2
                                or packet.blePacket.advType == 4
                                or packet.blePacket.advType == 6) and (
                                    packet.blePacket.advAddress != None) and (
                                        packet.crcOK and not packet.direction):

                            newDevice = Devices.Device(
                                address=packet.blePacket.advAddress,
                                name=packet.blePacket.name,
                                RSSI=packet.RSSI,
                                txAdd=packet.txAdd)
                            self._devices.appendOrUpdate(newDevice)

            except Exception as e:
                logging.exception("packet processing error")
                self.notify("PACKET_PROCESSING_ERROR", {"errorString": str(e)})
Ejemplo n.º 3
0
    def __init__ (self, parent = None):  
        super(SpectrumAnalyzer, self).__init__(parent)
        self.resize(700, 700)      
        self.setWindowTitle("Spectrum Analyzer")  
        self.UIsetup()
        self.device =  Devices.sundCardDevice(FORMAT, CHANNELS, samlingRate, CHUNK)

        self.ON_OFF = False   # False means OFF
Ejemplo n.º 4
0
 def operation(self, ip, community, version):
     temp_walk = Devices.Devices(community, version)
     self.result_desc = temp_walk.walkthrongh(ip, self.IFDESCR)
     self.result_Type = temp_walk.walkthrongh(ip, self.IFTYPE)
     self.result_Mtu = temp_walk.walkthrongh(ip, self.IFMTU)
     self.result_Speed = temp_walk.walkthrongh(ip, self.IFSPEED)
     self.result_Admin = temp_walk.walkthrongh(ip, self.IFADMINSTATUS)
     self.result_Opera = temp_walk.walkthrongh(ip, self.IFOPERSTATUS)
     self.removeDWDM()
Ejemplo n.º 5
0
	def fillDevicesCombo(self):
		self.yiswiz.cmbRoot.clear()
		self.yiswiz.cmbHome.clear()
		self.yiswiz.cmbBoot.clear()
		self.yiswiz.cmbSwap.clear()
		
		self.yiswiz.cmbRoot.insertItem("Devices")
		self.yiswiz.cmbHome.insertItem("Devices")
		self.yiswiz.cmbBoot.insertItem("Devices")
		self.yiswiz.cmbSwap.insertItem("Devices")
		
		disk_info=Devices()
		self.disk_types=disk_info.invokeDevices("DISK-PARTITION-TYPES")
		self.disk_type_keys=self.disk_types.keys()
		
		#fill cmbRoot and leditSwap
		for keys in self.disk_type_keys:
			value=self.disk_types[keys]
			pos=string.find(value,'swap',6)
			swap_flag=0
			if pos==-1:
				self.yiswiz.cmbRoot.insertItem("/dev/"+keys+'->'+value)
			else:	
				self.yiswiz.cmbSwap.insertItem("/dev/"+keys)
				swap_flag=1
		
		if swap_flag==0:
			self.yiswiz.cmbSwap.changeItem("Devices",0)
			self.yiswiz.cmbSwap.setEnabled(0)
		
		#fill cmbHome and cmbBoot
		if len(self.disk_type_keys) > 2:
			for keys in self.disk_type_keys:
				value=self.disk_types[keys]
				pos=string.find(value,'swap',6)
				if pos==-1:
					self.yiswiz.cmbHome.insertItem("/dev/"+keys+'->'+value)
					self.yiswiz.cmbBoot.insertItem("/dev/"+keys+'->'+value)
		else:
			self.yiswiz.cmbHome.changeItem("Devices",0)
			self.yiswiz.cmbHome.setEnabled(0)
			self.yiswiz.cmbBoot.changeItem("Devices",0)
			self.yiswiz.cmbBoot.setEnabled(0)
    def save_device(self, request, access_token, refresh_token):
        """
        Create a new device instance.
        Args:
            request.
            access_token.
            refresh_token.

        Returns:
            new device instance.
        """
        device = Devices.objects.filter(device_token=request.headers[DEVICE_TOKEN_HEADER]).first()
        if device is not None:
            to_delete = AccessToken.objects.get(pk=device.access_token.id)
            device.access_token = access_token
            device.refresh_token = refresh_token
            device.user = request.user
            device.language = request.headers['HTTP_ACCEPT_LANGUAGE']
            device.save()
            to_delete.delete()
        else:
            application_arn = self.get_application_arn(request)
            device = Devices(device_token=request.headers[DEVICE_TOKEN_HEADER],
                             user=request.user,
                             access_token=access_token,
                             refresh_token=refresh_token,
                             language=request.headers['HTTP_ACCEPT_LANGUAGE'])

            operational_system = device.ANDROID \
                if application_arn == settings.ANDROID_ARN \
                else device.iOS

            device.operational_system = operational_system
            awsclient = boto3.client('sns')

            response = awsclient.create_platform_endpoint(
                PlatformApplicationArn=application_arn,
                Token=device.device_token,
            )

            device.arn = response['EndpointArn']
            return device.save()
Ejemplo n.º 7
0
    def __init__(self):
        super(MainWindow, self).__init__()
        uic.loadUi('GUI/mainwindow.ui', self)

        self.openTabs = {}  # Dict for Post-Office
        self.postman = Postman()
        self.postman.Post.connect(self.postOffice)

        ### Parse XML ###
        root = parseXML(directory="xml")

        ### Create Devices ###
        liste = []
        for item in root:
            _class = Devices.getDevice(item[0].value('Type'))
            liste.append(_class(item))
        ###

        self.wToolbox.setVisible(False)
        self.wQueue.setVisible(False)

        ### Prepare Device View ###
        self.deviceModel = DeviceModel(liste)
        self.listView.setModel(self.deviceModel)
        self.listView.doubleClicked.connect(self.tabAdd)
        self.uiTabs.tabCloseRequested.connect(self.tabClose)
        ###

        ### Prepare Queue ###
        self.qModel = QueueModel()
        self.treeView.setModel(self.qModel)
        self.treeView.setItemDelegate(QueueDelegate())
        self.queueThread = QueueThread(self.postman)
        self.thread = QtCore.QThread()
        self.queueThread.moveToThread(self.thread)
        self.thread.started.connect(self.queueThread.process)
        self.queueThread.finished.connect(self.thread.quit)
        self.queueThread.newMaximum.connect(self.queueProgress.setMaximum)
        self.queueThread.processed.connect(self.queueProgress.setValue)
        ###

        ### Prepare Logging Monitor ###
        self.monitor = Monitor(self.postman, self)
        self.actionLogging_Monitor.triggered.connect(self.monitor.show)
        ###

        self.bExecute.clicked.connect(self.startExecute)
        self.bQueueRemoveItem.clicked.connect(self.removeQueueItem)
        self.bClearAll.clicked.connect(self.qModel.clearAll)

        self.toolModel = ToolModel(Tools.TOOL_LIST)
        self.uiToolList.setModel(self.toolModel)

        self.show()
Ejemplo n.º 8
0
  def __init__(self):
    super(MainWindow, self).__init__()
    uic.loadUi('GUI/mainwindow.ui', self)

    self.openTabs = {} # Dict for Post-Office
    self.postman = Postman()
    self.postman.Post.connect(self.postOffice)

    ### Parse XML ###
    root = parseXML(directory="xml")

    ### Create Devices ###
    liste = []
    for item in root:
      _class = Devices.getDevice(item[0].value('Type'))
      liste.append(_class(item))
    ###

    self.wToolbox.setVisible(False)
    self.wQueue.setVisible(False)

    ### Prepare Device View ###
    self.deviceModel = DeviceModel(liste)
    self.listView.setModel(self.deviceModel)
    self.listView.doubleClicked.connect(self.tabAdd)
    self.uiTabs.tabCloseRequested.connect(self.tabClose)
    ###

    ### Prepare Queue ###
    self.qModel = QueueModel()
    self.treeView.setModel(self.qModel)
    self.treeView.setItemDelegate(QueueDelegate())
    self.queueThread = QueueThread(self.postman)
    self.thread = QtCore.QThread()
    self.queueThread.moveToThread(self.thread)
    self.thread.started.connect(self.queueThread.process)
    self.queueThread.finished.connect(self.thread.quit)
    self.queueThread.newMaximum.connect(self.queueProgress.setMaximum)
    self.queueThread.processed.connect(self.queueProgress.setValue)
    ###

    ### Prepare Logging Monitor ###
    self.monitor = Monitor(self.postman, self)
    self.actionLogging_Monitor.triggered.connect(self.monitor.show)
    ###

    self.bExecute.clicked.connect(self.startExecute)
    self.bQueueRemoveItem.clicked.connect(self.removeQueueItem)
    self.bClearAll.clicked.connect(self.qModel.clearAll)

    self.toolModel = ToolModel(Tools.TOOL_LIST)
    self.uiToolList.setModel(self.toolModel)

    self.show()
Ejemplo n.º 9
0
 def __init__(self, I2A_address, I2PE_address):
     self.node = zmqNode('User')
     self.node.target = self
     self.node.logging = True
     self.apparatus = APE_Interfaces.ApparatusInterface(self.node)
     self.apparatus.defaultBlocking = False
     self.executor = APE_Interfaces.ExecutorInterface(self.node)
     self.User = Devices.User_Consol('User')
     self.connect2A(I2A_address)
     self.connect2PE(I2PE_address)
     self.node.start_listening()
Ejemplo n.º 10
0
    def config_ip_addr(*args):
        """args[0] is Router name ex., R1
           args[1] is Router link ex., Link_R1_R2
           args[2] has options 'configure'/ """

        dev = Devices.Devices()
        sys.stdout.write("Configuring IP address for %s" % args[0])
        status  = dev.set_IP(args[0],args[1],args[2])
        if status is False:
            sys.stdout.write("Configuration of IP Address for %s Failed" % args[0])
        else:
            sys.stdout.write("Configured  IP Address for %s" % args[0])
Ejemplo n.º 11
0
    def route(self, Device, AS_id, Interface):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=90)
            #print 'flag =%d' % flag
            if flag == 0 or flag == 2:
                Dev.Login(Device, child)
                configs = """
				configure terminal
				router bgp %d
				neighbor %s next-hop-self
				end
				""" % (AS_id, Interface)
                commands = configs.split('\n')
                execute.execute(child, commands)
                #time.sleep(5)
                child.sendcontrol('m')
            #	print "BGP synchronization enabled in %s " % (Device)

            if flag == 1 or flag == 3:
                configs = """
				configure terminal
				router bgp %d
				neighbor %s next-hop-self
				end
				""" % (AS_id, Interface)
                commands = configs.split('\n')
                execute.execute(child, commands)
                #time.sleep(5)
                child.sendcontrol('m')
            #	print "BGP synchronization enabled in %s " % (Device)

            #else:
            #	print 'Expected prompt not found'

            return True

        else:
            return False
Ejemplo n.º 12
0
def update(message):
    """Update the local directory with information about this device"""
    now      = time.time()
    header   = message["header"]
    sensorId = header["sensorid"]

    if not (sensorId in directory):
        # new device discovered
        desc = Devices.getDescription(header["mfrid"], header["productid"])
        print("ADD device:%s %s" % (hex(sensorId), desc))
        directory[sensorId] = {"header": message["header"]}
        #trace(allkeys(directory))

    directory[sensorId]["time"] = now
Ejemplo n.º 13
0
def readDevices():
    res = os.popen('wmic /output:devices.csv diskdrive list brief /format:csv')
    res.close()
    reader = csv.reader(open('devices.csv', encoding='UTF-16LE'))
    startIndex = 0
    devices = list()
    for tmp in reader:
        startIndex += 1
        if startIndex > 2:
            size = int(int(tmp[5]) / 1024 / 1024 / 1024)
            device = Devices(tmp[1], tmp[2], tmp[3], str(size) + 'G')
            devices.append(device)

    return devices
Ejemplo n.º 14
0
    def redistribution(self, Device, AS_id, Process_id=None):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=90)
            if flag == 0 or flag == 2:
                Dev.Login(Device, child)
                configs = """
				configure terminal
				router bgp %d
				redistribute ospf %d
				exit
				router ospf %d
				redistribute bgp %d subnets
				end
				""" % (AS_id, Process_id, Process_id, AS_id)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            if flag == 1 or flag == 3:
                configs = """
				configure terminal
				router bgp %d
				redistribute ospf %d
				exit
				router ospf %d
				redistribute bgp %d subnets
				end
				""" % (AS_id, Process_id, Process_id, AS_id)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            return True

        else:
            return False
Ejemplo n.º 15
0
def update(message):
    """Update the local directory with information about this device"""
    now = time.time()
    header = message["header"]
    sensorId = header["sensorid"]

    if not (sensorId in directory):
        # new device discovered
        desc = Devices.getDescription(header["mfrid"], header["productid"])
        print("ADD device:%s %s" % (hex(sensorId), desc))
        directory[sensorId] = {"header": message["header"]}
        #trace(allkeys(directory))

    directory[sensorId]["time"] = now
Ejemplo n.º 16
0
 def CreateDevices(self):
     self.devices.append(Devices.Buzzer(self.client, 15, 7))
     self.devices.append(Devices.Ventilation(self.client, 5))
     self.devices.append(Devices.Power(self.client, 20))
     self.devices.append(Devices.NoiseSensor(self.client, 12, emulation=True))
     for i in range(2):
         self.devices.append(Devices.Thermometer(self.client, i, 15, emulation=True))
     for i in range(4):
         self.devices.append(Devices.MovementSensor(self.client, i, 10, emulation=True))
Ejemplo n.º 17
0
    def onDeviceAdded(self, device):
        self._debug('Device added %s %s' % (device.id(), device.name()))

        if device not in (x.device for x in self.devices
                          if hasattr(x, 'device')):
            haDevs = devs.createDevices(device, self.hub, self._buildTopic,
                                        self.config('use_via'))
            self._debug('New discovery %s' %
                        json.dumps(self._debugDevice(device, haDevs)))
            for haDev in haDevs:
                self.devices.append(haDev)
                self.publishDevice(haDev)
                self.publishState(haDev)
        else:
            self._debug('Device already exists, ignoring')
Ejemplo n.º 18
0
def checking_operabilty(Device, command):
    device_data = getdata.get_data()
    hostname = device_data['Device_Details'][Device]['Hostname']
    Dev = Devices.Devices()
    child = Dev.connect(Device)
    if child:

      clear_buffer.flushBuffer(1, child)
      child.sendcontrol('m')
      child.sendcontrol('m')
      child.sendcontrol('m')
      flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#',\
             pexpect.EOF, pexpect.TIMEOUT], timeout=90)
      if flag in (0, 2):
        Dev.Login(Device, child)
        configs = """
        %s
        """ % (command)
        commands = configs.split('\n')
        execute.execute(child, commands)
        resp = child.before.decode('utf-8')
        child.sendcontrol('m')
        child.sendcontrol('m')
        regex = r'up'
        if re.search(regex, resp):
          return True
        else:
          return False

      if flag in (1, 3):
        configs = """
        %s
        """ % (command)
        commands = configs.split('\n')
        execute.execute(child, commands)
        resp = child.before.decode('utf-8')
        child.sendcontrol('m')
        child.sendcontrol('m')
        regex = r'up'
        if re.search(regex, resp):
          return True
        else:
          return False

      return True

    else:
      return False
Ejemplo n.º 19
0
    def Configure_ebgpvrf(self, Device, AS_id, VRF_Name, Interface,
                          neighbor_AS_id, Action):
        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if child:
            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                     pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (1, 3):
                Dev.Login(Device, child)
                if Action == 'enable':
                    configs = """
                        configure terminal
                        router bgp %d
                        address-family ipv4 vrf %s
                        neighbor %s remote-as %s
                        neighbor %s activate     
                        exit-address-family
                        end
                        """ % (AS_id, VRF_Name, Interface, neighbor_AS_id,
                               Interface)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    time.sleep(6)
                    child.sendcontrol('m')
                    child.sendline('exit')
                    child.sendcontrol('m')

                else:
                    unconfig = """
                    configure terminal
                    no router bgp %s
                    end
                    """ % (AS_id)
                    commands = unconfig.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

                return True

        else:
            return False
Ejemplo n.º 20
0
    def discover(self):
        self.discovered_flag = False
        self._debug('Discovering devices ...')

        self.devices = self.staticDevices + []
        devMgr = DeviceManager(self.context)
        for device in devMgr.retrieveDevices():
            haDevs = devs.createDevices(device, self.hub, self._buildTopic,
                                        self.config('use_via'))
            self._debug('Discovered %s' %
                        json.dumps(self._debugDevice(device, haDevs)))
            for haDev in haDevs:
                self.devices.append(haDev)

        self.discovered_flag = True
        self._debug('Discovered %s devices' % len(self.devices))
        Application().queue(self.cleanupDevices)
Ejemplo n.º 21
0
def checking_operabilty(Device, command):
    device_data = getdata.get_data()
    hostname = device_data['Device_Details'][Device]['Hostname']
    Dev = Devices.Devices()
    child = Dev.connect(Device)
    if (child):

        clear_buffer.flushBuffer(10, child)
        child.sendcontrol('m')
        child.sendcontrol('m')
        child.sendcontrol('m')
        flag = child.expect([
            hostname + '>', hostname + '#', 'Router\>', 'Router\#',
            pexpect.EOF, pexpect.TIMEOUT
        ],
                            timeout=90)
        #print 'flag =%d' % flag
        if flag == 0 or flag == 2:
            Dev.Login(Device, child)
            configs = """
				%s
				""" % (command)
            commands = configs.split('\n')
            execute.execute(child, commands)
            #time.sleep(15)
            child.sendcontrol('m')
        #	print "BGP synchronization enabled in %s " % (Device)

        if flag == 1 or flag == 3:
            configs = """
				%s
				""" % (command)
            commands = configs.split('\n')
            execute.execute(child, commands)
            #time.sleep(15)
            child.sendcontrol('m')
        #	print "BGP synchronization enabled in %s " % (Device)

        #else:
        #	print 'Expected prompt not found'

        return True

    else:
        return False
Ejemplo n.º 22
0
    def route(self, Device, AS_id, Interface):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if (child):

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([
                hostname + '>', hostname + '#', 'Router\>', 'Router\#',
                pexpect.EOF, pexpect.TIMEOUT
            ],
                                timeout=90)
            if flag == 0 or flag == 2:
                Dev.Login(Device, child)
                configs = """
				configure terminal
				router bgp %d
				neighbor %s next-hop-self
				end
				""" % (AS_id, Interface)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            if flag == 1 or flag == 3:
                configs = """
				configure terminal
				router bgp %d
				neighbor %s next-hop-self
				end
				""" % (AS_id, Interface)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            return True

        else:
            return False
Ejemplo n.º 23
0
    def enable_syn(self, Device, AS_id):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if child:

            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                    pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (0, 2):
                Dev.Login(Device, child)
                configs = """
                configure terminal
                router bgp %d
                synchronization
                end
                """ % (AS_id)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            if flag in (1, 3):
                configs = """
                configure terminal
                router bgp %d
                synchronization
                end
                """ % (AS_id)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            return True

        else:
            return False
Ejemplo n.º 24
0
    def advertising_loopback(self, Device, AS_id, Interface, mask):
        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        if child:

            clear_buffer.flushBuffer(10, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                   pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (0, 2):
                Dev.Login(Device, child)
                configs = """
                configure terminal
                router bgp %d
                network %s mask %s
                end
                """ % (AS_id, Interface, mask)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            if flag in (1, 3):
                configs = """
                configure terminal
                router bgp %d
                network %s mask %s
                end
                """ % (AS_id, Interface, mask)
                commands = configs.split('\n')
                execute.execute(child, commands)
                child.sendcontrol('m')

            return True

        else:
            return False
Ejemplo n.º 25
0
def singleOutput():
    print '''
        <table class="table is-bordered is-narrow is-fullwidth">
          <tr>
            <th>OID</th>
            <th>Description</th>
          </tr>
        '''
    # --------------------------------------------------------------
    user = Devices.Devices(community, 2)
    user.main(ipList, community, 2, mib)

    for item in user.result:
        print '<tr class="is-selected"><td><strong>' + mib.upper(
        ) + '</strong></td><td></td></tr>'
        for x in range(len(item)):
            if item[x].value != '':
                if (item[x].snmp_type).upper() == 'TICKS':
                    t_item = tools.humanize(int(item[x].value))
                else:
                    t_item = item[x].value
                print '<tr><td>' + item[
                    x].oid + '</td><td>' + t_item + '</td></tr>'
Ejemplo n.º 26
0
 def createDevice(self, devName, devType, exec_address, rel_address):
     # Handle purely local creation of a device
     if self.node is None:
         self.devicelist[devName] = {}
         if devType != '':
             try:
                 device = getattr(Devices, devType)(devName)
             except AttributeError:
                 return False
         else:
             device = Devices.Device(devName)
         self.devicelist[devName]['Address'] = device
         self.devicelist[devName]['AddressType'] = 'pointer'
         if devType != '':
             self.devicelist[devName]['Address'].executor = self
         return True
     # Handle local creation at remote request
     elif self.node.name == rel_address:
         try:
             device = getattr(Devices, devType)(devName)
         except AttributeError:
             return False
         self.devicelist[devName] = {}
         self.devicelist[devName]['Address'] = device
         self.devicelist[devName]['AddressType'] = 'pointer'
         self.devicelist[devName]['Address'].executor = self
         return True
     # Handle remote creation of a device
     else:
         self.devicelist[devName] = {}
         self.devicelist[devName]['Address'] = rel_address
         self.devicelist[devName]['AddressType'] = 'zmqNode'
         return self._send_message(
             subject='target.executor.createDevice',
             args=[devName, devType, rel_address, rel_address],
             target=rel_address,
         )
Ejemplo n.º 27
0
def checking_operabilty(Device, command):
    device_data = getdata.get_data()
    hostname = device_data['Device_Details'][Device]['Hostname']
    Dev = Devices.Devices()
    child = Dev.connect(Device)
    if (child):

        clear_buffer.flushBuffer(10, child)
        child.sendcontrol('m')
        child.sendcontrol('m')
        child.sendcontrol('m')
        flag = child.expect([
            hostname + '>', hostname + '#', 'Router\>', 'Router\#',
            pexpect.EOF, pexpect.TIMEOUT
        ],
                            timeout=90)
        if flag == 0 or flag == 2:
            Dev.Login(Device, child)
            configs = """
				%s
				""" % (command)
            commands = configs.split('\n')
            execute.execute(child, commands)
            child.sendcontrol('m')

        if flag == 1 or flag == 3:
            configs = """
				%s
				""" % (command)
            commands = configs.split('\n')
            execute.execute(child, commands)
            child.sendcontrol('m')

        return True

    else:
        return False
Ejemplo n.º 28
0
    def __init__(self):
        Application().registerShutdown(self.onShutdown)
        self.live = TelldusLive(self.context)  # pylint: disable=too-many-function-args

        self.discovered_flag = False

        self.mqtt_connected_flag = False
        self.client = mqtt.Client()
        self.client.on_disconnect = self.onMqttDisconnect
        self.client.on_connect = self.onMqttConnect
        self.client.on_message = self.onMqttMessage

        username = self.config('username')
        password = self.config('password')
        # if username setup mqtt login
        if username != '':
            self.client.username_pw_set(username, password)

        useConfigUrl = self.config('useConfigUrl')
        configUrl = 'https://live.telldus.se' if self.config(
            'configUrl') == 'live' else ('http://%s' % getIpAddr())

        self.hub = devs.HaHub(self.config('device_name'), self._buildTopic,
                              configUrl if useConfigUrl else None)
        self._debug('Hub: %s' % json.dumps(self._getDeviceConfig(self.hub)))

        self.staticDevices = [
            self.hub,
            devs.HaLiveConnection(self.hub, self.live, self._buildTopic),
            devs.HaIpAddr(self.hub, self._buildTopic),
            devs.HaCpu(self.hub, self._buildTopic),
            devs.HaRamFree(self.hub, self._buildTopic),
            devs.HaNetIORecv(self.hub, self._buildTopic),
            devs.HaNetIOSent(self.hub, self._buildTopic)
        ]
        self.devices = self.staticDevices + []
        Application().queue(self.discoverAndConnect)
        Application().registerScheduledTask(self._updateTimedSensors,
                                            seconds=30)
Ejemplo n.º 29
0
    def Configure_mpls(self, Device, Links, mpls_label_proto, Action):
        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if child:
            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                     pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (1, 3):
                Dev.Login(Device, child)
                if Action == 'enable':
                    if isinstance(Links, list):
                        for Lnk in Links:
                            interface = device_data['Link_Details'][Lnk][
                                Device]
                            configs = """
                                          configure terminal
                                          ip cef
                                          mpls label protocol %s
                                          mpls ldp router-id Loopback0 force
                                          interface %s
                                          mpls ip
                                          mpls label protocol %s
                                          exit
                                          exit
                                """ % (mpls_label_proto, interface,
                                       mpls_label_proto)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
                        child.sendline('exit')
                        child.sendcontrol('m')

                else:
                    if isinstance(Links, list):
                        for Lnk in Links:
                            interface = device_data['Link_Details'][Lnk][
                                Device]
                            unconfig = """
                           configure terminal
                           no mpls label protocol %s
                           no mpls ldp router-id Loopback0 force
                           interface %s
                           no mpls ip
                           no mpls label protocol %s
                           exit
                           exit
                           """ % (mpls_label_proto, interface,
                                  mpls_label_proto)
                            commands = unconfig.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')

                return True

        else:
            return False
Ejemplo n.º 30
0
import Log

sys.path.append('/home/centos/www/Classes/Instagram')
import LoginInsta
import FollowInsta

sys.path.append('/home/centos/www/Classes/Dizu')
import LoginDizu
import ConectarDizu

sys.path.append('/home/centos/www/Bibliotecas/')

import Config

#Generate random device to change browser viewport and bypass recaptcha
device = Devices.Device('', True)
chrome = Driver.Chrome()
chrome.set_viewport_size(device.width,device.height)

tempPath   = Config.getTempPath()
fileName   = "log"
fields     = ["ID","Account","Date","Time","Event","Stage","Value","Content","png","html","js","ViewPort","User-Agent"]
log        = Log.LogCSV(tempPath, fileName, fields)
log.device = device.name

try:
    ok = chrome.getRetries('https://www.instagram.com', 3, 10)

    if ok == True:
        xpathUser  = '******'
        xpathPass  = '******'
Ejemplo n.º 31
0
	def fillDevicesList(self):
		disk_info=Devices()
		disk_devices=disk_info.invokeDevices("DISK-NAMES")
		for diskname in disk_devices:
			self.yiswiz.cmbDevices.insertItem(diskname)
Ejemplo n.º 32
0
    def Configure_EBGP(self, Device, AS_id, Interface, neighbor_AS_id, Action,
                       NW_id, Mask):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        port = device_data['Device_Details'][Device]['port']

        if port != "zebra":
            if child:
                clear_buffer.flushBuffer(1, child)
                child.sendcontrol('m')
                child.sendcontrol('m')
                child.sendcontrol('m')
                flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                               pexpect.EOF, pexpect.TIMEOUT], timeout=90)
                if flag in (0, 2):
                    Dev.Login(Device, child)
                    if Action == 'enable':
                        if isinstance(Interface, list):
                            for interface in Interface:
                                configs = """
                                    configure terminal
                                    router bgp %d
                                    neighbor %s remote-as %d
                                    network %s mask %s
                                    exit
                                    exit
                                    """ % (AS_id, interface, neighbor_AS_id,
                                           NW_id, Mask)
                                commands = configs.split('\n')
                                execute.execute(child, commands)
                                time.sleep(6)
                                child.sendcontrol('m')
                            child.sendline('exit')
                            child.sendcontrol('m')

                        else:
                            interface = Interface
                            configs = """
                            configure terminal
                            router bgp %d
                            neighbor %s remote-as %d
                            network %s mask %s
                            exit
                            exit
                            """ % (AS_id, interface, neighbor_AS_id, NW_id,
                                   Mask)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            child.sendcontrol('m')

                    else:
                        unconfig = """
                        configure terminal
                        no router bgp %d
                        exit
                        exit
                        """ % (AS_id)
                        commands = unconfig.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                if flag in (1, 3):
                    if Action == 'enable':
                        if isinstance(Interface, list):
                            for interface in Interface:

                                configs = """
                                    configure terminal
                                    router bgp %d
                                    neighbor %s remote-as %d
                                    network %s mask %s
                                    exit
                                    exit
                                    """ % (AS_id, interface, neighbor_AS_id,
                                           NW_id, Mask)
                                commands = configs.split('\n')
                                execute.execute(child, commands)
                                child.sendcontrol('m')
                            child.sendline('exit')
                            child.sendcontrol('m')

                        else:
                            interface = Interface
                            configs = """
                            configure terminal
                            router bgp %d
                            neighbor %s remote-as %d
                            network %s mask %s
                            exit
                            exit
                            """ % (AS_id, interface, neighbor_AS_id, NW_id,
                                   Mask)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            child.sendcontrol('m')

                    else:
                        unconfig = """
                        configure terminal
                        no router bgp %d
                        exit
                        exit
                        """ % (AS_id)
                        commands = unconfig.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                    return True
        elif port == 'zebra':
            port = "bgpd"
            device_data = getdata.get_data()
            IP_add = device_data['Device_Details'][Device]['ip_add']
            child = pexpect.spawn('telnet ' + IP_add + ' ' + port)
            hostname = device_data['Device_Details'][Device]['Hostname']
            clear_buffer.flushBuffer(1, child)

            child.sendcontrol('m')
            flag = (child.expect(['bgpd*', 'Password*', \
                    pexpect.EOF, pexpect.TIMEOUT], timeout=100))
            if flag == 1:
                child.send('zebra')
                child.sendcontrol('m')
                flag = child.expect(['bgpd*>', pexpect.EOF, \
                       pexpect.TIMEOUT], timeout=50)
                if flag == 0:
                    child.send('enable')
                    child.sendcontrol('m')

                    if child:
                        flag = child.expect(['bgpd#*', pexpect.EOF, \
                                         pexpect.TIMEOUT], timeout=90)
                        if flag == 0:
                            Dev.Login(Device, child)
                            if Action == 'enable':
                                if isinstance(Interface, list):
                                    for interface in Interface:
                                        configs = """
                                               configure terminal
                                               router bgp %d
                                               neighbor %s remote-as %d
                                               network %s
                                               exit
                                               exit
                                               """ % (AS_id, interface,
                                                      neighbor_AS_id, NW_id)
                                        commands = configs.split('\n')
                                        execute.execute(child, commands)
                                        time.sleep(6)
                                        child.sendcontrol('m')
                                        child.sendline('exit')
                                        child.sendcontrol('m')

                                else:
                                    interface = Interface
                                    configs = """
                                           configure terminal
                                           router bgp %d
                                           neighbor %s remote-as %d
                                           network %s
                                           exit
                                           exit
                                           """ % (AS_id, interface,
                                                  neighbor_AS_id, NW_id)
                                    commands = configs.split('\n')
                                    execute.execute(child, commands)
                                    child.sendcontrol('m')

                            else:
                                unconfig = """
                                           configure terminal
                                           no router bgp %d
                                           exit
                                           exit
                                           """ % (AS_id)
                                commands = unconfig.split('\n')
                                execute.execute(child, commands)
                                child.sendcontrol('m')

                            return True

        else:
            return False
Ejemplo n.º 33
0
    def redistribution_connected(self, Device, AS_id):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)
        port = device_data['Device_Details'][Device]['port']

        if port != "zebra":
            if child:

                clear_buffer.flushBuffer(1, child)
                child.sendcontrol('m')
                child.sendcontrol('m')
                child.sendcontrol('m')
                flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                       pexpect.EOF, pexpect.TIMEOUT], timeout=90)
                if flag in (0, 2):
                    Dev.Login(Device, child)
                    configs = """
                                  configure terminal
                                  router bgp %d
                                  redistribute connected
                                  end
                                  """ % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

                if flag in (1, 3):
                    configs = """
                                  configure terminal
                                  router bgp %d
                                  redistribute connected
                                  end
                                  """ % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

                return True

        elif port == 'zebra':
            port = "bgpd"
            device_data = getdata.get_data()
            IP_add = device_data['Device_Details'][Device]['ip_add']
            child = pexpect.spawn('telnet ' + IP_add + ' ' + port)
            hostname = device_data['Device_Details'][Device]['Hostname']
            clear_buffer.flushBuffer(1, child)

            child.sendcontrol('m')
            flag = (child.expect(['bgpd*', 'Password*', pexpect.EOF,\
                    pexpect.TIMEOUT], timeout=100))
            if flag == 1:
                child.send('zebra')
                child.sendcontrol('m')
                flag = child.expect(['bgpd*>', pexpect.EOF,\
                       pexpect.TIMEOUT], timeout=50)
                if flag == 0:
                    child.send('enable')
                    child.sendcontrol('m')

                if child:

                    clear_buffer.flushBuffer(1, child)
                    child.sendcontrol('m')
                    child.sendcontrol('m')
                    child.sendcontrol('m')
                    flag = child.expect(['bgpd#*', pexpect.EOF, \
                           pexpect.TIMEOUT], timeout=90)
                    if flag in (0, 2):
                        Dev.Login(Device, child)
                        configs = """
                             configure terminal
                             router bgp %d
                             redistribute connected
                             end
                             """ % (AS_id)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                    if flag in (1, 3):
                        configs = """
                             configure terminal
                             router bgp %d
                             redistribute connected
                             end
                             """ % (AS_id)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                    return True
        else:
            return False
Ejemplo n.º 34
0
    def Configure_IBGP(self, Device, AS_id, Interface, Action):

        device_data = getdata.get_data()
        hostname = device_data['Device_Details'][Device]['Hostname']
        Dev = Devices.Devices()
        child = Dev.connect(Device)

        if child:

            clear_buffer.flushBuffer(1, child)
            child.sendcontrol('m')
            child.sendcontrol('m')
            child.sendcontrol('m')
            flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \
                     pexpect.EOF, pexpect.TIMEOUT], timeout=90)
            if flag in (0, 2):
                Dev.Login(Device, child)
                if Action == 'enable':
                    if isinstance(Interface, list):
                        for interface in Interface:
                            configs = """
                                configure terminal
                                router bgp %d
                                neighbor %s remote-as %d
                                neighbor %s update-source loopback 0
                                exit
                                exit
                                """ % (AS_id, interface, AS_id, interface)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
                        child.sendline('exit')
                        child.sendcontrol('m')

                    else:
                        interface = Interface
                        configs = """
                        configure terminal
                        router bgp %d
                        neighbor %s remote-as %d
                        neighbor %s update-source loopback 0
                        exit
                        exit
                        """ % (AS_id, interface, AS_id, interface)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                else:
                    unconfig = """
                    configure terminal
                    no router bgp %d
                    exit
                    exit
                    """ % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

            if flag in (1, 3):
                if Action == 'enable':
                    if isinstance(Interface, list):
                        for interface in Interface:
                            print(interface)
                            configs = """
                                configure terminal
                                router bgp %d
                                neighbor %s remote-as %d
                                neighbor %s update-source loopback 0
                                exit
                                exit
                                """ % (AS_id, interface, AS_id, interface)
                            commands = configs.split('\n')
                            execute.execute(child, commands)
                            time.sleep(6)
                            child.sendcontrol('m')
                        child.sendline('exit')
                        child.sendcontrol('m')

                    else:
                        interface = Interface
                        configs = """
                        configure terminal
                        router bgp %d
                        neighbor %s remote-as %d
                        neighbor %s update-source loopback 0
                        exit
                        exit
                        exit
                        """ % (AS_id, interface, AS_id, interface)
                        commands = configs.split('\n')
                        execute.execute(child, commands)
                        child.sendcontrol('m')

                else:
                    unconfig = """
                    configure terminal
                    no router bgp %d
                    exit
                    exit
                    """ % (AS_id)
                    commands = configs.split('\n')
                    execute.execute(child, commands)
                    child.sendcontrol('m')

                return True

        else:
            return False