Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func checkServers() {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {
- var servers = getServers()
- if (servers.count != 0){
- for index in 0...(servers.count - 1) {
- //dispatch_async(dispatch_get_main_queue()) {
- setStatusForAlias(servers[index]["alias"]!, status: "-1")
- self.drawStatus(NSIndexPath(forRow: ServerIndexForAlias(servers[index]["alias"]!), inSection: 0), status: -1)
- (self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: ServerIndexForAlias(servers[index]["alias"]!), inSection: 0))!.viewWithTag(3) as! UIImageView).image = UIImage(named:"finding")
- //}
- }
- for index in 0...(servers.count - 1) {
- let alias = servers[index]["alias"]!
- //NMSSHLogger.sharedLogger().enabled = false
- let session = NMSSHSession.connectToHost(servers[index]["ip"]!, port: (servers[index]["port"]! != "" && Int(servers[index]["port"]!) != nil) ? Int(servers[index]["port"]!)! : 22, withUsername: servers[index]["ip"])
- session.timeout = 1
- dispatch_sync(
- dispatch_get_main_queue(), {
- print(session.lastError)})
- if (session.connected){
- dispatch_sync(
- dispatch_get_main_queue(), {
- if(session.supportedAuthenticationMethods().contains({$0 as! String == "password"})){
- var start = true
- while (start || session.lastError.code == -9){
- print(servers[index]["username"])
- start = false
- session.authenticateByPassword(servers[index]["password"]!)
- print(session.lastError)
- }
- } else {
- var start = true
- while (start || session.lastError.code == -9){
- print(servers[index]["username"])
- start = false
- //print(session.host)
- session.authenticateByKeyboardInteractiveUsingBlock(
- {(test: String!) -> String! in
- //print("attention: \(test)")
- return servers[index]["password"]!
- }
- )
- print(session.lastError)
- }
- }
- }
- )
- if session.authorized == true {
- dispatch_async(dispatch_get_main_queue()) {
- setStatusForAlias(alias, status: "0")
- self.drawStatus(NSIndexPath(forRow: ServerIndexForAlias(alias), inSection: 0), status: 0)
- (self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: ServerIndexForAlias(servers[index]["alias"]!), inSection: 0))!.viewWithTag(3) as! UIImageView).image = UIImage(named:"unknown")
- }
- } else {
- dispatch_async(dispatch_get_main_queue()) {
- setStatusForAlias(alias, status: "1")
- self.drawStatus(NSIndexPath(forRow: ServerIndexForAlias(alias), inSection: 0), status: 1)
- (self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: ServerIndexForAlias(servers[index]["alias"]!), inSection: 0))!.viewWithTag(3) as! UIImageView).image = UIImage(named:"notFound")
- }
- }
- } else {
- dispatch_async(dispatch_get_main_queue()) {
- setStatusForAlias(alias, status: "2")
- self.drawStatus(NSIndexPath(forRow: ServerIndexForAlias(alias), inSection: 0), status: 2)
- (self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: ServerIndexForAlias(servers[index]["alias"]!), inSection: 0))!.viewWithTag(3) as! UIImageView).image = UIImage(named:"notFound")
- }
- }
- session.disconnect()
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement