|
|
@ -9,9 +9,6 @@ import logging |
|
|
|
import paramiko, json |
|
|
|
import paramiko, json |
|
|
|
import socket |
|
|
|
import socket |
|
|
|
|
|
|
|
|
|
|
|
# import pexpect |
|
|
|
|
|
|
|
# from api.utils.storage.caches import developer_auth_code |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__file__) |
|
|
|
logger = logging.getLogger(__file__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -89,57 +86,6 @@ class SSHConnection(object): |
|
|
|
self._client.close() |
|
|
|
self._client.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def pshell_command(cmdstrs, user_obj, developer_email, timeout=60 * 10): |
|
|
|
|
|
|
|
# result = default_result() |
|
|
|
|
|
|
|
# run = pexpect.spawn(cmdstrs, encoding='utf-8') |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# index = run.expect( |
|
|
|
|
|
|
|
# ["Two-factor Authentication", "Invalid username and password combination", pexpect.EOF, pexpect.TIMEOUT], |
|
|
|
|
|
|
|
# timeout=timeout) |
|
|
|
|
|
|
|
# if index == 0: |
|
|
|
|
|
|
|
# count = 1 |
|
|
|
|
|
|
|
# if timeout == -1: |
|
|
|
|
|
|
|
# timeout = 60 * 60 * 24 |
|
|
|
|
|
|
|
# while True and count < timeout / 3: |
|
|
|
|
|
|
|
# code = developer_auth_code("get", user_obj, developer_email) |
|
|
|
|
|
|
|
# if code: |
|
|
|
|
|
|
|
# run.sendline(code) |
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
|
|
# err = run.expect(["Unauthorized Access", pexpect.EOF, pexpect.TIMEOUT]) |
|
|
|
|
|
|
|
# if err == 0: |
|
|
|
|
|
|
|
# result['exit_code'] = 2 |
|
|
|
|
|
|
|
# result['return_info'] = 'Unauthorized Access 【验证码有误】' |
|
|
|
|
|
|
|
# elif err == 1: |
|
|
|
|
|
|
|
# result['exit_code'] = 0 |
|
|
|
|
|
|
|
# result['return_info'] = 'Verify Code Success' |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# result['exit_code'] = 3 |
|
|
|
|
|
|
|
# result['return_info'] = 'Verify Code TimeOut or UnKnown Error 【双重验证未知错误】' |
|
|
|
|
|
|
|
# developer_auth_code("del", user_obj, developer_email) |
|
|
|
|
|
|
|
# return result |
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
|
|
|
|
# logger.error("cmdstrs:%s developer_email:%s user_obj:%s Exception:%s" % ( |
|
|
|
|
|
|
|
# cmdstrs, developer_email, user_obj, e)) |
|
|
|
|
|
|
|
# developer_auth_code("del", user_obj, developer_email) |
|
|
|
|
|
|
|
# result['exit_code'] = 0 |
|
|
|
|
|
|
|
# result['return_info'] = 'Success' |
|
|
|
|
|
|
|
# return result |
|
|
|
|
|
|
|
# count += 1 |
|
|
|
|
|
|
|
# time.sleep(3) |
|
|
|
|
|
|
|
# elif index == 1: |
|
|
|
|
|
|
|
# result['exit_code'] = 1 |
|
|
|
|
|
|
|
# result['return_info'] = 'Invalid username and password combination 【密码或者账号有误】' |
|
|
|
|
|
|
|
# elif index == 2: |
|
|
|
|
|
|
|
# result['exit_code'] = 0 |
|
|
|
|
|
|
|
# result['return_info'] = 'Alreay Success' |
|
|
|
|
|
|
|
# else: |
|
|
|
|
|
|
|
# result['exit_code'] = 4 |
|
|
|
|
|
|
|
# result['return_info'] = 'Code TimeOut or UnKnown Error 【验证超时】' |
|
|
|
|
|
|
|
# except Exception as e: |
|
|
|
|
|
|
|
# logger.error("cmdstrs:%s developer_email:%s user_obj:%s Exception:%s" % (cmdstrs, developer_email, user_obj, e)) |
|
|
|
|
|
|
|
# return result |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def shell_command(cmdstrs, timeout): |
|
|
|
def shell_command(cmdstrs, timeout): |
|
|
|
result = default_result() |
|
|
|
result = default_result() |
|
|
|
result['return_info'] = '' |
|
|
|
result['return_info'] = '' |
|
|
|