예제 #1
0
파일: Risque.py 프로젝트: Changer098/larry
    def getTicketBody(self, ticketNumber):
        # if not self.loadedSession:
        #     if self.testSession():
        #         self.loadedSession = True
        #         ConfigurationDriver.saveSession()
        #     else:
        #         self.login()
        if not ConfigurationDriver.loadedSession:
            self.login()
        ticket = None
        if ConfigurationDriver.cookiesStored():
            ticket = self.session.get(
                'https://risque.itap.purdue.edu/Tickets/Data/TicketDetail.aspx?id=%s'
                % ticketNumber,
                cookies=ConfigurationDriver.getCookies())
        else:
            ticket = self.session.get(
                'https://risque.itap.purdue.edu/Tickets/Data/TicketDetail.aspx?id=%s'
                % ticketNumber)
            ConfigurationDriver.storeCookies(self.session.cookies)

        txt = ticket.content
        # Store session
        if "You have asked to login to" in txt:
            raise ValueError("Failed to get ticket body, login invalid")
        else:
            if not ConfigurationDriver.loadedSession:
                persist = SingeltonManager.getPersistenceModule()
                if persist is not None:
                    persist.save()
        return txt
예제 #2
0
 def ctrlchandler(self, sig, frame):
     if ConfigurationDriver.isLocked():
         ConfigurationDriver.clearCredentials()
         ConfigurationDriver.unlock()
     if self.currentPage[0] == "Main Page":
         self.exit()
     # raise an exception on main thread, and leave
     raise StopIteration()
예제 #3
0
파일: Risque.py 프로젝트: Changer098/larry
 def testSession(self):
     data = None
     if ConfigurationDriver.cookiesStored():
         data = self.session.get('https://risque.itap.purdue.edu',
                                 cookies=ConfigurationDriver.getCookies())
     else:
         return False
     if "login" in data.url:
         return False
     return True
예제 #4
0
 def credentials_page(self):
     print("Store Credentials")
     if ConfigurationDriver.credentialsStored():
         print("Credentials already stored")
         response = raw_input("overwrite? (y/n): ")
         if response.lower() == "y":
             ConfigurationDriver.getCredentials()
     else:
         ConfigurationDriver.getCredentials()
     self.goToMainPage()
예제 #5
0
파일: Risque.py 프로젝트: Changer098/larry
 def getTicketData(self, ticketNumber):
     try:
         ticket = self.getTicketBody(ticketNumber)
         return self.parseTicket(ticket)
     except ValueError:
         print("Failed to get ticket, login invalid")
         result = raw_input(
             "Failed to login to risque, change risque password? (y/n)")
         if result.lower() == "y":
             newRisquePass = PasswordUtility.getpassword(
                 "Risque Password (BoilerKey): ")
             user, risquePass, switchPass = ConfigurationDriver.getCredentials(
             )
             ConfigurationDriver.storeCredentials(user, newRisquePass,
                                                  switchPass)
         ConfigurationDriver.clearCookies()
         return None
예제 #6
0
 def main(self):
     if not self.artDisabled:
         print(art.art.getArt())
     while not self.exitApp:
         currentPage = self.currentPage
         try:
             currentPage[1]()
         except AuthenticationException:
             result = raw_input("Failed to login to switch, change switch password? (y/n)")
             if result.lower() == "y":
                 newPassword = PasswordUtility.getpassword("Switch Password: ")
                 user, risquePass, switchPass = ConfigurationDriver.getCredentials()
                 ConfigurationDriver.storeCredentials(user, risquePass, newPassword)
             self.goToMainPage()
         except StopIteration:
             self.goToMainPage()
         except Exception as e:
             print(e)
             print(traceback.format_exc())
             self.goToMainPage()
예제 #7
0
파일: fexTest.py 프로젝트: Changer098/larry
def main():
    username = raw_input("SSH username: "******"SSH password: "******"Running Activate Test")
    ticket = Ticket(0, None, None, None)
    pic = PIC("test", "pjis-141-c3560cx-01:01-Gi1/0/3",
              "pjis-141-c3560cx-01:01-Gi1/0/3", "Activate", None)
    pic.applyNewConfig(None, "128.210.148.000/24 Public Subnet (877)",
                       "10/100T-SW-A")
    ticket.addPic(pic)
    config = Config.Config(ticket)
    config.run()

    print("Running Modify Test")
    ticket = Ticket(0, None, None, None)
    pic = PIC("test", "pjis-141-c3560cx-01:01-Gi1/0/3",
              "pjis-141-c3560cx-01:01-Gi1/0/3", "Modify", None)
    pic.applyCurrentConfig(None, "128.210.148.000/24 Public Subnet (877)",
                           "10/100T-SW-A")
    pic.applyNewConfig(None, "128.210.148.000/24 Public Subnet (1)",
                       "10/100/1000T-SW-A")
    ticket.addPic(pic)
    config = Config.Config(ticket)
    config.run()

    print("Running Deactivate Test")
    ticket = Ticket(0, None, None, None)
    pic = PIC("test", "pjis-141-c3560cx-01:01-Gi1/0/3",
              "pjis-141-c3560cx-01:01-Gi1/0/3", "Deactivate", None)
    pic.applyCurrentConfig(None, "128.210.148.000/24 Public Subnet (1)",
                           "100/1000T-SW-A")
    ticket.addPic(pic)
    config = Config.Config(ticket)
    config.run()
예제 #8
0
    def run(self):
        currentHost = None
        iosConnection = None
        failed = list()  # list of pics that are not valid

        if len(self.ticket.configurablePics) == 0:
            # print Logger.WARNING + "Ticket has no configurable PICs, add provider ports to continue" + Logger.NORMAL
            self.logger.logWarning(
                "Ticket has no configurable PICs, add provider ports to continue",
                True)
            return

        for pic in self.ticket.configurablePics:
            provider = pic.getProvider()
            if provider.getHostFromProvider(provider) is None:
                # print Logger.FAIL + "Failed to get host for provider {0}".format(provider) + Logger.NORMAL
                self.logger.logError(
                    "Failed to get host for provider {0}".format(provider),
                    True)
                failed.append(pic)
                continue
            if currentHost != provider.getHostFromProvider(provider):
                currentHost = provider.getHostFromProvider(provider)
                driver = ConfigurationDriver.getDriver()
                if iosConnection is not None:
                    iosConnection.disconnect()
                iosConnection = IOS(driver, currentHost, provider.switchType)
            try:
                if not self.verify(iosConnection, provider, pic):
                    failed.append(pic)
                else:
                    # print Logger.OKGREEN + "{0} is valid".format(pic.name) + Logger.NORMAL
                    self.logger.logSuccess("{0} is valid".format(pic.name),
                                           True)
            except Exception as e:
                # traceback.print_exc()
                # print Logger.FAIL + "Failed to verify {0} with provider {1}, error: {2}".format(pic.name, provider, e) + Logger.NORMAL
                self.logger.logException(
                    "Failed to verify {0} with provider {1}".format(
                        pic.name, provider), e, True)
                failed.append(pic)

        self.printSummary(self.ticket.configurablePics, failed)
예제 #9
0
파일: Config.py 프로젝트: Changer098/larry
    def run(self):
        currentHost = None
        iosConnection = None

        if len(self.ticket.configurablePics) == 0:
            # print Logger.WARNING + "Ticket has no configurable PICs, add provider ports to continue" + Logger.NORMAL
            self.logger.logWarning(
                "Ticket has no configurable PICs, add provider ports to continue"
            )
            return

        for pic in self.ticket.configurablePics:
            provider = pic.getProvider()
            newHost = provider.getHostFromProvider(provider)
            if provider.getHostFromProvider(provider) is None:
                # print Logger.FAIL + "Failed to get host for provider {0}".format(provider) + Logger.NORMAL
                self.logger.logError(
                    "Failed to get host for provider {0}".format(provider),
                    True)
                continue
            if currentHost != newHost:
                if iosConnection is not None:
                    # leaving host
                    if self.hostChanged:
                        iosConnection.write()
                currentHost = newHost
                driver = ConfigurationDriver.getDriver()
                iosConnection = IOS(driver, currentHost, provider.switchType)
                self.hostChanged = False
            try:
                self.config(iosConnection, provider, pic)
            except Exception, e:
                # print "Failed to configure {0} with provider {1}, error: {2}".format(pic.name, provider, e)
                self.logger.logException(
                    "Failed to configure {0} with provider {1}".format(
                        pic.name, provider), e, True)
예제 #10
0
 def main(self, ticketNumber=None):
     if not ConfigurationDriver.credentialsStored():
         ConfigurationDriver.lock()
     username, risquePassword, switchPassword = ConfigurationDriver.getCredentials(
     )
     if ticketNumber is None:
         ticketNumber = raw_input("Risque Ticket Number: ")
     ConfigurationDriver.unlock()
     print("Getting Info from Risque")
     if self.risque is None:
         self.risque = Risque(username, risquePassword)
     ticket = self.risque.getTicketData(ticketNumber)
     if ticket is None:
         print("Failed to get ticket from risque")
         if self.appUI is not None:
             self.appUI.goToMainPage()
         return
     self.__printDebugTicket(ticket)
     Config.Config(ticket).run()
예제 #11
0
 def setUpClass(cls):
     ConfigurationDriver.useTestCredentials("", "")
     Hosts.USE_DEBUG = True